Skip to content

Commit 3f27884

Browse files
committed
Refactor: move { } parsing into parse_and_visit_class_body
Reduce some duplication between statement parsing and expression parsing for classes. This commit should not change behavior.
1 parent cc01a89 commit 3f27884

File tree

2 files changed

+8
-14
lines changed

2 files changed

+8
-14
lines changed

src/quick-lint-js/parse-expression-inl.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2482,22 +2482,15 @@ expression* parser::parse_class_expression(Visitor& v) {
24822482
this->parse_and_visit_class_heading(
24832483
v, /*require_name=*/name_requirement::optional);
24842484

2485-
const char8* span_end;
24862485
if (this->peek().type == token_type::left_curly) {
2487-
this->skip();
2488-
24892486
this->parse_and_visit_class_body(v);
2490-
2491-
QLJS_PARSER_UNIMPLEMENTED_IF_NOT_TOKEN(token_type::right_curly);
2492-
span_end = this->peek().end;
2493-
this->skip();
24942487
} else {
2495-
span_end = this->lexer_.end_of_previous_token();
24962488
this->error_reporter_->report(error_missing_body_for_class{
24972489
.class_keyword_and_name_and_heritage =
2498-
source_code_span(span_begin, span_end),
2490+
source_code_span(span_begin, this->lexer_.end_of_previous_token()),
24992491
});
25002492
}
2493+
const char8* span_end = this->lexer_.end_of_previous_token();
25012494

25022495
v.visit_exit_class_scope();
25032496
return this->make_expression<expression::_class>(

src/quick-lint-js/parse-statement-inl.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,14 +1101,9 @@ void parser::parse_and_visit_class(Visitor &v,
11011101

11021102
switch (this->peek().type) {
11031103
case token_type::left_curly:
1104-
this->skip();
1105-
11061104
v.visit_enter_class_scope();
11071105
this->parse_and_visit_class_body(v);
11081106
v.visit_exit_class_scope();
1109-
1110-
QLJS_PARSER_UNIMPLEMENTED_IF_NOT_TOKEN(token_type::right_curly);
1111-
this->skip();
11121107
break;
11131108

11141109
default: {
@@ -1202,9 +1197,15 @@ void parser::parse_and_visit_class_heading(
12021197
template <QLJS_PARSE_VISITOR Visitor>
12031198
void parser::parse_and_visit_class_body(Visitor &v) {
12041199
class_guard g(this, std::exchange(this->in_class_, true));
1200+
1201+
this->skip();
1202+
12051203
while (this->peek().type != token_type::right_curly) {
12061204
this->parse_and_visit_class_member(v);
12071205
}
1206+
1207+
QLJS_PARSER_UNIMPLEMENTED_IF_NOT_TOKEN(token_type::right_curly);
1208+
this->skip();
12081209
}
12091210

12101211
template <QLJS_PARSE_VISITOR Visitor>

0 commit comments

Comments
 (0)