diff --git a/src/Bundle.js b/src/Bundle.js index 7d6904d..4c2f5a8 100644 --- a/src/Bundle.js +++ b/src/Bundle.js @@ -210,7 +210,24 @@ export default class Bundle { this.modules.push( module ); this.moduleById.set( id, module ); - return this.fetchAllDependencies( module ).then( () => module ); + return this.fetchAllDependencies( module ).then( () => { + module.exportsAll = blank(); + keys( module.exports ).forEach( name => { + module.exportsAll[name] = module.id; + }); + module.exportAllSources.forEach( source => { + const id = module.resolvedIds[ source ]; + const exportAllModule = this.moduleById.get( id ); + keys( exportAllModule.exportsAll ).forEach( name => { + if ( name in module.exportsAll ) { + throw new Error( `A module cannot have multiple exports with the same name ('${name}')` + + ` from ${module.exportsAll[ name ] } and ${exportAllModule.exportsAll[ name ]}` ); + } + module.exportsAll[ name ] = exportAllModule.exportsAll[ name ]; + }); + }); + return module; + }); }); } diff --git a/src/utils/object.js b/src/utils/object.js index 688b1ca..62c3a07 100644 --- a/src/utils/object.js +++ b/src/utils/object.js @@ -1,3 +1,4 @@ +const { hasOwnProperty } = Object.prototype; export const { keys } = Object; export function blank () { @@ -11,7 +12,7 @@ export function forOwn ( object, func ) { export function assign ( target, ...sources ) { sources.forEach( source => { for ( let key in source ) { - if ( source.hasOwnProperty( key ) ) target[ key ] = source[ key ]; + if ( hasOwnProperty.call( source, key ) ) target[ key ] = source[ key ]; } }); diff --git a/test/function/double-named-export-from/_config.js b/test/function/double-named-export-from/_config.js new file mode 100644 index 0000000..1b402d3 --- /dev/null +++ b/test/function/double-named-export-from/_config.js @@ -0,0 +1,14 @@ +const path = require('path'); +const assert = require( 'assert' ); + +function normalize( file ) { + return path.resolve( __dirname, file ).split( '\\' ).join( '/' ); +} + +module.exports = { + description: 'throws on duplicate export * from', + error: err => { + assert.equal( err.message, `A module cannot have multiple exports with the same name ('foo')` + + ` from ${normalize( 'foo.js' )} and ${normalize( 'deep.js' )}` ); + } +}; diff --git a/test/function/double-named-export-from/bar.js b/test/function/double-named-export-from/bar.js new file mode 100644 index 0000000..0dfd7e9 --- /dev/null +++ b/test/function/double-named-export-from/bar.js @@ -0,0 +1 @@ +export * from './deep.js'; \ No newline at end of file diff --git a/test/function/double-named-export-from/deep.js b/test/function/double-named-export-from/deep.js new file mode 100644 index 0000000..a7b877b --- /dev/null +++ b/test/function/double-named-export-from/deep.js @@ -0,0 +1 @@ +export var foo = 2; \ No newline at end of file diff --git a/test/function/double-named-export-from/foo.js b/test/function/double-named-export-from/foo.js new file mode 100644 index 0000000..467f528 --- /dev/null +++ b/test/function/double-named-export-from/foo.js @@ -0,0 +1 @@ +export var foo = 1; \ No newline at end of file diff --git a/test/function/double-named-export-from/main.js b/test/function/double-named-export-from/main.js new file mode 100644 index 0000000..ae6aade --- /dev/null +++ b/test/function/double-named-export-from/main.js @@ -0,0 +1,2 @@ +export * from './foo.js'; +export * from './bar.js'; \ No newline at end of file