-
-
Notifications
You must be signed in to change notification settings - Fork 258
Conversation
"name": "x", | ||
"decorators": [ | ||
{ | ||
"type": "Decorator", |
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.
@thejameskyle commented here:
Decorator
should probably be broken into an alias of many different types.interface Decorator <: Node { expression: Expression; } interface ClassDecorator <: Decorator { type: "ClassDecorator" } interface ParameterDecorator <: Decorator { type: "ParameterDecorator" } // etc...
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.
@thejameskyle Thanks for your comment!
I agree that different types of decorators should be renamed and have Decorator
as an alias to allow transformers to exactly match desired nodes. However, as far as I looked through babel-types, there are already 6 different types of decorators that are all expressed as Decorator
:
- ObjectMethod
- ObjectProperty
- ClassDeclaration
- ClassExpression
- ClassMethod
- ClassProperty
I think the renaming can be done separately from this PR because it will involve a lot of changes to other packages like babel-types. What do you think?
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.
I'm worried how this will impact existing transforms. Adding a Decorator
type in a new location will cause transforms that are looking for existing types of decorators without validating the rest of the AST will break.
Maybe this one can be the first Decorator node of a new sub-type and we can update the rest later?
82943ad
to
87edfd1
Compare
@thejameskyle I've updated the code to use Also, I've excluded function parameter decorators because the proposal says:
|
EDITED: I mistakenly wrote "function expression" when I meant "function declaration". it's now corrected. Function declaration decorators and function parameter decorators have been It wouldn't hurt to have syntactical support for these two so that we can I do expect that over time, especially if the implementation based on On Tue, Mar 22, 2016 at 8:52 AM Shuhei Kagawa notifications@github.com
|
@IgorMinar I'd like to parse function parameter decorators too but I'd rather want this PR to be merged sooner. @thejameskyle What do you think about supporting function parameters decorators at this time? |
I'm fine with either. If excluding function declaration and function On Wed, Mar 23, 2016 at 4:21 AM Shuhei Kagawa notifications@github.com
|
It's probably fine if they are be behind separate |
Sorry I haven't had a chance to look at this sooner. This looks good besides the fact that |
87edfd1
to
066229f
Compare
@kittens @thejameskyle Updated @IgorMinar Just to make it clear, function expression decorators are currently not supported due to this check. |
Don't know if we want a test for params in other node type that are functions:
|
@hzoo Thanks for your advice. I'll add tests for the other node types. |
066229f
to
29a6578
Compare
@hzoo I added tests for other node types except
To support |
Sounds good, I didn't think arrow functions were in there but I didn't check the proposal or anything 😛. |
@hzoo @thejameskyle is this PR good? Can we get it merged? thanks! |
👍 from me |
We may want to figure out the issue with runtime 5/6 before we release I think? And we haven't made a release yet since moving the repo |
Thanks everyone 🎉 @hzoo Do we need to update other packages before releasing it? I'm afraid that a new property |
Yeah we'll need to update babel-types at least https://github.com/babel/babel/tree/master/packages/babel-types/src/definitions, but the checks are restrictive checks so it shouldn't error? (Benefits of keeping it in the monorepo are showing 😄). The decorators transform isn't working atm and there's logan's https://github.com/loganfsmyth/babel-plugin-transform-decorators-legacy |
@hzoo Thanks! As far as I know, the types that will get
The legacy transformer shouldn't error because it doesn't use |
Because Method Parameter Decorators is now a TC39 stage 0 proposal, I'd like to propose babylon to parse parameter decorators.
While the actual transform is still being debated, it would be great if babylon only parses the syntax and allows users to transform it with third-party plugins. One concrete use case is Angular 2's decorators.
https://phabricator.babeljs.io/T1301
(Reopening #3 that was automatically closed because of rebased
master
)