From 8d7d672bc551c9ff40e958600468c459992a3b9b Mon Sep 17 00:00:00 2001 From: zhiyuanzmj <32807958+zhiyuanzmj@users.noreply.github.com> Date: Sat, 13 Jan 2024 03:26:50 +0800 Subject: [PATCH] fix(compiler-vapor): should not prefix member expression (#92) --- .../transforms/__snapshots__/vOn.spec.ts.snap | 12 ++++++++++++ .../compiler-vapor/__tests__/transforms/vOn.spec.ts | 11 +++++++++++ packages/compiler-vapor/src/generate.ts | 2 +- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/packages/compiler-vapor/__tests__/transforms/__snapshots__/vOn.spec.ts.snap b/packages/compiler-vapor/__tests__/transforms/__snapshots__/vOn.spec.ts.snap index 7aa9e632ac..a469d61bd4 100644 --- a/packages/compiler-vapor/__tests__/transforms/__snapshots__/vOn.spec.ts.snap +++ b/packages/compiler-vapor/__tests__/transforms/__snapshots__/vOn.spec.ts.snap @@ -226,6 +226,18 @@ export function render(_ctx) { }" `; +exports[`v-on > should not prefix member expression 1`] = ` +"import { template as _template, children as _children, on as _on } from 'vue/vapor'; + +export function render(_ctx) { + const t0 = _template("
") + const n0 = t0() + const { 0: [n1],} = _children(n0) + _on(n1, "click", (...args) => (_ctx.foo.bar && _ctx.foo.bar(...args))) + return n0 +}" +`; + exports[`v-on > should not wrap keys guard if no key modifier is present 1`] = ` "import { template as _template, children as _children, on as _on, withModifiers as _withModifiers } from 'vue/vapor'; diff --git a/packages/compiler-vapor/__tests__/transforms/vOn.spec.ts b/packages/compiler-vapor/__tests__/transforms/vOn.spec.ts index 0b64270696..6fae1713fe 100644 --- a/packages/compiler-vapor/__tests__/transforms/vOn.spec.ts +++ b/packages/compiler-vapor/__tests__/transforms/vOn.spec.ts @@ -707,4 +707,15 @@ describe('v-on', () => { '(_ctx.event) === "click" ? "mouseup" : (_ctx.event)', ) }) + + test('should not prefix member expression', () => { + const { code } = compileWithVOn(``, { + prefixIdentifiers: true, + }) + + expect(code).matchSnapshot() + expect(code).contains( + `_on(n1, "click", (...args) => (_ctx.foo.bar && _ctx.foo.bar(...args)))`, + ) + }) }) diff --git a/packages/compiler-vapor/src/generate.ts b/packages/compiler-vapor/src/generate.ts index 262ba0898d..9d916146fe 100644 --- a/packages/compiler-vapor/src/generate.ts +++ b/packages/compiler-vapor/src/generate.ts @@ -652,7 +652,7 @@ function genExpression( if (isLocal) return ids.push(id) }, - true, + false, [], knownIds, ) -- 2.47.3