From d944ebf6db8c3e91c4502c187ff58b081e4f8ded Mon Sep 17 00:00:00 2001 From: Christopher Chedeau Date: Sun, 22 Jan 2017 12:33:21 -0800 Subject: [PATCH] Ignore EmptyStatement inside of switch case (#391) Fixes #378 --- src/printer.js | 2 +- tests/switch/__snapshots__/jsfmt.spec.js.snap | 9 +++++++++ tests/switch/empty_switch.js | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 tests/switch/empty_switch.js diff --git a/src/printer.js b/src/printer.js index f06decfa..6bbf18a7 100644 --- a/src/printer.js +++ b/src/printer.js @@ -977,7 +977,7 @@ function genericPrintNoParens(path, options, print) { if (n.test) parts.push("case ", path.call(print, "test"), ":"); else parts.push("default:"); - if (n.consequent.length > 0) { + if (n.consequent.find(node => node.type !== "EmptyStatement")) { const cons = path.call( function(consequentPath) { return printStatementSequence(consequentPath, options, print); diff --git a/tests/switch/__snapshots__/jsfmt.spec.js.snap b/tests/switch/__snapshots__/jsfmt.spec.js.snap index 60b9dc0f..0005e88a 100644 --- a/tests/switch/__snapshots__/jsfmt.spec.js.snap +++ b/tests/switch/__snapshots__/jsfmt.spec.js.snap @@ -1,3 +1,12 @@ +exports[`test empty_switch.js 1`] = ` +"switch (1) { default:; } +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +switch (1) { + default: +} +" +`; + exports[`test more_switch.js 1`] = ` "/* @flow */ diff --git a/tests/switch/empty_switch.js b/tests/switch/empty_switch.js new file mode 100644 index 00000000..b91bfe9d --- /dev/null +++ b/tests/switch/empty_switch.js @@ -0,0 +1 @@ +switch (1) { default:; }