Skip to content

Commit 697da58

Browse files
authored
fix: braces in blocks with conditional braces should not be removed when containing a single empty statement (#469)
1 parent fd164bd commit 697da58

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/generation/generate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8336,7 +8336,7 @@ fn gen_conditional_brace_body<'a>(opts: GenConditionalBraceBodyOptions<'a>, cont
83368336

83378337
fn get_force_braces(body_node: Node) -> bool {
83388338
if let Node::BlockStmt(body_node) = body_node {
8339-
body_node.stmts.is_empty()
8339+
body_node.stmts.is_empty() || body_node.stmts.iter().all(|s| s.kind() == NodeKind::EmptyStmt)
83408340
} else {
83418341
false
83428342
}

tests/specs/issues/issue0468.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
== should not remove the braces in an if/while statement when the body contains empty statements ==
2+
if (true) {;}
3+
while (true) {;}
4+
5+
// these going multi-line is ok... nobody should be writing this
6+
// and fixing it just adds more complexity
7+
if (true) {;;}
8+
while (true) {;;}
9+
10+
[expect]
11+
if (true) {}
12+
while (true) {}
13+
14+
// these going multi-line is ok... nobody should be writing this
15+
// and fixing it just adds more complexity
16+
if (true) {
17+
}
18+
while (true) {
19+
}

0 commit comments

Comments
 (0)