1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const source_map_1 = require("source-map");
|
4 | function merge(oldMap, newMap) {
|
5 | if (!oldMap)
|
6 | return newMap;
|
7 | if (!newMap)
|
8 | return oldMap;
|
9 | const oldMapConsumer = new source_map_1.SourceMapConsumer(oldMap);
|
10 | const newMapConsumer = new source_map_1.SourceMapConsumer(newMap);
|
11 | const mergedMapGenerator = new source_map_1.SourceMapGenerator();
|
12 |
|
13 | newMapConsumer.eachMapping((mapping) => {
|
14 |
|
15 |
|
16 | if (mapping.originalLine == null)
|
17 | return;
|
18 | const origPosInOldMap = oldMapConsumer.originalPositionFor({
|
19 | line: mapping.originalLine,
|
20 | column: mapping.originalColumn
|
21 | });
|
22 | if (origPosInOldMap.source == null)
|
23 | return;
|
24 | mergedMapGenerator.addMapping({
|
25 | original: {
|
26 | line: origPosInOldMap.line,
|
27 | column: origPosInOldMap.column
|
28 | },
|
29 | generated: {
|
30 | line: mapping.generatedLine,
|
31 | column: mapping.generatedColumn
|
32 | },
|
33 | source: origPosInOldMap.source,
|
34 | name: origPosInOldMap.name
|
35 | });
|
36 | });
|
37 | const maps = [oldMap, newMap];
|
38 | const consumers = [oldMapConsumer, newMapConsumer];
|
39 | consumers.forEach((consumer, index) => {
|
40 | maps[index].sources.forEach(sourceFile => {
|
41 | const sourceContent = consumer.sourceContentFor(sourceFile, true);
|
42 | if (sourceContent !== null) {
|
43 | mergedMapGenerator.setSourceContent(sourceFile, sourceContent);
|
44 | }
|
45 | });
|
46 | });
|
47 | return JSON.parse(mergedMapGenerator.toString());
|
48 | }
|
49 | exports.merge = merge;
|