diff --git a/lib/coffee-script/coffee-script.js b/lib/coffee-script/coffee-script.js index c29ba622..2b5bc335 100644 --- a/lib/coffee-script/coffee-script.js +++ b/lib/coffee-script/coffee-script.js @@ -233,9 +233,13 @@ var answer, sourceMap; sourceMap = mainModule._sourceMaps[filename]; if (sourceMap) { - answer = sourceMap.getSourcePosition([line, column]); + answer = sourceMap.getSourcePosition([line - 1, column - 1]); + } + if (answer) { + return [answer[0] + 1, answer[1] + 1]; + } else { + return null; } - return answer; }; frames = (function() { var _j, _len1, _results; diff --git a/src/coffee-script.coffee b/src/coffee-script.coffee index 7592039d..e806bf46 100644 --- a/src/coffee-script.coffee +++ b/src/coffee-script.coffee @@ -193,18 +193,12 @@ parser.yy.parseError = (message, {token}) -> # sourceMap, so we must monkey-patch Error to display CoffeeScript source # positions. -# Ideally, this would happen in a way that is scalable to multiple compile-to- -# JS languages trying to do the same thing in the same NodeJS process. We can -# implement it as if there were an API, and then patch in support for that -# API. The following maybe should be in its own npm module that multiple -# compilers can include. - patched = false patchStackTrace = -> return if patched patched = true mainModule = require.main - # Map of filenames -> functions that return a sourceMap string. + # Map of filenames -> sourceMap object. mainModule._sourceMaps = {} # (Assigning to a property of the Module object in the normal module cache is @@ -216,8 +210,8 @@ patchStackTrace = -> getSourceMapping = (filename, line, column) -> sourceMap = mainModule._sourceMaps[filename] - answer = sourceMap.getSourcePosition [line, column] if sourceMap - answer + answer = sourceMap.getSourcePosition [line-1, column-1] if sourceMap + if answer then [answer[0]+1, answer[1]+1] else null frames = for frame in stack break if frame.getFunction() is exports.run