tree-sitter / tree-sitter-typescript

TypeScript grammar for tree-sitter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

bug: incorrect parsing of type definition

jrvidal opened this issue · comments

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)

7b4275d

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