From 7e5f1b14a3e8a30ed28f3197f52942e8f440eeb2 Mon Sep 17 00:00:00 2001 From: Demian Ferreiro Date: Mon, 25 Feb 2013 15:12:25 -0300 Subject: [PATCH] Pass 0-based indexes to CompilerError --- lib/coffee-script/coffee-script.js | 2 +- lib/coffee-script/error.js | 6 +++--- lib/coffee-script/lexer.js | 2 +- src/coffee-script.coffee | 2 +- src/error.coffee | 6 +++--- src/lexer.coffee | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/coffee-script/coffee-script.js b/lib/coffee-script/coffee-script.js index cc8929d7..cda53a54 100644 --- a/lib/coffee-script/coffee-script.js +++ b/lib/coffee-script/coffee-script.js @@ -180,7 +180,7 @@ loc = _arg.loc, token = _arg.token; message = "unexpected " + token; first_line = loc.first_line, first_column = loc.first_column, last_line = loc.last_line, last_column = loc.last_column; - throw new CompilerError(message, first_line + 1, first_column + 1, last_line + 1, last_column + 1); + throw new CompilerError(message, first_line, first_column, last_line, last_column); }; }).call(this); diff --git a/lib/coffee-script/error.js b/lib/coffee-script/error.js index c0a64d3f..ca318cee 100644 --- a/lib/coffee-script/error.js +++ b/lib/coffee-script/error.js @@ -25,11 +25,11 @@ CompilerError.prototype.prettyMessage = function(fileName, code) { var errorLength, errorLine, marker, message; - message = "" + fileName + ":" + this.startLine + ":" + this.startColumn + ": error: " + this.message; + message = "" + fileName + ":" + (this.startLine + 1) + ":" + (this.startColumn + 1) + ": error: " + this.message; if (this.startLine === this.endLine) { - errorLine = code.split('\n')[this.startLine - 1]; + errorLine = code.split('\n')[this.startLine]; errorLength = this.endColumn - this.startColumn + 1; - marker = (repeat(' ', this.startColumn - 1)) + (repeat('^', errorLength)); + marker = (repeat(' ', this.startColumn)) + (repeat('^', errorLength)); message += "\n" + errorLine + "\n" + marker; } else { void 0; diff --git a/lib/coffee-script/lexer.js b/lib/coffee-script/lexer.js index f1e5d464..009dbb1e 100644 --- a/lib/coffee-script/lexer.js +++ b/lib/coffee-script/lexer.js @@ -788,7 +788,7 @@ }; Lexer.prototype.error = function(message) { - throw new CompilerError(message, this.chunkLine + 1, this.chunkColumn + 1); + throw new CompilerError(message, this.chunkLine, this.chunkColumn); }; return Lexer; diff --git a/src/coffee-script.coffee b/src/coffee-script.coffee index 359a86b1..8eb28e0a 100644 --- a/src/coffee-script.coffee +++ b/src/coffee-script.coffee @@ -145,4 +145,4 @@ parser.yy.parseError = (message, {loc, token}) -> message = "unexpected #{token}" {first_line, first_column, last_line, last_column} = loc - throw new CompilerError message, first_line + 1, first_column + 1, last_line + 1, last_column + 1 \ No newline at end of file + throw new CompilerError message, first_line, first_column, last_line, last_column \ No newline at end of file diff --git a/src/error.coffee b/src/error.coffee index 9fde0033..30e425c7 100644 --- a/src/error.coffee +++ b/src/error.coffee @@ -15,11 +15,11 @@ exports.CompilerError = class CompilerError extends Error # showing where the error is. # TODO: tests prettyMessage: (fileName, code) -> - message = "#{fileName}:#{@startLine}:#{@startColumn}: error: #{@message}" + message = "#{fileName}:#{@startLine + 1}:#{@startColumn + 1}: error: #{@message}" if @startLine is @endLine - errorLine = code.split('\n')[@startLine - 1] + errorLine = code.split('\n')[@startLine] errorLength = @endColumn - @startColumn + 1 - marker = (repeat ' ', @startColumn - 1) + (repeat '^', errorLength) + marker = (repeat ' ', @startColumn) + (repeat '^', errorLength) message += "\n#{errorLine}\n#{marker}" else # TODO: How do we show multi-line errors? diff --git a/src/lexer.coffee b/src/lexer.coffee index e4e06f63..2fab121d 100644 --- a/src/lexer.coffee +++ b/src/lexer.coffee @@ -698,7 +698,7 @@ exports.Lexer = class Lexer error: (message) -> # TODO: Are there some cases we could improve the error line number by # passing the offset in the chunk where the error happened? - throw new CompilerError message, @chunkLine + 1, @chunkColumn + 1 + throw new CompilerError message, @chunkLine, @chunkColumn # Constants # ---------