source-mapper
Advanced tools
Comparing version 0.2.1 to 0.3.0
# Changes | ||
## 0.3.0 | ||
- Add optional `offset` parameter | ||
## 0.2.1 | ||
@@ -4,0 +8,0 @@ |
@@ -38,3 +38,3 @@ /* | ||
exports.line = function (consumer, line) { | ||
exports.line = function (consumer, line, offset) { | ||
return line.replace(stackRE, function (m, pre, p, nr, post) { | ||
@@ -46,3 +46,3 @@ /*jslint unparam: true*/ | ||
var mapped = consumer.originalPositionFor({ | ||
line : Number(nr), | ||
line : Number(nr) - (offset || 0), | ||
column : 0 | ||
@@ -55,3 +55,3 @@ }); | ||
exports.stream = function (consumer) { | ||
exports.stream = function (consumer, offset) { | ||
if (!(consumer instanceof sourceMap.SourceMapConsumer)) { | ||
@@ -66,3 +66,3 @@ consumer = new sourceMap.SourceMapConsumer(consumer); | ||
if (p !== -1) { | ||
this.queue(exports.line(consumer, buf.substring(0, p + 1))); | ||
this.queue(exports.line(consumer, buf.substring(0, p + 1), offset)); | ||
buf = buf.substring(p + 1); | ||
@@ -69,0 +69,0 @@ } |
{ | ||
"name": "source-mapper", | ||
"version": "0.2.1", | ||
"version": "0.3.0", | ||
"description": "Replace URLs in track traces with original sources", | ||
@@ -5,0 +5,0 @@ "author": "Maximilian Antoni <mail@maxantoni.de> (http://maxantoni.de)", |
# Source Mapper | ||
Replace URLs in track traces with original sources based on [source-map][]. For | ||
Replace URLs in stack traces with original sources based on [source-map][]. For | ||
node and the browser. | ||
@@ -26,4 +26,12 @@ | ||
maps. | ||
- `stream(map)` returns a [through][] stream that replaces URLs in stack traces | ||
with the original source location. | ||
- `consumer(map)` returns a source map consumer for the given `map`. | ||
- `line(consumer, line[, offset])` maps the given line to the original source | ||
using a consumer. If `offset` is given, it is substracted from the line | ||
number. | ||
- `stream(consumer[, offset])` returns a [through][] stream that replaces URLs | ||
in stack traces with the original source location using a consumer. If | ||
`offset` is given, it is substracted from the line number. | ||
- `stream(map[, offset])` returns a [through][] stream that replaces URLs in | ||
stack traces with the original source location using a source map. If | ||
`offset` is given, it is substracted from the line number. | ||
@@ -30,0 +38,0 @@ ## Development |
@@ -17,3 +17,14 @@ /*global describe, it, before, beforeEach*/ | ||
function spy(obj, prop) { | ||
var fn = obj[prop]; | ||
function s() { | ||
s.calls.push(Array.prototype.slice.call(arguments)); | ||
return fn.apply(this, arguments); | ||
} | ||
s.calls = []; | ||
obj[prop] = s; | ||
return s; | ||
} | ||
describe('source-mapper', function () { | ||
@@ -110,2 +121,21 @@ var js; | ||
it('passes line number minus offset to consumer (line)', function () { | ||
var s = spy(c, 'originalPositionFor'); | ||
mapper.line(c, 'about:blank:12', 7); | ||
assert.equal(s.calls.length, 1); | ||
assert.equal(s.calls[0][0].line, 5); | ||
}); | ||
it('passes line number minus offset to consumer (stream)', function () { | ||
var s = spy(c, 'originalPositionFor'); | ||
var stream = mapper.stream(c, 7); | ||
stream.write('about:blank:12\n'); | ||
assert.equal(s.calls.length, 1); | ||
assert.equal(s.calls[0][0].line, 5); | ||
}); | ||
}); |
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
9035
176
52