Skip to content

Commit 246fd7a

Browse files
committed
fix(typescript): don't double-diagnose some statements inside 'declare namespace'
1 parent 43675c2 commit 246fd7a

File tree

2 files changed

+14
-31
lines changed

2 files changed

+14
-31
lines changed

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

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2910,37 +2910,6 @@ void Parser::parse_and_visit_typescript_declare_namespace_or_module(
29102910
case Token_Type::regexp:
29112911
QLJS_UNREACHABLE();
29122912
break;
2913-
2914-
case Token_Type::colon:
2915-
case Token_Type::dot_dot_dot:
2916-
case Token_Type::kw_case:
2917-
case Token_Type::kw_catch:
2918-
case Token_Type::kw_default:
2919-
case Token_Type::kw_else:
2920-
case Token_Type::kw_extends:
2921-
case Token_Type::kw_finally:
2922-
case Token_Type::question:
2923-
case Token_Type::question_dot:
2924-
case Token_Type::right_square: {
2925-
this->is_current_typescript_namespace_non_empty_ = true;
2926-
if (this->options_.typescript_definition_file) {
2927-
this->diag_reporter_->report(Diag_DTS_Non_Declaring_Statement{
2928-
.first_statement_token = this->peek().span(),
2929-
});
2930-
} else {
2931-
this->diag_reporter_->report(
2932-
Diag_Declare_Namespace_Cannot_Contain_Statement{
2933-
.first_statement_token = this->peek().span(),
2934-
.declare_keyword = declare_keyword_span,
2935-
});
2936-
}
2937-
bool parsed_statement = this->parse_and_visit_statement(
2938-
v, Parse_Statement_Options{
2939-
.possibly_followed_by_another_statement = true,
2940-
});
2941-
QLJS_ASSERT(parsed_statement);
2942-
break;
2943-
}
29442913
}
29452914
}
29462915
stop_parsing_body:

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,6 +1029,7 @@ TEST_F(
10291029
u8"switch (true) { default: declare namespace ns { break; } }"_sv, //
10301030
u8" ^^^^^ Diag_Invalid_Break"_diag,
10311031
typescript_options);
1032+
10321033
test_parse_and_visit_module(
10331034
u8"declare namespace ns { continue; }"_sv, //
10341035
u8" ^^^^^^^^ Diag_Invalid_Continue"_diag,
@@ -1037,6 +1038,19 @@ TEST_F(
10371038
u8"for (;;) { declare namespace ns { continue; } }"_sv, //
10381039
u8" ^^^^^^^^ Diag_Invalid_Continue"_diag,
10391040
typescript_options);
1041+
1042+
test_parse_and_visit_module(
1043+
u8"declare namespace ns { else { } }"_sv, //
1044+
u8" ^^^^ Diag_Else_Has_No_If"_diag,
1045+
typescript_options);
1046+
test_parse_and_visit_module(
1047+
u8"declare namespace ns { catch { } }"_sv, //
1048+
u8" ^^^^^ Diag_Catch_Without_Try"_diag,
1049+
typescript_options);
1050+
test_parse_and_visit_module(
1051+
u8"declare namespace ns { finally { } }"_sv, //
1052+
u8" ^^^^^^^ Diag_Finally_Without_Try"_diag,
1053+
typescript_options);
10401054
}
10411055

10421056
TEST_F(Test_Parse_TypeScript_Declare_Namespace,

0 commit comments

Comments
 (0)