MCPcopy
hub / github.com/webpack/webpack / codeGeneration

Method codeGeneration

lib/container/ContainerEntryModule.js:162–275  ·  view source on GitHub ↗

* Generates code and runtime requirements for this module. * @param {CodeGenerationContext} context context for code generation * @returns {CodeGenerationResult} result

({ moduleGraph, chunkGraph, runtimeTemplate })

Source from the content-addressed store, hash-verified

160 * @returns {CodeGenerationResult} result
161 */
162 codeGeneration({ moduleGraph, chunkGraph, runtimeTemplate }) {
163 /** @type {Sources} */
164 const sources = new Map();
165 const runtimeRequirements = new Set([
166 RuntimeGlobals.definePropertyGetters,
167 RuntimeGlobals.hasOwnProperty,
168 RuntimeGlobals.exports
169 ]);
170 /** @type {string[]} */
171 const getters = [];
172
173 for (const block of this.blocks) {
174 const { dependencies } = block;
175
176 const modules = dependencies.map((dependency) => {
177 const dep = /** @type {ContainerExposedDependency} */ (dependency);
178 return {
179 name: dep.exposedName,
180 module: moduleGraph.getModule(dep),
181 request: dep.userRequest
182 };
183 });
184
185 /** @type {string} */
186 let str;
187
188 if (modules.some((m) => !m.module)) {
189 str = runtimeTemplate.throwMissingModuleErrorBlock({
190 request: modules.map((m) => m.request).join(", ")
191 });
192 } else {
193 str = `return ${runtimeTemplate.blockPromise({
194 block,
195 message: "",
196 chunkGraph,
197 runtimeRequirements
198 })}.then(${runtimeTemplate.returningFunction(
199 runtimeTemplate.returningFunction(
200 `(${modules
201 .map(({ module, request }) =>
202 runtimeTemplate.moduleRaw({
203 module,
204 chunkGraph,
205 request,
206 weak: false,
207 runtimeRequirements
208 })
209 )
210 .join(", ")})`
211 )
212 )});`;
213 }
214
215 getters.push(
216 `${JSON.stringify(modules[0].name)}: ${runtimeTemplate.basicFunction(
217 "",
218 str
219 )}`

Callers

nothing calls this directly

Calls 11

blockPromiseMethod · 0.80
returningFunctionMethod · 0.80
moduleRawMethod · 0.80
basicFunctionMethod · 0.80
renderConstMethod · 0.80
indentMethod · 0.80
getModuleMethod · 0.45
pushMethod · 0.45
asStringMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected