summaryrefslogtreecommitdiff
path: root/node_modules/source-map/lib/source-map-generator.js
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2023-10-14 22:41:29 +0800
committerlittleblack111 <littleblack11111@gmail.com>2023-10-14 22:41:29 +0800
commitaf842b8362016d0ac572de8c5810b67258df8bd7 (patch)
treef904a9294f8d1780a60e6630cf6fd4b494aa7878 /node_modules/source-map/lib/source-map-generator.js
parentbd9536ee06890c07456337fec3e7a916e03d8f6e (diff)
updates
Diffstat (limited to 'node_modules/source-map/lib/source-map-generator.js')
-rw-r--r--node_modules/source-map/lib/source-map-generator.js326
1 files changed, 169 insertions, 157 deletions
diff --git a/node_modules/source-map/lib/source-map-generator.js b/node_modules/source-map/lib/source-map-generator.js
index 8111e061..508bcfbb 100644
--- a/node_modules/source-map/lib/source-map-generator.js
+++ b/node_modules/source-map/lib/source-map-generator.js
@@ -5,10 +5,10 @@
* http://opensource.org/licenses/BSD-3-Clause
*/
-const base64VLQ = require("./base64-vlq");
-const util = require("./util");
-const ArraySet = require("./array-set").ArraySet;
-const MappingList = require("./mapping-list").MappingList;
+var base64VLQ = require('./base64-vlq');
+var util = require('./util');
+var ArraySet = require('./array-set').ArraySet;
+var MappingList = require('./mapping-list').MappingList;
/**
* An instance of the SourceMapGenerator represents a source map which is
@@ -18,33 +18,35 @@ const MappingList = require("./mapping-list").MappingList;
* - file: The filename of the generated source.
* - sourceRoot: A root for all relative URLs in this source map.
*/
-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;
+function SourceMapGenerator(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;
+}
+
+SourceMapGenerator.prototype._version = 3;
- /**
- * Creates a new SourceMapGenerator based on a SourceMapConsumer
- *
- * @param aSourceMapConsumer The SourceMap.
- */
- static fromSourceMap(aSourceMapConsumer) {
- const sourceRoot = aSourceMapConsumer.sourceRoot;
- const generator = new SourceMapGenerator({
+/**
+ * Creates a new SourceMapGenerator based on a SourceMapConsumer
+ *
+ * @param aSourceMapConsumer The SourceMap.
+ */
+SourceMapGenerator.fromSourceMap =
+ function SourceMapGenerator_fromSourceMap(aSourceMapConsumer) {
+ var sourceRoot = aSourceMapConsumer.sourceRoot;
+ var generator = new SourceMapGenerator({
file: aSourceMapConsumer.file,
- sourceRoot
+ sourceRoot: sourceRoot
});
- aSourceMapConsumer.eachMapping(function(mapping) {
- const newMapping = {
+ aSourceMapConsumer.eachMapping(function (mapping) {
+ var newMapping = {
generated: {
line: mapping.generatedLine,
column: mapping.generatedColumn
@@ -69,8 +71,8 @@ class SourceMapGenerator {
generator.addMapping(newMapping);
});
- aSourceMapConsumer.sources.forEach(function(sourceFile) {
- let sourceRelative = sourceFile;
+ aSourceMapConsumer.sources.forEach(function (sourceFile) {
+ var sourceRelative = sourceFile;
if (sourceRoot !== null) {
sourceRelative = util.relative(sourceRoot, sourceFile);
}
@@ -79,29 +81,30 @@ class SourceMapGenerator {
generator._sources.add(sourceRelative);
}
- const content = aSourceMapConsumer.sourceContentFor(sourceFile);
+ var content = aSourceMapConsumer.sourceContentFor(sourceFile);
if (content != null) {
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.
- */
- 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);
+/**
+ * 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);
if (!this._skipValidation) {
this._validateMapping(generated, original, source, name);
@@ -126,16 +129,17 @@ class SourceMapGenerator {
generatedColumn: generated.column,
originalLine: original != null && original.line,
originalColumn: original != null && original.column,
- source,
- name
+ source: source,
+ name: name
});
- }
+ };
- /**
- * Set the source content for a source file.
- */
- setSourceContent(aSourceFile, aSourceContent) {
- let source = aSourceFile;
+/**
+ * Set the source content for a source file.
+ */
+SourceMapGenerator.prototype.setSourceContent =
+ function SourceMapGenerator_setSourceContent(aSourceFile, aSourceContent) {
+ var source = aSourceFile;
if (this._sourceRoot != null) {
source = util.relative(this._sourceRoot, source);
}
@@ -155,53 +159,52 @@ class SourceMapGenerator {
this._sourcesContents = null;
}
}
- }
+ };
- /**
- * 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;
+/**
+ * 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;
// If aSourceFile is omitted, we will use the file property of the SourceMap
if (aSourceFile == null) {
if (aSourceMapConsumer.file == 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.'
);
}
sourceFile = aSourceMapConsumer.file;
}
- const sourceRoot = this._sourceRoot;
+ var sourceRoot = this._sourceRoot;
// Make "sourceFile" relative if an absolute Url is passed.
if (sourceRoot != null) {
sourceFile = util.relative(sourceRoot, sourceFile);
}
// Applying the SourceMap can add and remove items from the sources and
// the names array.
- const newSources = this._mappings.toArray().length > 0
- ? new ArraySet()
- : this._sources;
- const newNames = new ArraySet();
+ var newSources = new ArraySet();
+ var 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.
- const original = aSourceMapConsumer.originalPositionFor({
+ var original = aSourceMapConsumer.originalPositionFor({
line: mapping.originalLine,
column: mapping.originalColumn
});
@@ -209,7 +212,7 @@ class SourceMapGenerator {
// Copy mapping
mapping.source = original.source;
if (aSourceMapPath != null) {
- mapping.source = util.join(aSourceMapPath, mapping.source);
+ mapping.source = util.join(aSourceMapPath, mapping.source)
}
if (sourceRoot != null) {
mapping.source = util.relative(sourceRoot, mapping.source);
@@ -222,12 +225,12 @@ class SourceMapGenerator {
}
}
- const source = mapping.source;
+ var source = mapping.source;
if (source != null && !newSources.has(source)) {
newSources.add(source);
}
- const name = mapping.name;
+ var name = mapping.name;
if (name != null && !newNames.has(name)) {
newNames.add(name);
}
@@ -237,99 +240,107 @@ class SourceMapGenerator {
this._names = newNames;
// Copy sourcesContents of applied map.
- aSourceMapConsumer.sources.forEach(function(srcFile) {
- const content = aSourceMapConsumer.sourceContentFor(srcFile);
+ aSourceMapConsumer.sources.forEach(function (sourceFile) {
+ var content = aSourceMapConsumer.sourceContentFor(sourceFile);
if (content != null) {
if (aSourceMapPath != null) {
- srcFile = util.join(aSourceMapPath, srcFile);
+ sourceFile = util.join(aSourceMapPath, sourceFile);
}
if (sourceRoot != null) {
- srcFile = util.relative(sourceRoot, srcFile);
+ sourceFile = util.relative(sourceRoot, sourceFile);
}
- this.setSourceContent(srcFile, content);
+ this.setSourceContent(sourceFile, 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.
- */
- _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.
+ */
+SourceMapGenerator.prototype._validateMapping =
+ function SourceMapGenerator_validateMapping(aGenerated, aOriginal, aSource,
+ aName) {
// When aOriginal is truthy but has empty values for .line and .column,
// it is most likely a programmer error. In this case we throw a very
// specific error message to try to guide them the right way.
// 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.
-
- } else if (aGenerated && "line" in aGenerated && "column" in aGenerated
- && aOriginal && "line" in aOriginal && "column" in aOriginal
+ return;
+ }
+ else if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
+ && aOriginal && 'line' in aOriginal && 'column' in aOriginal
&& aGenerated.line > 0 && aGenerated.column >= 0
&& aOriginal.line > 0 && aOriginal.column >= 0
&& aSource) {
// Cases 2 and 3.
-
- } else {
- throw new Error("Invalid mapping: " + JSON.stringify({
+ return;
+ }
+ else {
+ throw new Error('Invalid mapping: ' + JSON.stringify({
generated: aGenerated,
source: aSource,
original: aOriginal,
name: aName
}));
}
- }
+ };
- /**
- * 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;
-
- const mappings = this._mappings.toArray();
- for (let i = 0, len = mappings.length; i < len; i++) {
+/**
+ * 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;
+
+ var mappings = this._mappings.toArray();
+ for (var i = 0, len = mappings.length; i < len; i++) {
mapping = mappings[i];
- next = "";
+ next = ''
if (mapping.generatedLine !== previousGeneratedLine) {
previousGeneratedColumn = 0;
while (mapping.generatedLine !== previousGeneratedLine) {
- next += ";";
+ next += ';';
previousGeneratedLine++;
}
- } else if (i > 0) {
- if (!util.compareByGeneratedPositionsInflated(mapping, mappings[i - 1])) {
- continue;
+ }
+ else {
+ if (i > 0) {
+ if (!util.compareByGeneratedPositionsInflated(mapping, mappings[i - 1])) {
+ continue;
+ }
+ next += ',';
}
- next += ",";
}
next += base64VLQ.encode(mapping.generatedColumn
@@ -361,28 +372,30 @@ class SourceMapGenerator {
}
return result;
- }
+ };
- _generateSourcesContent(aSources, aSourceRoot) {
- return aSources.map(function(source) {
+SourceMapGenerator.prototype._generateSourcesContent =
+ function SourceMapGenerator_generateSourcesContent(aSources, aSourceRoot) {
+ return aSources.map(function (source) {
if (!this._sourcesContents) {
return null;
}
if (aSourceRoot != null) {
source = util.relative(aSourceRoot, source);
}
- const key = util.toSetString(source);
+ var key = util.toSetString(source);
return Object.prototype.hasOwnProperty.call(this._sourcesContents, key)
? this._sourcesContents[key]
: null;
}, this);
- }
+ };
- /**
- * Externalize the source map.
- */
- toJSON() {
- const map = {
+/**
+ * Externalize the source map.
+ */
+SourceMapGenerator.prototype.toJSON =
+ function SourceMapGenerator_toJSON() {
+ var map = {
version: this._version,
sources: this._sources.toArray(),
names: this._names.toArray(),
@@ -399,15 +412,14 @@ class SourceMapGenerator {
}
return map;
- }
+ };
- /**
- * Render the source map being generated to a string.
- */
- toString() {
+/**
+ * Render the source map being generated to a string.
+ */
+SourceMapGenerator.prototype.toString =
+ function SourceMapGenerator_toString() {
return JSON.stringify(this.toJSON());
- }
-}
+ };
-SourceMapGenerator.prototype._version = 3;
exports.SourceMapGenerator = SourceMapGenerator;