From 6e59abd5a6da9553c1bea4adb841c717cee54f38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Segersv=C3=A4rd?= Date: Wed, 26 Aug 2015 15:19:25 +0200 Subject: [PATCH] Fixed `ExternalModule.needsNamed`, and ES6 imports. --- src/ExternalModule.js | 4 +++- src/finalisers/es6.js | 20 ++++++++++---------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/ExternalModule.js b/src/ExternalModule.js index 5d782c2..185f634 100644 --- a/src/ExternalModule.js +++ b/src/ExternalModule.js @@ -26,9 +26,11 @@ export default class ExternalModule { if ( !this.exports.defines( name ) ) { let idName = name; - if (name === 'default' ) { + if ( name === 'default' ) { idName = this.name; this.needsDefault = true; + } else { + this.needsNamed = true; } this.exports.define( name, { diff --git a/src/finalisers/es6.js b/src/finalisers/es6.js index ac928ed..9b36f9f 100644 --- a/src/finalisers/es6.js +++ b/src/finalisers/es6.js @@ -1,13 +1,13 @@ -import { blank, keys } from '../utils/object'; +import { keys } from '../utils/object'; -function uniqueNames ( declarations ) { - let uniques = blank(); +function specifiersFor ( scope ) { + return keys( scope.names ) + .filter( notDefault ) + .map( name => { + const id = scope.lookup( name ); - declarations - .filter( declaration => !/^(default|\*)$/.test( declaration.name ) ) - .forEach( declaration => uniques[ declaration.name ] = true ); - - return keys( uniques ); + return name !== id.name ? `${name} as ${id.name}` : name; + }); } function notDefault ( name ) { @@ -19,7 +19,7 @@ export default function es6 ( bundle, magicString ) { .map( module => { const specifiers = []; - if ( module.exports.inScope( 'default' ) ) { + if ( module.needsDefault ) { specifiers.push( module.exports.lookup( 'default' ).name ); } @@ -29,7 +29,7 @@ export default function es6 ( bundle, magicString ) { } if ( module.needsNamed ) { - specifiers.push( '{ ' + uniqueNames( module.importedByBundle ) + specifiers.push( '{ ' + specifiersFor( module.exports ) .join( ', ' ) + ' }' ); }