Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions source-map-support.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,8 @@ function wrapCallSite(frame) {
column: column
});
frame = cloneCallSite(frame);
var originalFunctionName = frame.getFunctionName;
frame.getFunctionName = function() { return position.name || originalFunctionName(); };
frame.getFileName = function() { return position.source; };
frame.getLineNumber = function() { return position.line; };
frame.getColumnNumber = function() { return position.column + 1; };
Expand Down
44 changes: 32 additions & 12 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ it('throw with empty source map', function() {
'throw new Error("test");'
], [
'Error: test',
/^ at Object\.exports\.test \((?:.*[/\\])?.generated.js:1:34\)$/
/^ at Object\.exports\.test \((?:.*[/\\])?\.generated.js:1:34\)$/
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are various minor regex changes too

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

]);
});

Expand All @@ -293,7 +293,7 @@ it('throw in Timeout with empty source map', function(done) {
' throw new Error("this is the error")',
/^ \^$/,
'Error: this is the error',
/^ at ((null)|(Timeout))\._onTimeout \((?:.*[/\\])?.generated.js:3:11\)$/
/^ at ((null)|(Timeout))\._onTimeout \((?:.*[/\\])?.generated\.js:3:11\)$/
]);
});

Expand All @@ -302,7 +302,7 @@ it('throw with source map with gap', function() {
'throw new Error("test");'
], [
'Error: test',
/^ at Object\.exports\.test \((?:.*[/\\])?.generated.js:1:34\)$/
/^ at Object\.exports\.test \((?:.*[/\\])?\.generated\.js:1:34\)$/
]);
});

Expand All @@ -311,7 +311,7 @@ it('sourcesContent with data URL', function() {
'throw new Error("test");'
], [
'Error: test',
/^ at Object\.exports\.test \((?:.*[/\\])?original.js:1001:5\)$/
/^ at Object\.exports\.test \((?:.*[/\\])?original\.js:1001:5\)$/
]);
});

Expand All @@ -321,7 +321,27 @@ it('finds the last sourceMappingURL', function() {
'throw new Error("test");'
], [
'Error: test',
/^ at Object\.exports\.test \((?:.*[/\\])?original.js:1002:5\)$/
/^ at Object\.exports\.test \((?:.*[/\\])?original\.js:1002:5\)$/
]);
});

it('maps original name from source', function() {
var sourceMap = createEmptySourceMap();
sourceMap.addMapping({
generated: { line: 2, column: 8 },
original: { line: 1000, column: 10 },
source: '.original.js',
name: 'myOriginalName'
});
compareStackTrace(sourceMap, [
'function foo() {',
' throw new Error("test");',
'}',
'foo();'
], [
'Error: test',
/^ at myOriginalName \((?:.*[/\\])?\.original.js:1000:11\)$/,
/^ at Object\.exports\.test \((?:.*[/\\])?\.generated.js:4:1\)$/
]);
});

Expand All @@ -337,7 +357,7 @@ it('default options', function(done) {
'this is the original code',
'^',
'Error: this is the error',
/^ at foo \((?:.*[/\\])?.original\.js:1:1\)$/
/^ at foo \((?:.*[/\\])?\.original\.js:1:1\)$/
]);
});

Expand All @@ -352,7 +372,7 @@ it('handleUncaughtExceptions is true', function(done) {
'this is the original code',
'^',
'Error: this is the error',
/^ at foo \((?:.*[/\\])?.original\.js:1:1\)$/
/^ at foo \((?:.*[/\\])?\.original\.js:1:1\)$/
]);
});

Expand Down Expand Up @@ -414,7 +434,7 @@ it('specifically requested error source', function(done) {
'process.on("uncaughtException", function (e) { console.log("SRC:" + sms.getErrorSource(e)); });',
'process.nextTick(foo);'
], [
/^SRC:.*[/\\].original.js:1$/,
/^SRC:.*[/\\]\.original\.js:1$/,
'this is the original code',
'^'
]);
Expand Down Expand Up @@ -488,9 +508,9 @@ it('should consult all retrieve source map providers', function(done) {
'process.nextTick(function() { console.log(count); });',
], [
'Error: this is the error',
/^ at foo \((?:.*[/\\])?original.js:1004:5\)$/,
/^ at foo \((?:.*[/\\])?original\.js:1004:5\)$/,
'Error: this is the error',
/^ at foo \((?:.*[/\\])?original.js:1004:5\)$/,
/^ at foo \((?:.*[/\\])?original\.js:1004:5\)$/,
'1', // The retrieval should only be attempted once
]);
});
Expand Down Expand Up @@ -525,9 +545,9 @@ it('should allow for runtime inline source maps', function(done) {
'require("./.generated.jss");',
], [
'Error: this is the error',
/^ at foo \(.*[/\\]original.js:1004:5\)$/,
/^ at foo \(.*[/\\]original\.js:1004:5\)$/,
'Error: this is the error',
/^ at foo \(.*[/\\]original.js:1004:5\)$/,
/^ at foo \(.*[/\\]original\.js:1004:5\)$/,
'0', // The retrieval should only be attempted once
]);
});
Expand Down