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.19 to 0.1.20

CHANGELOG.md

12

lib/source-map/source-map-generator.js

@@ -145,10 +145,10 @@ /* -*- Mode: js; js-indent-level: 2; -*- */

/**
* Applies a SourceMap for a source file to the SourceMap.
* Each mapping to the supplied source file is rewritten using the
* supplied SourceMap. Note: The resolution for the resulting mappings
* is the minimium of this map and the supplied map.
* Applies the mappings of a sub-source-map for a specific source file to the
* source map being generated. Each mapping to the supplied source file is
* rewritten using the supplied source map. Note: The resolution for the
* resulting mappings is the minimium of this map and the supplied map.
*
* @param aSourceMapConsumer The SourceMap to be applied.
* @param aSourceMapConsumer The source map to be applied.
* @param aSourceFile Optional. The filename of the source file.
* If omitted, sourceMapConsumer.file will be used.
* If omitted, SourceMapConsumer's file property will be used.
*/

@@ -155,0 +155,0 @@ SourceMapGenerator.prototype.applySourceMap =

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

var SourceMapGenerator = require('./source-map-generator').SourceMapGenerator;
var util = require('./util');

@@ -29,2 +30,3 @@ /**

this.children = [];
this.sourceContents = {};
this.line = aLine === undefined ? null : aLine;

@@ -117,2 +119,10 @@ this.column = aColumn === undefined ? null : aColumn;

// Copy sourcesContent into SourceNode
aSourceMapConsumer.sources.forEach(function (sourceFile) {
var content = aSourceMapConsumer.sourceContentFor(sourceFile);
if (content) {
node.setSourceContent(sourceFile, content);
}
});
return node;

@@ -248,2 +258,32 @@

/**
* Set the source content for a source file. This will be added to the SourceMapGenerator
* in the sourcesContent field.
*
* @param aSourceFile The filename of the source file
* @param aSourceContent The content of the source file
*/
SourceNode.prototype.setSourceContent =
function SourceNode_setSourceContent(aSourceFile, aSourceContent) {
this.sourceContents[util.toSetString(aSourceFile)] = aSourceContent;
};
/**
* Walk over the tree of SourceNodes. The walking function is called for each
* source file content and is passed the filename and source content.
*
* @param aFn The traversal function.
*/
SourceNode.prototype.walkSourceContents =
function SourceNode_walkSourceContents(aFn) {
this.children.forEach(function (chunk) {
if (chunk instanceof SourceNode) {
chunk.walkSourceContents(aFn);
}
}, this);
Object.keys(this.sourceContents).forEach(function (sourceFileKey) {
aFn(util.fromSetString(sourceFileKey), this.sourceContents[sourceFileKey]);
}, this);
};
/**
* Return the string representation of this source node. Walks over the tree

@@ -308,2 +348,5 @@ * and concatenates all the various snippets together to one string.

});
this.walkSourceContents(function (sourceFile, sourceContent) {
map.setSourceContent(sourceFile, sourceContent);
});

@@ -310,0 +353,0 @@ return { code: generated.code, map: map };

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

var schemeRegexp = /^[A-Za-z0-9+.\-]+:\/\//;
function join(aRoot, aPath) {
return aPath.charAt(0) === '/'
return aPath.charAt(0) === '/' || aPath.match(schemeRegexp)
? aPath

@@ -55,2 +57,7 @@ : aRoot.replace(/\/$/, '') + '/' + aPath;

function fromSetString(aStr) {
return aStr.substr(1);
}
exports.fromSetString = fromSetString;
function relative(aRoot, aPath) {

@@ -57,0 +64,0 @@ aRoot = aRoot.replace(/\/$/, '');

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

@@ -6,0 +6,0 @@ "author": "Nick Fitzgerald <nfitzgerald@mozilla.com>",

@@ -258,2 +258,11 @@ # Source Map

#### SourceNode.prototype.setSourceContent(sourceFile, sourceContent)
Set the source content for a source file. This will be added to the
`SourceMap` in the `sourcesContent` field.
* `sourceFile`: The filename of the source file
* `sourceContent`: The content of the source file
#### SourceNode.prototype.walk(fn)

@@ -267,2 +276,9 @@

#### SourceNode.prototype.walkSourceContents(fn)
Walk over the tree of SourceNodes. The walking function is called for each
source file content and is passed the filename and source content.
* `fn`: The traversal function.
#### SourceNode.prototype.join(sep)

@@ -269,0 +285,0 @@

@@ -253,2 +253,21 @@ /* -*- Mode: js; js-indent-level: 2; -*- */

exports['test github issue #43'] = function (assert, util) {
var map = new SourceMapGenerator({
sourceRoot: 'http://example.com',
file: 'foo.js'
});
map.addMapping({
original: { line: 1, column: 1 },
generated: { line: 2, column: 2 },
source: 'http://cdn.example.com/original.js'
});
map = new SourceMapConsumer(map.toString());
var sources = map.sources;
assert.equal(sources.length, 1,
'Should only be one source.');
assert.equal(sources[0], 'http://cdn.example.com/original.js',
'Should not be joined with the sourceRoot.');
};
});

@@ -239,2 +239,45 @@ /* -*- Mode: js; js-indent-level: 2; -*- */

exports['test setSourceContent with toStringWithSourceMap'] = function (assert, util) {
var aNode = new SourceNode(1, 1, 'a.js', 'a');
aNode.setSourceContent('a.js', 'someContent');
var node = new SourceNode(null, null, null,
['(function () {\n',
' ', aNode,
' ', new SourceNode(1, 1, 'b.js', 'b'),
'}());']);
node.setSourceContent('b.js', 'otherContent');
var map = node.toStringWithSourceMap({
file: 'foo.js'
}).map;
assert.ok(map instanceof SourceMapGenerator, 'map instanceof SourceMapGenerator');
map = new SourceMapConsumer(map.toString());
assert.equal(map.sources.length, 2);
assert.equal(map.sources[0], 'a.js');
assert.equal(map.sources[1], 'b.js');
assert.equal(map.sourcesContent.length, 2);
assert.equal(map.sourcesContent[0], 'someContent');
assert.equal(map.sourcesContent[1], 'otherContent');
};
exports['test walkSourceContents'] = function (assert, util) {
var aNode = new SourceNode(1, 1, 'a.js', 'a');
aNode.setSourceContent('a.js', 'someContent');
var node = new SourceNode(null, null, null,
['(function () {\n',
' ', aNode,
' ', new SourceNode(1, 1, 'b.js', 'b'),
'}());']);
node.setSourceContent('b.js', 'otherContent');
var results = [];
node.walkSourceContents(function (sourceFile, sourceContent) {
results.push([sourceFile, sourceContent]);
});
assert.equal(results.length, 2);
assert.equal(results[0][0], 'a.js');
assert.equal(results[0][1], 'someContent');
assert.equal(results[1][0], 'b.js');
assert.equal(results[1][1], 'otherContent');
};
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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