perf(compiler-core): treat v-for with constant exp as a stable fragment (#1394)

This commit is contained in:
HcySunYang
2020-06-18 04:13:14 +08:00
committed by GitHub
parent 8899a90fc4
commit 8a2cf21b71
9 changed files with 125 additions and 24 deletions

View File

@@ -203,7 +203,7 @@ export const transformElement: NodeTransform = (node, context) => {
vnodeDynamicProps,
vnodeDirectives,
!!shouldUseBlock,
false /* isForBlock */,
false /* disableTracking */,
node.loc
)
}

View File

@@ -55,9 +55,14 @@ export const transformFor = createStructuralDirectiveTransform(
forNode.source
]) as ForRenderListExpression
const keyProp = findProp(node, `key`)
const fragmentFlag = keyProp
? PatchFlags.KEYED_FRAGMENT
: PatchFlags.UNKEYED_FRAGMENT
const isStableFragment =
forNode.source.type === NodeTypes.SIMPLE_EXPRESSION &&
forNode.source.isConstant
const fragmentFlag = isStableFragment
? PatchFlags.STABLE_FRAGMENT
: keyProp
? PatchFlags.KEYED_FRAGMENT
: PatchFlags.UNKEYED_FRAGMENT
forNode.codegenNode = createVNodeCall(
context,
helper(FRAGMENT),
@@ -67,7 +72,7 @@ export const transformFor = createStructuralDirectiveTransform(
undefined,
undefined,
true /* isBlock */,
true /* isForBlock */,
!isStableFragment /* disableTracking */,
node.loc
) as ForCodegenNode
@@ -122,9 +127,11 @@ export const transformFor = createStructuralDirectiveTransform(
// but mark it as a block.
childBlock = (children[0] as PlainElementNode)
.codegenNode as VNodeCall
childBlock.isBlock = true
helper(OPEN_BLOCK)
helper(CREATE_BLOCK)
childBlock.isBlock = !isStableFragment
if (childBlock.isBlock) {
helper(OPEN_BLOCK)
helper(CREATE_BLOCK)
}
}
renderExp.arguments.push(createFunctionExpression(