tree-sitter-typescript icon indicating copy to clipboard operation
tree-sitter-typescript copied to clipboard

bug: Question mark for object member not captured in its own tree node

Open carueda opened this issue 1 year ago • 1 comments

Did you check existing issues?

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

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

No response

Describe the bug

Please consider this typescript definition:

interface Foo {
    lat?: number,
}

Using the playground, here's the corresponding tree:

program [0, 0] - [4, 0]
  interface_declaration [0, 0] - [2, 1]
    name: type_identifier [0, 10] - [0, 13]
    body: interface_body [0, 14] - [2, 1]
      property_signature [1, 4] - [1, 16]
        name: property_identifier [1, 4] - [1, 7]
        type: type_annotation [1, 8] - [1, 16]
          predefined_type [1, 10] - [1, 16]

As expected, property_signature [1, 4] - [1, 16] refers to the lat definition.

However, there's no sub-node for the optional specifier, that is, the ? next to lat, or, alternatively, some other node type that indicates the member is optional.

Perhaps this is not a bug, but it is surprising nonetheless, unless I'm missing something.

Also note that:

interface Foo {
    lat: number,
}

that is, with no ?, gets the very same tree (except different ranges of course).

Steps To Reproduce/Bad Parse Tree

(please see above)

Expected Behavior/Parse Tree

Not exactly sure what the fully correct tree should look like, but I would expect an additional or alternative sub-node that indicates the member is optional.

Repro

Just my example above.

Thanks!

carueda avatar Sep 10 '24 12:09 carueda