Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: exclude TemplateLiteral expression from isConstant #729

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/babel-plugin-jsx/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ export const isConstant = (
isConstant((property as any).value)
);
}
if (t.isLiteral(node)) {
if (!t.isTemplateLiteral(node) && t.isLiteral(node)) {
return true;
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ _createVNode("div", {
}, null, 6);"
`;

exports[`TemplateLiteral prop and event co-usage > TemplateLiteral prop and event co-usage 1`] = `
"import { createVNode as _createVNode } from "vue";
_createVNode("div", {
"value": \`\${foo}\`,
"onClick": () => foo.value++
}, null, 8, ["value", "onClick"]);"
`;

exports[`Without JSX should work > Without JSX should work 1`] = `
"import { createVNode } from 'vue';
createVNode('div', null, ['Without JSX should work']);"
Expand Down
4 changes: 4 additions & 0 deletions packages/babel-plugin-jsx/test/snapshot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ const transpile = (source: string, options: VueJSXPluginOptions = {}) =>
name: 'using v-slots without children should not be spread',
from: '<A v-slots={slots} />',
},
{
name: 'TemplateLiteral prop and event co-usage',
from: '<div value={`${foo}`} onClick={() => foo.value++}></div>',
},
].forEach(({ name, from }) => {
test(name, async () => {
expect(
Expand Down
Loading