Parse error on import() syntax
Wilfred opened this issue · comments
Wilfred Hughes commented
The following piece of code is valid but it is parsed incorrectly:
type ExpressionNamerFn = (
expr: import('expressions').Expr,
) => string;
Here's a link to the TypeScript Playground showing that the snippet above is valid JavaScript or TypeScript:
https://www.typescriptlang.org/play?#code/C4TwDgpgBAogHmAThAziglgewHYDkCGAthIgGLZQC8UAFAFBRQQKIBcU6hYmiwNA5MySoMOFPwCUAOnhIANHQlUAfFBTBE6bAHMA3EA
The output of tree-sitter parse
is the following:
$ difft --dump-ts a.ts
program (0, 0) - (3, 0)
type_alias_declaration (0, 0) - (2, 12)
type (0, 0) - (0, 4) "type"
type_identifier (0, 5) - (0, 22) "ExpressionNamerFn"
= (0, 23) - (0, 24) "="
function_type (0, 25) - (2, 11)
formal_parameters (0, 25) - (2, 1)
( (0, 25) - (0, 26) "("
required_parameter (1, 2) - (1, 34)
identifier (1, 2) - (1, 6) "expr"
type_annotation (1, 6) - (1, 34)
: (1, 6) - (1, 7) ":"
ERROR (1, 8) - (1, 30)
identifier (1, 8) - (1, 14) "import"
parenthesized_type (1, 14) - (1, 29)
( (1, 14) - (1, 15) "("
literal_type (1, 15) - (1, 28)
string (1, 15) - (1, 28)
' (1, 15) - (1, 16) "'"
string_fragment (1, 16) - (1, 27) "expressions"
' (1, 27) - (1, 28) "'"
) (1, 28) - (1, 29) ")"
. (1, 29) - (1, 30) "."
type_identifier (1, 30) - (1, 34) "Expr"
, (1, 34) - (1, 35) ","
) (2, 0) - (2, 1) ")"
=> (2, 2) - (2, 4) "=>"
predefined_type (2, 5) - (2, 11)
string (2, 5) - (2, 11) "string"
; (2, 11) - (2, 12) ";"
Amaan Qureshi commented
this is becoming a bit snowflakey, but not hard to fix...I guess