pass line information from coffee parseErrors to the worker

This commit is contained in:
nightwing 2013-04-18 17:07:40 +04:00
commit 4dd3475fd9
4 changed files with 19 additions and 22 deletions

File diff suppressed because one or more lines are too long

View file

@ -49,7 +49,11 @@ module.exports = {
try { try {
coffee.parse("a = 12 f"); coffee.parse("a = 12 f");
} catch (e) { } catch (e) {
assert.ok((e + "").indexOf("Parse error on line 1: Unexpected 'IDENTIFIER'") >= 0); assert.equal(e.message, "Unexpected 'IDENTIFIER'");
assert.equal(e.location.first_line, 0);
assert.equal(e.location.first_column, 7);
assert.equal(e.location.last_line, 0);
assert.equal(e.location.last_column, 7);
} }
} }
}; };

View file

@ -53,27 +53,16 @@ oop.inherits(Worker, Mirror);
try { try {
coffee.parse(value); coffee.parse(value);
} catch(e) { } catch(e) {
var m = e.message.match(/Parse error on line (\d+): (.*)/); var loc = e.location;
if (m) { if (loc) {
this.sender.emit("error", { this.sender.emit("error", {
row: parseInt(m[1], 10) - 1, row: loc.first_line,
column: null, column: loc.first_column,
text: m[2], endRow: loc.last_line,
endColumn: loc.last_column,
text: e.message,
type: "error" type: "error"
}); });
return;
}
if (e instanceof SyntaxError) {
var m = e.message.match(/ on line (\d+)/);
if (m) {
this.sender.emit("error", {
row: parseInt(m[1], 10) - 1,
column: null,
text: e.message.replace(m[0], ""),
type: "error"
});
}
} }
return; return;
} }

View file

@ -124,6 +124,8 @@ void function(){
fs.writeFile(x.path, data, "utf-8", function(err){ fs.writeFile(x.path, data, "utf-8", function(err){
if (err) throw err if (err) throw err
console.log("File " + x.name + " saved.") console.log("File " + x.name + " saved.")
console.warn("mode/coffee/coffee-script file needs to updated manually")
console.warn("mode/coffee/parser.js: parseError function needs to be modified")
}) })
}) })
} }