Description
Hi!
The following piece of code is invalid but it is parsed correctly:
export default let a = 42
Here's a link to the TypeScript Playground showing that the snippet above is invalid JavaScript or TypeScript:
https://www.typescriptlang.org/play?#code/KYDwDg9gTgLgBAE2AMwIYFcA29PHquAXjgBYAmAbiA
The output of tree-sitter parse
is the following:
(program [0, 0] - [1, 0]
(export_statement [0, 0] - [0, 26]
declaration: (lexical_declaration [0, 15] - [0, 26]
(variable_declarator [0, 19] - [0, 25]
name: (identifier [0, 19] - [0, 20])
value: (number [0, 23] - [0, 25])))))
This issue was introduced in 0.20.0, the 0.19.0 grammar gave an ERROR
node: 39b534f
I am not sure that declarations should be allowed in export default
. I'd be happy if you can point me to the specification you're following when working on the grammar, so I can triple-check before opening issues
The parser not marking syntax errors as such is not a big problem, like in this kind of issues. The consuming code can assume it won't happen.
In this issue, the consuming code has to adapt to the new grammar, because export default function foo() { }
contains a function_declaration
instead of a function
. I worked around like this:
switch (node.type):
case "class-declaration":
case "function-declaration":
// valid because 'class' and 'function' node types exist
case "variable-declaration":
case "module-declaration":
default:
// syntax error