From 0d3ab7bb259233f76b31248500dfffc7f21371a6 Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Tue, 27 Dec 2016 17:04:10 -0500 Subject: [PATCH] use Set rather than Map for deshadowing --- src/Bundle.js | 6 +++--- src/ast/scopes/ModuleScope.js | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Bundle.js b/src/Bundle.js index ba2b4a5..3a1774b 100644 --- a/src/Bundle.js +++ b/src/Bundle.js @@ -212,18 +212,18 @@ export default class Bundle { return name; } - const toDeshadow = new Map(); + const toDeshadow = new Set(); this.externalModules.forEach( module => { const safeName = getSafeName( module.name ); - toDeshadow.set( safeName, true ); + toDeshadow.add( safeName ); module.name = safeName; // ensure we don't shadow named external imports, if // we're creating an ES6 bundle forOwn( module.declarations, ( declaration, name ) => { const safeName = getSafeName( name ); - toDeshadow.set( safeName, true ); + toDeshadow.add( safeName ); declaration.setSafeName( safeName ); }); }); diff --git a/src/ast/scopes/ModuleScope.js b/src/ast/scopes/ModuleScope.js index 5a18d6f..4c8804c 100644 --- a/src/ast/scopes/ModuleScope.js +++ b/src/ast/scopes/ModuleScope.js @@ -14,13 +14,13 @@ export default class ModuleScope extends Scope { } deshadow ( names ) { - names = new Map( names ); + names = new Set( names ); forOwn( this.module.imports, specifier => { if ( specifier.module.isExternal ) return; specifier.module.getExports().forEach( name => { - names.set(name); + names.add( name ); }); if ( specifier.name !== '*' ) { @@ -29,9 +29,10 @@ export default class ModuleScope extends Scope { this.module.bundle.onwarn( `Non-existent export '${specifier.name}' is imported from ${specifier.module.id} by ${this.module.id}` ); return; } + const name = declaration.getName( true ); if ( name !== specifier.name ) { - names.set( declaration.getName( true ) ); + names.add( declaration.getName( true ) ); } } });