Socket
Socket
Sign inDemoInstall

source-mapper

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

source-mapper - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

5

CHANGES.md
# Changes
## 1.0.1
- Fix parsing traces with columns
- Improve matcher regexp and trace formatting
## 1.0.0

@@ -4,0 +9,0 @@

19

lib/source-mapper.js

@@ -14,5 +14,5 @@ /*

var stackRE = new RegExp('^(\\s*(?:at (?:.+ \\()?)?)'
+ '(\\[stdin\\]|about:blank|(?:http|file)\\:\\/\\/.+|Unknown script code|'
+ '<anonymous>)\\:([0-9]+)(\\:[0-9]+\\)?$|\\)?$)', 'gm');
var stackRE = new RegExp('^\\s*(.*)?'
+ '(\\[stdin\\]|about:blank|http:\\/\\/[a-z0-9\\-_\\.]+(:[0-9]+)?\\/.*|'
+ 'file:\\/\\/.+|Unknown script code|<anonymous>)[:\\d]+\\)?$', 'gm');

@@ -40,12 +40,15 @@

exports.line = function (consumer, line, offset) {
return line.replace(stackRE, function (m, pre, p, nr, post) {
return line.replace(stackRE, function (_, pre) {
/*jslint unparam: true*/
if (nr < 1) {
return m;
var m = _.match(/:(\d+)(:\d+)?(\D*)$/);
var n = Number(m[1]) - (offset || 0);
if (n < 1) {
return _;
}
var mapped = consumer.originalPositionFor({
line : Number(nr) - (offset || 0),
line : n,
column : 0
});
return pre + mapped.source + ':' + mapped.line + post;
pre = ' ' + (pre || '').replace('@', ' ');
return pre + mapped.source + ':' + mapped.line + (m[2] || '') + m[3];
});

@@ -52,0 +55,0 @@ };

{
"name": "source-mapper",
"version": "1.0.0",
"description": "Replace URLs in track traces with original sources",
"version": "1.0.1",
"description": "Replace strack traces with original sources using source maps",
"keywords": ["stack", "trace", "source-maps"],
"author": "Maximilian Antoni <mail@maxantoni.de> (http://maxantoni.de)",

@@ -6,0 +7,0 @@ "homepage": "https://github.com/mantoni/source-mapper.js",

@@ -7,4 +7,4 @@ # Source Mapper

Replace URLs in stack traces with original sources based on [source-map][]. For
node and the browser.
Replace stack traces with original sources using [source-map][]. For node and
the browser.

@@ -35,6 +35,6 @@ ## Install

number.
- `stream(consumer[, offset])` returns a [through][] stream that replaces URLs
- `stream(consumer[, offset])` returns a [through2][] 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
- `stream(map[, offset])` returns a [through2][] stream that replaces URLs in
stack traces with the original source location using a source map. If

@@ -65,2 +65,2 @@ `offset` is given, it is substracted from the line number.

[source-map]: https://github.com/mozilla/source-map
[through]: https://github.com/dominictarr/through
[through2]: https://github.com/rvagg/through2

@@ -39,2 +39,4 @@ /*global describe, it, before, beforeEach*/

js = script.toString();
x = mapper.extract(js);
c = mapper.consumer(x.map);
done(err);

@@ -44,7 +46,2 @@ });

beforeEach(function () {
x = mapper.extract(js);
c = mapper.consumer(x.map);
});
it('removes sourceMappingURL from js', function () {

@@ -71,3 +68,3 @@ var xjs = x.js.trim();

assert.equal(arr[1], base + ':4');
assert.equal(arr[1], ' ' + base + ':4');
assert.equal(arr[5], ' at ' + base + ':4:9');

@@ -87,17 +84,47 @@ assert.equal(arr[6], ' at Object.<anonymous> (' + base + ':5:2)');

assert.equal(mapped, 'test/fixture/thrower.js:4');
assert.equal(mapped, ' test/fixture/thrower.js:4');
});
it('maps http:// line', function () {
it('maps http://localhost line', function () {
var mapped = mapper.line(c, 'http://localhost/test:5');
assert.equal(mapped, 'test/fixture/thrower.js:4');
assert.equal(mapped, ' test/fixture/thrower.js:4');
});
it('maps http://l0cal.ho-s_t.com line', function () {
var mapped = mapper.line(c, 'http://l0cal.ho-s_t.com/test:5');
assert.equal(mapped, ' test/fixture/thrower.js:4');
});
it('maps http://localhost line with port', function () {
var mapped = mapper.line(c, 'http://localhost:1234/test:5');
assert.equal(mapped, ' test/fixture/thrower.js:4');
});
it('maps http://localhost line with column', function () {
var mapped = mapper.line(c, 'http://localhost/test:5:0');
assert.equal(mapped, ' test/fixture/thrower.js:4:0');
});
it('maps http://localhost line with port and column', function () {
var mapped = mapper.line(c, 'http://localhost:1234/test:5:0');
assert.equal(mapped, ' test/fixture/thrower.js:4:0');
});
it('maps file:// line', function () {
var mapped = mapper.line(c, 'file://that/file/test:5');
assert.equal(mapped, 'test/fixture/thrower.js:4');
assert.equal(mapped, ' test/fixture/thrower.js:4');
});
it('maps file:// line with column', function () {
var mapped = mapper.line(c, 'file://that/file/test:5:0');
assert.equal(mapped, ' test/fixture/thrower.js:4:0');
});
it('maps IE 10 stack line', function () {

@@ -108,3 +135,3 @@ var mapped = mapper.line(c,

assert.equal(mapped,
'at Anonymous function (test/fixture/thrower.js:4:1)');
' at Anonymous function (test/fixture/thrower.js:4:1)');
});

@@ -115,6 +142,12 @@

assert.equal(mapped, 'at Object.fail (test/fixture/thrower.js:4:1)');
assert.equal(mapped, ' at Object.fail (test/fixture/thrower.js:4:1)');
});
it('does not map "abc http://"', function () {
it('maps Safari line', function () {
var mapped = mapper.line(c, 'equal@file:///some/path:5:1');
assert.equal(mapped, ' equal test/fixture/thrower.js:4:1');
});
it('does not map "abc http://localhost:5"', function () {
var line = 'abc http://localhost:5';

@@ -131,2 +164,8 @@

it('does not map "http://local.somehost:5/"', function () {
var line = 'http://local.somehost:5/';
assert.equal(mapper.line(c, line), line);
});
it('passes line number minus offset to consumer (line)', function () {

@@ -151,2 +190,14 @@ var s = spy(c, 'originalPositionFor');

it('returns original line if line number is 0', function () {
var line = 'http://localhost:0';
assert.equal(mapper.line(c, line), line);
});
it('returns original line if line number minus offset is 0', function () {
var line = 'http://localhost:7';
assert.equal(mapper.line(c, line, 7), line);
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc