Browse Source

Predefine the 'exports' global, and bind locals to found globals.

gh-109
Oskar Segersvärd 10 years ago
parent
commit
c222063edd
  1. 9
      src/Bundle.js
  2. 5
      src/Module.js

9
src/Bundle.js

@ -32,6 +32,12 @@ export default class Bundle {
// The global scope, and the bundle's internal scope. // The global scope, and the bundle's internal scope.
this.globals = new Scope(); this.globals = new Scope();
this.scope = new Scope( this.globals ); 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. // Alias for entryModule.exports.
this.exports = null; this.exports = null;
@ -44,9 +50,6 @@ export default class Bundle {
this.statements = null; this.statements = null;
this.externalModules = []; this.externalModules = [];
this.internalNamespaceModules = []; this.internalNamespaceModules = [];
this.assumedGlobals = blank();
this.assumedGlobals.exports = true; // TODO strictly speaking, this only applies with non-ES6, non-default-only bundles
} }
build () { build () {

5
src/Module.js

@ -254,6 +254,7 @@ export default class Module {
keys( statement.dependsOn ).forEach( name => { keys( statement.dependsOn ).forEach( name => {
if ( !this.locals.inScope( name ) ) { if ( !this.locals.inScope( name ) ) {
this.bundle.globals.define( 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 => { .forEach( name => {
const id = this.locals.lookup( 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}`; replacements[ name ] = `${id.module.name}.${id.originalName}`;
} }
}); });

Loading…
Cancel
Save