AsyncDependenciesBlock.js
2.42 KB
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
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
"use strict";
const DependenciesBlock = require("./DependenciesBlock");
/** @typedef {import("./ChunkGroup")} ChunkGroup */
/** @typedef {import("./Module")} Module */
/** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
/** @typedef {import("./util/createHash").Hash} Hash */
/** @typedef {TODO} GroupOptions */
module.exports = class AsyncDependenciesBlock extends DependenciesBlock {
/**
* @param {GroupOptions} groupOptions options for the group
* @param {Module} module the Module object
* @param {DependencyLocation=} loc the line of code
* @param {TODO=} request the request
*/
constructor(groupOptions, module, loc, request) {
super();
if (typeof groupOptions === "string") {
groupOptions = { name: groupOptions };
} else if (!groupOptions) {
groupOptions = { name: undefined };
}
this.groupOptions = groupOptions;
/** @type {ChunkGroup=} */
this.chunkGroup = undefined;
this.module = module;
this.loc = loc;
this.request = request;
/** @type {DependenciesBlock} */
this.parent = undefined;
}
/**
* @returns {string} The name of the chunk
*/
get chunkName() {
return this.groupOptions.name;
}
/**
* @param {string} value The new chunk name
* @returns {void}
*/
set chunkName(value) {
this.groupOptions.name = value;
}
/**
* @returns {never} this throws and should never be called
*/
get chunks() {
throw new Error("Moved to AsyncDependenciesBlock.chunkGroup");
}
/**
* @param {never} value setter value
* @returns {never} this is going to throw therefore we should throw type
* assertions by returning never
*/
set chunks(value) {
throw new Error("Moved to AsyncDependenciesBlock.chunkGroup");
}
/**
* @param {Hash} hash the hash used to track block changes, from "crypto" module
* @returns {void}
*/
updateHash(hash) {
hash.update(JSON.stringify(this.groupOptions));
hash.update(
(this.chunkGroup &&
this.chunkGroup.chunks
.map(chunk => {
return chunk.id !== null ? chunk.id : "";
})
.join(",")) ||
""
);
super.updateHash(hash);
}
/**
* @returns {void}
*/
disconnect() {
this.chunkGroup = undefined;
super.disconnect();
}
/**
* @returns {void}
*/
unseal() {
this.chunkGroup = undefined;
super.unseal();
}
/**
* @returns {void}
*/
sortItems() {
super.sortItems();
}
};