Browse Source

Merge pull request #169 from Victorystick/namespace-missing-export

Informative error message when namespace property doesn't exist
better-aggressive
Rich Harris 9 years ago
parent
commit
4460f40ffa
  1. 8
      src/Module.js
  2. 9
      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 ]; 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.module.id;
throw err;
}
original.addReference( reference ); original.addReference( reference );
return; return;
} }

9
test/function/namespace-missing-export/_config.js

@ -0,0 +1,9 @@
var assert = require( 'assert' );
var path = require( 'path' );
module.exports = {
error: function ( err ) {
assert.equal( path.normalize( err.file ), path.resolve( __dirname, 'empty.js' ) );
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