From: 三咲智子 Kevin Deng Date: Mon, 29 Jan 2024 14:28:40 +0000 (+0800) Subject: refactor(compiler-vapor): make dynamic.children an array X-Git-Tag: v3.6.0-alpha.1~16^2~639 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ed9368c06c146ca4260bdae194d98fdf64b3bb10;p=thirdparty%2Fvuejs%2Fcore.git refactor(compiler-vapor): make dynamic.children an array --- diff --git a/packages/compiler-vapor/src/ir.ts b/packages/compiler-vapor/src/ir.ts index 40b79cf6e7..f79c878418 100644 --- a/packages/compiler-vapor/src/ir.ts +++ b/packages/compiler-vapor/src/ir.ts @@ -200,9 +200,8 @@ export interface IRDynamicInfo { id: number | null dynamicFlags: DynamicFlag placeholder: number | null - children: IRDynamicChildren + children: IRDynamicInfo[] } -export type IRDynamicChildren = Record export type IRExpression = SimpleExpressionNode | string export interface IREffect { diff --git a/packages/compiler-vapor/src/transform.ts b/packages/compiler-vapor/src/transform.ts index 073b4ad6a7..61f0f6e893 100644 --- a/packages/compiler-vapor/src/transform.ts +++ b/packages/compiler-vapor/src/transform.ts @@ -103,7 +103,7 @@ export const genDefaultDynamic = (): IRDynamicInfo => ({ id: null, dynamicFlags: 0, placeholder: null, - children: {}, + children: [], }) // TODO use class for better perf @@ -313,9 +313,8 @@ function transformNode( function transformChildren(ctx: TransformContext) { const { children } = ctx.node - let i = 0 - for (; i < children.length; i++) { - const child = children[i] + + for (const [i, child] of children.entries()) { const childContext = createContext(child, ctx, i) transformNode(childContext) ctx.childrenTemplate.push(childContext.template) @@ -331,9 +330,7 @@ function processDynamicChildren(ctx: TransformContext) { let prevChildren: IRDynamicInfo[] = [] let hasStatic = false - for (let index = 0; index < node.children.length; index++) { - const child = ctx.dynamic.children[index] - + for (const [index, child] of ctx.dynamic.children.entries()) { if (!child || !(child.dynamicFlags & DynamicFlag.INSERT)) { if (prevChildren.length) { if (hasStatic) { @@ -363,7 +360,7 @@ function processDynamicChildren(ctx: TransformContext) { prevChildren.push(child) - if (index === node.children.length - 1) { + if (index === ctx.dynamic.children.length - 1) { ctx.registerOperation({ type: IRNodeTypes.APPEND_NODE, loc: node.loc,