@@ -5,16 +5,15 @@ import {
5
5
ElementNode ,
6
6
ObjectExpression ,
7
7
NodeTypes ,
8
- VNodeCall
8
+ VNodeCall ,
9
+ helperNameMap ,
10
+ CAPITALIZE
9
11
} from '@vue/compiler-core'
10
12
import { transformOn } from '../../src/transforms/vOn'
11
13
import { V_ON_WITH_MODIFIERS , V_ON_WITH_KEYS } from '../../src/runtimeHelpers'
12
14
import { transformElement } from '../../../compiler-core/src/transforms/transformElement'
13
15
import { transformExpression } from '../../../compiler-core/src/transforms/transformExpression'
14
- import {
15
- createObjectMatcher ,
16
- genFlagText
17
- } from '../../../compiler-core/__tests__/testUtils'
16
+ import { genFlagText } from '../../../compiler-core/__tests__/testUtils'
18
17
import { PatchFlags } from '@vue/shared'
19
18
20
19
function parseWithVOn ( template : string , options : CompilerOptions = { } ) {
@@ -83,42 +82,37 @@ describe('compiler-dom: transform v-on', () => {
83
82
} )
84
83
expect ( prop ) . toMatchObject ( {
85
84
type : NodeTypes . JS_PROPERTY ,
86
- value : createObjectMatcher ( {
87
- handler : {
88
- callee : V_ON_WITH_MODIFIERS ,
89
- arguments : [ { content : '_ctx.test' } , '["stop"]' ]
90
- } ,
91
- options : createObjectMatcher ( {
92
- capture : { content : 'true' , isStatic : false } ,
93
- passive : { content : 'true' , isStatic : false }
94
- } )
95
- } )
85
+ key : {
86
+ content : `onClick.capture.passive`
87
+ } ,
88
+ value : {
89
+ callee : V_ON_WITH_MODIFIERS ,
90
+ arguments : [ { content : '_ctx.test' } , '["stop"]' ]
91
+ }
96
92
} )
97
93
} )
98
94
99
95
it ( 'should wrap keys guard for keyboard events or dynamic events' , ( ) => {
100
96
const {
101
97
props : [ prop ]
102
- } = parseWithVOn ( `<div @keyDown .stop.capture.ctrl.a="test"/>` , {
98
+ } = parseWithVOn ( `<div @keydown .stop.capture.ctrl.a="test"/>` , {
103
99
prefixIdentifiers : true
104
100
} )
105
101
expect ( prop ) . toMatchObject ( {
106
102
type : NodeTypes . JS_PROPERTY ,
107
- value : createObjectMatcher ( {
108
- handler : {
109
- callee : V_ON_WITH_KEYS ,
110
- arguments : [
111
- {
112
- callee : V_ON_WITH_MODIFIERS ,
113
- arguments : [ { content : '_ctx.test' } , '["stop","ctrl"]' ]
114
- } ,
115
- '["a"]'
116
- ]
117
- } ,
118
- options : createObjectMatcher ( {
119
- capture : { content : 'true' , isStatic : false }
120
- } )
121
- } )
103
+ key : {
104
+ content : `onKeydown.capture`
105
+ } ,
106
+ value : {
107
+ callee : V_ON_WITH_KEYS ,
108
+ arguments : [
109
+ {
110
+ callee : V_ON_WITH_MODIFIERS ,
111
+ arguments : [ { content : '_ctx.test' } , '["stop","ctrl"]' ]
112
+ } ,
113
+ '["a"]'
114
+ ]
115
+ }
122
116
} )
123
117
} )
124
118
@@ -206,9 +200,21 @@ describe('compiler-dom: transform v-on', () => {
206
200
type : NodeTypes . COMPOUND_EXPRESSION ,
207
201
children : [
208
202
`(` ,
209
- { children : [ `"on" + (` , { content : 'event' } , `)` ] } ,
210
- `).toLowerCase() === "onclick" ? "onContextmenu" : (` ,
211
- { children : [ `"on" + (` , { content : 'event' } , `)` ] } ,
203
+ {
204
+ children : [
205
+ `"on" + _${ helperNameMap [ CAPITALIZE ] } (` ,
206
+ { content : 'event' } ,
207
+ `)`
208
+ ]
209
+ } ,
210
+ `) === "onClick" ? "onContextmenu" : (` ,
211
+ {
212
+ children : [
213
+ `"on" + _${ helperNameMap [ CAPITALIZE ] } (` ,
214
+ { content : 'event' } ,
215
+ `)`
216
+ ]
217
+ } ,
212
218
`)`
213
219
]
214
220
} )
@@ -232,9 +238,21 @@ describe('compiler-dom: transform v-on', () => {
232
238
type : NodeTypes . COMPOUND_EXPRESSION ,
233
239
children : [
234
240
`(` ,
235
- { children : [ `"on" + (` , { content : 'event' } , `)` ] } ,
236
- `).toLowerCase() === "onclick" ? "onMouseup" : (` ,
237
- { children : [ `"on" + (` , { content : 'event' } , `)` ] } ,
241
+ {
242
+ children : [
243
+ `"on" + _${ helperNameMap [ CAPITALIZE ] } (` ,
244
+ { content : 'event' } ,
245
+ `)`
246
+ ]
247
+ } ,
248
+ `) === "onClick" ? "onMouseup" : (` ,
249
+ {
250
+ children : [
251
+ `"on" + _${ helperNameMap [ CAPITALIZE ] } (` ,
252
+ { content : 'event' } ,
253
+ `)`
254
+ ]
255
+ } ,
238
256
`)`
239
257
]
240
258
} )
@@ -254,24 +272,17 @@ describe('compiler-dom: transform v-on', () => {
254
272
expect ( ( root as any ) . children [ 0 ] . codegenNode . patchFlag ) . toBe (
255
273
genFlagText ( PatchFlags . HYDRATE_EVENTS )
256
274
)
257
- expect ( prop . value ) . toMatchObject ( {
258
- type : NodeTypes . JS_CACHE_EXPRESSION ,
259
- index : 1 ,
275
+ expect ( prop ) . toMatchObject ( {
276
+ key : {
277
+ content : `onKeyup.capture`
278
+ } ,
260
279
value : {
261
- type : NodeTypes . JS_OBJECT_EXPRESSION ,
262
- properties : [
263
- {
264
- key : { content : 'handler' } ,
265
- value : {
266
- type : NodeTypes . JS_CALL_EXPRESSION ,
267
- callee : V_ON_WITH_KEYS
268
- }
269
- } ,
270
- {
271
- key : { content : 'options' } ,
272
- value : { type : NodeTypes . JS_OBJECT_EXPRESSION }
273
- }
274
- ]
280
+ type : NodeTypes . JS_CACHE_EXPRESSION ,
281
+ index : 1 ,
282
+ value : {
283
+ type : NodeTypes . JS_CALL_EXPRESSION ,
284
+ callee : V_ON_WITH_KEYS
285
+ }
275
286
}
276
287
} )
277
288
} )
0 commit comments