Skip to content

Commit

Permalink
fix: unicode char was not extracting correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergio Moreno committed Apr 9, 2021
1 parent 5aa10cd commit 3653f6f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/macro/src/macroJs.test.ts
Expand Up @@ -80,14 +80,14 @@ describe("js macro", () => {
])
})

it("message with unicode chars is respected", () => {
it("message with unicode chars is interpreted by babel", () => {
const macro = createMacro()
const exp = parseExpression('t`Message \\u0020`')
const tokens = macro.tokenizeTemplateLiteral(exp)
expect(tokens).toEqual([
{
type: "text",
value: 'Message \\u0020',
value: 'Message ',
},
])
})
Expand Down
3 changes: 2 additions & 1 deletion packages/macro/src/macroJs.ts
Expand Up @@ -264,7 +264,8 @@ export default class MacroJs {
R.evolve({
quasis: R.map((text: babelTypes.TemplateElement) => {
// Don't output tokens without text.
const value = text.value.raw
// if it's an unicode we keep the cooked value because it's the parsed value by babel (without unicode chars)
const value = /\\u[a-fA-F0-9]{4}/g.test(text.value.raw) ? text.value.cooked : text.value.raw
if (value === "") return null

return {
Expand Down
2 changes: 1 addition & 1 deletion packages/macro/src/macroJsx.ts
Expand Up @@ -231,7 +231,7 @@ export default class MacroJSX {
R.evolve({
quasis: R.map((text: babelTypes.TemplateElement) => {
// Don"t output tokens without text.
const value = text.value.raw
const value = /\\u[a-fA-F0-9]{4}/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 3653f6f

@vercel
Copy link

@vercel vercel bot commented on 3653f6f Apr 9, 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.