MCPcopy
hub / github.com/webpack/webpack / contextifySourceMap

Function contextifySourceMap

lib/NormalModule.js:654–680  ·  view source on GitHub ↗
(context, sourceMap, associatedObjectForCache)

Source from the content-addressed store, hash-verified

652 * @returns {string | RawSourceMap} new source map
653 */
654const contextifySourceMap = (context, sourceMap, associatedObjectForCache) => {
655 if (typeof sourceMap === "string" || !Array.isArray(sourceMap.sources)) {
656 return sourceMap;
657 }
658 const { sourceRoot } = sourceMap;
659 /** @type {(source: string) => string} */
660 const mapper = !sourceRoot
661 ? (source) => source
662 : sourceRoot.endsWith("/")
663 ? (source) =>
664 source.startsWith("/")
665 ? `${sourceRoot.slice(0, -1)}${source}`
666 : `${sourceRoot}${source}`
667 : (source) =>
668 source.startsWith("/")
669 ? `${sourceRoot}${source}`
670 : `${sourceRoot}/${source}`;
671 const newSources = sourceMap.sources.map((source) =>
672 contextifySourceUrl(context, mapper(source), associatedObjectForCache)
673 );
674 return {
675 ...sourceMap,
676 file: "x",
677 sourceRoot: undefined,
678 sources: newSources
679 };
680};
681
682/**
683 * @param {string | Buffer} input the input

Callers 2

createSourceForAssetMethod · 0.85
createSourceMethod · 0.85

Calls 3

contextifySourceUrlFunction · 0.85
isArrayMethod · 0.80
sliceMethod · 0.80

Tested by

no test coverage detected