merge relative source path fix, bump version, fixes #4

This commit is contained in:
Evan Wallace 2013-04-24 19:16:25 -07:00
commit 03703165e8
3 changed files with 36 additions and 25 deletions

View File

@ -1,7 +1,7 @@
{ {
"name": "source-map-support", "name": "source-map-support",
"description": "Fixes stack traces for files with source maps", "description": "Fixes stack traces for files with source maps",
"version": "0.1.3", "version": "0.1.4",
"main": "./source-map-support.js", "main": "./source-map-support.js",
"scripts": { "scripts": {
"test": "node_modules/mocha/bin/mocha" "test": "node_modules/mocha/bin/mocha"

View File

@ -18,11 +18,22 @@ function mapSourcePosition(cache, position) {
// Parse the source map // Parse the source map
if (fs.existsSync(sourceMappingURL)) { if (fs.existsSync(sourceMappingURL)) {
var sourceMapData = fs.readFileSync(sourceMappingURL, 'utf8'); var sourceMapData = fs.readFileSync(sourceMappingURL, 'utf8');
sourceMap = new SourceMapConsumer(sourceMapData); sourceMap = {
url: sourceMappingURL,
map: new SourceMapConsumer(sourceMapData)
};
cache[position.source] = sourceMap; cache[position.source] = sourceMap;
} }
} }
return sourceMap ? sourceMap.originalPositionFor(position) : position;
// Resolve the source URL relative to the URL of the source map
if (sourceMap) {
var originalPosition = sourceMap.map.originalPositionFor(position);
originalPosition.source = path.resolve(path.dirname(sourceMap.url), originalPosition.source);
return originalPosition;
} else {
return position;
}
} }
// Parses code generated by FormatEvalOrigin(), a function inside V8: // Parses code generated by FormatEvalOrigin(), a function inside V8:

44
test.js
View File

@ -74,7 +74,7 @@ it('normal throw', function() {
'throw new Error("test");' 'throw new Error("test");'
], [ ], [
'Error: test', 'Error: test',
' at Object.exports.test (./line1.js:1001:101)' /^ at Object\.exports\.test \(.*\/line1\.js:1001:101\)$/
]); ]);
}); });
@ -86,8 +86,8 @@ it('throw inside function', function() {
'foo();' 'foo();'
], [ ], [
'Error: test', 'Error: test',
' at foo (./line2.js:1002:102)', /^ at foo \(.*\/line2\.js:1002:102\)$/,
' at Object.exports.test (./line4.js:1004:104)' /^ at Object\.exports\.test \(.*\/line4\.js:1004:104\)$/
]); ]);
}); });
@ -102,9 +102,9 @@ it('throw inside function inside function', function() {
'foo();' 'foo();'
], [ ], [
'Error: test', 'Error: test',
' at bar (./line3.js:1003:103)', /^ at bar \(.*\/line3\.js:1003:103\)$/,
' at foo (./line5.js:1005:105)', /^ at foo \(.*\/line5\.js:1005:105\)$/,
' at Object.exports.test (./line7.js:1007:107)' /^ at Object\.exports\.test \(.*\/line7\.js:1007:107\)$/
]); ]);
}); });
@ -113,8 +113,8 @@ it('eval', function() {
'eval("throw new Error(\'test\')");' 'eval("throw new Error(\'test\')");'
], [ ], [
'Error: test', 'Error: test',
/^ at Object.eval \(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\.exports\.test \(.*\/line1\.js:1001:101\)$/
]); ]);
}); });
@ -123,9 +123,9 @@ it('eval inside eval', function() {
'eval("eval(\'throw new Error(\\"test\\")\')");' 'eval("eval(\'throw new Error(\\"test\\")\')");'
], [ ], [
'Error: test', 'Error: test',
/^ at Object.eval \(eval at <anonymous> \(eval at <anonymous> \(\.\/line1\.js:1001:101\)/, /^ 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\.eval \(eval at <anonymous> \(.*\/line1\.js:1001:101\)/,
' at Object.exports.test (./line1.js:1001:101)' /^ at Object\.exports\.test \(.*\/line1\.js:1001:101\)$/
]); ]);
}); });
@ -137,9 +137,9 @@ it('eval inside function', function() {
'foo();' 'foo();'
], [ ], [
'Error: test', 'Error: test',
/^ at eval \(eval at foo \(\.\/line2\.js:1002:102\)/, /^ at eval \(eval at foo \(.*\/line2\.js:1002:102\)/,
' at foo (./line2.js:1002:102)', /^ at foo \(.*\/line2\.js:1002:102\)/,
' at Object.exports.test (./line4.js:1004:104)' /^ at Object\.exports\.test \(.*\/line4\.js:1004:104\)$/
]); ]);
}); });
@ -149,7 +149,7 @@ it('eval with sourceURL', function() {
], [ ], [
'Error: test', 'Error: test',
' at Object.eval (sourceURL.js:1:7)', ' at Object.eval (sourceURL.js:1:7)',
' at Object.exports.test (./line1.js:1001:101)' /^ at Object\.exports\.test \(.*\/line1\.js:1001:101\)$/
]); ]);
}); });
@ -159,8 +159,8 @@ it('eval with sourceURL inside eval', function() {
], [ ], [
'Error: test', 'Error: test',
' at Object.eval (sourceURL.js:1:7)', ' at Object.eval (sourceURL.js:1:7)',
/^ at Object.eval \(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\.exports\.test \(.*\/line1\.js:1001:101\)$/
]); ]);
}); });
@ -172,11 +172,11 @@ it('default options', function(done) {
'process.nextTick(foo);', 'process.nextTick(foo);',
'process.nextTick(function() { process.exit(1); });' 'process.nextTick(function() { process.exit(1); });'
], [ ], [
'./.original.js:1', /\/.original\.js:1$/,
'this is the original code', 'this is the original code',
'^', '^',
'Error: this is the error', 'Error: this is the error',
' at foo (./.original.js:1:1)' /^ at foo \(.*\/.original\.js:1:1\)$/
]); ]);
}); });
@ -187,11 +187,11 @@ it('handleUncaughtExceptions is true', function(done) {
'require("./source-map-support").install({ handleUncaughtExceptions: true });', 'require("./source-map-support").install({ handleUncaughtExceptions: true });',
'process.nextTick(foo);' 'process.nextTick(foo);'
], [ ], [
'./.original.js:1', /\/.original\.js:1$/,
'this is the original code', 'this is the original code',
'^', '^',
'Error: this is the error', 'Error: this is the error',
' at foo (./.original.js:1:1)' /^ at foo \(.*\/.original\.js:1:1\)$/
]); ]);
}); });
@ -206,6 +206,6 @@ it('handleUncaughtExceptions is false', function(done) {
'function foo() { throw new Error("this is the error"); }', 'function foo() { throw new Error("this is the error"); }',
' ^', ' ^',
'Error: this is the error', 'Error: this is the error',
' at foo (./.original.js:1:1)' /^ at foo \(.*\/.original\.js:1:1\)$/
]); ]);
}); });