File tree Expand file tree Collapse file tree 3 files changed +29
-0
lines changed Expand file tree Collapse file tree 3 files changed +29
-0
lines changed Original file line number Diff line number Diff line change 1139
1139
{ source_code_span continue_statement ; }, \
1140
1140
.error (QLJS_TRANSLATABLE ("continue can only be used inside of a loop" ), \
1141
1141
continue_statement )) \
1142
+ \
1143
+ QLJS_ERROR_TYPE ( \
1144
+ error_redundant_semicolon_after_else , "E202" , \
1145
+ { source_code_span semicolon ; }, \
1146
+ .warning (QLJS_TRANSLATABLE ("redundant semicolon after else" ), \
1147
+ semicolon )) \
1142
1148
/* END */
1143
1149
1144
1150
namespace quick_lint_js {
Original file line number Diff line number Diff line change @@ -2516,6 +2516,13 @@ class parser {
2516
2516
2517
2517
if (this ->peek ().type == token_type::kw_else) {
2518
2518
this ->skip ();
2519
+ if (this ->peek ().type == token_type::semicolon) {
2520
+ source_code_span semicolon = this ->peek ().span ();
2521
+ this ->error_reporter_ ->report (error_redundant_semicolon_after_else{
2522
+ .semicolon = source_code_span (
2523
+ semicolon.begin (), semicolon.end ()),
2524
+ });
2525
+ }
2519
2526
parse_and_visit_body ();
2520
2527
}
2521
2528
}
Original file line number Diff line number Diff line change @@ -578,6 +578,22 @@ TEST(test_parse, else_without_if) {
578
578
}
579
579
}
580
580
581
+ TEST (test_parse, else_redundant_semicolon) {
582
+ {
583
+ spy_visitor v;
584
+ padded_string code (u8" if (cond) { body; } else; { body; }" _sv);
585
+ parser p (&code, &v);
586
+ EXPECT_TRUE (p.parse_and_visit_statement (v));
587
+ EXPECT_THAT (v.visits , ElementsAre (" visit_variable_use" , // cond
588
+ " visit_enter_block_scope" , // (if)
589
+ " visit_variable_use" , // body
590
+ " visit_exit_block_scope" )); // (else)
591
+ EXPECT_THAT (v.errors , ElementsAre (ERROR_TYPE_FIELD (
592
+ error_redundant_semicolon_after_else, semicolon,
593
+ offsets_matcher (&code, strlen (u8" if (cond) { body; } else" ), u8" ;" ))));
594
+ }
595
+ }
596
+
581
597
TEST (test_parse, block_statement) {
582
598
{
583
599
spy_visitor v = parse_and_visit_statement (u8" { }" _sv);
You can’t perform that action at this time.
0 commit comments