From: Evan You Date: Mon, 18 Nov 2019 02:26:25 +0000 (-0500) Subject: fix(compiler): include createTextVNode helper for hoisted static content (fix #465) X-Git-Tag: v3.0.0-alpha.0~188 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e89d0099379ba49697ae4b6853ab749046733475;p=thirdparty%2Fvuejs%2Fcore.git fix(compiler): include createTextVNode helper for hoisted static content (fix #465) --- diff --git a/packages/compiler-core/src/codegen.ts b/packages/compiler-core/src/codegen.ts index 8baff9cb39..d903d023cb 100644 --- a/packages/compiler-core/src/codegen.ts +++ b/packages/compiler-core/src/codegen.ts @@ -35,7 +35,8 @@ import { RESOLVE_COMPONENT, RESOLVE_DIRECTIVE, SET_BLOCK_TRACKING, - CREATE_COMMENT + CREATE_COMMENT, + CREATE_TEXT } from './runtimeHelpers' type CodegenNode = TemplateChildNode | JSChildNode @@ -212,18 +213,11 @@ export function generate( // has check cost, but hoists are lifted out of the function - we need // to provide the helper here. if (ast.hoists.length) { - push( - `const _${helperNameMap[CREATE_VNODE]} = Vue.${ - helperNameMap[CREATE_VNODE] - }\n` - ) - if (ast.helpers.includes(CREATE_COMMENT)) { - push( - `const _${helperNameMap[CREATE_COMMENT]} = Vue.${ - helperNameMap[CREATE_COMMENT] - }\n` - ) - } + const staticHelpers = [CREATE_VNODE, CREATE_COMMENT, CREATE_TEXT] + .filter(helper => ast.helpers.includes(helper)) + .map(s => `${helperNameMap[s]}: _${helperNameMap[s]}`) + .join(', ') + push(`const { ${staticHelpers} } = Vue\n`) } } }