Browse Source

Use ExternalModules as their own default value.

gh-109
Oskar Segersvärd 10 years ago
parent
commit
979f61baf1
  1. 37
      src/ExternalModule.js

37
src/ExternalModule.js

@ -2,7 +2,11 @@
export default class ExternalModule { export default class ExternalModule {
constructor ( { id, bundle } ) { constructor ( { id, bundle } ) {
this.id = id; this.id = id;
// Implement `Identifier` interface.
this.originalName = id;
this.name = id; this.name = id;
this.module = this;
this.isExternal = true; this.isExternal = true;
this.importedByBundle = []; this.importedByBundle = [];
@ -17,32 +21,39 @@ export default class ExternalModule {
this.needsNamed = false; this.needsNamed = false;
this.needsAll = false; this.needsAll = false;
bundle.scope.define( this.name, this ); bundle.scope.define( this.originalName, this );
this.exports = bundle.scope.virtual(); this.exports = bundle.scope.virtual();
const ref = this.exports.reference; const { lookup, reference } = this.exports;
// Override reference. // Override reference.
this.exports.reference = name => { this.exports.reference = name => {
if ( !this.exports.defines( name ) ) { if ( name === 'default' ) {
let idName = name; this.needsDefault = true;
return bundle.scope.reference( this.originalName );
}
if ( name === 'default' ) { if ( !this.exports.defines( name ) ) {
idName = this.name; this.needsNamed = true;
this.needsDefault = true;
} else {
this.needsNamed = true;
}
this.exports.define( name, { this.exports.define( name, {
originalName: idName, originalName: name,
name: idName, name,
module: this module: this
}); });
} }
return ref.call( this.exports, name ); return reference.call( this.exports, name );
};
// Override lookup.
this.exports.lookup = name => {
if ( name === 'default' ) {
return this;
}
return lookup.call( this.exports, name );
}; };
} }
} }

Loading…
Cancel
Save