MCPcopy
hub / github.com/webpack/webpack / renderModule

Method renderModule

lib/css/CssModulesPlugin.js:918–1029  ·  view source on GitHub ↗

* Renders css module source. * @param {CssModule} module css module * @param {ChunkRenderContext} renderContext options object * @param {CompilationHooks} hooks hooks * @returns {Source | null} css module source

(module, renderContext, hooks)

Source from the content-addressed store, hash-verified

916 * @returns {Source | null} css module source
917 */
918 static renderModule(module, renderContext, hooks) {
919 const { undoPath, hash, moduleFactoryCache, moduleSourceContent } =
920 renderContext;
921 const cacheEntry = moduleFactoryCache.get(moduleSourceContent);
922
923 /** @type {Inheritance} */
924 const inheritance = [[module.cssLayer, module.supports, module.media]];
925 if (module.inheritance) {
926 inheritance.push(...module.inheritance);
927 }
928
929 /** @type {CachedSource} */
930 let source;
931 if (
932 cacheEntry &&
933 cacheEntry.undoPath === undoPath &&
934 cacheEntry.hash === hash &&
935 cacheEntry.inheritance.length === inheritance.length &&
936 cacheEntry.inheritance.every(([layer, supports, media], i) => {
937 const item = inheritance[i];
938 if (Array.isArray(item)) {
939 return layer === item[0] && supports === item[1] && media === item[2];
940 }
941 return false;
942 })
943 ) {
944 source = cacheEntry.source;
945 } else {
946 if (!moduleSourceContent) return null;
947 let plan = publicPathPlaceholderPlans.get(moduleSourceContent);
948 if (plan === undefined) {
949 plan = computePublicPathPlaceholderPlan(
950 /** @type {string} */ (moduleSourceContent.source())
951 );
952 publicPathPlaceholderPlans.set(moduleSourceContent, plan);
953 }
954
955 /** @type {Source} */
956 let moduleSource = moduleSourceContent;
957
958 // Apply placeholder substitutions only when present; the common
959 // (no-placeholder) case skips the ReplaceSource wrapper entirely.
960 if (plan.autos.length > 0 || (hash && plan.hashes.length > 0)) {
961 const replaceSource = new ReplaceSource(moduleSourceContent);
962 const autoLen = PUBLIC_PATH_AUTO.length;
963 for (let i = 0; i < plan.autos.length; i++) {
964 const start = plan.autos[i];
965 replaceSource.replace(start, start + autoLen - 1, undoPath);
966 }
967 if (hash) {
968 for (let i = 0; i < plan.hashes.length; i++) {
969 const { start, end, length } = plan.hashes[i];
970 // `end` is exclusive; ReplaceSource.replace takes an inclusive end.
971 replaceSource.replace(
972 start,
973 end - 1,
974 length === 0 ? hash : hash.slice(0, length)
975 );

Callers 2

_renderCssMethod · 0.45
renderChunkMethod · 0.45

Calls 10

tryRunOrWebpackErrorFunction · 0.85
isArrayMethod · 0.80
sourceMethod · 0.80
sliceMethod · 0.80
getMethod · 0.45
pushMethod · 0.45
setMethod · 0.45
replaceMethod · 0.45
callMethod · 0.45

Tested by

no test coverage detected