Просмотр исходного кода

fix(compiler-vapor): handle no template

三咲智子 Kevin Deng 2 лет назад
Родитель
Сommit
48d2aa3bcb

+ 10 - 7
packages/compiler-vapor/src/generate.ts

@@ -10,7 +10,7 @@ import {
 import {
   type BlockFunctionIRNode,
   DynamicFlag,
-  type IRDynamicChildren,
+  type IRDynamicInfo,
   IRNodeTypes,
   type OperationNode,
   type RootIRNode,
@@ -313,20 +313,23 @@ export function generate(
   }
 }
 
-function genChildren(children: IRDynamicChildren) {
+function genChildren(children: IRDynamicInfo[]) {
   let code = ''
   let offset = 0
-  for (const [index, child] of Object.entries(children)) {
-    const childrenLength = Object.keys(child.children).length
+
+  for (const [index, child] of children.entries()) {
     if (child.dynamicFlags & DynamicFlag.NON_TEMPLATE) {
       offset--
-      continue
     }
 
     const idx = Number(index) + offset
     const id =
-      child.dynamicFlags & DynamicFlag.INSERT ? child.placeholder : child.id
-    const childrenString = childrenLength && genChildren(child.children)
+      child.dynamicFlags & DynamicFlag.REFERENCED
+        ? child.dynamicFlags & DynamicFlag.INSERT
+          ? child.anchor
+          : child.id
+        : null
+    const childrenString = genChildren(child.children)
 
     if (id !== null || childrenString) {
       code += ` ${idx}: [`

+ 1 - 1
packages/compiler-vapor/src/ir.ts

@@ -199,7 +199,7 @@ export enum DynamicFlag {
 export interface IRDynamicInfo {
   id: number | null
   dynamicFlags: DynamicFlag
-  placeholder: number | null
+  anchor: number | null
   children: IRDynamicInfo[]
 }
 

+ 4 - 2
packages/compiler-vapor/src/transform.ts

@@ -102,7 +102,7 @@ const defaultOptions = {
 export const genDefaultDynamic = (): IRDynamicInfo => ({
   id: null,
   dynamicFlags: 0,
-  placeholder: null,
+  anchor: null,
   children: [],
 })
 
@@ -335,7 +335,9 @@ function processDynamicChildren(ctx: TransformContext<RootNode | ElementNode>) {
       if (prevChildren.length) {
         if (hasStatic) {
           ctx.childrenTemplate[index - prevChildren.length] = `<!>`
-          const anchor = (prevChildren[0].placeholder = ctx.increaseId())
+
+          prevChildren[0].dynamicFlags -= DynamicFlag.NON_TEMPLATE
+          const anchor = (prevChildren[0].anchor = ctx.increaseId())
 
           ctx.registerOperation({
             type: IRNodeTypes.INSERT_NODE,