diff --git a/src/Module.js b/src/Module.js index daacb8b..1c50b10 100644 --- a/src/Module.js +++ b/src/Module.js @@ -72,6 +72,7 @@ export default class Module { else { node.specifiers.forEach( specifier => { this.reexports[ specifier.exported.name ] = { + start: specifier.start, source, localName: specifier.local.name, module: null // filled in later @@ -591,7 +592,16 @@ export default class Module { // export { foo } from './other.js' const reexportDeclaration = this.reexports[ name ]; if ( reexportDeclaration ) { - return reexportDeclaration.module.traceExport( reexportDeclaration.localName ); + const declaration = reexportDeclaration.module.traceExport( reexportDeclaration.localName ); + + if ( !declaration ) { + const err = new Error( `'${reexportDeclaration.localName}' is not exported by '${reexportDeclaration.module.id}' (imported by '${this.id}')` ); + err.file = this.id; + err.loc = getLocation( this.code, reexportDeclaration.start ); + throw err; + } + + return declaration; } const exportDeclaration = this.exports[ name ]; diff --git a/test/function/reexport-missing-error/_config.js b/test/function/reexport-missing-error/_config.js new file mode 100644 index 0000000..6918683 --- /dev/null +++ b/test/function/reexport-missing-error/_config.js @@ -0,0 +1,8 @@ +var assert = require( 'assert' ); + +module.exports = { + description: 'reexporting a missing identifier should print an error', + error: function ( error ) { + assert.ok( /^'foo' is not exported/.test( error.message ) ); + } +}; diff --git a/test/function/reexport-missing-error/empty.js b/test/function/reexport-missing-error/empty.js new file mode 100644 index 0000000..8d5a2a2 --- /dev/null +++ b/test/function/reexport-missing-error/empty.js @@ -0,0 +1 @@ +// this space left intentionally blank diff --git a/test/function/reexport-missing-error/main.js b/test/function/reexport-missing-error/main.js new file mode 100644 index 0000000..2440c7f --- /dev/null +++ b/test/function/reexport-missing-error/main.js @@ -0,0 +1 @@ +export { foo as bar } from './empty.js';