[79a0317] | 1 | /*
|
---|
| 2 | MIT License http://www.opensource.org/licenses/mit-license.php
|
---|
| 3 | */
|
---|
| 4 |
|
---|
| 5 | "use strict";
|
---|
| 6 |
|
---|
| 7 | const RuntimeModule = require("../RuntimeModule");
|
---|
| 8 | const Template = require("../Template");
|
---|
| 9 |
|
---|
| 10 | /** @typedef {import("../Compilation")} Compilation */
|
---|
| 11 | /** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
|
---|
| 12 |
|
---|
| 13 | class ChunkPrefetchFunctionRuntimeModule extends RuntimeModule {
|
---|
| 14 | /**
|
---|
| 15 | * @param {string} childType TODO
|
---|
| 16 | * @param {string} runtimeFunction TODO
|
---|
| 17 | * @param {string} runtimeHandlers TODO
|
---|
| 18 | */
|
---|
| 19 | constructor(childType, runtimeFunction, runtimeHandlers) {
|
---|
| 20 | super(`chunk ${childType} function`);
|
---|
| 21 | this.childType = childType;
|
---|
| 22 | this.runtimeFunction = runtimeFunction;
|
---|
| 23 | this.runtimeHandlers = runtimeHandlers;
|
---|
| 24 | }
|
---|
| 25 |
|
---|
| 26 | /**
|
---|
| 27 | * @returns {string | null} runtime code
|
---|
| 28 | */
|
---|
| 29 | generate() {
|
---|
| 30 | const { runtimeFunction, runtimeHandlers } = this;
|
---|
| 31 | const compilation = /** @type {Compilation} */ (this.compilation);
|
---|
| 32 | const { runtimeTemplate } = compilation;
|
---|
| 33 | return Template.asString([
|
---|
| 34 | `${runtimeHandlers} = {};`,
|
---|
| 35 | `${runtimeFunction} = ${runtimeTemplate.basicFunction("chunkId", [
|
---|
| 36 | // map is shorter than forEach
|
---|
| 37 | `Object.keys(${runtimeHandlers}).map(${runtimeTemplate.basicFunction(
|
---|
| 38 | "key",
|
---|
| 39 | `${runtimeHandlers}[key](chunkId);`
|
---|
| 40 | )});`
|
---|
| 41 | ])}`
|
---|
| 42 | ]);
|
---|
| 43 | }
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 | module.exports = ChunkPrefetchFunctionRuntimeModule;
|
---|