perf: hoist dynamic props lists

This commit is contained in:
Evan You
2021-07-07 14:47:59 -04:00
parent 979a841946
commit 02339b67d8
5 changed files with 18 additions and 7 deletions

View File

@@ -288,7 +288,7 @@ export interface VNodeCall extends Node {
| ForRenderListExpression // v-for fragment call
| undefined
patchFlag: string | undefined
dynamicProps: string | undefined
dynamicProps: string | SimpleExpressionNode | undefined
directives: DirectiveArguments | undefined
isBlock: boolean
disableTracking: boolean

View File

@@ -113,7 +113,7 @@ export interface TransformContext
onNodeRemoved(): void
addIdentifiers(exp: ExpressionNode | string): void
removeIdentifiers(exp: ExpressionNode | string): void
hoist(exp: JSChildNode): SimpleExpressionNode
hoist(exp: string | JSChildNode): SimpleExpressionNode
cache<T extends JSChildNode>(exp: T, isVNode?: boolean): CacheExpression | T
constantCache: Map<TemplateChildNode, ConstantTypes>
@@ -277,6 +277,7 @@ export function createTransformContext(
}
},
hoist(exp) {
if (isString(exp)) exp = createSimpleExpression(exp, false)
context.hoists.push(exp)
const identifier = createSimpleExpression(
`_hoisted_${context.hoists.length}`,

View File

@@ -102,6 +102,9 @@ function walk(
codegenNode.props = context.hoist(props)
}
}
if (codegenNode.dynamicProps) {
codegenNode.dynamicProps = context.hoist(codegenNode.dynamicProps)
}
}
}
} else if (child.type === NodeTypes.TEXT_CALL) {