Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

AsyncDependenciesBlock.js 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. };