Skip to content

Commit

Permalink
fix(fe): allow commas after interface methods in .d.ts files
Browse files Browse the repository at this point in the history
  • Loading branch information
strager committed Jan 10, 2024
1 parent 292ecaa commit 4e6038e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
3 changes: 3 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ Semantic Versioning.
attribute; write 'className' instead"), are now only reported when 'react' is
imported and if 'preact' is not imported. This fixes false warnings in Preact
code. ([#1152][])
* Commas are now allowed after methods in interfaces in `.d.ts` files. (They
were previously only allowed in `.ts` files.) ([#1171][])

## 3.0.0 (2024-01-01)

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

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

[E0001]: https://quick-lint-js.com/errors/E0001/
[E0003]: https://quick-lint-js.com/errors/E0003/
Expand Down
14 changes: 7 additions & 7 deletions src/quick-lint-js/fe/parse-class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -888,20 +888,20 @@ void Parser::parse_and_visit_class_or_interface_member(
.is_interface_method = is_interface,
};
bool is_abstract_method = this->find_modifier(Token_Type::kw_abstract);
if (declare_keyword.has_value() ||
p->options_.typescript_definition_file) {
if (is_interface) {
v.visit_enter_function_scope();
p->parse_and_visit_interface_function_parameters_and_body_no_scope(
v, property_name_span, attributes, param_options);
v.visit_exit_function_scope();
} else if (declare_keyword.has_value() ||
p->options_.typescript_definition_file) {
p->parse_and_visit_declare_class_method_parameters_and_body(
v, property_name_span, attributes, param_options);
} else if (is_abstract_method) {
v.visit_enter_function_scope();
p->parse_and_visit_abstract_function_parameters_and_body_no_scope(
v, property_name_span, attributes, param_options);
v.visit_exit_function_scope();
} else if (is_interface) {
v.visit_enter_function_scope();
p->parse_and_visit_interface_function_parameters_and_body_no_scope(
v, property_name_span, attributes, param_options);
v.visit_exit_function_scope();
} else {
// class C { myMethod() {} }
bool is_possibly_typescript_overload = false;
Expand Down
21 changes: 21 additions & 0 deletions test/test-parse-typescript-declare-interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,27 @@ TEST_F(Test_Parse_TypeScript_Declare_Interface,
ElementsAreArray({interface_decl(u8"I"_sv)}));
}
}

TEST_F(Test_Parse_TypeScript_Declare_Interface,
commas_are_allowed_between_properties) {
{
Spy_Visitor p = test_parse_and_visit_module(
u8"declare interface I { m(), M(): T, p, P: T, }"_sv, no_diags,
typescript_options);
EXPECT_THAT(p.property_declarations,
ElementsAreArray({u8"m"_sv, u8"M"_sv, u8"p"_sv, u8"P"_sv}));
}

{
// NOTE(strager): This used to report that ',' was not allowed only in .d.ts
// files. https://github.com/quick-lint/quick-lint-js/issues/1171
Spy_Visitor p = test_parse_and_visit_module(
u8"declare interface I { m(), M(): T, p, P: T, }"_sv, no_diags,
typescript_definition_options);
EXPECT_THAT(p.property_declarations,
ElementsAreArray({u8"m"_sv, u8"M"_sv, u8"p"_sv, u8"P"_sv}));
}
}
}
}

Expand Down

0 comments on commit 4e6038e

Please sign in to comment.