From 449a12c8f0ce254f5fafb9d6641aa98290a3463a Mon Sep 17 00:00:00 2001 From: "Matthew \"strager\" Glazar" Date: Sat, 30 Dec 2023 01:27:14 -0500 Subject: [PATCH] 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. --- src/quick-lint-js/fe/parse-statement.cpp | 15 ++++++++------- test/test-parse-typescript-declare-namespace.cpp | 12 ++++++++++++ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/quick-lint-js/fe/parse-statement.cpp b/src/quick-lint-js/fe/parse-statement.cpp index 730edfa730..03c7852b92 100644 --- a/src/quick-lint-js/fe/parse-statement.cpp +++ b/src/quick-lint-js/fe/parse-statement.cpp @@ -3399,13 +3399,14 @@ void Parser::parse_and_visit_typescript_declare_block( } else { // require_declaration will cause parse_and_visit_statement to report // Diag_Declare_Namespace_Cannot_Contain_Statement. - bool parsed_statement = this->parse_and_visit_statement( - v, Parse_Statement_Options{ - .possibly_followed_by_another_statement = true, - .require_declaration = true, - .declare_keyword = declare_context.declare_keyword_span(), - }); - QLJS_ASSERT(parsed_statement); + [[maybe_unused]] bool parsed_statement = + this->parse_and_visit_statement( + v, + Parse_Statement_Options{ + .possibly_followed_by_another_statement = true, + .require_declaration = true, + .declare_keyword = declare_context.declare_keyword_span(), + }); } break; diff --git a/test/test-parse-typescript-declare-namespace.cpp b/test/test-parse-typescript-declare-namespace.cpp index 5495c3d037..d1a5bbcdbb 100644 --- a/test/test-parse-typescript-declare-namespace.cpp +++ b/test/test-parse-typescript-declare-namespace.cpp @@ -1067,6 +1067,18 @@ TEST_F(Test_Parse_TypeScript_Declare_Namespace, non_empty_namespace_decl(u8"ns"_sv))); } } + +TEST_F(Test_Parse_TypeScript_Declare_Namespace, + declare_namespace_cannot_contain_loop_label) { + test_parse_and_visit_module( + u8"declare namespace ns { label: export class C {} }"_sv, + u8" ^^^^^ Diag_Declare_Namespace_Cannot_Contain_Statement.first_statement_token"_diag, + typescript_options); + test_parse_and_visit_module( + u8"declare namespace ns { label: }"_sv, + u8" ^^^^^ Diag_Declare_Namespace_Cannot_Contain_Statement.first_statement_token"_diag, + typescript_options); +} } }