Skip to content
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

Merged

Conversation

nicolo-ribaudo
Copy link
Member

Q                       A
Fixed Issues?
Patch: Bug Fix? y
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR
Any Dependency Changes?
License MIT

This PR is part of #7542; I'm splitting it in smaller PRs.

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())().

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())().
@nicolo-ribaudo nicolo-ribaudo added PR: Spec Compliance 👓 A type of pull request used for our changelog categories Spec: Decorators labels Apr 12, 2018
@babel-bot
Copy link
Collaborator

babel-bot commented Apr 12, 2018

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/7600/

@hzoo hzoo mentioned this pull request Apr 14, 2018
2 tasks
@@ -135,11 +135,18 @@ defineType("Import", {
});

defineType("Decorator", {
visitor: ["expression"],
visitor: ["expression", "arguments"],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

callee?

@jridgewell
Copy link
Member

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. @foo() certainly is, but there's no way to compose a DecoratorMemberExpression with a DecoratorCallExpression as the base.

And there's no way to continue compose a a DecoratorCallExpression into a another DecoratorCallExpression...

@hzoo hzoo added this to the Babel 7 RC milestone Apr 17, 2018
Copy link
Member

@xtuc xtuc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, great work!

@existentialism existentialism merged commit 341bdab into babel:master Apr 17, 2018
@nicolo-ribaudo nicolo-ribaudo deleted the decorators-updated-parsing branch April 17, 2018 21:26
@benjamn
Copy link
Contributor

benjamn commented May 24, 2018

The parsing changes here make sense, but the @babel/plugin-proposal-decorators transform doesn't seem to respect the new .arguments property here or here, which is leading to bugs such as meteor/meteor#9895. I will try to submit a PR to fix this, but I wanted to flag it as a problem here, in case I'm missing something, or anyone else has thoughts.

benjamn added a commit to benjamn/babel that referenced this pull request May 24, 2018
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
@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Oct 4, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: Spec Compliance 👓 A type of pull request used for our changelog categories Spec: Decorators
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants