Preserve new lines after directives (#464)

It's annoying that the line after `"use strict";` gets eaten away on babylon. This fixes it :)

Fixes #216
This commit is contained in:
Christopher Chedeau authored and James Long committed 2017-01-25 16:26:09 -05:00
1 parent b4f1649d1a
commit 1334dbc781
4 files changed
+63

No files matched your search

+3
View File
@@ -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"
);
@@ -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\";
}
"
`;
+1
View File
@@ -1 +1,2 @@
run_spec(__dirname);
run_spec(__dirname, {parser: 'babylon'});
+7
View File
@@ -0,0 +1,7 @@
/* @flow */
"use strict";
import a from "a";
a();