1 |
9bb1e829
|
cagy
|
/*
|
2 |
|
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
3 |
|
|
Author Tobias Koppers @sokra
|
4 |
|
|
*/
|
5 |
|
|
"use strict";
|
6 |
|
|
|
7 |
|
|
/** @typedef {import("./Module")} Module */
|
8 |
|
|
/** @typedef {import("./Dependency")} Dependency */
|
9 |
|
|
|
10 |
|
|
class ModuleReason {
|
11 |
|
|
/**
|
12 |
|
|
* @param {Module} module the referencing module
|
13 |
|
|
* @param {Dependency} dependency the referencing dependency
|
14 |
|
|
* @param {string=} explanation some extra detail
|
15 |
|
|
*/
|
16 |
|
|
constructor(module, dependency, explanation) {
|
17 |
|
|
this.module = module;
|
18 |
|
|
this.dependency = dependency;
|
19 |
|
|
this.explanation = explanation;
|
20 |
|
|
this._chunks = null;
|
21 |
|
|
}
|
22 |
|
|
|
23 |
|
|
hasChunk(chunk) {
|
24 |
|
|
if (this._chunks) {
|
25 |
|
|
if (this._chunks.has(chunk)) return true;
|
26 |
|
|
} else if (this.module && this.module._chunks.has(chunk)) return true;
|
27 |
|
|
return false;
|
28 |
|
|
}
|
29 |
|
|
|
30 |
|
|
rewriteChunks(oldChunk, newChunks) {
|
31 |
|
|
if (!this._chunks) {
|
32 |
|
|
if (this.module) {
|
33 |
|
|
if (!this.module._chunks.has(oldChunk)) return;
|
34 |
|
|
this._chunks = new Set(this.module._chunks);
|
35 |
|
|
} else {
|
36 |
|
|
this._chunks = new Set();
|
37 |
|
|
}
|
38 |
|
|
}
|
39 |
|
|
if (this._chunks.has(oldChunk)) {
|
40 |
|
|
this._chunks.delete(oldChunk);
|
41 |
|
|
for (let i = 0; i < newChunks.length; i++) {
|
42 |
|
|
this._chunks.add(newChunks[i]);
|
43 |
|
|
}
|
44 |
|
|
}
|
45 |
|
|
}
|
46 |
|
|
}
|
47 |
|
|
|
48 |
|
|
module.exports = ModuleReason;
|