You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ModuleReason.js 1.2KB

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