Browse Source

Add error message when reexporting missing identifier

better-aggressive
Oskar Segersvärd 9 years ago
parent
commit
bc0b6c514a
  1. 12
      src/Module.js
  2. 8
      test/function/reexport-missing-error/_config.js
  3. 1
      test/function/reexport-missing-error/empty.js
  4. 1
      test/function/reexport-missing-error/main.js

12
src/Module.js

@ -194,6 +194,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
@ -724,7 +725,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 ];

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

1
test/function/reexport-missing-error/empty.js

@ -0,0 +1 @@
// this space left intentionally blank

1
test/function/reexport-missing-error/main.js

@ -0,0 +1 @@
export { foo as bar } from './empty.js';
Loading…
Cancel
Save