[79a0317] | 1 | /*
|
---|
| 2 | MIT License http://www.opensource.org/licenses/mit-license.php
|
---|
| 3 | Author Tobias Koppers @sokra
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | "use strict";
|
---|
| 7 |
|
---|
| 8 | const DependenciesBlock = require("./DependenciesBlock");
|
---|
| 9 | const makeSerializable = require("./util/makeSerializable");
|
---|
| 10 |
|
---|
| 11 | /** @typedef {import("./ChunkGraph")} ChunkGraph */
|
---|
| 12 | /** @typedef {import("./ChunkGroup")} ChunkGroup */
|
---|
| 13 | /** @typedef {import("./ChunkGroup").ChunkGroupOptions} ChunkGroupOptions */
|
---|
| 14 | /** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
|
---|
| 15 | /** @typedef {import("./Dependency").UpdateHashContext} UpdateHashContext */
|
---|
| 16 | /** @typedef {import("./Entrypoint").EntryOptions} EntryOptions */
|
---|
| 17 | /** @typedef {import("./Module")} Module */
|
---|
| 18 | /** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
---|
| 19 | /** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
|
---|
| 20 | /** @typedef {import("./util/Hash")} Hash */
|
---|
| 21 |
|
---|
| 22 | class AsyncDependenciesBlock extends DependenciesBlock {
|
---|
| 23 | /**
|
---|
| 24 | * @param {(ChunkGroupOptions & { entryOptions?: EntryOptions }) | null} groupOptions options for the group
|
---|
| 25 | * @param {(DependencyLocation | null)=} loc the line of code
|
---|
| 26 | * @param {(string | null)=} request the request
|
---|
| 27 | */
|
---|
| 28 | constructor(groupOptions, loc, request) {
|
---|
| 29 | super();
|
---|
| 30 | if (typeof groupOptions === "string") {
|
---|
| 31 | groupOptions = { name: groupOptions };
|
---|
| 32 | } else if (!groupOptions) {
|
---|
| 33 | groupOptions = { name: undefined };
|
---|
| 34 | }
|
---|
| 35 | this.groupOptions = groupOptions;
|
---|
| 36 | this.loc = loc;
|
---|
| 37 | this.request = request;
|
---|
| 38 | this._stringifiedGroupOptions = undefined;
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | /**
|
---|
| 42 | * @returns {string | null | undefined} The name of the chunk
|
---|
| 43 | */
|
---|
| 44 | get chunkName() {
|
---|
| 45 | return this.groupOptions.name;
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | /**
|
---|
| 49 | * @param {string | undefined} value The new chunk name
|
---|
| 50 | * @returns {void}
|
---|
| 51 | */
|
---|
| 52 | set chunkName(value) {
|
---|
| 53 | if (this.groupOptions.name !== value) {
|
---|
| 54 | this.groupOptions.name = value;
|
---|
| 55 | this._stringifiedGroupOptions = undefined;
|
---|
| 56 | }
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | /**
|
---|
| 60 | * @param {Hash} hash the hash used to track dependencies
|
---|
| 61 | * @param {UpdateHashContext} context context
|
---|
| 62 | * @returns {void}
|
---|
| 63 | */
|
---|
| 64 | updateHash(hash, context) {
|
---|
| 65 | const { chunkGraph } = context;
|
---|
| 66 | if (this._stringifiedGroupOptions === undefined) {
|
---|
| 67 | this._stringifiedGroupOptions = JSON.stringify(this.groupOptions);
|
---|
| 68 | }
|
---|
| 69 | const chunkGroup = chunkGraph.getBlockChunkGroup(this);
|
---|
| 70 | hash.update(
|
---|
| 71 | `${this._stringifiedGroupOptions}${chunkGroup ? chunkGroup.id : ""}`
|
---|
| 72 | );
|
---|
| 73 | super.updateHash(hash, context);
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | /**
|
---|
| 77 | * @param {ObjectSerializerContext} context context
|
---|
| 78 | */
|
---|
| 79 | serialize(context) {
|
---|
| 80 | const { write } = context;
|
---|
| 81 | write(this.groupOptions);
|
---|
| 82 | write(this.loc);
|
---|
| 83 | write(this.request);
|
---|
| 84 | super.serialize(context);
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | /**
|
---|
| 88 | * @param {ObjectDeserializerContext} context context
|
---|
| 89 | */
|
---|
| 90 | deserialize(context) {
|
---|
| 91 | const { read } = context;
|
---|
| 92 | this.groupOptions = read();
|
---|
| 93 | this.loc = read();
|
---|
| 94 | this.request = read();
|
---|
| 95 | super.deserialize(context);
|
---|
| 96 | }
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 | makeSerializable(AsyncDependenciesBlock, "webpack/lib/AsyncDependenciesBlock");
|
---|
| 100 |
|
---|
| 101 | Object.defineProperty(AsyncDependenciesBlock.prototype, "module", {
|
---|
| 102 | get() {
|
---|
| 103 | throw new Error(
|
---|
| 104 | "module property was removed from AsyncDependenciesBlock (it's not needed)"
|
---|
| 105 | );
|
---|
| 106 | },
|
---|
| 107 | set() {
|
---|
| 108 | throw new Error(
|
---|
| 109 | "module property was removed from AsyncDependenciesBlock (it's not needed)"
|
---|
| 110 | );
|
---|
| 111 | }
|
---|
| 112 | });
|
---|
| 113 |
|
---|
| 114 | module.exports = AsyncDependenciesBlock;
|
---|