]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
refactor: update SlotFnBuilder to include parent parameter in buildSlots
authordaiwei <daiwei521@126.com>
Sat, 16 Aug 2025 14:24:06 +0000 (22:24 +0800)
committerdaiwei <daiwei521@126.com>
Sat, 16 Aug 2025 14:24:06 +0000 (22:24 +0800)
packages/compiler-core/src/transforms/vSlot.ts
packages/compiler-ssr/src/transforms/ssrTransformComponent.ts

index 43296dcc9b67a606c4cfafb4309a28bf41b5d1a3..da29d0de8977c343b1009fd4155299ff494db58d 100644 (file)
@@ -100,6 +100,7 @@ export type SlotFnBuilder = (
   vFor: DirectiveNode | undefined,
   slotChildren: TemplateChildNode[],
   loc: SourceLocation,
+  parent: ElementNode,
 ) => FunctionExpression
 
 const buildClientSlotFn: SlotFnBuilder = (props, _vForExp, children, loc) =>
@@ -147,7 +148,7 @@ export function buildSlots(
     slotsProperties.push(
       createObjectProperty(
         arg || createSimpleExpression('default', true),
-        buildSlotFn(exp, undefined, children, loc),
+        buildSlotFn(exp, undefined, children, loc, node),
       ),
     )
   }
@@ -200,7 +201,13 @@ export function buildSlots(
     }
 
     const vFor = findDir(slotElement, 'for')
-    const slotFunction = buildSlotFn(slotProps, vFor, slotChildren, slotLoc)
+    const slotFunction = buildSlotFn(
+      slotProps,
+      vFor,
+      slotChildren,
+      slotLoc,
+      slotElement,
+    )
 
     // check if this slot is conditional (v-if/v-for)
     let vIf: DirectiveNode | undefined
@@ -304,7 +311,7 @@ export function buildSlots(
       props: ExpressionNode | undefined,
       children: TemplateChildNode[],
     ) => {
-      const fn = buildSlotFn(props, undefined, children, loc)
+      const fn = buildSlotFn(props, undefined, children, loc, node)
       if (__COMPAT__ && context.compatConfig) {
         fn.isNonScopedSlot = true
       }
index 94492449e7bf8127b5b8946ca2793307e24032ad..c940bb88ded5eda1a7ec6776805db5b0f8d7a300 100644 (file)
@@ -142,9 +142,9 @@ export const ssrTransformComponent: NodeTransform = (node, context) => {
     // fallback in case the child is render-fn based). Store them in an array
     // for later use.
     if (clonedNode.children.length) {
-      buildSlots(clonedNode, context, (props, vFor, children) => {
+      buildSlots(clonedNode, context, (props, vFor, children, _loc, parent) => {
         vnodeBranches.push(
-          createVNodeSlotBranch(props, vFor, children, context, clonedNode),
+          createVNodeSlotBranch(props, vFor, children, context, parent),
         )
         return createFunctionExpression(undefined)
       })