Allow placeholders in JSXElements when parsing templates (#7583)
This commit is contained in:
parent
840ba187a7
commit
f98dff9189
@ -64,7 +64,7 @@ function placeholderVisitorHandler(
|
|||||||
state: MetadataState,
|
state: MetadataState,
|
||||||
) {
|
) {
|
||||||
let name;
|
let name;
|
||||||
if (t.isIdentifier(node)) {
|
if (t.isIdentifier(node) || t.isJSXIdentifier(node)) {
|
||||||
name = ((node: any): BabelNodeIdentifier).name;
|
name = ((node: any): BabelNodeIdentifier).name;
|
||||||
} else if (t.isStringLiteral(node)) {
|
} else if (t.isStringLiteral(node)) {
|
||||||
name = ((node: any): BabelNodeStringLiteral).value;
|
name = ((node: any): BabelNodeStringLiteral).value;
|
||||||
|
|||||||
@ -204,5 +204,20 @@ describe("@babel/template", function() {
|
|||||||
expect(result.test.type).to.equal("BinaryExpression");
|
expect(result.test.type).to.equal("BinaryExpression");
|
||||||
expect(result.test.left).to.equal(value);
|
expect(result.test.left).to.equal(value);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should replace JSX placeholder", () => {
|
||||||
|
const result = template.expression(
|
||||||
|
`
|
||||||
|
<TAG>{'content'}</TAG>
|
||||||
|
`,
|
||||||
|
{
|
||||||
|
plugins: ["jsx"],
|
||||||
|
},
|
||||||
|
)({
|
||||||
|
TAG: t.jsxIdentifier("div"),
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(generator(result).code).to.equal("<div>{'content'}</div>");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user