-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Update babelParse to use legacy decorator syntax #21506
Conversation
This kind of makes sense to me. Do you know if lit 2 uses the legacy proposal as well? @valentinpalkovic |
@kasperpeulen No, they don't use it: https://github.com/43081j/postcss-lit/blob/master/src/userConfig.ts#L13. @kasperpeulen EDIT: Sorry. I was too fast reading your comment. I will investigate what lit 2 does. |
@kasperpeulen At least in their docs they propose to use the "2018-09" version of the proposal when used with babel, which is not the EDIT: Hehe, you were a couple of seconds faster. :D |
But we have to consider that transpiling the code with babel and parsing it with EDIT: Even the new proposals do not support |
Right, so if I understand correctly:
Shall we include tests for lit 2.0 examples and stage 3/TS5.0 examples? |
@kasperpeulen If we decide to stick with the current solution, I would highly recommend adding some further tests to cover more decorator syntaxes. On the other hand, it feels "wrong" to opt-out to the legacy syntax. I personally not a fan of this solution. |
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.
Thanks!
f083759
to
262b007
Compare
Closes #21243
What I did
Set up 'legacy-decorator' syntax for babelParser, because it is the only available plugin that supports property decorators (at least, which does not throw an error), which are heavily used in Angular.
As noted here,
@babel/parser
does not support registering other plugins only the ones which are integrated into the core of@babel/parser
.The
legacy-decorator
plugin uses the originalStage 1
proposal. Whereas e.g. Typescript uses theStage 2
proposal (in Typescript 5.0, even the Stage 3.0 proposal).It seems that in Babel 8, the
@babel/plugin-proposal-decorators
get merged into@babel/parser
, which will very like supportparameter decorators
with the newest decorator Stage 3.0 proposal:Differences between the proposals
It is essential to know in which particular areas the proposals differ from each other and whether there are any differences by applying decorators by ignoring the internal implementations of decorators, because for AST parsing this is not relevant.
Differences between Stage 2 / 3 proposal:
Differences between Stage 1 / 2 proposal:
Differences between Typescript "experimental" decorators / Stage 2 decorators:
Impact evaluation:
Opting out for an older decorator proposal might introduce unforeseeable bugs. The babel parser might not be able to parse newer decorator proposal syntax and will likely throw an error.
Optional: Allow the user to overwrite the basic parsing settings
postcss-lit
has implemented the possibility to overwrite the default options, passed to the babel parser. Should we do this as well?!Alternative: Gently recover from "soft" errors.
We can pass the option
errorRecovery: true
to the@babel/parser
to continue parsing the code, if babel can recover from the error state. Then we don't have to opt-out to the olddecorators
proposal and we can still parse the AST without babel throwing a non-recoverable error.Mentionable resources
Checklist
MIGRATION.MD
Maintainers
make sure to add the
ci:merged
orci:daily
GH label to it.["cleanup", "BREAKING CHANGE", "feature request", "bug", "documentation", "maintenance", "dependencies", "other"]