Browse Source

include file info with error object when parse fails

contingency-plan
Rich Harris 10 years ago
parent
commit
2bffd6dbb0
  1. 16
      src/Module.js
  2. 5
      test/samples/import-not-at-top-level-fails/_config.js
  3. 0
      test/samples/import-not-at-top-level-fails/main.js

16
src/Module.js

@ -18,10 +18,16 @@ export default class Module {
filename: path
});
this.ast = parse( code, {
ecmaVersion: 6,
sourceType: 'module'
});
try {
this.ast = parse( code, {
ecmaVersion: 6,
sourceType: 'module'
});
} catch ( err ) {
err.file = path;
throw err;
}
this.analyse();
}
@ -311,4 +317,4 @@ export default class Module {
this.defaultExportName = name;
}
}
}
}

5
test/samples/import-not-at-top-level-fails/_config.js

@ -1,8 +1,11 @@
var path = require( 'path' );
var assert = require( 'assert' );
module.exports = {
description: 'disallows non-top-level imports',
error: function ( err ) {
assert.ok( false, 'TODO: pick an error message' );
assert.equal( err.file, path.resolve( __dirname, 'main.js' ) );
assert.deepEqual( err.loc, { line: 2, column: 2 });
assert.ok( /may only appear at the top level/.test( err.message ) );
}
};

0
test/samples/import-not-at-top-level-fails/index.js → test/samples/import-not-at-top-level-fails/main.js

Loading…
Cancel
Save