From 0e2bc09409f6667f846d80acc0a29e70c490546d Mon Sep 17 00:00:00 2001 From: Christopher Chedeau Date: Sun, 9 Apr 2017 16:37:54 -0700 Subject: [PATCH] Properly handle \r\n in JSXText (#1170) Fixes #1168 --- src/printer.js | 2 +- tests/jsx-newlines/__snapshots__/jsfmt.spec.js.snap | 11 +++++++++++ tests/jsx-newlines/windows.js | 3 +++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 tests/jsx-newlines/windows.js diff --git a/src/printer.js b/src/printer.js index 4d0b22b1..a3dd2b2e 100644 --- a/src/printer.js +++ b/src/printer.js @@ -2757,7 +2757,7 @@ function printJSXChildren(path, options, print, jsxWhitespace) { if (/\S/.test(value)) { // treat each line of text as its own entity - value.split(/(\n\s*)/).forEach(line => { + value.split(/(\r?\n\s*)/).forEach(line => { const newlines = line.match(/\n/g); if (newlines) { children.push(hardline); diff --git a/tests/jsx-newlines/__snapshots__/jsfmt.spec.js.snap b/tests/jsx-newlines/__snapshots__/jsfmt.spec.js.snap index 2638cada..5d95e552 100644 --- a/tests/jsx-newlines/__snapshots__/jsfmt.spec.js.snap +++ b/tests/jsx-newlines/__snapshots__/jsfmt.spec.js.snap @@ -187,3 +187,14 @@ regression_extra_newline_2 = ( ); " `; + +exports[`windows.js 1`] = ` +"
+Text +
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +
+ Text +
; +" +`; diff --git a/tests/jsx-newlines/windows.js b/tests/jsx-newlines/windows.js new file mode 100644 index 00000000..12bf628e --- /dev/null +++ b/tests/jsx-newlines/windows.js @@ -0,0 +1,3 @@ +
+Text +