diff --git a/src/quick-lint-js/fe/parse.h b/src/quick-lint-js/fe/parse.h index f3f5f5cdb5..214d93dbbc 100644 --- a/src/quick-lint-js/fe/parse.h +++ b/src/quick-lint-js/fe/parse.h @@ -1173,7 +1173,7 @@ void Parser::parse_and_visit_parenthesized_expression( const Char8 *expression_begin = this->peek().begin; - Expression *ast = this->parse_expression(v); + Expression *ast = this->parse_expression(v, {.trailing_identifiers = true}); this->visit_expression(ast, v, Variable_Context::rhs); if constexpr (check_for_sketchy_conditions) { diff --git a/test/test-parse-statement.cpp b/test/test-parse-statement.cpp index befaa08fce..4c62f1996b 100644 --- a/test/test-parse-statement.cpp +++ b/test/test-parse-statement.cpp @@ -595,6 +595,27 @@ TEST_F(Test_Parse_Statement, if_with_else) { } } +TEST_F(Test_Parse_Statement, if_else_with_malformed_condition) { + { + Test_Parser p( + u8"if (e isntanceof DataNotLoadedError) { } else { throw e; }"_sv, + capture_diags); + p.parse_and_visit_statement(); + EXPECT_THAT(p.visits, + ElementsAreArray({"visit_variable_use", // e + "visit_variable_use", // typoed instanceof + "visit_variable_use", // DataNotLoadedError + "visit_enter_block_scope", // + "visit_exit_block_scope", // + "visit_enter_block_scope", // + "visit_variable_use", // e + "visit_exit_block_scope"})); + EXPECT_THAT( + p.errors, + ::testing::Not(::testing::Contains(DIAG_TYPE(Diag_Else_Has_No_If)))); + } +} + TEST_F(Test_Parse_Statement, if_without_body) { { Spy_Visitor p = test_parse_and_visit_statement( diff --git a/test/test-parse.cpp b/test/test-parse.cpp index 474815828e..6fe88d6b0a 100644 --- a/test/test-parse.cpp +++ b/test/test-parse.cpp @@ -320,8 +320,9 @@ TEST_F(Test_Parse, utter_garbage) { assert_diagnostics( p.code, p.errors, { - u8" ^ Diag_Expected_Parentheses_Around_If_Condition"_diag, // - u8" ^ Diag_Unexpected_Token"_diag, + u8" ^ Diag_Unexpected_Token"_diag, // : + u8" ^^^^^^^^ Diag_Unexpected_Identifier_In_Expression"_diag, // kjaslkjd + u8" ^^^^^^^^^^^ Diag_Expected_Parentheses_Around_If_Condition"_diag, // :\nkjaskljd }); } }