MCPcopy
hub / github.com/rollup/rollup / collapseSourcemaps

Function collapseSourcemaps

src/utils/collapseSourcemaps.ts:202–244  ·  view source on GitHub ↗
(
	file: string,
	map: Omit<DecodedSourceMap, 'sourcesContent'> & { sourcesContent: (string | null)[] },
	modules: readonly Module[],
	bundleSourcemapChain: readonly DecodedSourceMapOrMissing[],
	excludeContent: boolean | undefined,
	log: LogHandler
)

Source from the content-addressed store, hash-verified

200}
201
202export function collapseSourcemaps(
203 file: string,
204 map: Omit<DecodedSourceMap, 'sourcesContent'> & { sourcesContent: (string | null)[] },
205 modules: readonly Module[],
206 bundleSourcemapChain: readonly DecodedSourceMapOrMissing[],
207 excludeContent: boolean | undefined,
208 log: LogHandler
209): SourceMap {
210 const linkMap = getLinkMap(log);
211 const moduleSources = modules
212 .filter(module => !module.excludeFromSourcemap)
213 .map(module =>
214 getCollapsedSourcemap(
215 module.id,
216 module.originalCode,
217 module.originalSourcemap,
218 module.sourcemapChain,
219 linkMap
220 )
221 );
222
223 const link = new Link(map, moduleSources);
224 const source = bundleSourcemapChain.reduce(linkMap, link);
225 let { sources, sourcesContent, names, mappings } = source.traceMappings();
226
227 if (file) {
228 const directory = dirname(file);
229 sources = sources.map((source: string) => relative(directory, source));
230 file = basename(file);
231 }
232
233 for (const module of modules) {
234 resetSourcemapCache(module.originalSourcemap, module.sourcemapChain);
235 }
236
237 return new SourceMap({
238 file,
239 mappings,
240 names,
241 sources,
242 sourcesContent: excludeContent ? undefined : sourcesContent
243 });
244}
245
246export function collapseSourcemap(
247 id: string,

Callers 1

transformChunkFunction · 0.90

Calls 7

dirnameFunction · 0.90
relativeFunction · 0.90
basenameFunction · 0.90
resetSourcemapCacheFunction · 0.90
getLinkMapFunction · 0.85
getCollapsedSourcemapFunction · 0.85
traceMappingsMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…