@@ -208,7 +208,8 @@ export function generate(
208
208
ssr
209
209
} = context
210
210
211
- const hasHelpers = ast . helpers . length > 0
211
+ const helpers = Array . from ( ast . helpers )
212
+ const hasHelpers = helpers . length > 0
212
213
const useWithBlock = ! prefixIdentifiers && mode !== 'module'
213
214
const genScopeId = ! __BROWSER__ && scopeId != null && mode === 'module'
214
215
const isSetupInlined = ! __BROWSER__ && ! ! options . inline
@@ -249,7 +250,7 @@ export function generate(
249
250
// function mode const declarations should be inside with block
250
251
// also they should be renamed to avoid collision with user properties
251
252
if ( hasHelpers ) {
252
- push ( `const { ${ ast . helpers . map ( aliasHelper ) . join ( ', ' ) } } = _Vue` )
253
+ push ( `const { ${ helpers . map ( aliasHelper ) . join ( ', ' ) } } = _Vue` )
253
254
push ( `\n` )
254
255
newline ( )
255
256
}
@@ -330,11 +331,10 @@ function genFunctionPreamble(ast: RootNode, context: CodegenContext) {
330
331
// In prefix mode, we place the const declaration at top so it's done
331
332
// only once; But if we not prefixing, we place the declaration inside the
332
333
// with block so it doesn't incur the `in` check cost for every helper access.
333
- if ( ast . helpers . length > 0 ) {
334
+ const helpers = Array . from ( ast . helpers )
335
+ if ( helpers . length > 0 ) {
334
336
if ( ! __BROWSER__ && prefixIdentifiers ) {
335
- push (
336
- `const { ${ ast . helpers . map ( aliasHelper ) . join ( ', ' ) } } = ${ VueBinding } \n`
337
- )
337
+ push ( `const { ${ helpers . map ( aliasHelper ) . join ( ', ' ) } } = ${ VueBinding } \n` )
338
338
} else {
339
339
// "with" mode.
340
340
// save Vue in a separate variable to avoid collision
@@ -350,7 +350,7 @@ function genFunctionPreamble(ast: RootNode, context: CodegenContext) {
350
350
CREATE_TEXT ,
351
351
CREATE_STATIC
352
352
]
353
- . filter ( helper => ast . helpers . includes ( helper ) )
353
+ . filter ( helper => helpers . includes ( helper ) )
354
354
. map ( aliasHelper )
355
355
. join ( ', ' )
356
356
push ( `const { ${ staticHelpers } } = _Vue\n` )
@@ -386,30 +386,32 @@ function genModulePreamble(
386
386
} = context
387
387
388
388
if ( genScopeId && ast . hoists . length ) {
389
- ast . helpers . push ( PUSH_SCOPE_ID , POP_SCOPE_ID )
389
+ ast . helpers . add ( PUSH_SCOPE_ID )
390
+ ast . helpers . add ( POP_SCOPE_ID )
390
391
}
391
392
392
393
// generate import statements for helpers
393
- if ( ast . helpers . length ) {
394
+ if ( ast . helpers . size ) {
395
+ const helpers = Array . from ( ast . helpers )
394
396
if ( optimizeImports ) {
395
397
// when bundled with webpack with code-split, calling an import binding
396
398
// as a function leads to it being wrapped with `Object(a.b)` or `(0,a.b)`,
397
399
// incurring both payload size increase and potential perf overhead.
398
400
// therefore we assign the imports to variables (which is a constant ~50b
399
401
// cost per-component instead of scaling with template size)
400
402
push (
401
- `import { ${ ast . helpers
403
+ `import { ${ helpers
402
404
. map ( s => helperNameMap [ s ] )
403
405
. join ( ', ' ) } } from ${ JSON . stringify ( runtimeModuleName ) } \n`
404
406
)
405
407
push (
406
- `\n// Binding optimization for webpack code-split\nconst ${ ast . helpers
408
+ `\n// Binding optimization for webpack code-split\nconst ${ helpers
407
409
. map ( s => `_${ helperNameMap [ s ] } = ${ helperNameMap [ s ] } ` )
408
410
. join ( ', ' ) } \n`
409
411
)
410
412
} else {
411
413
push (
412
- `import { ${ ast . helpers
414
+ `import { ${ helpers
413
415
. map ( s => `${ helperNameMap [ s ] } as _${ helperNameMap [ s ] } ` )
414
416
. join ( ', ' ) } } from ${ JSON . stringify ( runtimeModuleName ) } \n`
415
417
)
0 commit comments