Skip to content

Commit a668083

Browse files
authored
Span for E064 is too much #280
changes in parse.h and test-parse-statement.cpp
1 parent f2cccdd commit a668083

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

src/quick-lint-js/error.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -572,9 +572,9 @@
572572
\
573573
QLJS_ERROR_TYPE( \
574574
error_missing_body_for_if_statement, "E064", \
575-
{ source_code_span if_and_condition; }, \
575+
{ source_code_span expected_body; }, \
576576
.error(QLJS_TRANSLATABLE("missing body for 'if' statement"), \
577-
if_and_condition)) \
577+
expected_body)) \
578578
\
579579
QLJS_ERROR_TYPE( \
580580
error_missing_body_for_switch_statement, "E106", \

src/quick-lint-js/parse.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2506,9 +2506,10 @@ class parser {
25062506
case token_type::end_of_file:
25072507
case token_type::kw_else:
25082508
case token_type::right_curly:
2509+
const char8 *end_of_if_condition = this->lexer_.end_of_previous_token();
25092510
this->error_reporter_->report(error_missing_body_for_if_statement{
2510-
.if_and_condition = source_code_span(
2511-
if_token_span.begin(), this->lexer_.end_of_previous_token()),
2511+
.expected_body =
2512+
source_code_span(end_of_if_condition, end_of_if_condition),
25122513
});
25132514
break;
25142515
}

test/test-parse-statement.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -458,8 +458,8 @@ TEST(test_parse, if_without_body) {
458458
"visit_variable_use")); // e
459459
EXPECT_THAT(v.errors,
460460
ElementsAre(ERROR_TYPE_FIELD(
461-
error_missing_body_for_if_statement, if_and_condition,
462-
offsets_matcher(&code, 0, u8"if (a)"))));
461+
error_missing_body_for_if_statement, expected_body,
462+
offsets_matcher(&code, strlen(u8"if (a)"), u8""))));
463463
}
464464

465465
{
@@ -472,8 +472,8 @@ TEST(test_parse, if_without_body) {
472472
"visit_exit_block_scope"));
473473
EXPECT_THAT(v.errors,
474474
ElementsAre(ERROR_TYPE_FIELD(
475-
error_missing_body_for_if_statement, if_and_condition,
476-
offsets_matcher(&code, strlen(u8"{\n"), u8"if (a)"))));
475+
error_missing_body_for_if_statement, expected_body,
476+
offsets_matcher(&code, strlen(u8"{\nif (a)"), u8""))));
477477
EXPECT_TRUE(p.parse_and_visit_statement(v));
478478
EXPECT_THAT(v.visits, ElementsAre("visit_enter_block_scope", //
479479
"visit_variable_use", // a
@@ -490,8 +490,8 @@ TEST(test_parse, if_without_body) {
490490
"visit_end_of_module"));
491491
EXPECT_THAT(v.errors,
492492
ElementsAre(ERROR_TYPE_FIELD(
493-
error_missing_body_for_if_statement, if_and_condition,
494-
offsets_matcher(&code, 0, u8"if (a)"))));
493+
error_missing_body_for_if_statement, expected_body,
494+
offsets_matcher(&code, strlen(u8"if (a)"), u8""))));
495495
}
496496
}
497497

0 commit comments

Comments
 (0)