diff --git a/src/Module.js b/src/Module.js index 96d6869..b8ea3a2 100644 --- a/src/Module.js +++ b/src/Module.js @@ -76,6 +76,14 @@ class SyntheticNamespaceDeclaration { const original = this.originals[ reference.name ]; + // throw with an informative error message if the reference doesn't exist. + if ( !original ) { + const err = new Error( `Export '${reference.name}' is not defined by '${this.module.id}'` ); + err.code = 'MISSING_EXPORT'; + err.file = this.id; + throw err; + } + original.addReference( reference ); return; } diff --git a/test/function/namespace-missing-export/_config.js b/test/function/namespace-missing-export/_config.js new file mode 100644 index 0000000..6236fac --- /dev/null +++ b/test/function/namespace-missing-export/_config.js @@ -0,0 +1,12 @@ +var assert = require( 'assert' ); + +module.exports = { + solo: true, + + error: function ( err ) { + console.log( err.message ); + // assert.equal( path.normalize(err.file), path.resolve( __dirname, 'main.js' ) ); + // assert.deepEqual( err.loc, { line: 8, column: 0 }); + assert.ok( /Export "foo" is not defined by/.test( err.message ) ); + } +}; diff --git a/test/function/namespace-missing-export/empty.js b/test/function/namespace-missing-export/empty.js new file mode 100644 index 0000000..e69de29 diff --git a/test/function/namespace-missing-export/main.js b/test/function/namespace-missing-export/main.js new file mode 100644 index 0000000..bfb885d --- /dev/null +++ b/test/function/namespace-missing-export/main.js @@ -0,0 +1,3 @@ +import * as mod from './empty.js'; + +mod.foo();