Browse Source

Warn on namespace conflicts

semi-dynamic-namespace-imports
Bogdan Chadkin 9 years ago
parent
commit
8798331389
  1. 7
      src/Bundle.js
  2. 3
      src/rollup.js
  3. 9
      test/function/double-named-export-from/_config.js
  4. 2
      test/test.js

7
src/Bundle.js

@ -26,8 +26,6 @@ export default class Bundle {
});
}
this.failOnExportAllDup = Boolean( options.failOnExportAllDup );
this.plugins = ensureArray( options.plugins );
this.plugins.forEach( plugin => {
@ -213,9 +211,6 @@ export default class Bundle {
this.moduleById.set( id, module );
return this.fetchAllDependencies( module ).then( () => {
if ( !this.failOnExportAllDup ) {
return module;
}
module.exportsAll = blank();
keys( module.exports ).forEach( name => {
module.exportsAll[name] = module.id;
@ -225,7 +220,7 @@ export default class Bundle {
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}')` +
this.onwarn( `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 ];

3
src/rollup.js

@ -31,8 +31,7 @@ const ALLOWED_KEYS = [
'sourceMapFile',
'targets',
'treeshake',
'useStrict',
'failOnExportAllDup'
'useStrict'
];
export function rollup ( options ) {

9
test/function/double-named-export-from/_config.js

@ -6,12 +6,11 @@ function normalize( file ) {
}
module.exports = {
solo: true,
description: 'throws on duplicate export * from',
options: {
failOnExportAllDup: true
},
error: err => {
assert.equal( err.message, `A module cannot have multiple exports with the same name ('foo')` +
warnings(warnings) {
assert.equal( warnings[0], `A module cannot have multiple exports with the same name ('foo')` +
` from ${normalize( 'foo.js' )} and ${normalize( 'deep.js' )}` );
assert.equal( warnings.length, 1 );
}
};

2
test/test.js

@ -76,7 +76,7 @@ describe( 'rollup', function () {
return rollup.rollup({ entry: 'x', plUgins: [] }).then( function () {
throw new Error( 'Missing expected error' );
}, function ( err ) {
assert.equal( err.message, 'Unexpected key \'plUgins\' found, expected one of: acorn, banner, cache, dest, entry, exports, external, footer, format, globals, indent, intro, moduleId, moduleName, noConflict, onwarn, outro, plugins, preferConst, sourceMap, sourceMapFile, targets, treeshake, useStrict, failOnExportAllDup' );
assert.equal( err.message, 'Unexpected key \'plUgins\' found, expected one of: acorn, banner, cache, dest, entry, exports, external, footer, format, globals, indent, intro, moduleId, moduleName, noConflict, onwarn, outro, plugins, preferConst, sourceMap, sourceMapFile, targets, treeshake, useStrict' );
});
});
});

Loading…
Cancel
Save