Browse Source

Fixed `ExternalModule.needsNamed`, and ES6 imports.

gh-109
Oskar Segersvärd 9 years ago
parent
commit
6e59abd5a6
  1. 4
      src/ExternalModule.js
  2. 20
      src/finalisers/es6.js

4
src/ExternalModule.js

@ -26,9 +26,11 @@ export default class ExternalModule {
if ( !this.exports.defines( name ) ) { if ( !this.exports.defines( name ) ) {
let idName = name; let idName = name;
if (name === 'default' ) { if ( name === 'default' ) {
idName = this.name; idName = this.name;
this.needsDefault = true; this.needsDefault = true;
} else {
this.needsNamed = true;
} }
this.exports.define( name, { this.exports.define( name, {

20
src/finalisers/es6.js

@ -1,13 +1,13 @@
import { blank, keys } from '../utils/object'; import { keys } from '../utils/object';
function uniqueNames ( declarations ) { function specifiersFor ( scope ) {
let uniques = blank(); return keys( scope.names )
.filter( notDefault )
.map( name => {
const id = scope.lookup( name );
declarations return name !== id.name ? `${name} as ${id.name}` : name;
.filter( declaration => !/^(default|\*)$/.test( declaration.name ) ) });
.forEach( declaration => uniques[ declaration.name ] = true );
return keys( uniques );
} }
function notDefault ( name ) { function notDefault ( name ) {
@ -19,7 +19,7 @@ export default function es6 ( bundle, magicString ) {
.map( module => { .map( module => {
const specifiers = []; const specifiers = [];
if ( module.exports.inScope( 'default' ) ) { if ( module.needsDefault ) {
specifiers.push( module.exports.lookup( 'default' ).name ); specifiers.push( module.exports.lookup( 'default' ).name );
} }
@ -29,7 +29,7 @@ export default function es6 ( bundle, magicString ) {
} }
if ( module.needsNamed ) { if ( module.needsNamed ) {
specifiers.push( '{ ' + uniqueNames( module.importedByBundle ) specifiers.push( '{ ' + specifiersFor( module.exports )
.join( ', ' ) + ' }' ); .join( ', ' ) + ' }' );
} }

Loading…
Cancel
Save