]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
chore: update
authordaiwei <daiwei521@126.com>
Fri, 30 May 2025 01:17:04 +0000 (09:17 +0800)
committerdaiwei <daiwei521@126.com>
Fri, 30 May 2025 01:40:54 +0000 (09:40 +0800)
packages/compiler-vapor/src/transform.ts
packages/compiler-vapor/src/transforms/transformSlotOutlet.ts
packages/compiler-vapor/src/transforms/vSlot.ts
packages/runtime-vapor/__tests__/componentSlots.spec.ts
packages/runtime-vapor/src/componentSlots.ts

index 6d07ebcaf52dd2109ca5ef5e15424ebb35084ad2..763e9612cdcc0536e619fd3d483f1a1c00623e33 100644 (file)
@@ -76,7 +76,7 @@ export class TransformContext<T extends AllNode = AllNode> {
 
   inVOnce: boolean = false
   inVFor: number = 0
-  inSlot: number = 0
+  inSlot: boolean = false
 
   comment: CommentNode[] = []
   component: Set<string> = this.ir.component
index a281c90a70d2e1939f46acca59439eefa931175c..dc2b620ddb25f5f769812a7c089e6dee20b2f231 100644 (file)
@@ -5,7 +5,6 @@ import {
   ErrorCodes,
   NodeTypes,
   type SimpleExpressionNode,
-  type TemplateChildNode,
   createCompilerError,
   createSimpleExpression,
   isStaticArgOf,
@@ -100,16 +99,7 @@ export const transformSlotOutlet: NodeTransform = (node, context) => {
   }
 
   return () => {
-    const {
-      block: { node: slotNode },
-      inSlot,
-    } = context
-    const forwarded =
-      inSlot !== 0 &&
-      slotNode.type === NodeTypes.ELEMENT &&
-      hasForwardedSlots(slotNode.children)
-    if (forwarded) context.ir.hasForwardedSlot = true
-
+    if (context.inSlot) context.ir.hasForwardedSlot = true
     exitBlock && exitBlock()
     context.dynamic.operation = {
       type: IRNodeTypes.SLOT_OUTLET_NODE,
@@ -117,7 +107,7 @@ export const transformSlotOutlet: NodeTransform = (node, context) => {
       name: slotName,
       props: irProps,
       fallback,
-      forwarded,
+      forwarded: context.inSlot,
     }
   }
 }
@@ -143,20 +133,3 @@ function createFallback(
   context.reference()
   return [fallback, exitBlock]
 }
-
-function hasForwardedSlots(children: TemplateChildNode[]): boolean {
-  for (let i = 0; i < children.length; i++) {
-    const child = children[i]
-    switch (child.type) {
-      case NodeTypes.ELEMENT:
-        if (
-          child.tagType === ElementTypes.SLOT ||
-          hasForwardedSlots(child.children)
-        ) {
-          return true
-        }
-        break
-    }
-  }
-  return false
-}
index 2e767cb41cd412792a2eb953b3d33ccd43b4c5de..525fa323d3a569a9c557d05f3aa12d7ece2394b5 100644 (file)
@@ -237,11 +237,11 @@ function createSlotBlock(
   const block: SlotBlockIRNode = newBlock(slotNode)
   block.props = dir && dir.exp
   const exitBlock = context.enterBlock(block)
-  context.inSlot++
+  context.inSlot = true
   return [
     block,
     () => {
-      context.inSlot--
+      context.inSlot = false
       exitBlock()
     },
   ]
index 46bfc3d938d03bf265e6ee0a90cf1629d6494f33..bdbd960363dbc783267b26fc9f3e5c8759008ec4 100644 (file)
@@ -554,5 +554,56 @@ describe('component: slots', () => {
       await nextTick()
       expect(host.innerHTML).toBe('bar<!--slot--><!--slot-->')
     })
+
+    test('mixed with non-forwarded slot', async () => {
+      const Child = defineVaporComponent({
+        setup() {
+          return [createSlot('foo', null)]
+        },
+      })
+      const Parent = defineVaporComponent({
+        setup() {
+          const createForwardedSlot = forwardedSlotCreator()
+          const n2 = createComponent(Child, null, {
+            foo: () => {
+              const n0 = createForwardedSlot('foo', null)
+              return n0
+            },
+          })
+          const n3 = createSlot('default', null)
+          return [n2, n3]
+        },
+      })
+
+      const foo = ref('foo')
+      const { host } = define({
+        setup() {
+          const n2 = createComponent(
+            Parent,
+            null,
+            {
+              foo: () => {
+                const n0 = template(' ')() as any
+                renderEffect(() => setText(n0, foo.value))
+                return n0
+              },
+              default: () => {
+                const n3 = template(' ')() as any
+                renderEffect(() => setText(n3, foo.value))
+                return n3
+              },
+            },
+            true,
+          )
+          return n2
+        },
+      }).render()
+
+      expect(host.innerHTML).toBe('foo<!--slot--><!--slot-->foo<!--slot-->')
+
+      foo.value = 'bar'
+      await nextTick()
+      expect(host.innerHTML).toBe('bar<!--slot--><!--slot-->bar<!--slot-->')
+    })
   })
 })
index 00ae4ea29ac75959620dfde6db8377fd95776035..19e9b5b6d1a9b51d9e1fa8df7d2dbf0f97c3cbdb 100644 (file)
@@ -93,11 +93,8 @@ export function forwardedSlotCreator(): (
   fallback?: VaporSlot,
 ) => Block {
   const instance = currentInstance as VaporComponentInstance
-  return (
-    name: string | (() => string),
-    rawProps?: LooseRawProps | null,
-    fallback?: VaporSlot,
-  ) => createSlot(name, rawProps, fallback, instance)
+  return (name, rawProps, fallback) =>
+    createSlot(name, rawProps, fallback, instance)
 }
 
 export function createSlot(