source-map
Advanced tools
Comparing version 0.1.13 to 0.1.14
@@ -154,8 +154,3 @@ /* -*- Mode: js; js-indent-level: 2; -*- */ | ||
temp = base64VLQ.decode(str); | ||
if (aSourceRoot) { | ||
mapping.source = util.join(aSourceRoot, this._sources.at(previousSource + temp.value)); | ||
} | ||
else { | ||
mapping.source = this._sources.at(previousSource + temp.value); | ||
} | ||
mapping.source = this._sources.at(previousSource + temp.value); | ||
previousSource += temp.value; | ||
@@ -284,4 +279,8 @@ str = temp.rest; | ||
if (mapping) { | ||
var source = util.getArg(mapping, 'source', null); | ||
if (source && this.sourceRoot) { | ||
source = util.join(this.sourceRoot, source); | ||
} | ||
return { | ||
source: util.getArg(mapping, 'source', null), | ||
source: source, | ||
line: util.getArg(mapping, 'originalLine', null), | ||
@@ -315,3 +314,3 @@ column: util.getArg(mapping, 'originalColumn', null), | ||
var relativeUrl = util.relative(this.sourceRoot, aSource); | ||
if (relativeUrl !== aSource && this._sources.has(relativeUrl)) { | ||
if (this._sources.has(relativeUrl)) { | ||
return this.sourcesContent[this._sources.indexOf(relativeUrl)]; | ||
@@ -350,2 +349,6 @@ } | ||
if (this.sourceRoot) { | ||
needle.source = util.relative(this.sourceRoot, needle.source); | ||
} | ||
var mapping = this._findMapping(needle, | ||
@@ -378,4 +381,3 @@ this._originalMappings, | ||
* @param Function aCallback | ||
* The function that is called with each mapping. This function should | ||
* not mutate the mapping. | ||
* The function that is called with each mapping. | ||
* @param Object aContext | ||
@@ -408,3 +410,17 @@ * Optional. If specified, this object will be the value of `this` every | ||
mappings.forEach(aCallback, context); | ||
var sourceRoot = this.sourceRoot; | ||
mappings.map(function (mapping) { | ||
var source = mapping.source; | ||
if (source && sourceRoot) { | ||
source = util.join(sourceRoot, source); | ||
} | ||
return { | ||
source: source, | ||
generatedLine: mapping.generatedLine, | ||
generatedColumn: mapping.generatedColumn, | ||
originalLine: mapping.originalLine, | ||
originalColumn: mapping.originalColumn, | ||
name: mapping.name | ||
}; | ||
}).forEach(aCallback, context); | ||
}; | ||
@@ -411,0 +427,0 @@ |
@@ -48,39 +48,29 @@ /* -*- Mode: js; js-indent-level: 2; -*- */ | ||
aSourceMapConsumer.eachMapping(function (mapping) { | ||
var source = mapping.source; | ||
if (source) { | ||
var newMapping = { | ||
generated: { | ||
line: mapping.generatedLine, | ||
column: mapping.generatedColumn | ||
} | ||
}; | ||
if (mapping.source) { | ||
newMapping.source = mapping.source; | ||
if (sourceRoot) { | ||
var relativeUrl = util.relative(sourceRoot, source); | ||
if (relativeUrl) { | ||
source = relativeUrl; | ||
} | ||
newMapping.source = util.relative(sourceRoot, newMapping.source); | ||
} | ||
generator.addMapping({ | ||
source: source, | ||
original: { | ||
line: mapping.originalLine, | ||
column: mapping.originalColumn | ||
}, | ||
generated: { | ||
line: mapping.generatedLine, | ||
column: mapping.generatedColumn | ||
}, | ||
name: mapping.name | ||
}); | ||
} else { | ||
generator.addMapping({ | ||
generated: { | ||
line: mapping.generatedLine, | ||
column: mapping.generatedColumn | ||
} | ||
}); | ||
newMapping.original = { | ||
line: mapping.originalLine, | ||
column: mapping.originalColumn | ||
}; | ||
if (mapping.name) { | ||
newMapping.name = mapping.name; | ||
} | ||
} | ||
generator.addMapping(newMapping); | ||
}); | ||
aSourceMapConsumer.sources.forEach(function (sourceFile) { | ||
var content = aSourceMapConsumer.sourceContentFor(sourceFile); | ||
if (sourceRoot) { | ||
var relativeUrl = util.relative(sourceRoot, sourceFile); | ||
if (relativeUrl) { | ||
sourceFile = relativeUrl; | ||
} | ||
} | ||
if (content) { | ||
@@ -133,2 +123,7 @@ generator.setSourceContent(sourceFile, content); | ||
function SourceMapGenerator_setSourceContent(aSourceFile, aSourceContent) { | ||
var source = aSourceFile; | ||
if (this._sourceRoot) { | ||
source = util.relative(this._sourceRoot, source); | ||
} | ||
if (aSourceContent !== null) { | ||
@@ -140,7 +135,7 @@ // Add the source content to the _sourcesContents map. | ||
} | ||
this._sourcesContents[util.toSetString(aSourceFile)] = aSourceContent; | ||
this._sourcesContents[util.toSetString(source)] = 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)]; | ||
delete this._sourcesContents[util.toSetString(source)]; | ||
if (Object.keys(this._sourcesContents).length === 0) { | ||
@@ -273,3 +268,6 @@ this._sourcesContents = null; | ||
if (this._sourcesContents) { | ||
map.sourcesContent = map.sources.map(function(source) { | ||
map.sourcesContent = map.sources.map(function (source) { | ||
if (map.sourceRoot) { | ||
source = util.relative(map.sourceRoot, source); | ||
} | ||
return Object.prototype.hasOwnProperty.call( | ||
@@ -276,0 +274,0 @@ this._sourcesContents, util.toSetString(source)) |
{ | ||
"name": "source-map", | ||
"description": "Generates and consumes source maps", | ||
"version": "0.1.13", | ||
"version": "0.1.14", | ||
"homepage": "https://github.com/mozilla/source-map", | ||
@@ -6,0 +6,0 @@ "author": "Nick Fitzgerald <nfitzgerald@mozilla.com>", |
@@ -13,2 +13,3 @@ /* -*- Mode: js; js-indent-level: 2; -*- */ | ||
var SourceMapConsumer = require('../../lib/source-map/source-map-consumer').SourceMapConsumer; | ||
var SourceMapGenerator = require('../../lib/source-map/source-map-generator').SourceMapGenerator; | ||
@@ -96,2 +97,6 @@ exports['test that we can instantiate with a string or an objects'] = function (assert, util) { | ||
if (mapping.source) { | ||
assert.equal(mapping.source.indexOf(util.testMap.sourceRoot), 0); | ||
} | ||
if (mapping.generatedLine === previousLine) { | ||
@@ -172,2 +177,63 @@ assert.ok(mapping.generatedColumn >= previousColumn); | ||
exports['test sourceRoot + generatedPositionFor'] = function (assert, util) { | ||
var map = new SourceMapGenerator({ | ||
sourceRoot: 'foo/bar', | ||
file: 'baz.js' | ||
}); | ||
map.addMapping({ | ||
original: { line: 1, column: 1 }, | ||
generated: { line: 2, column: 2 }, | ||
source: 'bang.coffee' | ||
}); | ||
map.addMapping({ | ||
original: { line: 5, column: 5 }, | ||
generated: { line: 6, column: 6 }, | ||
source: 'bang.coffee' | ||
}); | ||
map = new SourceMapConsumer(map.toString()); | ||
// Should handle without sourceRoot. | ||
var pos = map.generatedPositionFor({ | ||
line: 1, | ||
column: 1, | ||
source: 'bang.coffee' | ||
}); | ||
assert.equal(pos.line, 2); | ||
assert.equal(pos.column, 2); | ||
// Should handle with sourceRoot. | ||
var pos = map.generatedPositionFor({ | ||
line: 1, | ||
column: 1, | ||
source: 'foo/bar/bang.coffee' | ||
}); | ||
assert.equal(pos.line, 2); | ||
assert.equal(pos.column, 2); | ||
}; | ||
exports['test sourceRoot + originalPositionFor'] = function (assert, util) { | ||
var map = new SourceMapGenerator({ | ||
sourceRoot: 'foo/bar', | ||
file: 'baz.js' | ||
}); | ||
map.addMapping({ | ||
original: { line: 1, column: 1 }, | ||
generated: { line: 2, column: 2 }, | ||
source: 'bang.coffee' | ||
}); | ||
map = new SourceMapConsumer(map.toString()); | ||
var pos = map.originalPositionFor({ | ||
line: 2, | ||
column: 2, | ||
}); | ||
// Should always have the prepended source root | ||
assert.equal(pos.source, 'foo/bar/bang.coffee'); | ||
assert.equal(pos.line, 1); | ||
assert.equal(pos.column, 1); | ||
}; | ||
}); |
@@ -217,3 +217,5 @@ /* -*- Mode: js; js-indent-level: 2; -*- */ | ||
exports['test .fromSourceMap with sourcesContent'] = function (assert, util) { | ||
var map = SourceMapGenerator.fromSourceMap(new SourceMapConsumer(util.testMapWithSourcesContent)); | ||
var map = SourceMapGenerator.fromSourceMap( | ||
new SourceMapConsumer(util.testMapWithSourcesContent)); | ||
assert.deepEqual(map.toJSON().sourcesContent, util.testMapWithSourcesContent.sourcesContent); | ||
@@ -220,0 +222,0 @@ assert.deepEqual(map.toJSON(), util.testMapWithSourcesContent); |
@@ -12,2 +12,4 @@ /* -*- Mode: js; js-indent-level: 2; -*- */ | ||
var util = require('../../lib/source-map/util'); | ||
// This is a test mapping which maps functions from two different files | ||
@@ -74,3 +76,4 @@ // (one.js and two.js) to a minified generated source. | ||
+ ', got ' + JSON.stringify(origMapping.column)); | ||
assert.equal(origMapping.source, originalSource, | ||
assert.equal(origMapping.source, | ||
originalSource ? util.join(map._sourceRoot, originalSource) : null, | ||
'Incorrect source, expected ' + JSON.stringify(originalSource) | ||
@@ -77,0 +80,0 @@ + ', got ' + JSON.stringify(origMapping.source)); |
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
105035
2536