diff --git a/src/Bundle.js b/src/Bundle.js index fa53ae6..63d6b79 100644 --- a/src/Bundle.js +++ b/src/Bundle.js @@ -127,6 +127,13 @@ export default class Bundle { this.externalModules.forEach( module => { module.name = getSafeName( module.name ); + + // ensure we don't shadow named external imports, if + // we're creating an ES6 bundle + keys( module.declarations ).forEach( name => { + const declaration = module.declarations[ name ]; + declaration.setSafeName( getSafeName( name ) ); + }); }); this.modules.forEach( module => { diff --git a/src/Declaration.js b/src/Declaration.js index 831a966..6710ff5 100644 --- a/src/Declaration.js +++ b/src/Declaration.js @@ -221,6 +221,8 @@ export class ExternalDeclaration { this.module = module; this.name = name; this.isExternal = true; + + this.safeName = null; } addAlias () { @@ -246,13 +248,17 @@ export class ExternalDeclaration { this.module.name; } - return es6 ? this.name : `${this.module.name}.${this.name}`; + return es6 ? this.safeName : `${this.module.name}.${this.name}`; } run () { return true; } + setSafeName ( name ) { + this.safeName = name; + } + use () { // noop? } diff --git a/test/form/external-import-alias-shadow/_expected/amd.js b/test/form/external-import-alias-shadow/_expected/amd.js index ca4d1a5..b60b8be 100644 --- a/test/form/external-import-alias-shadow/_expected/amd.js +++ b/test/form/external-import-alias-shadow/_expected/amd.js @@ -1,9 +1,9 @@ define(['acorn'], function (acorn) { 'use strict'; - function parse(source) { + function parse$1(source) { return acorn.parse(source, { ecmaVersion: 6 }); } - console.log(parse('foo')); + console.log(parse$1('foo')); -}); \ No newline at end of file +}); diff --git a/test/form/external-import-alias-shadow/_expected/cjs.js b/test/form/external-import-alias-shadow/_expected/cjs.js index 60ff081..26f9991 100644 --- a/test/form/external-import-alias-shadow/_expected/cjs.js +++ b/test/form/external-import-alias-shadow/_expected/cjs.js @@ -2,8 +2,8 @@ var acorn = require('acorn'); -function parse(source) { +function parse$1(source) { return acorn.parse(source, { ecmaVersion: 6 }); } -console.log(parse('foo')); \ No newline at end of file +console.log(parse$1('foo')); diff --git a/test/form/external-import-alias-shadow/_expected/es6.js b/test/form/external-import-alias-shadow/_expected/es6.js index bdb3b4b..2750231 100644 --- a/test/form/external-import-alias-shadow/_expected/es6.js +++ b/test/form/external-import-alias-shadow/_expected/es6.js @@ -1,7 +1,7 @@ import { parse } from 'acorn'; -function parse$$(source) { +function parse$1(source) { return parse(source, { ecmaVersion: 6 }); } -console.log(parse$$('foo')); \ No newline at end of file +console.log(parse$1('foo')); diff --git a/test/form/external-import-alias-shadow/_expected/iife.js b/test/form/external-import-alias-shadow/_expected/iife.js index e296ac0..fea2c7e 100644 --- a/test/form/external-import-alias-shadow/_expected/iife.js +++ b/test/form/external-import-alias-shadow/_expected/iife.js @@ -1,10 +1,10 @@ (function (acorn) { 'use strict'; - function parse(source) { + function parse$1(source) { return acorn.parse(source, { ecmaVersion: 6 }); } - console.log(parse('foo')); + console.log(parse$1('foo')); -}(acorn)); \ No newline at end of file +}(acorn)); diff --git a/test/form/external-import-alias-shadow/_expected/umd.js b/test/form/external-import-alias-shadow/_expected/umd.js index 90827c6..7be513d 100644 --- a/test/form/external-import-alias-shadow/_expected/umd.js +++ b/test/form/external-import-alias-shadow/_expected/umd.js @@ -4,10 +4,10 @@ (factory(global.acorn)); }(this, function (acorn) { 'use strict'; - function parse(source) { + function parse$1(source) { return acorn.parse(source, { ecmaVersion: 6 }); } - console.log(parse('foo')); + console.log(parse$1('foo')); -})); \ No newline at end of file +}));