Skip to content
This repository was archived by the owner on Jul 19, 2025. It is now read-only.

Commit 8ccfce5

Browse files
authored
refactor(compiler/runtime-vapor): remove unnecessary slot key (#225)
1 parent 8a59311 commit 8ccfce5

File tree

6 files changed

+6
-29
lines changed

6 files changed

+6
-29
lines changed

packages/compiler-vapor/__tests__/transforms/__snapshots__/vSlot.spec.ts.snap

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,25 +65,22 @@ export function render(_ctx) {
6565
fn: () => {
6666
const n0 = t0()
6767
return n0
68-
},
69-
key: "0"
68+
}
7069
}
7170
: _ctx.anotherCondition
7271
? {
7372
name: "condition",
7473
fn: _withDestructure(({ foo, bar }) => [foo, bar], (_ctx0) => {
7574
const n2 = t1()
7675
return n2
77-
}),
78-
key: "1"
76+
})
7977
}
8078
: {
8179
name: "condition",
8280
fn: () => {
8381
const n4 = t2()
8482
return n4
85-
},
86-
key: "2"
83+
}
8784
})], true)
8885
return n6
8986
}"

packages/compiler-vapor/__tests__/transforms/vSlot.spec.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,6 @@ describe('compiler: transform slot', () => {
290290
loop: {
291291
source: { content: 'list' },
292292
value: { content: 'item' },
293-
key: undefined,
294293
index: undefined,
295294
},
296295
},
@@ -323,7 +322,6 @@ describe('compiler: transform slot', () => {
323322
loop: {
324323
source: { content: 'list' },
325324
value: undefined,
326-
key: undefined,
327325
index: {
328326
type: NodeTypes.SIMPLE_EXPRESSION,
329327
},
@@ -359,16 +357,14 @@ describe('compiler: transform slot', () => {
359357
condition: { content: 'condition' },
360358
positive: {
361359
slotType: DynamicSlotType.BASIC,
362-
key: 0,
363360
},
364361
negative: {
365362
slotType: DynamicSlotType.CONDITIONAL,
366363
condition: { content: 'anotherCondition' },
367364
positive: {
368365
slotType: DynamicSlotType.BASIC,
369-
key: 1,
370366
},
371-
negative: { slotType: DynamicSlotType.BASIC, key: 2 },
367+
negative: { slotType: DynamicSlotType.BASIC },
372368
},
373369
},
374370
],

packages/compiler-vapor/src/generators/component.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,12 +199,11 @@ function genBasicDynamicSlot(
199199
slot: ComponentBasicDynamicSlot,
200200
context: CodegenContext,
201201
): CodeFragment[] {
202-
const { name, fn, key } = slot
202+
const { name, fn } = slot
203203
return genMulti(
204204
DELIMITERS_OBJECT_NEWLINE,
205205
['name: ', ...genExpression(name, context)],
206206
['fn: ', ...genSlotBlockWithProps(fn, context)],
207-
...(key !== undefined ? [`key: "${key}"`] : []),
208207
)
209208
}
210209

packages/compiler-vapor/src/ir.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,6 @@ export interface ComponentBasicDynamicSlot {
222222
slotType: DynamicSlotType.BASIC
223223
name: SimpleExpressionNode
224224
fn: ComponentSlotBlockIRNode
225-
key?: number
226225
}
227226

228227
export interface ComponentLoopDynamicSlot {

packages/compiler-vapor/src/transforms/vSlot.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ export const transformVSlot: NodeTransform = (node, context) => {
135135
slotType: DynamicSlotType.BASIC,
136136
name: arg!,
137137
fn: block,
138-
key: 0,
139138
},
140139
})
141140
} else if (vElse) {
@@ -157,14 +156,12 @@ export const transformVSlot: NodeTransform = (node, context) => {
157156
slotType: DynamicSlotType.BASIC,
158157
name: arg!,
159158
fn: block,
160-
key: ifNode.positive.key! + 1,
161159
},
162160
}
163161
: {
164162
slotType: DynamicSlotType.BASIC,
165163
name: arg!,
166164
fn: block,
167-
key: ifNode.positive.key! + 1,
168165
}
169166
ifNode.negative = negative
170167
} else {

packages/runtime-vapor/src/componentSlots.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ export type Slots = Readonly<InternalSlots>
3030
export interface DynamicSlot {
3131
name: string
3232
fn: Slot
33-
key?: string
3433
}
3534

3635
type DynamicSlotFn = () => DynamicSlot | DynamicSlot[]
@@ -72,17 +71,7 @@ export function initSlots(
7271
}
7372
} else if (dynamicSlot) {
7473
// conditional single slot generated by <template v-if="..." #foo>
75-
slots[dynamicSlot.name] = withCtx(
76-
dynamicSlot.key
77-
? (...args: any[]) => {
78-
const res = dynamicSlot.fn(...args)
79-
// attach branch key so each conditional branch is considered a
80-
// different fragment
81-
if (res) (res as any).key = dynamicSlot.key
82-
return res
83-
}
84-
: dynamicSlot.fn,
85-
)
74+
slots[dynamicSlot.name] = withCtx(dynamicSlot.fn)
8675
slotRecord[dynamicSlot.name] = true
8776
}
8877
// delete stale slots

0 commit comments

Comments
 (0)