generic type as return type of arrow function
kawmra opened this issue · comments
Masashi Kawamura commented
Using a generic type as the return type of arrow functions seems to confuse the parser.
const a = (): Array<string> => {
return []
}
is parsed to
[
"Script",
"VariableDeclaration",
"const",
"VariableDefinition",
"Equals",
"BinaryExpression", // <- ?
"BinaryExpression",
"ArrowFunction",
"ParamList",
"(",
")",
"TypeAnnotation",
":",
"TypeName",
"⚠",
"CompareOp",
"VariableName",
"CompareOp",
"⚠",
"Arrow",
"ObjectExpression",
"{",
"Property",
"PropertyDefinition",
"⚠",
"}"
]
It only happens if specify dialect: "tsx"
, not dialect: "ts"
.
I tested that with following code:
import { parser } from "@lezer/javascript";
const script = "...";
const list: string[] = [];
parser.configure({ dialect: "tsx" }).parse(script).iterate({
enter: (node) => {
list.push(node.name);
},
});
console.log(list);
Marijn Haverbeke commented
There is no tsx
dialect, so the parser tries to parse this as plain JavaScript. Use dialect: "ts jsx"
.
Masashi Kawamura commented
oh i missed that, thank you!