Skip to content

Commit

Permalink
fix(js_parser): correctly parse break statements containing keywords (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ah-yu authored Jul 12, 2024
1 parent 616a4aa commit d8a7dbc
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 5 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b
}
}
```
- Fix [#3410](https://github.com/biomejs/biome/issues/3410) by correctly parsing break statements containing keywords.
```js
out: while (true) {
break out;
}
```
Contributed by @ah-yu

## v1.8.3 (2024-06-27)

Expand Down
5 changes: 4 additions & 1 deletion crates/biome_js_parser/src/syntax/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,9 @@ fn parse_throw_statement(p: &mut JsParser) -> ParsedSyntax {
// break foo;
// }
// }
// out: while (true) {
// break out;
// }

// test_err js break_stmt
// function foo() { break; }
Expand All @@ -598,7 +601,7 @@ fn parse_break_statement(p: &mut JsParser) -> ParsedSyntax {
let start = p.cur_range();
p.expect(T![break]); // break keyword

let error = if !p.has_preceding_line_break() && p.at(T![ident]) {
let error = if !p.has_preceding_line_break() && is_at_identifier(p) {
let label_name = p.cur_text();

let error = match p.state().get_labelled_item(label_name) {
Expand Down
3 changes: 3 additions & 0 deletions crates/biome_js_parser/test_data/inline/ok/break_stmt.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ while (true) {
break foo;
}
}
out: while (true) {
break out;
}
54 changes: 50 additions & 4 deletions crates/biome_js_parser/test_data/inline/ok/break_stmt.rast
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,42 @@ JsModule {
r_curly_token: [email protected] "}" [Newline("\n")] [],
},
},
JsLabeledStatement {
label: JsLabel {
value_token: [email protected] "out" [Newline("\n")] [],
},
colon_token: [email protected] ":" [] [Whitespace(" ")],
body: JsWhileStatement {
while_token: [email protected] "while" [] [Whitespace(" ")],
l_paren_token: [email protected] "(" [] [],
test: JsBooleanLiteralExpression {
value_token: [email protected] "true" [] [],
},
r_paren_token: [email protected] ")" [] [Whitespace(" ")],
body: JsBlockStatement {
l_curly_token: [email protected] "{" [] [],
statements: JsStatementList [
JsBreakStatement {
break_token: [email protected] "break" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")],
label: JsLabel {
value_token: [email protected] "out" [] [],
},
semicolon_token: [email protected] ";" [] [],
},
],
r_curly_token: [email protected] "}" [Newline("\n")] [],
},
},
},
],
eof_token: EOF@52..53 "" [Newline("\n")] [],
eof_token: EOF@87..88 "" [Newline("\n")] [],
}

0: JS_MODULE@0..53
0: JS_MODULE@0..88
0: (empty)
1: (empty)
2: [email protected]
3: JS_MODULE_ITEM_LIST@0..52
3: JS_MODULE_ITEM_LIST@0..87
0: [email protected]
0: [email protected] "while" [] [Whitespace(" ")]
1: [email protected] "(" [] []
Expand Down Expand Up @@ -77,4 +104,23 @@ JsModule {
2: [email protected] ";" [] []
2: [email protected] "}" [Newline("\n"), Whitespace(" ")] []
2: [email protected] "}" [Newline("\n")] []
4: [email protected] "" [Newline("\n")] []
1: [email protected]
0: [email protected]
0: [email protected] "out" [Newline("\n")] []
1: [email protected] ":" [] [Whitespace(" ")]
2: [email protected]
0: [email protected] "while" [] [Whitespace(" ")]
1: [email protected] "(" [] []
2: [email protected]
0: [email protected] "true" [] []
3: [email protected] ")" [] [Whitespace(" ")]
4: [email protected]
0: [email protected] "{" [] []
1: [email protected]
0: [email protected]
0: [email protected] "break" [Newline("\n"), Whitespace(" ")] [Whitespace(" ")]
1: [email protected]
0: [email protected] "out" [] []
2: [email protected] ";" [] []
2: [email protected] "}" [Newline("\n")] []
4: [email protected] "" [Newline("\n")] []

0 comments on commit d8a7dbc

Please sign in to comment.