From f084957ab6edc9c70333bc83637271730cf3c036 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Segersv=C3=A4rd?= Date: Mon, 31 Aug 2015 10:13:56 +0200 Subject: [PATCH] Access reexports of externals safely when needed. --- src/finalisers/shared/getExportBlock.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/finalisers/shared/getExportBlock.js b/src/finalisers/shared/getExportBlock.js index 1357f31..6c53a3d 100644 --- a/src/finalisers/shared/getExportBlock.js +++ b/src/finalisers/shared/getExportBlock.js @@ -1,22 +1,24 @@ +function wrapAccess ( id ) { + return ( id.originalName !== 'default' && id.module && id.module.isExternal ) ? + id.module.name + propertyAccess( id.originalName ) : id.name; +} + function propertyAccess ( name ) { return name === 'default' ? `['default']` : `.${name}`; } export default function getExportBlock ( bundle, exportMode, mechanism = 'return' ) { if ( exportMode === 'default' ) { - const defaultExportName = bundle.exports.lookup( 'default' ).name; + const id = bundle.exports.lookup( 'default' ); - return `${mechanism} ${defaultExportName};`; + return `${mechanism} ${wrapAccess( id )};`; } return bundle.toExport .map( name => { const id = bundle.exports.lookup( name ); - const reference = ( id.originalName !== 'default' && id.module && id.module.isExternal ) ? - id.module.name + propertyAccess( id.name ) : id.name; - - return `exports${propertyAccess( name )} = ${reference};`; + return `exports${propertyAccess( name )} = ${wrapAccess( id )};`; }) .join( '\n' ); }