Skip to content

bug: decorator of class_declaration changes its relation when class is exported #331

@kamilogorek

Description

@kamilogorek

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.25.4 (726dcd1e872149d95de581589fc408fb8ea9cb0b)

Describe the bug

Similar bug to what has been already reported in #309 but only happens when export modifier is added to the class declaration.

This prevents from finding class declarations that contain only specific decorators, as in exported case, decorator is not child of a class, but rather its preceding sibling.

ref: https://ast-grep.github.io/playground.html#eyJtb2RlIjoiQ29uZmlnIiwibGFuZyI6InR5cGVzY3JpcHQiLCJxdWVyeSI6ImNvbnNvbGUubG9nKCRNQVRDSCkiLCJyZXdyaXRlIjoibG9nZ2VyLmxvZygkTUFUQ0gpIiwic3RyaWN0bmVzcyI6InNtYXJ0Iiwic2VsZWN0b3IiOiIiLCJjb25maWciOiIiLCJzb3VyY2UiOiJAT25lKClcbmV4cG9ydCBjbGFzcyBIZWxsb1dvcmxkIHt9XG5cbkBUd28oKVxuY2xhc3MgSGVsbG9UaGVyZSB7fSJ9

Bad Parse Tree

export_statement
  - decorator
  - class declaration

class_declaration
  - decorator

Expected Parse Tree

export_statement
  - class declaration
    - decorator

class_declaration
  - decorator

Repro

@One()
export class HelloWorld {}

@Two()
class HelloThere {}

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