Skip to content

Commit 89af5d5

Browse files
ahmafistrager
authored andcommitted
fix span E094
Now if there is a missing body for a for loop, the error points to the end of the for loop defintion where body should start
1 parent d67e5ba commit 89af5d5

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

src/quick-lint-js/parse.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2482,9 +2482,9 @@ class parser {
24822482
bool parsed_body =
24832483
this->parse_and_visit_statement_disallowing_declaration(v);
24842484
if (!parsed_body) {
2485+
const char8 *here = this->lexer_.end_of_previous_token();
24852486
this->error_reporter_->report(error_missing_body_for_for_statement{
2486-
.for_and_header = source_code_span(
2487-
for_token_span.begin(), this->lexer_.end_of_previous_token()),
2487+
.for_and_header = source_code_span(here, here),
24882488
});
24892489
}
24902490

test/test-parse-loop.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -918,10 +918,11 @@ TEST(test_parse, for_loop_without_body) {
918918
"visit_variable_use", // myArray
919919
"visit_variable_declaration", // x
920920
"visit_exit_for_scope"));
921-
EXPECT_THAT(v.errors,
922-
ElementsAre(ERROR_TYPE_FIELD(
923-
error_missing_body_for_for_statement, for_and_header,
924-
offsets_matcher(&code, 0, u8"for (let x of myArray)"))));
921+
EXPECT_THAT(
922+
v.errors,
923+
ElementsAre(ERROR_TYPE_FIELD(
924+
error_missing_body_for_for_statement, for_and_header,
925+
offsets_matcher(&code, strlen(u8"for (let x of myArray)"), u8""))));
925926
}
926927

927928
{
@@ -938,8 +939,8 @@ TEST(test_parse, for_loop_without_body) {
938939
EXPECT_THAT(v.errors,
939940
ElementsAre(ERROR_TYPE_FIELD(
940941
error_missing_body_for_for_statement, for_and_header,
941-
offsets_matcher(&code, strlen(u8"{ "),
942-
u8"for (let x of myArray)"))));
942+
offsets_matcher(&code, strlen(u8"{ for (let x of myArray)"),
943+
u8""))));
943944
}
944945
}
945946

0 commit comments

Comments
 (0)