refactor(compiler/runtime-vapor): remove unnecessary slot key (#225)
This commit is contained in:
parent
8a59311a22
commit
8ccfce5ec7
|
@ -65,8 +65,7 @@ export function render(_ctx) {
|
||||||
fn: () => {
|
fn: () => {
|
||||||
const n0 = t0()
|
const n0 = t0()
|
||||||
return n0
|
return n0
|
||||||
},
|
}
|
||||||
key: "0"
|
|
||||||
}
|
}
|
||||||
: _ctx.anotherCondition
|
: _ctx.anotherCondition
|
||||||
? {
|
? {
|
||||||
|
@ -74,16 +73,14 @@ export function render(_ctx) {
|
||||||
fn: _withDestructure(({ foo, bar }) => [foo, bar], (_ctx0) => {
|
fn: _withDestructure(({ foo, bar }) => [foo, bar], (_ctx0) => {
|
||||||
const n2 = t1()
|
const n2 = t1()
|
||||||
return n2
|
return n2
|
||||||
}),
|
})
|
||||||
key: "1"
|
|
||||||
}
|
}
|
||||||
: {
|
: {
|
||||||
name: "condition",
|
name: "condition",
|
||||||
fn: () => {
|
fn: () => {
|
||||||
const n4 = t2()
|
const n4 = t2()
|
||||||
return n4
|
return n4
|
||||||
},
|
}
|
||||||
key: "2"
|
|
||||||
})], true)
|
})], true)
|
||||||
return n6
|
return n6
|
||||||
}"
|
}"
|
||||||
|
|
|
@ -290,7 +290,6 @@ describe('compiler: transform slot', () => {
|
||||||
loop: {
|
loop: {
|
||||||
source: { content: 'list' },
|
source: { content: 'list' },
|
||||||
value: { content: 'item' },
|
value: { content: 'item' },
|
||||||
key: undefined,
|
|
||||||
index: undefined,
|
index: undefined,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -323,7 +322,6 @@ describe('compiler: transform slot', () => {
|
||||||
loop: {
|
loop: {
|
||||||
source: { content: 'list' },
|
source: { content: 'list' },
|
||||||
value: undefined,
|
value: undefined,
|
||||||
key: undefined,
|
|
||||||
index: {
|
index: {
|
||||||
type: NodeTypes.SIMPLE_EXPRESSION,
|
type: NodeTypes.SIMPLE_EXPRESSION,
|
||||||
},
|
},
|
||||||
|
@ -359,16 +357,14 @@ describe('compiler: transform slot', () => {
|
||||||
condition: { content: 'condition' },
|
condition: { content: 'condition' },
|
||||||
positive: {
|
positive: {
|
||||||
slotType: DynamicSlotType.BASIC,
|
slotType: DynamicSlotType.BASIC,
|
||||||
key: 0,
|
|
||||||
},
|
},
|
||||||
negative: {
|
negative: {
|
||||||
slotType: DynamicSlotType.CONDITIONAL,
|
slotType: DynamicSlotType.CONDITIONAL,
|
||||||
condition: { content: 'anotherCondition' },
|
condition: { content: 'anotherCondition' },
|
||||||
positive: {
|
positive: {
|
||||||
slotType: DynamicSlotType.BASIC,
|
slotType: DynamicSlotType.BASIC,
|
||||||
key: 1,
|
|
||||||
},
|
},
|
||||||
negative: { slotType: DynamicSlotType.BASIC, key: 2 },
|
negative: { slotType: DynamicSlotType.BASIC },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
|
@ -199,12 +199,11 @@ function genBasicDynamicSlot(
|
||||||
slot: ComponentBasicDynamicSlot,
|
slot: ComponentBasicDynamicSlot,
|
||||||
context: CodegenContext,
|
context: CodegenContext,
|
||||||
): CodeFragment[] {
|
): CodeFragment[] {
|
||||||
const { name, fn, key } = slot
|
const { name, fn } = slot
|
||||||
return genMulti(
|
return genMulti(
|
||||||
DELIMITERS_OBJECT_NEWLINE,
|
DELIMITERS_OBJECT_NEWLINE,
|
||||||
['name: ', ...genExpression(name, context)],
|
['name: ', ...genExpression(name, context)],
|
||||||
['fn: ', ...genSlotBlockWithProps(fn, context)],
|
['fn: ', ...genSlotBlockWithProps(fn, context)],
|
||||||
...(key !== undefined ? [`key: "${key}"`] : []),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -222,7 +222,6 @@ export interface ComponentBasicDynamicSlot {
|
||||||
slotType: DynamicSlotType.BASIC
|
slotType: DynamicSlotType.BASIC
|
||||||
name: SimpleExpressionNode
|
name: SimpleExpressionNode
|
||||||
fn: ComponentSlotBlockIRNode
|
fn: ComponentSlotBlockIRNode
|
||||||
key?: number
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ComponentLoopDynamicSlot {
|
export interface ComponentLoopDynamicSlot {
|
||||||
|
|
|
@ -135,7 +135,6 @@ export const transformVSlot: NodeTransform = (node, context) => {
|
||||||
slotType: DynamicSlotType.BASIC,
|
slotType: DynamicSlotType.BASIC,
|
||||||
name: arg!,
|
name: arg!,
|
||||||
fn: block,
|
fn: block,
|
||||||
key: 0,
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
} else if (vElse) {
|
} else if (vElse) {
|
||||||
|
@ -157,14 +156,12 @@ export const transformVSlot: NodeTransform = (node, context) => {
|
||||||
slotType: DynamicSlotType.BASIC,
|
slotType: DynamicSlotType.BASIC,
|
||||||
name: arg!,
|
name: arg!,
|
||||||
fn: block,
|
fn: block,
|
||||||
key: ifNode.positive.key! + 1,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
: {
|
: {
|
||||||
slotType: DynamicSlotType.BASIC,
|
slotType: DynamicSlotType.BASIC,
|
||||||
name: arg!,
|
name: arg!,
|
||||||
fn: block,
|
fn: block,
|
||||||
key: ifNode.positive.key! + 1,
|
|
||||||
}
|
}
|
||||||
ifNode.negative = negative
|
ifNode.negative = negative
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -30,7 +30,6 @@ export type Slots = Readonly<InternalSlots>
|
||||||
export interface DynamicSlot {
|
export interface DynamicSlot {
|
||||||
name: string
|
name: string
|
||||||
fn: Slot
|
fn: Slot
|
||||||
key?: string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type DynamicSlotFn = () => DynamicSlot | DynamicSlot[]
|
type DynamicSlotFn = () => DynamicSlot | DynamicSlot[]
|
||||||
|
@ -72,17 +71,7 @@ export function initSlots(
|
||||||
}
|
}
|
||||||
} else if (dynamicSlot) {
|
} else if (dynamicSlot) {
|
||||||
// conditional single slot generated by <template v-if="..." #foo>
|
// conditional single slot generated by <template v-if="..." #foo>
|
||||||
slots[dynamicSlot.name] = withCtx(
|
slots[dynamicSlot.name] = withCtx(dynamicSlot.fn)
|
||||||
dynamicSlot.key
|
|
||||||
? (...args: any[]) => {
|
|
||||||
const res = dynamicSlot.fn(...args)
|
|
||||||
// attach branch key so each conditional branch is considered a
|
|
||||||
// different fragment
|
|
||||||
if (res) (res as any).key = dynamicSlot.key
|
|
||||||
return res
|
|
||||||
}
|
|
||||||
: dynamicSlot.fn,
|
|
||||||
)
|
|
||||||
slotRecord[dynamicSlot.name] = true
|
slotRecord[dynamicSlot.name] = true
|
||||||
}
|
}
|
||||||
// delete stale slots
|
// delete stale slots
|
||||||
|
|
Loading…
Reference in New Issue