-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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 decorators parsing #7719
Update decorators parsing #7719
Conversation
This commit introduces three changes: 1) Class properties can be decorated 2) Decorators can contain arbitrary expressions, using @(...) 3) The Decorator node type has a new property, "arguments". This makes it possible do distinguish @dec() and @(dec()), which have different behaviors because @(dec()) is equivalent to @(dec())().
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/7600/ |
@@ -135,11 +135,18 @@ defineType("Import", { | |||
}); | |||
|
|||
defineType("Decorator", { | |||
visitor: ["expression"], | |||
visitor: ["expression", "arguments"], |
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.
callee
?
The code changes themselves look fine to me. A few edge cases: @foo().bar
@foo()()()
class Foo {} I don't think either of those decorators syntaxes are legal according to the syntax. And there's no way to continue compose a a |
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.
LGTM, great work!
The parsing changes here make sense, but the |
babel#7719 (comment) Although babel#7719 updated the parser to produce decorator.arguments when a decorator is called with arguments, @babel/plugin-proposal-decorators was not updated to respect this new property. This fix is loosely modeled after similar functionality in the non-legacy decorators PR by @nicolo-ribaudo: https://github.com/nicolo-ribaudo/babel/blob/f6239a6c8f1cf3eaf76a66c40de08aa3305d1d1a/packages/babel-plugin-proposal-decorators/src/transformer.js#L33-L41
This PR is part of #7542; I'm splitting it in smaller PRs.