fix(compiler-core/v-on): support inline handler with return type annotation (#6769)

fix #6378
This commit is contained in:
Travis 2022-11-08 11:09:15 +08:00 committed by GitHub
parent 640cfce4ff
commit bcfe480d75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View 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="

View 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