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

22
src/Module.js

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

Loading…
Cancel
Save