mirror of https://github.com/vuejs/core.git
wip: adjust slots codegen
This commit is contained in:
parent
4b6100623f
commit
e6d4a24f1f
|
@ -190,6 +190,42 @@ function genModelModifiers(
|
|||
|
||||
function genRawSlots(slots: IRSlots[], context: CodegenContext) {
|
||||
if (!slots.length) return
|
||||
const staticSlots = slots[0]
|
||||
if (staticSlots.slotType === IRSlotType.STATIC) {
|
||||
// single static slot
|
||||
return genStaticSlots(
|
||||
staticSlots,
|
||||
context,
|
||||
slots.length > 1 ? slots.slice(1) : undefined,
|
||||
)
|
||||
} else {
|
||||
return genStaticSlots(
|
||||
{ slotType: IRSlotType.STATIC, slots: {} },
|
||||
context,
|
||||
slots,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
function genStaticSlots(
|
||||
{ slots }: IRSlotsStatic,
|
||||
context: CodegenContext,
|
||||
dynamicSlots?: IRSlots[],
|
||||
) {
|
||||
const args = Object.keys(slots).map(name => [
|
||||
`${JSON.stringify(name)}: `,
|
||||
...genSlotBlockWithProps(slots[name], context),
|
||||
])
|
||||
if (dynamicSlots) {
|
||||
args.push([`$: `, ...genDynamicSlots(dynamicSlots, context)])
|
||||
}
|
||||
return genMulti(DELIMITERS_OBJECT_NEWLINE, ...args)
|
||||
}
|
||||
|
||||
function genDynamicSlots(
|
||||
slots: IRSlots[],
|
||||
context: CodegenContext,
|
||||
): CodeFragment[] {
|
||||
return genMulti(
|
||||
DELIMITERS_ARRAY_NEWLINE,
|
||||
...slots.map(slot =>
|
||||
|
@ -202,17 +238,6 @@ function genRawSlots(slots: IRSlots[], context: CodegenContext) {
|
|||
)
|
||||
}
|
||||
|
||||
function genStaticSlots({ slots }: IRSlotsStatic, context: CodegenContext) {
|
||||
const names = Object.keys(slots)
|
||||
return genMulti(
|
||||
DELIMITERS_OBJECT_NEWLINE,
|
||||
...names.map(name => [
|
||||
`${JSON.stringify(name)}: `,
|
||||
...genSlotBlockWithProps(slots[name], context),
|
||||
]),
|
||||
)
|
||||
}
|
||||
|
||||
function genDynamicSlot(
|
||||
slot: IRSlotDynamic,
|
||||
context: CodegenContext,
|
||||
|
|
|
@ -3,7 +3,6 @@ import { type Block, Fragment, isValidBlock } from './block'
|
|||
import { type RawProps, resolveDynamicProps } from './componentProps'
|
||||
import { currentInstance } from '@vue/runtime-core'
|
||||
import type { VaporComponentInstance } from './component'
|
||||
import { renderEffect } from './renderEffect'
|
||||
|
||||
export type RawSlots = Record<string, Slot> & {
|
||||
$?: (StaticSlots | DynamicSlotFn)[]
|
||||
|
|
Loading…
Reference in New Issue