From c222063edd5bfdacc8e17dbb7a6c5f585b206d03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Segersv=C3=A4rd?= Date: Wed, 26 Aug 2015 16:53:57 +0200 Subject: [PATCH] Predefine the 'exports' global, and bind locals to found globals. --- src/Bundle.js | 9 ++++++--- src/Module.js | 5 ++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Bundle.js b/src/Bundle.js index 0b46897..6ac16d0 100644 --- a/src/Bundle.js +++ b/src/Bundle.js @@ -32,6 +32,12 @@ export default class Bundle { // The global scope, and the bundle's internal scope. this.globals = new Scope(); this.scope = new Scope( this.globals ); + + // TODO strictly speaking, this only applies with non-ES6, non-default-only bundles + // However, the deconfliction logic is greatly simplified by being the same for all formats. + this.globals.define( 'exports' ); + this.scope.bind( 'exports', this.globals.reference( 'exports' ) ); + // Alias for entryModule.exports. this.exports = null; @@ -44,9 +50,6 @@ export default class Bundle { this.statements = null; this.externalModules = []; this.internalNamespaceModules = []; - - this.assumedGlobals = blank(); - this.assumedGlobals.exports = true; // TODO strictly speaking, this only applies with non-ES6, non-default-only bundles } build () { diff --git a/src/Module.js b/src/Module.js index e4e9a9f..6420fdd 100644 --- a/src/Module.js +++ b/src/Module.js @@ -254,6 +254,7 @@ export default class Module { keys( statement.dependsOn ).forEach( name => { if ( !this.locals.inScope( name ) ) { this.bundle.globals.define( name ); + this.locals.bind( name, this.bundle.globals.reference( name ) ); } }); }); @@ -533,7 +534,9 @@ export default class Module { .forEach( name => { const id = this.locals.lookup( name ); - if ( id.module && id.module.isExternal ) { + // HACK: We check that `id` isn't its own module, + // since that is the case for external defaults. + if ( id.module && id !== id.module && id.module.isExternal ) { replacements[ name ] = `${id.module.name}.${id.originalName}`; } });