Skip to content

Commit 1144cc7

Browse files
committed
fix(): fix testing suite #1098
1 parent 8bb2983 commit 1144cc7

4 files changed

Lines changed: 8 additions & 9 deletions

File tree

packages/conf/index.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { GeneratorOptions } from "@babel/core";
22

3-
export const UNICODE_REGEX: RegExp
43
export declare type CatalogFormat = "lingui" | "minimal" | "po" | "csv" | "po-gettext";
54
export type CatalogFormatOptions = {
65
origins?: boolean;

packages/conf/src/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ import fs from "fs"
44
import chalk from "chalk"
55
import { cosmiconfigSync } from "cosmiconfig"
66
import { multipleValidOptions, validate } from "jest-validate"
7-
// This regex will detect if a string contains unicode chars, when they're we should interpolate them
8-
// why? because platforms like react native doesn't parse them, just doing a JSON.parse makes them UTF-8 friendly
9-
export const UNICODE_REGEX = /\\u[a-fA-F0-9]{4}|\\x[a-fA-F0-9]{2}/g;
7+
108
export type CatalogFormat = "lingui" | "minimal" | "po" | "csv"
119

1210
export type CatalogFormatOptions = {

packages/macro/src/macroJs.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as R from "ramda"
22
import * as babelTypes from "@babel/types"
33
import { NodePath } from "@babel/traverse"
4-
import { UNICODE_REGEX } from "@lingui/conf"
54

65
import ICUMessageFormat from "./icu"
76
import { zip, makeCounter } from "./utils"
@@ -266,7 +265,9 @@ export default class MacroJs {
266265
quasis: R.map((text: babelTypes.TemplateElement) => {
267266
// Don't output tokens without text.
268267
// if it's an unicode we keep the cooked value because it's the parsed value by babel (without unicode chars)
269-
const value = UNICODE_REGEX.test(text.value.raw) ? text.value.cooked : text.value.raw
268+
// This regex will detect if a string contains unicode chars, when they're we should interpolate them
269+
// why? because platforms like react native doesn't parse them, just doing a JSON.parse makes them UTF-8 friendly
270+
const value = /\\u[a-fA-F0-9]{4}|\\x[a-fA-F0-9]{2}/g.test(text.value.raw) ? text.value.cooked : text.value.raw
270271
if (value === "") return null
271272

272273
return {

packages/macro/src/macroJsx.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as R from "ramda"
22
import * as babelTypes from "@babel/types"
33
import { NodePath } from "@babel/traverse"
4-
import { UNICODE_REGEX } from "@lingui/conf"
54

65
import ICUMessageFormat from "./icu"
76
import { zip, makeCounter } from "./utils"
@@ -231,8 +230,10 @@ export default class MacroJSX {
231230
// Don"t output tokens without text.
232231
R.evolve({
233232
quasis: R.map((text: babelTypes.TemplateElement) => {
234-
// Don"t output tokens without text.
235-
const value = UNICODE_REGEX.test(text.value.raw) ? text.value.cooked : text.value.raw
233+
// if it's an unicode we keep the cooked value because it's the parsed value by babel (without unicode chars)
234+
// This regex will detect if a string contains unicode chars, when they're we should interpolate them
235+
// why? because platforms like react native doesn't parse them, just doing a JSON.parse makes them UTF-8 friendly
236+
const value = /\\u[a-fA-F0-9]{4}|\\x[a-fA-F0-9]{2}/g.test(text.value.raw) ? text.value.cooked : text.value.raw
236237
if (value === "") return null
237238

238239
return this.tokenizeText(this.clearBackslashes(value))

0 commit comments

Comments
 (0)