-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
content tag #162
content tag #162
Conversation
8695c2e
to
9b681bb
Compare
@gitKrystan i think this works. But you would need to remove most of the ambiguous cases... |
Thanks. I will look into this ASAP. Might not be until next week though. |
btw, i didn't remove the tests for the ambiguous parts. Wanted to wait on content-tag. |
how do you mean? is there an issue / failing test for that project? |
Can you re-run |
The purpose of the ambiguous cases in the tests is that we don't introduce syntax errors when prettifying. e.g. <template>Hello World</template>
(oops) => {} We should be able to detect this case and print: <template>Hello World</template>;
(oops) => {} |
I'm adding failing tests for those to content-tag now 🎉 |
It would be converted to something like
How would it happen that you introduce syntax errors? Although it works with typescript. |
I have lots of thoughts, but no idea which ones are relevant. Please push the lockfile changes so I can run the tests and see what you are talking about. 🙏 |
Looks like there are a few different types of test failure: Missing visitor keys for 'Template'.Cause unknown. This seems to be the majority of the failures. Ambiguous cases that are now syntax errors.With the previous Example of a more realistic case. const ListItem = <template><li>My Item</li></template> // no semi
<template>
<ul>
<ListItem />
<ListItem />
<ListItem />
</ul>
</template> If If Change of behavior in other ambiguous cases.These are still not considered syntax errors in the Here's an example of where the behavior change appears to be introducing a syntax error where there was none. The user added a semi-colon to prevent the syntax error and this plugin removed it.
Change of behavior with config
|
I think i missed something when pushing... |
Thanks again for working on this! |
e463cb9
to
d10c0e6
Compare
mmm, still 600 failing tests in ci... I'll check again tomorrow |
vitest was somehow auto updating all tests snapshots... this will need more work |
okay, now down to 360. Also, some export default where added... Not sure if they should be there . |
I can probably revert the semi change by changing the ast type to function expression for the template. I think. |
After reverting all the snapshot changes, it looks like a lot of the failures are unexpected |
Yes. There is also 1 bug at But note that i only add the export default if it's enabled in the options: |
tests/unit-tests/ambiguous/__snapshots__/arrow-parens-avoid.test.ts.snap
Outdated
Show resolved
Hide resolved
@gitKrystan are you okay with this changes to semi handling? it looks like you expected this to happen?
see link |
now all green |
nope, example is failing. content-tag does not like vite build. edit: just set content-tag as external, now works. but browser env will not |
Content-tag in browsers won't work until this is merged: embroider-build/content-tag#18 Demo of usage: https://github.com/NullVoxPopuli/limber/blob/main/packages/ember-repl/addon/src/browser/gjs.ts#L14 cc @ef4 |
55f6a60
to
a796125
Compare
tests/unit-tests/ambiguous/__snapshots__/arrow-parens-avoid.test.ts.snap
Outdated
Show resolved
Hide resolved
tests/unit-tests/ambiguous/__snapshots__/arrow-parens-avoid.test.ts.snap
Outdated
Show resolved
Hide resolved
ac104bb
to
768b996
Compare
@gitKrystan I think this is ready. I wonder if the ambiguous handling is still relevant with content-tag? edit: I realized now that its not ready... some ambiguous constructs actually can cause content-tag to fail parsing. |
@gitKrystan i was able to minimize the changes to semi handling. |
@@ -1938,17 +1916,16 @@ export interface Signature { | |||
Yields: []; | |||
} | |||
|
|||
<template> | |||
export default (<template> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like we picked up an accidental export default
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
its because i'm leaving as TemplateOnlyComponent<Signature>
to prettiers default handling.
Since it now remains an expression, we cannot safely remove or add default exports to it.
are you okay with this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems fine. Let's see if anyone complains.
Thanks again for all this work! Re: the cases causing syntax errors. Let's keep them for now since they get swallowed anyway. As we've discovered, what counts as a syntax error might change as the implementation of content-tag evolves. Re: ambiguous cases, we want to follow Prettier's current patterns as discussed here. We can/should update that analysis if necessary since content-tag doesn't produce an array like |
a0ae055
to
b9b5fea
Compare
ambiguous cases: <template></template>
<template></template> its either wrapped in a |
96188cb
to
db8ebd3
Compare
@gitKrystan squashed commits, its ready now |
I did the update for eslint, and though that it might work for this as well.
design:
Preprocessor.parse
from content-tag to get template locations. manually convert gjs files with<template>
tags into valid JS, which doesn't change location. The<template>
tag gets converted into empty objects.Template
Ast node, which holds the template content.estree
Prettier printer, which formats the valid JS above.Template
AST node described above.Template
AST node with the results from above, wrapped in<template>
others:
</template> as TemplateOnlyComponent<Signature>
will be left to prettiers default handling