From 9ee71422273691e5734c9759e13ff2075625a739 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 25 Mar 2020 09:51:54 +0100 Subject: [PATCH] LibJS: Fix parsing of `if (typeof "foo" === "string")` Move parsing of unary expressions into the primary expression parsing step so that `typeof` takes precedence over `===` in the above example. --- Libraries/LibJS/Parser.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Libraries/LibJS/Parser.cpp b/Libraries/LibJS/Parser.cpp index 7b1769ac4a..379b8a1038 100644 --- a/Libraries/LibJS/Parser.cpp +++ b/Libraries/LibJS/Parser.cpp @@ -216,6 +216,9 @@ NonnullRefPtr Parser::parse_statement() NonnullRefPtr Parser::parse_primary_expression() { + if (match_unary_prefixed_expression()) + return parse_unary_prefixed_expression(); + switch (m_current_token.type()) { case TokenType::ParenOpen: { consume(TokenType::ParenOpen); @@ -320,9 +323,6 @@ NonnullRefPtr Parser::parse_array_expression() NonnullRefPtr Parser::parse_expression(int min_precedence, Associativity associativity) { - if (match_unary_prefixed_expression()) - return parse_unary_prefixed_expression(); - auto expression = parse_primary_expression(); while (match_secondary_expression()) { int new_precedence = operator_precedence(m_current_token.type());