output esprima compatible error messages - fixes babel/babel-eslint#3
This commit is contained in:
parent
65a6fce75c
commit
be9da7ef08
@ -62,7 +62,20 @@ exports.parse = function (code) {
|
||||
var comments = opts.onComment = [];
|
||||
var tokens = opts.onToken = [];
|
||||
|
||||
var ast = acorn.parse(code, opts);
|
||||
var ast;
|
||||
try {
|
||||
ast = acorn.parse(code, opts);
|
||||
} catch (err) {
|
||||
if (err instanceof SyntaxError) {
|
||||
err.lineNumber = err.loc.line;
|
||||
err.column = err.loc.column;
|
||||
|
||||
// remove trailing "(LINE:COLUMN)" acorn message and add in esprima syntax error message start
|
||||
err.message = "Line X: " + err.message.replace(/ \((\d+):(\d+)\)$/, "");
|
||||
}
|
||||
|
||||
throw err;
|
||||
}
|
||||
|
||||
// convert tokens
|
||||
ast.tokens = tokens.map(acornToEsprima.toToken);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user