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: Parse error on const x: import('foo').Bar<Baz> #322

Open
2 tasks done
gthb opened this issue Jan 6, 2025 · 1 comment
Open
2 tasks done

bug: Parse error on const x: import('foo').Bar<Baz> #322

gthb opened this issue Jan 6, 2025 · 1 comment
Labels

Comments

@gthb
Copy link

gthb commented Jan 6, 2025

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.25.0 (ba19fe31bed96a28aa5a1b9253a716e494ed7a9b)

Describe the bug

A type declaration containing the dynamic import syntax with a type parameter applied fails to parse, though it is valid Typescript.

Steps To Reproduce/Bad Parse Tree

Minimal example:

const foo: import('./bar').Bar<string> = 'baz';

This is valid Typescript, but tree-sitter-typescript produces a parse error:

❯ tree-sitter parse foo.ts                      
(program [0, 0] - [1, 0]
  (lexical_declaration [0, 0] - [0, 30]
    (variable_declarator [0, 6] - [0, 30]
      name: (identifier [0, 6] - [0, 9])
      type: (type_annotation [0, 9] - [0, 30]
        (member_expression [0, 11] - [0, 30]
          object: (call_expression [0, 11] - [0, 26]
            function: (import [0, 11] - [0, 17])
            arguments: (arguments [0, 17] - [0, 26]
              (string [0, 18] - [0, 25]
                (string_fragment [0, 19] - [0, 24]))))
          property: (property_identifier [0, 27] - [0, 30])))))
  (expression_statement [0, 30] - [0, 47]
    (type_assertion [0, 30] - [0, 46]
      (type_arguments [0, 30] - [0, 38]
        (predefined_type [0, 31] - [0, 37]))
      (ERROR [0, 39] - [0, 40])
      (string [0, 41] - [0, 46]
        (string_fragment [0, 42] - [0, 45])))))
foo.ts	Parse:   14.33 ms	    3 bytes/ms	(MISSING ";" [0, 30] - [0, 30])

Expected Behavior/Parse Tree

I expect a parse tree without error nodes.

I'm not familiar enough to say exactly what that valid tree should look like, because I'm not using tree-sitter directly — I'm using it via Difftastic (with git -c diff.external=difft diff), and these parse errors cause Difftastic to fall back to a text-based (not syntax-aware) diff.

Repro

const foo: import('./bar').Bar<string> = 'baz';
@gthb gthb added the bug label Jan 6, 2025
@gthb
Copy link
Author

gthb commented Jan 6, 2025

See #246 where a parse error involving the import(...) syntax in a type assertion context was fixed — I suppose that fix just overlooked the import(...).Type<TypeParams> case.

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