From 030a70fd382c82f033eab049aa57c5ccebdf23d1 Mon Sep 17 00:00:00 2001 From: Benjamin Tan Date: Wed, 11 Jan 2017 22:47:22 +0800 Subject: [PATCH] Fix misprinting of directives. Closes #29. --- src/printer.js | 2 +- tests/prettier/__snapshots__/jsfmt.spec.js.snap | 14 ++++++++++++++ tests/prettier/directives.js | 5 +++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 tests/prettier/directives.js diff --git a/src/printer.js b/src/printer.js index 0bba17879..e87b08a37 100644 --- a/src/printer.js +++ b/src/printer.js @@ -522,7 +522,7 @@ function genericPrintNoParens(path, options, print) { parts.push( indent( options.tabWidth, - concat([ line, print(childPath), ";", line ]) + concat([ hardline, print(childPath), ";", hardline ]) ) ); }, diff --git a/tests/prettier/__snapshots__/jsfmt.spec.js.snap b/tests/prettier/__snapshots__/jsfmt.spec.js.snap index a1221a5a1..eabfb3c56 100644 --- a/tests/prettier/__snapshots__/jsfmt.spec.js.snap +++ b/tests/prettier/__snapshots__/jsfmt.spec.js.snap @@ -1,3 +1,17 @@ +exports[`test directives.js 1`] = ` +"\"use strict\"; + +function fn() { + \"use strict\"; +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +\"use strict\"; + +function fn() { + \"use strict\"; +}" +`; + exports[`test optional-type-name.js 1`] = ` "type Foo = (any) => string diff --git a/tests/prettier/directives.js b/tests/prettier/directives.js new file mode 100644 index 000000000..777ed217c --- /dev/null +++ b/tests/prettier/directives.js @@ -0,0 +1,5 @@ +"use strict"; + +function fn() { + "use strict"; +}