Skip to content

Commit 158256e

Browse files
committed
fix(typescript): don't double-parse for 'await <T>() => {x}'
visit_variable_use("x") occurs twice when parsing 'await <T>() => {x}'. This is bad. Fix it.
1 parent 82f50c7 commit 158256e

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

docs/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ Semantic Versioning.
168168
to make an optional type").
169169
* `class T<T> {}` no longer falsely reports [E0034][] ("redeclaration of
170170
variable").
171+
* `await <T>() => {}` no longer does confusing things.
171172

172173
## 2.18.0 (2023-11-03)
173174

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,16 +1287,15 @@ Expression* Parser::parse_await_expression(Parse_Visitor_Base& v,
12871287
Parser_Transaction transaction = this->begin_transaction();
12881288

12891289
bool parsed_ok = this->catch_fatal_parse_errors([&] {
1290-
// FIXME(#831): v should not be used here. We should use a
1291-
// buffering_visitor.
12921290
if (this->in_top_level_) {
12931291
// Try to parse the / as a regular expression literal or the < as a
12941292
// JSX element.
1295-
[[maybe_unused]] Expression* ast = this->parse_expression(v, prec);
1293+
[[maybe_unused]] Expression* ast =
1294+
this->parse_expression(Null_Visitor::instance, prec);
12961295
} else {
12971296
// Try to parse the / or < as a binary operator.
12981297
[[maybe_unused]] Expression* ast = this->parse_expression_remainder(
1299-
v,
1298+
Null_Visitor::instance,
13001299
this->make_expression<Expression::Variable>(
13011300
await_token.identifier_name(), await_token.type),
13021301
prec);

test/test-parse-typescript-generic-arrow.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,17 @@ TEST_F(Test_Parse_TypeScript_Generic_Arrow,
391391
}
392392
}
393393
}
394+
395+
TEST_F(Test_Parse_TypeScript_Generic_Arrow,
396+
generic_async_function_with_await_keyword) {
397+
{
398+
Spy_Visitor p = test_parse_and_visit_expression(
399+
u8"await <T>() => { await(myPromise); }"_sv,
400+
u8"^^^^^ Diag_Await_Followed_By_Arrow_Function.await_operator"_diag,
401+
typescript_options);
402+
EXPECT_THAT(p.variable_uses, ElementsAreArray({u8"myPromise"_sv}));
403+
}
404+
}
394405
}
395406
}
396407

0 commit comments

Comments
 (0)