mirror of https://github.com/vuejs/core.git
refactor(compiler-vapor): make dynamic.children an array
This commit is contained in:
parent
22436ea341
commit
ed9368c06c
|
@ -200,9 +200,8 @@ export interface IRDynamicInfo {
|
||||||
id: number | null
|
id: number | null
|
||||||
dynamicFlags: DynamicFlag
|
dynamicFlags: DynamicFlag
|
||||||
placeholder: number | null
|
placeholder: number | null
|
||||||
children: IRDynamicChildren
|
children: IRDynamicInfo[]
|
||||||
}
|
}
|
||||||
export type IRDynamicChildren = Record<number, IRDynamicInfo>
|
|
||||||
|
|
||||||
export type IRExpression = SimpleExpressionNode | string
|
export type IRExpression = SimpleExpressionNode | string
|
||||||
export interface IREffect {
|
export interface IREffect {
|
||||||
|
|
|
@ -103,7 +103,7 @@ export const genDefaultDynamic = (): IRDynamicInfo => ({
|
||||||
id: null,
|
id: null,
|
||||||
dynamicFlags: 0,
|
dynamicFlags: 0,
|
||||||
placeholder: null,
|
placeholder: null,
|
||||||
children: {},
|
children: [],
|
||||||
})
|
})
|
||||||
|
|
||||||
// TODO use class for better perf
|
// TODO use class for better perf
|
||||||
|
@ -313,9 +313,8 @@ function transformNode(
|
||||||
|
|
||||||
function transformChildren(ctx: TransformContext<RootNode | ElementNode>) {
|
function transformChildren(ctx: TransformContext<RootNode | ElementNode>) {
|
||||||
const { children } = ctx.node
|
const { children } = ctx.node
|
||||||
let i = 0
|
|
||||||
for (; i < children.length; i++) {
|
for (const [i, child] of children.entries()) {
|
||||||
const child = children[i]
|
|
||||||
const childContext = createContext(child, ctx, i)
|
const childContext = createContext(child, ctx, i)
|
||||||
transformNode(childContext)
|
transformNode(childContext)
|
||||||
ctx.childrenTemplate.push(childContext.template)
|
ctx.childrenTemplate.push(childContext.template)
|
||||||
|
@ -331,9 +330,7 @@ function processDynamicChildren(ctx: TransformContext<RootNode | ElementNode>) {
|
||||||
let prevChildren: IRDynamicInfo[] = []
|
let prevChildren: IRDynamicInfo[] = []
|
||||||
let hasStatic = false
|
let hasStatic = false
|
||||||
|
|
||||||
for (let index = 0; index < node.children.length; index++) {
|
for (const [index, child] of ctx.dynamic.children.entries()) {
|
||||||
const child = ctx.dynamic.children[index]
|
|
||||||
|
|
||||||
if (!child || !(child.dynamicFlags & DynamicFlag.INSERT)) {
|
if (!child || !(child.dynamicFlags & DynamicFlag.INSERT)) {
|
||||||
if (prevChildren.length) {
|
if (prevChildren.length) {
|
||||||
if (hasStatic) {
|
if (hasStatic) {
|
||||||
|
@ -363,7 +360,7 @@ function processDynamicChildren(ctx: TransformContext<RootNode | ElementNode>) {
|
||||||
|
|
||||||
prevChildren.push(child)
|
prevChildren.push(child)
|
||||||
|
|
||||||
if (index === node.children.length - 1) {
|
if (index === ctx.dynamic.children.length - 1) {
|
||||||
ctx.registerOperation({
|
ctx.registerOperation({
|
||||||
type: IRNodeTypes.APPEND_NODE,
|
type: IRNodeTypes.APPEND_NODE,
|
||||||
loc: node.loc,
|
loc: node.loc,
|
||||||
|
|
Loading…
Reference in New Issue