From 0f205833e1f1e1854bbb3cab36d695006e38ce27 Mon Sep 17 00:00:00 2001 From: "Matthew \"strager\" Glazar" Date: Tue, 19 Dec 2023 20:10:55 -0500 Subject: [PATCH] fix(fe): don't treat 'expr' as a JSX element --- docs/CHANGELOG.md | 3 +-- src/quick-lint-js/fe/parse-expression.cpp | 2 ++ test/test-parse-typescript-angle-type-assertion.cpp | 12 ++++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 10b9ef8001..eb78fc0522 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -76,8 +76,7 @@ Semantic Versioning. * `interface I { get: any; }` (field named `get` with a type annotation) no longer reports [E0054][] ("unexpected token"). (Implemented by [Rui Serra][].) - * In type assertions, certain types (array types, generic arrow types, and - type references with a namespace) such as in `expr` and + * In type assertions, certain types such as in `expr` and `< () => RT>expr`, are no longer incorrectly interpreted as JSX. ## 2.18.0 (2023-11-03) diff --git a/src/quick-lint-js/fe/parse-expression.cpp b/src/quick-lint-js/fe/parse-expression.cpp index 377b13ea5e..e1b276c063 100644 --- a/src/quick-lint-js/fe/parse-expression.cpp +++ b/src/quick-lint-js/fe/parse-expression.cpp @@ -3600,6 +3600,7 @@ Expression* Parser::parse_jsx_or_typescript_generic_expression( // expr // Type assertion. // expr // Type assertion. + case Token_Type::ampersand: case Token_Type::left_square: case Token_Type::pipe: this->lexer_.roll_back_transaction(std::move(transaction)); @@ -4110,6 +4111,7 @@ Expression* Parser::parse_typescript_angle_type_assertion_expression( // expr // expr // expr + case Token_Type::ampersand: case Token_Type::dot: case Token_Type::left_square: case Token_Type::pipe: diff --git a/test/test-parse-typescript-angle-type-assertion.cpp b/test/test-parse-typescript-angle-type-assertion.cpp index 15b97043ef..bcea78d9f0 100644 --- a/test/test-parse-typescript-angle-type-assertion.cpp +++ b/test/test-parse-typescript-angle-type-assertion.cpp @@ -88,6 +88,18 @@ TEST_F(Test_Parse_TypeScript_Angle_Type_Assertion, angle_type_assertion) { ElementsAreArray({u8"Type1", u8"Type2", u8"expr"})); } + { + Spy_Visitor p = test_parse_and_visit_statement( + u8"(expr);"_sv, no_diags, typescript_options); + EXPECT_THAT(p.visits, ElementsAreArray({ + "visit_variable_type_use", // Type1 + "visit_variable_type_use", // Type2 + "visit_variable_use", // expr + })); + EXPECT_THAT(p.variable_uses, + ElementsAreArray({u8"Type1", u8"Type2", u8"expr"})); + } + for (String8_View code : { u8"(expr);"_sv, u8"<(Type)>(expr);"_sv,