Skip to content

Commit d67e5ba

Browse files
ahmafistrager
authored andcommitted
fix span E119
Now if there is a missing body for a catch clause, the error points to the end of the catch clause defintion where body should start
1 parent 6f4f85c commit d67e5ba

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/quick-lint-js/parse.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1971,7 +1971,6 @@ class parser {
19711971

19721972
if (this->peek().type == token_type::kw_catch) {
19731973
parsed_catch = true;
1974-
source_code_span catch_token_span = this->peek().span();
19751974
this->skip();
19761975

19771976
v.visit_enter_block_scope();
@@ -2043,8 +2042,9 @@ class parser {
20432042
if (this->peek().type == token_type::left_curly) {
20442043
this->parse_and_visit_statement_block_no_scope(v);
20452044
} else {
2045+
const char8 *here = this->lexer_.end_of_previous_token();
20462046
this->error_reporter_->report(error_missing_body_for_catch_clause{
2047-
.catch_token = catch_token_span,
2047+
.catch_token = source_code_span(here, here),
20482048
});
20492049
}
20502050
v.visit_exit_block_scope();

test/test-parse-statement.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ TEST(test_parse, catch_without_body) {
350350
EXPECT_THAT(v.errors,
351351
ElementsAre(ERROR_TYPE_FIELD(
352352
error_missing_body_for_catch_clause, catch_token,
353-
offsets_matcher(&code, strlen(u8"try {} "), u8"catch"))));
353+
offsets_matcher(&code, strlen(u8"try {} catch"), u8""))));
354354
}
355355
}
356356

0 commit comments

Comments
 (0)