Skip to content

Commit 449a12c

Browse files
committed
fix(typescript): don't crash on statementless loop label in declare namespace
Parser::parse_and_visit_statement returns false for a statementless loop label, leading to an assertion failure. Remove the incorrect assertion.
1 parent 2947147 commit 449a12c

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3399,13 +3399,14 @@ void Parser::parse_and_visit_typescript_declare_block(
33993399
} else {
34003400
// require_declaration will cause parse_and_visit_statement to report
34013401
// Diag_Declare_Namespace_Cannot_Contain_Statement.
3402-
bool parsed_statement = this->parse_and_visit_statement(
3403-
v, Parse_Statement_Options{
3404-
.possibly_followed_by_another_statement = true,
3405-
.require_declaration = true,
3406-
.declare_keyword = declare_context.declare_keyword_span(),
3407-
});
3408-
QLJS_ASSERT(parsed_statement);
3402+
[[maybe_unused]] bool parsed_statement =
3403+
this->parse_and_visit_statement(
3404+
v,
3405+
Parse_Statement_Options{
3406+
.possibly_followed_by_another_statement = true,
3407+
.require_declaration = true,
3408+
.declare_keyword = declare_context.declare_keyword_span(),
3409+
});
34093410
}
34103411
break;
34113412

test/test-parse-typescript-declare-namespace.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,6 +1067,18 @@ TEST_F(Test_Parse_TypeScript_Declare_Namespace,
10671067
non_empty_namespace_decl(u8"ns"_sv)));
10681068
}
10691069
}
1070+
1071+
TEST_F(Test_Parse_TypeScript_Declare_Namespace,
1072+
declare_namespace_cannot_contain_loop_label) {
1073+
test_parse_and_visit_module(
1074+
u8"declare namespace ns { label: export class C {} }"_sv,
1075+
u8" ^^^^^ Diag_Declare_Namespace_Cannot_Contain_Statement.first_statement_token"_diag,
1076+
typescript_options);
1077+
test_parse_and_visit_module(
1078+
u8"declare namespace ns { label: }"_sv,
1079+
u8" ^^^^^ Diag_Declare_Namespace_Cannot_Contain_Statement.first_statement_token"_diag,
1080+
typescript_options);
1081+
}
10701082
}
10711083
}
10721084

0 commit comments

Comments
 (0)