|
@ -3,33 +3,28 @@ import { keys } from '../utils/object'; |
|
|
export default function es6 ( bundle, magicString, { exportMode }, options ) { |
|
|
export default function es6 ( bundle, magicString, { exportMode }, options ) { |
|
|
const importBlock = bundle.externalModules |
|
|
const importBlock = bundle.externalModules |
|
|
.map( module => { |
|
|
.map( module => { |
|
|
let defaultSpecifier = null; |
|
|
const specifiers = []; |
|
|
let namedSpecifiers = null; |
|
|
|
|
|
|
|
|
|
|
|
if ( module.needsDefault ) { |
|
|
if ( module.needsDefault ) { |
|
|
const defaultImportDeclaration = module.importedByBundle.filter( declaration => declaration.name === 'default' )[0]; |
|
|
specifiers.push( module.importedByBundle.filter( declaration => |
|
|
defaultSpecifier = defaultImportDeclaration.localName; |
|
|
declaration.name === 'default' )[0].localName ); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if ( module.needsNamed ) { |
|
|
if ( module.needsAll ) { |
|
|
namedSpecifiers = '{ ' + module.importedByBundle |
|
|
specifiers.push( '* as ' + module.importedByBundle.filter( declaration => |
|
|
.filter( declaration => declaration.name !== 'default' ) |
|
|
declaration.name === '*' )[0].localName ); |
|
|
.map( declaration => { |
|
|
|
|
|
const { name, localName } = declaration; |
|
|
|
|
|
|
|
|
|
|
|
return name === localName ? |
|
|
|
|
|
name : |
|
|
|
|
|
`${name} as ${localName}`; |
|
|
|
|
|
}) |
|
|
|
|
|
.join( ', ' ) + ' }'; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const specifiers = module.needsDefault && module.needsNamed ? |
|
|
if ( module.needsNamed ) { |
|
|
`${defaultSpecifier}, ${namedSpecifiers}` : |
|
|
specifiers.push( '{ ' + module.importedByBundle |
|
|
( defaultSpecifier || namedSpecifiers ); |
|
|
.filter( declaration => !/^(default|\*)$/.test( declaration.name ) ) |
|
|
|
|
|
.map( ({ name, localName }) => |
|
|
|
|
|
name === localName ? name : `${name} as ${localName}` ) |
|
|
|
|
|
.join( ', ' ) + ' }' ); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
return specifiers ? |
|
|
return specifiers.length ? |
|
|
`import ${specifiers} from '${module.id}';` : |
|
|
`import ${specifiers.join( ', ' )} from '${module.id}';` : |
|
|
`import '${module.id}';`; |
|
|
`import '${module.id}';`; |
|
|
}) |
|
|
}) |
|
|
.join( '\n' ); |
|
|
.join( '\n' ); |
|
|