@@ -17,7 +17,8 @@ import {
17
17
getBindingAttr ,
18
18
getAndRemoveAttr ,
19
19
getRawBindingAttr ,
20
- pluckModuleFunction
20
+ pluckModuleFunction ,
21
+ getAndRemoveAttrByRegex
21
22
} from '../helpers'
22
23
23
24
export const onRE = / ^ @ | ^ v - o n : /
@@ -31,6 +32,8 @@ export const bindRE = /^:|^\.|^v-bind:/
31
32
const propBindRE = / ^ \. /
32
33
const modifierRE = / \. [ ^ . ] + / g
33
34
35
+ const scopedSlotShorthandRE = / ^ : ? \( .* \) $ /
36
+
34
37
const lineBreakRE = / [ \r \n ] /
35
38
const whitespaceRE = / \s + / g
36
39
@@ -568,9 +571,20 @@ function processSlotContent (el) {
568
571
getAndRemoveAttr ( el , 'slot-scope' ) ||
569
572
// new in 2.6: slot-props and its shorthand works the same as slot-scope
570
573
// when used on <template> containers
571
- getAndRemoveAttr ( el , 'slot-props' ) ||
572
- getAndRemoveAttr ( el , '()' )
574
+ getAndRemoveAttr ( el , 'slot-props' )
573
575
)
576
+ // 2.6 shorthand syntax
577
+ const shorthand = getAndRemoveAttrByRegex ( el , scopedSlotShorthandRE )
578
+ if ( shorthand ) {
579
+ if ( process . env . NODE_ENV !== 'production' && el . slotScope ) {
580
+ warn (
581
+ `Unexpected mixed usage of different slot syntaxes.` ,
582
+ el
583
+ )
584
+ }
585
+ el . slotTarget = getScopedSlotShorthandName ( shorthand )
586
+ el . slotScope = shorthand . value
587
+ }
574
588
} else if ( ( slotScope = getAndRemoveAttr ( el , 'slot-scope' ) ) ) {
575
589
/* istanbul ignore if */
576
590
if ( process . env . NODE_ENV !== 'production' && el . attrsMap [ 'v-for' ] ) {
@@ -585,19 +599,29 @@ function processSlotContent (el) {
585
599
el . slotScope = slotScope
586
600
} else {
587
601
// 2.6: slot-props on component, denotes default slot
588
- slotScope = getAndRemoveAttr ( el , 'slot-props' ) || getAndRemoveAttr ( el , '()' )
589
- if ( slotScope ) {
590
- if ( process . env . NODE_ENV !== 'production' && ! maybeComponent ( el ) ) {
591
- warn (
592
- `slot-props cannot be used on non-component elements.` ,
593
- el . rawAttrsMap [ 'slot-props' ] || el . rawAttrsMap [ '()' ]
594
- )
602
+ slotScope = getAndRemoveAttr ( el , 'slot-props' )
603
+ const shorthand = getAndRemoveAttrByRegex ( el , scopedSlotShorthandRE )
604
+ if ( slotScope || shorthand ) {
605
+ if ( process . env . NODE_ENV !== 'production' ) {
606
+ if ( ! maybeComponent ( el ) ) {
607
+ warn (
608
+ `slot-props cannot be used on non-component elements.` ,
609
+ el . rawAttrsMap [ 'slot-props' ] || el . rawAttrsMap [ '()' ]
610
+ )
611
+ }
612
+ if ( slotScope && shorthand ) {
613
+ warn (
614
+ `Unexpected mixed usage of different slot syntaxes.` ,
615
+ el
616
+ )
617
+ }
595
618
}
596
619
// add the component's children to its default slot
597
620
const slots = el . scopedSlots || ( el . scopedSlots = { } )
598
- const slotContainer = slots [ `"default"` ] = createASTElement ( 'template' , [ ] , el )
621
+ const target = shorthand ? getScopedSlotShorthandName ( shorthand ) : `"default"`
622
+ const slotContainer = slots [ target ] = createASTElement ( 'template' , [ ] , el )
599
623
slotContainer . children = el . children
600
- slotContainer . slotScope = slotScope
624
+ slotContainer . slotScope = shorthand ? shorthand . value : slotScope
601
625
// remove children as they are returned from scopedSlots now
602
626
el . children = [ ]
603
627
// mark el non-plain so data gets generated
@@ -617,6 +641,14 @@ function processSlotContent (el) {
617
641
}
618
642
}
619
643
644
+ function getScopedSlotShorthandName ( { name } ) {
645
+ return name . charAt ( 0 ) === ':'
646
+ // dynamic :(name)
647
+ ? name . slice ( 2 , - 1 ) || `"default"`
648
+ // static (name)
649
+ : `"${ name . slice ( 1 , - 1 ) || `default` } "`
650
+ }
651
+
620
652
// handle <slot/> outlets
621
653
function processSlotOutlet ( el ) {
622
654
if ( el . tag === 'slot' ) {
0 commit comments