diff --git a/packages/compiler-vapor/src/generators/component.ts b/packages/compiler-vapor/src/generators/component.ts index b6e2c6213..4ab96d3b6 100644 --- a/packages/compiler-vapor/src/generators/component.ts +++ b/packages/compiler-vapor/src/generators/component.ts @@ -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, diff --git a/packages/runtime-vapor/src/componentSlots.ts b/packages/runtime-vapor/src/componentSlots.ts index dd78e7bd7..7557f79e0 100644 --- a/packages/runtime-vapor/src/componentSlots.ts +++ b/packages/runtime-vapor/src/componentSlots.ts @@ -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 & { $?: (StaticSlots | DynamicSlotFn)[]