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

Method codeGeneration

lib/sharing/ConsumeSharedModule.js:266–332  ·  view source on GitHub ↗

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

({ chunkGraph, runtimeTemplate })

Source from the content-addressed store, hash-verified

264 * @returns {CodeGenerationResult} result
265 */
266 codeGeneration({ chunkGraph, runtimeTemplate }) {
267 const runtimeRequirements = new Set([RuntimeGlobals.shareScopeMap]);
268 const {
269 shareScope,
270 shareKey,
271 strictVersion,
272 requiredVersion,
273 import: request,
274 singleton,
275 eager
276 } = this.options;
277 /** @type {undefined | string} */
278 let fallbackCode;
279 if (request) {
280 if (eager) {
281 const dep = this.dependencies[0];
282 fallbackCode = runtimeTemplate.syncModuleFactory({
283 dependency: dep,
284 chunkGraph,
285 runtimeRequirements,
286 request: this.options.import
287 });
288 } else {
289 const block = this.blocks[0];
290 fallbackCode = runtimeTemplate.asyncModuleFactory({
291 block,
292 chunkGraph,
293 runtimeRequirements,
294 request: this.options.import
295 });
296 }
297 }
298
299 const args = [
300 JSON.stringify(shareScope),
301 JSON.stringify(shareKey),
302 JSON.stringify(eager)
303 ];
304 if (requiredVersion) {
305 args.push(stringifyHoley(requiredVersion));
306 }
307 if (fallbackCode) {
308 args.push(fallbackCode);
309 }
310
311 /** @type {string} */
312 let fn;
313
314 if (requiredVersion) {
315 if (strictVersion) {
316 fn = singleton ? "loadStrictSingletonVersion" : "loadStrictVersion";
317 } else {
318 fn = singleton ? "loadSingletonVersion" : "loadVersion";
319 }
320 } else {
321 fn = singleton ? "loadSingleton" : "load";
322 }
323

Callers

nothing calls this directly

Calls 5

syncModuleFactoryMethod · 0.80
asyncModuleFactoryMethod · 0.80
returningFunctionMethod · 0.80
pushMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected