|
|
@ -10,6 +10,22 @@ function uniqueNames ( declarations ) { |
|
|
|
return keys( uniques ); |
|
|
|
} |
|
|
|
|
|
|
|
function notDefault ( name ) { |
|
|
|
return name !== 'default'; |
|
|
|
} |
|
|
|
|
|
|
|
function getSpecifiers ( exports, replacements ) { |
|
|
|
return keys( exports ).filter( notDefault ).map( name => { |
|
|
|
const specifier = exports[ name ]; |
|
|
|
console.log( 'specifier', specifier ) |
|
|
|
const canonicalName = replacements[ specifier.localName ] || specifier.localName; |
|
|
|
|
|
|
|
return canonicalName === name ? |
|
|
|
name : |
|
|
|
`${canonicalName} as ${name}`; |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
export default function es6 ( bundle, magicString ) { |
|
|
|
const importBlock = bundle.externalModules |
|
|
|
.map( module => { |
|
|
@ -40,23 +56,20 @@ export default function es6 ( bundle, magicString ) { |
|
|
|
magicString.prepend( importBlock + '\n\n' ); |
|
|
|
} |
|
|
|
|
|
|
|
const exports = bundle.entryModule.exports; |
|
|
|
const exportBlock = keys( exports ).map( exportedName => { |
|
|
|
const specifier = exports[ exportedName ]; |
|
|
|
const module = bundle.entryModule; |
|
|
|
|
|
|
|
const canonicalName = bundle.entryModule.replacements[ specifier.localName ] || specifier.localName; |
|
|
|
const specifiers = getSpecifiers( module.exports, module.replacements ) |
|
|
|
.concat( getSpecifiers( module.reexports, module.replacements ) ); |
|
|
|
|
|
|
|
if ( exportedName === 'default' ) { |
|
|
|
return `export default ${canonicalName};`; |
|
|
|
} |
|
|
|
let exportBlock = specifiers.length ? `export { ${specifiers.join(', ')} };` : ''; |
|
|
|
|
|
|
|
return exportedName === canonicalName ? |
|
|
|
`export { ${exportedName} };` : |
|
|
|
`export { ${canonicalName} as ${exportedName} };`; |
|
|
|
}).join( '\n' ); |
|
|
|
const defaultExport = module.exports.default || module.reexports.default; |
|
|
|
if ( defaultExport ) { |
|
|
|
exportBlock += `export default ${bundle.traceExport(module,'default')};`; |
|
|
|
} |
|
|
|
|
|
|
|
if ( exportBlock ) { |
|
|
|
magicString.append( '\n\n' + exportBlock ); |
|
|
|
magicString.append( '\n\n' + exportBlock.trim() ); |
|
|
|
} |
|
|
|
|
|
|
|
return magicString.trim(); |
|
|
|