Phase 3: - Declare PowerPointApi 1.5 and replace template manifest values - Remove the dead command pipeline and the tracked Babel/polyfill setup - Extract constants, status/settings contexts, PowerPoint services, and an error boundary - Build with ES2020 and strict TypeScript; hash production assets and drop prod source maps - Add Vitest tests, CI, LICENSE, Node 20 pinning, and prune unused dependencies - Correct the README, user guide, developer guide, and audit notes Phase 4: - Add a persisted 16:9/4:3 slide size setting used by all layout tools - Add dark mode with Office/system theme detection - Make sections collapsible and move to accessible Fluent controls - Announce status through aria-live and add semantic status icons - Add a progress counter with cooperative cancellation and a Stop button - Update the tracked dependency tree for the pruned packages
This commit is contained in:
1 parent
e57258afe9
commit
89989c04e9
6211 files changed
+7028
-274819
No files matched your search
+317
-191
@@ -11,6 +11,14 @@ var ArraySet = require('./array-set').ArraySet;
|
||||
var base64VLQ = require('./base64-vlq');
|
||||
var quickSort = require('./quick-sort').quickSort;
|
||||
|
||||
// Upper bound for a section's `offset.line` in an indexed source map. A flat
|
||||
// map spends one ';' per generated line, so a tiny indexed map with a huge
|
||||
// offset.line turns into a huge amount of work and memory once its mappings
|
||||
// are copied into a SourceMapGenerator (CVE-2026-93749). Ten million lines is
|
||||
// far beyond any real generated file. Columns are VLQ-encoded as deltas and
|
||||
// don't amplify, so they only need to be valid integers.
|
||||
var MAX_SECTION_OFFSET_LINE = 1e7;
|
||||
|
||||
function SourceMapConsumer(aSourceMap, aSourceMapURL) {
|
||||
var sourceMap = aSourceMap;
|
||||
if (typeof aSourceMap === 'string') {
|
||||
@@ -22,9 +30,9 @@ function SourceMapConsumer(aSourceMap, 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 +79,7 @@ Object.defineProperty(SourceMapConsumer.prototype, '_generatedMappings', {
|
||||
}
|
||||
|
||||
return this.__generatedMappings;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
SourceMapConsumer.prototype.__originalMappings = null;
|
||||
@@ -84,13 +92,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 +108,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 +140,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 +159,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 +168,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 +206,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 +216,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];
|
||||
|
||||
@@ -221,14 +231,20 @@ SourceMapConsumer.prototype.allGeneratedPositionsFor =
|
||||
var originalLine = mapping.originalLine;
|
||||
|
||||
// Iterate until either we run out of mappings, or we run into
|
||||
// a mapping for a different line than the one we found. Since
|
||||
// mappings are sorted, this is guaranteed to find all mappings for
|
||||
// the line we found.
|
||||
while (mapping && mapping.originalLine === originalLine) {
|
||||
// a mapping for a different source or line than the one we found.
|
||||
// Since mappings are sorted, this is guaranteed to find all mappings
|
||||
// for the line we found. The source check also stops the search from
|
||||
// continuing into the next source's mappings when this source has
|
||||
// none at or after the requested line.
|
||||
while (
|
||||
mapping &&
|
||||
mapping.source === needle.source &&
|
||||
mapping.originalLine === originalLine
|
||||
) {
|
||||
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];
|
||||
@@ -237,16 +253,19 @@ SourceMapConsumer.prototype.allGeneratedPositionsFor =
|
||||
var originalColumn = mapping.originalColumn;
|
||||
|
||||
// Iterate until either we run out of mappings, or we run into
|
||||
// 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) {
|
||||
// a mapping for a different source or 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.source === needle.source &&
|
||||
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,7 +349,9 @@ 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)
|
||||
return sourceRoot &&
|
||||
util.isAbsolute(sourceRoot) &&
|
||||
util.isAbsolute(source)
|
||||
? util.relative(sourceRoot, source)
|
||||
: source;
|
||||
});
|
||||
@@ -360,7 +381,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 +412,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 +483,7 @@ BasicSourceMapConsumer.prototype._version = 3;
|
||||
Object.defineProperty(BasicSourceMapConsumer.prototype, 'sources', {
|
||||
get: function () {
|
||||
return this._absoluteSources.slice();
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -527,11 +558,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;
|
||||
|
||||
@@ -601,12 +630,26 @@ BasicSourceMapConsumer.prototype._parseMappings =
|
||||
sortGenerated(generatedMappings, subarrayStart);
|
||||
this.__generatedMappings = generatedMappings;
|
||||
|
||||
// Sources without mappings have a null bucket. Leave those out, or the
|
||||
// nulls end up in __originalMappings.
|
||||
var sourceBuckets = [];
|
||||
for (var i = 0; i < originalMappings.length; i++) {
|
||||
if (originalMappings[i] != null) {
|
||||
quickSort(originalMappings[i], util.compareByOriginalPositionsNoSource);
|
||||
sourceBuckets.push(originalMappings[i]);
|
||||
}
|
||||
}
|
||||
this.__originalMappings = [].concat(...originalMappings);
|
||||
|
||||
// Spreading every bucket into a single concat call overflows the stack
|
||||
// once a few hundred thousand sources have mappings, so concat at most
|
||||
// 4096 buckets at a time. Most maps have fewer, and need a single call.
|
||||
var sortedOriginalMappings = [];
|
||||
for (var b = 0; b < sourceBuckets.length; b += 4096) {
|
||||
sortedOriginalMappings = sortedOriginalMappings.concat(
|
||||
...sourceBuckets.slice(b, b + 4096)
|
||||
);
|
||||
}
|
||||
this.__originalMappings = sortedOriginalMappings;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -614,20 +657,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 +739,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 +758,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 +772,7 @@ BasicSourceMapConsumer.prototype.originalPositionFor =
|
||||
source: source,
|
||||
line: util.getArg(mapping, 'originalLine', null),
|
||||
column: util.getArg(mapping, 'originalColumn', null),
|
||||
name: name
|
||||
name: name,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -726,7 +781,7 @@ BasicSourceMapConsumer.prototype.originalPositionFor =
|
||||
source: null,
|
||||
line: null,
|
||||
column: null,
|
||||
name: null
|
||||
name: null,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -739,8 +794,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 +824,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 +848,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 +884,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 +910,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 +918,7 @@ BasicSourceMapConsumer.prototype.generatedPositionFor =
|
||||
return {
|
||||
line: null,
|
||||
column: null,
|
||||
lastColumn: null
|
||||
lastColumn: null,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -933,8 +991,9 @@ function IndexedSourceMapConsumer(aSourceMap, aSourceMapURL) {
|
||||
|
||||
var lastOffset = {
|
||||
line: -1,
|
||||
column: 0
|
||||
column: 0,
|
||||
};
|
||||
var maxOffsetLine = 0;
|
||||
this._sections = sections.map(function (s) {
|
||||
if (s.url) {
|
||||
// The url field will require support for asynchronicity.
|
||||
@@ -945,22 +1004,68 @@ 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 (!isValidOffset(offsetLine) || !isValidOffset(offsetColumn)) {
|
||||
throw new Error(
|
||||
'Section offset line and column must be non-negative integers.'
|
||||
);
|
||||
}
|
||||
if (offsetLine > MAX_SECTION_OFFSET_LINE) {
|
||||
throw new Error(
|
||||
'Section offset line must not exceed ' + MAX_SECTION_OFFSET_LINE + '.'
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
offsetLine < lastOffset.line ||
|
||||
(offsetLine === lastOffset.line && offsetColumn < lastOffset.column)
|
||||
) {
|
||||
throw new Error('Section offsets must be ordered and non-overlapping.');
|
||||
}
|
||||
lastOffset = offset;
|
||||
|
||||
var consumer = new SourceMapConsumer(util.getArg(s, 'map'), aSourceMapURL);
|
||||
|
||||
// Offsets of a nested indexed map add up with this one, so apply the
|
||||
// bound to the total.
|
||||
var totalOffsetLine = offsetLine + (consumer._maxOffsetLine || 0);
|
||||
if (totalOffsetLine > MAX_SECTION_OFFSET_LINE) {
|
||||
throw new Error(
|
||||
'Section offset line must not exceed ' +
|
||||
MAX_SECTION_OFFSET_LINE +
|
||||
', including offsets of nested sections.'
|
||||
);
|
||||
}
|
||||
if (totalOffsetLine > maxOffsetLine) {
|
||||
maxOffsetLine = totalOffsetLine;
|
||||
}
|
||||
|
||||
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
|
||||
generatedColumn: offsetColumn + 1,
|
||||
},
|
||||
consumer: new SourceMapConsumer(util.getArg(s, 'map'), aSourceMapURL)
|
||||
}
|
||||
consumer: consumer,
|
||||
};
|
||||
});
|
||||
|
||||
// The largest offset.line of any section, including nested sections.
|
||||
this._maxOffsetLine = maxOffsetLine;
|
||||
}
|
||||
|
||||
/**
|
||||
* Section offsets come from untrusted input and are used as line/column
|
||||
* numbers, so only accept non-negative safe integers (rejects NaN, Infinity,
|
||||
* strings, fractions, etc).
|
||||
*/
|
||||
function isValidOffset(aValue) {
|
||||
return (
|
||||
typeof aValue === 'number' &&
|
||||
aValue >= 0 &&
|
||||
aValue <= 9007199254740991 && // Number.MAX_SAFE_INTEGER
|
||||
Math.floor(aValue) === aValue
|
||||
);
|
||||
}
|
||||
|
||||
IndexedSourceMapConsumer.prototype = Object.create(SourceMapConsumer.prototype);
|
||||
@@ -978,12 +1083,16 @@ 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++) {
|
||||
sources.push(this._sections[i].consumer.sources[j]);
|
||||
// Read the getter once per section: for a nested indexed map it is
|
||||
// itself this getter, and re-reading it per item is exponential in the
|
||||
// nesting depth (CVE-2026-93749).
|
||||
var sectionSources = this._sections[i].consumer.sources;
|
||||
for (var j = 0; j < sectionSources.length; j++) {
|
||||
sources.push(sectionSources[j]);
|
||||
}
|
||||
}
|
||||
return sources;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -1009,21 +1118,27 @@ 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);
|
||||
});
|
||||
// The needle's column is 0-based, generatedOffset.generatedColumn is
|
||||
// 1-based.
|
||||
return (
|
||||
needle.generatedColumn - (section.generatedOffset.generatedColumn - 1)
|
||||
);
|
||||
}
|
||||
);
|
||||
var section = this._sections[sectionIndex];
|
||||
|
||||
if (!section) {
|
||||
@@ -1031,18 +1146,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 -
|
||||
line: needle.generatedLine - (section.generatedOffset.generatedLine - 1),
|
||||
column:
|
||||
needle.generatedColumn -
|
||||
(section.generatedOffset.generatedLine === needle.generatedLine
|
||||
? section.generatedOffset.generatedColumn - 1
|
||||
: 0),
|
||||
bias: aArgs.bias
|
||||
? section.generatedOffset.generatedColumn - 1
|
||||
: 0),
|
||||
bias: aArgs.bias,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1074,59 +1189,61 @@ IndexedSourceMapConsumer.prototype.sourceContentFor =
|
||||
}
|
||||
if (nullOnMissing) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
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];
|
||||
// SourceMapConsumer.prototype.allGeneratedPositionsFor and
|
||||
// BasicSourceMapConsumer.prototype.generatedPositionFor search
|
||||
// this._originalMappings, which holds the mappings of every section with
|
||||
// their generated positions already shifted by the section offset. They need
|
||||
// these two methods.
|
||||
|
||||
// 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) {
|
||||
continue;
|
||||
}
|
||||
var generatedPosition = section.consumer.generatedPositionFor(aArgs);
|
||||
if (generatedPosition) {
|
||||
var ret = {
|
||||
line: generatedPosition.line +
|
||||
(section.generatedOffset.generatedLine - 1),
|
||||
column: generatedPosition.column +
|
||||
(section.generatedOffset.generatedLine === generatedPosition.line
|
||||
? section.generatedOffset.generatedColumn - 1
|
||||
: 0)
|
||||
};
|
||||
return ret;
|
||||
}
|
||||
/**
|
||||
* Returns the index of a source in this._sources, which holds the URLs of
|
||||
* the sources that have mappings, or -1. Accepts any name a section
|
||||
* accepts: relative to the section's sourceRoot or a URL from `sources`.
|
||||
*/
|
||||
IndexedSourceMapConsumer.prototype._findSourceIndex = function (aSource) {
|
||||
// this._sources is filled in by _parseMappings, which runs on first access
|
||||
// to the mappings.
|
||||
this._generatedMappings;
|
||||
|
||||
for (var i = 0; i < this._sections.length; i++) {
|
||||
var consumer = this._sections[i].consumer;
|
||||
var index = consumer._findSourceIndex(aSource);
|
||||
if (index === -1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return {
|
||||
line: null,
|
||||
column: null
|
||||
};
|
||||
};
|
||||
// The same URL _parseMappings stores the source under.
|
||||
var url = util.computeSourceURL(
|
||||
consumer.sourceRoot,
|
||||
consumer._sources.at(index),
|
||||
this._sourceMapURL
|
||||
);
|
||||
if (this._sources.has(url)) {
|
||||
return this._sources.indexOf(url);
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
};
|
||||
|
||||
IndexedSourceMapConsumer.prototype._findMapping =
|
||||
BasicSourceMapConsumer.prototype._findMapping;
|
||||
|
||||
// Searching the mappings of all sections at once finds the closest mapping
|
||||
// across sections, the same as for the map without sections.
|
||||
IndexedSourceMapConsumer.prototype.generatedPositionFor =
|
||||
BasicSourceMapConsumer.prototype.generatedPositionFor;
|
||||
|
||||
// Computes the spans on this._generatedMappings, the offset-shifted mappings
|
||||
// of all sections, which the lookups above return. A mapping's span ends
|
||||
// where the next mapping starts, even if that one is in the next section.
|
||||
IndexedSourceMapConsumer.prototype.computeColumnSpans =
|
||||
BasicSourceMapConsumer.prototype.computeColumnSpans;
|
||||
|
||||
/**
|
||||
* Parse the mappings in a string in to a data structure which we can easily
|
||||
@@ -1144,8 +1261,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);
|
||||
@@ -1160,18 +1281,20 @@ IndexedSourceMapConsumer.prototype._parseMappings =
|
||||
// The mappings coming from the consumer for the section have
|
||||
// generated positions relative to the start of the section, so we
|
||||
// need to offset them to be relative to the start of the concatenated
|
||||
// generated file.
|
||||
// generated file. The column offset only applies to the section's
|
||||
// first line.
|
||||
var adjustedMapping = {
|
||||
source: source,
|
||||
generatedLine: mapping.generatedLine +
|
||||
(section.generatedOffset.generatedLine - 1),
|
||||
generatedColumn: mapping.generatedColumn +
|
||||
(section.generatedOffset.generatedLine === mapping.generatedLine
|
||||
? section.generatedOffset.generatedColumn - 1
|
||||
: 0),
|
||||
generatedLine:
|
||||
mapping.generatedLine + (section.generatedOffset.generatedLine - 1),
|
||||
generatedColumn:
|
||||
mapping.generatedColumn +
|
||||
(mapping.generatedLine === 1
|
||||
? section.generatedOffset.generatedColumn - 1
|
||||
: 0),
|
||||
originalLine: mapping.originalLine,
|
||||
originalColumn: mapping.originalColumn,
|
||||
name: name
|
||||
name: name,
|
||||
};
|
||||
|
||||
this.__generatedMappings.push(adjustedMapping);
|
||||
@@ -1181,7 +1304,10 @@ IndexedSourceMapConsumer.prototype._parseMappings =
|
||||
}
|
||||
}
|
||||
|
||||
quickSort(this.__generatedMappings, util.compareByGeneratedPositionsDeflated);
|
||||
quickSort(
|
||||
this.__generatedMappings,
|
||||
util.compareByGeneratedPositionsDeflated
|
||||
);
|
||||
quickSort(this.__originalMappings, util.compareByOriginalPositions);
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user