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

bug: wrong `await_expression` node when `call_expression` has a `type_arguments`

Open ofseed opened this issue 1 year ago • 0 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

When wrote a code snippet like this:

await f()

The tree will be

(program ; [0, 0] - [1, 0]
  (expression_statement ; [0, 0] - [0, 9]
    (await_expression ; [0, 0] - [0, 9]
      (call_expression ; [0, 6] - [0, 9]
        function: (identifier) ; [0, 6] - [0, 7]
        arguments: (arguments))))) ; [0, 7] - [0, 9]

But if the function f receives a type argument, like this

await f<T>()

The tree will be:

(program ; [0, 0] - [1, 0]
  (expression_statement ; [0, 0] - [0, 12]
    (call_expression ; [0, 0] - [0, 12]
      function: (await_expression ; [0, 0] - [0, 7]
        (identifier)) ; [0, 6] - [0, 7]
      type_arguments: (type_arguments ; [0, 7] - [0, 10]
        (type_identifier)) ; [0, 8] - [0, 9]
      arguments: (arguments)))) ; [0, 10] - [0, 12]

The location of the node await_expression will be in a different place in this case.

Steps To Reproduce/Bad Parse Tree

  1. Code snippet
await f<T>()
  1. The tree
(program ; [0, 0] - [1, 0]
  (expression_statement ; [0, 0] - [0, 12]
    (call_expression ; [0, 0] - [0, 12]
      function: (await_expression ; [0, 0] - [0, 7]
        (identifier)) ; [0, 6] - [0, 7]
      type_arguments: (type_arguments ; [0, 7] - [0, 10]
        (type_identifier)) ; [0, 8] - [0, 9]
      arguments: (arguments)))) ; [0, 10] - [0, 12]

Expected Behavior/Parse Tree

(program
  (expression_statement
    (await_expression
      (call_expression
        function: (identifier)
        type_arguments: (type_arguments
          (type_identifier))
        arguments: (arguments)))))

Repro

await f<T>()

ofseed avatar Mar 04 '24 06:03 ofseed