diff --git a/src/Bundle.js b/src/Bundle.js index 7659ce0..46c8fff 100644 --- a/src/Bundle.js +++ b/src/Bundle.js @@ -309,6 +309,7 @@ export default class Bundle { keys( this.entryModule.reexports ).forEach( key => { const reexportDeclaration = this.entryModule.reexports[ key ]; + if ( reexportDeclaration.module.isExternal ) return; const originalDeclaration = reexportDeclaration.module.findDeclaration( reexportDeclaration.importedName ); if ( originalDeclaration && originalDeclaration.type === 'VariableDeclaration' ) { @@ -530,6 +531,22 @@ export default class Bundle { traceExport ( module, name, es6 ) { const reexportDeclaration = module.reexports[ name ]; if ( reexportDeclaration ) { + if ( reexportDeclaration.module.isExternal ) { + if ( name === 'default' ) { + return reexportDeclaration.module.needsNamed && !es6 ? + `${reexportDeclaration.module.name}__default` : + reexportDeclaration.module.name; + } + + if ( name === '*' ) { + return reexportDeclaration.module.name; + } + + return es6 ? + name : + `${reexportDeclaration.module.name}.${name}`; + } + return this.traceExport( reexportDeclaration.module, reexportDeclaration.importedName ); } diff --git a/src/Module.js b/src/Module.js index dc30291..a004182 100644 --- a/src/Module.js +++ b/src/Module.js @@ -239,7 +239,7 @@ export default class Module { let module = this; let name = specifier.exported.name; - while ( module.reexports[ name ] && module.reexports[ name ].isUsed ) { + while ( !module.isExternal && module.reexports[ name ] && module.reexports[ name ].isUsed ) { reexport = module.reexports[ name ]; module = reexport.module; name = reexport.importedName; @@ -266,15 +266,6 @@ export default class Module { keys( statement.dependsOn ).forEach( name => { if ( statement.defines[ name ] ) return; - let module = this; - let reexportDeclaration; - while ( module.reexports[ name ] ) { - reexportDeclaration = module.reexports[ name ]; - module = reexportDeclaration.module; - name = reexportDeclaration.importedName; - } - - addDependency( weakDependencies, reexportDeclaration ) || addDependency( weakDependencies, this.exportAlls[ name ] ) || addDependency( weakDependencies, this.imports[ name ] ); }); @@ -395,7 +386,7 @@ export default class Module { return module.markAllExportStatements(); } - return module.markExport( importDeclaration.name, 'TODO_suggestedName', this ); + return module.markExport( importDeclaration.name, name, this ); }); } @@ -461,7 +452,7 @@ export default class Module { return this.bundle.fetchModule( reexportDeclaration.source, this.id ) .then( otherModule => { reexportDeclaration.module = otherModule; - return otherModule.markExport( reexportDeclaration.importedName, 'TODO_suggestedName', this ); + return otherModule.markExport( reexportDeclaration.importedName, suggestedName, this ); }); } diff --git a/src/Statement.js b/src/Statement.js index a710d36..00d4c4e 100644 --- a/src/Statement.js +++ b/src/Statement.js @@ -246,7 +246,9 @@ export default class Statement { reexport.isUsed = true; reexport.module = otherModule; - return otherModule.markExport( specifier.local.name, specifier.exported.name, this.module ); + return otherModule.isExternal ? + null : + otherModule.markExport( specifier.local.name, specifier.exported.name, this.module ); }); }); } diff --git a/src/finalisers/shared/getExportBlock.js b/src/finalisers/shared/getExportBlock.js index c789669..72aee4a 100644 --- a/src/finalisers/shared/getExportBlock.js +++ b/src/finalisers/shared/getExportBlock.js @@ -11,7 +11,10 @@ export default function getExportBlock ( bundle, exportMode, mechanism = 'return return bundle.toExport .map( name => { const prop = name === 'default' ? `['default']` : `.${name}`; - name = bundle.trace( bundle.entryModule, name ); + const reexport = bundle.entryModule.reexports[ name ]; + name = reexport ? + bundle.traceExport( bundle.entryModule, name ) : + bundle.trace( bundle.entryModule, name ); return `exports${prop} = ${name};`; }) .join( '\n' );