MCPcopy
hub / github.com/webpack/webpack / getLazySource

Method getLazySource

lib/ContextModule.js:1102–1241  ·  view source on GitHub ↗

* @param {AsyncDependenciesBlock[]} blocks blocks * @param {ModuleId} id module id * @param {ImportPhaseType} phase import phase * @param {object} context context * @param {ChunkGraph} context.chunkGraph the chunk graph * @param {RuntimeTemplate} context.runtimeTemplate the chunk graph *

(blocks, id, phase, { chunkGraph, runtimeTemplate })

Source from the content-addressed store, hash-verified

1100 * @returns {string} source code
1101 */
1102 getLazySource(blocks, id, phase, { chunkGraph, runtimeTemplate }) {
1103 const moduleGraph = chunkGraph.moduleGraph;
1104 let hasMultipleOrNoChunks = false;
1105 let hasNoChunk = true;
1106 let hasNoModuleDeferred = true;
1107 const fakeMap = this.getFakeMap(
1108 blocks.map((b) => b.dependencies[0]),
1109 chunkGraph
1110 );
1111 const hasFakeMap = typeof fakeMap === "object";
1112 /** @typedef {{ userRequest: string, dependency: ContextElementDependency, chunks: undefined | Chunk[], module: Module, block: AsyncDependenciesBlock, asyncDeps: undefined | ModuleId[] }} Item */
1113 /**
1114 * @type {Item[]}
1115 */
1116 const items = blocks
1117 .map((block) => {
1118 const dependency =
1119 /** @type {ContextElementDependency} */
1120 (block.dependencies[0]);
1121 return {
1122 dependency,
1123 module: /** @type {Module} */ (moduleGraph.getModule(dependency)),
1124 block,
1125 userRequest: dependency.userRequest,
1126 chunks: undefined,
1127 asyncDeps: undefined
1128 };
1129 })
1130 .filter((item) => item.module);
1131 for (const item of items) {
1132 const chunkGroup = chunkGraph.getBlockChunkGroup(item.block);
1133 const chunks = (chunkGroup && chunkGroup.chunks) || [];
1134 item.chunks = chunks;
1135 if (chunks.length > 0) {
1136 hasNoChunk = false;
1137 }
1138 if (chunks.length !== 1) {
1139 hasMultipleOrNoChunks = true;
1140 }
1141 const isModuleDeferred =
1142 ImportPhaseUtils.isDefer(phase) &&
1143 !(/** @type {BuildMeta} */ (item.module.buildMeta).async);
1144 if (isModuleDeferred) {
1145 const asyncDeps = Array.from(
1146 getOutgoingAsyncModules(chunkGraph.moduleGraph, item.module),
1147 (m) => chunkGraph.getModuleId(m)
1148 ).filter((id) => id !== null);
1149 item.asyncDeps = asyncDeps;
1150 hasNoModuleDeferred = false;
1151 }
1152 }
1153 const shortMode = hasNoChunk && hasNoModuleDeferred && !hasFakeMap;
1154 const sortedItems = items.sort((a, b) => {
1155 if (a.userRequest === b.userRequest) return 0;
1156 return a.userRequest < b.userRequest ? -1 : 1;
1157 });
1158 /** @type {Record<string, ModuleId | (ModuleId | FakeMapType | ChunkId[] | (ModuleId[] | undefined))[]>} */
1159 const map = Object.create(null);

Callers 1

getSourceStringMethod · 0.95

Calls 13

getFakeMapMethod · 0.95
getOutgoingAsyncModulesFunction · 0.85
getBlockChunkGroupMethod · 0.80
getModuleIdMethod · 0.80
sortMethod · 0.80
renderConstMethod · 0.80
basicFunctionMethod · 0.80
indentMethod · 0.80
returningFunctionMethod · 0.80
getModuleMethod · 0.45
createMethod · 0.45

Tested by

no test coverage detected