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

Method codeGeneration

lib/dll/DelegatedModule.js:170–213  ·  view source on GitHub ↗

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

({ runtimeTemplate, moduleGraph, chunkGraph })

Source from the content-addressed store, hash-verified

168 * @returns {CodeGenerationResult} result
169 */
170 codeGeneration({ runtimeTemplate, moduleGraph, chunkGraph }) {
171 const dep = /** @type {DelegatedSourceDependency} */ (this.dependencies[0]);
172 const sourceModule = moduleGraph.getModule(dep);
173 /** @type {string} */
174 let str;
175
176 if (!sourceModule) {
177 str = runtimeTemplate.throwMissingModuleErrorBlock({
178 request: this.sourceRequest
179 });
180 } else {
181 str = `module.exports = (${runtimeTemplate.moduleExports({
182 module: sourceModule,
183 chunkGraph,
184 request: dep.request,
185 /** @type {RuntimeRequirements} */
186 runtimeRequirements: new Set()
187 })})`;
188
189 switch (this.delegationType) {
190 case "require":
191 str += `(${JSON.stringify(this.request)})`;
192 break;
193 case "object":
194 str += `[${JSON.stringify(this.request)}]`;
195 break;
196 }
197
198 str += ";";
199 }
200
201 /** @type {Sources} */
202 const sources = new Map();
203 if (this.useSourceMap || this.useSimpleSourceMap) {
204 sources.set(JAVASCRIPT_TYPE, new OriginalSource(str, this.identifier()));
205 } else {
206 sources.set(JAVASCRIPT_TYPE, new RawSource(str));
207 }
208
209 return {
210 sources,
211 runtimeRequirements: RUNTIME_REQUIREMENTS
212 };
213 }
214
215 /**
216 * Returns the estimated size for the requested source type.

Callers

nothing calls this directly

Calls 5

identifierMethod · 0.95
moduleExportsMethod · 0.80
getModuleMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected