@@ -135,7 +135,7 @@ function processSFCListeners (elements: ElementNode[], s: MagicString, filename:
135135 options . warn ?.( warning )
136136
137137 if ( options . wrapListeners && prop . exp ?. loc ?. source )
138- s . overwrite ( prop . exp . loc . start . offset , prop . exp . loc . end . offset , guardedVueExpression ( prop . exp . loc . source , warning ) )
138+ wrapVueExpression ( s , prop . exp . loc . start . offset , prop . exp . loc . end . offset , warning )
139139 }
140140
141141 for ( const child of node . children || [ ] ) {
@@ -148,13 +148,13 @@ function processSFCListeners (elements: ElementNode[], s: MagicString, filename:
148148 walk ( element )
149149}
150150
151- function guardedVueExpression ( expression : string , warning : ListenerWarning ) {
151+ function wrapVueExpression ( s : MagicString , start : number , end : number , warning : ListenerWarning ) {
152152 const details = JSON . stringify ( {
153153 source : 'vue' ,
154154 ...warning ,
155155 } )
156- const run = `{ const __ile_handler = ( ${ expression } ); return typeof __ile_handler === 'function' ? __ile_handler($event) : __ile_handler }`
157- return `($event) => (window.__ILE_GUARD_LISTENER_CALL__ ? window.__ILE_GUARD_LISTENER_CALL__(() => ${ run } , $event, ${ details } ) : (() => ${ run } )())`
156+ s . appendLeft ( start , `($event) => window.__ILE_GUARD_LISTENER_CALL__(() => { const _ileHandler = (` )
157+ s . appendRight ( end , `); return typeof _ileHandler === 'function' ? _ileHandler($event) : _ileHandler }, $event, ${ details } )` )
158158}
159159
160160function isOnDirective ( prop : any ) : prop is DirectiveNode {
0 commit comments