Skip to content

Commit 1ccefe0

Browse files
authored
fix(switch): inconsistent line spreading (#1256)
Fixes #1176
1 parent a071ade commit 1ccefe0

2 files changed

Lines changed: 5 additions & 14 deletions

File tree

src/printer.js

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1891,9 +1891,11 @@ function printNode(path, options, print) {
18911891
")"
18921892
]);
18931893
case "while":
1894+
case "switch":
18941895
return group(
18951896
concat([
1896-
"while (",
1897+
node.kind,
1898+
" (",
18971899
group(
18981900
concat([
18991901
indent(concat([softline, path.call(print, "test")])),
@@ -2042,18 +2044,6 @@ function printNode(path, options, print) {
20422044
printBodyControlStructure(path, options, print, "body")
20432045
]);
20442046
}
2045-
case "switch":
2046-
return concat([
2047-
group(
2048-
concat([
2049-
"switch (",
2050-
indent(concat([softline, path.call(print, "test")])),
2051-
softline,
2052-
")"
2053-
])
2054-
),
2055-
printBodyControlStructure(path, options, print, "body")
2056-
]);
20572047
case "case":
20582048
return concat([
20592049
node.test
@@ -2579,6 +2569,7 @@ function printNode(path, options, print) {
25792569
node !== parent.body &&
25802570
(parent.kind === "if" ||
25812571
parent.kind === "while" ||
2572+
parent.kind === "switch" ||
25822573
parent.kind === "do");
25832574

25842575
const parts = printBinaryExpression(

tests/switch/__snapshots__/jsfmt.spec.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ switch (
332332
333333
switch (
334334
$longLongLongLongLongLongLongVariable &&
335-
$longLongLongLongLongLongLongVariable
335+
$longLongLongLongLongLongLongVariable
336336
) {
337337
}
338338

0 commit comments

Comments
 (0)