diff --git a/src/Bundle.js b/src/Bundle.js index c62b138..49aaa5f 100644 --- a/src/Bundle.js +++ b/src/Bundle.js @@ -171,7 +171,6 @@ export default class Bundle { if ( defaultExport.declaredName && !defaultExport.isModified ) return; // TODO encapsulate check for whether we need synthetic default name const defaultName = getSafeName( module.suggestedNames.default ); - module.replacements.default = defaultName; } @@ -201,7 +200,16 @@ export default class Bundle { const otherModule = importDeclaration.module; if ( otherModule.isExternal ) { - // TODO ES6 + if ( es6 ) throw new Error( 'TODO ES6' ); + + if ( importDeclaration.name === 'default' ) { + return otherModule.needsNamed ? + `${otherModule.name}__default` : + otherModule.name; + } + + // TODO namespaces + return `${otherModule.name}.${importDeclaration.name}`; } @@ -214,7 +222,7 @@ export default class Bundle { // with getCanonicalName) function getSafeName ( name ) { - while ( conflicts[ name ] ) { + while ( definers[ name ] || conflicts[ name ] ) { // TODO this seems wonky name = `_${name}`; } diff --git a/src/finalisers/shared/getExportBlock.js b/src/finalisers/shared/getExportBlock.js index ca91179..ba6ffe8 100644 --- a/src/finalisers/shared/getExportBlock.js +++ b/src/finalisers/shared/getExportBlock.js @@ -1,6 +1,9 @@ export default function getExportBlock ( bundle, exportMode, mechanism = 'return' ) { if ( exportMode === 'default' ) { - return `${mechanism} ${bundle.entryModule.replacements.default};`; + const defaultExport = bundle.entryModule.exports.default; + let defaultExportName = bundle.entryModule.replacements.default || defaultExport.statement.node.declaration.name; + + return `${mechanism} ${defaultExportName};`; } return bundle.toExport