summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibJS/Parser.cpp3
-rw-r--r--Userland/Libraries/LibJS/Tests/syntax/coalesce-logic-expression-mixing.js13
2 files changed, 15 insertions, 1 deletions
diff --git a/Userland/Libraries/LibJS/Parser.cpp b/Userland/Libraries/LibJS/Parser.cpp
index 6ca40d55ac..e53cfa6053 100644
--- a/Userland/Libraries/LibJS/Parser.cpp
+++ b/Userland/Libraries/LibJS/Parser.cpp
@@ -2001,6 +2001,7 @@ NonnullRefPtr<Expression const> Parser::parse_expression(int min_precedence, Ass
expression = create_ast_node<TaggedTemplateLiteral>({ m_source_code, rule_start.position(), position() }, move(expression), move(template_literal));
}
if (should_continue_parsing) {
+ auto original_forbidden = forbidden;
while (match_secondary_expression(forbidden)) {
int new_precedence = g_operator_precedence.get(m_state.current_token.type());
if (new_precedence < min_precedence)
@@ -2010,7 +2011,7 @@ NonnullRefPtr<Expression const> Parser::parse_expression(int min_precedence, Ass
check_for_invalid_object_property(expression);
Associativity new_associativity = operator_associativity(m_state.current_token.type());
- auto result = parse_secondary_expression(move(expression), new_precedence, new_associativity, forbidden);
+ auto result = parse_secondary_expression(move(expression), new_precedence, new_associativity, original_forbidden);
expression = result.expression;
forbidden = forbidden.merge(result.forbidden);
while (match(TokenType::TemplateLiteralStart) && !is<UpdateExpression>(*expression)) {
diff --git a/Userland/Libraries/LibJS/Tests/syntax/coalesce-logic-expression-mixing.js b/Userland/Libraries/LibJS/Tests/syntax/coalesce-logic-expression-mixing.js
index 303e53b85b..bde6fec38c 100644
--- a/Userland/Libraries/LibJS/Tests/syntax/coalesce-logic-expression-mixing.js
+++ b/Userland/Libraries/LibJS/Tests/syntax/coalesce-logic-expression-mixing.js
@@ -20,6 +20,19 @@ test("mixing coalescing and logical operators with parens", () => {
expect("if (0) a || (b * c) ?? d").not.toEval();
});
+test("mixing coalescing and logical operators in ternary expressions", () => {
+ expect("0 || 0 ? 0 : 0 ?? 0").toEval();
+ expect("0 ?? 0 ? 0 : 0 || 0").toEval();
+ expect("0 ? 0 || 0 : 0 ?? 0").toEval();
+ expect("0 ? 0 ?? 0 : 0 || 0").toEval();
+ expect("0 && 0 ? 0 ?? 0 : 0 || 0").toEval();
+ expect("0 ?? 0 ? 0 && 0 : 0 || 0").toEval();
+ expect("0 ?? 0 ? 0 || 0 : 0 && 0").toEval();
+ expect("0 || 0 ? 0 ?? 0 : 0 && 0").toEval();
+ expect("0 && 0 ? 0 || 0 : 0 ?? 0").toEval();
+ expect("0 || 0 ? 0 && 0 : 0 ?? 0").toEval();
+});
+
test("mixing coalescing and logical operators when 'in' isn't allowed", () => {
expect("for (a ?? b || c in a; false;);").not.toEval();
expect("for (a ?? b && c in a; false;);").not.toEval();