@@ -478,7 +478,10 @@ describe('compiler: transform component slots', () => {
478
478
} )
479
479
480
480
test ( 'should only force dynamic slots when actually using scope vars w/ prefixIdentifiers: true' , ( ) => {
481
- function assertDynamicSlots ( template : string , shouldForce : boolean ) {
481
+ function assertDynamicSlots (
482
+ template : string ,
483
+ expectedPatchFlag ?: PatchFlags ,
484
+ ) {
482
485
const { root } = parseWithSlots ( template , { prefixIdentifiers : true } )
483
486
let flag : any
484
487
if ( root . children [ 0 ] . type === NodeTypes . FOR ) {
@@ -491,8 +494,8 @@ describe('compiler: transform component slots', () => {
491
494
. children [ 0 ] as ComponentNode
492
495
flag = ( innerComp . codegenNode as VNodeCall ) . patchFlag
493
496
}
494
- if ( shouldForce ) {
495
- expect ( flag ) . toBe ( PatchFlags . DYNAMIC_SLOTS )
497
+ if ( expectedPatchFlag ) {
498
+ expect ( flag ) . toBe ( expectedPatchFlag )
496
499
} else {
497
500
expect ( flag ) . toBeUndefined ( )
498
501
}
@@ -502,44 +505,63 @@ describe('compiler: transform component slots', () => {
502
505
`<div v-for="i in list">
503
506
<Comp v-slot="bar">foo</Comp>
504
507
</div>` ,
505
- false ,
506
508
)
507
509
508
510
assertDynamicSlots (
509
511
`<div v-for="i in list">
510
512
<Comp v-slot="bar">{{ i }}</Comp>
511
513
</div>` ,
512
- true ,
514
+ PatchFlags . DYNAMIC_SLOTS ,
513
515
)
514
516
515
517
// reference the component's own slot variable should not force dynamic slots
516
518
assertDynamicSlots (
517
519
`<Comp v-slot="foo">
518
520
<Comp v-slot="bar">{{ bar }}</Comp>
519
521
</Comp>` ,
520
- false ,
521
522
)
522
523
523
524
assertDynamicSlots (
524
525
`<Comp v-slot="foo">
525
526
<Comp v-slot="bar">{{ foo }}</Comp>
526
527
</Comp>` ,
527
- true ,
528
+ PatchFlags . DYNAMIC_SLOTS ,
528
529
)
529
530
530
531
// #2564
531
532
assertDynamicSlots (
532
533
`<div v-for="i in list">
533
534
<Comp v-slot="bar"><button @click="fn(i)" /></Comp>
534
535
</div>` ,
535
- true ,
536
+ PatchFlags . DYNAMIC_SLOTS ,
536
537
)
537
538
538
539
assertDynamicSlots (
539
540
`<div v-for="i in list">
540
541
<Comp v-slot="bar"><button @click="fn()" /></Comp>
541
542
</div>` ,
542
- false ,
543
+ )
544
+
545
+ // #9380
546
+ assertDynamicSlots (
547
+ `<div v-for="i in list">
548
+ <Comp :i="i">foo</Comp>
549
+ </div>` ,
550
+ PatchFlags . PROPS ,
551
+ )
552
+
553
+ assertDynamicSlots (
554
+ `<div v-for="i in list">
555
+ <Comp v-slot="{ value = i }"><button @click="fn()" /></Comp>
556
+ </div>` ,
557
+ PatchFlags . DYNAMIC_SLOTS ,
558
+ )
559
+
560
+ assertDynamicSlots (
561
+ `<div v-for="i in list">
562
+ <Comp v-slot:[i]><button @click="fn()" /></Comp>
563
+ </div>` ,
564
+ PatchFlags . DYNAMIC_SLOTS ,
543
565
)
544
566
} )
545
567
0 commit comments