MCPcopy
hub / github.com/mozilla/source-map / SourceMapGenerator

Class SourceMapGenerator

lib/source-map-generator.js:21–436  ·  view source on GitHub ↗

* An instance of the SourceMapGenerator represents a source map which is * being built incrementally. You may pass an object with the following * properties: * * - file: The filename of the generated source. * - sourceRoot: A root for all relative URLs in this source map.

Source from the content-addressed store, hash-verified

19 * - sourceRoot: A root for all relative URLs in this source map.
20 */
21class SourceMapGenerator {
22 constructor(aArgs) {
23 if (!aArgs) {
24 aArgs = {};
25 }
26 this._file = util.getArg(aArgs, "file", null);
27 this._sourceRoot = util.getArg(aArgs, "sourceRoot", null);
28 this._skipValidation = util.getArg(aArgs, "skipValidation", false);
29 this._sources = new ArraySet();
30 this._names = new ArraySet();
31 this._mappings = new MappingList();
32 this._sourcesContents = null;
33 }
34
35 /**
36 * Creates a new SourceMapGenerator based on a SourceMapConsumer
37 *
38 * @param aSourceMapConsumer The SourceMap.
39 */
40 static fromSourceMap(aSourceMapConsumer) {
41 const sourceRoot = aSourceMapConsumer.sourceRoot;
42 const generator = new SourceMapGenerator({
43 file: aSourceMapConsumer.file,
44 sourceRoot,
45 });
46 aSourceMapConsumer.eachMapping(function (mapping) {
47 const newMapping = {
48 generated: {
49 line: mapping.generatedLine,
50 column: mapping.generatedColumn,
51 },
52 };
53
54 if (mapping.source != null) {
55 newMapping.source = mapping.source;
56 if (sourceRoot != null) {
57 newMapping.source = util.relative(sourceRoot, newMapping.source);
58 }
59
60 newMapping.original = {
61 line: mapping.originalLine,
62 column: mapping.originalColumn,
63 };
64
65 if (mapping.name != null) {
66 newMapping.name = mapping.name;
67 }
68 }
69
70 generator.addMapping(newMapping);
71 });
72 aSourceMapConsumer.sources.forEach(function (sourceFile) {
73 let sourceRelative = sourceFile;
74 if (sourceRoot != null) {
75 sourceRelative = util.relative(sourceRoot, sourceFile);
76 }
77
78 if (!generator._sources.has(sourceRelative)) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…