Browse Source

Fail on duplicating in export * from

semi-dynamic-namespace-imports
Bogdan Chadkin 9 years ago
parent
commit
d5c232d6cc
  1. 19
      src/Bundle.js
  2. 3
      src/utils/object.js
  3. 14
      test/function/double-named-export-from/_config.js
  4. 1
      test/function/double-named-export-from/bar.js
  5. 1
      test/function/double-named-export-from/deep.js
  6. 1
      test/function/double-named-export-from/foo.js
  7. 2
      test/function/double-named-export-from/main.js

19
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;
});
});
}

3
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 ];
}
});

14
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' )}` );
}
};

1
test/function/double-named-export-from/bar.js

@ -0,0 +1 @@
export * from './deep.js';

1
test/function/double-named-export-from/deep.js

@ -0,0 +1 @@
export var foo = 2;

1
test/function/double-named-export-from/foo.js

@ -0,0 +1 @@
export var foo = 1;

2
test/function/double-named-export-from/main.js

@ -0,0 +1,2 @@
export * from './foo.js';
export * from './bar.js';
Loading…
Cancel
Save