]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
chore(compiler-core): use aliasHelper (#3592)
authoredison <daiwei521@126.com>
Thu, 12 May 2022 00:40:05 +0000 (08:40 +0800)
committerGitHub <noreply@github.com>
Thu, 12 May 2022 00:40:05 +0000 (20:40 -0400)
packages/compiler-core/src/codegen.ts

index 2b641e9ad69d47fb659234ea09f3e417db81c2fa..9d715149b99abf678fe0337d4286597acfca1fa6 100644 (file)
@@ -58,6 +58,8 @@ import { ImportItem } from './transform'
 
 const PURE_ANNOTATION = `/*#__PURE__*/`
 
+const aliasHelper = (s: symbol) => `${helperNameMap[s]}: _${helperNameMap[s]}`
+
 type CodegenNode = TemplateChildNode | JSChildNode | SSRCodegenNode
 
 export interface CodegenResult {
@@ -247,11 +249,7 @@ export function generate(
     // function mode const declarations should be inside with block
     // also they should be renamed to avoid collision with user properties
     if (hasHelpers) {
-      push(
-        `const { ${ast.helpers
-          .map(s => `${helperNameMap[s]}: _${helperNameMap[s]}`)
-          .join(', ')} } = _Vue`
-      )
+      push(`const { ${ast.helpers.map(aliasHelper).join(', ')} } = _Vue`)
       push(`\n`)
       newline()
     }
@@ -328,7 +326,6 @@ function genFunctionPreamble(ast: RootNode, context: CodegenContext) {
     !__BROWSER__ && ssr
       ? `require(${JSON.stringify(runtimeModuleName)})`
       : runtimeGlobalName
-  const aliasHelper = (s: symbol) => `${helperNameMap[s]}: _${helperNameMap[s]}`
   // Generate const declaration for helpers
   // In prefix mode, we place the const declaration at top so it's done
   // only once; But if we not prefixing, we place the declaration inside the