Browse Source

Fail on export all dup optionally

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

5
src/Bundle.js

@ -26,6 +26,8 @@ export default class Bundle {
});
}
this.failOnExportAllDup = Boolean( options.failOnExportAllDup );
this.plugins = ensureArray( options.plugins );
this.plugins.forEach( plugin => {
@ -211,6 +213,9 @@ 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;

3
src/rollup.js

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

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

@ -7,6 +7,9 @@ function normalize( file ) {
module.exports = {
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')` +
` from ${normalize( 'foo.js' )} and ${normalize( 'deep.js' )}` );

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

Loading…
Cancel
Save