Skip to content

bug: method_definition decorators should be inside the method_definition node #309

Open
@mclaughlinconnor

Description

@mclaughlinconnor

Did you check existing issues?

  • I have read all the tree-sitter docs if it relates to using the parser
  • I have searched the existing issues of tree-sitter-typescript

Tree-Sitter CLI Version, if relevant (output of tree-sitter --version)

tree-sitter 0.22.6 (b40f342067a89cd6331bf4c27407588320f3c263)

Describe the bug

Parsing code where a decorator is attached to a method definition puts the (decorator) inside the class nearby to the (method_definition) instead of being inside the (method_definition) like I'd expect it to be. Other similar situations (e.g., (class_declaration), (_parameter_name), (public_field_definition)) have the decorator inside the decorated node.

The typescript AST also has the decorator inside of the method definition

https://ts-ast-viewer.com/#code/MYGwhgzhAEBiD29oG8BQ1oAEBOBTMAJvAHYgCe0AZogEJjYAUAlCgL6rtA

Steps To Reproduce/Bad Parse Tree

Trying to parse:

class Foo {
  @readonly fooBar() {}
}

Will produce:

(program
  (class_declaration
    (type_identifier)
    (class_body
      (decorator
        (identifier))
      (method_definition
        (property_identifier)
        (formal_parameters)
        (statement_block)))))

Expected Behavior/Parse Tree

I'd expect the parse tree to look like this

(program
  (class_declaration
    (type_identifier)
    (class_body
      (method_definition
        (decorator
          (identifier))
        (property_identifier)
        (formal_parameters)
        (statement_block)))))

Repro

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions