diff --git a/src/printer.js b/src/printer.js index 66d071628..93aae542d 100644 --- a/src/printer.js +++ b/src/printer.js @@ -115,6 +115,9 @@ function genericPrintNoParens(path, options, print) { path.each( function(childPath) { parts.push(print(childPath), ";", hardline); + if (util.newlineExistsAfter(options.originalText, util.locEnd(childPath.getValue()))) { + parts.push(hardline); + } }, "directives" ); diff --git a/tests/directives/__snapshots__/jsfmt.spec.js.snap b/tests/directives/__snapshots__/jsfmt.spec.js.snap index f680d0532..b63c61eb4 100644 --- a/tests/directives/__snapshots__/jsfmt.spec.js.snap +++ b/tests/directives/__snapshots__/jsfmt.spec.js.snap @@ -1,3 +1,40 @@ +exports[`test newline.js 1`] = ` +"/* @flow */ + +\"use strict\"; + +import a from \"a\"; + +a(); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/* @flow */ + +\"use strict\"; + +import a from \"a\"; + +a(); +" +`; + +exports[`test newline.js 2`] = ` +"/* @flow */ + +\"use strict\"; + +import a from \"a\"; + +a(); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +/* @flow */ +\"use strict\"; + +import a from \"a\"; + +a(); +" +`; + exports[`test test.js 1`] = ` "\"use strict\"; @@ -12,3 +49,18 @@ function fn() { } " `; + +exports[`test test.js 2`] = ` +"\"use strict\"; + +function fn() { + \"use strict\"; +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +\"use strict\"; + +function fn() { + \"use strict\"; +} +" +`; diff --git a/tests/directives/jsfmt.spec.js b/tests/directives/jsfmt.spec.js index 989047bcc..d5ec770a9 100644 --- a/tests/directives/jsfmt.spec.js +++ b/tests/directives/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(__dirname); +run_spec(__dirname, {parser: 'babylon'}); diff --git a/tests/directives/newline.js b/tests/directives/newline.js new file mode 100644 index 000000000..8da10321b --- /dev/null +++ b/tests/directives/newline.js @@ -0,0 +1,7 @@ +/* @flow */ + +"use strict"; + +import a from "a"; + +a();