fix(compiler-core): hoisted vnode calls and scoped id calls should be marked pure
Otherwise they cannot be tree-shaken
This commit is contained in:
@@ -45,7 +45,7 @@ function walk(
|
||||
) {
|
||||
for (let i = 0; i < children.length; i++) {
|
||||
const child = children[i]
|
||||
// only plain elements are eligible for hoisting.
|
||||
// only plain elements & text calls are eligible for hoisting.
|
||||
if (
|
||||
child.type === NodeTypes.ELEMENT &&
|
||||
child.tagType === ElementTypes.ELEMENT
|
||||
@@ -79,7 +79,14 @@ function walk(
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (
|
||||
child.type === NodeTypes.TEXT_CALL &&
|
||||
isStaticNode(child.content, resultCache)
|
||||
) {
|
||||
child.codegenNode = context.hoist(child.codegenNode)
|
||||
}
|
||||
|
||||
// walk further
|
||||
if (child.type === NodeTypes.ELEMENT) {
|
||||
walk(child.children, context, resultCache)
|
||||
} else if (child.type === NodeTypes.FOR) {
|
||||
@@ -91,11 +98,6 @@ function walk(
|
||||
// Do not hoist v-if single child because it has to be a block
|
||||
walk(branchChildren, context, resultCache, branchChildren.length === 1)
|
||||
}
|
||||
} else if (
|
||||
child.type === NodeTypes.TEXT_CALL &&
|
||||
isStaticNode(child.content, resultCache)
|
||||
) {
|
||||
child.codegenNode = context.hoist(child.codegenNode)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user