Browse Source

use Set rather than Map for deshadowing

gh-786
Rich-Harris 8 years ago
parent
commit
0d3ab7bb25
  1. 6
      src/Bundle.js
  2. 7
      src/ast/scopes/ModuleScope.js

6
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 );
});
});

7
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 ) );
}
}
});

Loading…
Cancel
Save