Merge pull request #729 from vuejs/fix-728

fix: exclude TemplateLiteral expression from isConstant
This commit is contained in:
zhiyuanzmj 2025-02-09 01:21:38 +08:00 committed by GitHub
commit 30fe3c5634
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 15 additions and 1 deletions

View File

@ -323,7 +323,9 @@ export const isConstant = (
isConstant((property as any).value)
);
}
if (t.isLiteral(node)) {
if (
t.isTemplateLiteral(node) ? !node.expressions.length : t.isLiteral(node)
) {
return true;
}
return false;

View File

@ -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']);"

View File

@ -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(