File tree 2 files changed +26
-3
lines changed
test/unit/features/component
2 files changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -617,7 +617,7 @@ function childrenHas$Slot (el): boolean {
617
617
return el . children ? el . children . some ( nodeHas$Slot ) : false
618
618
}
619
619
620
- const $slotRE = / \$ s l o t /
620
+ const $slotRE = / ( ^ | [ ^ \w _ $ ] ) \$ s l o t ( $ | [ ^ \w _ $ ] ) /
621
621
function nodeHas$Slot ( node ) : boolean {
622
622
// caching
623
623
if ( hasOwn ( node , 'has$Slot' ) ) {
Original file line number Diff line number Diff line change @@ -690,10 +690,33 @@ describe('Component scoped slot', () => {
690
690
expect ( vm . $el . innerHTML ) . toBe ( `default<div>default</div><div>static</div>` )
691
691
} )
692
692
693
+ // testing $slot detection: bracket access, using $slot alone, passing as arguments...
694
+ it ( 'should work for alternative $slot usage' , ( ) => {
695
+ const vm = new Vue ( {
696
+ template : `<foo>{{ $slot['foo'] }}<div slot="foo">{{ $slot }}</div><div>{{ pick($slot) }}</div></foo>` ,
697
+ methods : { pick : s => s . foo } ,
698
+ components : { foo : { template : `<div><slot foo="default"/><slot name="foo"/></div>` } }
699
+ } ) . $mount ( )
700
+ expect ( vm . $el . innerHTML ) . toBe ( `default<div>default</div><div>{}</div>` )
701
+ } )
702
+
703
+ // should not consider detection if $slot is inside longer valid identifier
693
704
it ( 'should not break when template expression uses $slots' , ( ) => {
694
705
const vm = new Vue ( {
695
- template : ``
696
- } )
706
+ data : { some$slot : 123 } ,
707
+ template : `<foo>{{ some$slot }}<div slot="foo">{{ $slots }}</div></foo>` ,
708
+ components : {
709
+ foo : {
710
+ render ( h ) {
711
+ // should be compiled as normal slots
712
+ expect ( this . $slots . default ) . toBeTruthy ( )
713
+ expect ( this . $slots . foo ) . toBeTruthy ( )
714
+ return h ( 'div' , [ this . $slots . default , this . $slots . foo ] )
715
+ }
716
+ }
717
+ }
718
+ } ) . $mount ( )
719
+ expect ( vm . $el . innerHTML ) . toBe ( `123<div>{}</div>` )
697
720
} )
698
721
} )
699
722
} )
You can’t perform that action at this time.
0 commit comments