source: frontend/node_modules/webpack/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 11 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 1.4 KB
Line 
1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3*/
4
5"use strict";
6
7const RuntimeModule = require("../RuntimeModule");
8const Template = require("../Template");
9
10/** @typedef {import("../Compilation")} Compilation */
11
12class ChunkPrefetchFunctionRuntimeModule extends RuntimeModule {
13 /**
14 * @param {"prefetch" | "preload"} type "prefetch" or "preload" chunk type function
15 * @param {string} runtimeFunction the runtime function name
16 * @param {string} runtimeHandlers the runtime handlers
17 */
18 constructor(type, runtimeFunction, runtimeHandlers) {
19 super(`chunk ${type} function`);
20 /** @type {string} */
21 this.runtimeFunction = runtimeFunction;
22 /** @type {string} */
23 this.runtimeHandlers = runtimeHandlers;
24 }
25
26 /**
27 * Generates runtime code for this runtime module.
28 * @returns {string | null} runtime code
29 */
30 generate() {
31 const { runtimeFunction, runtimeHandlers } = this;
32 const compilation = /** @type {Compilation} */ (this.compilation);
33 const { runtimeTemplate } = compilation;
34 return Template.asString([
35 `${runtimeHandlers} = {};`,
36 `${runtimeFunction} = ${runtimeTemplate.basicFunction("chunkId", [
37 // map is shorter than forEach
38 `Object.keys(${runtimeHandlers}).map(${runtimeTemplate.basicFunction(
39 "key",
40 `${runtimeHandlers}[key](chunkId);`
41 )});`
42 ])}`
43 ]);
44 }
45}
46
47module.exports = ChunkPrefetchFunctionRuntimeModule;
Note: See TracBrowser for help on using the repository browser.