From a07a633603b6236aac9d9aa9e1496888bae614b7 Mon Sep 17 00:00:00 2001 From: "qing.deng" Date: Fri, 16 Sep 2022 15:04:45 +0800 Subject: [PATCH 1/2] fix: syntax error when v-on contains objects --- packages/compiler-sfc/src/compileScript.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/compiler-sfc/src/compileScript.ts b/packages/compiler-sfc/src/compileScript.ts index 5a77e8a9463..f4f6ff7936e 100644 --- a/packages/compiler-sfc/src/compileScript.ts +++ b/packages/compiler-sfc/src/compileScript.ts @@ -2135,7 +2135,11 @@ function processExp(exp: string, dir?: string): string { if (dir === 'slot') { exp = `(${exp})=>{}` } else if (dir === 'on') { - exp = `()=>{${exp}}` + if (/^\{.*\}$/.test(exp.trim())) { + exp = `()=>(${exp})` + } else { + exp = `()=>{${exp}}` + } } else if (dir === 'for') { const inMatch = exp.match(forAliasRE) if (inMatch) { From ac2114b18c77aa30613946f9051afcbc06ff56e9 Mon Sep 17 00:00:00 2001 From: "qing.deng" Date: Fri, 16 Sep 2022 15:04:54 +0800 Subject: [PATCH 2/2] test: update cases --- .../compiler-sfc/__tests__/compileScript.spec.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/compiler-sfc/__tests__/compileScript.spec.ts b/packages/compiler-sfc/__tests__/compileScript.spec.ts index 08d404b9c16..778c13a449b 100644 --- a/packages/compiler-sfc/__tests__/compileScript.spec.ts +++ b/packages/compiler-sfc/__tests__/compileScript.spec.ts @@ -474,6 +474,18 @@ defineExpose({ foo: 123 }) `) }) + + test('v-on contain object', () => { + // should not error + compile(` + +