Skip to content

Commit

Permalink
fix(fe): parse decorators on abstract classes
Browse files Browse the repository at this point in the history
  • Loading branch information
strager committed Jan 25, 2024
1 parent 8bfbd10 commit 7796545
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Semantic Versioning.
* VS Code: You can now make quick-lint-js messages fun and insulting with the
`quick-lint-js.snarky` setting (disabled by default). (Implemented by
[vegerot][].)
* TypeScript: Decorators on abstract classes are now parsed. ([#1194][])

### Fixed

Expand Down Expand Up @@ -1415,6 +1416,7 @@ Beta release.
[#1168]: https://github.com/quick-lint/quick-lint-js/pull/1168
[#1171]: https://github.com/quick-lint/quick-lint-js/issues/1171
[#1180]: https://github.com/quick-lint/quick-lint-js/issues/1180
[#1194]: https://github.com/quick-lint/quick-lint-js/issues/1194

[E0001]: https://quick-lint-js.com/errors/E0001/
[E0003]: https://quick-lint-js.com/errors/E0003/
Expand Down
14 changes: 14 additions & 0 deletions src/quick-lint-js/fe/parse-class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@
namespace quick_lint_js {
void Parser::parse_and_visit_class(Parse_Visitor_Base &v,
Parse_Class_Options options) {
if (this->peek().type == Token_Type::kw_abstract) {
if (options.abstract_keyword_span.has_value()) {
// abstract abstract class???
QLJS_PARSER_UNIMPLEMENTED();
}
options.abstract_keyword_span = this->peek().span();
this->skip();
if (this->peek().has_leading_newline) {
this->diag_reporter_->report(
Diag_Newline_Not_Allowed_After_Abstract_Keyword{
.abstract_keyword = *options.abstract_keyword_span,
});
}
}
QLJS_ASSERT(this->peek().type == Token_Type::kw_class);
Source_Code_Span class_keyword_span = this->peek().span();

Expand Down
1 change: 1 addition & 0 deletions src/quick-lint-js/fe/parse-statement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2999,6 +2999,7 @@ void Parser::parse_and_visit_decorator_statement(Parse_Visitor_Base &v) {
this->parse_and_visit_one_or_more_decorators(decorator_visits.visitor());

switch (this->peek().type) {
case Token_Type::kw_abstract:
case Token_Type::kw_class:
this->parse_and_visit_class(
v, Parse_Class_Options{
Expand Down
11 changes: 11 additions & 0 deletions test/test-parse-decorator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,17 @@ TEST_F(Test_Parse_Decorator,
typescript_options);
}

TEST_F(Test_Parse_Decorator, decorator_on_typescript_abstract_class) {
test_parse_and_visit_module(
u8"@decorator abstract class C { abstract m(); }"_sv, no_diags,
typescript_options);

test_parse_and_visit_module(
u8"@decorator abstract\nclass C { abstract m(); }"_sv, //
u8" ^^^^^^^^ Diag_Newline_Not_Allowed_After_Abstract_Keyword.abstract_keyword"_diag,
typescript_options);
}

TEST_F(Test_Parse_Decorator, typescript_parameter_decorator) {
{
Spy_Visitor p = test_parse_and_visit_statement(
Expand Down

0 comments on commit 7796545

Please sign in to comment.