Skip to content

Commit bcfe480

Browse files
authoredNov 8, 2022
fix(compiler-core/v-on): support inline handler with return type annotation (#6769)
fix #6378
1 parent 640cfce commit bcfe480

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed
 

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

+15
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,21 @@ describe('compiler: transform v-on', () => {
271271
})
272272
})
273273

274+
test('should NOT wrap as function if expression is already function expression (with Typescript)', () => {
275+
const { node } = parseWithVOn(`<div @click="(e: any): any => foo(e)"/>`)
276+
expect((node.codegenNode as VNodeCall).props).toMatchObject({
277+
properties: [
278+
{
279+
key: { content: `onClick` },
280+
value: {
281+
type: NodeTypes.SIMPLE_EXPRESSION,
282+
content: `(e: any): any => foo(e)`
283+
}
284+
}
285+
]
286+
})
287+
})
288+
274289
test('should NOT wrap as function if expression is already function expression (with newlines)', () => {
275290
const { node } = parseWithVOn(
276291
`<div @click="

‎packages/compiler-core/src/transforms/vOn.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { hasScopeRef, isMemberExpression } from '../utils'
1717
import { TO_HANDLER_KEY } from '../runtimeHelpers'
1818

1919
const fnExpRE =
20-
/^\s*([\w$_]+|(async\s*)?\([^)]*?\))\s*=>|^\s*(async\s+)?function(?:\s+[\w$]+)?\s*\(/
20+
/^\s*([\w$_]+|(async\s*)?\([^)]*?\))\s*(:[^=]+)?=>|^\s*(async\s+)?function(?:\s+[\w$]+)?\s*\(/
2121

2222
export interface VOnDirectiveNode extends DirectiveNode {
2323
// v-on without arg is handled directly in ./transformElements.ts due to it affecting

0 commit comments

Comments
 (0)
Please sign in to comment.