source-map
Advanced tools
Comparing version 0.1.12 to 0.1.13
@@ -67,3 +67,3 @@ /* -*- Mode: js; js-indent-level: 2; -*- */ | ||
this._sources = ArraySet.fromArray(sources); | ||
this._sourceRoot = sourceRoot; | ||
this.sourceRoot = sourceRoot; | ||
this.sourcesContent = sourcesContent; | ||
@@ -111,3 +111,3 @@ this.file = file; | ||
return this._sources.toArray().map(function (s) { | ||
return this._sourceRoot ? util.join(this._sourceRoot, s) : s; | ||
return this.sourceRoot ? util.join(this.sourceRoot, s) : s; | ||
}, this); | ||
@@ -308,10 +308,10 @@ } | ||
function SourceMapConsumer_sourceContentFor(aSource) { | ||
if(!this.sourcesContent) { | ||
if (!this.sourcesContent) { | ||
return null; | ||
} | ||
if(this._sourceRoot) { | ||
if (this.sourceRoot) { | ||
// Try to remove the sourceRoot | ||
var relativeUrl = util.relative(this._sourceRoot, aSource); | ||
if(relativeUrl !== aSource && this._sources.has(relativeUrl)) { | ||
var relativeUrl = util.relative(this.sourceRoot, aSource); | ||
if (relativeUrl !== aSource && this._sources.has(relativeUrl)) { | ||
return this.sourcesContent[this._sources.indexOf(relativeUrl)]; | ||
@@ -321,3 +321,3 @@ } | ||
if(this._sources.has(aSource)) { | ||
if (this._sources.has(aSource)) { | ||
return this.sourcesContent[this._sources.indexOf(aSource)]; | ||
@@ -324,0 +324,0 @@ } |
@@ -36,2 +36,59 @@ /* -*- Mode: js; js-indent-level: 2; -*- */ | ||
/** | ||
* Creates a new SourceMapGenerator based on a SourceMapConsumer | ||
* | ||
* @param aSourceMapConsumer The SourceMap. | ||
*/ | ||
SourceMapGenerator.fromSourceMap = | ||
function SourceMapGenerator_fromSourceMap(aSourceMapConsumer) { | ||
var sourceRoot = aSourceMapConsumer.sourceRoot; | ||
var generator = new SourceMapGenerator({ | ||
file: aSourceMapConsumer.file, | ||
sourceRoot: sourceRoot | ||
}); | ||
aSourceMapConsumer.eachMapping(function (mapping) { | ||
var source = mapping.source; | ||
if (source) { | ||
if (sourceRoot) { | ||
var relativeUrl = util.relative(sourceRoot, source); | ||
if (relativeUrl) { | ||
source = relativeUrl; | ||
} | ||
} | ||
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 | ||
} | ||
}); | ||
} | ||
}); | ||
aSourceMapConsumer.sources.forEach(function (sourceFile) { | ||
var content = aSourceMapConsumer.sourceContentFor(sourceFile); | ||
if (sourceRoot) { | ||
var relativeUrl = util.relative(sourceRoot, sourceFile); | ||
if (relativeUrl) { | ||
sourceFile = relativeUrl; | ||
} | ||
} | ||
if (content) { | ||
generator.setSourceContent(sourceFile, content); | ||
} | ||
}); | ||
return generator; | ||
}; | ||
/** | ||
* Add a single mapping from original source line and column to the generated | ||
@@ -76,6 +133,6 @@ * source's line and column for this source map being created. The mapping | ||
function SourceMapGenerator_setSourceContent(aSourceFile, aSourceContent) { | ||
if(aSourceContent !== null) { | ||
if (aSourceContent !== null) { | ||
// Add the source content to the _sourcesContents map. | ||
// Create a new _sourcesContents map if the property is null. | ||
if(!this._sourcesContents) { | ||
if (!this._sourcesContents) { | ||
this._sourcesContents = {}; | ||
@@ -88,3 +145,3 @@ } | ||
delete this._sourcesContents[util.toSetString(aSourceFile)]; | ||
if(Object.keys(this._sourcesContents).length === 0) { | ||
if (Object.keys(this._sourcesContents).length === 0) { | ||
this._sourcesContents = null; | ||
@@ -91,0 +148,0 @@ } |
@@ -191,3 +191,3 @@ /* -*- Mode: js; js-indent-level: 2; -*- */ | ||
sourceMappingActive = true; | ||
} else if(sourceMappingActive) { | ||
} else if (sourceMappingActive) { | ||
map.addMapping({ | ||
@@ -194,0 +194,0 @@ generated: { |
{ | ||
"name": "source-map", | ||
"description": "Generates and consumes source maps", | ||
"version": "0.1.12", | ||
"version": "0.1.13", | ||
"homepage": "https://github.com/mozilla/source-map", | ||
@@ -6,0 +6,0 @@ "author": "Nick Fitzgerald <nfitzgerald@mozilla.com>", |
@@ -13,2 +13,4 @@ /* -*- Mode: js; js-indent-level: 2; -*- */ | ||
var SourceMapGenerator = require('../../lib/source-map/source-map-generator').SourceMapGenerator; | ||
var SourceMapConsumer = require('../../lib/source-map/source-map-consumer').SourceMapConsumer; | ||
var util = require('./util'); | ||
@@ -209,2 +211,13 @@ exports['test some simple stuff'] = function (assert, util) { | ||
}; | ||
exports['test .fromSourceMap'] = function (assert, util) { | ||
var map = SourceMapGenerator.fromSourceMap(new SourceMapConsumer(util.testMap)); | ||
assert.deepEqual(map.toJSON(), util.testMap); | ||
}; | ||
exports['test .fromSourceMap with sourcesContent'] = function (assert, util) { | ||
var map = SourceMapGenerator.fromSourceMap(new SourceMapConsumer(util.testMapWithSourcesContent)); | ||
assert.deepEqual(map.toJSON().sourcesContent, util.testMapWithSourcesContent.sourcesContent); | ||
assert.deepEqual(map.toJSON(), util.testMapWithSourcesContent); | ||
}; | ||
}); |
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
102806
2468