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.

110 lines
2.4 KiB

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