Skip to content

Commit 4e6038e

Browse files
committed
fix(fe): allow commas after interface methods in .d.ts files
1 parent 292ecaa commit 4e6038e

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

docs/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ Semantic Versioning.
2727
attribute; write 'className' instead"), are now only reported when 'react' is
2828
imported and if 'preact' is not imported. This fixes false warnings in Preact
2929
code. ([#1152][])
30+
* Commas are now allowed after methods in interfaces in `.d.ts` files. (They
31+
were previously only allowed in `.ts` files.) ([#1171][])
3032

3133
## 3.0.0 (2024-01-01)
3234

@@ -1385,6 +1387,7 @@ Beta release.
13851387
[wagner riffel]: https://github.com/wgrr
13861388

13871389
[#1152]: https://github.com/quick-lint/quick-lint-js/issues/1152
1390+
[#1171]: https://github.com/quick-lint/quick-lint-js/issues/1171
13881391

13891392
[E0001]: https://quick-lint-js.com/errors/E0001/
13901393
[E0003]: https://quick-lint-js.com/errors/E0003/

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -888,20 +888,20 @@ void Parser::parse_and_visit_class_or_interface_member(
888888
.is_interface_method = is_interface,
889889
};
890890
bool is_abstract_method = this->find_modifier(Token_Type::kw_abstract);
891-
if (declare_keyword.has_value() ||
892-
p->options_.typescript_definition_file) {
891+
if (is_interface) {
892+
v.visit_enter_function_scope();
893+
p->parse_and_visit_interface_function_parameters_and_body_no_scope(
894+
v, property_name_span, attributes, param_options);
895+
v.visit_exit_function_scope();
896+
} else if (declare_keyword.has_value() ||
897+
p->options_.typescript_definition_file) {
893898
p->parse_and_visit_declare_class_method_parameters_and_body(
894899
v, property_name_span, attributes, param_options);
895900
} else if (is_abstract_method) {
896901
v.visit_enter_function_scope();
897902
p->parse_and_visit_abstract_function_parameters_and_body_no_scope(
898903
v, property_name_span, attributes, param_options);
899904
v.visit_exit_function_scope();
900-
} else if (is_interface) {
901-
v.visit_enter_function_scope();
902-
p->parse_and_visit_interface_function_parameters_and_body_no_scope(
903-
v, property_name_span, attributes, param_options);
904-
v.visit_exit_function_scope();
905905
} else {
906906
// class C { myMethod() {} }
907907
bool is_possibly_typescript_overload = false;

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,27 @@ TEST_F(Test_Parse_TypeScript_Declare_Interface,
6060
ElementsAreArray({interface_decl(u8"I"_sv)}));
6161
}
6262
}
63+
64+
TEST_F(Test_Parse_TypeScript_Declare_Interface,
65+
commas_are_allowed_between_properties) {
66+
{
67+
Spy_Visitor p = test_parse_and_visit_module(
68+
u8"declare interface I { m(), M(): T, p, P: T, }"_sv, no_diags,
69+
typescript_options);
70+
EXPECT_THAT(p.property_declarations,
71+
ElementsAreArray({u8"m"_sv, u8"M"_sv, u8"p"_sv, u8"P"_sv}));
72+
}
73+
74+
{
75+
// NOTE(strager): This used to report that ',' was not allowed only in .d.ts
76+
// files. https://github.com/quick-lint/quick-lint-js/issues/1171
77+
Spy_Visitor p = test_parse_and_visit_module(
78+
u8"declare interface I { m(), M(): T, p, P: T, }"_sv, no_diags,
79+
typescript_definition_options);
80+
EXPECT_THAT(p.property_declarations,
81+
ElementsAreArray({u8"m"_sv, u8"M"_sv, u8"p"_sv, u8"P"_sv}));
82+
}
83+
}
6384
}
6485
}
6586

0 commit comments

Comments
 (0)