2013-01-31 01:49:25 +08:00
|
|
|
/*
|
|
|
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
|
|
Author Tobias Koppers @sokra
|
|
|
|
*/
|
2016-12-29 15:10:25 +08:00
|
|
|
"use strict";
|
|
|
|
|
2017-06-14 00:58:14 +08:00
|
|
|
class ModuleReason {
|
2017-11-22 01:52:35 +08:00
|
|
|
constructor(module, dependency, explanation) {
|
2016-12-29 15:10:25 +08:00
|
|
|
this.module = module;
|
|
|
|
this.dependency = dependency;
|
2017-11-22 01:52:35 +08:00
|
|
|
this.explanation = explanation;
|
2017-06-14 00:58:14 +08:00
|
|
|
this._chunks = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
hasChunk(chunk) {
|
2018-02-25 09:00:20 +08:00
|
|
|
if (this._chunks) {
|
|
|
|
if (this._chunks.has(chunk)) return true;
|
|
|
|
} else if (this.module && this.module._chunks.has(chunk)) return true;
|
2017-06-14 00:58:14 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
rewriteChunks(oldChunk, newChunks) {
|
2018-02-25 09:00:20 +08:00
|
|
|
if (!this._chunks) {
|
|
|
|
if (this.module) {
|
|
|
|
if (!this.module._chunks.has(oldChunk)) return;
|
2017-11-06 20:02:35 +08:00
|
|
|
this._chunks = new Set(this.module._chunks);
|
|
|
|
} else {
|
|
|
|
this._chunks = new Set();
|
|
|
|
}
|
2017-06-14 00:58:14 +08:00
|
|
|
}
|
2018-02-25 09:00:20 +08:00
|
|
|
if (this._chunks.has(oldChunk)) {
|
2017-06-14 00:58:14 +08:00
|
|
|
this._chunks.delete(oldChunk);
|
2018-02-25 09:00:20 +08:00
|
|
|
for (let i = 0; i < newChunks.length; i++) {
|
2017-06-14 00:58:14 +08:00
|
|
|
this._chunks.add(newChunks[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = ModuleReason;
|