5
5
createCallExpression ,
6
6
createObjectExpression ,
7
7
createSimpleExpression ,
8
- NodeTypes
8
+ NodeTypes ,
9
+ CallExpression ,
10
+ ObjectExpression
9
11
} from '@vue/compiler-core'
10
12
import { V_ON_MODIFIERS_GUARD , V_ON_KEYS_GUARD } from '../runtimeHelpers'
11
13
@@ -32,6 +34,7 @@ export const transformOn: DirectiveTransform = (dir, node, context) => {
32
34
const { modifiers } = dir
33
35
const baseResult = baseTransform ( dir , node , context )
34
36
if ( ! modifiers . length ) return baseResult
37
+
35
38
const { key, value } = baseResult . props [ 0 ]
36
39
const runtimeModifiers = modifiers . filter ( m => ! ( m in EVENT_OPTION_MODIFIERS ) )
37
40
let handler = createCallExpression ( context . helper ( V_ON_MODIFIERS_GUARD ) , [
@@ -49,17 +52,15 @@ export const transformOn: DirectiveTransform = (dir, node, context) => {
49
52
JSON . stringify ( runtimeModifiers . filter ( m => ! ( m in NOT_KEY_MODIFIERS ) ) )
50
53
] )
51
54
}
52
- const properties = [
53
- createObjectProperty ( 'handler' , handler ) ,
54
- // so the runtime knows the options never change
55
- createObjectProperty ( 'persistent' , createSimpleExpression ( 'true' , false ) )
56
- ]
55
+
56
+ let returnExp : CallExpression | ObjectExpression = handler
57
57
58
58
const eventOptionModifiers = modifiers . filter (
59
59
modifier => modifier in EVENT_OPTION_MODIFIERS
60
60
)
61
61
if ( eventOptionModifiers . length ) {
62
- properties . push (
62
+ returnExp = createObjectExpression ( [
63
+ createObjectProperty ( 'handler' , handler ) ,
63
64
createObjectProperty (
64
65
'options' ,
65
66
createObjectExpression (
@@ -70,12 +71,14 @@ export const transformOn: DirectiveTransform = (dir, node, context) => {
70
71
)
71
72
)
72
73
)
73
- )
74
- )
74
+ ) ,
75
+ // so the runtime knows the options never change
76
+ createObjectProperty ( 'persistent' , createSimpleExpression ( 'true' , false ) )
77
+ ] )
75
78
}
76
79
77
80
return {
78
- props : [ createObjectProperty ( key , createObjectExpression ( properties ) ) ] ,
81
+ props : [ createObjectProperty ( key , returnExp ) ] ,
79
82
needRuntime : false
80
83
}
81
84
}
0 commit comments