From f08cdcabfbef6833bbe2139bf953865e652672c5 Mon Sep 17 00:00:00 2001 From: zhiyuanzmj <260480378@qq.com> Date: Sat, 7 Dec 2024 21:57:07 +0800 Subject: [PATCH 1/3] fix: exclude TemplateLiteral expression from isConstant --- packages/babel-plugin-jsx/src/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/babel-plugin-jsx/src/utils.ts b/packages/babel-plugin-jsx/src/utils.ts index 6e1d24de..d1c35b6a 100644 --- a/packages/babel-plugin-jsx/src/utils.ts +++ b/packages/babel-plugin-jsx/src/utils.ts @@ -323,7 +323,7 @@ export const isConstant = ( isConstant((property as any).value) ); } - if (t.isLiteral(node)) { + if (t.isLiteral(node) && !t.isTemplateLiteral(node)) { return true; } return false; From 37057c4f4a1233c087a31e5acc0929118aece15d Mon Sep 17 00:00:00 2001 From: zhiyuanzmj <260480378@qq.com> Date: Sat, 7 Dec 2024 22:16:19 +0800 Subject: [PATCH 2/3] chore: add test --- packages/babel-plugin-jsx/src/utils.ts | 2 +- .../test/__snapshots__/snapshot.test.ts.snap | 8 ++++++++ packages/babel-plugin-jsx/test/snapshot.test.ts | 4 ++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/babel-plugin-jsx/src/utils.ts b/packages/babel-plugin-jsx/src/utils.ts index d1c35b6a..7cbf271f 100644 --- a/packages/babel-plugin-jsx/src/utils.ts +++ b/packages/babel-plugin-jsx/src/utils.ts @@ -323,7 +323,7 @@ export const isConstant = ( isConstant((property as any).value) ); } - if (t.isLiteral(node) && !t.isTemplateLiteral(node)) { + if (!t.isTemplateLiteral(node) && t.isLiteral(node)) { return true; } return false; diff --git a/packages/babel-plugin-jsx/test/__snapshots__/snapshot.test.ts.snap b/packages/babel-plugin-jsx/test/__snapshots__/snapshot.test.ts.snap index 3ffb6738..fe97df98 100644 --- a/packages/babel-plugin-jsx/test/__snapshots__/snapshot.test.ts.snap +++ b/packages/babel-plugin-jsx/test/__snapshots__/snapshot.test.ts.snap @@ -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']);" diff --git a/packages/babel-plugin-jsx/test/snapshot.test.ts b/packages/babel-plugin-jsx/test/snapshot.test.ts index 407da6ea..e1488fd2 100644 --- a/packages/babel-plugin-jsx/test/snapshot.test.ts +++ b/packages/babel-plugin-jsx/test/snapshot.test.ts @@ -208,6 +208,10 @@ const transpile = (source: string, options: VueJSXPluginOptions = {}) => name: 'using v-slots without children should not be spread', from: '', }, + { + name: 'TemplateLiteral prop and event co-usage', + from: '