diff --git a/src/printer.js b/src/printer.js index 25a5440f..0f18e077 100644 --- a/src/printer.js +++ b/src/printer.js @@ -3428,7 +3428,7 @@ function isFirstStatement(path) { function isLastStatement(path) { const parent = path.getParentNode(); const node = path.getValue(); - const body = parent.body; + const body = parent.body.filter(stmt => stmt.type !== "EmptyStatement"); return body && body[body.length - 1] === node; } diff --git a/tests/empty_statement/__snapshots__/jsfmt.spec.js.snap b/tests/empty_statement/__snapshots__/jsfmt.spec.js.snap index fd88f42c..161db24f 100644 --- a/tests/empty_statement/__snapshots__/jsfmt.spec.js.snap +++ b/tests/empty_statement/__snapshots__/jsfmt.spec.js.snap @@ -21,3 +21,17 @@ do; while (1); `; + +exports[`no-newline.js 1`] = ` +if (a) { + b; + + + ; +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +if (a) { + b; +} + +`; diff --git a/tests/empty_statement/no-newline.js b/tests/empty_statement/no-newline.js new file mode 100644 index 00000000..93c8e9bf --- /dev/null +++ b/tests/empty_statement/no-newline.js @@ -0,0 +1,6 @@ +if (a) { + b; + + + ; +}