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

@@ -281,7 +281,7 @@ export interface VNodeCall extends Node {
dynamicProps: string | undefined
directives: DirectiveArguments | undefined
isBlock: boolean
isForBlock: boolean
disableTracking: boolean
}
// JS Node Types ---------------------------------------------------------------
@@ -492,7 +492,7 @@ export interface ForCodegenNode extends VNodeCall {
props: undefined
children: ForRenderListExpression
patchFlag: string
isForBlock: true
disableTracking: boolean
}
export interface ForRenderListExpression extends CallExpression {
@@ -543,7 +543,7 @@ export function createVNodeCall(
dynamicProps?: VNodeCall['dynamicProps'],
directives?: VNodeCall['directives'],
isBlock: VNodeCall['isBlock'] = false,
isForBlock: VNodeCall['isForBlock'] = false,
disableTracking: VNodeCall['disableTracking'] = false,
loc = locStub
): VNodeCall {
if (context) {
@@ -567,7 +567,7 @@ export function createVNodeCall(
dynamicProps,
directives,
isBlock,
isForBlock,
disableTracking,
loc
}
}

View File

@@ -698,13 +698,13 @@ function genVNodeCall(node: VNodeCall, context: CodegenContext) {
dynamicProps,
directives,
isBlock,
isForBlock
disableTracking
} = node
if (directives) {
push(helper(WITH_DIRECTIVES) + `(`)
}
if (isBlock) {
push(`(${helper(OPEN_BLOCK)}(${isForBlock ? `true` : ``}), `)
push(`(${helper(OPEN_BLOCK)}(${disableTracking ? `true` : ``}), `)
}
if (pure) {
push(PURE_ANNOTATION)

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(