Skip to content

Commit 0954818

Browse files
authored
fix: only use do/while newline behaviour when asi (#481)
1 parent 8f2cd0f commit 0954818

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

src/generation/generate.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4336,21 +4336,20 @@ fn gen_do_while_stmt<'a>(node: &'a DoWhileStmt, context: &mut Context<'a>) -> Pr
43364336
// the braces are technically optional on do while statements
43374337
let mut items = PrintItems::new();
43384338
items.push_str("do");
4339-
let open_brace_token = if let Stmt::Block(_) = node.body {
4340-
context.token_finder.get_first_open_brace_token_within(node)
4341-
} else {
4342-
None
4343-
};
43444339
items.extend(gen_brace_separator(
43454340
GenBraceSeparatorOptions {
43464341
brace_position: context.config.do_while_statement_brace_position,
4347-
open_brace_token,
4342+
open_brace_token: if let Stmt::Block(_) = node.body {
4343+
context.token_finder.get_first_open_brace_token_within(node)
4344+
} else {
4345+
None
4346+
},
43484347
start_header_lsil: None,
43494348
},
43504349
context,
43514350
));
43524351
items.extend(gen_node(node.body.into(), context));
4353-
if open_brace_token.is_some() {
4352+
if context.config.semi_colons.is_true() || matches!(node.body, Stmt::Block(_)) {
43544353
items.extend(gen_control_flow_separator(
43554354
context.config.do_while_statement_next_control_flow_position,
43564355
&node.body.range(),
@@ -4360,7 +4359,7 @@ fn gen_do_while_stmt<'a>(node: &'a DoWhileStmt, context: &mut Context<'a>) -> Pr
43604359
context,
43614360
));
43624361
} else {
4363-
// if the body is not a block, then we just always
4362+
// if ASI and the body is not a block, then we just always
43644363
// put this on the next line for simplicity for now
43654364
items.push_signal(Signal::NewLine);
43664365
}

tests/specs/statements/doWhileStatement/DoWhileStatement_All.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,13 @@ do {
5858
[expect]
5959
do {
6060
} while (true);
61+
62+
== should handle do while with an if stmt ==
63+
do if (true) {
64+
console.log(5);
65+
} while (true);
66+
67+
[expect]
68+
do if (true) {
69+
console.log(5);
70+
} while (true);

0 commit comments

Comments
 (0)