Merge pull request #2827 from hden/lineno

Lineno
This commit is contained in:
Jeremy Ashkenas
2013-03-17 04:29:44 -07:00
2 changed files with 9 additions and 11 deletions

View File

@@ -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;

View File

@@ -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