Browse Source

trying something new...

contingency-plan
Rich-Harris 10 years ago
parent
commit
4420d508c6
  1. 7
      src/Bundle.js
  2. 22
      src/Module.js

7
src/Bundle.js

@ -198,6 +198,7 @@ export default class Bundle {
// defined in this module
if ( !importDeclaration ) {
if ( localName === 'default' ) return module.defaultName();
return module.replacements[ localName ] || localName;
}
@ -224,6 +225,10 @@ export default class Bundle {
return otherModule.replacements[ '*' ];
}
if ( importDeclaration.name === 'default' ) {
return otherModule.defaultName();
}
const exportDeclaration = otherModule.exports[ importDeclaration.name ];
if ( exportDeclaration ) return trace( otherModule, exportDeclaration.localName );
@ -240,7 +245,7 @@ export default class Bundle {
}
function getSafeName ( name ) {
while ( conflicts[ name ] ) { // TODO this seems wonky
while ( definers[ name ] || conflicts[ name ] ) { // TODO this seems wonky
name = `_${name}`;
}

22
src/Module.js

@ -120,6 +120,7 @@ export default class Module {
}
this.exports[ exportedName ] = {
statement,
localName,
exportedName,
linkedImport: source ? this.imports[ localName ] : null
@ -257,6 +258,14 @@ export default class Module {
return { strongDependencies, weakDependencies };
}
defaultName () {
const defaultExport = this.exports.default;
if ( !defaultExport ) return null;
if ( defaultExport.identifier && !defaultExport.isModified ) return defaultExport.identifier;
return this.replacements.default;
}
findDefiningStatement ( name ) {
if ( this.definitions[ name ] ) return this.definitions[ name ];
@ -382,6 +391,10 @@ export default class Module {
});
}
if ( importDeclaration.name === 'default' ) {
return exportDeclaration.statement.mark();
}
exportDeclaration.isUsed = true;
return module.mark( exportDeclaration.localName );
});
@ -610,14 +623,7 @@ export default class Module {
}
else if ( statement.node.type === 'ExportDefaultDeclaration' ) {
//const canonicalName = this.getCanonicalName( 'default', format === 'es6' );
let canonicalName;
if ( this.replacements.default ) {
canonicalName = this.replacements.default;
} else {
canonicalName = statement.node.declaration.name; // TODO declaredName?
canonicalName = this.replacements[ canonicalName ] || canonicalName;
}
const canonicalName = this.defaultName();
if ( statement.node.declaration.type === 'Identifier' && canonicalName === ( moduleReplacements[ statement.node.declaration.name ] || statement.node.declaration.name ) ) {
magicString.remove( statement.start, statement.next );

Loading…
Cancel
Save