Skip to content

Commit 00cba19

Browse files
committed
Better fix for #36 (thanks @pspeter3).
1 parent 6f539e6 commit 00cba19

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

source-map-support.js

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,6 @@ function retrieveSourceMap(source) {
114114
}
115115

116116
function mapSourcePosition(position) {
117-
// Fix position in Node where some (internal) code is prepended.
118-
// See https://github.com/evanw/node-source-map-support/issues/36
119-
if (!isInBrowser() && position.line === 1) {
120-
position.column -= 62
121-
}
122-
123117
var sourceMap = sourceMapCache[position.source];
124118
if (!sourceMap) {
125119
// Call the (overrideable) retrieveSourceMap function to get the source map.
@@ -271,16 +265,25 @@ function cloneCallSite(frame) {
271265
return object;
272266
}
273267

274-
function wrapCallSite(frame) {
268+
function wrapCallSite(frame, fromModule) {
275269
// Most call sites will return the source file from getFileName(), but code
276270
// passed to eval() ending in "//# sourceURL=..." will return the source file
277271
// from getScriptNameOrSourceURL() instead
278272
var source = frame.getFileName() || frame.getScriptNameOrSourceURL();
279273
if (source) {
274+
var line = frame.getLineNumber();
275+
var column = frame.getColumnNumber() - 1;
276+
277+
// Fix position in Node where some (internal) code is prepended.
278+
// See https://github.com/evanw/node-source-map-support/issues/36
279+
if (fromModule && line === 1) {
280+
column -= 63;
281+
}
282+
280283
var position = mapSourcePosition({
281284
source: source,
282-
line: frame.getLineNumber(),
283-
column: frame.getColumnNumber() - 1
285+
line: line,
286+
column: column
284287
});
285288
frame = cloneCallSite(frame);
286289
frame.getFileName = function() { return position.source; };
@@ -310,8 +313,15 @@ function prepareStackTrace(error, stack) {
310313
fileContentsCache = {};
311314
sourceMapCache = {};
312315
}
316+
317+
var fromModule =
318+
!isInBrowser() &&
319+
stack.length &&
320+
stack[stack.length - 1].getFileName() === 'module.js'
321+
;
322+
313323
return error + stack.map(function(frame) {
314-
return '\n at ' + wrapCallSite(frame);
324+
return '\n at ' + wrapCallSite(frame, fromModule);
315325
}).join('');
316326
}
317327

0 commit comments

Comments
 (0)