diff --git a/src/ExternalModule.js b/src/ExternalModule.js index a237a47..e8749f8 100644 --- a/src/ExternalModule.js +++ b/src/ExternalModule.js @@ -22,7 +22,7 @@ export default class ExternalModule { this.needsNamed = false; this.needsAll = false; - this.exports = bundle.scope.virtual(); + this.exports = bundle.scope.virtual( false ); const { reference } = this.exports; diff --git a/src/Module.js b/src/Module.js index 21681ee..111d978 100644 --- a/src/Module.js +++ b/src/Module.js @@ -51,14 +51,16 @@ export default class Module { this.resolvedIds = blank(); // Virtual scopes for the local and exported names. - this.locals = bundle.scope.virtual(); - this.exports = bundle.scope.virtual(); + this.locals = bundle.scope.virtual( true ); + this.exports = bundle.scope.virtual( false ); const { reference, inScope } = this.exports; this.exports.reference = name => { // If we have it, grab it. - if ( inScope.call( this.exports, name ) ) return reference.call( this.exports, name ); + if ( inScope.call( this.exports, name ) ) { + return reference.call( this.exports, name ); + } // ... otherwise search exportAlls. for ( const module of this.exportAlls ) { @@ -67,7 +69,8 @@ export default class Module { } } - throw new Error( `The name ${name} is never exported!` ); + // throw new Error( `The name "${name}" is never exported (from ${this.id})!` ); + return reference.call( this.exports, name ); }; this.exports.inScope = name => { @@ -185,7 +188,7 @@ export default class Module { name = declaration.id.name; } - this.locals.define({ + this.locals.define( name, { originalName: name, name, diff --git a/src/Scope.js b/src/Scope.js index ebdd8d7..1c04fae 100644 --- a/src/Scope.js +++ b/src/Scope.js @@ -143,11 +143,10 @@ export default class Scope { } // Create and return a virtual `Scope` instance, bound to - // the actual scope of `this`. - virtual () { - const scope = new Scope(); + // the actual scope of `this`, optionally inherit the parent scope. + virtual ( inheritParent ) { + const scope = new Scope( inheritParent ? this.parent : null ); scope.ids = this.ids; - scope.parent = this.parent; return scope; } }