|
|
@ -6,6 +6,10 @@ function notDefault ( name ) { |
|
|
|
|
|
|
|
export default function es ( bundle, magicString, { intro, outro } ) { |
|
|
|
const importBlock = bundle.externalModules |
|
|
|
.filter( module => { |
|
|
|
const imported = keys( module.declarations ); |
|
|
|
return imported.length !== 1 || imported[0][0] !== '*'; |
|
|
|
}) |
|
|
|
.map( module => { |
|
|
|
const specifiers = []; |
|
|
|
const specifiersList = [specifiers]; |
|
|
@ -13,11 +17,16 @@ export default function es ( bundle, magicString, { intro, outro } ) { |
|
|
|
.filter( name => name !== '*' && name !== 'default' ) |
|
|
|
.filter( name => module.declarations[ name ].activated ) |
|
|
|
.map( name => { |
|
|
|
if ( name[0] === '*' ) { |
|
|
|
return `* as ${module.name}`; |
|
|
|
} |
|
|
|
|
|
|
|
const declaration = module.declarations[ name ]; |
|
|
|
|
|
|
|
if ( declaration.name === declaration.safeName ) return declaration.name; |
|
|
|
return `${declaration.name} as ${declaration.safeName}`; |
|
|
|
}); |
|
|
|
}) |
|
|
|
.filter( Boolean ); |
|
|
|
|
|
|
|
if ( module.declarations.default ) { |
|
|
|
if ( module.exportsNamespace ) { |
|
|
@ -55,14 +64,25 @@ export default function es ( bundle, magicString, { intro, outro } ) { |
|
|
|
|
|
|
|
const module = bundle.entryModule; |
|
|
|
|
|
|
|
const specifiers = module.getExports().filter( notDefault ).map( name => { |
|
|
|
const exportAllDeclarations = []; |
|
|
|
|
|
|
|
const specifiers = module.getExports() |
|
|
|
.filter( notDefault ) |
|
|
|
.map( name => { |
|
|
|
const declaration = module.traceExport( name ); |
|
|
|
const rendered = declaration.getName( true ); |
|
|
|
|
|
|
|
if ( name[0] === '*' ) { |
|
|
|
// export * from 'external'
|
|
|
|
exportAllDeclarations.push( `export * from '${name.slice( 1 )}';` ); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
return rendered === name ? |
|
|
|
name : |
|
|
|
`${rendered} as ${name}`; |
|
|
|
}); |
|
|
|
}) |
|
|
|
.filter( Boolean ); |
|
|
|
|
|
|
|
let exportBlock = specifiers.length ? `export { ${specifiers.join(', ')} };` : ''; |
|
|
|
|
|
|
@ -72,6 +92,7 @@ export default function es ( bundle, magicString, { intro, outro } ) { |
|
|
|
} |
|
|
|
|
|
|
|
if ( exportBlock ) magicString.append( '\n\n' + exportBlock.trim() ); |
|
|
|
if ( exportAllDeclarations.length ) magicString.append( '\n\n' + exportAllDeclarations.join( '\n' ).trim() ); |
|
|
|
if ( outro ) magicString.append( outro ); |
|
|
|
|
|
|
|
return magicString.trim(); |
|
|
|