Skip to content

Commit 0f20583

Browse files
committed
fix(fe): don't treat '<A & B>expr' as a JSX element
1 parent 970c4d5 commit 0f20583

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

docs/CHANGELOG.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ Semantic Versioning.
7676
* `interface I { get: any; }` (field named `get` with a type annotation) no
7777
longer reports [E0054][] ("unexpected token"). (Implemented by [Rui
7878
Serra][].)
79-
* In type assertions, certain types (array types, generic arrow types, and
80-
type references with a namespace) such as in `<string[]>expr` and
79+
* In type assertions, certain types such as in `<string[]>expr` and
8180
`< <T>() => RT>expr`, are no longer incorrectly interpreted as JSX.
8281

8382
## 2.18.0 (2023-11-03)

src/quick-lint-js/fe/parse-expression.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3600,6 +3600,7 @@ Expression* Parser::parse_jsx_or_typescript_generic_expression(
36003600

36013601
// <T | U>expr // Type assertion.
36023602
// <T[]>expr // Type assertion.
3603+
case Token_Type::ampersand:
36033604
case Token_Type::left_square:
36043605
case Token_Type::pipe:
36053606
this->lexer_.roll_back_transaction(std::move(transaction));
@@ -4110,6 +4111,7 @@ Expression* Parser::parse_typescript_angle_type_assertion_expression(
41104111
// <T | U>expr
41114112
// <T[]>expr
41124113
// <ns.T>expr
4114+
case Token_Type::ampersand:
41134115
case Token_Type::dot:
41144116
case Token_Type::left_square:
41154117
case Token_Type::pipe:

test/test-parse-typescript-angle-type-assertion.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,18 @@ TEST_F(Test_Parse_TypeScript_Angle_Type_Assertion, angle_type_assertion) {
8888
ElementsAreArray({u8"Type1", u8"Type2", u8"expr"}));
8989
}
9090

91+
{
92+
Spy_Visitor p = test_parse_and_visit_statement(
93+
u8"<Type1 & Type2>(expr);"_sv, no_diags, typescript_options);
94+
EXPECT_THAT(p.visits, ElementsAreArray({
95+
"visit_variable_type_use", // Type1
96+
"visit_variable_type_use", // Type2
97+
"visit_variable_use", // expr
98+
}));
99+
EXPECT_THAT(p.variable_uses,
100+
ElementsAreArray({u8"Type1", u8"Type2", u8"expr"}));
101+
}
102+
91103
for (String8_View code : {
92104
u8"<Type>(expr);"_sv,
93105
u8"<(Type)>(expr);"_sv,

0 commit comments

Comments
 (0)