diff --git a/src/printer.js b/src/printer.js index ed59bfc7..488b021e 100644 --- a/src/printer.js +++ b/src/printer.js @@ -1193,7 +1193,11 @@ function genericPrintNoParens(path, options, print) { if (n.consequent.find(node => node.type !== "EmptyStatement")) { const cons = path.call(consequentPath => { - return join(hardline, consequentPath.map(print)); + return join(hardline, consequentPath.map((p, i) => { + const shouldAddLine = i !== n.consequent.length - 1 && + util.isNextLineEmpty(options.originalText, p.getValue()); + return concat([print(p), shouldAddLine ? hardline : ""]); + })); }, "consequent"); parts.push( isCurlyBracket(cons) diff --git a/tests/switch/__snapshots__/jsfmt.spec.js.snap b/tests/switch/__snapshots__/jsfmt.spec.js.snap index eed54119..9d65ac16 100644 --- a/tests/switch/__snapshots__/jsfmt.spec.js.snap +++ b/tests/switch/__snapshots__/jsfmt.spec.js.snap @@ -36,6 +36,18 @@ switch (foo) { case \\"baz\\": doOtherThing(); } + +switch (x) { + case y: + call(); + + break; + + case z: + call(); + + break; +} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ switch (foo) { case \\"bar\\": @@ -68,6 +80,18 @@ switch (foo) { case \\"baz\\": doOtherThing(); } + +switch (x) { + case y: + call(); + + break; + + case z: + call(); + + break; +} " `; diff --git a/tests/switch/empty_lines.js b/tests/switch/empty_lines.js index 5972dbe8..4ecca081 100644 --- a/tests/switch/empty_lines.js +++ b/tests/switch/empty_lines.js @@ -33,3 +33,15 @@ switch (foo) { case "baz": doOtherThing(); } + +switch (x) { + case y: + call(); + + break; + + case z: + call(); + + break; +}