1- import { hyphenate , isArray } from '@vue/shared'
1+ import { hyphenate , isArray , isString , isFunction } from '@vue/shared'
22import {
33 ErrorCodes ,
44 ComponentInternalInstance ,
5- callWithAsyncErrorHandling
5+ callWithAsyncErrorHandling , warn
66} from '@vue/runtime-core'
77
88interface Invoker extends EventListener {
@@ -81,7 +81,7 @@ const getNow = () =>
8181 cachedNow || ( p . then ( ( ) => ( cachedNow = 0 ) ) , ( cachedNow = Date . now ( ) ) )
8282
8383function createInvoker (
84- initialValue : EventValue ,
84+ initialValue : EventValue | unknown ,
8585 instance : ComponentInternalInstance | null
8686) {
8787 const invoker : Invoker = ( e : Event & { _vts ?: number } ) => {
@@ -109,11 +109,22 @@ function createInvoker(
109109 [ e ]
110110 )
111111 }
112- invoker . value = initialValue
112+ invoker . value = sanitizeEventValue ( initialValue )
113113 invoker . attached = getNow ( )
114114 return invoker
115115}
116116
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+
117128function patchStopImmediatePropagation (
118129 e : Event ,
119130 value : EventValue
@@ -124,7 +135,7 @@ function patchStopImmediatePropagation(
124135 originalStop . call ( e )
125136 ; ( e as any ) . _stopped = true
126137 }
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 ) )
128139 } else {
129140 return value
130141 }
0 commit comments