@@ -160,6 +160,7 @@ export function buildSlots(
160
160
let hasNamedDefaultSlot = false
161
161
const implicitDefaultChildren : TemplateChildNode [ ] = [ ]
162
162
const seenSlotNames = new Set < string > ( )
163
+ let conditionalBranchIndex = 0
163
164
164
165
for ( let i = 0 ; i < children . length ; i ++ ) {
165
166
const slotElement = children [ i ]
@@ -210,7 +211,7 @@ export function buildSlots(
210
211
dynamicSlots . push (
211
212
createConditionalExpression (
212
213
vIf . exp ! ,
213
- buildDynamicSlot ( slotName , slotFunction ) ,
214
+ buildDynamicSlot ( slotName , slotFunction , conditionalBranchIndex ++ ) ,
214
215
defaultFallback
215
216
)
216
217
)
@@ -243,10 +244,14 @@ export function buildSlots(
243
244
conditional . alternate = vElse . exp
244
245
? createConditionalExpression (
245
246
vElse . exp ,
246
- buildDynamicSlot ( slotName , slotFunction ) ,
247
+ buildDynamicSlot (
248
+ slotName ,
249
+ slotFunction ,
250
+ conditionalBranchIndex ++
251
+ ) ,
247
252
defaultFallback
248
253
)
249
- : buildDynamicSlot ( slotName , slotFunction )
254
+ : buildDynamicSlot ( slotName , slotFunction , conditionalBranchIndex ++ )
250
255
} else {
251
256
context . onError (
252
257
createCompilerError ( ErrorCodes . X_V_ELSE_NO_ADJACENT_IF , vElse . loc )
@@ -369,12 +374,19 @@ export function buildSlots(
369
374
370
375
function buildDynamicSlot (
371
376
name : ExpressionNode ,
372
- fn : FunctionExpression
377
+ fn : FunctionExpression ,
378
+ index ?: number
373
379
) : ObjectExpression {
374
- return createObjectExpression ( [
380
+ const props = [
375
381
createObjectProperty ( `name` , name ) ,
376
382
createObjectProperty ( `fn` , fn )
377
- ] )
383
+ ]
384
+ if ( index != null ) {
385
+ props . push (
386
+ createObjectProperty ( `key` , createSimpleExpression ( String ( index ) , true ) )
387
+ )
388
+ }
389
+ return createObjectExpression ( props )
378
390
}
379
391
380
392
function hasForwardedSlots ( children : TemplateChildNode [ ] ) : boolean {
0 commit comments