Repository: lingui/js-lingui
Pull request #1035 (2021-04-08 18:40:31)

fix: unicode chars were extracting with double slashes
Re-fixes the unicode error we found migrating the passCulture application to v3.

I went for a walk and start to think about this and saw that we weren't extracting correctly the unicodes.

`\\unicode` is not correct => `\unicode`this is correct 

**probably with this adjustment we fix the wrong behaviour when we built the application to production**

About the string failing in development about not being processed as a string, we'll see tomorrow debuggin the node_modules which is the root cause 

![https://media0.giphy.com/media/LmNwrBhejkK9EFP504/200.gif](https://media0.giphy.com/media/LmNwrBhejkK9EFP504/200.gif)

#1022 

vercel[bot]: This pull request is being automatically deployed with Vercel ([learn more](https://vercel.link/github-learn-more)).  
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: [https://vercel.com/lingui-js/js-lingui/De3JPP6YZa39dTnF2WTo3Q6ZUxTJ](https://vercel.com/lingui-js/js-lingui/De3JPP6YZa39dTnF2WTo3Q6ZUxTJ)  
✅ Preview: [https://js-lingui-git-fix-lingui-js.vercel.app](https://js-lingui-git-fix-lingui-js.vercel.app)


github-actions[bot]: ## size-limit report 📦 
| Path                                                               | Size         |
| ------------------------------------------------------------------ | ------------ |
| ./packages/core/build/cjs/core.production.min.js                   | 2.73 KB (0%) |
| ./packages/detect-locale/build/cjs/detect-locale.production.min.js | 798 B (0%)   |
| ./packages/react/build/cjs/react.production.min.js                 | 4.85 KB (0%) |
codecov[bot]: # [Codecov](https://codecov.io/gh/lingui/js-lingui/pull/1035?src=pr&el=h1) Report
> Merging [#1035](https://codecov.io/gh/lingui/js-lingui/pull/1035?src=pr&el=desc) (5ab3b12) into [main](https://codecov.io/gh/lingui/js-lingui/commit/9b2705feada95f5272346bacee54a26b5518af5e?el=desc) (9b2705f) will **not change** coverage.
> The diff coverage is `66.66%`.

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

```diff
@@           Coverage Diff           @@
##             main    #1035   +/-   ##
=======================================
  Coverage   83.21%   83.21%           
=======================================
  Files          53       53           
  Lines        1626     1626           
  Branches      441      441           
=======================================
  Hits         1353     1353           
  Misses        158      158           
  Partials      115      115           
```


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

------

[Continue to review full report at Codecov](https://codecov.io/gh/lingui/js-lingui/pull/1035?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/1035?src=pr&el=footer). Last update [9b2705f...5ab3b12](https://codecov.io/gh/lingui/js-lingui/pull/1035?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/packages/macro/src/macroJs.ts b/packages/macro/src/macroJs.ts
index 6b1e61e9..b394b86a 100644
--- a/packages/macro/src/macroJs.ts
+++ b/packages/macro/src/macroJs.ts
@@ -361,7 +361,7 @@ export default class MacroJs {
    */
   clearBackslashes(value: string) {
     // it's an unicode char so we should keep them
-    if (value.includes('\\u')) return value
+    if (value.includes('\\u')) return value.replace(removeExtraScapedLiterals, "\/u")
     // if not we replace the extra scaped literals
     return value.replace(removeExtraScapedLiterals, "`")
   }
diff --git a/packages/macro/src/macroJsx.ts b/packages/macro/src/macroJsx.ts
index d7c93730..085b8057 100644
--- a/packages/macro/src/macroJsx.ts
+++ b/packages/macro/src/macroJsx.ts
@@ -7,7 +7,7 @@ import { zip, makeCounter } from "./utils"
 import { ID, COMMENT, MESSAGE } from "./constants"
 
 const pluralRuleRe = /(_[\d\w]+|zero|one|two|few|many|other)/
-const removeExtraScapedLiterals = /(?:\\(.))/
+const removeExtraScapedLiterals = /(?:\\(.))/g
 const jsx2icuExactChoice = (value) =>
   value.replace(/_(\d+)/, "=$1").replace(/_(\w+)/, "$1")
 
@@ -365,7 +365,7 @@ export default class MacroJSX {
    * */
   clearBackslashes(value: string) {
     // it's an unicode char so we should keep them
-    if (value.includes('\\u')) return value
+    if (value.includes('\\u')) return value.replace(removeExtraScapedLiterals, "\/u")
     // if not we replace the extra scaped literals
     return value.replace(removeExtraScapedLiterals, "`")
   }


Test patch:
diff --git a/packages/macro/src/macroJs.test.ts b/packages/macro/src/macroJs.test.ts
index 4e70dfc9..fce4a902 100644
--- a/packages/macro/src/macroJs.test.ts
+++ b/packages/macro/src/macroJs.test.ts
@@ -87,7 +87,7 @@ describe("js macro", () => {
       expect(tokens).toEqual([
         {
           type: "text",
-          value: 'Message \\u0020',
+          value: 'Message \/u0020',
         },
       ])
     })