source-map
Advanced tools
Comparing version 0.7.2 to 0.7.3
# Change Log | ||
## 0.7.3 | ||
* Fix a bug where nested uses of `SourceMapConsumer` could result in a | ||
`TypeError`. [#338](https://github.com/mozilla/source-map/issues/338) | ||
[#330](https://github.com/mozilla/source-map/issues/330) | ||
[#319](https://github.com/mozilla/source-map/issues/319) | ||
## 0.7.2 | ||
@@ -4,0 +11,0 @@ |
@@ -8,6 +8,2 @@ /* -*- Mode: js; js-indent-level: 2; -*- */ | ||
var util = require('./util'); | ||
var has = Object.prototype.hasOwnProperty; | ||
var hasNativeMap = typeof Map !== "undefined"; | ||
/** | ||
@@ -19,105 +15,88 @@ * A data structure which is a combination of an array and a set. Adding a new | ||
*/ | ||
function ArraySet() { | ||
this._array = []; | ||
this._set = hasNativeMap ? new Map() : Object.create(null); | ||
} | ||
class ArraySet { | ||
constructor() { | ||
this._array = []; | ||
this._set = new Map(); | ||
} | ||
/** | ||
* Static method for creating ArraySet instances from an existing array. | ||
*/ | ||
ArraySet.fromArray = function ArraySet_fromArray(aArray, aAllowDuplicates) { | ||
var set = new ArraySet(); | ||
for (var i = 0, len = aArray.length; i < len; i++) { | ||
set.add(aArray[i], aAllowDuplicates); | ||
/** | ||
* Static method for creating ArraySet instances from an existing array. | ||
*/ | ||
static fromArray(aArray, aAllowDuplicates) { | ||
const set = new ArraySet(); | ||
for (let i = 0, len = aArray.length; i < len; i++) { | ||
set.add(aArray[i], aAllowDuplicates); | ||
} | ||
return set; | ||
} | ||
return set; | ||
}; | ||
/** | ||
* Return how many unique items are in this ArraySet. If duplicates have been | ||
* added, than those do not count towards the size. | ||
* | ||
* @returns Number | ||
*/ | ||
ArraySet.prototype.size = function ArraySet_size() { | ||
return hasNativeMap ? this._set.size : Object.getOwnPropertyNames(this._set).length; | ||
}; | ||
/** | ||
* Return how many unique items are in this ArraySet. If duplicates have been | ||
* added, than those do not count towards the size. | ||
* | ||
* @returns Number | ||
*/ | ||
size() { | ||
return this._set.size; | ||
} | ||
/** | ||
* Add the given string to this set. | ||
* | ||
* @param String aStr | ||
*/ | ||
ArraySet.prototype.add = function ArraySet_add(aStr, aAllowDuplicates) { | ||
var sStr = hasNativeMap ? aStr : util.toSetString(aStr); | ||
var isDuplicate = hasNativeMap ? this.has(aStr) : has.call(this._set, sStr); | ||
var idx = this._array.length; | ||
if (!isDuplicate || aAllowDuplicates) { | ||
this._array.push(aStr); | ||
} | ||
if (!isDuplicate) { | ||
if (hasNativeMap) { | ||
/** | ||
* Add the given string to this set. | ||
* | ||
* @param String aStr | ||
*/ | ||
add(aStr, aAllowDuplicates) { | ||
const isDuplicate = this.has(aStr); | ||
const idx = this._array.length; | ||
if (!isDuplicate || aAllowDuplicates) { | ||
this._array.push(aStr); | ||
} | ||
if (!isDuplicate) { | ||
this._set.set(aStr, idx); | ||
} else { | ||
this._set[sStr] = idx; | ||
} | ||
} | ||
}; | ||
/** | ||
* Is the given string a member of this set? | ||
* | ||
* @param String aStr | ||
*/ | ||
ArraySet.prototype.has = function ArraySet_has(aStr) { | ||
if (hasNativeMap) { | ||
return this._set.has(aStr); | ||
} else { | ||
var sStr = util.toSetString(aStr); | ||
return has.call(this._set, sStr); | ||
/** | ||
* Is the given string a member of this set? | ||
* | ||
* @param String aStr | ||
*/ | ||
has(aStr) { | ||
return this._set.has(aStr); | ||
} | ||
}; | ||
/** | ||
* What is the index of the given string in the array? | ||
* | ||
* @param String aStr | ||
*/ | ||
ArraySet.prototype.indexOf = function ArraySet_indexOf(aStr) { | ||
if (hasNativeMap) { | ||
var idx = this._set.get(aStr); | ||
/** | ||
* What is the index of the given string in the array? | ||
* | ||
* @param String aStr | ||
*/ | ||
indexOf(aStr) { | ||
const idx = this._set.get(aStr); | ||
if (idx >= 0) { | ||
return idx; | ||
} | ||
} else { | ||
var sStr = util.toSetString(aStr); | ||
if (has.call(this._set, sStr)) { | ||
return this._set[sStr]; | ||
throw new Error('"' + aStr + '" is not in the set.'); | ||
} | ||
/** | ||
* What is the element at the given index? | ||
* | ||
* @param Number aIdx | ||
*/ | ||
at(aIdx) { | ||
if (aIdx >= 0 && aIdx < this._array.length) { | ||
return this._array[aIdx]; | ||
} | ||
throw new Error("No element indexed by " + aIdx); | ||
} | ||
throw new Error('"' + aStr + '" is not in the set.'); | ||
}; | ||
/** | ||
* What is the element at the given index? | ||
* | ||
* @param Number aIdx | ||
*/ | ||
ArraySet.prototype.at = function ArraySet_at(aIdx) { | ||
if (aIdx >= 0 && aIdx < this._array.length) { | ||
return this._array[aIdx]; | ||
/** | ||
* Returns the array representation of this set (which has the proper indices | ||
* indicated by indexOf). Note that this is a copy of the internal array used | ||
* for storing the members so that no one can mess with internal state. | ||
*/ | ||
toArray() { | ||
return this._array.slice(); | ||
} | ||
throw new Error('No element indexed by ' + aIdx); | ||
}; | ||
/** | ||
* Returns the array representation of this set (which has the proper indices | ||
* indicated by indexOf). Note that this is a copy of the internal array used | ||
* for storing the members so that no one can mess with internal state. | ||
*/ | ||
ArraySet.prototype.toArray = function ArraySet_toArray() { | ||
return this._array.slice(); | ||
}; | ||
} | ||
exports.ArraySet = ArraySet; |
@@ -38,3 +38,3 @@ /* -*- Mode: js; js-indent-level: 2; -*- */ | ||
var base64 = require('./base64'); | ||
const base64 = require("./base64"); | ||
@@ -53,12 +53,12 @@ // A single base 64 digit can contain 6 bits of data. For the base 64 variable | ||
var VLQ_BASE_SHIFT = 5; | ||
const VLQ_BASE_SHIFT = 5; | ||
// binary: 100000 | ||
var VLQ_BASE = 1 << VLQ_BASE_SHIFT; | ||
const VLQ_BASE = 1 << VLQ_BASE_SHIFT; | ||
// binary: 011111 | ||
var VLQ_BASE_MASK = VLQ_BASE - 1; | ||
const VLQ_BASE_MASK = VLQ_BASE - 1; | ||
// binary: 100000 | ||
var VLQ_CONTINUATION_BIT = VLQ_BASE; | ||
const VLQ_CONTINUATION_BIT = VLQ_BASE; | ||
@@ -83,5 +83,6 @@ /** | ||
*/ | ||
// eslint-disable-next-line no-unused-vars | ||
function fromVLQSigned(aValue) { | ||
var isNegative = (aValue & 1) === 1; | ||
var shifted = aValue >> 1; | ||
const isNegative = (aValue & 1) === 1; | ||
const shifted = aValue >> 1; | ||
return isNegative | ||
@@ -96,6 +97,6 @@ ? -shifted | ||
exports.encode = function base64VLQ_encode(aValue) { | ||
var encoded = ""; | ||
var digit; | ||
let encoded = ""; | ||
let digit; | ||
var vlq = toVLQSigned(aValue); | ||
let vlq = toVLQSigned(aValue); | ||
@@ -102,0 +103,0 @@ do { |
@@ -8,3 +8,3 @@ /* -*- Mode: js; js-indent-level: 2; -*- */ | ||
var intToCharMap = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split(''); | ||
const intToCharMap = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split(""); | ||
@@ -14,3 +14,3 @@ /** | ||
*/ | ||
exports.encode = function (number) { | ||
exports.encode = function(number) { | ||
if (0 <= number && number < intToCharMap.length) { | ||
@@ -17,0 +17,0 @@ return intToCharMap[number]; |
@@ -34,9 +34,8 @@ /* -*- Mode: js; js-indent-level: 2; -*- */ | ||
// element than the one we are searching for, so we return -1. | ||
var mid = Math.floor((aHigh - aLow) / 2) + aLow; | ||
var cmp = aCompare(aNeedle, aHaystack[mid], true); | ||
const mid = Math.floor((aHigh - aLow) / 2) + aLow; | ||
const cmp = aCompare(aNeedle, aHaystack[mid], true); | ||
if (cmp === 0) { | ||
// Found the element we are looking for. | ||
return mid; | ||
} | ||
else if (cmp > 0) { | ||
} else if (cmp > 0) { | ||
// Our needle is greater than aHaystack[mid]. | ||
@@ -52,20 +51,17 @@ if (aHigh - mid > 1) { | ||
return aHigh < aHaystack.length ? aHigh : -1; | ||
} else { | ||
return mid; | ||
} | ||
return mid; | ||
} | ||
else { | ||
// Our needle is less than aHaystack[mid]. | ||
if (mid - aLow > 1) { | ||
// The element is in the lower half. | ||
return recursiveSearch(aLow, mid, aNeedle, aHaystack, aCompare, aBias); | ||
} | ||
// we are in termination case (3) or (2) and return the appropriate thing. | ||
if (aBias == exports.LEAST_UPPER_BOUND) { | ||
return mid; | ||
} else { | ||
return aLow < 0 ? -1 : aLow; | ||
} | ||
// Our needle is less than aHaystack[mid]. | ||
if (mid - aLow > 1) { | ||
// The element is in the lower half. | ||
return recursiveSearch(aLow, mid, aNeedle, aHaystack, aCompare, aBias); | ||
} | ||
// we are in termination case (3) or (2) and return the appropriate thing. | ||
if (aBias == exports.LEAST_UPPER_BOUND) { | ||
return mid; | ||
} | ||
return aLow < 0 ? -1 : aLow; | ||
} | ||
@@ -96,3 +92,3 @@ | ||
var index = recursiveSearch(-1, aHaystack.length, aNeedle, aHaystack, | ||
let index = recursiveSearch(-1, aHaystack.length, aNeedle, aHaystack, | ||
aCompare, aBias || exports.GREATEST_LOWER_BOUND); | ||
@@ -99,0 +95,0 @@ if (index < 0) { |
@@ -8,3 +8,3 @@ /* -*- Mode: js; js-indent-level: 2; -*- */ | ||
var util = require('./util'); | ||
const util = require("./util"); | ||
@@ -17,6 +17,6 @@ /** | ||
// Optimized for most common case | ||
var lineA = mappingA.generatedLine; | ||
var lineB = mappingB.generatedLine; | ||
var columnA = mappingA.generatedColumn; | ||
var columnB = mappingB.generatedColumn; | ||
const lineA = mappingA.generatedLine; | ||
const lineB = mappingB.generatedLine; | ||
const columnA = mappingA.generatedColumn; | ||
const columnB = mappingB.generatedColumn; | ||
return lineB > lineA || lineB == lineA && columnB >= columnA || | ||
@@ -31,52 +31,53 @@ util.compareByGeneratedPositionsInflated(mappingA, mappingB) <= 0; | ||
*/ | ||
function MappingList() { | ||
this._array = []; | ||
this._sorted = true; | ||
// Serves as infimum | ||
this._last = {generatedLine: -1, generatedColumn: 0}; | ||
} | ||
class MappingList { | ||
constructor() { | ||
this._array = []; | ||
this._sorted = true; | ||
// Serves as infimum | ||
this._last = {generatedLine: -1, generatedColumn: 0}; | ||
} | ||
/** | ||
* Iterate through internal items. This method takes the same arguments that | ||
* `Array.prototype.forEach` takes. | ||
* | ||
* NOTE: The order of the mappings is NOT guaranteed. | ||
*/ | ||
MappingList.prototype.unsortedForEach = | ||
function MappingList_forEach(aCallback, aThisArg) { | ||
/** | ||
* Iterate through internal items. This method takes the same arguments that | ||
* `Array.prototype.forEach` takes. | ||
* | ||
* NOTE: The order of the mappings is NOT guaranteed. | ||
*/ | ||
unsortedForEach(aCallback, aThisArg) { | ||
this._array.forEach(aCallback, aThisArg); | ||
}; | ||
} | ||
/** | ||
* Add the given source mapping. | ||
* | ||
* @param Object aMapping | ||
*/ | ||
MappingList.prototype.add = function MappingList_add(aMapping) { | ||
if (generatedPositionAfter(this._last, aMapping)) { | ||
this._last = aMapping; | ||
this._array.push(aMapping); | ||
} else { | ||
this._sorted = false; | ||
this._array.push(aMapping); | ||
/** | ||
* Add the given source mapping. | ||
* | ||
* @param Object aMapping | ||
*/ | ||
add(aMapping) { | ||
if (generatedPositionAfter(this._last, aMapping)) { | ||
this._last = aMapping; | ||
this._array.push(aMapping); | ||
} else { | ||
this._sorted = false; | ||
this._array.push(aMapping); | ||
} | ||
} | ||
}; | ||
/** | ||
* Returns the flat, sorted array of mappings. The mappings are sorted by | ||
* generated position. | ||
* | ||
* WARNING: This method returns internal data without copying, for | ||
* performance. The return value must NOT be mutated, and should be treated as | ||
* an immutable borrow. If you want to take ownership, you must make your own | ||
* copy. | ||
*/ | ||
MappingList.prototype.toArray = function MappingList_toArray() { | ||
if (!this._sorted) { | ||
this._array.sort(util.compareByGeneratedPositionsInflated); | ||
this._sorted = true; | ||
/** | ||
* Returns the flat, sorted array of mappings. The mappings are sorted by | ||
* generated position. | ||
* | ||
* WARNING: This method returns internal data without copying, for | ||
* performance. The return value must NOT be mutated, and should be treated as | ||
* an immutable borrow. If you want to take ownership, you must make your own | ||
* copy. | ||
*/ | ||
toArray() { | ||
if (!this._sorted) { | ||
this._array.sort(util.compareByGeneratedPositionsInflated); | ||
this._sorted = true; | ||
} | ||
return this._array; | ||
} | ||
return this._array; | ||
}; | ||
} | ||
exports.MappingList = MappingList; |
@@ -8,86 +8,147 @@ /* -*- Mode: js; js-indent-level: 2; -*- */ | ||
var util = require('./util'); | ||
var binarySearch = require('./binary-search'); | ||
var ArraySet = require('./array-set').ArraySet; | ||
var base64VLQ = require('./base64-vlq'); | ||
var readWasm = require('../lib/read-wasm'); | ||
var wasm = require('./wasm'); | ||
const util = require("./util"); | ||
const binarySearch = require("./binary-search"); | ||
const ArraySet = require("./array-set").ArraySet; | ||
const base64VLQ = require("./base64-vlq"); // eslint-disable-line no-unused-vars | ||
const readWasm = require("../lib/read-wasm"); | ||
const wasm = require("./wasm"); | ||
function SourceMapConsumer(aSourceMap, aSourceMapURL) { | ||
var sourceMap = aSourceMap; | ||
if (typeof aSourceMap === 'string') { | ||
sourceMap = util.parseSourceMapInput(aSourceMap); | ||
const INTERNAL = Symbol("smcInternal"); | ||
class SourceMapConsumer { | ||
constructor(aSourceMap, aSourceMapURL) { | ||
// If the constructor was called by super(), just return Promise<this>. | ||
// Yes, this is a hack to retain the pre-existing API of the base-class | ||
// constructor also being an async factory function. | ||
if (aSourceMap == INTERNAL) { | ||
return Promise.resolve(this); | ||
} | ||
return _factory(aSourceMap, aSourceMapURL); | ||
} | ||
return Promise.resolve().then(_ => { | ||
return sourceMap.sections != null | ||
? new IndexedSourceMapConsumer(sourceMap, aSourceMapURL) | ||
: new BasicSourceMapConsumer(sourceMap, aSourceMapURL); | ||
}); | ||
} | ||
static initialize(opts) { | ||
readWasm.initialize(opts["lib/mappings.wasm"]); | ||
} | ||
SourceMapConsumer.initialize = opts => { | ||
readWasm.initialize(opts["lib/mappings.wasm"]); | ||
}; | ||
static fromSourceMap(aSourceMap, aSourceMapURL) { | ||
return _factoryBSM(aSourceMap, aSourceMapURL); | ||
} | ||
SourceMapConsumer.fromSourceMap = function(aSourceMap, aSourceMapURL) { | ||
return BasicSourceMapConsumer.fromSourceMap(aSourceMap, aSourceMapURL); | ||
} | ||
/** | ||
* Construct a new `SourceMapConsumer` from `rawSourceMap` and `sourceMapUrl` | ||
* (see the `SourceMapConsumer` constructor for details. Then, invoke the `async | ||
* function f(SourceMapConsumer) -> T` with the newly constructed consumer, wait | ||
* for `f` to complete, call `destroy` on the consumer, and return `f`'s return | ||
* value. | ||
* | ||
* You must not use the consumer after `f` completes! | ||
* | ||
* By using `with`, you do not have to remember to manually call `destroy` on | ||
* the consumer, since it will be called automatically once `f` completes. | ||
* | ||
* ```js | ||
* const xSquared = await SourceMapConsumer.with( | ||
* myRawSourceMap, | ||
* null, | ||
* async function (consumer) { | ||
* // Use `consumer` inside here and don't worry about remembering | ||
* // to call `destroy`. | ||
* | ||
* const x = await whatever(consumer); | ||
* return x * x; | ||
* } | ||
* ); | ||
* | ||
* // You may not use that `consumer` anymore out here; it has | ||
* // been destroyed. But you can use `xSquared`. | ||
* console.log(xSquared); | ||
* ``` | ||
*/ | ||
static with(rawSourceMap, sourceMapUrl, f) { | ||
// Note: The `acorn` version that `webpack` currently depends on doesn't | ||
// support `async` functions, and the nodes that we support don't all have | ||
// `.finally`. Therefore, this is written a bit more convolutedly than it | ||
// should really be. | ||
/** | ||
* Construct a new `SourceMapConsumer` from `rawSourceMap` and `sourceMapUrl` | ||
* (see the `SourceMapConsumer` constructor for details. Then, invoke the `async | ||
* function f(SourceMapConsumer) -> T` with the newly constructed consumer, wait | ||
* for `f` to complete, call `destroy` on the consumer, and return `f`'s return | ||
* value. | ||
* | ||
* You must not use the consumer after `f` completes! | ||
* | ||
* By using `with`, you do not have to remember to manually call `destroy` on | ||
* the consumer, since it will be called automatically once `f` completes. | ||
* | ||
* ```js | ||
* const xSquared = await SourceMapConsumer.with( | ||
* myRawSourceMap, | ||
* null, | ||
* async function (consumer) { | ||
* // Use `consumer` inside here and don't worry about remembering | ||
* // to call `destroy`. | ||
* | ||
* const x = await whatever(consumer); | ||
* return x * x; | ||
* } | ||
* ); | ||
* | ||
* // You may not use that `consumer` anymore out here; it has | ||
* // been destroyed. But you can use `xSquared`. | ||
* console.log(xSquared); | ||
* ``` | ||
*/ | ||
SourceMapConsumer.with = function(rawSourceMap, sourceMapUrl, f) { | ||
// Note: The `acorn` version that `webpack` currently depends on doesn't | ||
// support `async` functions, and the nodes that we support don't all have | ||
// `.finally`. Therefore, this is written a bit more convolutedly than it | ||
// should really be. | ||
let consumer = null; | ||
const promise = new SourceMapConsumer(rawSourceMap, sourceMapUrl); | ||
return promise | ||
.then(c => { | ||
consumer = c; | ||
return f(c); | ||
}) | ||
.then(x => { | ||
if (consumer) { | ||
consumer.destroy(); | ||
} | ||
return x; | ||
}, e => { | ||
if (consumer) { | ||
consumer.destroy(); | ||
} | ||
throw e; | ||
}); | ||
} | ||
let consumer = null; | ||
const promise = new SourceMapConsumer(rawSourceMap, sourceMapUrl); | ||
return promise | ||
.then(c => { | ||
consumer = c; | ||
return f(c); | ||
}) | ||
.then(x => { | ||
if (consumer) { | ||
consumer.destroy(); | ||
} | ||
return x; | ||
}, e => { | ||
if (consumer) { | ||
consumer.destroy(); | ||
} | ||
throw e; | ||
}); | ||
}; | ||
/** | ||
* Parse the mappings in a string in to a data structure which we can easily | ||
* query (the ordered arrays in the `this.__generatedMappings` and | ||
* `this.__originalMappings` properties). | ||
*/ | ||
_parseMappings(aStr, aSourceRoot) { | ||
throw new Error("Subclasses must implement _parseMappings"); | ||
} | ||
/** | ||
* Iterate over each mapping between an original source/line/column and a | ||
* generated line/column in this source map. | ||
* | ||
* @param Function aCallback | ||
* The function that is called with each mapping. | ||
* @param Object aContext | ||
* Optional. If specified, this object will be the value of `this` every | ||
* time that `aCallback` is called. | ||
* @param aOrder | ||
* Either `SourceMapConsumer.GENERATED_ORDER` or | ||
* `SourceMapConsumer.ORIGINAL_ORDER`. Specifies whether you want to | ||
* iterate over the mappings sorted by the generated file's line/column | ||
* order or the original's source/line/column order, respectively. Defaults to | ||
* `SourceMapConsumer.GENERATED_ORDER`. | ||
*/ | ||
eachMapping(aCallback, aContext, aOrder) { | ||
throw new Error("Subclasses must implement eachMapping"); | ||
} | ||
/** | ||
* Returns all generated line and column information for the original source, | ||
* line, and column provided. If no column is provided, returns all mappings | ||
* corresponding to a either the line we are searching for or the next | ||
* closest line that has any mappings. Otherwise, returns all mappings | ||
* corresponding to the given line and either the column we are searching for | ||
* or the next closest column that has any offsets. | ||
* | ||
* The only argument is an object with the following properties: | ||
* | ||
* - source: The filename of the original source. | ||
* - line: The line number in the original source. The line number is 1-based. | ||
* - column: Optional. the column number in the original source. | ||
* The column number is 0-based. | ||
* | ||
* and an array of objects is returned, each with the following properties: | ||
* | ||
* - line: The line number in the generated source, or null. The | ||
* line number is 1-based. | ||
* - column: The column number in the generated source, or null. | ||
* The column number is 0-based. | ||
*/ | ||
allGeneratedPositionsFor(aArgs) { | ||
throw new Error("Subclasses must implement allGeneratedPositionsFor"); | ||
} | ||
destroy() { | ||
throw new Error("Subclasses must implement destroy"); | ||
} | ||
} | ||
/** | ||
@@ -97,13 +158,2 @@ * The version of the source mapping spec that we are consuming. | ||
SourceMapConsumer.prototype._version = 3; | ||
/** | ||
* Parse the mappings in a string in to a data structure which we can easily | ||
* query (the ordered arrays in the `this.__generatedMappings` and | ||
* `this.__originalMappings` properties). | ||
*/ | ||
SourceMapConsumer.prototype._parseMappings = | ||
function SourceMapConsumer_parseMappings(aStr, aSourceRoot) { | ||
throw new Error("Subclasses must implement _parseMappings"); | ||
}; | ||
SourceMapConsumer.GENERATED_ORDER = 1; | ||
@@ -115,55 +165,2 @@ SourceMapConsumer.ORIGINAL_ORDER = 2; | ||
/** | ||
* Iterate over each mapping between an original source/line/column and a | ||
* generated line/column in this source map. | ||
* | ||
* @param Function aCallback | ||
* The function that is called with each mapping. | ||
* @param Object aContext | ||
* Optional. If specified, this object will be the value of `this` every | ||
* time that `aCallback` is called. | ||
* @param aOrder | ||
* Either `SourceMapConsumer.GENERATED_ORDER` or | ||
* `SourceMapConsumer.ORIGINAL_ORDER`. Specifies whether you want to | ||
* iterate over the mappings sorted by the generated file's line/column | ||
* order or the original's source/line/column order, respectively. Defaults to | ||
* `SourceMapConsumer.GENERATED_ORDER`. | ||
*/ | ||
SourceMapConsumer.prototype.eachMapping = | ||
function SourceMapConsumer_eachMapping(aCallback, aContext, aOrder) { | ||
throw new Error("Subclasses must implement eachMapping"); | ||
}; | ||
/** | ||
* Returns all generated line and column information for the original source, | ||
* line, and column provided. If no column is provided, returns all mappings | ||
* corresponding to a either the line we are searching for or the next | ||
* closest line that has any mappings. Otherwise, returns all mappings | ||
* corresponding to the given line and either the column we are searching for | ||
* or the next closest column that has any offsets. | ||
* | ||
* The only argument is an object with the following properties: | ||
* | ||
* - source: The filename of the original source. | ||
* - line: The line number in the original source. The line number is 1-based. | ||
* - column: Optional. the column number in the original source. | ||
* The column number is 0-based. | ||
* | ||
* and an array of objects is returned, each with the following properties: | ||
* | ||
* - line: The line number in the generated source, or null. The | ||
* line number is 1-based. | ||
* - column: The column number in the generated source, or null. | ||
* The column number is 0-based. | ||
*/ | ||
SourceMapConsumer.prototype.allGeneratedPositionsFor = | ||
function SourceMapConsumer_allGeneratedPositionsFor(aArgs) { | ||
throw new Error("Subclasses must implement allGeneratedPositionsFor"); | ||
}; | ||
SourceMapConsumer.prototype.destroy = | ||
function SourceMapConsumer_destroy() { | ||
throw new Error("Subclasses must implement destroy"); | ||
}; | ||
exports.SourceMapConsumer = SourceMapConsumer; | ||
@@ -205,143 +202,130 @@ | ||
*/ | ||
function BasicSourceMapConsumer(aSourceMap, aSourceMapURL) { | ||
var sourceMap = aSourceMap; | ||
if (typeof aSourceMap === 'string') { | ||
sourceMap = util.parseSourceMapInput(aSourceMap); | ||
} | ||
class BasicSourceMapConsumer extends SourceMapConsumer { | ||
constructor(aSourceMap, aSourceMapURL) { | ||
return super(INTERNAL).then(that => { | ||
let sourceMap = aSourceMap; | ||
if (typeof aSourceMap === "string") { | ||
sourceMap = util.parseSourceMapInput(aSourceMap); | ||
} | ||
var version = util.getArg(sourceMap, 'version'); | ||
var sources = util.getArg(sourceMap, 'sources'); | ||
// 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); | ||
var sourcesContent = util.getArg(sourceMap, 'sourcesContent', null); | ||
var mappings = util.getArg(sourceMap, 'mappings'); | ||
var file = util.getArg(sourceMap, 'file', null); | ||
const version = util.getArg(sourceMap, "version"); | ||
let sources = util.getArg(sourceMap, "sources"); | ||
// Sass 3.3 leaves out the 'names' array, so we deviate from the spec (which | ||
// requires the array) to play nice here. | ||
const names = util.getArg(sourceMap, "names", []); | ||
let sourceRoot = util.getArg(sourceMap, "sourceRoot", null); | ||
const sourcesContent = util.getArg(sourceMap, "sourcesContent", null); | ||
const mappings = util.getArg(sourceMap, "mappings"); | ||
const file = util.getArg(sourceMap, "file", null); | ||
// 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); | ||
} | ||
// 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 != that._version) { | ||
throw new Error("Unsupported version: " + version); | ||
} | ||
if (sourceRoot) { | ||
sourceRoot = util.normalize(sourceRoot); | ||
} | ||
if (sourceRoot) { | ||
sourceRoot = util.normalize(sourceRoot); | ||
} | ||
sources = sources | ||
.map(String) | ||
// Some source maps produce relative source paths like "./foo.js" instead of | ||
// "foo.js". Normalize these first so that future comparisons will succeed. | ||
// See bugzil.la/1090768. | ||
.map(util.normalize) | ||
// Always ensure that absolute sources are internally stored relative to | ||
// the source root, if the source root is absolute. Not doing this would | ||
// be particularly problematic when the source root is a prefix of the | ||
// source (valid, but why??). See github issue #199 and bugzil.la/1188982. | ||
.map(function (source) { | ||
return sourceRoot && util.isAbsolute(sourceRoot) && util.isAbsolute(source) | ||
? util.relative(sourceRoot, source) | ||
: source; | ||
}); | ||
sources = sources | ||
.map(String) | ||
// Some source maps produce relative source paths like "./foo.js" instead of | ||
// "foo.js". Normalize these first so that future comparisons will succeed. | ||
// See bugzil.la/1090768. | ||
.map(util.normalize) | ||
// Always ensure that absolute sources are internally stored relative to | ||
// the source root, if the source root is absolute. Not doing this would | ||
// be particularly problematic when the source root is a prefix of the | ||
// source (valid, but why??). See github issue #199 and bugzil.la/1188982. | ||
.map(function(source) { | ||
return sourceRoot && util.isAbsolute(sourceRoot) && util.isAbsolute(source) | ||
? util.relative(sourceRoot, source) | ||
: source; | ||
}); | ||
// Pass `true` below to allow duplicate names and sources. While source maps | ||
// are intended to be compressed and deduplicated, the TypeScript compiler | ||
// sometimes generates source maps with duplicates in them. See Github issue | ||
// #72 and bugzil.la/889492. | ||
this._names = ArraySet.fromArray(names.map(String), true); | ||
this._sources = ArraySet.fromArray(sources, true); | ||
// Pass `true` below to allow duplicate names and sources. While source maps | ||
// are intended to be compressed and deduplicated, the TypeScript compiler | ||
// sometimes generates source maps with duplicates in them. See Github issue | ||
// #72 and bugzil.la/889492. | ||
that._names = ArraySet.fromArray(names.map(String), true); | ||
that._sources = ArraySet.fromArray(sources, true); | ||
this._absoluteSources = this._sources.toArray().map(function (s) { | ||
return util.computeSourceURL(sourceRoot, s, aSourceMapURL); | ||
}); | ||
that._absoluteSources = that._sources.toArray().map(function(s) { | ||
return util.computeSourceURL(sourceRoot, s, aSourceMapURL); | ||
}); | ||
this.sourceRoot = sourceRoot; | ||
this.sourcesContent = sourcesContent; | ||
this._mappings = mappings; | ||
this._sourceMapURL = aSourceMapURL; | ||
this.file = file; | ||
that.sourceRoot = sourceRoot; | ||
that.sourcesContent = sourcesContent; | ||
that._mappings = mappings; | ||
that._sourceMapURL = aSourceMapURL; | ||
that.file = file; | ||
this._computedColumnSpans = false; | ||
this._mappingsPtr = 0; | ||
this._wasm = null; | ||
that._computedColumnSpans = false; | ||
that._mappingsPtr = 0; | ||
that._wasm = null; | ||
return wasm().then(wasm => { | ||
this._wasm = wasm; | ||
return this; | ||
}); | ||
} | ||
return wasm().then(w => { | ||
that._wasm = w; | ||
return that; | ||
}); | ||
}); | ||
} | ||
BasicSourceMapConsumer.prototype = Object.create(SourceMapConsumer.prototype); | ||
BasicSourceMapConsumer.prototype.consumer = SourceMapConsumer; | ||
/** | ||
* Utility function to find the index of a source. Returns -1 if not | ||
* found. | ||
*/ | ||
_findSourceIndex(aSource) { | ||
let relativeSource = aSource; | ||
if (this.sourceRoot != null) { | ||
relativeSource = util.relative(this.sourceRoot, relativeSource); | ||
} | ||
/** | ||
* Utility function to find the index of a source. Returns -1 if not | ||
* found. | ||
*/ | ||
BasicSourceMapConsumer.prototype._findSourceIndex = function(aSource) { | ||
var relativeSource = aSource; | ||
if (this.sourceRoot != null) { | ||
relativeSource = util.relative(this.sourceRoot, relativeSource); | ||
} | ||
if (this._sources.has(relativeSource)) { | ||
return this._sources.indexOf(relativeSource); | ||
} | ||
if (this._sources.has(relativeSource)) { | ||
return this._sources.indexOf(relativeSource); | ||
} | ||
// Maybe aSource is an absolute URL as returned by |sources|. In | ||
// this case we can't simply undo the transform. | ||
for (let i = 0; i < this._absoluteSources.length; ++i) { | ||
if (this._absoluteSources[i] == aSource) { | ||
return i; | ||
} | ||
} | ||
// Maybe aSource is an absolute URL as returned by |sources|. In | ||
// this case we can't simply undo the transform. | ||
var i; | ||
for (i = 0; i < this._absoluteSources.length; ++i) { | ||
if (this._absoluteSources[i] == aSource) { | ||
return i; | ||
} | ||
return -1; | ||
} | ||
return -1; | ||
}; | ||
/** | ||
* Create a BasicSourceMapConsumer from a SourceMapGenerator. | ||
* | ||
* @param SourceMapGenerator aSourceMap | ||
* The source map that will be consumed. | ||
* @param String aSourceMapURL | ||
* The URL at which the source map can be found (optional) | ||
* @returns BasicSourceMapConsumer | ||
*/ | ||
BasicSourceMapConsumer.fromSourceMap = | ||
function SourceMapConsumer_fromSourceMap(aSourceMap, aSourceMapURL) { | ||
/** | ||
* Create a BasicSourceMapConsumer from a SourceMapGenerator. | ||
* | ||
* @param SourceMapGenerator aSourceMap | ||
* The source map that will be consumed. | ||
* @param String aSourceMapURL | ||
* The URL at which the source map can be found (optional) | ||
* @returns BasicSourceMapConsumer | ||
*/ | ||
static fromSourceMap(aSourceMap, aSourceMapURL) { | ||
return new BasicSourceMapConsumer(aSourceMap.toString()); | ||
}; | ||
} | ||
/** | ||
* The version of the source mapping spec that we are consuming. | ||
*/ | ||
BasicSourceMapConsumer.prototype._version = 3; | ||
/** | ||
* The list of original sources. | ||
*/ | ||
Object.defineProperty(BasicSourceMapConsumer.prototype, 'sources', { | ||
get: function () { | ||
get sources() { | ||
return this._absoluteSources.slice(); | ||
} | ||
}); | ||
BasicSourceMapConsumer.prototype._getMappingsPtr = function () { | ||
if (this._mappingsPtr === 0) { | ||
this._parseMappings(this._mappings, this.sourceRoot); | ||
_getMappingsPtr() { | ||
if (this._mappingsPtr === 0) { | ||
this._parseMappings(this._mappings, this.sourceRoot); | ||
} | ||
return this._mappingsPtr; | ||
} | ||
return this._mappingsPtr; | ||
}; | ||
/** | ||
* Parse the mappings in a string in to a data structure which we can easily | ||
* query (the ordered arrays in the `this.__generatedMappings` and | ||
* `this.__originalMappings` properties). | ||
*/ | ||
BasicSourceMapConsumer.prototype._parseMappings = | ||
function BasicSourceMapConsumer_parseMappings(aStr, aSourceRoot) { | ||
/** | ||
* Parse the mappings in a string in to a data structure which we can easily | ||
* query (the ordered arrays in the `this.__generatedMappings` and | ||
* `this.__originalMappings` properties). | ||
*/ | ||
_parseMappings(aStr, aSourceRoot) { | ||
const size = aStr.length; | ||
@@ -351,3 +335,3 @@ | ||
const mappingsBuf = new Uint8Array(this._wasm.exports.memory.buffer, mappingsBufPtr, size); | ||
for (var i = 0; i < size; i++) { | ||
for (let i = 0; i < size; i++) { | ||
mappingsBuf[i] = aStr.charCodeAt(i); | ||
@@ -375,3 +359,3 @@ } | ||
msg += "invalid base 64 character while parsing a VLQ"; | ||
break | ||
break; | ||
default: | ||
@@ -386,9 +370,8 @@ msg += "unknown error code"; | ||
this._mappingsPtr = mappingsPtr; | ||
}; | ||
} | ||
BasicSourceMapConsumer.prototype.eachMapping = | ||
function BasicSourceMapConsumer_eachMapping(aCallback, aContext, aOrder) { | ||
var context = aContext || null; | ||
var order = aOrder || SourceMapConsumer.GENERATED_ORDER; | ||
var sourceRoot = this.sourceRoot; | ||
eachMapping(aCallback, aContext, aOrder) { | ||
const context = aContext || null; | ||
const order = aOrder || SourceMapConsumer.GENERATED_ORDER; | ||
const sourceRoot = this.sourceRoot; | ||
@@ -421,9 +404,8 @@ this._wasm.withMappingCallback( | ||
); | ||
}; | ||
} | ||
BasicSourceMapConsumer.prototype.allGeneratedPositionsFor = | ||
function BasicSourceMapConsumer_allGeneratedPositionsFor(aArgs) { | ||
var source = util.getArg(aArgs, 'source'); | ||
var originalLine = util.getArg(aArgs, 'line'); | ||
var originalColumn = aArgs.column || 0; | ||
allGeneratedPositionsFor(aArgs) { | ||
let source = util.getArg(aArgs, "source"); | ||
const originalLine = util.getArg(aArgs, "line"); | ||
const originalColumn = aArgs.column || 0; | ||
@@ -443,3 +425,3 @@ source = this._findSourceIndex(source); | ||
var mappings = []; | ||
const mappings = []; | ||
@@ -462,3 +444,3 @@ this._wasm.withMappingCallback( | ||
originalLine - 1, | ||
'column' in aArgs, | ||
"column" in aArgs, | ||
originalColumn | ||
@@ -470,6 +452,5 @@ ); | ||
return mappings; | ||
}; | ||
} | ||
BasicSourceMapConsumer.prototype.destroy = | ||
function BasicSourceMapConsumer_destroy() { | ||
destroy() { | ||
if (this._mappingsPtr !== 0) { | ||
@@ -479,10 +460,9 @@ this._wasm.exports.free_mappings(this._mappingsPtr); | ||
} | ||
}; | ||
} | ||
/** | ||
* Compute the last column for each generated mapping. The last column is | ||
* inclusive. | ||
*/ | ||
BasicSourceMapConsumer.prototype.computeColumnSpans = | ||
function SourceMapConsumer_computeColumnSpans() { | ||
/** | ||
* Compute the last column for each generated mapping. The last column is | ||
* inclusive. | ||
*/ | ||
computeColumnSpans() { | ||
if (this._computedColumnSpans) { | ||
@@ -494,33 +474,32 @@ return; | ||
this._computedColumnSpans = true; | ||
}; | ||
} | ||
/** | ||
* Returns the original source, line, and column information for the generated | ||
* source's line and column positions provided. The only argument is an object | ||
* with the following properties: | ||
* | ||
* - line: The line number in the generated source. The line number | ||
* is 1-based. | ||
* - column: The column number in the generated source. The column | ||
* number is 0-based. | ||
* - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or | ||
* 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the | ||
* closest element that is smaller than or greater than the one we are | ||
* searching for, respectively, if the exact element cannot be found. | ||
* Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'. | ||
* | ||
* and an object is returned with the following properties: | ||
* | ||
* - source: The original source file, or null. | ||
* - line: The line number in the original source, or null. The | ||
* line number is 1-based. | ||
* - column: The column number in the original source, or null. The | ||
* column number is 0-based. | ||
* - name: The original identifier, or null. | ||
*/ | ||
BasicSourceMapConsumer.prototype.originalPositionFor = | ||
function SourceMapConsumer_originalPositionFor(aArgs) { | ||
var needle = { | ||
generatedLine: util.getArg(aArgs, 'line'), | ||
generatedColumn: util.getArg(aArgs, 'column') | ||
/** | ||
* Returns the original source, line, and column information for the generated | ||
* source's line and column positions provided. The only argument is an object | ||
* with the following properties: | ||
* | ||
* - line: The line number in the generated source. The line number | ||
* is 1-based. | ||
* - column: The column number in the generated source. The column | ||
* number is 0-based. | ||
* - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or | ||
* 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the | ||
* closest element that is smaller than or greater than the one we are | ||
* searching for, respectively, if the exact element cannot be found. | ||
* Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'. | ||
* | ||
* and an object is returned with the following properties: | ||
* | ||
* - source: The original source file, or null. | ||
* - line: The line number in the original source, or null. The | ||
* line number is 1-based. | ||
* - column: The column number in the original source, or null. The | ||
* column number is 0-based. | ||
* - name: The original identifier, or null. | ||
*/ | ||
originalPositionFor(aArgs) { | ||
const needle = { | ||
generatedLine: util.getArg(aArgs, "line"), | ||
generatedColumn: util.getArg(aArgs, "column") | ||
}; | ||
@@ -536,3 +515,3 @@ | ||
var bias = util.getArg(aArgs, 'bias', SourceMapConsumer.GREATEST_LOWER_BOUND); | ||
let bias = util.getArg(aArgs, "bias", SourceMapConsumer.GREATEST_LOWER_BOUND); | ||
if (bias == null) { | ||
@@ -542,3 +521,3 @@ bias = SourceMapConsumer.GREATEST_LOWER_BOUND; | ||
var mapping; | ||
let mapping; | ||
this._wasm.withMappingCallback(m => mapping = m, () => { | ||
@@ -555,3 +534,3 @@ this._wasm.exports.original_location_for( | ||
if (mapping.generatedLine === needle.generatedLine) { | ||
var source = util.getArg(mapping, 'source', null); | ||
let source = util.getArg(mapping, "source", null); | ||
if (source !== null) { | ||
@@ -562,3 +541,3 @@ source = this._sources.at(source); | ||
var name = util.getArg(mapping, 'name', null); | ||
let name = util.getArg(mapping, "name", null); | ||
if (name !== null) { | ||
@@ -569,6 +548,6 @@ name = this._names.at(name); | ||
return { | ||
source: source, | ||
line: util.getArg(mapping, 'originalLine', null), | ||
column: util.getArg(mapping, 'originalColumn', null), | ||
name: name | ||
source, | ||
line: util.getArg(mapping, "originalLine", null), | ||
column: util.getArg(mapping, "originalColumn", null), | ||
name | ||
}; | ||
@@ -584,10 +563,9 @@ } | ||
}; | ||
}; | ||
} | ||
/** | ||
* Return true if we have the source content for every source in the source | ||
* map, false otherwise. | ||
*/ | ||
BasicSourceMapConsumer.prototype.hasContentsOfAllSources = | ||
function BasicSourceMapConsumer_hasContentsOfAllSources() { | ||
/** | ||
* Return true if we have the source content for every source in the source | ||
* map, false otherwise. | ||
*/ | ||
hasContentsOfAllSources() { | ||
if (!this.sourcesContent) { | ||
@@ -597,12 +575,11 @@ return false; | ||
return this.sourcesContent.length >= this._sources.size() && | ||
!this.sourcesContent.some(function (sc) { return sc == null; }); | ||
}; | ||
!this.sourcesContent.some(function(sc) { return sc == null; }); | ||
} | ||
/** | ||
* Returns the original source content. The only argument is the url of the | ||
* original source file. Returns null if no original source content is | ||
* available. | ||
*/ | ||
BasicSourceMapConsumer.prototype.sourceContentFor = | ||
function SourceMapConsumer_sourceContentFor(aSource, nullOnMissing) { | ||
/** | ||
* Returns the original source content. The only argument is the url of the | ||
* original source file. Returns null if no original source content is | ||
* available. | ||
*/ | ||
sourceContentFor(aSource, nullOnMissing) { | ||
if (!this.sourcesContent) { | ||
@@ -612,3 +589,3 @@ return null; | ||
var index = this._findSourceIndex(aSource); | ||
const index = this._findSourceIndex(aSource); | ||
if (index >= 0) { | ||
@@ -618,3 +595,3 @@ return this.sourcesContent[index]; | ||
var relativeSource = aSource; | ||
let relativeSource = aSource; | ||
if (this.sourceRoot != null) { | ||
@@ -624,3 +601,3 @@ relativeSource = util.relative(this.sourceRoot, relativeSource); | ||
var url; | ||
let url; | ||
if (this.sourceRoot != null | ||
@@ -632,6 +609,6 @@ && (url = util.urlParse(this.sourceRoot))) { | ||
// https://bugzilla.mozilla.org/show_bug.cgi?id=885597. | ||
var fileUriAbsPath = relativeSource.replace(/^file:\/\//, ""); | ||
const fileUriAbsPath = relativeSource.replace(/^file:\/\//, ""); | ||
if (url.scheme == "file" | ||
&& this._sources.has(fileUriAbsPath)) { | ||
return this.sourcesContent[this._sources.indexOf(fileUriAbsPath)] | ||
return this.sourcesContent[this._sources.indexOf(fileUriAbsPath)]; | ||
} | ||
@@ -652,33 +629,31 @@ | ||
} | ||
else { | ||
throw new Error('"' + relativeSource + '" is not in the SourceMap.'); | ||
} | ||
}; | ||
/** | ||
* Returns the generated line and column information for the original source, | ||
* line, and column positions provided. The only argument is an object with | ||
* the following properties: | ||
* | ||
* - source: The filename of the original source. | ||
* - line: The line number in the original source. The line number | ||
* is 1-based. | ||
* - column: The column number in the original source. The column | ||
* number is 0-based. | ||
* - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or | ||
* 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the | ||
* closest element that is smaller than or greater than the one we are | ||
* searching for, respectively, if the exact element cannot be found. | ||
* Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'. | ||
* | ||
* and an object is returned with the following properties: | ||
* | ||
* - line: The line number in the generated source, or null. The | ||
* line number is 1-based. | ||
* - column: The column number in the generated source, or null. | ||
* The column number is 0-based. | ||
*/ | ||
BasicSourceMapConsumer.prototype.generatedPositionFor = | ||
function SourceMapConsumer_generatedPositionFor(aArgs) { | ||
var source = util.getArg(aArgs, 'source'); | ||
throw new Error('"' + relativeSource + '" is not in the SourceMap.'); | ||
} | ||
/** | ||
* Returns the generated line and column information for the original source, | ||
* line, and column positions provided. The only argument is an object with | ||
* the following properties: | ||
* | ||
* - source: The filename of the original source. | ||
* - line: The line number in the original source. The line number | ||
* is 1-based. | ||
* - column: The column number in the original source. The column | ||
* number is 0-based. | ||
* - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or | ||
* 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the | ||
* closest element that is smaller than or greater than the one we are | ||
* searching for, respectively, if the exact element cannot be found. | ||
* Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'. | ||
* | ||
* and an object is returned with the following properties: | ||
* | ||
* - line: The line number in the generated source, or null. The | ||
* line number is 1-based. | ||
* - column: The column number in the generated source, or null. | ||
* The column number is 0-based. | ||
*/ | ||
generatedPositionFor(aArgs) { | ||
let source = util.getArg(aArgs, "source"); | ||
source = this._findSourceIndex(source); | ||
@@ -693,6 +668,6 @@ if (source < 0) { | ||
var needle = { | ||
source: source, | ||
originalLine: util.getArg(aArgs, 'line'), | ||
originalColumn: util.getArg(aArgs, 'column') | ||
const needle = { | ||
source, | ||
originalLine: util.getArg(aArgs, "line"), | ||
originalColumn: util.getArg(aArgs, "column") | ||
}; | ||
@@ -708,3 +683,3 @@ | ||
var bias = util.getArg(aArgs, 'bias', SourceMapConsumer.GREATEST_LOWER_BOUND); | ||
let bias = util.getArg(aArgs, "bias", SourceMapConsumer.GREATEST_LOWER_BOUND); | ||
if (bias == null) { | ||
@@ -714,3 +689,3 @@ bias = SourceMapConsumer.GREATEST_LOWER_BOUND; | ||
var mapping; | ||
let mapping; | ||
this._wasm.withMappingCallback(m => mapping = m, () => { | ||
@@ -733,4 +708,4 @@ this._wasm.exports.generated_location_for( | ||
return { | ||
line: util.getArg(mapping, 'generatedLine', null), | ||
column: util.getArg(mapping, 'generatedColumn', null), | ||
line: util.getArg(mapping, "generatedLine", null), | ||
column: util.getArg(mapping, "generatedColumn", null), | ||
lastColumn, | ||
@@ -746,4 +721,6 @@ }; | ||
}; | ||
}; | ||
} | ||
} | ||
BasicSourceMapConsumer.prototype.consumer = SourceMapConsumer; | ||
exports.BasicSourceMapConsumer = BasicSourceMapConsumer; | ||
@@ -800,94 +777,93 @@ | ||
*/ | ||
function IndexedSourceMapConsumer(aSourceMap, aSourceMapURL) { | ||
var sourceMap = aSourceMap; | ||
if (typeof aSourceMap === 'string') { | ||
sourceMap = util.parseSourceMapInput(aSourceMap); | ||
} | ||
class IndexedSourceMapConsumer extends SourceMapConsumer { | ||
constructor(aSourceMap, aSourceMapURL) { | ||
return super(INTERNAL).then(that => { | ||
let sourceMap = aSourceMap; | ||
if (typeof aSourceMap === "string") { | ||
sourceMap = util.parseSourceMapInput(aSourceMap); | ||
} | ||
var version = util.getArg(sourceMap, 'version'); | ||
var sections = util.getArg(sourceMap, 'sections'); | ||
const version = util.getArg(sourceMap, "version"); | ||
const sections = util.getArg(sourceMap, "sections"); | ||
if (version != this._version) { | ||
throw new Error('Unsupported version: ' + version); | ||
} | ||
if (version != that._version) { | ||
throw new Error("Unsupported version: " + version); | ||
} | ||
this._sources = new ArraySet(); | ||
this._names = new ArraySet(); | ||
that._sources = new ArraySet(); | ||
that._names = new ArraySet(); | ||
that.__generatedMappings = null; | ||
that.__originalMappings = null; | ||
that.__generatedMappingsUnsorted = null; | ||
that.__originalMappingsUnsorted = null; | ||
var lastOffset = { | ||
line: -1, | ||
column: 0 | ||
}; | ||
return Promise.all(sections.map(s => { | ||
if (s.url) { | ||
// The url field will require support for asynchronicity. | ||
// See https://github.com/mozilla/source-map/issues/16 | ||
throw new Error('Support for url field in sections not implemented.'); | ||
} | ||
var offset = util.getArg(s, 'offset'); | ||
var offsetLine = util.getArg(offset, 'line'); | ||
var offsetColumn = util.getArg(offset, 'column'); | ||
let lastOffset = { | ||
line: -1, | ||
column: 0 | ||
}; | ||
return Promise.all(sections.map(s => { | ||
if (s.url) { | ||
// The url field will require support for asynchronicity. | ||
// See https://github.com/mozilla/source-map/issues/16 | ||
throw new Error("Support for url field in sections not implemented."); | ||
} | ||
const offset = util.getArg(s, "offset"); | ||
const offsetLine = util.getArg(offset, "line"); | ||
const offsetColumn = util.getArg(offset, "column"); | ||
if (offsetLine < lastOffset.line || | ||
(offsetLine === lastOffset.line && offsetColumn < lastOffset.column)) { | ||
throw new Error('Section offsets must be ordered and non-overlapping.'); | ||
} | ||
lastOffset = offset; | ||
if (offsetLine < lastOffset.line || | ||
(offsetLine === lastOffset.line && offsetColumn < lastOffset.column)) { | ||
throw new Error("Section offsets must be ordered and non-overlapping."); | ||
} | ||
lastOffset = offset; | ||
const consumer = new SourceMapConsumer(util.getArg(s, 'map'), aSourceMapURL); | ||
return consumer.then(consumer => { | ||
return { | ||
generatedOffset: { | ||
// The offset fields are 0-based, but we use 1-based indices when | ||
// encoding/decoding from VLQ. | ||
generatedLine: offsetLine + 1, | ||
generatedColumn: offsetColumn + 1 | ||
}, | ||
consumer: consumer | ||
}; | ||
const cons = new SourceMapConsumer(util.getArg(s, "map"), aSourceMapURL); | ||
return cons.then(consumer => { | ||
return { | ||
generatedOffset: { | ||
// The offset fields are 0-based, but we use 1-based indices when | ||
// encoding/decoding from VLQ. | ||
generatedLine: offsetLine + 1, | ||
generatedColumn: offsetColumn + 1 | ||
}, | ||
consumer | ||
}; | ||
}); | ||
})).then(s => { | ||
that._sections = s; | ||
return that; | ||
}); | ||
}); | ||
})).then(sections => { | ||
this._sections = sections; | ||
return this; | ||
}); | ||
} | ||
} | ||
IndexedSourceMapConsumer.prototype = Object.create(SourceMapConsumer.prototype); | ||
IndexedSourceMapConsumer.prototype.constructor = SourceMapConsumer; | ||
// `__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. | ||
IndexedSourceMapConsumer.prototype.__generatedMappings = null; | ||
Object.defineProperty(IndexedSourceMapConsumer.prototype, '_generatedMappings', { | ||
configurable: true, | ||
enumerable: true, | ||
get: function () { | ||
// `__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. | ||
get _generatedMappings() { | ||
if (!this.__generatedMappings) { | ||
@@ -899,9 +875,4 @@ this._sortGeneratedMappings(); | ||
} | ||
}); | ||
IndexedSourceMapConsumer.prototype.__originalMappings = null; | ||
Object.defineProperty(IndexedSourceMapConsumer.prototype, '_originalMappings', { | ||
configurable: true, | ||
enumerable: true, | ||
get: function () { | ||
get _originalMappings() { | ||
if (!this.__originalMappings) { | ||
@@ -913,9 +884,4 @@ this._sortOriginalMappings(); | ||
} | ||
}); | ||
IndexedSourceMapConsumer.prototype.__generatedMappingsUnsorted = null; | ||
Object.defineProperty(IndexedSourceMapConsumer.prototype, '_generatedMappingsUnsorted', { | ||
configurable: true, | ||
enumerable: true, | ||
get: function () { | ||
get _generatedMappingsUnsorted() { | ||
if (!this.__generatedMappingsUnsorted) { | ||
@@ -927,9 +893,4 @@ this._parseMappings(this._mappings, this.sourceRoot); | ||
} | ||
}); | ||
IndexedSourceMapConsumer.prototype.__originalMappingsUnsorted = null; | ||
Object.defineProperty(IndexedSourceMapConsumer.prototype, '_originalMappingsUnsorted', { | ||
configurable: true, | ||
enumerable: true, | ||
get: function () { | ||
get _originalMappingsUnsorted() { | ||
if (!this.__originalMappingsUnsorted) { | ||
@@ -941,31 +902,22 @@ this._parseMappings(this._mappings, this.sourceRoot); | ||
} | ||
}); | ||
IndexedSourceMapConsumer.prototype._sortGeneratedMappings = | ||
function IndexedSourceMapConsumer_sortGeneratedMappings() { | ||
_sortGeneratedMappings() { | ||
const mappings = this._generatedMappingsUnsorted; | ||
mappings.sort(util.compareByGeneratedPositionsDeflated); | ||
this.__generatedMappings = mappings; | ||
}; | ||
} | ||
IndexedSourceMapConsumer.prototype._sortOriginalMappings = | ||
function IndexedSourceMapConsumer_sortOriginalMappings() { | ||
_sortOriginalMappings() { | ||
const mappings = this._originalMappingsUnsorted; | ||
mappings.sort(util.compareByOriginalPositions); | ||
this.__originalMappings = mappings; | ||
}; | ||
} | ||
/** | ||
* The version of the source mapping spec that we are consuming. | ||
*/ | ||
IndexedSourceMapConsumer.prototype._version = 3; | ||
/** | ||
* The list of original sources. | ||
*/ | ||
Object.defineProperty(IndexedSourceMapConsumer.prototype, 'sources', { | ||
get: function () { | ||
var sources = []; | ||
for (var i = 0; i < this._sections.length; i++) { | ||
for (var j = 0; j < this._sections[i].consumer.sources.length; j++) { | ||
/** | ||
* The list of original sources. | ||
*/ | ||
get sources() { | ||
const sources = []; | ||
for (let i = 0; i < this._sections.length; i++) { | ||
for (let j = 0; j < this._sections[i].consumer.sources.length; j++) { | ||
sources.push(this._sections[i].consumer.sources[j]); | ||
@@ -976,28 +928,26 @@ } | ||
} | ||
}); | ||
/** | ||
* Returns the original source, line, and column information for the generated | ||
* source's line and column positions provided. The only argument is an object | ||
* with the following properties: | ||
* | ||
* - line: The line number in the generated source. The line number | ||
* is 1-based. | ||
* - column: The column number in the generated source. The column | ||
* number is 0-based. | ||
* | ||
* and an object is returned with the following properties: | ||
* | ||
* - source: The original source file, or null. | ||
* - line: The line number in the original source, or null. The | ||
* line number is 1-based. | ||
* - column: The column number in the original source, or null. The | ||
* column number is 0-based. | ||
* - name: The original identifier, or null. | ||
*/ | ||
IndexedSourceMapConsumer.prototype.originalPositionFor = | ||
function IndexedSourceMapConsumer_originalPositionFor(aArgs) { | ||
var needle = { | ||
generatedLine: util.getArg(aArgs, 'line'), | ||
generatedColumn: util.getArg(aArgs, 'column') | ||
/** | ||
* Returns the original source, line, and column information for the generated | ||
* source's line and column positions provided. The only argument is an object | ||
* with the following properties: | ||
* | ||
* - line: The line number in the generated source. The line number | ||
* is 1-based. | ||
* - column: The column number in the generated source. The column | ||
* number is 0-based. | ||
* | ||
* and an object is returned with the following properties: | ||
* | ||
* - source: The original source file, or null. | ||
* - line: The line number in the original source, or null. The | ||
* line number is 1-based. | ||
* - column: The column number in the original source, or null. The | ||
* column number is 0-based. | ||
* - name: The original identifier, or null. | ||
*/ | ||
originalPositionFor(aArgs) { | ||
const needle = { | ||
generatedLine: util.getArg(aArgs, "line"), | ||
generatedColumn: util.getArg(aArgs, "column") | ||
}; | ||
@@ -1007,5 +957,5 @@ | ||
// to an original position. | ||
var sectionIndex = binarySearch.search(needle, this._sections, | ||
function(needle, section) { | ||
var cmp = needle.generatedLine - section.generatedOffset.generatedLine; | ||
const sectionIndex = binarySearch.search(needle, this._sections, | ||
function(aNeedle, section) { | ||
const cmp = aNeedle.generatedLine - section.generatedOffset.generatedLine; | ||
if (cmp) { | ||
@@ -1015,6 +965,6 @@ return cmp; | ||
return (needle.generatedColumn - | ||
return (aNeedle.generatedColumn - | ||
section.generatedOffset.generatedColumn); | ||
}); | ||
var section = this._sections[sectionIndex]; | ||
const section = this._sections[sectionIndex]; | ||
@@ -1039,26 +989,24 @@ if (!section) { | ||
}); | ||
}; | ||
} | ||
/** | ||
* Return true if we have the source content for every source in the source | ||
* map, false otherwise. | ||
*/ | ||
IndexedSourceMapConsumer.prototype.hasContentsOfAllSources = | ||
function IndexedSourceMapConsumer_hasContentsOfAllSources() { | ||
return this._sections.every(function (s) { | ||
/** | ||
* Return true if we have the source content for every source in the source | ||
* map, false otherwise. | ||
*/ | ||
hasContentsOfAllSources() { | ||
return this._sections.every(function(s) { | ||
return s.consumer.hasContentsOfAllSources(); | ||
}); | ||
}; | ||
} | ||
/** | ||
* Returns the original source content. The only argument is the url of the | ||
* original source file. Returns null if no original source content is | ||
* available. | ||
*/ | ||
IndexedSourceMapConsumer.prototype.sourceContentFor = | ||
function IndexedSourceMapConsumer_sourceContentFor(aSource, nullOnMissing) { | ||
for (var i = 0; i < this._sections.length; i++) { | ||
var section = this._sections[i]; | ||
/** | ||
* Returns the original source content. The only argument is the url of the | ||
* original source file. Returns null if no original source content is | ||
* available. | ||
*/ | ||
sourceContentFor(aSource, nullOnMissing) { | ||
for (let i = 0; i < this._sections.length; i++) { | ||
const section = this._sections[i]; | ||
var content = section.consumer.sourceContentFor(aSource, true); | ||
const content = section.consumer.sourceContentFor(aSource, true); | ||
if (content) { | ||
@@ -1071,38 +1019,35 @@ return content; | ||
} | ||
else { | ||
throw new Error('"' + aSource + '" is not in the SourceMap.'); | ||
} | ||
}; | ||
throw new Error('"' + aSource + '" is not in the SourceMap.'); | ||
} | ||
/** | ||
* Returns the generated line and column information for the original source, | ||
* line, and column positions provided. The only argument is an object with | ||
* the following properties: | ||
* | ||
* - source: The filename of the original source. | ||
* - line: The line number in the original source. The line number | ||
* is 1-based. | ||
* - column: The column number in the original source. The column | ||
* number is 0-based. | ||
* | ||
* and an object is returned with the following properties: | ||
* | ||
* - line: The line number in the generated source, or null. The | ||
* line number is 1-based. | ||
* - column: The column number in the generated source, or null. | ||
* The column number is 0-based. | ||
*/ | ||
IndexedSourceMapConsumer.prototype.generatedPositionFor = | ||
function IndexedSourceMapConsumer_generatedPositionFor(aArgs) { | ||
for (var i = 0; i < this._sections.length; i++) { | ||
var section = this._sections[i]; | ||
/** | ||
* Returns the generated line and column information for the original source, | ||
* line, and column positions provided. The only argument is an object with | ||
* the following properties: | ||
* | ||
* - source: The filename of the original source. | ||
* - line: The line number in the original source. The line number | ||
* is 1-based. | ||
* - column: The column number in the original source. The column | ||
* number is 0-based. | ||
* | ||
* and an object is returned with the following properties: | ||
* | ||
* - line: The line number in the generated source, or null. The | ||
* line number is 1-based. | ||
* - column: The column number in the generated source, or null. | ||
* The column number is 0-based. | ||
*/ | ||
generatedPositionFor(aArgs) { | ||
for (let i = 0; i < this._sections.length; i++) { | ||
const section = this._sections[i]; | ||
// Only consider this section if the requested source is in the list of | ||
// sources of the consumer. | ||
if (section.consumer._findSourceIndex(util.getArg(aArgs, 'source')) === -1) { | ||
if (section.consumer._findSourceIndex(util.getArg(aArgs, "source")) === -1) { | ||
continue; | ||
} | ||
var generatedPosition = section.consumer.generatedPositionFor(aArgs); | ||
const generatedPosition = section.consumer.generatedPositionFor(aArgs); | ||
if (generatedPosition) { | ||
var ret = { | ||
const ret = { | ||
line: generatedPosition.line + | ||
@@ -1123,27 +1068,30 @@ (section.generatedOffset.generatedLine - 1), | ||
}; | ||
}; | ||
} | ||
/** | ||
* Parse the mappings in a string in to a data structure which we can easily | ||
* query (the ordered arrays in the `this.__generatedMappings` and | ||
* `this.__originalMappings` properties). | ||
*/ | ||
IndexedSourceMapConsumer.prototype._parseMappings = | ||
function IndexedSourceMapConsumer_parseMappings(aStr, aSourceRoot) { | ||
/** | ||
* Parse the mappings in a string in to a data structure which we can easily | ||
* query (the ordered arrays in the `this.__generatedMappings` and | ||
* `this.__originalMappings` properties). | ||
*/ | ||
_parseMappings(aStr, aSourceRoot) { | ||
const generatedMappings = this.__generatedMappingsUnsorted = []; | ||
const originalMappings = this.__originalMappingsUnsorted = []; | ||
for (var i = 0; i < this._sections.length; i++) { | ||
var section = this._sections[i]; | ||
for (let i = 0; i < this._sections.length; i++) { | ||
const section = this._sections[i]; | ||
var sectionMappings = []; | ||
const sectionMappings = []; | ||
section.consumer.eachMapping(m => sectionMappings.push(m)); | ||
for (var j = 0; j < sectionMappings.length; j++) { | ||
var mapping = sectionMappings[j]; | ||
for (let j = 0; j < sectionMappings.length; j++) { | ||
const mapping = sectionMappings[j]; | ||
var source = util.computeSourceURL(section.consumer.sourceRoot, source, this._sourceMapURL); | ||
// TODO: test if null is correct here. The original code used | ||
// `source`, which would actually have gotten used as null because | ||
// var's get hoisted. | ||
// See: https://github.com/mozilla/source-map/issues/333 | ||
let source = util.computeSourceURL(section.consumer.sourceRoot, null, this._sourceMapURL); | ||
this._sources.add(source); | ||
source = this._sources.indexOf(source); | ||
var name = null; | ||
let name = null; | ||
if (mapping.name) { | ||
@@ -1158,4 +1106,4 @@ this._names.add(mapping.name); | ||
// generated file. | ||
var adjustedMapping = { | ||
source: source, | ||
const adjustedMapping = { | ||
source, | ||
generatedLine: mapping.generatedLine + | ||
@@ -1169,7 +1117,7 @@ (section.generatedOffset.generatedLine - 1), | ||
originalColumn: mapping.originalColumn, | ||
name: name | ||
name | ||
}; | ||
generatedMappings.push(adjustedMapping); | ||
if (typeof adjustedMapping.originalLine === 'number') { | ||
if (typeof adjustedMapping.originalLine === "number") { | ||
originalMappings.push(adjustedMapping); | ||
@@ -1179,10 +1127,9 @@ } | ||
} | ||
}; | ||
} | ||
IndexedSourceMapConsumer.prototype.eachMapping = | ||
function IndexedSourceMapConsumer_eachMapping(aCallback, aContext, aOrder) { | ||
var context = aContext || null; | ||
var order = aOrder || SourceMapConsumer.GENERATED_ORDER; | ||
eachMapping(aCallback, aContext, aOrder) { | ||
const context = aContext || null; | ||
const order = aOrder || SourceMapConsumer.GENERATED_ORDER; | ||
var mappings; | ||
let mappings; | ||
switch (order) { | ||
@@ -1199,5 +1146,5 @@ case SourceMapConsumer.GENERATED_ORDER: | ||
var sourceRoot = this.sourceRoot; | ||
mappings.map(function (mapping) { | ||
var source = null; | ||
const sourceRoot = this.sourceRoot; | ||
mappings.map(function(mapping) { | ||
let source = null; | ||
if (mapping.source !== null) { | ||
@@ -1208,3 +1155,3 @@ source = this._sources.at(mapping.source); | ||
return { | ||
source: source, | ||
source, | ||
generatedLine: mapping.generatedLine, | ||
@@ -1217,11 +1164,10 @@ generatedColumn: mapping.generatedColumn, | ||
}, this).forEach(aCallback, context); | ||
}; | ||
} | ||
/** | ||
* Find the mapping that best matches the hypothetical "needle" mapping that | ||
* we are searching for in the given "haystack" of mappings. | ||
*/ | ||
IndexedSourceMapConsumer.prototype._findMapping = | ||
function IndexedSourceMapConsumer_findMapping(aNeedle, aMappings, aLineName, | ||
aColumnName, aComparator, aBias) { | ||
/** | ||
* Find the mapping that best matches the hypothetical "needle" mapping that | ||
* we are searching for in the given "haystack" of mappings. | ||
*/ | ||
_findMapping(aNeedle, aMappings, aLineName, | ||
aColumnName, aComparator, aBias) { | ||
// To return the position we are searching for, we must first find the | ||
@@ -1233,7 +1179,7 @@ // mapping for the given position and then return the opposite position it | ||
if (aNeedle[aLineName] <= 0) { | ||
throw new TypeError('Line must be greater than or equal to 1, got ' | ||
throw new TypeError("Line must be greater than or equal to 1, got " | ||
+ aNeedle[aLineName]); | ||
} | ||
if (aNeedle[aColumnName] < 0) { | ||
throw new TypeError('Column must be greater than or equal to 0, got ' | ||
throw new TypeError("Column must be greater than or equal to 0, got " | ||
+ aNeedle[aColumnName]); | ||
@@ -1243,7 +1189,6 @@ } | ||
return binarySearch.search(aNeedle, aMappings, aComparator, aBias); | ||
}; | ||
} | ||
IndexedSourceMapConsumer.prototype.allGeneratedPositionsFor = | ||
function IndexedSourceMapConsumer_allGeneratedPositionsFor(aArgs) { | ||
var line = util.getArg(aArgs, 'line'); | ||
allGeneratedPositionsFor(aArgs) { | ||
const line = util.getArg(aArgs, "line"); | ||
@@ -1254,6 +1199,6 @@ // When there is no exact match, BasicSourceMapConsumer.prototype._findMapping | ||
// the given line, provided such a mapping exists. | ||
var needle = { | ||
source: util.getArg(aArgs, 'source'), | ||
const needle = { | ||
source: util.getArg(aArgs, "source"), | ||
originalLine: line, | ||
originalColumn: util.getArg(aArgs, 'column', 0) | ||
originalColumn: util.getArg(aArgs, "column", 0) | ||
}; | ||
@@ -1274,5 +1219,5 @@ | ||
var mappings = []; | ||
const mappings = []; | ||
var index = this._findMapping(needle, | ||
let index = this._findMapping(needle, | ||
this._originalMappings, | ||
@@ -1284,6 +1229,6 @@ "originalLine", | ||
if (index >= 0) { | ||
var mapping = this._originalMappings[index]; | ||
let mapping = this._originalMappings[index]; | ||
if (aArgs.column === undefined) { | ||
var originalLine = mapping.originalLine; | ||
const originalLine = mapping.originalLine; | ||
@@ -1300,4 +1245,4 @@ // Iterate until either we run out of mappings, or we run into | ||
mappings.push({ | ||
line: util.getArg(mapping, 'generatedLine', null), | ||
column: util.getArg(mapping, 'generatedColumn', null), | ||
line: util.getArg(mapping, "generatedLine", null), | ||
column: util.getArg(mapping, "generatedColumn", null), | ||
lastColumn, | ||
@@ -1309,3 +1254,3 @@ }); | ||
} else { | ||
var originalColumn = mapping.originalColumn; | ||
const originalColumn = mapping.originalColumn; | ||
@@ -1324,4 +1269,4 @@ // Iterate until either we run out of mappings, or we run into | ||
mappings.push({ | ||
line: util.getArg(mapping, 'generatedLine', null), | ||
column: util.getArg(mapping, 'generatedColumn', null), | ||
line: util.getArg(mapping, "generatedLine", null), | ||
column: util.getArg(mapping, "generatedColumn", null), | ||
lastColumn, | ||
@@ -1336,11 +1281,30 @@ }); | ||
return mappings; | ||
}; | ||
} | ||
IndexedSourceMapConsumer.prototype.destroy = | ||
function IndexedSourceMapConsumer_destroy() { | ||
for (var i = 0; i < this._sections.length; i++) { | ||
destroy() { | ||
for (let i = 0; i < this._sections.length; i++) { | ||
this._sections[i].consumer.destroy(); | ||
} | ||
}; | ||
} | ||
} | ||
exports.IndexedSourceMapConsumer = IndexedSourceMapConsumer; | ||
exports.IndexedSourceMapConsumer = IndexedSourceMapConsumer; | ||
/* | ||
* Cheat to get around inter-twingled classes. `factory()` can be at the end | ||
* where it has access to non-hoisted classes, but it gets hoisted itself. | ||
*/ | ||
function _factory(aSourceMap, aSourceMapURL) { | ||
let sourceMap = aSourceMap; | ||
if (typeof aSourceMap === "string") { | ||
sourceMap = util.parseSourceMapInput(aSourceMap); | ||
} | ||
const consumer = sourceMap.sections != null | ||
? new IndexedSourceMapConsumer(sourceMap, aSourceMapURL) | ||
: new BasicSourceMapConsumer(sourceMap, aSourceMapURL); | ||
return Promise.resolve(consumer); | ||
} | ||
function _factoryBSM(aSourceMap, aSourceMapURL) { | ||
return BasicSourceMapConsumer.fromSourceMap(aSourceMap, aSourceMapURL); | ||
} |
@@ -8,6 +8,6 @@ /* -*- Mode: js; js-indent-level: 2; -*- */ | ||
var base64VLQ = require('./base64-vlq'); | ||
var util = require('./util'); | ||
var ArraySet = require('./array-set').ArraySet; | ||
var MappingList = require('./mapping-list').MappingList; | ||
const base64VLQ = require("./base64-vlq"); | ||
const util = require("./util"); | ||
const ArraySet = require("./array-set").ArraySet; | ||
const MappingList = require("./mapping-list").MappingList; | ||
@@ -22,31 +22,29 @@ /** | ||
*/ | ||
function SourceMapGenerator(aArgs) { | ||
if (!aArgs) { | ||
aArgs = {}; | ||
class SourceMapGenerator { | ||
constructor(aArgs) { | ||
if (!aArgs) { | ||
aArgs = {}; | ||
} | ||
this._file = util.getArg(aArgs, "file", null); | ||
this._sourceRoot = util.getArg(aArgs, "sourceRoot", null); | ||
this._skipValidation = util.getArg(aArgs, "skipValidation", false); | ||
this._sources = new ArraySet(); | ||
this._names = new ArraySet(); | ||
this._mappings = new MappingList(); | ||
this._sourcesContents = null; | ||
} | ||
this._file = util.getArg(aArgs, 'file', null); | ||
this._sourceRoot = util.getArg(aArgs, 'sourceRoot', null); | ||
this._skipValidation = util.getArg(aArgs, 'skipValidation', false); | ||
this._sources = new ArraySet(); | ||
this._names = new ArraySet(); | ||
this._mappings = new MappingList(); | ||
this._sourcesContents = null; | ||
} | ||
SourceMapGenerator.prototype._version = 3; | ||
/** | ||
* 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({ | ||
/** | ||
* Creates a new SourceMapGenerator based on a SourceMapConsumer | ||
* | ||
* @param aSourceMapConsumer The SourceMap. | ||
*/ | ||
static fromSourceMap(aSourceMapConsumer) { | ||
const sourceRoot = aSourceMapConsumer.sourceRoot; | ||
const generator = new SourceMapGenerator({ | ||
file: aSourceMapConsumer.file, | ||
sourceRoot: sourceRoot | ||
sourceRoot | ||
}); | ||
aSourceMapConsumer.eachMapping(function (mapping) { | ||
var newMapping = { | ||
aSourceMapConsumer.eachMapping(function(mapping) { | ||
const newMapping = { | ||
generated: { | ||
@@ -76,4 +74,4 @@ line: mapping.generatedLine, | ||
}); | ||
aSourceMapConsumer.sources.forEach(function (sourceFile) { | ||
var sourceRelative = sourceFile; | ||
aSourceMapConsumer.sources.forEach(function(sourceFile) { | ||
let sourceRelative = sourceFile; | ||
if (sourceRoot !== null) { | ||
@@ -87,3 +85,3 @@ sourceRelative = util.relative(sourceRoot, sourceFile); | ||
var content = aSourceMapConsumer.sourceContentFor(sourceFile); | ||
const content = aSourceMapConsumer.sourceContentFor(sourceFile); | ||
if (content != null) { | ||
@@ -94,20 +92,19 @@ generator.setSourceContent(sourceFile, content); | ||
return generator; | ||
}; | ||
} | ||
/** | ||
* Add a single mapping from original source line and column to the generated | ||
* source's line and column for this source map being created. The mapping | ||
* object should have the following properties: | ||
* | ||
* - generated: An object with the generated line and column positions. | ||
* - original: An object with the original line and column positions. | ||
* - source: The original source file (relative to the sourceRoot). | ||
* - name: An optional original token name for this mapping. | ||
*/ | ||
SourceMapGenerator.prototype.addMapping = | ||
function SourceMapGenerator_addMapping(aArgs) { | ||
var generated = util.getArg(aArgs, 'generated'); | ||
var original = util.getArg(aArgs, 'original', null); | ||
var source = util.getArg(aArgs, 'source', null); | ||
var name = util.getArg(aArgs, 'name', null); | ||
/** | ||
* Add a single mapping from original source line and column to the generated | ||
* source's line and column for this source map being created. The mapping | ||
* object should have the following properties: | ||
* | ||
* - generated: An object with the generated line and column positions. | ||
* - original: An object with the original line and column positions. | ||
* - source: The original source file (relative to the sourceRoot). | ||
* - name: An optional original token name for this mapping. | ||
*/ | ||
addMapping(aArgs) { | ||
const generated = util.getArg(aArgs, "generated"); | ||
const original = util.getArg(aArgs, "original", null); | ||
let source = util.getArg(aArgs, "source", null); | ||
let name = util.getArg(aArgs, "name", null); | ||
@@ -137,13 +134,12 @@ if (!this._skipValidation) { | ||
originalColumn: original != null && original.column, | ||
source: source, | ||
name: name | ||
source, | ||
name | ||
}); | ||
}; | ||
} | ||
/** | ||
* Set the source content for a source file. | ||
*/ | ||
SourceMapGenerator.prototype.setSourceContent = | ||
function SourceMapGenerator_setSourceContent(aSourceFile, aSourceContent) { | ||
var source = aSourceFile; | ||
/** | ||
* Set the source content for a source file. | ||
*/ | ||
setSourceContent(aSourceFile, aSourceContent) { | ||
let source = aSourceFile; | ||
if (this._sourceRoot != null) { | ||
@@ -168,23 +164,22 @@ source = util.relative(this._sourceRoot, source); | ||
} | ||
}; | ||
} | ||
/** | ||
* 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 source map to be applied. | ||
* @param aSourceFile Optional. The filename of the source file. | ||
* If omitted, SourceMapConsumer's file property will be used. | ||
* @param aSourceMapPath Optional. The dirname of the path to the source map | ||
* to be applied. If relative, it is relative to the SourceMapConsumer. | ||
* This parameter is needed when the two source maps aren't in the same | ||
* directory, and the source map to be applied contains relative source | ||
* paths. If so, those relative source paths need to be rewritten | ||
* relative to the SourceMapGenerator. | ||
*/ | ||
SourceMapGenerator.prototype.applySourceMap = | ||
function SourceMapGenerator_applySourceMap(aSourceMapConsumer, aSourceFile, aSourceMapPath) { | ||
var sourceFile = aSourceFile; | ||
/** | ||
* 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 source map to be applied. | ||
* @param aSourceFile Optional. The filename of the source file. | ||
* If omitted, SourceMapConsumer's file property will be used. | ||
* @param aSourceMapPath Optional. The dirname of the path to the source map | ||
* to be applied. If relative, it is relative to the SourceMapConsumer. | ||
* This parameter is needed when the two source maps aren't in the same | ||
* directory, and the source map to be applied contains relative source | ||
* paths. If so, those relative source paths need to be rewritten | ||
* relative to the SourceMapGenerator. | ||
*/ | ||
applySourceMap(aSourceMapConsumer, aSourceFile, aSourceMapPath) { | ||
let sourceFile = aSourceFile; | ||
// If aSourceFile is omitted, we will use the file property of the SourceMap | ||
@@ -194,3 +189,3 @@ if (aSourceFile == null) { | ||
throw new Error( | ||
'SourceMapGenerator.prototype.applySourceMap requires either an explicit source file, ' + | ||
"SourceMapGenerator.prototype.applySourceMap requires either an explicit source file, " + | ||
'or the source map\'s "file" property. Both were omitted.' | ||
@@ -201,3 +196,3 @@ ); | ||
} | ||
var sourceRoot = this._sourceRoot; | ||
const sourceRoot = this._sourceRoot; | ||
// Make "sourceFile" relative if an absolute Url is passed. | ||
@@ -209,12 +204,12 @@ if (sourceRoot != null) { | ||
// the names array. | ||
var newSources = this._mappings.toArray().length > 0 | ||
const newSources = this._mappings.toArray().length > 0 | ||
? new ArraySet() | ||
: this._sources; | ||
var newNames = new ArraySet(); | ||
const newNames = new ArraySet(); | ||
// Find mappings for the "sourceFile" | ||
this._mappings.unsortedForEach(function (mapping) { | ||
this._mappings.unsortedForEach(function(mapping) { | ||
if (mapping.source === sourceFile && mapping.originalLine != null) { | ||
// Check if it can be mapped by the source map, then update the mapping. | ||
var original = aSourceMapConsumer.originalPositionFor({ | ||
const original = aSourceMapConsumer.originalPositionFor({ | ||
line: mapping.originalLine, | ||
@@ -227,3 +222,3 @@ column: mapping.originalColumn | ||
if (aSourceMapPath != null) { | ||
mapping.source = util.join(aSourceMapPath, mapping.source) | ||
mapping.source = util.join(aSourceMapPath, mapping.source); | ||
} | ||
@@ -241,3 +236,3 @@ if (sourceRoot != null) { | ||
var source = mapping.source; | ||
const source = mapping.source; | ||
if (source != null && !newSources.has(source)) { | ||
@@ -247,3 +242,3 @@ newSources.add(source); | ||
var name = mapping.name; | ||
const name = mapping.name; | ||
if (name != null && !newNames.has(name)) { | ||
@@ -258,30 +253,28 @@ newNames.add(name); | ||
// Copy sourcesContents of applied map. | ||
aSourceMapConsumer.sources.forEach(function (sourceFile) { | ||
var content = aSourceMapConsumer.sourceContentFor(sourceFile); | ||
aSourceMapConsumer.sources.forEach(function(srcFile) { | ||
const content = aSourceMapConsumer.sourceContentFor(srcFile); | ||
if (content != null) { | ||
if (aSourceMapPath != null) { | ||
sourceFile = util.join(aSourceMapPath, sourceFile); | ||
srcFile = util.join(aSourceMapPath, srcFile); | ||
} | ||
if (sourceRoot != null) { | ||
sourceFile = util.relative(sourceRoot, sourceFile); | ||
srcFile = util.relative(sourceRoot, srcFile); | ||
} | ||
this.setSourceContent(sourceFile, content); | ||
this.setSourceContent(srcFile, content); | ||
} | ||
}, this); | ||
}; | ||
} | ||
/** | ||
* A mapping can have one of the three levels of data: | ||
* | ||
* 1. Just the generated position. | ||
* 2. The Generated position, original position, and original source. | ||
* 3. Generated and original position, original source, as well as a name | ||
* token. | ||
* | ||
* To maintain consistency, we validate that any new mapping being added falls | ||
* in to one of these categories. | ||
*/ | ||
SourceMapGenerator.prototype._validateMapping = | ||
function SourceMapGenerator_validateMapping(aGenerated, aOriginal, aSource, | ||
aName) { | ||
/** | ||
* A mapping can have one of the three levels of data: | ||
* | ||
* 1. Just the generated position. | ||
* 2. The Generated position, original position, and original source. | ||
* 3. Generated and original position, original source, as well as a name | ||
* token. | ||
* | ||
* To maintain consistency, we validate that any new mapping being added falls | ||
* in to one of these categories. | ||
*/ | ||
_validateMapping(aGenerated, aOriginal, aSource, aName) { | ||
// When aOriginal is truthy but has empty values for .line and .column, | ||
@@ -291,18 +284,17 @@ // it is most likely a programmer error. In this case we throw a very | ||
// For example: https://github.com/Polymer/polymer-bundler/pull/519 | ||
if (aOriginal && typeof aOriginal.line !== 'number' && typeof aOriginal.column !== 'number') { | ||
if (aOriginal && typeof aOriginal.line !== "number" && typeof aOriginal.column !== "number") { | ||
throw new Error( | ||
'original.line and original.column are not numbers -- you probably meant to omit ' + | ||
'the original mapping entirely and only map the generated position. If so, pass ' + | ||
'null for the original mapping instead of an object with empty or null values.' | ||
"original.line and original.column are not numbers -- you probably meant to omit " + | ||
"the original mapping entirely and only map the generated position. If so, pass " + | ||
"null for the original mapping instead of an object with empty or null values." | ||
); | ||
} | ||
if (aGenerated && 'line' in aGenerated && 'column' in aGenerated | ||
if (aGenerated && "line" in aGenerated && "column" in aGenerated | ||
&& aGenerated.line > 0 && aGenerated.column >= 0 | ||
&& !aOriginal && !aSource && !aName) { | ||
// Case 1. | ||
return; | ||
} | ||
else if (aGenerated && 'line' in aGenerated && 'column' in aGenerated | ||
&& aOriginal && 'line' in aOriginal && 'column' in aOriginal | ||
} else if (aGenerated && "line" in aGenerated && "column" in aGenerated | ||
&& aOriginal && "line" in aOriginal && "column" in aOriginal | ||
&& aGenerated.line > 0 && aGenerated.column >= 0 | ||
@@ -312,6 +304,5 @@ && aOriginal.line > 0 && aOriginal.column >= 0 | ||
// Cases 2 and 3. | ||
return; | ||
} | ||
else { | ||
throw new Error('Invalid mapping: ' + JSON.stringify({ | ||
} else { | ||
throw new Error("Invalid mapping: " + JSON.stringify({ | ||
generated: aGenerated, | ||
@@ -323,26 +314,25 @@ source: aSource, | ||
} | ||
}; | ||
} | ||
/** | ||
* Serialize the accumulated mappings in to the stream of base 64 VLQs | ||
* specified by the source map format. | ||
*/ | ||
SourceMapGenerator.prototype._serializeMappings = | ||
function SourceMapGenerator_serializeMappings() { | ||
var previousGeneratedColumn = 0; | ||
var previousGeneratedLine = 1; | ||
var previousOriginalColumn = 0; | ||
var previousOriginalLine = 0; | ||
var previousName = 0; | ||
var previousSource = 0; | ||
var result = ''; | ||
var next; | ||
var mapping; | ||
var nameIdx; | ||
var sourceIdx; | ||
/** | ||
* Serialize the accumulated mappings in to the stream of base 64 VLQs | ||
* specified by the source map format. | ||
*/ | ||
_serializeMappings() { | ||
let previousGeneratedColumn = 0; | ||
let previousGeneratedLine = 1; | ||
let previousOriginalColumn = 0; | ||
let previousOriginalLine = 0; | ||
let previousName = 0; | ||
let previousSource = 0; | ||
let result = ""; | ||
let next; | ||
let mapping; | ||
let nameIdx; | ||
let sourceIdx; | ||
var mappings = this._mappings.toArray(); | ||
for (var i = 0, len = mappings.length; i < len; i++) { | ||
const mappings = this._mappings.toArray(); | ||
for (let i = 0, len = mappings.length; i < len; i++) { | ||
mapping = mappings[i]; | ||
next = '' | ||
next = ""; | ||
@@ -352,13 +342,10 @@ if (mapping.generatedLine !== previousGeneratedLine) { | ||
while (mapping.generatedLine !== previousGeneratedLine) { | ||
next += ';'; | ||
next += ";"; | ||
previousGeneratedLine++; | ||
} | ||
} | ||
else { | ||
if (i > 0) { | ||
if (!util.compareByGeneratedPositionsInflated(mapping, mappings[i - 1])) { | ||
continue; | ||
} | ||
next += ','; | ||
} else if (i > 0) { | ||
if (!util.compareByGeneratedPositionsInflated(mapping, mappings[i - 1])) { | ||
continue; | ||
} | ||
next += ","; | ||
} | ||
@@ -395,7 +382,6 @@ | ||
return result; | ||
}; | ||
} | ||
SourceMapGenerator.prototype._generateSourcesContent = | ||
function SourceMapGenerator_generateSourcesContent(aSources, aSourceRoot) { | ||
return aSources.map(function (source) { | ||
_generateSourcesContent(aSources, aSourceRoot) { | ||
return aSources.map(function(source) { | ||
if (!this._sourcesContents) { | ||
@@ -407,3 +393,3 @@ return null; | ||
} | ||
var key = util.toSetString(source); | ||
const key = util.toSetString(source); | ||
return Object.prototype.hasOwnProperty.call(this._sourcesContents, key) | ||
@@ -413,10 +399,9 @@ ? this._sourcesContents[key] | ||
}, this); | ||
}; | ||
} | ||
/** | ||
* Externalize the source map. | ||
*/ | ||
SourceMapGenerator.prototype.toJSON = | ||
function SourceMapGenerator_toJSON() { | ||
var map = { | ||
/** | ||
* Externalize the source map. | ||
*/ | ||
toJSON() { | ||
const map = { | ||
version: this._version, | ||
@@ -438,12 +423,13 @@ sources: this._sources.toArray(), | ||
return map; | ||
}; | ||
} | ||
/** | ||
* Render the source map being generated to a string. | ||
*/ | ||
SourceMapGenerator.prototype.toString = | ||
function SourceMapGenerator_toString() { | ||
/** | ||
* Render the source map being generated to a string. | ||
*/ | ||
toString() { | ||
return JSON.stringify(this.toJSON()); | ||
}; | ||
} | ||
} | ||
SourceMapGenerator.prototype._version = 3; | ||
exports.SourceMapGenerator = SourceMapGenerator; |
@@ -8,11 +8,11 @@ /* -*- Mode: js; js-indent-level: 2; -*- */ | ||
var SourceMapGenerator = require('./source-map-generator').SourceMapGenerator; | ||
var util = require('./util'); | ||
const SourceMapGenerator = require("./source-map-generator").SourceMapGenerator; | ||
const util = require("./util"); | ||
// Matches a Windows-style `\r\n` newline or a `\n` newline used by all other | ||
// operating systems these days (capturing the result). | ||
var REGEX_NEWLINE = /(\r?\n)/; | ||
const REGEX_NEWLINE = /(\r?\n)/; | ||
// Newline character code for charCodeAt() comparisons | ||
var NEWLINE_CODE = 10; | ||
const NEWLINE_CODE = 10; | ||
@@ -22,3 +22,3 @@ // Private symbol for identifying `SourceNode`s when multiple versions of | ||
// versions! | ||
var isSourceNode = "$$$isSourceNode$$$"; | ||
const isSourceNode = "$$$isSourceNode$$$"; | ||
@@ -37,26 +37,26 @@ /** | ||
*/ | ||
function SourceNode(aLine, aColumn, aSource, aChunks, aName) { | ||
this.children = []; | ||
this.sourceContents = {}; | ||
this.line = aLine == null ? null : aLine; | ||
this.column = aColumn == null ? null : aColumn; | ||
this.source = aSource == null ? null : aSource; | ||
this.name = aName == null ? null : aName; | ||
this[isSourceNode] = true; | ||
if (aChunks != null) this.add(aChunks); | ||
} | ||
class SourceNode { | ||
constructor(aLine, aColumn, aSource, aChunks, aName) { | ||
this.children = []; | ||
this.sourceContents = {}; | ||
this.line = aLine == null ? null : aLine; | ||
this.column = aColumn == null ? null : aColumn; | ||
this.source = aSource == null ? null : aSource; | ||
this.name = aName == null ? null : aName; | ||
this[isSourceNode] = true; | ||
if (aChunks != null) this.add(aChunks); | ||
} | ||
/** | ||
* Creates a SourceNode from generated code and a SourceMapConsumer. | ||
* | ||
* @param aGeneratedCode The generated code | ||
* @param aSourceMapConsumer The SourceMap for the generated code | ||
* @param aRelativePath Optional. The path that relative sources in the | ||
* SourceMapConsumer should be relative to. | ||
*/ | ||
SourceNode.fromStringWithSourceMap = | ||
function SourceNode_fromStringWithSourceMap(aGeneratedCode, aSourceMapConsumer, aRelativePath) { | ||
/** | ||
* Creates a SourceNode from generated code and a SourceMapConsumer. | ||
* | ||
* @param aGeneratedCode The generated code | ||
* @param aSourceMapConsumer The SourceMap for the generated code | ||
* @param aRelativePath Optional. The path that relative sources in the | ||
* SourceMapConsumer should be relative to. | ||
*/ | ||
static fromStringWithSourceMap(aGeneratedCode, aSourceMapConsumer, aRelativePath) { | ||
// The SourceNode we want to fill with the generated code | ||
// and the SourceMap | ||
var node = new SourceNode(); | ||
const node = new SourceNode(); | ||
@@ -67,8 +67,8 @@ // All even indices of this array are one line of the generated code, | ||
// Processed fragments are accessed by calling `shiftNextLine`. | ||
var remainingLines = aGeneratedCode.split(REGEX_NEWLINE); | ||
var remainingLinesIndex = 0; | ||
var shiftNextLine = function() { | ||
var lineContents = getNextLine(); | ||
const remainingLines = aGeneratedCode.split(REGEX_NEWLINE); | ||
let remainingLinesIndex = 0; | ||
const shiftNextLine = function() { | ||
const lineContents = getNextLine(); | ||
// The last line of a file might not have a newline. | ||
var newLine = getNextLine() || ""; | ||
const newLine = getNextLine() || ""; | ||
return lineContents + newLine; | ||
@@ -83,3 +83,3 @@ | ||
// We need to remember the position of "remainingLines" | ||
var lastGeneratedLine = 1, lastGeneratedColumn = 0; | ||
let lastGeneratedLine = 1, lastGeneratedColumn = 0; | ||
@@ -89,5 +89,6 @@ // The generate SourceNodes we need a code range. | ||
// Here we store the last mapping. | ||
var lastMapping = null; | ||
let lastMapping = null; | ||
let nextLine; | ||
aSourceMapConsumer.eachMapping(function (mapping) { | ||
aSourceMapConsumer.eachMapping(function(mapping) { | ||
if (lastMapping !== null) { | ||
@@ -106,4 +107,4 @@ // We add the code from "lastMapping" to "mapping": | ||
// "mapping.generatedColumn" with "lastMapping" | ||
var nextLine = remainingLines[remainingLinesIndex] || ''; | ||
var code = nextLine.substr(0, mapping.generatedColumn - | ||
nextLine = remainingLines[remainingLinesIndex] || ""; | ||
const code = nextLine.substr(0, mapping.generatedColumn - | ||
lastGeneratedColumn); | ||
@@ -127,3 +128,3 @@ remainingLines[remainingLinesIndex] = nextLine.substr(mapping.generatedColumn - | ||
if (lastGeneratedColumn < mapping.generatedColumn) { | ||
var nextLine = remainingLines[remainingLinesIndex] || ''; | ||
nextLine = remainingLines[remainingLinesIndex] || ""; | ||
node.add(nextLine.substr(0, mapping.generatedColumn)); | ||
@@ -146,4 +147,4 @@ remainingLines[remainingLinesIndex] = nextLine.substr(mapping.generatedColumn); | ||
// Copy sourcesContent into SourceNode | ||
aSourceMapConsumer.sources.forEach(function (sourceFile) { | ||
var content = aSourceMapConsumer.sourceContentFor(sourceFile); | ||
aSourceMapConsumer.sources.forEach(function(sourceFile) { | ||
const content = aSourceMapConsumer.sourceContentFor(sourceFile); | ||
if (content != null) { | ||
@@ -163,3 +164,3 @@ if (aRelativePath != null) { | ||
} else { | ||
var source = aRelativePath | ||
const source = aRelativePath | ||
? util.join(aRelativePath, mapping.source) | ||
@@ -174,141 +175,130 @@ : mapping.source; | ||
} | ||
}; | ||
} | ||
/** | ||
* Add a chunk of generated JS to this source node. | ||
* | ||
* @param aChunk A string snippet of generated JS code, another instance of | ||
* SourceNode, or an array where each member is one of those things. | ||
*/ | ||
SourceNode.prototype.add = function SourceNode_add(aChunk) { | ||
if (Array.isArray(aChunk)) { | ||
aChunk.forEach(function (chunk) { | ||
this.add(chunk); | ||
}, this); | ||
} | ||
else if (aChunk[isSourceNode] || typeof aChunk === "string") { | ||
if (aChunk) { | ||
this.children.push(aChunk); | ||
/** | ||
* Add a chunk of generated JS to this source node. | ||
* | ||
* @param aChunk A string snippet of generated JS code, another instance of | ||
* SourceNode, or an array where each member is one of those things. | ||
*/ | ||
add(aChunk) { | ||
if (Array.isArray(aChunk)) { | ||
aChunk.forEach(function(chunk) { | ||
this.add(chunk); | ||
}, this); | ||
} else if (aChunk[isSourceNode] || typeof aChunk === "string") { | ||
if (aChunk) { | ||
this.children.push(aChunk); | ||
} | ||
} else { | ||
throw new TypeError( | ||
"Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk | ||
); | ||
} | ||
return this; | ||
} | ||
else { | ||
throw new TypeError( | ||
"Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk | ||
); | ||
} | ||
return this; | ||
}; | ||
/** | ||
* Add a chunk of generated JS to the beginning of this source node. | ||
* | ||
* @param aChunk A string snippet of generated JS code, another instance of | ||
* SourceNode, or an array where each member is one of those things. | ||
*/ | ||
SourceNode.prototype.prepend = function SourceNode_prepend(aChunk) { | ||
if (Array.isArray(aChunk)) { | ||
for (var i = aChunk.length-1; i >= 0; i--) { | ||
this.prepend(aChunk[i]); | ||
/** | ||
* Add a chunk of generated JS to the beginning of this source node. | ||
* | ||
* @param aChunk A string snippet of generated JS code, another instance of | ||
* SourceNode, or an array where each member is one of those things. | ||
*/ | ||
prepend(aChunk) { | ||
if (Array.isArray(aChunk)) { | ||
for (let i = aChunk.length - 1; i >= 0; i--) { | ||
this.prepend(aChunk[i]); | ||
} | ||
} else if (aChunk[isSourceNode] || typeof aChunk === "string") { | ||
this.children.unshift(aChunk); | ||
} else { | ||
throw new TypeError( | ||
"Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk | ||
); | ||
} | ||
return this; | ||
} | ||
else if (aChunk[isSourceNode] || typeof aChunk === "string") { | ||
this.children.unshift(aChunk); | ||
} | ||
else { | ||
throw new TypeError( | ||
"Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk | ||
); | ||
} | ||
return this; | ||
}; | ||
/** | ||
* Walk over the tree of JS snippets in this node and its children. The | ||
* walking function is called once for each snippet of JS and is passed that | ||
* snippet and the its original associated source's line/column location. | ||
* | ||
* @param aFn The traversal function. | ||
*/ | ||
SourceNode.prototype.walk = function SourceNode_walk(aFn) { | ||
var chunk; | ||
for (var i = 0, len = this.children.length; i < len; i++) { | ||
chunk = this.children[i]; | ||
if (chunk[isSourceNode]) { | ||
chunk.walk(aFn); | ||
} | ||
else { | ||
if (chunk !== '') { | ||
/** | ||
* Walk over the tree of JS snippets in this node and its children. The | ||
* walking function is called once for each snippet of JS and is passed that | ||
* snippet and the its original associated source's line/column location. | ||
* | ||
* @param aFn The traversal function. | ||
*/ | ||
walk(aFn) { | ||
let chunk; | ||
for (let i = 0, len = this.children.length; i < len; i++) { | ||
chunk = this.children[i]; | ||
if (chunk[isSourceNode]) { | ||
chunk.walk(aFn); | ||
} else if (chunk !== "") { | ||
aFn(chunk, { source: this.source, | ||
line: this.line, | ||
column: this.column, | ||
name: this.name }); | ||
line: this.line, | ||
column: this.column, | ||
name: this.name }); | ||
} | ||
} | ||
} | ||
}; | ||
/** | ||
* Like `String.prototype.join` except for SourceNodes. Inserts `aStr` between | ||
* each of `this.children`. | ||
* | ||
* @param aSep The separator. | ||
*/ | ||
SourceNode.prototype.join = function SourceNode_join(aSep) { | ||
var newChildren; | ||
var i; | ||
var len = this.children.length; | ||
if (len > 0) { | ||
newChildren = []; | ||
for (i = 0; i < len-1; i++) { | ||
/** | ||
* Like `String.prototype.join` except for SourceNodes. Inserts `aStr` between | ||
* each of `this.children`. | ||
* | ||
* @param aSep The separator. | ||
*/ | ||
join(aSep) { | ||
let newChildren; | ||
let i; | ||
const len = this.children.length; | ||
if (len > 0) { | ||
newChildren = []; | ||
for (i = 0; i < len - 1; i++) { | ||
newChildren.push(this.children[i]); | ||
newChildren.push(aSep); | ||
} | ||
newChildren.push(this.children[i]); | ||
newChildren.push(aSep); | ||
this.children = newChildren; | ||
} | ||
newChildren.push(this.children[i]); | ||
this.children = newChildren; | ||
return this; | ||
} | ||
return this; | ||
}; | ||
/** | ||
* Call String.prototype.replace on the very right-most source snippet. Useful | ||
* for trimming whitespace from the end of a source node, etc. | ||
* | ||
* @param aPattern The pattern to replace. | ||
* @param aReplacement The thing to replace the pattern with. | ||
*/ | ||
SourceNode.prototype.replaceRight = function SourceNode_replaceRight(aPattern, aReplacement) { | ||
var lastChild = this.children[this.children.length - 1]; | ||
if (lastChild[isSourceNode]) { | ||
lastChild.replaceRight(aPattern, aReplacement); | ||
/** | ||
* Call String.prototype.replace on the very right-most source snippet. Useful | ||
* for trimming whitespace from the end of a source node, etc. | ||
* | ||
* @param aPattern The pattern to replace. | ||
* @param aReplacement The thing to replace the pattern with. | ||
*/ | ||
replaceRight(aPattern, aReplacement) { | ||
const lastChild = this.children[this.children.length - 1]; | ||
if (lastChild[isSourceNode]) { | ||
lastChild.replaceRight(aPattern, aReplacement); | ||
} else if (typeof lastChild === "string") { | ||
this.children[this.children.length - 1] = lastChild.replace(aPattern, aReplacement); | ||
} else { | ||
this.children.push("".replace(aPattern, aReplacement)); | ||
} | ||
return this; | ||
} | ||
else if (typeof lastChild === 'string') { | ||
this.children[this.children.length - 1] = lastChild.replace(aPattern, aReplacement); | ||
} | ||
else { | ||
this.children.push(''.replace(aPattern, aReplacement)); | ||
} | ||
return this; | ||
}; | ||
/** | ||
* 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) { | ||
/** | ||
* 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 | ||
*/ | ||
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) { | ||
for (var i = 0, len = this.children.length; i < len; i++) { | ||
/** | ||
* 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. | ||
*/ | ||
walkSourceContents(aFn) { | ||
for (let i = 0, len = this.children.length; i < len; i++) { | ||
if (this.children[i][isSourceNode]) { | ||
@@ -319,82 +309,45 @@ this.children[i].walkSourceContents(aFn); | ||
var sources = Object.keys(this.sourceContents); | ||
for (var i = 0, len = sources.length; i < len; i++) { | ||
const sources = Object.keys(this.sourceContents); | ||
for (let i = 0, len = sources.length; i < len; i++) { | ||
aFn(util.fromSetString(sources[i]), this.sourceContents[sources[i]]); | ||
} | ||
}; | ||
} | ||
/** | ||
* Return the string representation of this source node. Walks over the tree | ||
* and concatenates all the various snippets together to one string. | ||
*/ | ||
SourceNode.prototype.toString = function SourceNode_toString() { | ||
var str = ""; | ||
this.walk(function (chunk) { | ||
str += chunk; | ||
}); | ||
return str; | ||
}; | ||
/** | ||
* Return the string representation of this source node. Walks over the tree | ||
* and concatenates all the various snippets together to one string. | ||
*/ | ||
toString() { | ||
let str = ""; | ||
this.walk(function(chunk) { | ||
str += chunk; | ||
}); | ||
return str; | ||
} | ||
/** | ||
* Returns the string representation of this source node along with a source | ||
* map. | ||
*/ | ||
SourceNode.prototype.toStringWithSourceMap = function SourceNode_toStringWithSourceMap(aArgs) { | ||
var generated = { | ||
code: "", | ||
line: 1, | ||
column: 0 | ||
}; | ||
var map = new SourceMapGenerator(aArgs); | ||
var sourceMappingActive = false; | ||
var lastOriginalSource = null; | ||
var lastOriginalLine = null; | ||
var lastOriginalColumn = null; | ||
var lastOriginalName = null; | ||
this.walk(function (chunk, original) { | ||
generated.code += chunk; | ||
if (original.source !== null | ||
&& original.line !== null | ||
&& original.column !== null) { | ||
if(lastOriginalSource !== original.source | ||
|| lastOriginalLine !== original.line | ||
|| lastOriginalColumn !== original.column | ||
|| lastOriginalName !== original.name) { | ||
map.addMapping({ | ||
source: original.source, | ||
original: { | ||
line: original.line, | ||
column: original.column | ||
}, | ||
generated: { | ||
line: generated.line, | ||
column: generated.column | ||
}, | ||
name: original.name | ||
}); | ||
} | ||
lastOriginalSource = original.source; | ||
lastOriginalLine = original.line; | ||
lastOriginalColumn = original.column; | ||
lastOriginalName = original.name; | ||
sourceMappingActive = true; | ||
} else if (sourceMappingActive) { | ||
map.addMapping({ | ||
generated: { | ||
line: generated.line, | ||
column: generated.column | ||
} | ||
}); | ||
lastOriginalSource = null; | ||
sourceMappingActive = false; | ||
} | ||
for (var idx = 0, length = chunk.length; idx < length; idx++) { | ||
if (chunk.charCodeAt(idx) === NEWLINE_CODE) { | ||
generated.line++; | ||
generated.column = 0; | ||
// Mappings end at eol | ||
if (idx + 1 === length) { | ||
lastOriginalSource = null; | ||
sourceMappingActive = false; | ||
} else if (sourceMappingActive) { | ||
/** | ||
* Returns the string representation of this source node along with a source | ||
* map. | ||
*/ | ||
toStringWithSourceMap(aArgs) { | ||
const generated = { | ||
code: "", | ||
line: 1, | ||
column: 0 | ||
}; | ||
const map = new SourceMapGenerator(aArgs); | ||
let sourceMappingActive = false; | ||
let lastOriginalSource = null; | ||
let lastOriginalLine = null; | ||
let lastOriginalColumn = null; | ||
let lastOriginalName = null; | ||
this.walk(function(chunk, original) { | ||
generated.code += chunk; | ||
if (original.source !== null | ||
&& original.line !== null | ||
&& original.column !== null) { | ||
if (lastOriginalSource !== original.source | ||
|| lastOriginalLine !== original.line | ||
|| lastOriginalColumn !== original.column | ||
|| lastOriginalName !== original.name) { | ||
map.addMapping({ | ||
@@ -413,14 +366,52 @@ source: original.source, | ||
} | ||
} else { | ||
generated.column++; | ||
lastOriginalSource = original.source; | ||
lastOriginalLine = original.line; | ||
lastOriginalColumn = original.column; | ||
lastOriginalName = original.name; | ||
sourceMappingActive = true; | ||
} else if (sourceMappingActive) { | ||
map.addMapping({ | ||
generated: { | ||
line: generated.line, | ||
column: generated.column | ||
} | ||
}); | ||
lastOriginalSource = null; | ||
sourceMappingActive = false; | ||
} | ||
} | ||
}); | ||
this.walkSourceContents(function (sourceFile, sourceContent) { | ||
map.setSourceContent(sourceFile, sourceContent); | ||
}); | ||
for (let idx = 0, length = chunk.length; idx < length; idx++) { | ||
if (chunk.charCodeAt(idx) === NEWLINE_CODE) { | ||
generated.line++; | ||
generated.column = 0; | ||
// Mappings end at eol | ||
if (idx + 1 === length) { | ||
lastOriginalSource = null; | ||
sourceMappingActive = false; | ||
} else if (sourceMappingActive) { | ||
map.addMapping({ | ||
source: original.source, | ||
original: { | ||
line: original.line, | ||
column: original.column | ||
}, | ||
generated: { | ||
line: generated.line, | ||
column: generated.column | ||
}, | ||
name: original.name | ||
}); | ||
} | ||
} else { | ||
generated.column++; | ||
} | ||
} | ||
}); | ||
this.walkSourceContents(function(sourceFile, sourceContent) { | ||
map.setSourceContent(sourceFile, sourceContent); | ||
}); | ||
return { code: generated.code, map: map }; | ||
}; | ||
return { code: generated.code, map }; | ||
} | ||
} | ||
exports.SourceNode = SourceNode; |
115
lib/util.js
@@ -23,13 +23,13 @@ /* -*- Mode: js; js-indent-level: 2; -*- */ | ||
return aDefaultValue; | ||
} else { | ||
} | ||
throw new Error('"' + aName + '" is a required argument.'); | ||
} | ||
} | ||
exports.getArg = getArg; | ||
var urlRegexp = /^(?:([\w+\-.]+):)?\/\/(?:(\w+:\w+)@)?([\w.-]*)(?::(\d+))?(.*)$/; | ||
var dataUrlRegexp = /^data:.+\,.+$/; | ||
const urlRegexp = /^(?:([\w+\-.]+):)?\/\/(?:(\w+:\w+)@)?([\w.-]*)(?::(\d+))?(.*)$/; | ||
const dataUrlRegexp = /^data:.+\,.+$/; | ||
function urlParse(aUrl) { | ||
var match = aUrl.match(urlRegexp); | ||
const match = aUrl.match(urlRegexp); | ||
if (!match) { | ||
@@ -49,9 +49,9 @@ return null; | ||
function urlGenerate(aParsedUrl) { | ||
var url = ''; | ||
let url = ""; | ||
if (aParsedUrl.scheme) { | ||
url += aParsedUrl.scheme + ':'; | ||
url += aParsedUrl.scheme + ":"; | ||
} | ||
url += '//'; | ||
url += "//"; | ||
if (aParsedUrl.auth) { | ||
url += aParsedUrl.auth + '@'; | ||
url += aParsedUrl.auth + "@"; | ||
} | ||
@@ -62,3 +62,3 @@ if (aParsedUrl.host) { | ||
if (aParsedUrl.port) { | ||
url += ":" + aParsedUrl.port | ||
url += ":" + aParsedUrl.port; | ||
} | ||
@@ -84,6 +84,6 @@ if (aParsedUrl.path) { | ||
return function (input) { | ||
for (var i = 0; i < cache.length; i++) { | ||
return function(input) { | ||
for (let i = 0; i < cache.length; i++) { | ||
if (cache[i].input === input) { | ||
var temp = cache[0]; | ||
const temp = cache[0]; | ||
cache[0] = cache[i]; | ||
@@ -95,3 +95,3 @@ cache[i] = temp; | ||
var result = f(input); | ||
const result = f(input); | ||
@@ -122,5 +122,5 @@ cache.unshift({ | ||
*/ | ||
var normalize = lruMemoize(function normalize(aPath) { | ||
var path = aPath; | ||
var url = urlParse(aPath); | ||
const normalize = lruMemoize(function normalize(aPath) { | ||
let path = aPath; | ||
const url = urlParse(aPath); | ||
if (url) { | ||
@@ -132,9 +132,9 @@ if (!url.path) { | ||
} | ||
var isAbsolute = exports.isAbsolute(path); | ||
const isAbsolute = exports.isAbsolute(path); | ||
// Split the path into parts between `/` characters. This is much faster than | ||
// using `.split(/\/+/g)`. | ||
var parts = []; | ||
var start = 0; | ||
var i = 0; | ||
const parts = []; | ||
let start = 0; | ||
let i = 0; | ||
while (true) { | ||
@@ -154,10 +154,11 @@ start = i; | ||
for (var part, up = 0, i = parts.length - 1; i >= 0; i--) { | ||
part = parts[i]; | ||
if (part === '.') { | ||
let up = 0; | ||
for (i = parts.length - 1; i >= 0; i--) { | ||
const part = parts[i]; | ||
if (part === ".") { | ||
parts.splice(i, 1); | ||
} else if (part === '..') { | ||
} else if (part === "..") { | ||
up++; | ||
} else if (up > 0) { | ||
if (part === '') { | ||
if (part === "") { | ||
// The first part is blank if the path is absolute. Trying to go | ||
@@ -174,6 +175,6 @@ // above the root is a no-op. Therefore we can remove all '..' parts | ||
} | ||
path = parts.join('/'); | ||
path = parts.join("/"); | ||
if (path === '') { | ||
path = isAbsolute ? '/' : '.'; | ||
if (path === "") { | ||
path = isAbsolute ? "/" : "."; | ||
} | ||
@@ -212,6 +213,6 @@ | ||
} | ||
var aPathUrl = urlParse(aPath); | ||
var aRootUrl = urlParse(aRoot); | ||
const aPathUrl = urlParse(aPath); | ||
const aRootUrl = urlParse(aRoot); | ||
if (aRootUrl) { | ||
aRoot = aRootUrl.path || '/'; | ||
aRoot = aRootUrl.path || "/"; | ||
} | ||
@@ -237,5 +238,5 @@ | ||
var joined = aPath.charAt(0) === '/' | ||
const joined = aPath.charAt(0) === "/" | ||
? aPath | ||
: normalize(aRoot.replace(/\/+$/, '') + '/' + aPath); | ||
: normalize(aRoot.replace(/\/+$/, "") + "/" + aPath); | ||
@@ -250,4 +251,4 @@ if (aRootUrl) { | ||
exports.isAbsolute = function (aPath) { | ||
return aPath.charAt(0) === '/' || urlRegexp.test(aPath); | ||
exports.isAbsolute = function(aPath) { | ||
return aPath.charAt(0) === "/" || urlRegexp.test(aPath); | ||
}; | ||
@@ -266,3 +267,3 @@ | ||
aRoot = aRoot.replace(/\/$/, ''); | ||
aRoot = aRoot.replace(/\/$/, ""); | ||
@@ -273,5 +274,5 @@ // It is possible for the path to be above the root. In this case, simply | ||
// a prefix that fits, or we run out of components to remove. | ||
var level = 0; | ||
while (aPath.indexOf(aRoot + '/') !== 0) { | ||
var index = aRoot.lastIndexOf("/"); | ||
let level = 0; | ||
while (aPath.indexOf(aRoot + "/") !== 0) { | ||
const index = aRoot.lastIndexOf("/"); | ||
if (index < 0) { | ||
@@ -297,8 +298,8 @@ return aPath; | ||
var supportsNullProto = (function () { | ||
var obj = Object.create(null); | ||
return !('__proto__' in obj); | ||
const supportsNullProto = (function() { | ||
const obj = Object.create(null); | ||
return !("__proto__" in obj); | ||
}()); | ||
function identity (s) { | ||
function identity(s) { | ||
return s; | ||
@@ -318,3 +319,3 @@ } | ||
if (isProtoString(aStr)) { | ||
return '$' + aStr; | ||
return "$" + aStr; | ||
} | ||
@@ -340,3 +341,3 @@ | ||
var length = s.length; | ||
const length = s.length; | ||
@@ -347,2 +348,3 @@ if (length < 9 /* "__proto__".length */) { | ||
/* eslint-disable no-multi-spaces */ | ||
if (s.charCodeAt(length - 1) !== 95 /* '_' */ || | ||
@@ -359,4 +361,5 @@ s.charCodeAt(length - 2) !== 95 /* '_' */ || | ||
} | ||
/* eslint-enable no-multi-spaces */ | ||
for (var i = length - 10; i >= 0; i--) { | ||
for (let i = length - 10; i >= 0; i--) { | ||
if (s.charCodeAt(i) !== 36 /* '$' */) { | ||
@@ -379,3 +382,3 @@ return false; | ||
function compareByOriginalPositions(mappingA, mappingB, onlyCompareOriginal) { | ||
var cmp = strcmp(mappingA.source, mappingB.source); | ||
let cmp = strcmp(mappingA.source, mappingB.source); | ||
if (cmp !== 0) { | ||
@@ -419,3 +422,3 @@ return cmp; | ||
function compareByGeneratedPositionsDeflated(mappingA, mappingB, onlyCompareGenerated) { | ||
var cmp = mappingA.generatedLine - mappingB.generatedLine; | ||
let cmp = mappingA.generatedLine - mappingB.generatedLine; | ||
if (cmp !== 0) { | ||
@@ -474,3 +477,3 @@ return cmp; | ||
function compareByGeneratedPositionsInflated(mappingA, mappingB) { | ||
var cmp = mappingA.generatedLine - mappingB.generatedLine; | ||
let cmp = mappingA.generatedLine - mappingB.generatedLine; | ||
if (cmp !== 0) { | ||
@@ -510,3 +513,3 @@ return cmp; | ||
function parseSourceMapInput(str) { | ||
return JSON.parse(str.replace(/^\)]}'[^\n]*\n/, '')); | ||
return JSON.parse(str.replace(/^\)]}'[^\n]*\n/, "")); | ||
} | ||
@@ -520,8 +523,8 @@ exports.parseSourceMapInput = parseSourceMapInput; | ||
function computeSourceURL(sourceRoot, sourceURL, sourceMapURL) { | ||
sourceURL = sourceURL || ''; | ||
sourceURL = sourceURL || ""; | ||
if (sourceRoot) { | ||
// This follows what Chrome does. | ||
if (sourceRoot[sourceRoot.length - 1] !== '/' && sourceURL[0] !== '/') { | ||
sourceRoot += '/'; | ||
if (sourceRoot[sourceRoot.length - 1] !== "/" && sourceURL[0] !== "/") { | ||
sourceRoot += "/"; | ||
} | ||
@@ -551,3 +554,3 @@ // The spec says: | ||
if (sourceMapURL) { | ||
var parsed = urlParse(sourceMapURL); | ||
const parsed = urlParse(sourceMapURL); | ||
if (!parsed) { | ||
@@ -558,3 +561,3 @@ throw new Error("sourceMapURL could not be parsed"); | ||
// Strip the last path component, but keep the "/". | ||
var index = parsed.path.lastIndexOf('/'); | ||
const index = parsed.path.lastIndexOf("/"); | ||
if (index >= 0) { | ||
@@ -561,0 +564,0 @@ parsed.path = parsed.path.substring(0, index + 1); |
@@ -23,3 +23,3 @@ const readWasm = require("../lib/read-wasm"); | ||
let currentCallback = null; | ||
const callbackStack = []; | ||
@@ -29,3 +29,3 @@ cachedWasm = readWasm().then(buffer => { | ||
env: { | ||
mapping_callback: function ( | ||
mapping_callback( | ||
generatedLine, | ||
@@ -45,3 +45,3 @@ generatedColumn, | ||
) { | ||
const mapping = new Mapping; | ||
const mapping = new Mapping(); | ||
// JS uses 1-based line numbers, wasm uses 0-based. | ||
@@ -67,36 +67,36 @@ mapping.generatedLine = generatedLine + 1; | ||
currentCallback(mapping); | ||
callbackStack[callbackStack.length - 1](mapping); | ||
}, | ||
start_all_generated_locations_for: function () { console.time("all_generated_locations_for"); }, | ||
end_all_generated_locations_for: function () { console.timeEnd("all_generated_locations_for"); }, | ||
start_all_generated_locations_for() { console.time("all_generated_locations_for"); }, | ||
end_all_generated_locations_for() { console.timeEnd("all_generated_locations_for"); }, | ||
start_compute_column_spans: function () { console.time("compute_column_spans"); }, | ||
end_compute_column_spans: function () { console.timeEnd("compute_column_spans"); }, | ||
start_compute_column_spans() { console.time("compute_column_spans"); }, | ||
end_compute_column_spans() { console.timeEnd("compute_column_spans"); }, | ||
start_generated_location_for: function () { console.time("generated_location_for"); }, | ||
end_generated_location_for: function () { console.timeEnd("generated_location_for"); }, | ||
start_generated_location_for() { console.time("generated_location_for"); }, | ||
end_generated_location_for() { console.timeEnd("generated_location_for"); }, | ||
start_original_location_for: function () { console.time("original_location_for"); }, | ||
end_original_location_for: function () { console.timeEnd("original_location_for"); }, | ||
start_original_location_for() { console.time("original_location_for"); }, | ||
end_original_location_for() { console.timeEnd("original_location_for"); }, | ||
start_parse_mappings: function () { console.time("parse_mappings"); }, | ||
end_parse_mappings: function () { console.timeEnd("parse_mappings"); }, | ||
start_parse_mappings() { console.time("parse_mappings"); }, | ||
end_parse_mappings() { console.timeEnd("parse_mappings"); }, | ||
start_sort_by_generated_location: function () { console.time("sort_by_generated_location"); }, | ||
end_sort_by_generated_location: function () { console.timeEnd("sort_by_generated_location"); }, | ||
start_sort_by_generated_location() { console.time("sort_by_generated_location"); }, | ||
end_sort_by_generated_location() { console.timeEnd("sort_by_generated_location"); }, | ||
start_sort_by_original_location: function () { console.time("sort_by_original_location"); }, | ||
end_sort_by_original_location: function () { console.timeEnd("sort_by_original_location"); }, | ||
start_sort_by_original_location() { console.time("sort_by_original_location"); }, | ||
end_sort_by_original_location() { console.timeEnd("sort_by_original_location"); }, | ||
} | ||
}); | ||
}).then(wasm => { | ||
}).then(Wasm => { | ||
return { | ||
exports: wasm.instance.exports, | ||
exports: Wasm.instance.exports, | ||
withMappingCallback: (mappingCallback, f) => { | ||
currentCallback = mappingCallback; | ||
callbackStack.push(mappingCallback); | ||
try { | ||
f(); | ||
} finally { | ||
currentCallback = null; | ||
callbackStack.pop(); | ||
} | ||
@@ -103,0 +103,0 @@ } |
{ | ||
"name": "source-map", | ||
"description": "Generates and consumes source maps", | ||
"version": "0.7.2", | ||
"version": "0.7.3", | ||
"homepage": "https://github.com/mozilla/source-map", | ||
@@ -62,4 +62,15 @@ "author": "Nick Fitzgerald <nfitzgerald@mozilla.com>", | ||
"scripts": { | ||
"test": "npm run build && node test/run-tests.js", | ||
"lint": "eslint *.js lib/ test/", | ||
"prebuild": "npm run lint", | ||
"build": "webpack --color", | ||
"pretest": "npm run build", | ||
"test": "node test/run-tests.js", | ||
"precoverage": "npm run build", | ||
"coverage": "nyc node test/run-tests.js", | ||
"setup": "mkdir -p coverage && cp -n .waiting.html coverage/index.html || true", | ||
"dev:live": "live-server --port=4103 --ignorePattern='(js|css|png)$' coverage", | ||
"dev:watch": "watch 'npm run coverage' lib/ test/", | ||
"predev": "npm run setup", | ||
"dev": "npm-run-all -p --silent dev:*", | ||
"clean": "rm -rf coverage .nyc_output", | ||
"toc": "doctoc --title '## Table of Contents' README.md && doctoc --title '## Table of Contents' CONTRIBUTING.md" | ||
@@ -69,5 +80,13 @@ }, | ||
"doctoc": "^0.15.0", | ||
"eslint": "^4.19.1", | ||
"live-server": "^1.2.0", | ||
"npm-run-all": "^4.1.2", | ||
"nyc": "^11.7.1", | ||
"watch": "^1.0.2", | ||
"webpack": "^3.10" | ||
}, | ||
"nyc": { | ||
"reporter": "html" | ||
}, | ||
"typings": "source-map" | ||
} |
@@ -5,2 +5,4 @@ # Source Map | ||
[![Coverage Status](https://coveralls.io/repos/github/mozilla/source-map/badge.svg)](https://coveralls.io/github/mozilla/source-map) | ||
[![NPM](https://nodei.co/npm/source-map.png?downloads=true&downloadRank=true)](https://www.npmjs.com/package/source-map) | ||
@@ -19,6 +21,6 @@ | ||
<script src="https://unpkg.com/source-map@0.7.2/dist/source-map.js"></script> | ||
<script src="https://unpkg.com/source-map@0.7.3/dist/source-map.js"></script> | ||
<script> | ||
sourceMap.SourceMapConsumer.initialize({ | ||
"lib/mappings.wasm": "https://unpkg.com/source-map@0.7.2/lib/mappings.wasm" | ||
"lib/mappings.wasm": "https://unpkg.com/source-map@0.7.3/lib/mappings.wasm" | ||
}); | ||
@@ -664,4 +666,3 @@ </script> | ||
const consumer = await new SourceMapConsumer(fs.readFileSync("path/to/my-file.js.map", "utf8")); | ||
onst node = SourceNode.fromStringWithSourceMap(fs.readFileSync("path/to/my-file.js"), | ||
consumer); | ||
const node = SourceNode.fromStringWithSourceMap(fs.readFileSync("path/to/my-file.js"), consumer); | ||
``` | ||
@@ -668,0 +669,0 @@ |
@@ -6,4 +6,4 @@ /* | ||
*/ | ||
exports.SourceMapGenerator = require('./lib/source-map-generator').SourceMapGenerator; | ||
exports.SourceMapConsumer = require('./lib/source-map-consumer').SourceMapConsumer; | ||
exports.SourceNode = require('./lib/source-node').SourceNode; | ||
exports.SourceMapGenerator = require("./lib/source-map-generator").SourceMapGenerator; | ||
exports.SourceMapConsumer = require("./lib/source-map-consumer").SourceMapConsumer; | ||
exports.SourceNode = require("./lib/source-node").SourceNode; |
Sorry, the diff of this file is too big to display
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
823
311689
7
6133