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

@@ -201,7 +201,7 @@ export function generate(
// enter render function
if (genScopeId && !ssr) {
push(`const render = _withId(`)
push(`const render = /*#__PURE__*/ _withId(`)
}
if (!ssr) {
push(`function render(_ctx, _cache) {`)
@@ -400,7 +400,7 @@ function genModulePreamble(
}
if (genScopeId) {
push(`const _withId = ${helper(WITH_SCOPE_ID)}("${scopeId}")`)
push(`const _withId = /*#__PURE__*/ ${helper(WITH_SCOPE_ID)}("${scopeId}")`)
newline()
}
@@ -445,6 +445,13 @@ function genHoists(hoists: JSChildNode[], context: CodegenContext) {
hoists.forEach((exp, i) => {
push(`const _hoisted_${i + 1} = `)
// make hosit function calls tree-shakable
if (
exp.type === NodeTypes.VNODE_CALL ||
exp.type === NodeTypes.JS_CALL_EXPRESSION
) {
push(`/*#__PURE__*/ `)
}
genNode(exp, context)
newline()
})