You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thanks to this comment from @bmish, I realized that the recently merged #653 can produce invalid html when changing quoteType. Looking into the issue more, I see there was an already existing issue that changing the value of string literals or AttrNodes can produce invalid html.
But, I'm kinda tired of chasing these kinds of things down.
In my opinion, we need a proper, well-typed Glimmer concrete syntax tree, parser, and printer. I'm thinking of writing one, but probably won't be whacking any more moles like this in the meantime.
Here's the relevant section on html attribute syntax: https://html.spec.whatwg.org/dev/syntax.html#attributes-2
Here are some tests that could be added to parse-result.test.ts, if someone else would like to fix these issues here:
test('Escape quotes properly when changing string values',function(){letast=parse(`{{helper 'val'}}`)asany;ast.body[0].params[0].value="aaron's house";expect(print(ast)).toEqual(``);});test('Escape string literals when changing quote type',function(){letast=parse(`{{helper "aaron's house"}}`)asany;ast.body[0].params[0].quoteType="'";expect(print(ast)).toEqual(`{{helper 'aaron\\'s house'}}`);ast=parse(`{{helper '"so-called"'}}`);ast.body[0].params[0].quoteType='"';expect(print(ast)).toEqual(`{{helper '\\"so-called\\"'}}`);});test('Escape attribute values when changing quote type',function(){letast=parse(`<img alt="john's house">`)asany;ast.body[0].attributes[0].quoteType="'";expect(print(ast)).toEqual(`<img alt='john\\'s house'>`);ast=parse(`<img alt='"so-called"'>`);ast.body[0].attributes[0].quoteType='"';expect(print(ast)).toEqual(`<img alt="\\"so-called\\"">`);ast=parse(`<div class="john's house {{this.otherClass}}"></div>`);ast.body[0].attributes[0].quoteType="'";expect(print(ast)).toEqual(`<div class='john's house {{this.otherClass}}"></div>`);ast=parse(`<div class='a "so-called" btn {{this.otherClass}}'></div>`);ast.body[0].attributes[0].quoteType='"';expect(print(ast)).toEqual(`<div class="a "so-called" btn {{this.otherClass}}"></div>`);});
The text was updated successfully, but these errors were encountered:
These rules are generally following prettier it seems and what it would do is simply leave it as is. If a quote is in a string in prettier it uses the opposite type to wrap it regardless of the setting.
Thanks to this comment from @bmish, I realized that the recently merged #653 can produce invalid html when changing quoteType. Looking into the issue more, I see there was an already existing issue that changing the value of string literals or AttrNodes can produce invalid html.
But, I'm kinda tired of chasing these kinds of things down.
In my opinion, we need a proper, well-typed Glimmer concrete syntax tree, parser, and printer. I'm thinking of writing one, but probably won't be whacking any more moles like this in the meantime.
Here's the relevant section on html attribute syntax: https://html.spec.whatwg.org/dev/syntax.html#attributes-2
Here are some tests that could be added to
parse-result.test.ts
, if someone else would like to fix these issues here:The text was updated successfully, but these errors were encountered: