]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
refactor(compiler-core): make ast.helpers a Set (#6774)
author三咲智子 Kevin Deng <sxzz@sxzz.moe>
Mon, 14 Nov 2022 01:44:02 +0000 (09:44 +0800)
committerGitHub <noreply@github.com>
Mon, 14 Nov 2022 01:44:02 +0000 (20:44 -0500)
packages/compiler-core/__tests__/__snapshots__/parse.spec.ts.snap
packages/compiler-core/__tests__/codegen.spec.ts
packages/compiler-core/src/ast.ts
packages/compiler-core/src/codegen.ts
packages/compiler-core/src/transform.ts
packages/compiler-sfc/src/compileScript.ts
packages/compiler-ssr/__tests__/ssrInjectCssVars.spec.ts
packages/compiler-ssr/src/ssrCodegenTransform.ts

index d7ac9888a598a4f7547397fd1898d456b55dc1d3..000cedaf86fa71fa8e17cac257f03d385a58a080 100644 (file)
@@ -49,7 +49,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -119,7 +119,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -189,7 +189,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -259,7 +259,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -353,7 +353,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -498,7 +498,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -574,7 +574,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -650,7 +650,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -720,7 +720,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -790,7 +790,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -866,7 +866,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -960,7 +960,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -1030,7 +1030,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -1100,7 +1100,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -1170,7 +1170,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -1240,7 +1240,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -1310,7 +1310,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -1380,7 +1380,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -1450,7 +1450,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -1502,7 +1502,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -1578,7 +1578,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -1654,7 +1654,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -1749,7 +1749,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -1844,7 +1844,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -1939,7 +1939,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -2050,7 +2050,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -2161,7 +2161,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -2272,7 +2272,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -2383,7 +2383,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -2494,7 +2494,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -2605,7 +2605,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -2716,7 +2716,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -2827,7 +2827,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -2897,7 +2897,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -2943,7 +2943,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -3013,7 +3013,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -3083,7 +3083,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -3153,7 +3153,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -3223,7 +3223,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -3293,7 +3293,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -3381,7 +3381,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -3451,7 +3451,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -3538,7 +3538,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -3649,7 +3649,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -3744,7 +3744,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -3839,7 +3839,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -3891,7 +3891,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -4038,7 +4038,7 @@ class=\\"bar\\"></div></template>",
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -4184,7 +4184,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -4254,7 +4254,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -4324,7 +4324,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -4394,7 +4394,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -4464,7 +4464,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -4534,7 +4534,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -4645,7 +4645,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -4756,7 +4756,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -4867,7 +4867,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -4978,7 +4978,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -5089,7 +5089,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -5200,7 +5200,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -5311,7 +5311,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -5422,7 +5422,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -5517,7 +5517,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -5628,7 +5628,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -5698,7 +5698,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -5811,7 +5811,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -5881,7 +5881,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -5951,7 +5951,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -6003,7 +6003,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -6055,7 +6055,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -6143,7 +6143,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -6213,7 +6213,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -6322,7 +6322,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -6398,7 +6398,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -6474,7 +6474,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -6520,7 +6520,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -6566,7 +6566,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -6630,7 +6630,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -6709,7 +6709,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -6901,7 +6901,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
@@ -7112,7 +7112,7 @@ Object {
   "codegenNode": undefined,
   "components": Array [],
   "directives": Array [],
-  "helpers": Array [],
+  "helpers": Set {},
   "hoists": Array [],
   "imports": Array [],
   "loc": Object {
index b51ca132836f2dcc7d7734c9ad3f13a697ed2ca1..e300580c04559348140a9a9744c74cf6d923b520 100644 (file)
@@ -41,7 +41,7 @@ function createRoot(options: Partial<RootNode> = {}): RootNode {
   return {
     type: NodeTypes.ROOT,
     children: [],
-    helpers: [],
+    helpers: new Set(),
     components: [],
     directives: [],
     imports: [],
@@ -57,7 +57,7 @@ function createRoot(options: Partial<RootNode> = {}): RootNode {
 describe('compiler: codegen', () => {
   test('module mode preamble', () => {
     const root = createRoot({
-      helpers: [CREATE_VNODE, RESOLVE_DIRECTIVE]
+      helpers: new Set([CREATE_VNODE, RESOLVE_DIRECTIVE])
     })
     const { code } = generate(root, { mode: 'module' })
     expect(code).toMatch(
@@ -68,7 +68,7 @@ describe('compiler: codegen', () => {
 
   test('module mode preamble w/ optimizeImports: true', () => {
     const root = createRoot({
-      helpers: [CREATE_VNODE, RESOLVE_DIRECTIVE]
+      helpers: new Set([CREATE_VNODE, RESOLVE_DIRECTIVE])
     })
     const { code } = generate(root, { mode: 'module', optimizeImports: true })
     expect(code).toMatch(
@@ -82,7 +82,7 @@ describe('compiler: codegen', () => {
 
   test('function mode preamble', () => {
     const root = createRoot({
-      helpers: [CREATE_VNODE, RESOLVE_DIRECTIVE]
+      helpers: new Set([CREATE_VNODE, RESOLVE_DIRECTIVE])
     })
     const { code } = generate(root, { mode: 'function' })
     expect(code).toMatch(`const _Vue = Vue`)
@@ -94,7 +94,7 @@ describe('compiler: codegen', () => {
 
   test('function mode preamble w/ prefixIdentifiers: true', () => {
     const root = createRoot({
-      helpers: [CREATE_VNODE, RESOLVE_DIRECTIVE]
+      helpers: new Set([CREATE_VNODE, RESOLVE_DIRECTIVE])
     })
     const { code } = generate(root, {
       mode: 'function',
index d6eda73bbbe5dbce35b043aa4fb7e20952b1bb16..457a9057633948cd963c2226271859603f2c2af5 100644 (file)
@@ -100,7 +100,7 @@ export type TemplateChildNode =
 export interface RootNode extends Node {
   type: NodeTypes.ROOT
   children: TemplateChildNode[]
-  helpers: symbol[]
+  helpers: Set<symbol>
   components: string[]
   directives: string[]
   hoists: (JSChildNode | null)[]
@@ -556,7 +556,7 @@ export function createRoot(
   return {
     type: NodeTypes.ROOT,
     children,
-    helpers: [],
+    helpers: new Set(),
     components: [],
     directives: [],
     hoists: [],
index 9d715149b99abf678fe0337d4286597acfca1fa6..dce58737735cc89a797ba18b79294d402990b76b 100644 (file)
@@ -208,7 +208,8 @@ export function generate(
     ssr
   } = context
 
-  const hasHelpers = ast.helpers.length > 0
+  const helpers = Array.from(ast.helpers)
+  const hasHelpers = helpers.length > 0
   const useWithBlock = !prefixIdentifiers && mode !== 'module'
   const genScopeId = !__BROWSER__ && scopeId != null && mode === 'module'
   const isSetupInlined = !__BROWSER__ && !!options.inline
@@ -249,7 +250,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(aliasHelper).join(', ')} } = _Vue`)
+      push(`const { ${helpers.map(aliasHelper).join(', ')} } = _Vue`)
       push(`\n`)
       newline()
     }
@@ -330,11 +331,10 @@ function genFunctionPreamble(ast: RootNode, context: CodegenContext) {
   // 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
   // with block so it doesn't incur the `in` check cost for every helper access.
-  if (ast.helpers.length > 0) {
+  const helpers = Array.from(ast.helpers)
+  if (helpers.length > 0) {
     if (!__BROWSER__ && prefixIdentifiers) {
-      push(
-        `const { ${ast.helpers.map(aliasHelper).join(', ')} } = ${VueBinding}\n`
-      )
+      push(`const { ${helpers.map(aliasHelper).join(', ')} } = ${VueBinding}\n`)
     } else {
       // "with" mode.
       // save Vue in a separate variable to avoid collision
@@ -350,7 +350,7 @@ function genFunctionPreamble(ast: RootNode, context: CodegenContext) {
           CREATE_TEXT,
           CREATE_STATIC
         ]
-          .filter(helper => ast.helpers.includes(helper))
+          .filter(helper => helpers.includes(helper))
           .map(aliasHelper)
           .join(', ')
         push(`const { ${staticHelpers} } = _Vue\n`)
@@ -386,11 +386,13 @@ function genModulePreamble(
   } = context
 
   if (genScopeId && ast.hoists.length) {
-    ast.helpers.push(PUSH_SCOPE_ID, POP_SCOPE_ID)
+    ast.helpers.add(PUSH_SCOPE_ID)
+    ast.helpers.add(POP_SCOPE_ID)
   }
 
   // generate import statements for helpers
-  if (ast.helpers.length) {
+  if (ast.helpers.size) {
+    const helpers = Array.from(ast.helpers)
     if (optimizeImports) {
       // when bundled with webpack with code-split, calling an import binding
       // as a function leads to it being wrapped with `Object(a.b)` or `(0,a.b)`,
@@ -398,18 +400,18 @@ function genModulePreamble(
       // therefore we assign the imports to variables (which is a constant ~50b
       // cost per-component instead of scaling with template size)
       push(
-        `import { ${ast.helpers
+        `import { ${helpers
           .map(s => helperNameMap[s])
           .join(', ')} } from ${JSON.stringify(runtimeModuleName)}\n`
       )
       push(
-        `\n// Binding optimization for webpack code-split\nconst ${ast.helpers
+        `\n// Binding optimization for webpack code-split\nconst ${helpers
           .map(s => `_${helperNameMap[s]} = ${helperNameMap[s]}`)
           .join(', ')}\n`
       )
     } else {
       push(
-        `import { ${ast.helpers
+        `import { ${helpers
           .map(s => `${helperNameMap[s]} as _${helperNameMap[s]}`)
           .join(', ')} } from ${JSON.stringify(runtimeModuleName)}\n`
       )
index 6397df92f3c6a3366bd3c5bbffce6f408c5e627e..3cb3e6bf01f47be068ab547ef23cea114722442a 100644 (file)
@@ -324,7 +324,7 @@ export function transform(root: RootNode, options: TransformOptions) {
     createRootCodegen(root, context)
   }
   // finalize meta information
-  root.helpers = [...context.helpers.keys()]
+  root.helpers = new Set([...context.helpers.keys()])
   root.components = [...context.components]
   root.directives = [...context.directives]
   root.imports = context.imports
index c87beb1537633838c9b07e66d9aa90281451ebfe..bb4e7f42c135479fecd5c7f3b22de0d2c1128607 100644 (file)
@@ -1561,7 +1561,7 @@ export function compileScript(
       // avoid duplicated unref import
       // as this may get injected by the render function preamble OR the
       // css vars codegen
-      if (ast && ast.helpers.includes(UNREF)) {
+      if (ast && ast.helpers.has(UNREF)) {
         helperImports.delete('unref')
       }
       returned = code
index 97df3045c67dea5f106bfb1e6feeba7bab31aeb9..0e29fb7e445e97efedff369775825e4c17540602 100644 (file)
@@ -127,10 +127,10 @@ describe('ssr: inject <style vars>', () => {
       }"
     `)
     expect(result.ast.helpers).toMatchInlineSnapshot(`
-      Array [
+      Set {
         Symbol(mergeProps),
         Symbol(unref),
-      ]
+      }
     `)
   })
 })
index d7d1645a0e764045574c0832b7f3c273030c38d5..954863b539352232e1342a734c65fa094c117993 100644 (file)
@@ -49,7 +49,7 @@ export function ssrCodegenTransform(ast: RootNode, options: CompilerOptions) {
       createCompoundExpression([`const _cssVars = { style: `, varsExp, `}`])
     )
     Array.from(cssContext.helpers.keys()).forEach(helper => {
-      if (!ast.helpers.includes(helper)) ast.helpers.push(helper)
+      ast.helpers.add(helper)
     })
   }
 
@@ -61,10 +61,13 @@ export function ssrCodegenTransform(ast: RootNode, options: CompilerOptions) {
   // Finalize helpers.
   // We need to separate helpers imported from 'vue' vs. '@vue/server-renderer'
   ast.ssrHelpers = Array.from(
-    new Set([...ast.helpers.filter(h => h in ssrHelpers), ...context.helpers])
+    new Set([
+      ...Array.from(ast.helpers).filter(h => h in ssrHelpers),
+      ...context.helpers
+    ])
   )
 
-  ast.helpers = ast.helpers.filter(h => !(h in ssrHelpers))
+  ast.helpers = new Set(Array.from(ast.helpers).filter(h => !(h in ssrHelpers)))
 }
 
 export type SSRTransformContext = ReturnType<typeof createSSRTransformContext>