Socket
Socket
Sign inDemoInstall

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.9 to 0.1.10

21

lib/source-map/array-set.js

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

var util = require('./util');
/**

@@ -36,15 +38,2 @@ * A data structure which is a combination of an array and a set. Adding a new

/**
* Because behavior goes wacky when you set `__proto__` on `this._set`, we
* have to prefix all the strings in our set with an arbitrary character.
*
* See https://github.com/mozilla/source-map/pull/31 and
* https://github.com/mozilla/source-map/issues/30
*
* @param String aStr
*/
ArraySet.prototype._toSetString = function ArraySet__toSetString (aStr) {
return "$" + aStr;
};
/**
* Add the given string to this set.

@@ -61,3 +50,3 @@ *

this._array.push(aStr);
this._set[this._toSetString(aStr)] = idx;
this._set[util.toSetString(aStr)] = idx;
};

@@ -72,3 +61,3 @@

return Object.prototype.hasOwnProperty.call(this._set,
this._toSetString(aStr));
util.toSetString(aStr));
};

@@ -83,3 +72,3 @@

if (this.has(aStr)) {
return this._set[this._toSetString(aStr)];
return this._set[util.toSetString(aStr)];
}

@@ -86,0 +75,0 @@ throw new Error('"' + aStr + '" is not in the set.');

@@ -30,2 +30,3 @@ /* -*- Mode: js; js-indent-level: 2; -*- */

* - sourceRoot: Optional. The URL root from which all sources are relative.
* - sourcesContent: Optional. An array of contents of the original source files.
* - mappings: A string of base64 VLQs which contain the actual mappings.

@@ -57,2 +58,3 @@ * - file: The generated file this source map is associated with.

var sourceRoot = util.getArg(sourceMap, 'sourceRoot', null);
var sourcesContent = util.getArg(sourceMap, 'sourcesContent', null);
var mappings = util.getArg(sourceMap, 'mappings');

@@ -68,2 +70,3 @@ var file = util.getArg(sourceMap, 'file');

this._sourceRoot = sourceRoot;
this.sourcesContent = sourcesContent;
this.file = file;

@@ -300,2 +303,28 @@

/**
* Returns the original source content. The only argument is
* the url of the original source file. Returns null if no
* original source content is availible.
*/
SourceMapConsumer.prototype.sourceContentFor =
function SourceMapConsumer_sourceContentFor(aSource) {
if(!this.sourcesContent) {
return null;
}
if(this._sourceRoot) {
// Try to remove the sourceRoot
var relativeUrl = util.relative(this._sourceRoot, aSource);
if(relativeUrl !== aSource && this._sources.has(relativeUrl)) {
return this.sourcesContent[this._sources.indexOf(relativeUrl)];
}
}
if(this._sources.has(aSource)) {
return this.sourcesContent[this._sources.indexOf(aSource)];
}
throw new Error('"' + aSource + '" is not in the SourceMap.');
};
/**
* Returns the generated line and column information for the original source,

@@ -302,0 +331,0 @@ * line, and column positions provided. The only argument is an object with

@@ -30,2 +30,3 @@ /* -*- Mode: js; js-indent-level: 2; -*- */

this._mappings = [];
this._sourcesContents = null;
}

@@ -71,2 +72,24 @@

/**
* Set the source content for a source file.
*/
SourceMapGenerator.prototype.setSourceContent =
function SourceMapGenerator_setSourceContent(aSourceFile, aSourceContent) {
if(aSourceContent !== null) {
// Add the source content to the _sourcesContents map.
// Create a new _sourcesContents map if the property is null.
if(!this._sourcesContents) {
this._sourcesContents = {};
}
this._sourcesContents[util.toSetString(aSourceFile)] = aSourceContent;
} else {
// Remove the source file from the _sourcesContents map.
// If the _sourcesContents map is empty, set the property to null.
delete this._sourcesContents[util.toSetString(aSourceFile)];
if(Object.keys(this._sourcesContents).length === 0) {
this._sourcesContents = null;
}
}
};
/**
* A mapping can have one of the three levels of data:

@@ -191,2 +214,10 @@ *

}
if (this._sourcesContents) {
map.sourcesContent = map.sources.map(function(source) {
return Object.prototype.hasOwnProperty.call(
this._sourcesContents, util.toSetString(source))
? this._sourcesContents[util.toSetString(source)]
: null;
}, this);
}
return map;

@@ -193,0 +224,0 @@ };

@@ -27,5 +27,5 @@ /* -*- Mode: js; js-indent-level: 2; -*- */

this.children = [];
this.line = aLine;
this.column = aColumn;
this.source = aSource;
this.line = aLine === undefined ? null : aLine;
this.column = aColumn === undefined ? null : aColumn;
this.source = aSource === undefined ? null : aSource;
if (aChunks != null) this.add(aChunks);

@@ -170,5 +170,5 @@ }

