]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(compiler-core/v-on): support inline handler with return type annotation (#6769)
authorTravis <godxiaoji@163.com>
Tue, 8 Nov 2022 03:09:15 +0000 (11:09 +0800)
committerGitHub <noreply@github.com>
Tue, 8 Nov 2022 03:09:15 +0000 (22:09 -0500)
fix #6378

packages/compiler-core/__tests__/transforms/vOn.spec.ts
packages/compiler-core/src/transforms/vOn.ts

index 8f943a7491ffecdff2c50d101aa03cf8c22ed9df..4ed9ea23a8285988f571f3af87dea6adafde890b 100644 (file)
@@ -271,6 +271,21 @@ describe('compiler: transform v-on', () => {
     })
   })
 
+  test('should NOT wrap as function if expression is already function expression (with Typescript)', () => {
+    const { node } = parseWithVOn(`<div @click="(e: any): any => foo(e)"/>`)
+    expect((node.codegenNode as VNodeCall).props).toMatchObject({
+      properties: [
+        {
+          key: { content: `onClick` },
+          value: {
+            type: NodeTypes.SIMPLE_EXPRESSION,
+            content: `(e: any): any => foo(e)`
+          }
+        }
+      ]
+    })
+  })
+
   test('should NOT wrap as function if expression is already function expression (with newlines)', () => {
     const { node } = parseWithVOn(
       `<div @click="
index ed39ecee12fdb6a1332c028dac78dcdea8c01c1d..b4d2e851ca9558f05851885d15f0bab065c95b3a 100644 (file)
@@ -17,7 +17,7 @@ import { hasScopeRef, isMemberExpression } from '../utils'
 import { TO_HANDLER_KEY } from '../runtimeHelpers'
 
 const fnExpRE =
-  /^\s*([\w$_]+|(async\s*)?\([^)]*?\))\s*=>|^\s*(async\s+)?function(?:\s+[\w$]+)?\s*\(/
+  /^\s*([\w$_]+|(async\s*)?\([^)]*?\))\s*(:[^=]+)?=>|^\s*(async\s+)?function(?:\s+[\w$]+)?\s*\(/
 
 export interface VOnDirectiveNode extends DirectiveNode {
   // v-on without arg is handled directly in ./transformElements.ts due to it affecting