]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
refactor: gen set $dp
authordaiwei <daiwei521@126.com>
Mon, 4 Aug 2025 03:41:28 +0000 (11:41 +0800)
committerdaiwei <daiwei521@126.com>
Mon, 4 Aug 2025 03:41:28 +0000 (11:41 +0800)
packages/compiler-vapor/__tests__/__snapshots__/compile.spec.ts.snap
packages/compiler-vapor/src/generators/template.ts
packages/runtime-vapor/src/dom/template.ts

index d243b362164e12bc0ae4d4a548b9be89d3c7310b..693e6593f4004a942243a9a7313b4c370f649304 100644 (file)
@@ -218,7 +218,7 @@ const t0 = _template("<div><div></div></div>", true)
 
 export function render(_ctx) {
   const _component_Comp = _resolveComponent("Comp")
-  const n3 = t0(1)
+  const n3 = t0(); n3.$dp = 1;
   const n1 = _child(n3)
   _setInsertionState(n1)
   const n0 = _createSlot("default", null)
index b42e2093f9c998b13407a67a1567f9f883b27547..1fec07f38db4f237c8e9ce622fc83cd786285dd4 100644 (file)
@@ -28,7 +28,8 @@ export function genSelf(
     dynamic
 
   if (id !== undefined && template !== undefined) {
-    push(NEWLINE, `const n${id} = t${template}(${dynamicChildOffset || ''})`)
+    push(NEWLINE, `const n${id} = t${template}()`)
+    if (dynamicChildOffset) push(`; n${id}.$dp = ${dynamicChildOffset};`)
     push(...genDirectivesForElement(id, context))
   }
 
@@ -114,6 +115,10 @@ export function genChildren(
       }
     }
 
+    if (child.dynamicChildOffset) {
+      pushBlock(`; ${variable}.$dp = ${child.dynamicChildOffset};`)
+    }
+
     if (id === child.anchor && !child.hasDynamicChild) {
       push(...genSelf(child, context))
     }
index 6423b626416083d929d714642aeaf7a97ec6cd86..dbe2c35832e582b4368c10bc5e9375dd9309da86 100644 (file)
@@ -6,15 +6,13 @@ let t: HTMLTemplateElement
 /*! #__NO_SIDE_EFFECTS__ */
 export function template(html: string, root?: boolean) {
   let node: Node
-  return (n?: number): Node & { $root?: true } => {
+  return (): Node & { $root?: true } => {
     if (isHydrating) {
       if (__DEV__ && !currentHydrationNode) {
         // TODO this should not happen
         throw new Error('No current hydration node')
       }
       node = adoptTemplate(currentHydrationNode!, html)!
-      // dynamic node position, default is 0
-      ;(node as any).$dp = n || 0
       if (root) (node as any).$root = true
       return node
     }