source-mapper
Advanced tools
Comparing version 0.1.0 to 0.2.0
# Changes | ||
## 0.2.0 | ||
- Reduce false matches | ||
- Add support to map single lines | ||
## 0.1.0 | ||
- Initial release |
@@ -14,4 +14,5 @@ /* | ||
/*jslint regexp: true*/ | ||
var stackRE = /(\sat .*)?(\[stdin\]|http\:\/\/.+)\:([0-9]+)/g; | ||
var stackRE = new RegExp('^(\\s*(?:at (?:.+ \\()?)?)' | ||
+ '(\\[stdin\\]|about:blank|(?:http|file)\\:\\/\\/.+)\\:([0-9]+)' | ||
+ '(\\:[0-9]+\\)?$|\\)?$)', 'gm'); | ||
@@ -21,7 +22,5 @@ | ||
var map = convert.fromSource(js); | ||
var mapper; | ||
if (map) { | ||
map = map.toObject(); | ||
delete map.sourcesContent; | ||
mapper = new sourceMap.SourceMapConsumer(map); | ||
js = convert.removeComments(js); | ||
@@ -31,3 +30,3 @@ } | ||
js : js, | ||
map : mapper | ||
map : map | ||
}; | ||
@@ -37,3 +36,26 @@ }; | ||
exports.stream = function (map) { | ||
exports.consumer = function (map) { | ||
return new sourceMap.SourceMapConsumer(map); | ||
}; | ||
exports.line = function (consumer, line) { | ||
return line.replace(stackRE, function (m, pre, p, nr, post) { | ||
/*jslint unparam: true*/ | ||
if (nr < 1) { | ||
return m; | ||
} | ||
var mapped = consumer.originalPositionFor({ | ||
line : Number(nr), | ||
column : 0 | ||
}); | ||
return pre + mapped.source + ':' + mapped.line + post; | ||
}); | ||
}; | ||
exports.stream = function (consumer) { | ||
if (!(consumer instanceof sourceMap.SourceMapConsumer)) { | ||
consumer = new sourceMap.SourceMapConsumer(consumer); | ||
} | ||
var buf = ''; | ||
@@ -45,15 +67,3 @@ return through(function (data) { | ||
if (p !== -1) { | ||
var str = buf.substring(0, p + 1).replace(stackRE, | ||
function (m, p1, p2, nr) { | ||
/*jslint unparam: true*/ | ||
if (nr < 1) { | ||
return m; | ||
} | ||
var mapped = map.originalPositionFor({ | ||
line : Number(nr), | ||
column : 0 | ||
}); | ||
return (p1 || '') + mapped.source + ':' + mapped.line; | ||
}); | ||
this.queue(str); | ||
this.queue(exports.line(consumer, buf.substring(0, p + 1))); | ||
buf = buf.substring(p + 1); | ||
@@ -67,3 +77,2 @@ } | ||
}); | ||
}; |
{ | ||
"name": "source-mapper", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Replace URLs in track traces with original sources", | ||
@@ -5,0 +5,0 @@ "author": "Maximilian Antoni <mail@maxantoni.de> (http://maxantoni.de)", |
@@ -21,2 +21,3 @@ /*global describe, it, before, beforeEach*/ | ||
var x; | ||
var c; | ||
@@ -34,2 +35,3 @@ before(function (done) { | ||
x = mapper.extract(js); | ||
c = mapper.consumer(x.map); | ||
}); | ||
@@ -70,2 +72,32 @@ | ||
it('maps about:blank line', function () { | ||
var base = path.resolve('test', 'fixture', 'thrower.js'); | ||
assert.equal(mapper.line(c, 'about:blank:5'), base + ':4'); | ||
}); | ||
it('maps http:// line', function () { | ||
var base = path.resolve('test', 'fixture', 'thrower.js'); | ||
assert.equal(mapper.line(c, 'http://localhost/test:5'), base + ':4'); | ||
}); | ||
it('maps file:// line', function () { | ||
var base = path.resolve('test', 'fixture', 'thrower.js'); | ||
assert.equal(mapper.line(c, 'file://that/file/test:5'), base + ':4'); | ||
}); | ||
it('does not map "abc http://"', function () { | ||
var line = 'abc http://localhost:5'; | ||
assert.equal(mapper.line(c, line), line); | ||
}); | ||
it('does not map "http://localhost:5/"', function () { | ||
var line = 'http://localhost:5/'; | ||
assert.equal(mapper.line(c, line), line); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7359
146