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: Non-null assertion operator ! parsed with wrong precedence #299

Open
2 tasks done
andersk opened this issue Jun 3, 2024 · 0 comments
Open
2 tasks done

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

andersk opened this issue Jun 3, 2024 · 0 comments
Labels

Comments

@andersk
Copy link

andersk commented Jun 3, 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)

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

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