Allow placeholders in JSXElements when parsing templates (#7583)

This commit is contained in:
Mateusz Burzyński 2018-03-23 09:27:51 +01:00 committed by GitHub
parent 840ba187a7
commit f98dff9189
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View File

@ -64,7 +64,7 @@ function placeholderVisitorHandler(
state: MetadataState,
) {
let name;
if (t.isIdentifier(node)) {
if (t.isIdentifier(node) || t.isJSXIdentifier(node)) {
name = ((node: any): BabelNodeIdentifier).name;
} else if (t.isStringLiteral(node)) {
name = ((node: any): BabelNodeStringLiteral).value;

View File

@ -204,5 +204,20 @@ describe("@babel/template", function() {
expect(result.test.type).to.equal("BinaryExpression");
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>");
});
});
});