1
- import { hyphenate , isArray } from '@vue/shared'
1
+ import { hyphenate , isArray , isString , isFunction } from '@vue/shared'
2
2
import {
3
3
ErrorCodes ,
4
4
ComponentInternalInstance ,
5
- callWithAsyncErrorHandling
5
+ callWithAsyncErrorHandling , warn
6
6
} from '@vue/runtime-core'
7
7
8
8
interface Invoker extends EventListener {
@@ -81,7 +81,7 @@ const getNow = () =>
81
81
cachedNow || ( p . then ( ( ) => ( cachedNow = 0 ) ) , ( cachedNow = Date . now ( ) ) )
82
82
83
83
function createInvoker (
84
- initialValue : EventValue ,
84
+ initialValue : EventValue | unknown ,
85
85
instance : ComponentInternalInstance | null
86
86
) {
87
87
const invoker : Invoker = ( e : Event & { _vts ?: number } ) => {
@@ -109,11 +109,22 @@ function createInvoker(
109
109
[ e ]
110
110
)
111
111
}
112
- invoker . value = initialValue
112
+ invoker . value = sanitizeEventValue ( initialValue )
113
113
invoker . attached = getNow ( )
114
114
return invoker
115
115
}
116
116
117
+ function sanitizeEventValue ( value : unknown ) : EventValue {
118
+ if ( isFunction ( value ) || isArray ( value ) ) {
119
+ return value as EventValue
120
+ }
121
+
122
+ if ( __DEV__ ) {
123
+ warn ( 'Wrong type passed to the event invoker, did you maybe forget @ or : in front of your prop? Received ' + ( isString ( value ) ? value : typeof value ) )
124
+ }
125
+ return ( ) => { }
126
+ }
127
+
117
128
function patchStopImmediatePropagation (
118
129
e : Event ,
119
130
value : EventValue
@@ -124,7 +135,7 @@ function patchStopImmediatePropagation(
124
135
originalStop . call ( e )
125
136
; ( e as any ) . _stopped = true
126
137
}
127
- return value . map ( fn => ( e : Event ) => ! ( e as any ) . _stopped && fn && fn ( e ) )
138
+ return ( value as Function [ ] ) . map ( fn => ( e : Event ) => ! ( e as any ) . _stopped && fn && fn ( e ) )
128
139
} else {
129
140
return value
130
141
}
0 commit comments