@@ -5,7 +5,7 @@ import { throwError } from 'shared/util'
5
5
import { VUE_VERSION } from 'shared/consts'
6
6
7
7
function isDestructuringSlotScope ( slotScope : string ) : boolean {
8
- return slotScope [ 0 ] === '{' && slotScope [ slotScope . length - 1 ] === '}'
8
+ return / ^ { . * } $ / . test ( slotScope )
9
9
}
10
10
11
11
function getVueTemplateCompilerHelpers (
@@ -46,7 +46,36 @@ function validateEnvironment(): void {
46
46
}
47
47
}
48
48
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
+ }
50
79
51
80
// Hide warning about <template> disallowed as root element
52
81
function customWarn ( msg ) {
@@ -70,14 +99,18 @@ export default function createScopedSlots(
70
99
for ( const scopedSlotName in scopedSlotsOption ) {
71
100
const slot = scopedSlotsOption [ scopedSlotName ]
72
101
const isFn = typeof slot === 'function'
102
+
103
+ const scopedSlotMatches = isScopedSlot ( slot )
104
+
73
105
// Type check to silence flow (can't use isFn)
74
106
const renderFn =
75
107
typeof slot === 'function'
76
108
? slot
77
- : compileToFunctions ( slot , { warn : customWarn } ) . render
109
+ : compileToFunctions ( scopedSlotMatches . slot , { warn : customWarn } )
110
+ . render
111
+
112
+ const slotScope = scopedSlotMatches . match && scopedSlotMatches . match [ 1 ]
78
113
79
- const hasSlotScopeAttr = ! isFn && slot . match ( slotScopeRe )
80
- const slotScope = hasSlotScopeAttr && hasSlotScopeAttr [ 1 ]
81
114
scopedSlots [ scopedSlotName ] = function ( props ) {
82
115
let res
83
116
if ( isFn ) {
0 commit comments