bug: missing semicolon in ternary consequence function expression
Sec-ant opened this issue · comments
Ze-Zheng Wu commented
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.22.6
Describe the bug
When a function expression without a trailing semicolon in its return statement is directly placed as the consequence of a ternary expression. The parse tree will report MISSING ;
under the return_statement
.
However, if the function expression is wrapped in a pair of parentheses, or if it is placed outside of the consequence, the return_statement
node will not report MISSING ;
.
Steps To Reproduce/Bad Parse Tree
(program [0, 0] - [4, 37]
(expression_statement [0, 0] - [0, 34]
(ternary_expression [0, 0] - [0, 33]
condition: (identifier [0, 0] - [0, 1])
consequence: (function_expression [0, 4] - [0, 29]
parameters: (formal_parameters [0, 12] - [0, 14])
body: (statement_block [0, 14] - [0, 29]
(return_statement [0, 16] - [0, 27]
(true [0, 23] - [0, 27]))))
alternative: (identifier [0, 32] - [0, 33])))
(expression_statement [2, 0] - [2, 36]
(ternary_expression [2, 0] - [2, 35]
condition: (identifier [2, 0] - [2, 1])
consequence: (parenthesized_expression [2, 4] - [2, 31]
(function_expression [2, 5] - [2, 30]
parameters: (formal_parameters [2, 13] - [2, 15])
body: (statement_block [2, 15] - [2, 30]
(return_statement [2, 17] - [2, 28]
(true [2, 24] - [2, 28])))))
alternative: (identifier [2, 34] - [2, 35])))
(lexical_declaration [4, 0] - [4, 37]
(variable_declarator [4, 6] - [4, 36]
name: (identifier [4, 6] - [4, 7])
value: (function_expression [4, 10] - [4, 36]
parameters: (formal_parameters [4, 18] - [4, 20])
body: (statement_block [4, 21] - [4, 36]
(return_statement [4, 23] - [4, 34]
(true [4, 30] - [4, 34])))))))
test.js 0.15 ms 722 bytes/ms (MISSING ";" [0, 27] - [0, 27])
Expected Behavior/Parse Tree
It shouldn't report MISSING ;
.
Repro
a ? function(){ return true } : b;
a ? (function(){ return true }) : b;
const a = function() { return true };
Ze-Zheng Wu commented
Wow thank you so much for this quick fix! ❤️ @amaanq