Fix switch new lines (#1156)

.#1136 accidentally removed all the empty lines between statements inside of switch cases. I just brough back the logic and made sure to only use it for everything but the last line.
master
Christopher Chedeau 2017-04-10 10:50:02 -07:00 committed by GitHub
parent 8cc5f22090
commit 6bff3f2de8
3 changed files with 41 additions and 1 deletions

View File

@ -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)

View File

@ -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;
}
"
`;

View File

@ -33,3 +33,15 @@ switch (foo) {
case "baz":
doOtherThing();
}
switch (x) {
case y:
call();
break;
case z:
call();
break;
}