Merge pull request #124 from tomhughes/source-map-update

Source map update
This commit is contained in:
Linus Unnebäck 2016-09-29 11:14:25 +02:00 committed by GitHub
commit 7b73305cb2
3 changed files with 50 additions and 40 deletions

View File

@ -9,7 +9,7 @@
"test": "mocha"
},
"dependencies": {
"source-map": "0.1.32"
"source-map": "^0.5.3"
},
"devDependencies": {
"browserify": "3.44.2",

View File

@ -210,7 +210,7 @@ function mapEvalOrigin(origin) {
if (match) {
var position = mapSourcePosition({
source: match[2],
line: match[3],
line: +match[3],
column: match[4] - 1
});
return 'eval at ' + match[1] + ' (' + position.source + ':' +

86
test.js
View File

@ -46,6 +46,16 @@ function createSingleLineSourceMap() {
return sourceMap;
}
function createSecondLineSourceMap() {
var sourceMap = createEmptySourceMap();
sourceMap.addMapping({
generated: { line: 2, column: 0 },
original: { line: 1, column: 0 },
source: '.original.js'
});
return sourceMap;
}
function createMultiLineSourceMap() {
var sourceMap = createEmptySourceMap();
for (var i = 1; i <= 100; i++) {
@ -129,7 +139,7 @@ it('normal throw', function() {
'throw new Error("test");'
], [
'Error: test',
/^ at Object\.exports\.test \(.*\/line1\.js:1001:101\)$/
/^ at Object\.exports\.test \((?:.*\/)?line1\.js:1001:101\)$/
]);
});
@ -141,8 +151,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 \((?:.*\/)?line2\.js:1002:102\)$/,
/^ at Object\.exports\.test \((?:.*\/)?line4\.js:1004:104\)$/
]);
});
@ -157,9 +167,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 \((?:.*\/)?line3\.js:1003:103\)$/,
/^ at foo \((?:.*\/)?line5\.js:1005:105\)$/,
/^ at Object\.exports\.test \((?:.*\/)?line7\.js:1007:107\)$/
]);
});
@ -170,9 +180,9 @@ it('eval', function() {
'Error: test',
// Before Node 4, `Object.eval`, after just `eval`.
/^ 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\)$/
]);
});
@ -181,9 +191,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> \((?:.*\/)?line1\.js:1001:101\)/,
/^ at (?:Object\.)?eval \(eval at <anonymous> \((?:.*\/)?line1\.js:1001:101\)/,
/^ at Object\.exports\.test \((?:.*\/)?line1\.js:1001:101\)$/
]);
});
@ -195,9 +205,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 \((?:.*\/)?line2\.js:1002:102\)/,
/^ at foo \((?:.*\/)?line2\.js:1002:102\)/,
/^ at Object\.exports\.test \((?:.*\/)?line4\.js:1004:104\)$/
]);
});
@ -207,7 +217,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 \((?:.*\/)?line1\.js:1001:101\)$/
]);
});
@ -217,8 +227,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> \((?:.*\/)?line1\.js:1001:101\)/,
/^ at Object\.exports\.test \((?:.*\/)?line1\.js:1001:101\)$/
]);
});
@ -238,7 +248,7 @@ it('function constructor', function() {
], [
'SyntaxError: Unexpected token )',
/^ at (?:Object\.)?Function \((?:unknown source|<anonymous>|native)\)$/,
/^ at Object\.exports\.test \(.*\/line1\.js:1001:101\)$/,
/^ at Object\.exports\.test \((?:.*\/)?line1\.js:1001:101\)$/,
]);
});
@ -247,7 +257,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\)$/
]);
});
@ -256,7 +266,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\)$/
]);
});
@ -265,7 +275,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\)$/
]);
});
@ -275,12 +285,12 @@ 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('default options', function(done) {
compareStdout(done, createSingleLineSourceMap(), [
compareStdout(done, createSecondLineSourceMap(), [
'',
'function foo() { throw new Error("this is the error"); }',
'require("./source-map-support").install();',
@ -291,12 +301,12 @@ 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\)$/
]);
});
it('handleUncaughtExceptions is true', function(done) {
compareStdout(done, createSingleLineSourceMap(), [
compareStdout(done, createSecondLineSourceMap(), [
'',
'function foo() { throw new Error("this is the error"); }',
'require("./source-map-support").install({ handleUncaughtExceptions: true });',
@ -306,12 +316,12 @@ 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\)$/
]);
});
it('handleUncaughtExceptions is false', function(done) {
compareStdout(done, createSingleLineSourceMap(), [
compareStdout(done, createSecondLineSourceMap(), [
'',
'function foo() { throw new Error("this is the error"); }',
'require("./source-map-support").install({ handleUncaughtExceptions: false });',
@ -325,7 +335,7 @@ it('handleUncaughtExceptions is false', function(done) {
/^ (?: )?\^$/,
'Error: this is the error',
/^ at foo \(.*\/.original\.js:1:1\)$/
/^ at foo \((?:.*\/)?.original\.js:1:1\)$/
]);
});
@ -340,7 +350,7 @@ it('default options with empty source map', function(done) {
'function foo() { throw new Error("this is the error"); }',
/^ (?: )?\^$/,
'Error: this is the error',
/^ at foo \(.*\/.generated.js:2:24\)$/
/^ at foo \((?:.*\/)?.generated.js:2:24\)$/
]);
});
@ -355,12 +365,12 @@ it('default options with source map with gap', function(done) {
'function foo() { throw new Error("this is the error"); }',
/^ (?: )?\^$/,
'Error: this is the error',
/^ at foo \(.*\/.generated.js:2:24\)$/
/^ at foo \((?:.*\/)?.generated.js:2:24\)$/
]);
});
it('specifically requested error source', function(done) {
compareStdout(done, createSingleLineSourceMap(), [
compareStdout(done, createSecondLineSourceMap(), [
'',
'function foo() { throw new Error("this is the error"); }',
'var sms = require("./source-map-support");',
@ -386,7 +396,7 @@ it('sourcesContent', function(done) {
' line 2',
' ^',
'Error: this is the error',
/^ at foo \(.*\/original\.js:1002:5\)$/
/^ at foo \((?:.*\/)?original\.js:1002:5\)$/
]);
});
@ -409,9 +419,9 @@ it('missing source maps should also be cached', function(done) {
'process.nextTick(function() { console.log(count); });',
], [
'Error: this is the error',
/^ at foo \(.*\/.generated.js:4:15\)$/,
/^ at foo \((?:.*\/)?.generated.js:4:15\)$/,
'Error: this is the error',
/^ at foo \(.*\/.generated.js:4:15\)$/,
/^ at foo \((?:.*\/)?.generated.js:4:15\)$/,
'1', // The retrieval should only be attempted once
]);
});
@ -442,9 +452,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
]);
});
@ -458,7 +468,7 @@ it('finds source maps with charset specified', function() {
var source = [ 'throw new Error("test");' ];
var expected = [
'Error: test',
/^ at Object\.exports\.test \(.*\/line1\.js:1001:101\)$/
/^ at Object\.exports\.test \((?:.*\/)?line1\.js:1001:101\)$/
];
fs.writeFileSync('.generated.js', 'exports.test = function() {' +
@ -482,7 +492,7 @@ it('allows code/comments after sourceMappingURL', function() {
var source = [ 'throw new Error("test");' ];
var expected = [
'Error: test',
/^ at Object\.exports\.test \(.*\/line1\.js:1001:101\)$/
/^ at Object\.exports\.test \((?:.*\/)?line1\.js:1001:101\)$/
];
fs.writeFileSync('.generated.js', 'exports.test = function() {' +