tree-sitter / tree-sitter-typescript

TypeScript grammar for tree-sitter
MIT License
332 stars 103 forks source link

bug: incorrect parsing of type definition #295

Closed jrvidal closed 24 minutes ago

jrvidal commented 1 month ago

Did you check existing issues?

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

7b4275d077ae196fc0ce42ab3ad091574e3ec519

Describe the bug

I'm getting highlight errors on some type definitions, and it seems like the cause is here, upstream.

Steps To Reproduce/Bad Parse Tree

type Foo = import('node:fs').ReadStream & {
  bar();
};
(program [0, 0] - [3, 0]
  (type_alias_declaration [0, 0] - [0, 17]
    name: (type_identifier [0, 5] - [0, 8])
    value: (type_identifier [0, 11] - [0, 17]))
  (expression_statement [0, 17] - [2, 2]
    (binary_expression [0, 17] - [2, 1]
      left: (member_expression [0, 17] - [0, 39]
        object: (parenthesized_expression [0, 17] - [0, 28]
          (string [0, 18] - [0, 27]
            (string_fragment [0, 19] - [0, 26])))
        property: (property_identifier [0, 29] - [0, 39]))
      right: (object [0, 42] - [2, 1]
        (ERROR [1, 2] - [1, 8]
          (property_identifier [1, 2] - [1, 5])
          (formal_parameters [1, 5] - [1, 7]))))))
repro.ts       0.15 ms     370 bytes/ms (MISSING ";" [0, 17] - [0, 17])

Expected Behavior/Parse Tree

As far as I can tell this is valid TypeScript (see playground link below), so the parse tree should not contain errors.

Repro

Playground link