diff --git a/lib/coffee-script/coffee-script.js b/lib/coffee-script/coffee-script.js index 3cd22229..df371bd8 100644 --- a/lib/coffee-script/coffee-script.js +++ b/lib/coffee-script/coffee-script.js @@ -169,10 +169,10 @@ parser.yy = require('./nodes'); parser.yy.parseError = function(message, _arg) { - var first_column, first_line, last_column, last_line, loc, token; - loc = _arg.loc, token = _arg.token; + var first_column, first_line, last_column, last_line, token, _ref; + 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; + _ref = parser.lexer.yylloc, first_line = _ref.first_line, first_column = _ref.first_column, last_line = _ref.last_line, last_column = _ref.last_column; throw new CompilerError(message, first_line, first_column, last_line, last_column); }; diff --git a/src/coffee-script.coffee b/src/coffee-script.coffee index d10fd188..c4bf5c15 100644 --- a/src/coffee-script.coffee +++ b/src/coffee-script.coffee @@ -137,13 +137,13 @@ parser.lexer = parser.yy = require './nodes' # Override Jison's default error handling function. -parser.yy.parseError = (message, {loc, token}) -> +parser.yy.parseError = (message, {token}) -> # Disregard Jison's message, it contains redundant line numer information. message = "unexpected #{token}" - # FIXME The `loc` received does not correspond to the `token` token, but to - # the one before it instead. That's why the test in error_messages.coffee is - # failing. There should be a way to get the location data... maybe accessing - # the lexer's tokens? - {first_line, first_column, last_line, last_column} = loc + # The second argument has a `loc` property, which should have the location + # data for this token. Unfortunately, Jison seems to send an outdated `loc` + # (from the previous token), so we take the location information directly + # from the lexer. + {first_line, first_column, last_line, last_column} = parser.lexer.yylloc throw new CompilerError message, first_line, first_column, last_line, last_column \ No newline at end of file diff --git a/test/error_messages.coffee b/test/error_messages.coffee index 7c406666..436f7847 100644 --- a/test/error_messages.coffee +++ b/test/error_messages.coffee @@ -20,13 +20,12 @@ test "lexer errors formating", -> ^ ''' -# FIXME Test not passing. See "parser.yy.parseError" in coffee-script.coffee test "parser error formating", -> assertErrorFormat ''' foo in bar or in baz ''', ''' - test.coffee:1:12: error: unexpected RELATION + test.coffee:1:15: error: unexpected RELATION foo in bar or in baz ^^ '''