Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

source-map

Package Overview
Dependencies
Maintainers
3
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

source-map - npm Package Compare versions

Comparing version 0.1.28 to 0.1.29

5

CHANGELOG.md
# Change Log
## 0.1.29
* Allow duplicate entries in the `names` and `sources` arrays of source maps
(usually from TypeScript) we are parsing. Fixes github isse 72.
## 0.1.28

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

19

lib/source-map/array-set.js

@@ -28,6 +28,6 @@ /* -*- Mode: js; js-indent-level: 2; -*- */

*/
ArraySet.fromArray = function ArraySet_fromArray(aArray) {
ArraySet.fromArray = function ArraySet_fromArray(aArray, aAllowDuplicates) {
var set = new ArraySet();
for (var i = 0, len = aArray.length; i < len; i++) {
set.add(aArray[i]);
set.add(aArray[i], aAllowDuplicates);
}

@@ -42,10 +42,11 @@ return set;

*/
ArraySet.prototype.add = function ArraySet_add(aStr) {
if (this.has(aStr)) {
// Already a member; nothing to do.
return;
ArraySet.prototype.add = function ArraySet_add(aStr, aAllowDuplicates) {
var isDuplicate = this.has(aStr);
var idx = this._array.length;
if (!isDuplicate || aAllowDuplicates) {
this._array.push(aStr);
}
var idx = this._array.length;
this._array.push(aStr);
this._set[util.toSetString(aStr)] = idx;
if (!isDuplicate) {
this._set[util.toSetString(aStr)] = idx;
}
};

@@ -52,0 +53,0 @@

@@ -65,4 +65,8 @@ /* -*- Mode: js; js-indent-level: 2; -*- */

this._names = ArraySet.fromArray(names);
this._sources = ArraySet.fromArray(sources);
// Pass `true` below to allow duplicate names and sources. While source maps
// are intended to be compressed and deduplicated, the TypeScript compiler
// sometimes generates source maps with duplicates in them. See Github issue
// #72 and bugzil.la/889492.
this._names = ArraySet.fromArray(names, true);
this._sources = ArraySet.fromArray(sources, true);
this.sourceRoot = sourceRoot;

@@ -69,0 +73,0 @@ this.sourcesContent = sourcesContent;

{
"name": "source-map",
"description": "Generates and consumes source maps",
"version": "0.1.28",
"version": "0.1.29",
"homepage": "https://github.com/mozilla/source-map",

@@ -21,3 +21,4 @@ "author": "Nick Fitzgerald <nfitzgerald@mozilla.com>",

"David Glasser <glasser@davidglasser.net>",
"Chase Douglas <chase@newrelic.com>"
"Chase Douglas <chase@newrelic.com>",
"Evan Wallace <evan.exe@gmail.com>"
],

@@ -24,0 +25,0 @@ "repository": {

@@ -71,2 +71,35 @@ /* -*- Mode: js; js-indent-level: 2; -*- */

exports['test .fromArray() with duplicates'] = function (assert, util) {
var set = ArraySet.fromArray(['foo', 'foo']);
assert.ok(set.has('foo'));
assert.strictEqual(set.at(0), 'foo');
assert.strictEqual(set.indexOf('foo'), 0);
assert.strictEqual(set.toArray().length, 1);
set = ArraySet.fromArray(['foo', 'foo'], true);
assert.ok(set.has('foo'));
assert.strictEqual(set.at(0), 'foo');
assert.strictEqual(set.at(1), 'foo');
assert.strictEqual(set.indexOf('foo'), 0);
assert.strictEqual(set.toArray().length, 2);
};
exports['test .add() with duplicates'] = function (assert, util) {
var set = new ArraySet();
set.add('foo');
set.add('foo');
assert.ok(set.has('foo'));
assert.strictEqual(set.at(0), 'foo');
assert.strictEqual(set.indexOf('foo'), 0);
assert.strictEqual(set.toArray().length, 1);
set.add('foo', true);
assert.ok(set.has('foo'));
assert.strictEqual(set.at(0), 'foo');
assert.strictEqual(set.at(1), 'foo');
assert.strictEqual(set.indexOf('foo'), 0);
assert.strictEqual(set.toArray().length, 2);
};
});

@@ -321,2 +321,72 @@ /* -*- Mode: js; js-indent-level: 2; -*- */

exports['test github issue #72, duplicate sources'] = function (assert, util) {
var map = new SourceMapConsumer({
"version": 3,
"file": "foo.js",
"sources": ["source1.js", "source1.js", "source3.js"],
"names": [],
"mappings": ";EAAC;;IAEE;;MEEE",
"sourceRoot": "http://example.com"
});
var pos = map.originalPositionFor({
line: 2,
column: 2
});
assert.equal(pos.source, 'http://example.com/source1.js');
assert.equal(pos.line, 1);
assert.equal(pos.column, 1);
var pos = map.originalPositionFor({
line: 4,
column: 4
});
assert.equal(pos.source, 'http://example.com/source1.js');
assert.equal(pos.line, 3);
assert.equal(pos.column, 3);
var pos = map.originalPositionFor({
line: 6,
column: 6
});
assert.equal(pos.source, 'http://example.com/source3.js');
assert.equal(pos.line, 5);
assert.equal(pos.column, 5);
};
exports['test github issue #72, duplicate names'] = function (assert, util) {
var map = new SourceMapConsumer({
"version": 3,
"file": "foo.js",
"sources": ["source.js"],
"names": ["name1", "name1", "name3"],
"mappings": ";EAACA;;IAEEA;;MAEEE",
"sourceRoot": "http://example.com"
});
var pos = map.originalPositionFor({
line: 2,
column: 2
});
assert.equal(pos.name, 'name1');
assert.equal(pos.line, 1);
assert.equal(pos.column, 1);
var pos = map.originalPositionFor({
line: 4,
column: 4
});
assert.equal(pos.name, 'name1');
assert.equal(pos.line, 3);
assert.equal(pos.column, 3);
var pos = map.originalPositionFor({
line: 6,
column: 6
});
assert.equal(pos.name, 'name3');
assert.equal(pos.line, 5);
assert.equal(pos.column, 5);
};
});

@@ -391,2 +391,28 @@ /* -*- Mode: js; js-indent-level: 2; -*- */

};
exports['test github issue #72, check for duplicate names or sources'] = function (assert, util) {
var map = new SourceMapGenerator({
file: 'test.js'
});
map.addMapping({
generated: { line: 1, column: 1 },
original: { line: 2, column: 2 },
source: 'a.js',
name: 'foo'
});
map.addMapping({
generated: { line: 3, column: 3 },
original: { line: 4, column: 4 },
source: 'a.js',
name: 'foo'
});
util.assertEqualMaps(assert, map.toJSON(), {
version: 3,
file: 'test.js',
sources: ['a.js'],
names: ['foo'],
mappings: 'CACEA;;GAEEA'
});
};
});
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