Просмотр исходного кода

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

Evan You 6 лет назад
Родитель
Сommit
e89d009937
1 измененных файлов с 7 добавлено и 13 удалено
  1. 7 13
      packages/compiler-core/src/codegen.ts

+ 7 - 13
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`)
         }
       }
     }