webpack/lib/ModuleReason.js

41 lines
915 B
JavaScript
Raw Normal View History

2013-01-31 01:49:25 +08:00
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
"use strict";
class ModuleReason {
2017-11-22 01:52:35 +08:00
constructor(module, dependency, explanation) {
this.module = module;
this.dependency = dependency;
2017-11-22 01:52:35 +08:00
this.explanation = explanation;
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;
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;
this._chunks = new Set(this.module._chunks);
} else {
this._chunks = new Set();
}
}
2018-02-25 09:00:20 +08:00
if (this._chunks.has(oldChunk)) {
this._chunks.delete(oldChunk);
2018-02-25 09:00:20 +08:00
for (let i = 0; i < newChunks.length; i++) {
this._chunks.add(newChunks[i]);
}
}
}
}
module.exports = ModuleReason;