source-map
Advanced tools
Comparing version 0.1.30 to 0.1.31
# Change Log | ||
## 0.1.31 | ||
* Delay parsing the mappings in SourceMapConsumer until queried for a source | ||
location. | ||
* Support Sass source maps (which at the time of writing deviate from the spec | ||
in small ways) in SourceMapConsumer. | ||
## 0.1.30 | ||
@@ -4,0 +12,0 @@ |
@@ -55,3 +55,5 @@ /* -*- Mode: js; js-indent-level: 2; -*- */ | ||
var sources = util.getArg(sourceMap, 'sources'); | ||
var names = util.getArg(sourceMap, 'names'); | ||
// Sass 3.3 leaves out the 'names' array, so we deviate from the spec (which | ||
// requires the array) to play nice here. | ||
var names = util.getArg(sourceMap, 'names', []); | ||
var sourceRoot = util.getArg(sourceMap, 'sourceRoot', null); | ||
@@ -62,3 +64,5 @@ var sourcesContent = util.getArg(sourceMap, 'sourcesContent', null); | ||
if (version !== this._version) { | ||
// Once again, Sass deviates from the spec and supplies the version as a | ||
// string rather than a number, so we use loose equality checking here. | ||
if (version != this._version) { | ||
throw new Error('Unsupported version: ' + version); | ||
@@ -73,32 +77,7 @@ } | ||
this._sources = ArraySet.fromArray(sources, true); | ||
this.sourceRoot = sourceRoot; | ||
this.sourcesContent = sourcesContent; | ||
this._mappings = mappings; | ||
this.file = file; | ||
// `this._generatedMappings` and `this._originalMappings` hold the parsed | ||
// mapping coordinates from the source map's "mappings" attribute. Each | ||
// object in the array is of the form | ||
// | ||
// { | ||
// generatedLine: The line number in the generated code, | ||
// generatedColumn: The column number in the generated code, | ||
// source: The path to the original source file that generated this | ||
// chunk of code, | ||
// originalLine: The line number in the original source that | ||
// corresponds to this chunk of generated code, | ||
// originalColumn: The column number in the original source that | ||
// corresponds to this chunk of generated code, | ||
// name: The name of the original symbol which generated this chunk of | ||
// code. | ||
// } | ||
// | ||
// All properties except for `generatedLine` and `generatedColumn` can be | ||
// `null`. | ||
// | ||
// `this._generatedMappings` is ordered by the generated positions. | ||
// | ||
// `this._originalMappings` is ordered by the original positions. | ||
this._generatedMappings = []; | ||
this._originalMappings = []; | ||
this._parseMappings(mappings, sourceRoot); | ||
} | ||
@@ -124,5 +103,5 @@ | ||
smc._generatedMappings = aSourceMap._mappings.slice() | ||
smc.__generatedMappings = aSourceMap._mappings.slice() | ||
.sort(util.compareByGeneratedPositions); | ||
smc._originalMappings = aSourceMap._mappings.slice() | ||
smc.__originalMappings = aSourceMap._mappings.slice() | ||
.sort(util.compareByOriginalPositions); | ||
@@ -149,5 +128,62 @@ | ||
// `__generatedMappings` and `__originalMappings` are arrays that hold the | ||
// parsed mapping coordinates from the source map's "mappings" attribute. They | ||
// are lazily instantiated, accessed via the `_generatedMappings` and | ||
// `_originalMappings` getters respectively, and we only parse the mappings | ||
// and create these arrays once queried for a source location. We jump through | ||
// these hoops because there can be many thousands of mappings, and parsing | ||
// them is expensive, so we only want to do it if we must. | ||
// | ||
// Each object in the arrays is of the form: | ||
// | ||
// { | ||
// generatedLine: The line number in the generated code, | ||
// generatedColumn: The column number in the generated code, | ||
// source: The path to the original source file that generated this | ||
// chunk of code, | ||
// originalLine: The line number in the original source that | ||
// corresponds to this chunk of generated code, | ||
// originalColumn: The column number in the original source that | ||
// corresponds to this chunk of generated code, | ||
// name: The name of the original symbol which generated this chunk of | ||
// code. | ||
// } | ||
// | ||
// All properties except for `generatedLine` and `generatedColumn` can be | ||
// `null`. | ||
// | ||
// `_generatedMappings` is ordered by the generated positions. | ||
// | ||
// `_originalMappings` is ordered by the original positions. | ||
SourceMapConsumer.prototype.__generatedMappings = null; | ||
Object.defineProperty(SourceMapConsumer.prototype, '_generatedMappings', { | ||
get: function () { | ||
if (!this.__generatedMappings) { | ||
this.__generatedMappings = []; | ||
this.__originalMappings = []; | ||
this._parseMappings(this._mappings, this.sourceRoot); | ||
} | ||
return this.__generatedMappings; | ||
} | ||
}); | ||
SourceMapConsumer.prototype.__originalMappings = null; | ||
Object.defineProperty(SourceMapConsumer.prototype, '_originalMappings', { | ||
get: function () { | ||
if (!this.__originalMappings) { | ||
this.__generatedMappings = []; | ||
this.__originalMappings = []; | ||
this._parseMappings(this._mappings, this.sourceRoot); | ||
} | ||
return this.__originalMappings; | ||
} | ||
}); | ||
/** | ||
* Parse the mappings in a string in to a data structure which we can easily | ||
* query (an ordered list in this._generatedMappings). | ||
* query (the ordered arrays in the `this.__generatedMappings` and | ||
* `this.__originalMappings` properties). | ||
*/ | ||
@@ -222,5 +258,5 @@ SourceMapConsumer.prototype._parseMappings = | ||
this._generatedMappings.push(mapping); | ||
this.__generatedMappings.push(mapping); | ||
if (typeof mapping.originalLine === 'number') { | ||
this._originalMappings.push(mapping); | ||
this.__originalMappings.push(mapping); | ||
} | ||
@@ -230,3 +266,3 @@ } | ||
this._originalMappings.sort(util.compareByOriginalPositions); | ||
this.__originalMappings.sort(util.compareByOriginalPositions); | ||
}; | ||
@@ -233,0 +269,0 @@ |
{ | ||
"name": "source-map", | ||
"description": "Generates and consumes source maps", | ||
"version": "0.1.30", | ||
"version": "0.1.31", | ||
"homepage": "https://github.com/mozilla/source-map", | ||
@@ -22,3 +22,4 @@ "author": "Nick Fitzgerald <nfitzgerald@mozilla.com>", | ||
"Chase Douglas <chase@newrelic.com>", | ||
"Evan Wallace <evan.exe@gmail.com>" | ||
"Evan Wallace <evan.exe@gmail.com>", | ||
"Heather Arthur <fayearthur@gmail.com>" | ||
], | ||
@@ -25,0 +26,0 @@ "repository": { |
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
149452
3528