Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve sources relative to the source map #4

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions source-map-support.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,19 @@ function mapSourcePosition(cache, position) {
if (fs.existsSync(sourceMappingURL)) {
var sourceMapData = fs.readFileSync(sourceMappingURL, 'utf8');
try {
sourceMap = new SourceMapConsumer(sourceMapData);
sourceMap = [sourceMappingURL, new SourceMapConsumer(sourceMapData)];
cache[position.source] = sourceMap;
} catch (e) {
}
}
}
return sourceMap ? sourceMap.originalPositionFor(position) : position;
if (sourceMap) {
var originalPosition = sourceMap[1].originalPositionFor(position);
originalPosition.source = path.resolve(path.dirname(sourceMap[0]), originalPosition.source)
Copy link

Choose a reason for hiding this comment

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

#31

return originalPosition
} else {
return position
}
}

// Parses code generated by FormatEvalOrigin(), a function inside V8:
Expand Down
45 changes: 23 additions & 22 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var SourceMapGenerator = require('source-map').SourceMapGenerator;
var child_process = require('child_process');
var assert = require('assert');
var fs = require('fs');
var path = require('path');

function compareStackTrace(source, expected) {
var sourceMap = new SourceMapGenerator({
Expand Down Expand Up @@ -64,7 +65,7 @@ it('normal throw', function() {
'throw new Error("test");'
], [
'Error: test',
' at Object.exports.test (./line1.js:1001:101)'
' at Object.exports.test ('+path.join(process.cwd(),'line1.js')+':1001:101)'
]);
});

Expand All @@ -76,8 +77,8 @@ it('throw inside function', function() {
'foo();'
], [
'Error: test',
' at foo (./line2.js:1002:102)',
' at Object.exports.test (./line4.js:1004:104)'
' at foo ('+path.join(process.cwd(),'line2.js')+':1002:102)',
' at Object.exports.test ('+path.join(process.cwd(),'line4.js')+':1004:104)'
]);
});

Expand All @@ -92,9 +93,9 @@ it('throw inside function inside function', function() {
'foo();'
], [
'Error: test',
' at bar (./line3.js:1003:103)',
' at foo (./line5.js:1005:105)',
' at Object.exports.test (./line7.js:1007:107)'
' at bar ('+path.join(process.cwd(),'line3.js')+':1003:103)',
' at foo ('+path.join(process.cwd(),'line5.js')+':1005:105)',
' at Object.exports.test ('+path.join(process.cwd(),'line7.js')+':1007:107)'
]);
});

Expand All @@ -103,8 +104,8 @@ it('eval', function() {
'eval("throw new Error(\'test\')");'
], [
'Error: test',
' at Object.eval (eval at <anonymous> (./line1.js:1001:101))',
' at Object.exports.test (./line1.js:1001:101)'
' at Object.eval (eval at <anonymous> ('+path.join(process.cwd(),'line1.js')+':1001:101))',
' at Object.exports.test ('+path.join(process.cwd(),'line1.js')+':1001:101)'
]);
});

Expand All @@ -113,9 +114,9 @@ it('eval inside eval', function() {
'eval("eval(\'throw new Error(\\"test\\")\')");'
], [
'Error: test',
' at Object.eval (eval at <anonymous> (eval at <anonymous> (./line1.js:1001:101)))',
' at Object.eval (eval at <anonymous> (./line1.js:1001:101))',
' at Object.exports.test (./line1.js:1001:101)'
' at Object.eval (eval at <anonymous> (eval at <anonymous> ('+path.join(process.cwd(),'line1.js')+':1001:101)))',
' at Object.eval (eval at <anonymous> ('+path.join(process.cwd(),'line1.js')+':1001:101))',
' at Object.exports.test ('+path.join(process.cwd(),'line1.js')+':1001:101)'
]);
});

Expand All @@ -127,9 +128,9 @@ it('eval inside function', function() {
'foo();'
], [
'Error: test',
' at eval (eval at foo (./line2.js:1002:102))',
' at foo (./line2.js:1002:102)',
' at Object.exports.test (./line4.js:1004:104)'
' at eval (eval at foo ('+path.join(process.cwd(),'line2.js')+':1002:102))',
' at foo ('+path.join(process.cwd(),'line2.js')+':1002:102)',
' at Object.exports.test ('+path.join(process.cwd(),'line4.js')+':1004:104)'
]);
});

Expand All @@ -139,7 +140,7 @@ it('eval with sourceURL', function() {
], [
'Error: test',
' at Object.eval (sourceURL.js:1:7)',
' at Object.exports.test (./line1.js:1001:101)'
' at Object.exports.test ('+path.join(process.cwd(),'line1.js')+':1001:101)'
]);
});

Expand All @@ -149,8 +150,8 @@ it('eval with sourceURL inside eval', function() {
], [
'Error: test',
' at Object.eval (sourceURL.js:1:7)',
' at Object.eval (eval at <anonymous> (./line1.js:1001:101))',
' at Object.exports.test (./line1.js:1001:101)'
' at Object.eval (eval at <anonymous> ('+path.join(process.cwd(),'line1.js')+':1001:101))',
' at Object.exports.test ('+path.join(process.cwd(),'line1.js')+':1001:101)'
]);
});

Expand All @@ -163,11 +164,11 @@ it('default options', function(done) {
'process.nextTick(function() { process.exit(1); });'
], [
'',
'./.original.js:1',
path.join(process.cwd(),'.original.js')+':1',
'this is the original code',
'^',
'Error: this is the error',
' at foo (./.original.js:1:1)'
' at foo ('+path.join(process.cwd(),'.original.js')+':1:1)'
]);
});

Expand All @@ -179,11 +180,11 @@ it('handleUncaughtExceptions is true', function(done) {
'process.nextTick(foo);'
], [
'',
'./.original.js:1',
path.join(process.cwd(),'.original.js')+':1',
'this is the original code',
'^',
'Error: this is the error',
' at foo (./.original.js:1:1)'
' at foo ('+path.join(process.cwd(),'.original.js')+':1:1)'
]);
});

Expand All @@ -199,6 +200,6 @@ it('handleUncaughtExceptions is false', function(done) {
'function foo() { throw new Error("this is the error"); }',
' ^',
'Error: this is the error',
' at foo (./.original.js:1:1)'
' at foo ('+path.join(process.cwd(),'.original.js')+':1:1)'
]);
});