]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(compiler-vapor): handle no template
author三咲智子 Kevin Deng <sxzz@sxzz.moe>
Mon, 29 Jan 2024 15:06:21 +0000 (23:06 +0800)
committer三咲智子 Kevin Deng <sxzz@sxzz.moe>
Mon, 29 Jan 2024 15:06:21 +0000 (23:06 +0800)
packages/compiler-vapor/src/generate.ts
packages/compiler-vapor/src/ir.ts
packages/compiler-vapor/src/transform.ts

index b673e0585a1af7ec2b3147e044a482d564607523..e629138617396c0a37335d68a10e6e25f810643f 100644 (file)
@@ -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}: [`
index f79c8784180e159e5e8e6ac26aa0ebd00fedd21b..a9c9d8f7cfb8c030dc18a88198b2807f504c6abc 100644 (file)
@@ -199,7 +199,7 @@ export enum DynamicFlag {
 export interface IRDynamicInfo {
   id: number | null
   dynamicFlags: DynamicFlag
-  placeholder: number | null
+  anchor: number | null
   children: IRDynamicInfo[]
 }
 
index 61f0f6e8937753b65b8810efdb790f336cda0fea..49c52fc2a0479f55451dcee2e962ab04a1ebbac4 100644 (file)
@@ -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,