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

Method fromSourceMap

lib/source-map-generator.js:40–88  ·  view source on GitHub ↗

* Creates a new SourceMapGenerator based on a SourceMapConsumer * * @param aSourceMapConsumer The SourceMap.

(aSourceMapConsumer)

Source from the content-addressed store, hash-verified

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)) {
79 generator._sources.add(sourceRelative);
80 }
81
82 const content = aSourceMapConsumer.sourceContentFor(sourceFile);
83 if (content != null) {
84 generator.setSourceContent(sourceFile, content);
85 }
86 });
87 return generator;
88 }
89
90 /**
91 * Add a single mapping from original source line and column to the generated

Callers

nothing calls this directly

Calls 6

addMappingMethod · 0.95
setSourceContentMethod · 0.95
hasMethod · 0.80
eachMappingMethod · 0.65
sourceContentForMethod · 0.65
addMethod · 0.45

Tested by

no test coverage detected