Skip to content

Commit ae792da

Browse files
committed
feat(typescript): parse 'declare namespace ns { import a = b; }'
1 parent 49ee834 commit ae792da

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2136,6 +2136,7 @@ void parser::parse_and_visit_typescript_declare_namespace(
21362136
case token_type::kw_const:
21372137
case token_type::kw_enum:
21382138
case token_type::kw_function:
2139+
case token_type::kw_import:
21392140
case token_type::kw_let:
21402141
case token_type::kw_module:
21412142
case token_type::kw_namespace:
@@ -4813,6 +4814,11 @@ void parser::parse_and_visit_declare_statement(
48134814
this->parse_and_visit_typescript_declare_namespace(v, declare_keyword_span);
48144815
break;
48154816

4817+
// declare namespace ns { import a = b; }
4818+
case token_type::kw_import:
4819+
this->parse_and_visit_import(v);
4820+
break;
4821+
48164822
// declare: // Label.
48174823
// declare();
48184824
case token_type::colon:

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,23 @@ TEST_F(test_parse_typescript_declare_namespace,
480480
}
481481
}
482482

483+
TEST_F(test_parse_typescript_declare_namespace,
484+
declare_namespace_allows_namespace_alias) {
485+
{
486+
test_parser p(u8"declare namespace ns { import a = b; }"_sv,
487+
typescript_options);
488+
p.parse_and_visit_module();
489+
EXPECT_THAT(p.visits, ElementsAreArray({
490+
"visit_variable_declaration", // ns
491+
"visit_enter_namespace_scope", // {
492+
"visit_variable_declaration", // a
493+
"visit_variable_namespace_use", // b
494+
"visit_exit_namespace_scope", // }
495+
"visit_end_of_module", //
496+
}));
497+
}
498+
}
499+
483500
TEST_F(test_parse_typescript_declare_namespace,
484501
enum_inside_declare_namespace_acts_like_declare_enum) {
485502
{

0 commit comments

Comments
 (0)