WXL
4 天以前 2cc85c64f1c64a2dbaeae276a3e2ca8420de76b7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
    MIT License http://www.opensource.org/licenses/mit-license.php
    Author Tobias Koppers @sokra
*/
 
"use strict";
 
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 */
/** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
/** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
/** @typedef {import("./util/Hash")} 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);
    }
 
    /**
     * 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/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)"
        );
    }
});
 
module.exports = AsyncDependenciesBlock;