@@ -208,7 +208,8 @@ export function generate(
208208 ssr
209209 } = context
210210
211- const hasHelpers = ast . helpers . length > 0
211+ const helpers = Array . from ( ast . helpers )
212+ const hasHelpers = helpers . length > 0
212213 const useWithBlock = ! prefixIdentifiers && mode !== 'module'
213214 const genScopeId = ! __BROWSER__ && scopeId != null && mode === 'module'
214215 const isSetupInlined = ! __BROWSER__ && ! ! options . inline
@@ -249,7 +250,7 @@ export function generate(
249250 // function mode const declarations should be inside with block
250251 // also they should be renamed to avoid collision with user properties
251252 if ( hasHelpers ) {
252- push ( `const { ${ ast . helpers . map ( aliasHelper ) . join ( ', ' ) } } = _Vue` )
253+ push ( `const { ${ helpers . map ( aliasHelper ) . join ( ', ' ) } } = _Vue` )
253254 push ( `\n` )
254255 newline ( )
255256 }
@@ -330,11 +331,10 @@ function genFunctionPreamble(ast: RootNode, context: CodegenContext) {
330331 // In prefix mode, we place the const declaration at top so it's done
331332 // only once; But if we not prefixing, we place the declaration inside the
332333 // 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 ) {
334336 if ( ! __BROWSER__ && prefixIdentifiers ) {
335- push (
336- `const { ${ ast . helpers . map ( aliasHelper ) . join ( ', ' ) } } = ${ VueBinding } \n`
337- )
337+ push ( `const { ${ helpers . map ( aliasHelper ) . join ( ', ' ) } } = ${ VueBinding } \n` )
338338 } else {
339339 // "with" mode.
340340 // save Vue in a separate variable to avoid collision
@@ -350,7 +350,7 @@ function genFunctionPreamble(ast: RootNode, context: CodegenContext) {
350350 CREATE_TEXT ,
351351 CREATE_STATIC
352352 ]
353- . filter ( helper => ast . helpers . includes ( helper ) )
353+ . filter ( helper => helpers . includes ( helper ) )
354354 . map ( aliasHelper )
355355 . join ( ', ' )
356356 push ( `const { ${ staticHelpers } } = _Vue\n` )
@@ -386,30 +386,32 @@ function genModulePreamble(
386386 } = context
387387
388388 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 )
390391 }
391392
392393 // generate import statements for helpers
393- if ( ast . helpers . length ) {
394+ if ( ast . helpers . size ) {
395+ const helpers = Array . from ( ast . helpers )
394396 if ( optimizeImports ) {
395397 // when bundled with webpack with code-split, calling an import binding
396398 // as a function leads to it being wrapped with `Object(a.b)` or `(0,a.b)`,
397399 // incurring both payload size increase and potential perf overhead.
398400 // therefore we assign the imports to variables (which is a constant ~50b
399401 // cost per-component instead of scaling with template size)
400402 push (
401- `import { ${ ast . helpers
403+ `import { ${ helpers
402404 . map ( s => helperNameMap [ s ] )
403405 . join ( ', ' ) } } from ${ JSON . stringify ( runtimeModuleName ) } \n`
404406 )
405407 push (
406- `\n// Binding optimization for webpack code-split\nconst ${ ast . helpers
408+ `\n// Binding optimization for webpack code-split\nconst ${ helpers
407409 . map ( s => `_${ helperNameMap [ s ] } = ${ helperNameMap [ s ] } ` )
408410 . join ( ', ' ) } \n`
409411 )
410412 } else {
411413 push (
412- `import { ${ ast . helpers
414+ `import { ${ helpers
413415 . map ( s => `${ helperNameMap [ s ] } as _${ helperNameMap [ s ] } ` )
414416 . join ( ', ' ) } } from ${ JSON . stringify ( runtimeModuleName ) } \n`
415417 )
0 commit comments