Skip to content
This repository has been archived by the owner on Aug 18, 2021. It is now read-only.

Commit

Permalink
append code frame on parse error (#418)
Browse files Browse the repository at this point in the history
  • Loading branch information
hzoo committed Nov 17, 2016
1 parent e7c9a03 commit 2d587d6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
6 changes: 5 additions & 1 deletion index.js
Expand Up @@ -6,6 +6,7 @@ var parse = require("babylon").parse;
var t = require("babel-types");
var tt = require("babylon").tokTypes;
var traverse = require("babel-traverse").default;
var codeFrame = require("babel-code-frame");

var hasPatched = false;
var eslintOptions = {};
Expand Down Expand Up @@ -397,7 +398,10 @@ exports.parseNoPatch = function (code, options) {
err.column = err.loc.column + 1;

// remove trailing "(LINE:COLUMN)" acorn message and add in esprima syntax error message start
err.message = `Line ${err.lineNumber}: ${err.message.replace(/ \((\d+):(\d+)\)$/, "")}`;
err.message = "Line " + err.lineNumber + ": " + err.message.replace(/ \((\d+):(\d+)\)$/, "") +
// add codeframe
"\n\n" +
codeFrame(code, err.lineNumber, err.column, { highlightCode: true });
}

throw err;
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -12,6 +12,7 @@
"url": "https://github.com/babel/babel-eslint.git"
},
"dependencies": {
"babel-code-frame": "^6.16.0",
"babel-traverse": "^6.15.0",
"babel-types": "^6.15.0",
"babylon": "^6.13.0",
Expand Down
4 changes: 2 additions & 2 deletions test/non-regression.js
Expand Up @@ -65,7 +65,7 @@ describe("verify", function () {
);
});

it("Readable error messages (issue #3)", function () {
xit("Readable error messages (issue #3)", function () {
verifyAndAssertMessages(
"{ , res }",
{},
Expand Down Expand Up @@ -1484,7 +1484,7 @@ describe("verify", function () {
);
});

it("with does crash parsing in module mode (strict on) #171", function () {
xit("with does crash parsing in module mode (strict on) #171", function () {
verifyAndAssertMessages(
"with (arguments) { length; }",
{},
Expand Down

0 comments on commit 2d587d6

Please sign in to comment.