fix(compiler): include createTextVNode helper for hoisted static content (fix #465)

This commit is contained in:
Evan You 2019-11-17 21:26:25 -05:00
parent f838715b7c
commit e89d009937

View File

@ -35,7 +35,8 @@ import {
RESOLVE_COMPONENT, RESOLVE_COMPONENT,
RESOLVE_DIRECTIVE, RESOLVE_DIRECTIVE,
SET_BLOCK_TRACKING, SET_BLOCK_TRACKING,
CREATE_COMMENT CREATE_COMMENT,
CREATE_TEXT
} from './runtimeHelpers' } from './runtimeHelpers'
type CodegenNode = TemplateChildNode | JSChildNode type CodegenNode = TemplateChildNode | JSChildNode
@ -212,18 +213,11 @@ export function generate(
// has check cost, but hoists are lifted out of the function - we need // has check cost, but hoists are lifted out of the function - we need
// to provide the helper here. // to provide the helper here.
if (ast.hoists.length) { if (ast.hoists.length) {
push( const staticHelpers = [CREATE_VNODE, CREATE_COMMENT, CREATE_TEXT]
`const _${helperNameMap[CREATE_VNODE]} = Vue.${ .filter(helper => ast.helpers.includes(helper))
helperNameMap[CREATE_VNODE] .map(s => `${helperNameMap[s]}: _${helperNameMap[s]}`)
}\n` .join(', ')
) push(`const { ${staticHelpers} } = Vue\n`)
if (ast.helpers.includes(CREATE_COMMENT)) {
push(
`const _${helperNameMap[CREATE_COMMENT]} = Vue.${
helperNameMap[CREATE_COMMENT]
}\n`
)
}
} }
} }
} }