generated.code += chunk;
if (original.source != null
&& original.line != null
&& original.column != null) {
if (original.source !== null
&& original.line !== null
&& original.column !== null) {
map.addMapping({

@@ -175,0 +175,0 @@ source: original.source,

@@ -40,2 +40,23 @@ /* -*- Mode: js; js-indent-level: 2; -*- */

/**
* Because behavior goes wacky when you set `__proto__` on objects, we
* have to prefix all the strings in our set with an arbitrary character.
*
* See https://github.com/mozilla/source-map/pull/31 and
* https://github.com/mozilla/source-map/issues/30
*
* @param String aStr
*/
function toSetString(aStr) {
return '$' + aStr
}
exports.toSetString = toSetString;
function relative(aRoot, aPath) {
return aPath.indexOf(aRoot.replace(/\/*$/, '') + '/') === 0
? aPath.substr(aRoot.length + 1)
: aPath;
}
exports.relative = relative;
});
{
"name": "source-map",
"description": "Generates and consumes source maps",
"version": "0.1.9",
"version": "0.1.10",
"homepage": "https://github.com/mozilla/source-map",
"author": "Nick Fitzgerald <nfitzgerald@mozilla.com>",
"contributors": [],
"contributors": [
"Stephen Crane",
"Ryan Seddon",
"Mihai Bazon <mihai.bazon@gmail.com>",
"Michael Ficarra <github.public.email@michael.ficarra.me>",
"Todd Wolfson <todd@twolfson.com>",
"Alexander Solovyov <alexander@solovyov.net>",
"Felix Gnass",
"Conrad Irwin <conrad.irwin@gmail.com>"
],
"repository": {

@@ -9,0 +18,0 @@ "type": "git",

@@ -87,2 +87,4 @@ # Source Map

* `sourcesContent`: Optional. An array of contents of the original source files.
* `mappings`: A string of base64 VLQs which contain the actual mappings.

@@ -133,2 +135,7 @@

#### SourceMapConsumer.prototype.sourceContentFor(source)
Returns the original source content for the source provided. The only
argument is the URL of the original source file.
#### SourceMapConsumer.prototype.eachMapping(callback, context, order)

@@ -179,2 +186,10 @@

#### SourceMapGenerator.prototype.setSourceContent(sourceFile, sourceContent)
Set the source content for an original source file.
* `sourceFile` the URL of the original source file.
* `sourceContent` the content of the source file.
#### SourceMapGenerator.prototype.toString()

@@ -181,0 +196,0 @@

@@ -142,2 +142,30 @@ /* -*- Mode: js; js-indent-level: 2; -*- */

exports['test that the `sourcesContent` field has the original sources'] = function (assert, util) {
var map = new SourceMapConsumer(util.testMapWithSourcesContent);
var sourcesContent = map.sourcesContent;
assert.equal(sourcesContent[0], ' ONE.foo = function (bar) {\n return baz(bar);\n };');
assert.equal(sourcesContent[1], ' TWO.inc = function (n) {\n return n + 1;\n };');
assert.equal(sourcesContent.length, 2);
};
exports['test that we can get the original sources for the sources'] = function (assert, util) {
var map = new SourceMapConsumer(util.testMapWithSourcesContent);
var sources = map.sources;
assert.equal(map.sourceContentFor(sources[0]), ' ONE.foo = function (bar) {\n return baz(bar);\n };');
assert.equal(map.sourceContentFor(sources[1]), ' TWO.inc = function (n) {\n return n + 1;\n };');
assert.equal(map.sourceContentFor("one.js"), ' ONE.foo = function (bar) {\n return baz(bar);\n };');
assert.equal(map.sourceContentFor("two.js"), ' TWO.inc = function (n) {\n return n + 1;\n };');
assert.throws(function () {
map.sourceContentFor("");
}, Error);
assert.throws(function () {
map.sourceContentFor("/the/root/three.js");
}, Error);
assert.throws(function () {
map.sourceContentFor("three.js");
}, Error);
};
});

@@ -187,2 +187,23 @@ /* -*- Mode: js; js-indent-level: 2; -*- */

exports['test that source content can be set'] = function (assert, util) {
var map = new SourceMapGenerator({
file: 'min.js',
sourceRoot: '/the/root'
});
map.addMapping({
generated: { line: 1, column: 1 },
original: { line: 1, column: 1 },
source: 'one.js'
});
map.addMapping({
generated: { line: 2, column: 1 },
original: { line: 1, column: 1 },
source: 'two.js'
});
map.setSourceContent('one.js', 'one file content');
map = JSON.parse(map.toString());
assert.deepEqual(map.sources, ['one.js', 'two.js']);
assert.deepEqual(map.sourcesContent, ['one file content', null]);
};
});

@@ -39,2 +39,18 @@ /* -*- Mode: js; js-indent-level: 2; -*- */

};
exports.testMapWithSourcesContent = {
version: 3,
file: 'min.js',
names: ['bar', 'baz', 'n'],
sources: ['one.js', 'two.js'],
sourcesContent: [
' ONE.foo = function (bar) {\n' +
' return baz(bar);\n' +
' };',
' TWO.inc = function (n) {\n' +
' return n + 1;\n' +
' };'
],
sourceRoot: '/the/root',
mappings: 'CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID;CCDb,IAAI,IAAM,SAAUE,GAClB,OAAOA'
};

@@ -41,0 +57,0 @@ function assertMapping(generatedLine, generatedColumn, originalSource,

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