Browse Source

Removed `defaultIdentifier` property from Module.

* Just use the `identifier` property of the default `Identifier`.
* Mark external modules imported as namespace with needsAll.
gh-109
Oskar Segersvärd 9 years ago
parent
commit
a29f03559d
  1. 26
      src/Module.js

26
src/Module.js

@ -140,25 +140,26 @@ export default class Module {
node.declaration.type === 'Identifier' ? node.declaration.type === 'Identifier' ?
node.declaration.name : node.declaration.name :
null; null;
const name = identifier || this.name;
// Always define a new `Identifier` for the default export. // Always define a new `Identifier` for the default export.
this.exports.define( 'default', { this.exports.define( 'default', {
originalName: this.name, originalName: name,
name: this.name, name,
module: this, module: this,
statement, statement,
localName: 'default',
// Keep the identifier name, if one exists.
// We can optimize the newly created default `Identifier` away,
// if it is never modified.
// in case of `export default foo; foo = somethingElse`
identifier, identifier,
isModified: false,
isDeclaration, isDeclaration,
isAnonymous, isAnonymous
isModified: false // in case of `export default foo; foo = somethingElse`
}); });
// If it was assigned by an identifier, remember which one, in case it doesn't get modified.
if ( identifier ) {
this.defaultIdentifier = identifier;
}
} }
// export { foo, bar, baz } // export { foo, bar, baz }
@ -222,6 +223,7 @@ export default class Module {
if ( isNamespace ) { if ( isNamespace ) {
// If it's a namespace import, we bind the localName to the module itself. // If it's a namespace import, we bind the localName to the module itself.
module.needsAll = true;
this.locals.bind( localName, module ); this.locals.bind( localName, module );
} else { } else {
const name = isDefault ? 'default' : specifier.imported.name; const name = isDefault ? 'default' : specifier.imported.name;
@ -305,8 +307,8 @@ export default class Module {
// If we have a default export and it's value is never modified, // If we have a default export and it's value is never modified,
// bind to it directly. // bind to it directly.
const def = this.exports.lookup( 'default' ); const def = this.exports.lookup( 'default' );
if ( def && !def.isModified && this.defaultIdentifier ) { if ( def && !def.isModified && def.identifier ) {
this.exports.bind( 'default', this.locals.reference( this.defaultIdentifier ) ); this.exports.bind( 'default', this.locals.reference( def.identifier ) );
} }
} }

Loading…
Cancel
Save