Ignore empty statement in switch newline detection (#1220)

Fixes #1200
master
Christopher Chedeau 2017-04-12 17:26:31 -07:00 committed by GitHub
parent 3a7559be58
commit ee7cfa9501
3 changed files with 30 additions and 6 deletions

View File

@ -1189,12 +1189,17 @@ function genericPrintNoParens(path, options, print, args) {
const cons = path.call(consequentPath => {
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 : ""]);
})
consequentPath
.map((p, i) => {
if (n.consequent[i].type === "EmptyStatement") {
return null;
}
const shouldAddLine =
i !== n.consequent.length - 1 &&
util.isNextLineEmpty(options.originalText, p.getValue());
return concat([print(p), shouldAddLine ? hardline : ""]);
})
.filter(e => e !== null)
);
}, "consequent");
parts.push(

View File

@ -48,6 +48,12 @@ switch (x) {
break;
}
switch (a) {
case b:
if (1) {};
c;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
switch (foo) {
case "bar":
@ -93,6 +99,13 @@ switch (x) {
break;
}
switch (a) {
case b:
if (1) {
}
c;
}
`;
exports[`empty_switch.js 1`] = `

View File

@ -45,3 +45,9 @@ switch (x) {
break;
}
switch (a) {
case b:
if (1) {};
c;
}