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:
Evan You
2020-05-01 17:34:11 -04:00
parent 6c60ce13e0
commit cad25d95a3
5 changed files with 45 additions and 34 deletions

View File

@@ -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)
}
}
}