From e0333264457baf8a231982a2b58841d97d463518 Mon Sep 17 00:00:00 2001 From: Alex Rattray Date: Wed, 11 Jan 2017 15:35:51 -0800 Subject: [PATCH] JSX maintains spaces that matter (fixes #30 and thus part of #73) --- src/printer.js | 2 +- tests/prettier/__snapshots__/jsfmt.spec.js.snap | 15 +++++++++++++-- tests/prettier/jsx-significant-space.js | 3 +++ 3 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 tests/prettier/jsx-significant-space.js diff --git a/src/printer.js b/src/printer.js index b9e237948bb2..0457538fbf29 100644 --- a/src/printer.js +++ b/src/printer.js @@ -1971,7 +1971,7 @@ function printJSXElement(path, options, print) { children.push( beginBreak ? hardline : "", - child.value.replace(/^\s+|\s+$/g, ""), + child.value.replace(/^\s+|\s+$/g, endBreak ? "" : " "), endBreak ? hardline : "" ); } else if (/\n/.test(child.value)) { diff --git a/tests/prettier/__snapshots__/jsfmt.spec.js.snap b/tests/prettier/__snapshots__/jsfmt.spec.js.snap index 0240a50f8a82..441a9fcb1625 100644 --- a/tests/prettier/__snapshots__/jsfmt.spec.js.snap +++ b/tests/prettier/__snapshots__/jsfmt.spec.js.snap @@ -60,13 +60,24 @@ const comp4 = (
Create wrapping parens and indentall the things.
+ >Create wrapping parens and indent all the things. ); const comp5 =
Keep it on one line.
; " `; +exports[`test jsx-significant-space.js 1`] = ` +" + foo bar + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + foo bar +; +" +`; + exports[`test jsx-split-attrs.js 1`] = ` "long_closed = @@ -155,7 +166,7 @@ const render4 = ({ styles }) => (
Create wrapping parens and indentall the things.
+ >Create wrapping parens and indent all the things. ); const render5 = ({ styles }) =>
Keep it on one line.
; diff --git a/tests/prettier/jsx-significant-space.js b/tests/prettier/jsx-significant-space.js new file mode 100644 index 000000000000..7b80d6ce7504 --- /dev/null +++ b/tests/prettier/jsx-significant-space.js @@ -0,0 +1,3 @@ + + foo bar +