Adds the @init: modifier to decorator plugins#13859
Adds the @init: modifier to decorator plugins#13859nicolo-ribaudo merged 5 commits intobabel:feat-7.16.0/decoratorsfrom
@init: modifier to decorator plugins#13859Conversation
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 3fec3c6:
|
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/49902/ |
| @@ -446,14 +446,42 @@ export default class StatementParser extends ExpressionParser { | |||
|
|
|||
There was a problem hiding this comment.
Nit: Can you put a spec link as comment before hasPlugin("decorators")? For example https://arai-a.github.io/ecma262-compare/?pr=2417&id=sec-decorators.
| shouldParseExportDeclaration(): boolean { | ||
| const { type } = this.state; | ||
| if (type === tt.at) { | ||
| if (type === tt.at || type === tt.atInit) { |
There was a problem hiding this comment.
We don't need to expect decorators-legacy plugin when type is tt.atInit, since the token is invalid in the legacy decorators. Maybe we can move the expectPlugin check to the tokenizer so we don't have to take care of that in parsing level.
| // Replace the previous state | ||
| this.state = old; | ||
|
|
||
| if (wordNext === charCodes.colon) { |
There was a problem hiding this comment.
We need to check the next character after : because it may form a doubleColon token ::, e.g.
class C {
@init::b p;
}is valid given that decorators-legacy and functionBind are enabled.
|
|
||
| if (wordNext === charCodes.colon) { | ||
| if (word !== "init" || containsEsc) { | ||
| throw this.raise(this.state.pos, Errors.UnsupportedDecoratorModifier); |
There was a problem hiding this comment.
No need to throw, we can recover by parsing it as if it was @init: (which is what would already happen by just removing throw).
nicolo-ribaudo
left a comment
There was a problem hiding this comment.
It looks like some fixtures need to be updated!
| shouldParseExportDeclaration(): boolean { | ||
| const { type } = this.state; | ||
| if (type === tt.at) { | ||
| if (type === tt.at || type === tt.atInit) { |
There was a problem hiding this comment.
| if (type === tt.at || type === tt.atInit) { | |
| if (tokenIsDecorator(type)) { |
5dd248e to
56a5229
Compare
0f5663a to
e6f6d3b
Compare
Adds the `@init:` modifier to the decorator plugins. If present, this adds `init: true` to the decorator node. This currently works in both plugins, the idea being that we can error for legacy versions of decorators which do not support `@init:` in the Babel plugin.
|
I have rebased |
56a5229 to
db77bd6
Compare
|
The last commit fixes #13859 (comment). |
|
The last commit does #13859 (comment) |
Adds the
@init:modifier to the decorator plugins. If present, thisadds
init: trueto the decorator node. This currently works in bothplugins, the idea being that we can error for legacy versions of
decorators which do not support
@init:in the Babel plugin.