Skip to content

bug: Non-null assertion operator ! parsed with wrong precedence #299

Open
@andersk

Description

@andersk

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

tree-sitter parses the TypeScript non-null assertion operator ! with incorrect precedence. The TypeScript compiler parses ! with precedence higher than new, but tree-sitter incorrectly parses it with precedence lower than || and ??.

For example, a && b! should be equivalent to a && (b!), not (a && b)!.

Steps To Reproduce/Bad Parse Tree

$ cat test.ts
a && b!
$ tree-sitter parse test.ts
(program [0, 0] - [1, 0]
  (expression_statement [0, 0] - [0, 7]
    (non_null_expression [0, 0] - [0, 7]
      (binary_expression [0, 0] - [0, 6]
        left: (identifier [0, 0] - [0, 1])
        right: (identifier [0, 5] - [0, 6])))))

Expected Behavior/Parse Tree

(program [0, 0] - [1, 0]
  (expression_statement [0, 0] - [0, 7]
    (binary_expression [0, 0] - [0, 7]
      left: (identifier [0, 0] - [0, 1])
      right: (non_null_expression [0, 5] - [0, 7]
        (identifier [0, 5] - [0, 6])))))

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