From baa09c05c8093e19175800d79876ab5f61dab722 Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Thu, 29 Oct 2015 23:52:34 -0400 Subject: [PATCH] allow multiple export alls in entry module --- src/Module.js | 16 +++++++--------- test/function/export-all-multiple/_config.js | 3 +++ test/function/export-all-multiple/bar.js | 1 + test/function/export-all-multiple/foo.js | 1 + test/function/export-all-multiple/main.js | 2 ++ 5 files changed, 14 insertions(+), 9 deletions(-) create mode 100644 test/function/export-all-multiple/_config.js create mode 100644 test/function/export-all-multiple/bar.js create mode 100644 test/function/export-all-multiple/foo.js create mode 100644 test/function/export-all-multiple/main.js diff --git a/src/Module.js b/src/Module.js index 9db3dd8..2c50732 100644 --- a/src/Module.js +++ b/src/Module.js @@ -690,17 +690,20 @@ export default class Module { return otherModule.namespace(); } - return otherModule.traceExport( importDeclaration.name, this ); + const declaration = otherModule.traceExport( importDeclaration.name ); + + if ( !declaration ) throw new Error( `Module ${otherModule.id} does not export ${importDeclaration.name} (imported by ${this.id})` ); + return declaration; } return null; } - traceExport ( name, importer ) { + traceExport ( name ) { // export { foo } from './other' const reexportDeclaration = this.reexports[ name ]; if ( reexportDeclaration ) { - return reexportDeclaration.module.traceExport( reexportDeclaration.localName, this ); + return reexportDeclaration.module.traceExport( reexportDeclaration.localName ); } const exportDeclaration = this.exports[ name ]; @@ -710,14 +713,9 @@ export default class Module { for ( let i = 0; i < this.exportAllModules.length; i += 1 ) { const module = this.exportAllModules[i]; - const declaration = module.traceExport( name, this ); + const declaration = module.traceExport( name ); if ( declaration ) return declaration; } - - let errorMessage = `Module ${this.id} does not export ${name}`; - if ( importer ) errorMessage += ` (imported by ${importer.id})`; - - throw new Error( errorMessage ); } } diff --git a/test/function/export-all-multiple/_config.js b/test/function/export-all-multiple/_config.js new file mode 100644 index 0000000..409610b --- /dev/null +++ b/test/function/export-all-multiple/_config.js @@ -0,0 +1,3 @@ +module.exports = { + description: 'allows multiple export * statements' +}; diff --git a/test/function/export-all-multiple/bar.js b/test/function/export-all-multiple/bar.js new file mode 100644 index 0000000..ca880df --- /dev/null +++ b/test/function/export-all-multiple/bar.js @@ -0,0 +1 @@ +export const BAR = 2; diff --git a/test/function/export-all-multiple/foo.js b/test/function/export-all-multiple/foo.js new file mode 100644 index 0000000..bf55e2d --- /dev/null +++ b/test/function/export-all-multiple/foo.js @@ -0,0 +1 @@ +export const FOO = 1; diff --git a/test/function/export-all-multiple/main.js b/test/function/export-all-multiple/main.js new file mode 100644 index 0000000..364742d --- /dev/null +++ b/test/function/export-all-multiple/main.js @@ -0,0 +1,2 @@ +export * from './foo.js'; +export * from './bar.js';