format: prettify entire project

This commit is contained in:
Rim
2025-04-02 06:50:39 -04:00
parent 86f0782a98
commit 7ccc0be712
1711 changed files with 755867 additions and 235931 deletions

View File

@ -17,14 +17,14 @@ function SourceMapConsumer(aSourceMap, aSourceMapURL) {
sourceMap = util.parseSourceMapInput(aSourceMap);
}
return sourceMap.sections != null
? new IndexedSourceMapConsumer(sourceMap, aSourceMapURL)
return sourceMap.sections != null ?
new IndexedSourceMapConsumer(sourceMap, aSourceMapURL)
: new BasicSourceMapConsumer(sourceMap, aSourceMapURL);
}
SourceMapConsumer.fromSourceMap = function(aSourceMap, aSourceMapURL) {
SourceMapConsumer.fromSourceMap = function (aSourceMap, aSourceMapURL) {
return BasicSourceMapConsumer.fromSourceMap(aSourceMap, aSourceMapURL);
}
};
/**
* The version of the source mapping spec that we are consuming.
@ -71,7 +71,7 @@ Object.defineProperty(SourceMapConsumer.prototype, '_generatedMappings', {
}
return this.__generatedMappings;
}
},
});
SourceMapConsumer.prototype.__originalMappings = null;
@ -84,13 +84,13 @@ Object.defineProperty(SourceMapConsumer.prototype, '_originalMappings', {
}
return this.__originalMappings;
}
},
});
SourceMapConsumer.prototype._charIsMappingSeparator =
function SourceMapConsumer_charIsMappingSeparator(aStr, index) {
var c = aStr.charAt(index);
return c === ";" || c === ",";
return c === ';' || c === ',';
};
/**
@ -100,7 +100,7 @@ SourceMapConsumer.prototype._charIsMappingSeparator =
*/
SourceMapConsumer.prototype._parseMappings =
function SourceMapConsumer_parseMappings(aStr, aSourceRoot) {
throw new Error("Subclasses must implement _parseMappings");
throw new Error('Subclasses must implement _parseMappings');
};
SourceMapConsumer.GENERATED_ORDER = 1;
@ -132,14 +132,14 @@ SourceMapConsumer.prototype.eachMapping =
var mappings;
switch (order) {
case SourceMapConsumer.GENERATED_ORDER:
mappings = this._generatedMappings;
break;
case SourceMapConsumer.ORIGINAL_ORDER:
mappings = this._originalMappings;
break;
default:
throw new Error("Unknown order of iteration.");
case SourceMapConsumer.GENERATED_ORDER:
mappings = this._generatedMappings;
break;
case SourceMapConsumer.ORIGINAL_ORDER:
mappings = this._originalMappings;
break;
default:
throw new Error('Unknown order of iteration.');
}
var sourceRoot = this.sourceRoot;
@ -151,7 +151,7 @@ SourceMapConsumer.prototype.eachMapping =
for (var i = 0, n = mappings.length; i < n; i++) {
var mapping = mappings[i];
var source = mapping.source === null ? null : sources.at(mapping.source);
if(source !== null) {
if (source !== null) {
source = util.computeSourceURL(sourceRoot, source, sourceMapURL);
}
boundCallback({
@ -160,7 +160,7 @@ SourceMapConsumer.prototype.eachMapping =
generatedColumn: mapping.generatedColumn,
originalLine: mapping.originalLine,
originalColumn: mapping.originalColumn,
name: mapping.name === null ? null : names.at(mapping.name)
name: mapping.name === null ? null : names.at(mapping.name),
});
}
};
@ -198,7 +198,7 @@ SourceMapConsumer.prototype.allGeneratedPositionsFor =
var needle = {
source: util.getArg(aArgs, 'source'),
originalLine: line,
originalColumn: util.getArg(aArgs, 'column', 0)
originalColumn: util.getArg(aArgs, 'column', 0),
};
needle.source = this._findSourceIndex(needle.source);
@ -208,12 +208,14 @@ SourceMapConsumer.prototype.allGeneratedPositionsFor =
var mappings = [];
var index = this._findMapping(needle,
this._originalMappings,
"originalLine",
"originalColumn",
util.compareByOriginalPositions,
binarySearch.LEAST_UPPER_BOUND);
var index = this._findMapping(
needle,
this._originalMappings,
'originalLine',
'originalColumn',
util.compareByOriginalPositions,
binarySearch.LEAST_UPPER_BOUND
);
if (index >= 0) {
var mapping = this._originalMappings[index];
@ -228,7 +230,7 @@ SourceMapConsumer.prototype.allGeneratedPositionsFor =
mappings.push({
line: util.getArg(mapping, 'generatedLine', null),
column: util.getArg(mapping, 'generatedColumn', null),
lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null)
lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null),
});
mapping = this._originalMappings[++index];
@ -240,13 +242,15 @@ SourceMapConsumer.prototype.allGeneratedPositionsFor =
// a mapping for a different line than the one we were searching for.
// Since mappings are sorted, this is guaranteed to find all mappings for
// the line we are searching for.
while (mapping &&
mapping.originalLine === line &&
mapping.originalColumn == originalColumn) {
while (
mapping &&
mapping.originalLine === line &&
mapping.originalColumn == originalColumn
) {
mappings.push({
line: util.getArg(mapping, 'generatedLine', null),
column: util.getArg(mapping, 'generatedColumn', null),
lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null)
lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null),
});
mapping = this._originalMappings[++index];
@ -330,8 +334,10 @@ function BasicSourceMapConsumer(aSourceMap, aSourceMapURL) {
// 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)
return (
sourceRoot && util.isAbsolute(sourceRoot) && util.isAbsolute(source)
) ?
util.relative(sourceRoot, source)
: source;
});
@ -360,7 +366,7 @@ BasicSourceMapConsumer.prototype.consumer = SourceMapConsumer;
* Utility function to find the index of a source. Returns -1 if not
* found.
*/
BasicSourceMapConsumer.prototype._findSourceIndex = function(aSource) {
BasicSourceMapConsumer.prototype._findSourceIndex = function (aSource) {
var relativeSource = aSource;
if (this.sourceRoot != null) {
relativeSource = util.relative(this.sourceRoot, relativeSource);
@ -391,55 +397,65 @@ BasicSourceMapConsumer.prototype._findSourceIndex = function(aSource) {
* The URL at which the source map can be found (optional)
* @returns BasicSourceMapConsumer
*/
BasicSourceMapConsumer.fromSourceMap =
function SourceMapConsumer_fromSourceMap(aSourceMap, aSourceMapURL) {
var smc = Object.create(BasicSourceMapConsumer.prototype);
BasicSourceMapConsumer.fromSourceMap = function SourceMapConsumer_fromSourceMap(
aSourceMap,
aSourceMapURL
) {
var smc = Object.create(BasicSourceMapConsumer.prototype);
var names = smc._names = ArraySet.fromArray(aSourceMap._names.toArray(), true);
var sources = smc._sources = ArraySet.fromArray(aSourceMap._sources.toArray(), true);
smc.sourceRoot = aSourceMap._sourceRoot;
smc.sourcesContent = aSourceMap._generateSourcesContent(smc._sources.toArray(),
smc.sourceRoot);
smc.file = aSourceMap._file;
smc._sourceMapURL = aSourceMapURL;
smc._absoluteSources = smc._sources.toArray().map(function (s) {
return util.computeSourceURL(smc.sourceRoot, s, aSourceMapURL);
});
var names = (smc._names = ArraySet.fromArray(
aSourceMap._names.toArray(),
true
));
var sources = (smc._sources = ArraySet.fromArray(
aSourceMap._sources.toArray(),
true
));
smc.sourceRoot = aSourceMap._sourceRoot;
smc.sourcesContent = aSourceMap._generateSourcesContent(
smc._sources.toArray(),
smc.sourceRoot
);
smc.file = aSourceMap._file;
smc._sourceMapURL = aSourceMapURL;
smc._absoluteSources = smc._sources.toArray().map(function (s) {
return util.computeSourceURL(smc.sourceRoot, s, aSourceMapURL);
});
// Because we are modifying the entries (by converting string sources and
// names to indices into the sources and names ArraySets), we have to make
// a copy of the entry or else bad things happen. Shared mutable state
// strikes again! See github issue #191.
// Because we are modifying the entries (by converting string sources and
// names to indices into the sources and names ArraySets), we have to make
// a copy of the entry or else bad things happen. Shared mutable state
// strikes again! See github issue #191.
var generatedMappings = aSourceMap._mappings.toArray().slice();
var destGeneratedMappings = smc.__generatedMappings = [];
var destOriginalMappings = smc.__originalMappings = [];
var generatedMappings = aSourceMap._mappings.toArray().slice();
var destGeneratedMappings = (smc.__generatedMappings = []);
var destOriginalMappings = (smc.__originalMappings = []);
for (var i = 0, length = generatedMappings.length; i < length; i++) {
var srcMapping = generatedMappings[i];
var destMapping = new Mapping;
destMapping.generatedLine = srcMapping.generatedLine;
destMapping.generatedColumn = srcMapping.generatedColumn;
for (var i = 0, length = generatedMappings.length; i < length; i++) {
var srcMapping = generatedMappings[i];
var destMapping = new Mapping();
destMapping.generatedLine = srcMapping.generatedLine;
destMapping.generatedColumn = srcMapping.generatedColumn;
if (srcMapping.source) {
destMapping.source = sources.indexOf(srcMapping.source);
destMapping.originalLine = srcMapping.originalLine;
destMapping.originalColumn = srcMapping.originalColumn;
if (srcMapping.source) {
destMapping.source = sources.indexOf(srcMapping.source);
destMapping.originalLine = srcMapping.originalLine;
destMapping.originalColumn = srcMapping.originalColumn;
if (srcMapping.name) {
destMapping.name = names.indexOf(srcMapping.name);
}
destOriginalMappings.push(destMapping);
if (srcMapping.name) {
destMapping.name = names.indexOf(srcMapping.name);
}
destGeneratedMappings.push(destMapping);
destOriginalMappings.push(destMapping);
}
quickSort(smc.__originalMappings, util.compareByOriginalPositions);
destGeneratedMappings.push(destMapping);
}
return smc;
};
quickSort(smc.__originalMappings, util.compareByOriginalPositions);
return smc;
};
/**
* The version of the source mapping spec that we are consuming.
@ -452,7 +468,7 @@ BasicSourceMapConsumer.prototype._version = 3;
Object.defineProperty(BasicSourceMapConsumer.prototype, 'sources', {
get: function () {
return this._absoluteSources.slice();
}
},
});
/**
@ -527,11 +543,9 @@ BasicSourceMapConsumer.prototype._parseMappings =
sortGenerated(generatedMappings, subarrayStart);
subarrayStart = generatedMappings.length;
}
else if (aStr.charAt(index) === ',') {
} else if (aStr.charAt(index) === ',') {
index++;
}
else {
} else {
mapping = new Mapping();
mapping.generatedLine = generatedLine;
@ -614,20 +628,28 @@ BasicSourceMapConsumer.prototype._parseMappings =
* we are searching for in the given "haystack" of mappings.
*/
BasicSourceMapConsumer.prototype._findMapping =
function SourceMapConsumer_findMapping(aNeedle, aMappings, aLineName,
aColumnName, aComparator, aBias) {
function SourceMapConsumer_findMapping(
aNeedle,
aMappings,
aLineName,
aColumnName,
aComparator,
aBias
) {
// To return the position we are searching for, we must first find the
// mapping for the given position and then return the opposite position it
// points to. Because the mappings are sorted, we can use binary search to
// find the best mapping.
if (aNeedle[aLineName] <= 0) {
throw new TypeError('Line must be greater than or equal to 1, got '
+ aNeedle[aLineName]);
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 '
+ aNeedle[aColumnName]);
throw new TypeError(
'Column must be greater than or equal to 0, got ' + aNeedle[aColumnName]
);
}
return binarySearch.search(aNeedle, aMappings, aComparator, aBias);
@ -688,14 +710,14 @@ BasicSourceMapConsumer.prototype.originalPositionFor =
function SourceMapConsumer_originalPositionFor(aArgs) {
var needle = {
generatedLine: util.getArg(aArgs, 'line'),
generatedColumn: util.getArg(aArgs, 'column')
generatedColumn: util.getArg(aArgs, 'column'),
};
var index = this._findMapping(
needle,
this._generatedMappings,
"generatedLine",
"generatedColumn",
'generatedLine',
'generatedColumn',
util.compareByGeneratedPositionsDeflated,
util.getArg(aArgs, 'bias', SourceMapConsumer.GREATEST_LOWER_BOUND)
);
@ -707,7 +729,11 @@ BasicSourceMapConsumer.prototype.originalPositionFor =
var source = util.getArg(mapping, 'source', null);
if (source !== null) {
source = this._sources.at(source);
source = util.computeSourceURL(this.sourceRoot, source, this._sourceMapURL);
source = util.computeSourceURL(
this.sourceRoot,
source,
this._sourceMapURL
);
}
var name = util.getArg(mapping, 'name', null);
if (name !== null) {
@ -717,7 +743,7 @@ BasicSourceMapConsumer.prototype.originalPositionFor =
source: source,
line: util.getArg(mapping, 'originalLine', null),
column: util.getArg(mapping, 'originalColumn', null),
name: name
name: name,
};
}
}
@ -726,7 +752,7 @@ BasicSourceMapConsumer.prototype.originalPositionFor =
source: null,
line: null,
column: null,
name: null
name: null,
};
};
@ -739,8 +765,12 @@ BasicSourceMapConsumer.prototype.hasContentsOfAllSources =
if (!this.sourcesContent) {
return false;
}
return this.sourcesContent.length >= this._sources.size() &&
!this.sourcesContent.some(function (sc) { return sc == null; });
return (
this.sourcesContent.length >= this._sources.size() &&
!this.sourcesContent.some(function (sc) {
return sc == null;
})
);
};
/**
@ -765,21 +795,21 @@ BasicSourceMapConsumer.prototype.sourceContentFor =
}
var url;
if (this.sourceRoot != null
&& (url = util.urlParse(this.sourceRoot))) {
if (this.sourceRoot != null && (url = util.urlParse(this.sourceRoot))) {
// XXX: file:// URIs and absolute paths lead to unexpected behavior for
// many users. We can help them out when they expect file:// URIs to
// behave like it would if they were running a local HTTP server. See
// https://bugzilla.mozilla.org/show_bug.cgi?id=885597.
var fileUriAbsPath = relativeSource.replace(/^file:\/\//, "");
if (url.scheme == "file"
&& this._sources.has(fileUriAbsPath)) {
return this.sourcesContent[this._sources.indexOf(fileUriAbsPath)]
var fileUriAbsPath = relativeSource.replace(/^file:\/\//, '');
if (url.scheme == 'file' && this._sources.has(fileUriAbsPath)) {
return this.sourcesContent[this._sources.indexOf(fileUriAbsPath)];
}
if ((!url.path || url.path == "/")
&& this._sources.has("/" + relativeSource)) {
return this.sourcesContent[this._sources.indexOf("/" + relativeSource)];
if (
(!url.path || url.path == '/') &&
this._sources.has('/' + relativeSource)
) {
return this.sourcesContent[this._sources.indexOf('/' + relativeSource)];
}
}
@ -789,8 +819,7 @@ BasicSourceMapConsumer.prototype.sourceContentFor =
// return null, so we provide a flag to exit gracefully.
if (nullOnMissing) {
return null;
}
else {
} else {
throw new Error('"' + relativeSource + '" is not in the SourceMap.');
}
};
@ -826,21 +855,21 @@ BasicSourceMapConsumer.prototype.generatedPositionFor =
return {
line: null,
column: null,
lastColumn: null
lastColumn: null,
};
}
var needle = {
source: source,
originalLine: util.getArg(aArgs, 'line'),
originalColumn: util.getArg(aArgs, 'column')
originalColumn: util.getArg(aArgs, 'column'),
};
var index = this._findMapping(
needle,
this._originalMappings,
"originalLine",
"originalColumn",
'originalLine',
'originalColumn',
util.compareByOriginalPositions,
util.getArg(aArgs, 'bias', SourceMapConsumer.GREATEST_LOWER_BOUND)
);
@ -852,7 +881,7 @@ BasicSourceMapConsumer.prototype.generatedPositionFor =
return {
line: util.getArg(mapping, 'generatedLine', null),
column: util.getArg(mapping, 'generatedColumn', null),
lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null)
lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null),
};
}
}
@ -860,7 +889,7 @@ BasicSourceMapConsumer.prototype.generatedPositionFor =
return {
line: null,
column: null,
lastColumn: null
lastColumn: null,
};
};
@ -933,7 +962,7 @@ function IndexedSourceMapConsumer(aSourceMap, aSourceMapURL) {
var lastOffset = {
line: -1,
column: 0
column: 0,
};
this._sections = sections.map(function (s) {
if (s.url) {
@ -945,8 +974,10 @@ function IndexedSourceMapConsumer(aSourceMap, aSourceMapURL) {
var offsetLine = util.getArg(offset, 'line');
var offsetColumn = util.getArg(offset, 'column');
if (offsetLine < lastOffset.line ||
(offsetLine === lastOffset.line && offsetColumn < lastOffset.column)) {
if (
offsetLine < lastOffset.line ||
(offsetLine === lastOffset.line && offsetColumn < lastOffset.column)
) {
throw new Error('Section offsets must be ordered and non-overlapping.');
}
lastOffset = offset;
@ -956,10 +987,10 @@ function IndexedSourceMapConsumer(aSourceMap, aSourceMapURL) {
// The offset fields are 0-based, but we use 1-based indices when
// encoding/decoding from VLQ.
generatedLine: offsetLine + 1,
generatedColumn: offsetColumn + 1
generatedColumn: offsetColumn + 1,
},
consumer: new SourceMapConsumer(util.getArg(s, 'map'), aSourceMapURL)
}
consumer: new SourceMapConsumer(util.getArg(s, 'map'), aSourceMapURL),
};
});
}
@ -983,7 +1014,7 @@ Object.defineProperty(IndexedSourceMapConsumer.prototype, 'sources', {
}
}
return sources;
}
},
});
/**
@ -1009,21 +1040,23 @@ IndexedSourceMapConsumer.prototype.originalPositionFor =
function IndexedSourceMapConsumer_originalPositionFor(aArgs) {
var needle = {
generatedLine: util.getArg(aArgs, 'line'),
generatedColumn: util.getArg(aArgs, 'column')
generatedColumn: util.getArg(aArgs, 'column'),
};
// Find the section containing the generated position we're trying to map
// to an original position.
var sectionIndex = binarySearch.search(needle, this._sections,
function(needle, section) {
var sectionIndex = binarySearch.search(
needle,
this._sections,
function (needle, section) {
var cmp = needle.generatedLine - section.generatedOffset.generatedLine;
if (cmp) {
return cmp;
}
return (needle.generatedColumn -
section.generatedOffset.generatedColumn);
});
return needle.generatedColumn - section.generatedOffset.generatedColumn;
}
);
var section = this._sections[sectionIndex];
if (!section) {
@ -1031,18 +1064,18 @@ IndexedSourceMapConsumer.prototype.originalPositionFor =
source: null,
line: null,
column: null,
name: null
name: null,
};
}
return section.consumer.originalPositionFor({
line: needle.generatedLine -
(section.generatedOffset.generatedLine - 1),
column: needle.generatedColumn -
(section.generatedOffset.generatedLine === needle.generatedLine
? section.generatedOffset.generatedColumn - 1
: 0),
bias: aArgs.bias
line: needle.generatedLine - (section.generatedOffset.generatedLine - 1),
column:
needle.generatedColumn -
(section.generatedOffset.generatedLine === needle.generatedLine ?
section.generatedOffset.generatedColumn - 1
: 0),
bias: aArgs.bias,
});
};
@ -1074,8 +1107,7 @@ IndexedSourceMapConsumer.prototype.sourceContentFor =
}
if (nullOnMissing) {
return null;
}
else {
} else {
throw new Error('"' + aSource + '" is not in the SourceMap.');
}
};
@ -1094,7 +1126,7 @@ IndexedSourceMapConsumer.prototype.sourceContentFor =
* 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.
* line number is 1-based.
* - column: The column number in the generated source, or null.
* The column number is 0-based.
*/
@ -1105,18 +1137,22 @@ IndexedSourceMapConsumer.prototype.generatedPositionFor =
// 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);
if (generatedPosition) {
var ret = {
line: generatedPosition.line +
line:
generatedPosition.line +
(section.generatedOffset.generatedLine - 1),
column: generatedPosition.column +
(section.generatedOffset.generatedLine === generatedPosition.line
? section.generatedOffset.generatedColumn - 1
: 0)
column:
generatedPosition.column +
(section.generatedOffset.generatedLine === generatedPosition.line ?
section.generatedOffset.generatedColumn - 1
: 0),
};
return ret;
}
@ -1124,7 +1160,7 @@ IndexedSourceMapConsumer.prototype.generatedPositionFor =
return {
line: null,
column: null
column: null,
};
};
@ -1144,8 +1180,12 @@ IndexedSourceMapConsumer.prototype._parseMappings =
var mapping = sectionMappings[j];
var source = section.consumer._sources.at(mapping.source);
if(source !== null) {
source = util.computeSourceURL(section.consumer.sourceRoot, source, this._sourceMapURL);
if (source !== null) {
source = util.computeSourceURL(
section.consumer.sourceRoot,
source,
this._sourceMapURL
);
}
this._sources.add(source);
source = this._sources.indexOf(source);
@ -1163,15 +1203,16 @@ IndexedSourceMapConsumer.prototype._parseMappings =
// generated file.
var adjustedMapping = {
source: source,
generatedLine: mapping.generatedLine +
(section.generatedOffset.generatedLine - 1),
generatedColumn: mapping.generatedColumn +
(section.generatedOffset.generatedLine === mapping.generatedLine
? section.generatedOffset.generatedColumn - 1
generatedLine:
mapping.generatedLine + (section.generatedOffset.generatedLine - 1),
generatedColumn:
mapping.generatedColumn +
(section.generatedOffset.generatedLine === mapping.generatedLine ?
section.generatedOffset.generatedColumn - 1
: 0),
originalLine: mapping.originalLine,
originalColumn: mapping.originalColumn,
name: name
name: name,
};
this.__generatedMappings.push(adjustedMapping);
@ -1181,7 +1222,10 @@ IndexedSourceMapConsumer.prototype._parseMappings =
}
}
quickSort(this.__generatedMappings, util.compareByGeneratedPositionsDeflated);
quickSort(
this.__generatedMappings,
util.compareByGeneratedPositionsDeflated
);
quickSort(this.__originalMappings, util.compareByOriginalPositions);
};