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
parent
8cc5f22090
commit
6bff3f2de8
|
@ -1193,7 +1193,11 @@ function genericPrintNoParens(path, options, print) {
|
||||||
|
|
||||||
if (n.consequent.find(node => node.type !== "EmptyStatement")) {
|
if (n.consequent.find(node => node.type !== "EmptyStatement")) {
|
||||||
const cons = path.call(consequentPath => {
|
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");
|
}, "consequent");
|
||||||
parts.push(
|
parts.push(
|
||||||
isCurlyBracket(cons)
|
isCurlyBracket(cons)
|
||||||
|
|
|
@ -36,6 +36,18 @@ switch (foo) {
|
||||||
case \\"baz\\":
|
case \\"baz\\":
|
||||||
doOtherThing();
|
doOtherThing();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch (x) {
|
||||||
|
case y:
|
||||||
|
call();
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case z:
|
||||||
|
call();
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
switch (foo) {
|
switch (foo) {
|
||||||
case \\"bar\\":
|
case \\"bar\\":
|
||||||
|
@ -68,6 +80,18 @@ switch (foo) {
|
||||||
case \\"baz\\":
|
case \\"baz\\":
|
||||||
doOtherThing();
|
doOtherThing();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch (x) {
|
||||||
|
case y:
|
||||||
|
call();
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case z:
|
||||||
|
call();
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
"
|
"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
|
|
@ -33,3 +33,15 @@ switch (foo) {
|
||||||
case "baz":
|
case "baz":
|
||||||
doOtherThing();
|
doOtherThing();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch (x) {
|
||||||
|
case y:
|
||||||
|
call();
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case z:
|
||||||
|
call();
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue