daiwei 10 месяцев назад
Родитель
Сommit
67995a1825

+ 1 - 1
packages/compiler-vapor/__tests__/__snapshots__/compile.spec.ts.snap

@@ -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)

+ 6 - 1
packages/compiler-vapor/src/generators/template.ts

@@ -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))
     }

+ 1 - 3
packages/runtime-vapor/src/dom/template.ts

@@ -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
     }