diff --git a/src/finalisers/es6.js b/src/finalisers/es6.js index ffdd16d..a86e04e 100644 --- a/src/finalisers/es6.js +++ b/src/finalisers/es6.js @@ -10,7 +10,13 @@ export default function es6 ( bundle, magicString ) { const specifiers = []; const specifiersList = [specifiers]; const importedNames = keys( module.declarations ) - .filter( name => name !== '*' && name !== 'default' ); + .filter( name => name !== '*' && name !== 'default' ) + .map( name => { + const declaration = module.declarations[ name ]; + + if ( declaration.name === declaration.safeName ) return declaration.name; + return `${declaration.name} as ${declaration.safeName}`; + }); if ( module.declarations.default ) { specifiers.push( module.name ); diff --git a/test/form/conflicting-imports/_config.js b/test/form/conflicting-imports/_config.js new file mode 100644 index 0000000..a9b8ddf --- /dev/null +++ b/test/form/conflicting-imports/_config.js @@ -0,0 +1,3 @@ +module.exports = { + description: 'ensures bundle imports are deconflicted (#659)' +}; diff --git a/test/form/conflicting-imports/_expected/amd.js b/test/form/conflicting-imports/_expected/amd.js new file mode 100644 index 0000000..e3b61ef --- /dev/null +++ b/test/form/conflicting-imports/_expected/amd.js @@ -0,0 +1,7 @@ +define(['foo', 'bar'], function (foo, bar) { 'use strict'; + + console.log( bar.a ); + + console.log( foo.a ); + +}); \ No newline at end of file diff --git a/test/form/conflicting-imports/_expected/cjs.js b/test/form/conflicting-imports/_expected/cjs.js new file mode 100644 index 0000000..2c2c321 --- /dev/null +++ b/test/form/conflicting-imports/_expected/cjs.js @@ -0,0 +1,8 @@ +'use strict'; + +var foo = require('foo'); +var bar = require('bar'); + +console.log( bar.a ); + +console.log( foo.a ); \ No newline at end of file diff --git a/test/form/conflicting-imports/_expected/es6.js b/test/form/conflicting-imports/_expected/es6.js new file mode 100644 index 0000000..281b463 --- /dev/null +++ b/test/form/conflicting-imports/_expected/es6.js @@ -0,0 +1,6 @@ +import { a } from 'foo'; +import { a as a$1 } from 'bar'; + +console.log( a$1 ); + +console.log( a ); diff --git a/test/form/conflicting-imports/_expected/iife.js b/test/form/conflicting-imports/_expected/iife.js new file mode 100644 index 0000000..6f9d443 --- /dev/null +++ b/test/form/conflicting-imports/_expected/iife.js @@ -0,0 +1,8 @@ +(function (foo,bar) { + 'use strict'; + + console.log( bar.a ); + + console.log( foo.a ); + +}(foo,bar)); \ No newline at end of file diff --git a/test/form/conflicting-imports/_expected/umd.js b/test/form/conflicting-imports/_expected/umd.js new file mode 100644 index 0000000..8254c77 --- /dev/null +++ b/test/form/conflicting-imports/_expected/umd.js @@ -0,0 +1,11 @@ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('foo'), require('bar')) : + typeof define === 'function' && define.amd ? define(['foo', 'bar'], factory) : + (factory(global.foo,global.bar)); +}(this, function (foo,bar) { 'use strict'; + + console.log( bar.a ); + + console.log( foo.a ); + +})); \ No newline at end of file diff --git a/test/form/conflicting-imports/main.js b/test/form/conflicting-imports/main.js new file mode 100644 index 0000000..8ed570b --- /dev/null +++ b/test/form/conflicting-imports/main.js @@ -0,0 +1,4 @@ +import { a } from 'foo'; +import './other.js'; + +console.log( a ); diff --git a/test/form/conflicting-imports/other.js b/test/form/conflicting-imports/other.js new file mode 100644 index 0000000..157ab35 --- /dev/null +++ b/test/form/conflicting-imports/other.js @@ -0,0 +1,3 @@ +import { a } from 'bar'; + +console.log( a );