Browse Source

Informative error message when namespace property doesn't exist

TypeError: Cannot read property 'addReference' of undefined
->
Export 'foo' is not defined by '<module name>'
better-aggressive
Oskar Segersvärd 9 years ago
parent
commit
41bfd877f3
  1. 8
      src/Module.js
  2. 12
      test/function/namespace-missing-export/_config.js
  3. 0
      test/function/namespace-missing-export/empty.js
  4. 3
      test/function/namespace-missing-export/main.js

8
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;
}

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

0
test/function/namespace-missing-export/empty.js

3
test/function/namespace-missing-export/main.js

@ -0,0 +1,3 @@
import * as mod from './empty.js';
mod.foo();
Loading…
Cancel
Save