1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

found a linear shift of lineno, dirty patch for now

It seems that js -> coffee line mapping has a linear shifting.
Dirty patch by applying linear correction.
Dumb, but maybe a hint.
This commit is contained in:
Hao-kang Den 2013-03-13 21:43:29 +08:00
parent 56413ba3b4
commit 052e3cc8eb
2 changed files with 13 additions and 9 deletions

View file

@ -233,7 +233,10 @@
var answer, sourceMap;
sourceMap = mainModule._sourceMaps[filename];
if (sourceMap) {
answer = sourceMap.getSourcePosition([line, column]);
answer = sourceMap.getSourcePosition([line - 1, column]);
}
if (answer) {
answer[0] += 1;
}
return answer;
};

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,7 +210,14 @@ patchStackTrace = ->
getSourceMapping = (filename, line, column) ->
sourceMap = mainModule._sourceMaps[filename]
answer = sourceMap.getSourcePosition [line, column] if sourceMap
answer = sourceMap.getSourcePosition [line - 1, column] if sourceMap
if answer
answer[0] += 1
# # un-comment to dirty patch the column number, not very accurate
# if answer[1] > 3
# answer[1] -= 3
# else
# answer[1] = 0
answer
frames = for frame in stack