Skip to content

bug: parse error on keyof import('a').A; #352

@forivall

Description

@forivall

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.9

Describe the bug

Similar to #322 , keyof with import expressions in type annotations are not parsed properly.

Steps To Reproduce/Bad Parse Tree

let foo: keyof import('a').A;

(program [0, 0] - [1, 0]
  (lexical_declaration [0, 0] - [0, 29]
    (variable_declarator [0, 4] - [0, 7]
      name: (identifier [0, 4] - [0, 7]))
    (ERROR [0, 7] - [0, 28]
      (member_expression [0, 15] - [0, 28]
        object: (call_expression [0, 15] - [0, 26]
          function: (import [0, 15] - [0, 21])
          arguments: (arguments [0, 21] - [0, 26]
            (string [0, 22] - [0, 25]
              (string_fragment [0, 23] - [0, 24]))))
        property: (property_identifier [0, 27] - [0, 28])))))

Expected Behavior/Parse Tree

(program [0, 0] - [1, 0]
  (lexical_declaration [0, 0] - [0, 29]
    (variable_declarator [0, 4] - [0, 28]
      name: (identifier [0, 4] - [0, 7])
      type: (type_annotation [0, 7] - [0, 28]
        (index_type_query [0, 9] - [0, 28]
          (member_expression [0, 15] - [0, 28]
            object: (call_expression [0, 15] - [0, 26]
              function: (import [0, 15] - [0, 21])
              arguments: (arguments [0, 21] - [0, 26]
                (string [0, 22] - [0, 25]
                  (string_fragment [0, 23] - [0, 24]))))
            property: (property_identifier [0, 27] - [0, 28])))))))

Or, this tree might be different if a node other than call_expression is used to parse import calls (which, imo, it should, since import expressions are different than call expressions in the ecmascript spec, and they're also treated specially in typescript type annotations. but that could be a different fix.

Repro

let foo: keyof import('a').A;

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