diff --git a/packages/macro/src/macroJsx.ts b/packages/macro/src/macroJsx.ts
index bddd6547f..4d60d95af 100644
--- a/packages/macro/src/macroJsx.ts
+++ b/packages/macro/src/macroJsx.ts
@@ -52,17 +52,10 @@ export default class MacroJSX {
}
safeJsxAttribute = (name: string, value: string) => {
- // Quoted JSX attributes use XML-style escapes instead of JavaScript-style escapes.
- // This means that is invalid, but is valid.
-
- // We could consider removing this condition and always wrap in a jsxExpressionContainer.
- const attributeValue = value.includes('"')
- ? this.types.jsxExpressionContainer(this.types.stringLiteral(value))
- : this.types.stringLiteral(value)
-
+ // This handles quoted JSX attributes and html entities.
return this.types.jsxAttribute(
this.types.jsxIdentifier(name),
- attributeValue
+ this.types.jsxExpressionContainer(this.types.stringLiteral(value))
)
}
diff --git a/packages/macro/test/fixtures/jsx-plural-select-nested.expected.js b/packages/macro/test/fixtures/jsx-plural-select-nested.expected.js
index b884f6d35..fd19a6c2e 100644
--- a/packages/macro/test/fixtures/jsx-plural-select-nested.expected.js
+++ b/packages/macro/test/fixtures/jsx-plural-select-nested.expected.js
@@ -1,5 +1,5 @@
import { Trans } from "@lingui/react";
-A lot of them0>}}"
+ }
+ values={{
count: count
}} components={{
0:
@@ -38,7 +41,10 @@ export default [
`,
expected: `
import { Trans } from "@lingui/react";
- #0> slot added} other {<1>#1> slots added}}"
+ }
+ values={{
count: count
}} components={{
0: ,
@@ -61,7 +67,7 @@ export default [
`,
expected: `
import { Trans } from "@lingui/react";
- A lot of them0>}}"} values={{
count: count
}} components={{
0:
@@ -84,7 +90,10 @@ export default [
`,
expected: `
import { Trans } from "@lingui/react";
- a lot of them0>}}"
+ }
+ values={{
0: items.length,
1: items.length,
2: 42
diff --git a/packages/macro/test/jsx-select.ts b/packages/macro/test/jsx-select.ts
index 0ef906ff9..07f114c9a 100644
--- a/packages/macro/test/jsx-select.ts
+++ b/packages/macro/test/jsx-select.ts
@@ -11,7 +11,7 @@ export default [
`,
expected: `
import { Trans } from "@lingui/react";
- Other0>}}"} values={{
count: count
}} components={{
0:
@@ -32,7 +32,7 @@ export default [
`,
expected: `
import { Trans } from "@lingui/react";
- Other0>}}"} values={{
0: user.gender
}} components={{
0:
diff --git a/packages/macro/test/jsx-selectOrdinal.ts b/packages/macro/test/jsx-selectOrdinal.ts
index a89f21c48..e3f846069 100644
--- a/packages/macro/test/jsx-selectOrdinal.ts
+++ b/packages/macro/test/jsx-selectOrdinal.ts
@@ -13,7 +13,10 @@ export default [
`,
expected: `
import { Trans } from "@lingui/react";
- #rd0>}} cat."
+ }
+ values={{
count: count
}} components={{
0:
@@ -34,7 +37,10 @@ export default [
`,
expected: `
import { Trans } from "@lingui/react";
- #rd0>}} cat."
+ }
+ values={{
0: user.numCats
}} components={{
0:
diff --git a/packages/macro/test/jsx-trans.ts b/packages/macro/test/jsx-trans.ts
index 950f9fc4f..97e70493a 100644
--- a/packages/macro/test/jsx-trans.ts
+++ b/packages/macro/test/jsx-trans.ts
@@ -7,7 +7,7 @@ export default [
`,
expected: `
import { Trans } from "@lingui/react";
- ;
+ ;
`,
},
{
@@ -18,7 +18,7 @@ export default [
`,
expected: `
import { Trans } from "@lingui/react";
- ;
+ ;
`,
},
{
@@ -29,7 +29,7 @@ export default [
`,
expected: `
import { Trans } from "@lingui/react";
- ;
+ ;
`,
},
{
@@ -40,7 +40,7 @@ export default [
`,
expected: `
import { Trans } from "@lingui/react";
- ;
+ ;
`,
},
{
@@ -51,7 +51,7 @@ export default [
`,
expected: `
import { Trans } from "@lingui/react";
- ;
+ ;
`,
},
{
@@ -73,7 +73,7 @@ export default [
`,
expected: `
import { Trans } from "@lingui/react";
- ;
@@ -87,7 +87,7 @@ export default [
`,
expected: `
import { Trans } from "@lingui/react";
- ;
`,
@@ -105,6 +105,23 @@ export default [
;
`,
},
+ {
+ name: "HTML attributes are handled",
+ input: `
+ import { Trans } from '@lingui/macro';
+
+ This should work
+ ;
+ `,
+ expected: `
+ import { Trans } from "@lingui/react";
+ This should work \\xA00>"}
+ components={{
+ 0: ,
+ }}
+ />;
+ `,
+ },
{
name: "Template literals as children",
input: `
@@ -113,7 +130,7 @@ export default [
`,
expected: `
import { Trans } from "@lingui/react";
- ;
@@ -127,7 +144,7 @@ export default [
`,
expected: `
import { Trans } from "@lingui/react";
- ;
+ ;
`,
},
{
@@ -145,7 +162,7 @@ export default [
`,
expected: `
import { Trans } from "@lingui/react";
- World!0><1/><2>My name is <3> <4>{name}4>3>2>"} values={{
name: name
}} components={{
0: ,
@@ -188,7 +205,7 @@ export default [
`,
expected: `
import { Trans } from "@lingui/react";
- Component inside expression container0>"} components={{
0:
}} />;
`,
@@ -201,7 +218,7 @@ export default [
`,
expected: `
import { Trans } from "@lingui/react";
- "} components={{
0:
}} />;
`,
@@ -222,7 +239,7 @@ export default [
production: true,
input: `
import { Trans } from '@lingui/macro';
- Hello World
+ Hello World
`,
expected: `
import { Trans } from "@lingui/react";
@@ -255,7 +272,7 @@ export default [
`,
expected: `
import { Trans } from "@lingui/react";
- ;
`,
@@ -272,7 +289,7 @@ export default [
`,
expected: `
import { Trans } from "@lingui/react";
- forced spaces0>!"} components={{
0:
}} />;
`,
@@ -288,7 +305,7 @@ export default [
`,
expected: `
import { Trans } from "@lingui/react";
- ;
+ ;
`,
},
{
@@ -303,7 +320,7 @@ export default [
`,
expected: `
import { Trans } from "@lingui/react";
- ;
+ ;
`,
},
{
@@ -314,7 +331,7 @@ export default [
expected: `
import { Trans } from "@lingui/react";
import { i18n } from "@lingui/core";
- more0>"} components={{
0: ;
+ ;
`,
},
{
@@ -361,7 +378,7 @@ export default [
`,
expected: `
import { Trans } from "@lingui/react";
- ;
+ ;
`,
},
]