From 4b7d2650008c598df2d84c5c4e439ecd1cda3ec0 Mon Sep 17 00:00:00 2001 From: Christopher Chedeau Date: Mon, 1 May 2017 14:39:03 -0700 Subject: [PATCH] Fix windows line ending on template literals (#1439) Fixes #1432 --- src/printer.js | 2 +- .../windows/__snapshots__/jsfmt.spec.js.snap | 19 +++++++++++++++++++ tests/windows/template.js | 7 +++++++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 tests/windows/template.js diff --git a/src/printer.js b/src/printer.js index 3a3f7ab5..9276c817 100644 --- a/src/printer.js +++ b/src/printer.js @@ -1513,7 +1513,7 @@ function genericPrintNoParens(path, options, print, args) { parts.push(concat(printClass(path, options, print))); return concat(parts); case "TemplateElement": - return join(literalline, n.value.raw.split("\n")); + return join(literalline, n.value.raw.split(/\r?\n/g)); case "TemplateLiteral": var expressions = path.map(print, "expressions"); diff --git a/tests/windows/__snapshots__/jsfmt.spec.js.snap b/tests/windows/__snapshots__/jsfmt.spec.js.snap index 2410a68b..13f25848 100644 --- a/tests/windows/__snapshots__/jsfmt.spec.js.snap +++ b/tests/windows/__snapshots__/jsfmt.spec.js.snap @@ -14,3 +14,22 @@ line; endings; `; + +exports[`template.js 1`] = ` +const aLongString = \` +Line 1 +Line 2 +Line 3 +Line 4 +Line 5 +\`; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +const aLongString = \` +Line 1 +Line 2 +Line 3 +Line 4 +Line 5 +\`; + +`; diff --git a/tests/windows/template.js b/tests/windows/template.js new file mode 100644 index 00000000..5b9e637a --- /dev/null +++ b/tests/windows/template.js @@ -0,0 +1,7 @@ +const aLongString = ` +Line 1 +Line 2 +Line 3 +Line 4 +Line 5 +`;