MCPcopy Create free account
hub / github.com/ptmt/react-native-macos / combineSourceMaps

Function combineSourceMaps

local-cli/bundle/output/unbundle/util.js:52–113  ·  view source on GitHub ↗
({
  moduleGroups,
  modules,
  withCustomOffsets,
}: CombineSourceMapsOptions)

Source from the content-addressed store, hash-verified

50};
51
52function combineSourceMaps({
53 moduleGroups,
54 modules,
55 withCustomOffsets,
56}: CombineSourceMapsOptions): IndexMap {
57 const offsets = [];
58 const sections = [];
59 const sourceMap: IndexMap = withCustomOffsets
60 ? {sections, version: 3, x_facebook_offsets: offsets}
61 : {sections, version: 3};
62
63 let line = 0;
64 modules.forEach(moduleTransport => {
65 const {code, id, name} = moduleTransport;
66 let column = 0;
67 let hasOffset = false;
68 let group;
69 let groupLines = 0;
70 let {map} = moduleTransport;
71
72 if (withCustomOffsets) {
73 if (moduleGroups && moduleGroups.modulesInGroups.has(id)) {
74 // this is a module appended to another module
75 return;
76 }
77
78
79 group = moduleGroups && moduleGroups.groups.get(id);
80 if (group && moduleGroups) {
81 const {modulesById} = moduleGroups;
82 const otherModules: Array<ModuleTransportLike> =
83 Array.from(group || [])
84 .map(moduleId => modulesById.get(moduleId))
85 .filter(Boolean); // needed to appease flow
86 otherModules.forEach(m => {
87 groupLines += countLines(m.code);
88 });
89 map = combineSourceMaps({
90 modules: [moduleTransport].concat(otherModules),
91 });
92 }
93
94 hasOffset = id != null;
95 column = wrapperEnd(code);
96 }
97
98 invariant(
99 !Array.isArray(map),
100 'Random Access Bundle source maps cannot be built from raw mappings',
101 );
102 sections.push(Section(line, column, map || lineToLineSourceMap(code, name)));
103 if (hasOffset) {
104 offsets[id] = line;
105 for (const moduleId of group || []) {
106 offsets[moduleId] = line;
107 }
108 }
109 line += countLines(code) + groupLines;

Calls 10

wrapperEndFunction · 0.85
invariantFunction · 0.85
SectionFunction · 0.85
lineToLineSourceMapFunction · 0.85
hasMethod · 0.80
fromMethod · 0.80
pushMethod · 0.80
countLinesFunction · 0.70
getMethod · 0.45
filterMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…