1
|
/*
|
2
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
Author Tobias Koppers @sokra
|
4
|
*/
|
5
|
"use strict";
|
6
|
|
7
|
const DependenciesBlock = require("./DependenciesBlock");
|
8
|
|
9
|
/** @typedef {import("./ChunkGroup")} ChunkGroup */
|
10
|
/** @typedef {import("./Module")} Module */
|
11
|
/** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
|
12
|
/** @typedef {import("./util/createHash").Hash} Hash */
|
13
|
/** @typedef {TODO} GroupOptions */
|
14
|
|
15
|
module.exports = class AsyncDependenciesBlock extends DependenciesBlock {
|
16
|
/**
|
17
|
* @param {GroupOptions} groupOptions options for the group
|
18
|
* @param {Module} module the Module object
|
19
|
* @param {DependencyLocation=} loc the line of code
|
20
|
* @param {TODO=} request the request
|
21
|
*/
|
22
|
constructor(groupOptions, module, loc, request) {
|
23
|
super();
|
24
|
if (typeof groupOptions === "string") {
|
25
|
groupOptions = { name: groupOptions };
|
26
|
} else if (!groupOptions) {
|
27
|
groupOptions = { name: undefined };
|
28
|
}
|
29
|
this.groupOptions = groupOptions;
|
30
|
/** @type {ChunkGroup=} */
|
31
|
this.chunkGroup = undefined;
|
32
|
this.module = module;
|
33
|
this.loc = loc;
|
34
|
this.request = request;
|
35
|
/** @type {DependenciesBlock} */
|
36
|
this.parent = undefined;
|
37
|
}
|
38
|
|
39
|
/**
|
40
|
* @returns {string} The name of the chunk
|
41
|
*/
|
42
|
get chunkName() {
|
43
|
return this.groupOptions.name;
|
44
|
}
|
45
|
|
46
|
/**
|
47
|
* @param {string} value The new chunk name
|
48
|
* @returns {void}
|
49
|
*/
|
50
|
set chunkName(value) {
|
51
|
this.groupOptions.name = value;
|
52
|
}
|
53
|
|
54
|
/**
|
55
|
* @returns {never} this throws and should never be called
|
56
|
*/
|
57
|
get chunks() {
|
58
|
throw new Error("Moved to AsyncDependenciesBlock.chunkGroup");
|
59
|
}
|
60
|
|
61
|
/**
|
62
|
* @param {never} value setter value
|
63
|
* @returns {never} this is going to throw therefore we should throw type
|
64
|
* assertions by returning never
|
65
|
*/
|
66
|
set chunks(value) {
|
67
|
throw new Error("Moved to AsyncDependenciesBlock.chunkGroup");
|
68
|
}
|
69
|
|
70
|
/**
|
71
|
* @param {Hash} hash the hash used to track block changes, from "crypto" module
|
72
|
* @returns {void}
|
73
|
*/
|
74
|
updateHash(hash) {
|
75
|
hash.update(JSON.stringify(this.groupOptions));
|
76
|
hash.update(
|
77
|
(this.chunkGroup &&
|
78
|
this.chunkGroup.chunks
|
79
|
.map(chunk => {
|
80
|
return chunk.id !== null ? chunk.id : "";
|
81
|
})
|
82
|
.join(",")) ||
|
83
|
""
|
84
|
);
|
85
|
super.updateHash(hash);
|
86
|
}
|
87
|
|
88
|
/**
|
89
|
* @returns {void}
|
90
|
*/
|
91
|
disconnect() {
|
92
|
this.chunkGroup = undefined;
|
93
|
super.disconnect();
|
94
|
}
|
95
|
|
96
|
/**
|
97
|
* @returns {void}
|
98
|
*/
|
99
|
unseal() {
|
100
|
this.chunkGroup = undefined;
|
101
|
super.unseal();
|
102
|
}
|
103
|
|
104
|
/**
|
105
|
* @returns {void}
|
106
|
*/
|
107
|
sortItems() {
|
108
|
super.sortItems();
|
109
|
}
|
110
|
};
|