@@ -17,7 +17,8 @@ import {
1717 getBindingAttr ,
1818 getAndRemoveAttr ,
1919 getRawBindingAttr ,
20- pluckModuleFunction
20+ pluckModuleFunction ,
21+ getAndRemoveAttrByRegex
2122} from '../helpers'
2223
2324export const onRE = / ^ @ | ^ v - o n : /
@@ -31,6 +32,8 @@ export const bindRE = /^:|^\.|^v-bind:/
3132const propBindRE = / ^ \. /
3233const modifierRE = / \. [ ^ . ] + / g
3334
35+ const scopedSlotShorthandRE = / ^ : ? \( .* \) $ /
36+
3437const lineBreakRE = / [ \r \n ] /
3538const whitespaceRE = / \s + / g
3639
@@ -568,9 +571,20 @@ function processSlotContent (el) {
568571 getAndRemoveAttr ( el , 'slot-scope' ) ||
569572 // new in 2.6: slot-props and its shorthand works the same as slot-scope
570573 // when used on <template> containers
571- getAndRemoveAttr ( el , 'slot-props' ) ||
572- getAndRemoveAttr ( el , '()' )
574+ getAndRemoveAttr ( el , 'slot-props' )
573575 )
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+ }
574588 } else if ( ( slotScope = getAndRemoveAttr ( el , 'slot-scope' ) ) ) {
575589 /* istanbul ignore if */
576590 if ( process . env . NODE_ENV !== 'production' && el . attrsMap [ 'v-for' ] ) {
@@ -585,19 +599,29 @@ function processSlotContent (el) {
585599 el . slotScope = slotScope
586600 } else {
587601 // 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+ }
595618 }
596619 // add the component's children to its default slot
597620 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 )
599623 slotContainer . children = el . children
600- slotContainer . slotScope = slotScope
624+ slotContainer . slotScope = shorthand ? shorthand . value : slotScope
601625 // remove children as they are returned from scopedSlots now
602626 el . children = [ ]
603627 // mark el non-plain so data gets generated
@@ -617,6 +641,14 @@ function processSlotContent (el) {
617641 }
618642}
619643
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+
620652// handle <slot/> outlets
621653function processSlotOutlet ( el ) {
622654 if ( el . tag === 'slot' ) {
0 commit comments