Repository: lingui/js-lingui
Pull request #581 (2019-10-30 11:32:17)

Keep multiple escaped newlines in Trans

now[bot]: 
This pull request is being automatically deployed with ZEIT Now ([learn more](https://zeit.co/docs/v2/integrations/now-for-github?utm_source=automated&utm_medium=github&utm_campaign=now_bot)).
To see the status of your deployment, click on the icon next to each commit.
	
codecov[bot]: # [Codecov](https://codecov.io/gh/lingui/js-lingui/pull/581?src=pr&el=h1) Report
> Merging [#581](https://codecov.io/gh/lingui/js-lingui/pull/581?src=pr&el=desc) into [next](https://codecov.io/gh/lingui/js-lingui/commit/da35f25f6927f30d2ac3aa58e7a9df9464346ca4?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `n/a`.

[![Impacted file tree graph](https://codecov.io/gh/lingui/js-lingui/pull/581/graphs/tree.svg?width=650&token=CuJ1VD5BY5&height=150&src=pr)](https://codecov.io/gh/lingui/js-lingui/pull/581?src=pr&el=tree)

```diff
@@           Coverage Diff           @@
##             next     #581   +/-   ##
=======================================
  Coverage   85.08%   85.08%           
=======================================
  Files          38       38           
  Lines        1153     1153           
  Branches      302      302           
=======================================
  Hits          981      981           
  Misses        101      101           
  Partials       71       71
```


| [Impacted Files](https://codecov.io/gh/lingui/js-lingui/pull/581?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [packages/macro/src/macroJsx.ts](https://codecov.io/gh/lingui/js-lingui/pull/581/diff?src=pr&el=tree#diff-cGFja2FnZXMvbWFjcm8vc3JjL21hY3JvSnN4LnRz) | `91.12% <ø> (ø)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/lingui/js-lingui/pull/581?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/lingui/js-lingui/pull/581?src=pr&el=footer). Last update [da35f25...bea9741](https://codecov.io/gh/lingui/js-lingui/pull/581?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

tricoder42: Good catch, thanks!

Patch:
diff --git a/packages/macro/src/macroJsx.ts b/packages/macro/src/macroJsx.ts
index c4429859..c24d8f0e 100644
--- a/packages/macro/src/macroJsx.ts
+++ b/packages/macro/src/macroJsx.ts
@@ -21,8 +21,8 @@ function normalizeWhitespace(text) {
       .replace(stripAroundTagsRe, "$1")
       .replace(keepSpaceRe, " ")
       // keep escaped newlines
-      .replace(/\\n/, "\n")
-      .replace(/\\s/, " ")
+      .replace(/\\n/g, "\n")
+      .replace(/\\s/g, " ")
       .trim()
   )
 }


Test patch:
diff --git a/packages/macro/test/jsx-trans.ts b/packages/macro/test/jsx-trans.ts
index f5b1ab42..ed598915 100644
--- a/packages/macro/test/jsx-trans.ts
+++ b/packages/macro/test/jsx-trans.ts
@@ -239,6 +239,20 @@ export default [
         <Trans id="Keep forced\\n newlines!" />;
       `
   },
+  {
+    input: `
+        import { Trans } from "@lingui/macro";
+        <Trans>
+          Keep multiple{"\\n"}
+          forced{"\\n"}
+          newlines!
+        </Trans>
+      `,
+    expected: `
+        import { Trans } from "@lingui/react";
+        <Trans id="Keep multiple\\n forced\\n newlines!" />;
+      `
+  },
   {
     input: `
         import { t, plural, Trans } from '@lingui/macro'