Skip to content

Commit 4ad3010

Browse files
committed
fix: allow automatic semicolons where binary operators are valid
1 parent 7b4275d commit 4ad3010

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

‎common/scanner.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ static bool scan_automatic_semicolon(TSLexer *lexer, const bool *valid_symbols,
9595
skip(lexer);
9696
} while (iswspace(lexer->lookahead));
9797
if (lexer->lookahead == ':') {
98-
return false;
98+
return valid_symbols[LOGICAL_OR]; // Don't return false if we're in a ternary by checking if || is valid
9999
}
100100
return true;
101101
}

‎test/corpus/expressions.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,3 +405,22 @@ Type arguments in JSX
405405
(jsx_opening_element)
406406
(jsx_text)
407407
(jsx_closing_element))))
408+
409+
==================================
410+
Ternary expression
411+
==================================
412+
413+
a ? function(){ return true } : b;
414+
415+
---
416+
417+
(program
418+
(expression_statement
419+
(ternary_expression
420+
(identifier)
421+
(function_expression
422+
(formal_parameters)
423+
(statement_block
424+
(return_statement
425+
(true))))
426+
(identifier))))

0 commit comments

Comments
 (0)
close