fix(compiler): do not hoist element with dynamic key (#187)
This commit is contained in:
@@ -6,12 +6,18 @@ import {
|
||||
ElementCodegenNode,
|
||||
PlainElementNode,
|
||||
ComponentNode,
|
||||
TemplateNode
|
||||
TemplateNode,
|
||||
ElementNode
|
||||
} from '../ast'
|
||||
import { TransformContext } from '../transform'
|
||||
import { APPLY_DIRECTIVES } from '../runtimeHelpers'
|
||||
import { PatchFlags } from '@vue/shared'
|
||||
import { isSlotOutlet } from '../utils'
|
||||
import { isSlotOutlet, findProp } from '../utils'
|
||||
|
||||
function hasDynamicKey(node: ElementNode) {
|
||||
const keyProp = findProp(node, 'key')
|
||||
return keyProp && keyProp.type === NodeTypes.DIRECTIVE
|
||||
}
|
||||
|
||||
export function hoistStatic(root: RootNode, context: TransformContext) {
|
||||
walk(
|
||||
@@ -47,7 +53,11 @@ function walk(
|
||||
child.type === NodeTypes.ELEMENT &&
|
||||
child.tagType === ElementTypes.ELEMENT
|
||||
) {
|
||||
if (!doNotHoistNode && isStaticNode(child, resultCache)) {
|
||||
if (
|
||||
!doNotHoistNode &&
|
||||
isStaticNode(child, resultCache) &&
|
||||
!hasDynamicKey(child)
|
||||
) {
|
||||
// whole tree is static
|
||||
child.codegenNode = context.hoist(child.codegenNode!)
|
||||
continue
|
||||
@@ -56,9 +66,10 @@ function walk(
|
||||
// hoisting.
|
||||
const flag = getPatchFlag(child)
|
||||
if (
|
||||
!flag ||
|
||||
flag === PatchFlags.NEED_PATCH ||
|
||||
flag === PatchFlags.TEXT
|
||||
(!flag ||
|
||||
flag === PatchFlags.NEED_PATCH ||
|
||||
flag === PatchFlags.TEXT) &&
|
||||
!hasDynamicKey(child)
|
||||
) {
|
||||
let codegenNode = child.codegenNode as ElementCodegenNode
|
||||
if (codegenNode.callee === APPLY_DIRECTIVES) {
|
||||
|
||||
Reference in New Issue
Block a user