Skip to content

Commit 30fe3c5

Browse files
authored
Merge pull request #729 from vuejs/fix-728
fix: exclude TemplateLiteral expression from isConstant
2 parents b82c590 + 4e47c5f commit 30fe3c5

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

packages/babel-plugin-jsx/src/utils.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,9 @@ export const isConstant = (
323323
isConstant((property as any).value)
324324
);
325325
}
326-
if (t.isLiteral(node)) {
326+
if (
327+
t.isTemplateLiteral(node) ? !node.expressions.length : t.isLiteral(node)
328+
) {
327329
return true;
328330
}
329331
return false;

packages/babel-plugin-jsx/test/__snapshots__/snapshot.test.ts.snap

+8
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ _createVNode("div", {
2323
}, null, 6);"
2424
`;
2525

26+
exports[`TemplateLiteral prop and event co-usage > TemplateLiteral prop and event co-usage 1`] = `
27+
"import { createVNode as _createVNode } from "vue";
28+
_createVNode("div", {
29+
"value": \`\${foo}\`,
30+
"onClick": () => foo.value++
31+
}, null, 8, ["value", "onClick"]);"
32+
`;
33+
2634
exports[`Without JSX should work > Without JSX should work 1`] = `
2735
"import { createVNode } from 'vue';
2836
createVNode('div', null, ['Without JSX should work']);"

packages/babel-plugin-jsx/test/snapshot.test.ts

+4
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,10 @@ const transpile = (source: string, options: VueJSXPluginOptions = {}) =>
208208
name: 'using v-slots without children should not be spread',
209209
from: '<A v-slots={slots} />',
210210
},
211+
{
212+
name: 'TemplateLiteral prop and event co-usage',
213+
from: '<div value={`${foo}`} onClick={() => foo.value++}></div>',
214+
},
211215
].forEach(({ name, from }) => {
212216
test(name, async () => {
213217
expect(

0 commit comments

Comments
 (0)