You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As a special case, functions and classes are exported as declarations, not expressions, and these declarations can be anonymous. This means functions will be hoisted.
I havent dug through the spec but vaguely trust MDN, also Acorn parses this as a function declaration. Misclassifying it as a function expression can leave autoformatters wanting to parenthesize this expression and likely can leave highlighters to use the wrong color.
The text was updated successfully, but these errors were encountered:
jackschu
changed the title
Default export of function declarations are misclassified as function expressions
Default export of anonymous function declaration is misclassified as function expression
Jun 17, 2024
The following piece of code is valid but it is parsed incorrectly:
Here's a link to the TypeScript Playground showing that the snippet above is valid JavaScript or TypeScript
The output of
tree-sitter parse
is the following:This example shows treesitter classifying this as a 'function_expression' when i think it should be classified as a 'function_declaration'.
This is because function declaration requires a name.
MDN mentions
I havent dug through the spec but vaguely trust MDN, also Acorn parses this as a function declaration. Misclassifying it as a function expression can leave autoformatters wanting to parenthesize this expression and likely can leave highlighters to use the wrong color.
The text was updated successfully, but these errors were encountered: