Skip to content

Commit

Permalink
fix: allow automatic semicolons where binary operators are valid
Browse files Browse the repository at this point in the history
  • Loading branch information
amaanq committed May 16, 2024
1 parent 7b4275d commit 4ad3010
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion common/scanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ static bool scan_automatic_semicolon(TSLexer *lexer, const bool *valid_symbols,
skip(lexer);
} while (iswspace(lexer->lookahead));
if (lexer->lookahead == ':') {
return false;
return valid_symbols[LOGICAL_OR]; // Don't return false if we're in a ternary by checking if || is valid
}
return true;
}
Expand Down
19 changes: 19 additions & 0 deletions test/corpus/expressions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -405,3 +405,22 @@ Type arguments in JSX
(jsx_opening_element)
(jsx_text)
(jsx_closing_element))))

==================================
Ternary expression
==================================

a ? function(){ return true } : b;

---

(program
(expression_statement
(ternary_expression
(identifier)
(function_expression
(formal_parameters)
(statement_block
(return_statement
(true))))
(identifier))))

0 comments on commit 4ad3010

Please sign in to comment.