UNPKG

webpack

Version:

Packs ECMAScript/CommonJs/AMD modules for the browser. Allows you to split your codebase into multiple bundles, which can be loaded on demand. Supports loaders to preprocess files, i.e. json, jsx, es7, css, less, ... and your custom stuff.

158 lines (141 loc) • 4.18 kB
/* MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ "use strict"; const makeSerializable = require("../util/makeSerializable"); const DependenciesBlock = require("./DependenciesBlock"); /** @import { ChunkGroupOptions } from "./ChunkGroup" */ /** @import { DependencyLocation, UpdateHashContext } from "./Dependency" */ /** @import { EntryOptions } from "./Entrypoint" */ /** * @import { * ObjectDeserializerContext, * ObjectSerializerContext * } from "../serialization/ObjectMiddleware" */ /** @import Hash from "../util/Hash" */ /** @typedef {(ChunkGroupOptions & { entryOptions?: EntryOptions } & { circular?: boolean })} GroupOptions */ class AsyncDependenciesBlock extends DependenciesBlock { /** * @param {GroupOptions | string | null} groupOptions options for the group * @param {(DependencyLocation | null)=} loc the line of code * @param {(string | null)=} request the request */ constructor(groupOptions, loc, request) { super(); if (typeof groupOptions === "string") { groupOptions = { name: groupOptions }; } else if (!groupOptions) { groupOptions = { name: undefined }; } if (typeof groupOptions.circular !== "boolean") { // default allow circular references groupOptions.circular = true; } /** @type {GroupOptions} */ this.groupOptions = groupOptions; /** @type {DependencyLocation | null | undefined} */ this.loc = loc; /** @type {string | null | undefined} */ this.request = request; /** @type {undefined | string} */ this._stringifiedGroupOptions = undefined; } /** * @returns {ChunkGroupOptions["name"]} The name of the chunk */ get chunkName() { return this.groupOptions.name; } /** * @param {string | undefined} value The new chunk name * @returns {void} */ set chunkName(value) { if (this.groupOptions.name !== value) { this.groupOptions.name = value; this._stringifiedGroupOptions = undefined; } } /** * @returns {boolean} Whether circular references are allowed */ get circular() { return Boolean(this.groupOptions.circular); } /** * Updates the hash with the data contributed by this instance. * @param {Hash} hash the hash used to track dependencies * @param {UpdateHashContext} context context * @returns {void} */ updateHash(hash, context) { const { chunkGraph } = context; if (this._stringifiedGroupOptions === undefined) { this._stringifiedGroupOptions = JSON.stringify(this.groupOptions); } const chunkGroup = chunkGraph.getBlockChunkGroup(this); hash.update( `${this._stringifiedGroupOptions}${chunkGroup ? chunkGroup.id : ""}` ); super.updateHash(hash, context); } /** * Returns whether this block is an async block, loaded on demand in its own chunk group. * @returns {this is AsyncDependenciesBlock} true for an AsyncDependenciesBlock */ isAsyncBlock() { return true; } /** * Serializes this instance into the provided serializer context. * @param {ObjectSerializerContext} context context */ serialize(context) { const { write } = context; write(this.groupOptions); write(this.loc); write(this.request); super.serialize(context); } /** * Restores this instance from the provided deserializer context. * @param {ObjectDeserializerContext} context context */ deserialize(context) { const { read } = context; this.groupOptions = read(); this.loc = read(); this.request = read(); super.deserialize(context); } } makeSerializable(AsyncDependenciesBlock, [ "webpack/lib/graph/AsyncDependenciesBlock", // TODO in the next major release: remove, they restore pre-move cache packs "webpack/lib/AsyncDependenciesBlock" ]); Object.defineProperty(AsyncDependenciesBlock.prototype, "module", { /** * Returns throws. * @deprecated * @returns {void} throws */ get() { throw new Error( "module property was removed from AsyncDependenciesBlock (it's not needed)" ); }, /** * Updates module. * @deprecated * @returns {never} throws */ set() { throw new Error( "module property was removed from AsyncDependenciesBlock (it's not needed)" ); } }); module.exports = AsyncDependenciesBlock;