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

View File

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

View File

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