Ignore empty statement in switch newline detection (#1220)

Fixes #1200
This commit is contained in:
Christopher Chedeau authored and GitHub committed 2017-04-12 17:26:31 -07:00
1 parent 3a7559be58
commit ee7cfa9501
3 files changed
+30 -6

No files matched your search

+11 -6
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(
@@ -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`] = `
+6
View File
@@ -45,3 +45,9 @@ switch (x) {
break;
}
switch (a) {
case b:
if (1) {};
c;
}