-
-
Notifications
You must be signed in to change notification settings - Fork 256
Question on class/method/property location data when it has decorator(s) #694
Comments
Hey @JamesHenry! We really appreciate you taking the time to report an issue. The collaborators If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack |
@JamesHenry IIRC this is fixed in decorators2 |
Indeed it is, thanks, @existentialism! Updating my parser config to use Is there any reason not to apply the location fix to the |
(Updated the description a bit as this does not just apply to method decorators) |
@JamesHenry not sure how others feel re: making changes to old decorator plugin, but I'm fine with it... and nice side effect: it'll help remove some comment-related hacking in prettier as well. |
(Other than test output) This is all that would need to change AFAICT: https://github.com/babel/babylon/compare/master...JamesHenry:target-decorators-location?expand=1#diff-71f5ec1ce64b229d1ebbcf5d9a486d8a |
I'd be super happy indeed :p |
Go ahead. |
Thanks @jridgewell, PR opened here #699 |
The PR was merged! Thanks all |
I find it a little unintuitive that if you apply a decorator to a method (or other target construct such as a class), the method's location data does not include the decorator, given that the
decorators: []
array is a property of the node.Both the TypeScript and Flow parsers (the only others I believe support decorators) behave differently to Babylon here, their relevant method node location includes the decorator content.
I could not find any guidance on location data within https://github.com/tc39/proposal-decorators
Was this behaviour explicitly discussed and decided on in Babylon? Are there other precedents of nested nodes "overflowing" their parents?
Example Code
Live example: http://astexplorer.net/#/gist/c7692dd145ef9aaa2c9600f976257a2a/bf55ed4537b7520a6c19045d7e9fa4e6f3f11d14
...take a look at the highlighted method for Bablyon vs TypeScript and Flow (and the location data in the AST of course).
The text was updated successfully, but these errors were encountered: