webpack/lib/AsyncDependenciesBlock.js

114 lines
3.2 KiB
JavaScript
Raw Normal View History

2013-01-31 01:49:25 +08:00
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
2018-07-30 23:08:51 +08:00
"use strict";
2018-05-15 18:20:17 +08:00
const DependenciesBlock = require("./DependenciesBlock");
const makeSerializable = require("./util/makeSerializable");
/** @typedef {import("./ChunkGroup").ChunkGroupOptions} ChunkGroupOptions */
/** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
/** @typedef {import("./Dependency").UpdateHashContext} UpdateHashContext */
/** @typedef {import("./Entrypoint").EntryOptions} EntryOptions */
2023-04-12 02:57:43 +08:00
/** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
/** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
2019-07-17 22:02:33 +08:00
/** @typedef {import("./util/Hash")} Hash */
2025-04-07 21:09:05 +08:00
/** @typedef {(ChunkGroupOptions & { entryOptions?: EntryOptions }) | string} GroupOptions */
2018-07-20 22:24:35 +08:00
class AsyncDependenciesBlock extends DependenciesBlock {
/**
2025-04-07 21:09:05 +08:00
* @param {GroupOptions | null} groupOptions options for the group
2023-06-17 06:33:17 +08:00
* @param {(DependencyLocation | null)=} loc the line of code
2023-06-17 02:49:43 +08:00
* @param {(string | null)=} request the request
*/
constructor(groupOptions, loc, request) {
super();
if (typeof groupOptions === "string") {
groupOptions = { name: groupOptions };
} else if (!groupOptions) {
groupOptions = { name: undefined };
}
this.groupOptions = groupOptions;
this.loc = loc;
this.request = request;
this._stringifiedGroupOptions = undefined;
}
/**
2025-09-11 08:10:10 +08:00
* @returns {ChunkGroupOptions["name"]} The name of the chunk
*/
get chunkName() {
return this.groupOptions.name;
}
/**
2023-05-26 02:31:28 +08:00
* @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;
}
}
/**
* @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);
2021-09-26 08:15:41 +08:00
hash.update(
`${this._stringifiedGroupOptions}${chunkGroup ? chunkGroup.id : ""}`
);
super.updateHash(hash, context);
}
2023-04-12 02:57:43 +08:00
/**
* @param {ObjectSerializerContext} context context
*/
serialize(context) {
const { write } = context;
write(this.groupOptions);
write(this.loc);
write(this.request);
super.serialize(context);
}
2023-04-12 02:57:43 +08:00
/**
* @param {ObjectDeserializerContext} context context
*/
deserialize(context) {
const { read } = context;
this.groupOptions = read();
this.loc = read();
this.request = read();
super.deserialize(context);
}
2018-07-20 22:24:35 +08:00
}
makeSerializable(AsyncDependenciesBlock, "webpack/lib/AsyncDependenciesBlock");
Object.defineProperty(AsyncDependenciesBlock.prototype, "module", {
get() {
throw new Error(
"module property was removed from AsyncDependenciesBlock (it's not needed)"
);
},
set() {
throw new Error(
"module property was removed from AsyncDependenciesBlock (it's not needed)"
);
}
});
2018-07-20 22:24:35 +08:00
module.exports = AsyncDependenciesBlock;