File tree 2 files changed +43
-3
lines changed
2 files changed +43
-3
lines changed Original file line number Diff line number Diff line change @@ -476,7 +476,47 @@ describe('compiler: transform v-on', () => {
476
476
index : 1 ,
477
477
value : {
478
478
type : NodeTypes . COMPOUND_EXPRESSION ,
479
- children : [ `(...args) => (` , { content : `_ctx.foo(...args)` } , `)` ]
479
+ children : [
480
+ `(...args) => (` ,
481
+ { content : `_ctx.foo && _ctx.foo(...args)` } ,
482
+ `)`
483
+ ]
484
+ }
485
+ } )
486
+ } )
487
+
488
+ test ( 'compound member expression handler' , ( ) => {
489
+ const { root, node } = parseWithVOn ( `<div v-on:click="foo.bar" />` , {
490
+ prefixIdentifiers : true ,
491
+ cacheHandlers : true
492
+ } )
493
+ expect ( root . cached ) . toBe ( 1 )
494
+ const vnodeCall = node . codegenNode as VNodeCall
495
+ // should not treat cached handler as dynamicProp, so no flags
496
+ expect ( vnodeCall . patchFlag ) . toBeUndefined ( )
497
+ expect (
498
+ ( vnodeCall . props as ObjectExpression ) . properties [ 0 ] . value
499
+ ) . toMatchObject ( {
500
+ type : NodeTypes . JS_CACHE_EXPRESSION ,
501
+ index : 1 ,
502
+ value : {
503
+ type : NodeTypes . COMPOUND_EXPRESSION ,
504
+ children : [
505
+ `(...args) => (` ,
506
+ {
507
+ children : [
508
+ { content : `_ctx.foo` } ,
509
+ `.` ,
510
+ { content : `bar` } ,
511
+ ` && ` ,
512
+ { content : `_ctx.foo` } ,
513
+ `.` ,
514
+ { content : `bar` } ,
515
+ `(...args)`
516
+ ]
517
+ } ,
518
+ `)`
519
+ ]
480
520
}
481
521
} )
482
522
} )
Original file line number Diff line number Diff line change @@ -108,9 +108,9 @@ export const transformOn: DirectiveTransform = (
108
108
// avoiding the need to be patched.
109
109
if ( shouldCache && isMemberExp ) {
110
110
if ( exp . type === NodeTypes . SIMPLE_EXPRESSION ) {
111
- exp . content + = `(...args)`
111
+ exp . content = `${ exp . content } && ${ exp . content } (...args)`
112
112
} else {
113
- exp . children . push ( ` (...args)`)
113
+ exp . children = [ ... exp . children , ` && ` , ... exp . children , ` (...args)`]
114
114
}
115
115
}
116
116
}
You can’t perform that action at this time.
0 commit comments