Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
2 tasks done
carueda opened this issue Sep 10, 2024 · 1 comment
Open
2 tasks done
Labels

Comments

@carueda
Copy link

carueda commented Sep 10, 2024

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)

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 carueda added the bug label Sep 10, 2024
@carueda
Copy link
Author

carueda commented Sep 11, 2024

Seems like same behavior for:

type Foo = {
    lat?: number,
}

Also just had a quick look at https://github.com/tree-sitter/tree-sitter-typescript/blob/master/test/corpus/types.txt, where similar cases are tested, eg:

type ConflictInfo = {
  start?: LineHandle,
  middle?: LineHandle,
  end?: LineHandle
}

so it's a bit intriguing that AFAICS this has not been noted before (or perhaps downstream tooling simply manages to determine the optional member situation via other means (which is not difficult anyway).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant