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

Question on class/method/property location data when it has decorator(s) #694

@JamesHenry

Description

@JamesHenry

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

class Other {
    @foo({ baz: true })
    static get bar() { return this._bar; }
}

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions