Skip to content
This repository was archived by the owner on Jan 19, 2019. It is now read-only.

Milestone: Decorator Support #63

Closed
14 tasks done
JamesHenry opened this issue Aug 22, 2016 · 16 comments
Closed
14 tasks done

Milestone: Decorator Support #63

JamesHenry opened this issue Aug 22, 2016 · 16 comments

Comments

@JamesHenry
Copy link
Member

JamesHenry commented Aug 22, 2016

This issue it to track progress against supporting decorators within the final AST that the parser produces. We currently remove them during parsing.

We need to ensure that the following are accurately carried over from the original TypeScript AST:

  • Parameter Decorators
    • On instance member
    • On static member
    • In constructor
  • Method Decorators
    • On instance member
    • On static member
  • Accessor Decorators
    • On instance member
    • On static member
  • Property Decorators
    • On instance member
    • On static member
  • Class Decorators

We also need to account for the difference between decorators and decorator factories:

Decorator:
unspecified-11

Decorator Factory:
unspecified-12

At the AST-level, the decorator node has an Identifier TSNode as an expression, whereas the decorator factory has a CallExpression TSNode.

Decorators are not currently covered by the ESTree spec as they are still a fairly early-stage es-proposal, but Angular 2, for example, has adopted them as a core aspect of the framework.

TypeScript adds a decorators array to the node in question, and I propose we do the same.

Resources:
https://www.typescriptlang.org/docs/handbook/decorators.html

@nzakas
Copy link
Member

nzakas commented Aug 22, 2016

TypeScript adds a decorators array to the node in question, and I propose we do the same.

Agreed.

It's probably worth looking at the AST that Babel produces for decorators, which I'm guessing is similar.

@JamesHenry
Copy link
Member Author

Good thinking!

astexplorer shows that babel-eslint produces near identical output, with both the decorator and decorator factory nodes (within a decorators array on the MethodDefinition) having a type of Decorator and an expression property.

As described above, the expression is an Identifier for the decorator, and a CallExpression for the decorator factory.

aug-22-2016 21-40-33

Here is a PR #64 for a Parameter Decorator and a Parameter Decorator Factory on an instance method to get the ball rolling and confirm the format with you.

Feel free to leave it open until more cases are added, but I need to break off now as it's quite late here.

@nzakas
Copy link
Member

nzakas commented Aug 22, 2016

Makes sense. Bonus points for the animated demo. :)

@nzakas
Copy link
Member

nzakas commented Aug 22, 2016

It looks like Flow does support decorators, and it's with the decorators array with Identifier or CallExpression as items, so probably best to mimic that.

@JamesHenry
Copy link
Member Author

Ok, cool thanks. Do you have a reference for that you can link to?

I will update that first PR now

@nzakas
Copy link
Member

nzakas commented Aug 24, 2016

I just used astexplorer.net.

@JamesHenry
Copy link
Member Author

Method decorator support (static and instance methods) now complete in #64

@JamesHenry JamesHenry changed the title Add decorators to AST Milestone: Decorator Support Aug 24, 2016
@JamesHenry
Copy link
Member Author

JamesHenry commented Aug 24, 2016

Class decorator support now also complete. I branched from the method decorator PR to avoid conflicts. PR is here #67

@JamesHenry
Copy link
Member Author

JamesHenry commented Aug 24, 2016

It appears that flow does not currently support Parameter Decorators.

I think it makes sense to just follow the same approach as with the other decorator types - a decorators array on the parameter identifier node directly

@nzakas
Copy link
Member

nzakas commented Aug 24, 2016

Agreed.

@JamesHenry
Copy link
Member Author

Cool, thanks. In which case PR for parameter decorators is ready #69

@JamesHenry
Copy link
Member Author

Property decorators up next! #72

@nzakas
Copy link
Member

nzakas commented Aug 26, 2016

You are rocking!

@JamesHenry
Copy link
Member Author

🎸

@nzakas nzakas closed this as completed in 138495f Aug 29, 2016
@nzakas
Copy link
Member

nzakas commented Aug 29, 2016

@JamesHenry you are awesome. Thanks for all your work on this.

@JamesHenry
Copy link
Member Author

Thanks so much @nzakas! Your patience and guidance has been invaluable throughout this process

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants