From 580bd6fe632b30f6ec30eb4d865841a3180e68a6 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Sun, 19 Mar 2017 15:00:41 -0400 Subject: [PATCH] use annotateWithScopes to get top-level declarations when deconflicting `template` --- src/generators/Generator.js | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/generators/Generator.js b/src/generators/Generator.js index a14668494a..464b71d17e 100644 --- a/src/generators/Generator.js +++ b/src/generators/Generator.js @@ -285,18 +285,9 @@ export default class Generator { // export is last property, we can just return it this.code.overwrite( defaultExport.start, defaultExport.declaration.start, `return ` ); } else { - // we need to avoid a conflict with anything on the top-level scope of the component - // however, determining which things these are is tricky, so we instead just avoid conflicts with any identifiers anywhere - const identifiers = new Set(); - walk( js, { - enter ( node ) { - if ( node.type === 'Identifier' ) { - identifiers.add( node.name ); - } - } - }); + const { declarations } = annotateWithScopes( js ); let template = 'template'; - for ( let i = 1; identifiers.has( template ); template = `template$${i++}` ); + for ( let i = 1; template in declarations; template = `template$${i++}` ); this.code.overwrite( defaultExport.start, defaultExport.declaration.start, `var ${template} = ` );