@@ -5,7 +5,7 @@ import { throwError } from 'shared/util'
55import { VUE_VERSION } from 'shared/consts'
66
77function isDestructuringSlotScope ( slotScope : string ) : boolean {
8- return slotScope [ 0 ] === '{' && slotScope [ slotScope . length - 1 ] === '}'
8+ return / ^ { . * } $ / . test ( slotScope )
99}
1010
1111function getVueTemplateCompilerHelpers (
@@ -46,7 +46,36 @@ function validateEnvironment(): void {
4646 }
4747}
4848
49- const slotScopeRe = / < [ ^ > ] + s l o t - s c o p e = \" ( .+ ) \" /
49+ function isScopedSlot ( slot ) {
50+ if ( typeof slot === 'function' ) return { match : null , slot }
51+
52+ const slotScopeRe = / < [ ^ > ] + s l o t - s c o p e = " ( .+ ) " /
53+ const vSlotRe = / < t e m p l a t e v - s l o t (?: : .+ ) ? = " ( .+ ) " /
54+ const shortVSlotRe = / < t e m p l a t e # .* = " ( .+ ) " /
55+
56+ const hasOldSlotScope = slot . match ( slotScopeRe )
57+ const hasVSlotScopeAttr = slot . match ( vSlotRe )
58+ const hasShortVSlotScopeAttr = slot . match ( shortVSlotRe )
59+
60+ if ( hasOldSlotScope ) {
61+ return { slot, match : hasOldSlotScope }
62+ } else if ( hasVSlotScopeAttr || hasShortVSlotScopeAttr ) {
63+ // Strip v-slot and #slot attributes from `template` tag. compileToFunctions leaves empty `template` tag otherwise.
64+ const sanitizedSlot = slot . replace (
65+ / ( < t e m p l a t e ) ( [ ^ > ] + ) ( > .+ < \/ t e m p l a t e > ) / ,
66+ '$1$3'
67+ )
68+ return {
69+ slot : sanitizedSlot ,
70+ match : hasVSlotScopeAttr || hasShortVSlotScopeAttr
71+ }
72+ }
73+ // we have no matches, so we just return
74+ return {
75+ slot : slot ,
76+ match : null
77+ }
78+ }
5079
5180// Hide warning about <template> disallowed as root element
5281function customWarn ( msg ) {
@@ -70,14 +99,18 @@ export default function createScopedSlots(
7099 for ( const scopedSlotName in scopedSlotsOption ) {
71100 const slot = scopedSlotsOption [ scopedSlotName ]
72101 const isFn = typeof slot === 'function'
102+
103+ const scopedSlotMatches = isScopedSlot ( slot )
104+
73105 // Type check to silence flow (can't use isFn)
74106 const renderFn =
75107 typeof slot === 'function'
76108 ? slot
77- : compileToFunctions ( slot , { warn : customWarn } ) . render
109+ : compileToFunctions ( scopedSlotMatches . slot , { warn : customWarn } )
110+ . render
111+
112+ const slotScope = scopedSlotMatches . match && scopedSlotMatches . match [ 1 ]
78113
79- const hasSlotScopeAttr = ! isFn && slot . match ( slotScopeRe )
80- const slotScope = hasSlotScopeAttr && hasSlotScopeAttr [ 1 ]
81114 scopedSlots [ scopedSlotName ] = function ( props ) {
82115 let res
83116 if ( isFn ) {
0 commit comments