Skip to content

Commit

Permalink
fix(): fix testing suite #1098
Browse files Browse the repository at this point in the history
  • Loading branch information
semoal committed Sep 6, 2021
1 parent 8bb2983 commit 1144cc7
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
1 change: 0 additions & 1 deletion packages/conf/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { GeneratorOptions } from "@babel/core";

export const UNICODE_REGEX: RegExp
export declare type CatalogFormat = "lingui" | "minimal" | "po" | "csv" | "po-gettext";
export type CatalogFormatOptions = {
origins?: boolean;
Expand Down
4 changes: 1 addition & 3 deletions packages/conf/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import fs from "fs"
import chalk from "chalk"
import { cosmiconfigSync } from "cosmiconfig"
import { multipleValidOptions, validate } from "jest-validate"
// This regex will detect if a string contains unicode chars, when they're we should interpolate them
// why? because platforms like react native doesn't parse them, just doing a JSON.parse makes them UTF-8 friendly
export const UNICODE_REGEX = /\\u[a-fA-F0-9]{4}|\\x[a-fA-F0-9]{2}/g;

export type CatalogFormat = "lingui" | "minimal" | "po" | "csv"

export type CatalogFormatOptions = {
Expand Down
5 changes: 3 additions & 2 deletions packages/macro/src/macroJs.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as R from "ramda"
import * as babelTypes from "@babel/types"
import { NodePath } from "@babel/traverse"
import { UNICODE_REGEX } from "@lingui/conf"

import ICUMessageFormat from "./icu"
import { zip, makeCounter } from "./utils"
Expand Down Expand Up @@ -266,7 +265,9 @@ export default class MacroJs {
quasis: R.map((text: babelTypes.TemplateElement) => {
// Don't output tokens without text.
// if it's an unicode we keep the cooked value because it's the parsed value by babel (without unicode chars)
const value = UNICODE_REGEX.test(text.value.raw) ? text.value.cooked : text.value.raw
// This regex will detect if a string contains unicode chars, when they're we should interpolate them
// why? because platforms like react native doesn't parse them, just doing a JSON.parse makes them UTF-8 friendly
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
if (value === "") return null

return {
Expand Down
7 changes: 4 additions & 3 deletions packages/macro/src/macroJsx.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as R from "ramda"
import * as babelTypes from "@babel/types"
import { NodePath } from "@babel/traverse"
import { UNICODE_REGEX } from "@lingui/conf"

import ICUMessageFormat from "./icu"
import { zip, makeCounter } from "./utils"
Expand Down Expand Up @@ -231,8 +230,10 @@ export default class MacroJSX {
// Don"t output tokens without text.
R.evolve({
quasis: R.map((text: babelTypes.TemplateElement) => {
// Don"t output tokens without text.
const value = UNICODE_REGEX.test(text.value.raw) ? text.value.cooked : text.value.raw
// if it's an unicode we keep the cooked value because it's the parsed value by babel (without unicode chars)
// This regex will detect if a string contains unicode chars, when they're we should interpolate them
// why? because platforms like react native doesn't parse them, just doing a JSON.parse makes them UTF-8 friendly
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
if (value === "") return null

return this.tokenizeText(this.clearBackslashes(value))
Expand Down

1 comment on commit 1144cc7

@vercel
Copy link

@vercel vercel bot commented on 1144cc7 Sep 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.