mirror of https://github.com/lukechilds/rollup.git
Oskar Segersvärd
10 years ago
1 changed files with 8 additions and 6 deletions
@ -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' ); |
|||
} |
|||
|
Loading…
Reference in new issue