Skip to content

Commit 60d7a83

Browse files
authored
fix: asi - do while - ensure separate lines (#480)
1 parent d20a346 commit 60d7a83

File tree

4 files changed

+42
-16
lines changed

4 files changed

+42
-16
lines changed

.github/workflows/ci.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
name: CI
22

3-
on: [push, pull_request]
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
push:
8+
branches:
9+
- main
10+
tags:
11+
- '*'
412

513
jobs:
614
build:

src/configuration/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ pub enum MemberSpacing {
8282
generate_str_to_from![MemberSpacing, [Maintain, "maintain"], [BlankLine, "blankLine"], [NewLine, "newLine"]];
8383

8484
/// Where to place the next control flow within a control flow statement.
85-
#[derive(Clone, PartialEq, Copy, Serialize, Deserialize)]
85+
#[derive(Debug, Clone, PartialEq, Copy, Serialize, Deserialize)]
8686
#[serde(rename_all = "camelCase")]
8787
pub enum NextControlFlowPosition {
8888
/// Maintains the next control flow being on the next line or the same line.

src/generation/generate.rs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4329,27 +4329,34 @@ fn gen_do_while_stmt<'a>(node: &'a DoWhileStmt, context: &mut Context<'a>) -> Pr
43294329
// the braces are technically optional on do while statements
43304330
let mut items = PrintItems::new();
43314331
items.push_str("do");
4332+
let open_brace_token = if let Stmt::Block(_) = node.body {
4333+
context.token_finder.get_first_open_brace_token_within(node)
4334+
} else {
4335+
None
4336+
};
43324337
items.extend(gen_brace_separator(
43334338
GenBraceSeparatorOptions {
43344339
brace_position: context.config.do_while_statement_brace_position,
4335-
open_brace_token: if let Stmt::Block(_) = node.body {
4336-
context.token_finder.get_first_open_brace_token_within(node)
4337-
} else {
4338-
None
4339-
},
4340+
open_brace_token,
43404341
start_header_lsil: None,
43414342
},
43424343
context,
43434344
));
43444345
items.extend(gen_node(node.body.into(), context));
4345-
items.extend(gen_control_flow_separator(
4346-
context.config.do_while_statement_next_control_flow_position,
4347-
&node.body.range(),
4348-
"while",
4349-
None,
4350-
None,
4351-
context,
4352-
));
4346+
if open_brace_token.is_some() {
4347+
items.extend(gen_control_flow_separator(
4348+
context.config.do_while_statement_next_control_flow_position,
4349+
&node.body.range(),
4350+
"while",
4351+
None,
4352+
None,
4353+
context,
4354+
));
4355+
} else {
4356+
// if the body is not a block, then we just always
4357+
// put this on the next line for simplicity for now
4358+
items.push_signal(Signal::NewLine);
4359+
}
43534360
items.push_str("while");
43544361
if context.config.do_while_statement_space_after_while_keyword {
43554362
items.push_str(" ");

tests/specs/issues/deno/issue017559.txt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
~~ deno: true, semiColons: asi ~~
1+
~~ deno: true, semiColons: asi, lineWidth: 40 ~~
22
== should keep semicolon on prop with generator next ==
33
class Test {
44
prop1 = 1;
@@ -16,3 +16,14 @@ class Test {
1616
*test() {
1717
}
1818
}
19+
20+
== should put while on next line when removing the semi-colon ==
21+
do action(); while (condition)
22+
do action()
23+
while (condition)
24+
25+
[expect]
26+
do action()
27+
while (condition)
28+
do action()
29+
while (condition)

0 commit comments

Comments
 (0)