@@ -30,43 +30,46 @@ const modifierGuards: Record<
30
30
}
31
31
32
32
export const on : Directive = ( { el, get, exp, arg, modifiers } ) => {
33
- if ( arg ) {
34
- let handler = simplePathRE . test ( exp )
35
- ? get ( `(e => ${ exp } (e))` )
36
- : get ( `($event => { ${ exp } })` )
33
+ if ( ! arg ) {
34
+ if ( import . meta. env . DEV ) {
35
+ console . error ( `v-on="obj" syntax is not supported in petite-vue.` )
36
+ }
37
+ return
38
+ }
39
+
40
+ let handler = simplePathRE . test ( exp )
41
+ ? get ( `(e => ${ exp } (e))` )
42
+ : get ( `($event => { ${ exp } })` )
43
+
44
+ // special lifecycle events
45
+ if ( arg === 'mounted' ) {
46
+ nextTick ( handler )
47
+ return
48
+ } else if ( arg === 'unmounted' ) {
49
+ return ( ) => handler ( )
50
+ }
37
51
38
- // special lifecycle events
39
- if ( arg === 'mounted' ) {
40
- nextTick ( handler )
41
- return
42
- } else if ( arg === 'unmounted' ) {
43
- return ( ) => handler ( )
52
+ if ( modifiers ) {
53
+ // map modifiers
54
+ if ( arg === 'click' ) {
55
+ if ( modifiers . right ) arg = 'contextmenu'
56
+ if ( modifiers . middle ) arg = 'mouseup'
44
57
}
45
58
46
- if ( modifiers ) {
47
- // map modifiers
48
- if ( arg === 'click' ) {
49
- if ( modifiers . right ) arg = 'contextmenu'
50
- if ( modifiers . middle ) arg = 'mouseup'
59
+ const raw = handler
60
+ handler = ( e : Event ) => {
61
+ if ( 'key' in e && ! ( hyphenate ( ( e as KeyboardEvent ) . key ) in modifiers ) ) {
62
+ return
51
63
}
52
-
53
- const raw = handler
54
- handler = ( e : Event ) => {
55
- if ( 'key' in e && ! ( hyphenate ( ( e as KeyboardEvent ) . key ) in modifiers ) ) {
64
+ for ( const key in modifiers ) {
65
+ const guard = modifierGuards [ key ]
66
+ if ( guard && guard ( e , modifiers ) ) {
56
67
return
57
68
}
58
- for ( const key in modifiers ) {
59
- const guard = modifierGuards [ key ]
60
- if ( guard && guard ( e , modifiers ) ) {
61
- return
62
- }
63
- }
64
- return raw ( e )
65
69
}
70
+ return raw ( e )
66
71
}
67
-
68
- listen ( el , arg , handler , modifiers )
69
- } else if ( import . meta. env . DEV ) {
70
- console . error ( `v-on="obj" syntax is not supported in petite-vue.` )
71
72
}
73
+
74
+ listen ( el , arg , handler , modifiers )
72
75
}
0 commit comments