]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
wip: adjust slots codegen
authorEvan You <evan@vuejs.org>
Sat, 7 Dec 2024 10:27:57 +0000 (18:27 +0800)
committerEvan You <evan@vuejs.org>
Sat, 7 Dec 2024 10:30:33 +0000 (18:30 +0800)
packages/compiler-vapor/src/generators/component.ts
packages/runtime-vapor/src/componentSlots.ts

index b6e2c621362f4fa61467ed6fa5b25b04b8097665..4ab96d3b6ec6a4e21f08bb44178def3b232b7a05 100644 (file)
@@ -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,
index dd78e7bd71b762c7cc526bac2a7854d0d98b1dab..7557f79e0771f370b0101f7fb1bbde31c459b2c8 100644 (file)
@@ -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)[]