webpack 5.85.1 → 5.87.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of webpack might be problematic. Click here for more details.

Files changed (140) hide show
  1. package/README.md +5 -2
  2. package/lib/APIPlugin.js +150 -99
  3. package/lib/CaseSensitiveModulesWarning.js +3 -1
  4. package/lib/Chunk.js +35 -17
  5. package/lib/ChunkGroup.js +11 -6
  6. package/lib/Compiler.js +4 -3
  7. package/lib/ConcatenationScope.js +2 -2
  8. package/lib/ConditionalInitFragment.js +11 -1
  9. package/lib/ConstPlugin.js +57 -29
  10. package/lib/ContextModule.js +4 -2
  11. package/lib/ContextModuleFactory.js +1 -0
  12. package/lib/DependenciesBlock.js +1 -1
  13. package/lib/DllModule.js +6 -0
  14. package/lib/EvalSourceMapDevToolPlugin.js +2 -1
  15. package/lib/ExternalModule.js +15 -8
  16. package/lib/FlagEntryExportAsUsedPlugin.js +4 -0
  17. package/lib/Module.js +7 -1
  18. package/lib/ModuleDependencyError.js +4 -2
  19. package/lib/ModuleDependencyWarning.js +4 -2
  20. package/lib/ModuleGraph.js +31 -24
  21. package/lib/ModuleGraphConnection.js +19 -6
  22. package/lib/ModuleInfoHeaderPlugin.js +9 -2
  23. package/lib/ModuleNotFoundError.js +5 -2
  24. package/lib/ModuleStoreError.js +2 -1
  25. package/lib/ModuleTypeConstants.js +7 -0
  26. package/lib/MultiWatching.js +4 -0
  27. package/lib/ProgressPlugin.js +71 -15
  28. package/lib/RuntimeGlobals.js +5 -0
  29. package/lib/RuntimePlugin.js +2 -1
  30. package/lib/RuntimeTemplate.js +20 -2
  31. package/lib/WebpackError.js +6 -5
  32. package/lib/WebpackOptionsApply.js +4 -2
  33. package/lib/WebpackOptionsDefaulter.js +10 -3
  34. package/lib/config/defaults.js +31 -2
  35. package/lib/css/CssExportsGenerator.js +9 -0
  36. package/lib/css/CssGenerator.js +1 -1
  37. package/lib/css/CssLoadingRuntimeModule.js +13 -6
  38. package/lib/css/CssModulesPlugin.js +42 -14
  39. package/lib/css/CssParser.js +12 -0
  40. package/lib/dependencies/ConstDependency.js +2 -2
  41. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +19 -0
  42. package/lib/dependencies/ImportParserPlugin.js +25 -1
  43. package/lib/dependencies/JsonExportsDependency.js +1 -1
  44. package/lib/ids/SyncModuleIdsPlugin.js +1 -0
  45. package/lib/javascript/BasicEvaluatedExpression.js +23 -15
  46. package/lib/javascript/CommonJsChunkFormatPlugin.js +6 -2
  47. package/lib/javascript/JavascriptModulesPlugin.js +1 -0
  48. package/lib/javascript/JavascriptParser.js +118 -58
  49. package/lib/javascript/JavascriptParserHelpers.js +37 -15
  50. package/lib/json/JsonData.js +2 -2
  51. package/lib/json/JsonParser.js +25 -12
  52. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +2 -1
  53. package/lib/optimize/AggressiveMergingPlugin.js +8 -0
  54. package/lib/optimize/AggressiveSplittingPlugin.js +9 -2
  55. package/lib/optimize/EnsureChunkConditionsPlugin.js +3 -0
  56. package/lib/optimize/FlagIncludedChunksPlugin.js +11 -5
  57. package/lib/optimize/InnerGraph.js +4 -4
  58. package/lib/optimize/LimitChunkCountPlugin.js +29 -4
  59. package/lib/optimize/MangleExportsPlugin.js +1 -1
  60. package/lib/optimize/MinMaxSizeWarning.js +5 -0
  61. package/lib/optimize/ModuleConcatenationPlugin.js +59 -2
  62. package/lib/optimize/RealContentHashPlugin.js +80 -30
  63. package/lib/optimize/RemoveParentModulesPlugin.js +6 -0
  64. package/lib/optimize/RuntimeChunkPlugin.js +9 -1
  65. package/lib/optimize/SideEffectsFlagPlugin.js +10 -1
  66. package/lib/optimize/SplitChunksPlugin.js +71 -31
  67. package/lib/performance/SizeLimitsPlugin.js +7 -4
  68. package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +3 -1
  69. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +3 -1
  70. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +5 -2
  71. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +3 -1
  72. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +3 -1
  73. package/lib/rules/BasicEffectRulePlugin.js +4 -0
  74. package/lib/rules/BasicMatcherRulePlugin.js +5 -0
  75. package/lib/rules/RuleSetCompiler.js +3 -3
  76. package/lib/rules/UseEffectRulePlugin.js +6 -4
  77. package/lib/runtime/AsyncModuleRuntimeModule.js +4 -1
  78. package/lib/runtime/AutoPublicPathRuntimeModule.js +3 -1
  79. package/lib/runtime/BaseUriRuntimeModule.js +2 -2
  80. package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +4 -1
  81. package/lib/runtime/CompatRuntimeModule.js +6 -1
  82. package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +4 -1
  83. package/lib/runtime/CreateScriptRuntimeModule.js +3 -1
  84. package/lib/runtime/CreateScriptUrlRuntimeModule.js +3 -1
  85. package/lib/runtime/DefinePropertyGettersRuntimeModule.js +4 -1
  86. package/lib/runtime/EnsureChunkRuntimeModule.js +14 -3
  87. package/lib/runtime/GetChunkFilenameRuntimeModule.js +5 -9
  88. package/lib/runtime/GetFullHashRuntimeModule.js +3 -2
  89. package/lib/runtime/GetMainFilenameRuntimeModule.js +4 -1
  90. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +3 -1
  91. package/lib/runtime/HasOwnPropertyRuntimeModule.js +4 -1
  92. package/lib/runtime/LoadScriptRuntimeModule.js +63 -47
  93. package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +4 -1
  94. package/lib/runtime/OnChunksLoadedRuntimeModule.js +3 -1
  95. package/lib/runtime/PublicPathRuntimeModule.js +3 -1
  96. package/lib/runtime/RelativeUrlRuntimeModule.js +4 -1
  97. package/lib/runtime/RuntimeIdRuntimeModule.js +5 -1
  98. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +8 -2
  99. package/lib/runtime/StartupEntrypointRuntimeModule.js +2 -1
  100. package/lib/serialization/BinaryMiddleware.js +143 -1
  101. package/lib/serialization/ErrorObjectSerializer.js +3 -0
  102. package/lib/serialization/ObjectMiddleware.js +9 -3
  103. package/lib/serialization/types.js +1 -1
  104. package/lib/sharing/ConsumeSharedFallbackDependency.js +3 -0
  105. package/lib/sharing/ConsumeSharedRuntimeModule.js +13 -4
  106. package/lib/sharing/ProvideSharedDependency.js +11 -0
  107. package/lib/sharing/ProvideSharedModule.js +4 -0
  108. package/lib/sharing/ProvideSharedPlugin.js +22 -21
  109. package/lib/sharing/ShareRuntimeModule.js +11 -4
  110. package/lib/sharing/resolveMatchedConfigs.js +1 -1
  111. package/lib/sharing/utils.js +32 -5
  112. package/lib/util/AsyncQueue.js +4 -2
  113. package/lib/util/ParallelismFactorCalculator.js +10 -0
  114. package/lib/util/Semaphore.js +1 -1
  115. package/lib/util/createHash.js +30 -9
  116. package/lib/util/deprecation.js +10 -3
  117. package/lib/util/deterministicGrouping.js +50 -11
  118. package/lib/util/findGraphRoots.js +4 -2
  119. package/lib/util/memoize.js +3 -3
  120. package/lib/util/processAsyncTree.js +7 -1
  121. package/lib/util/registerExternalSerializer.js +1 -1
  122. package/lib/util/runtime.js +14 -1
  123. package/lib/util/smartGrouping.js +1 -1
  124. package/lib/validateSchema.js +6 -2
  125. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +5 -1
  126. package/lib/wasm-async/AsyncWebAssemblyParser.js +7 -3
  127. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +13 -6
  128. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +3 -1
  129. package/lib/wasm-sync/WebAssemblyGenerator.js +1 -0
  130. package/lib/wasm-sync/WebAssemblyParser.js +6 -2
  131. package/lib/web/JsonpChunkLoadingRuntimeModule.js +13 -3
  132. package/lib/webpack.js +11 -2
  133. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +14 -15
  134. package/module.d.ts +1 -0
  135. package/package.json +4 -4
  136. package/schemas/WebpackOptions.check.js +1 -1
  137. package/schemas/WebpackOptions.json +51 -5
  138. package/schemas/plugins/css/CssGeneratorOptions.json +1 -1
  139. package/schemas/plugins/css/CssParserOptions.json +1 -1
  140. package/types.d.ts +476 -218
@@ -11,11 +11,14 @@ const BULK_SIZE = 2000;
11
11
 
12
12
  // We are using an object instead of a Map as this will stay static during the runtime
13
13
  // so access to it can be optimized by v8
14
+ /** @type {Object<string, Map<string, string>>} */
14
15
  const digestCaches = {};
15
16
 
17
+ /** @typedef {function(): Hash} HashFactory */
18
+
16
19
  class BulkUpdateDecorator extends Hash {
17
20
  /**
18
- * @param {Hash | function(): Hash} hashOrFactory function to create a hash
21
+ * @param {Hash | HashFactory} hashOrFactory function to create a hash
19
22
  * @param {string=} hashKey key for caching
20
23
  */
21
24
  constructor(hashOrFactory, hashKey) {
@@ -43,7 +46,8 @@ class BulkUpdateDecorator extends Hash {
43
46
  typeof data !== "string" ||
44
47
  data.length > BULK_SIZE
45
48
  ) {
46
- if (this.hash === undefined) this.hash = this.hashFactory();
49
+ if (this.hash === undefined)
50
+ this.hash = /** @type {HashFactory} */ (this.hashFactory)();
47
51
  if (this.buffer.length > 0) {
48
52
  this.hash.update(this.buffer);
49
53
  this.buffer = "";
@@ -52,7 +56,8 @@ class BulkUpdateDecorator extends Hash {
52
56
  } else {
53
57
  this.buffer += data;
54
58
  if (this.buffer.length > BULK_SIZE) {
55
- if (this.hash === undefined) this.hash = this.hashFactory();
59
+ if (this.hash === undefined)
60
+ this.hash = /** @type {HashFactory} */ (this.hashFactory)();
56
61
  this.hash.update(this.buffer);
57
62
  this.buffer = "";
58
63
  }
@@ -77,7 +82,7 @@ class BulkUpdateDecorator extends Hash {
77
82
  }
78
83
  const cacheEntry = digestCache.get(buffer);
79
84
  if (cacheEntry !== undefined) return cacheEntry;
80
- this.hash = this.hashFactory();
85
+ this.hash = /** @type {HashFactory} */ (this.hashFactory)();
81
86
  }
82
87
  if (buffer.length > 0) {
83
88
  this.hash.update(buffer);
@@ -111,7 +116,9 @@ class DebugHash extends Hash {
111
116
  if (data.startsWith(prefix)) {
112
117
  data = Buffer.from(data.slice(prefix.length), "hex").toString();
113
118
  }
114
- this.string += `[${data}](${new Error().stack.split("\n", 3)[2]})\n`;
119
+ this.string += `[${data}](${
120
+ /** @type {string} */ (new Error().stack).split("\n", 3)[2]
121
+ })\n`;
115
122
  return this;
116
123
  }
117
124
 
@@ -125,9 +132,13 @@ class DebugHash extends Hash {
125
132
  }
126
133
  }
127
134
 
135
+ /** @type {typeof import("crypto") | undefined} */
128
136
  let crypto = undefined;
137
+ /** @type {typeof import("./hash/xxhash64") | undefined} */
129
138
  let createXXHash64 = undefined;
139
+ /** @type {typeof import("./hash/md4") | undefined} */
130
140
  let createMd4 = undefined;
141
+ /** @type {typeof import("./hash/BatchedHash") | undefined} */
131
142
  let BatchedHash = undefined;
132
143
 
133
144
  /**
@@ -150,7 +161,9 @@ module.exports = algorithm => {
150
161
  BatchedHash = require("./hash/BatchedHash");
151
162
  }
152
163
  }
153
- return new BatchedHash(createXXHash64());
164
+ return new /** @type {typeof import("./hash/BatchedHash")} */ (
165
+ BatchedHash
166
+ )(createXXHash64());
154
167
  case "md4":
155
168
  if (createMd4 === undefined) {
156
169
  createMd4 = require("./hash/md4");
@@ -158,14 +171,22 @@ module.exports = algorithm => {
158
171
  BatchedHash = require("./hash/BatchedHash");
159
172
  }
160
173
  }
161
- return new BatchedHash(createMd4());
174
+ return new /** @type {typeof import("./hash/BatchedHash")} */ (
175
+ BatchedHash
176
+ )(createMd4());
162
177
  case "native-md4":
163
178
  if (crypto === undefined) crypto = require("crypto");
164
- return new BulkUpdateDecorator(() => crypto.createHash("md4"), "md4");
179
+ return new BulkUpdateDecorator(
180
+ () => /** @type {typeof import("crypto")} */ (crypto).createHash("md4"),
181
+ "md4"
182
+ );
165
183
  default:
166
184
  if (crypto === undefined) crypto = require("crypto");
167
185
  return new BulkUpdateDecorator(
168
- () => crypto.createHash(algorithm),
186
+ () =>
187
+ /** @type {typeof import("crypto")} */ (crypto).createHash(
188
+ /** @type {string} */ (algorithm)
189
+ ),
169
190
  algorithm
170
191
  );
171
192
  }
@@ -78,7 +78,7 @@ exports.arrayToSetDeprecation = (set, name) => {
78
78
  );
79
79
  /**
80
80
  * @deprecated
81
- * @this {Set}
81
+ * @this {Set<any>}
82
82
  * @returns {number} count
83
83
  */
84
84
  set[method] = function () {
@@ -101,7 +101,7 @@ exports.arrayToSetDeprecation = (set, name) => {
101
101
  );
102
102
  /**
103
103
  * @deprecated
104
- * @this {Set}
104
+ * @this {Set<any>}
105
105
  * @returns {number} count
106
106
  */
107
107
  set.push = function () {
@@ -119,9 +119,13 @@ exports.arrayToSetDeprecation = (set, name) => {
119
119
  );
120
120
  };
121
121
  }
122
+ /**
123
+ * @param {number} index index
124
+ * @returns {any} value
125
+ */
122
126
  const createIndexGetter = index => {
123
127
  /**
124
- * @this {Set} a Set
128
+ * @this {Set<any>} a Set
125
129
  * @returns {any} the value at this location
126
130
  */
127
131
  const fn = function () {
@@ -134,6 +138,9 @@ exports.arrayToSetDeprecation = (set, name) => {
134
138
  };
135
139
  return fn;
136
140
  };
141
+ /**
142
+ * @param {number} index index
143
+ */
137
144
  const defineIndexGetter = index => {
138
145
  Object.defineProperty(set, index, {
139
146
  get: createIndexGetter(index),
@@ -94,7 +94,8 @@ const subtractSizeFrom = (total, size) => {
94
94
  };
95
95
 
96
96
  /**
97
- * @param {Iterable<Node>} nodes some nodes
97
+ * @template T
98
+ * @param {Iterable<Node<T>>} nodes some nodes
98
99
  * @returns {Record<string, number>} total size
99
100
  */
100
101
  const sumSize = nodes => {
@@ -105,6 +106,11 @@ const sumSize = nodes => {
105
106
  return sum;
106
107
  };
107
108
 
109
+ /**
110
+ * @param {Record<string, number>} size size
111
+ * @param {Record<string, number>} maxSize minimum size
112
+ * @returns {boolean} true, when size is too big
113
+ */
108
114
  const isTooBig = (size, maxSize) => {
109
115
  for (const key of Object.keys(size)) {
110
116
  const s = size[key];
@@ -117,6 +123,11 @@ const isTooBig = (size, maxSize) => {
117
123
  return false;
118
124
  };
119
125
 
126
+ /**
127
+ * @param {Record<string, number>} size size
128
+ * @param {Record<string, number>} minSize minimum size
129
+ * @returns {boolean} true, when size is too small
130
+ */
120
131
  const isTooSmall = (size, minSize) => {
121
132
  for (const key of Object.keys(size)) {
122
133
  const s = size[key];
@@ -129,6 +140,11 @@ const isTooSmall = (size, minSize) => {
129
140
  return false;
130
141
  };
131
142
 
143
+ /**
144
+ * @param {Record<string, number>} size size
145
+ * @param {Record<string, number>} minSize minimum size
146
+ * @returns {Set<string>} set of types that are too small
147
+ */
132
148
  const getTooSmallTypes = (size, minSize) => {
133
149
  const types = new Set();
134
150
  for (const key of Object.keys(size)) {
@@ -142,6 +158,12 @@ const getTooSmallTypes = (size, minSize) => {
142
158
  return types;
143
159
  };
144
160
 
161
+ /**
162
+ * @template T
163
+ * @param {TODO} size size
164
+ * @param {Set<string>} types types
165
+ * @returns {number} number of matching size types
166
+ */
145
167
  const getNumberOfMatchingSizeTypes = (size, types) => {
146
168
  let i = 0;
147
169
  for (const key of Object.keys(size)) {
@@ -150,6 +172,11 @@ const getNumberOfMatchingSizeTypes = (size, types) => {
150
172
  return i;
151
173
  };
152
174
 
175
+ /**
176
+ * @param {Record<string, number>} size size
177
+ * @param {Set<string>} types types
178
+ * @returns {number} selective size sum
179
+ */
153
180
  const selectiveSizeSum = (size, types) => {
154
181
  let sum = 0;
155
182
  for (const key of Object.keys(size)) {
@@ -180,20 +207,20 @@ class Node {
180
207
  class Group {
181
208
  /**
182
209
  * @param {Node<T>[]} nodes nodes
183
- * @param {number[]} similarities similarities between the nodes (length = nodes.length - 1)
210
+ * @param {number[] | null} similarities similarities between the nodes (length = nodes.length - 1)
184
211
  * @param {Record<string, number>=} size size of the group
185
212
  */
186
213
  constructor(nodes, similarities, size) {
187
214
  this.nodes = nodes;
188
215
  this.similarities = similarities;
189
216
  this.size = size || sumSize(nodes);
190
- /** @type {string} */
217
+ /** @type {string | undefined} */
191
218
  this.key = undefined;
192
219
  }
193
220
 
194
221
  /**
195
- * @param {function(Node): boolean} filter filter function
196
- * @returns {Node[]} removed nodes
222
+ * @param {function(Node<T>): boolean} filter filter function
223
+ * @returns {Node<T>[] | undefined} removed nodes
197
224
  */
198
225
  popNodes(filter) {
199
226
  const newNodes = [];
@@ -208,7 +235,7 @@ class Group {
208
235
  if (newNodes.length > 0) {
209
236
  newSimilarities.push(
210
237
  lastNode === this.nodes[i - 1]
211
- ? this.similarities[i - 1]
238
+ ? /** @type {number[]} */ (this.similarities)[i - 1]
212
239
  : similarity(lastNode.key, node.key)
213
240
  );
214
241
  }
@@ -225,7 +252,8 @@ class Group {
225
252
  }
226
253
 
227
254
  /**
228
- * @param {Iterable<Node>} nodes nodes
255
+ * @template T
256
+ * @param {Iterable<Node<T>>} nodes nodes
229
257
  * @returns {number[]} similarities
230
258
  */
231
259
  const getSimilarities = nodes => {
@@ -297,6 +325,11 @@ module.exports = ({ maxSize, minSize, items, getSize, getKey }) => {
297
325
  if (initialNodes.length > 0) {
298
326
  const initialGroup = new Group(initialNodes, getSimilarities(initialNodes));
299
327
 
328
+ /**
329
+ * @param {Group<T>} group group
330
+ * @param {Record<string, number>} consideredSize size of the group to consider
331
+ * @returns {boolean} true, if the group was modified
332
+ */
300
333
  const removeProblematicNodes = (group, consideredSize = group.size) => {
301
334
  const problemTypes = getTooSmallTypes(consideredSize, minSize);
302
335
  if (problemTypes.size > 0) {
@@ -347,7 +380,7 @@ module.exports = ({ maxSize, minSize, items, getSize, getKey }) => {
347
380
  const queue = [initialGroup];
348
381
 
349
382
  while (queue.length) {
350
- const group = queue.pop();
383
+ const group = /** @type {Group<T>} */ (queue.pop());
351
384
  // only groups bigger than maxSize need to be splitted
352
385
  if (!isTooBig(group.size, maxSize)) {
353
386
  result.push(group);
@@ -428,7 +461,9 @@ module.exports = ({ maxSize, minSize, items, getSize, getKey }) => {
428
461
  // rightSize ^^^^^^^^^^^^^^^
429
462
 
430
463
  while (pos <= right + 1) {
431
- const similarity = group.similarities[pos - 1];
464
+ const similarity = /** @type {number[]} */ (group.similarities)[
465
+ pos - 1
466
+ ];
432
467
  if (
433
468
  similarity < bestSimilarity &&
434
469
  !isTooSmall(leftSize, minSize) &&
@@ -458,7 +493,9 @@ module.exports = ({ maxSize, minSize, items, getSize, getKey }) => {
458
493
  /** @type {number[]} */
459
494
  const rightSimilarities = [];
460
495
  for (let i = right + 2; i < group.nodes.length; i++) {
461
- rightSimilarities.push(group.similarities[i - 1]);
496
+ rightSimilarities.push(
497
+ /** @type {number[]} */ (group.similarities)[i - 1]
498
+ );
462
499
  rightNodes.push(group.nodes[i]);
463
500
  }
464
501
  queue.push(new Group(rightNodes, rightSimilarities));
@@ -467,7 +504,9 @@ module.exports = ({ maxSize, minSize, items, getSize, getKey }) => {
467
504
  /** @type {number[]} */
468
505
  const leftSimilarities = [];
469
506
  for (let i = 1; i < left; i++) {
470
- leftSimilarities.push(group.similarities[i - 1]);
507
+ leftSimilarities.push(
508
+ /** @type {number[]} */ (group.similarities)[i - 1]
509
+ );
471
510
  leftNodes.push(group.nodes[i]);
472
511
  }
473
512
  queue.push(new Group(leftNodes, leftSimilarities));
@@ -109,7 +109,9 @@ module.exports = (items, getDependencies) => {
109
109
  // Are there still edges unprocessed in the current node?
110
110
  if (topOfStack.openEdges.length > 0) {
111
111
  // Process one dependency
112
- const dependency = topOfStack.openEdges.pop();
112
+ const dependency =
113
+ /** @type {Node<T>} */
114
+ (topOfStack.openEdges.pop());
113
115
  switch (dependency.marker) {
114
116
  case NO_MARKER:
115
117
  // dependency has not be visited yet
@@ -169,7 +171,7 @@ module.exports = (items, getDependencies) => {
169
171
  // so it's not really a root cycle
170
172
  // remove the cycle from the root cycles
171
173
  // and convert it to a normal node
172
- rootCycles.delete(dependency.cycle);
174
+ rootCycles.delete(/** @type {Cycle<T>} */ (dependency.cycle));
173
175
  dependency.marker = DONE_MARKER;
174
176
  break;
175
177
  // DONE_MARKER: nothing to do, don't recurse into dependencies
@@ -13,18 +13,18 @@
13
13
  */
14
14
  const memoize = fn => {
15
15
  let cache = false;
16
- /** @type {T} */
16
+ /** @type {T | undefined} */
17
17
  let result = undefined;
18
18
  return () => {
19
19
  if (cache) {
20
- return result;
20
+ return /** @type {T} */ (result);
21
21
  } else {
22
22
  result = fn();
23
23
  cache = true;
24
24
  // Allow to clean up memory for fn
25
25
  // and all dependent resources
26
26
  fn = undefined;
27
- return result;
27
+ return /** @type {T} */ (result);
28
28
  }
29
29
  };
30
30
  };
@@ -21,6 +21,9 @@ const processAsyncTree = (items, concurrency, processor, callback) => {
21
21
  let finished = false;
22
22
  let processScheduled = true;
23
23
 
24
+ /**
25
+ * @param {T} item item
26
+ */
24
27
  const push = item => {
25
28
  queue.push(item);
26
29
  if (!processScheduled && processing < concurrency) {
@@ -29,6 +32,9 @@ const processAsyncTree = (items, concurrency, processor, callback) => {
29
32
  }
30
33
  };
31
34
 
35
+ /**
36
+ * @param {E | null | undefined} err error
37
+ */
32
38
  const processorCallback = err => {
33
39
  processing--;
34
40
  if (err && !finished) {
@@ -46,7 +52,7 @@ const processAsyncTree = (items, concurrency, processor, callback) => {
46
52
  if (finished) return;
47
53
  while (processing < concurrency && queue.length > 0) {
48
54
  processing++;
49
- const item = queue.pop();
55
+ const item = /** @type {T} */ (queue.pop());
50
56
  processor(item, push, processorCallback);
51
57
  }
52
58
  processScheduled = false;
@@ -26,7 +26,7 @@ const {
26
26
  /** @typedef {import("./serialization").ObjectDeserializerContext} ObjectDeserializerContext */
27
27
  /** @typedef {import("./serialization").ObjectSerializerContext} ObjectSerializerContext */
28
28
 
29
- /** @typedef {ObjectSerializerContext & { writeLazy?: (any) => void }} WebpackObjectSerializerContext */
29
+ /** @typedef {ObjectSerializerContext & { writeLazy?: (value: any) => void }} WebpackObjectSerializerContext */
30
30
 
31
31
  const CURRENT_MODULE = "webpack/lib/util/registerExternalSerializer";
32
32
 
@@ -434,7 +434,7 @@ class RuntimeSpecMap {
434
434
 
435
435
  /**
436
436
  * @param {RuntimeSpec} runtime the runtimes
437
- * @returns {T} value
437
+ * @returns {T | undefined} value
438
438
  */
439
439
  get(runtime) {
440
440
  switch (this._mode) {
@@ -517,6 +517,9 @@ class RuntimeSpecMap {
517
517
  }
518
518
  }
519
519
 
520
+ /**
521
+ * @param {RuntimeSpec} runtime the runtimes
522
+ */
520
523
  delete(runtime) {
521
524
  switch (this._mode) {
522
525
  case 0:
@@ -593,6 +596,9 @@ class RuntimeSpecMap {
593
596
  exports.RuntimeSpecMap = RuntimeSpecMap;
594
597
 
595
598
  class RuntimeSpecSet {
599
+ /**
600
+ * @param {Iterable<RuntimeSpec>=} iterable iterable
601
+ */
596
602
  constructor(iterable) {
597
603
  /** @type {Map<string, RuntimeSpec>} */
598
604
  this._map = new Map();
@@ -603,10 +609,17 @@ class RuntimeSpecSet {
603
609
  }
604
610
  }
605
611
 
612
+ /**
613
+ * @param {RuntimeSpec} runtime runtime
614
+ */
606
615
  add(runtime) {
607
616
  this._map.set(getRuntimeKey(runtime), runtime);
608
617
  }
609
618
 
619
+ /**
620
+ * @param {RuntimeSpec} runtime runtime
621
+ * @returns {boolean} true, when the runtime exists
622
+ */
610
623
  has(runtime) {
611
624
  return this._map.has(getRuntimeKey(runtime));
612
625
  }
@@ -110,7 +110,7 @@ const smartGrouping = (items, groupConfigs) => {
110
110
  /** @type {(T | R)[]} */
111
111
  const results = [];
112
112
  for (;;) {
113
- /** @type {Group<T, R>} */
113
+ /** @type {Group<T, R> | undefined} */
114
114
  let bestGroup = undefined;
115
115
  let bestGroupSize = -1;
116
116
  let bestGroupItems = undefined;
@@ -119,7 +119,9 @@ const validateSchema = (schema, options, validationConfiguration) => {
119
119
  )
120
120
  ) {
121
121
  return `${formattedError}\nDid you mean ${
122
- DID_YOU_MEAN[params.additionalProperty]
122
+ DID_YOU_MEAN[
123
+ /** @type {keyof DID_YOU_MEAN} */ (params.additionalProperty)
124
+ ]
123
125
  }?`;
124
126
  }
125
127
 
@@ -129,7 +131,9 @@ const validateSchema = (schema, options, validationConfiguration) => {
129
131
  params.additionalProperty
130
132
  )
131
133
  ) {
132
- return `${formattedError}\n${REMOVED[params.additionalProperty]}?`;
134
+ return `${formattedError}\n${
135
+ REMOVED[/** @type {keyof REMOVED} */ (params.additionalProperty)]
136
+ }?`;
133
137
  }
134
138
 
135
139
  if (!error.dataPath) {
@@ -9,6 +9,9 @@ const RuntimeGlobals = require("../RuntimeGlobals");
9
9
  const RuntimeModule = require("../RuntimeModule");
10
10
  const Template = require("../Template");
11
11
 
12
+ /** @typedef {import("../Chunk")} Chunk */
13
+ /** @typedef {import("../Compilation")} Compilation */
14
+
12
15
  /**
13
16
  * @typedef {Object} AsyncWasmLoadingRuntimeModuleOptions
14
17
  * @property {function(string): string} generateLoadBinaryCode
@@ -29,7 +32,8 @@ class AsyncWasmLoadingRuntimeModule extends RuntimeModule {
29
32
  * @returns {string} runtime code
30
33
  */
31
34
  generate() {
32
- const { compilation, chunk } = this;
35
+ const compilation = /** @type {Compilation} */ (this.compilation);
36
+ const chunk = /** @type {Chunk} */ (this.chunk);
33
37
  const { outputOptions, runtimeTemplate } = compilation;
34
38
  const fn = RuntimeGlobals.instantiateWasm;
35
39
  const wasmModuleSrcPath = compilation.getPath(
@@ -11,6 +11,8 @@ const Parser = require("../Parser");
11
11
  const StaticExportsDependency = require("../dependencies/StaticExportsDependency");
12
12
  const WebAssemblyImportDependency = require("../dependencies/WebAssemblyImportDependency");
13
13
 
14
+ /** @typedef {import("../Module").BuildInfo} BuildInfo */
15
+ /** @typedef {import("../Module").BuildMeta} BuildMeta */
14
16
  /** @typedef {import("../Parser").ParserState} ParserState */
15
17
  /** @typedef {import("../Parser").PreparsedAst} PreparsedAst */
16
18
 
@@ -43,9 +45,11 @@ class WebAssemblyParser extends Parser {
43
45
  }
44
46
 
45
47
  // flag it as async module
46
- state.module.buildInfo.strict = true;
47
- state.module.buildMeta.exportsType = "namespace";
48
- state.module.buildMeta.async = true;
48
+ const buildInfo = /** @type {BuildInfo} */ (state.module.buildInfo);
49
+ buildInfo.strict = true;
50
+ const BuildMeta = /** @type {BuildMeta} */ (state.module.buildMeta);
51
+ BuildMeta.exportsType = "namespace";
52
+ BuildMeta.async = true;
49
53
 
50
54
  // parse it
51
55
  const program = decode(source, decoderOpts);
@@ -10,6 +10,7 @@ const Template = require("../Template");
10
10
  const { compareModulesByIdentifier } = require("../util/comparators");
11
11
  const WebAssemblyUtils = require("./WebAssemblyUtils");
12
12
 
13
+ /** @typedef {import("@webassemblyjs/ast").Signature} Signature */
13
14
  /** @typedef {import("../Chunk")} Chunk */
14
15
  /** @typedef {import("../ChunkGraph")} ChunkGraph */
15
16
  /** @typedef {import("../Compilation")} Compilation */
@@ -91,9 +92,11 @@ const generateImportObject = (
91
92
  value: `${instanceVar}[${JSON.stringify(usedName)}]`
92
93
  });
93
94
  } else {
94
- const params = description.signature.params.map(
95
- (param, k) => "p" + k + param.valtype
96
- );
95
+ const params =
96
+ /** @type {Signature} */
97
+ (description.signature).params.map(
98
+ (param, k) => "p" + k + param.valtype
99
+ );
97
100
 
98
101
  const mod = `${RuntimeGlobals.moduleCache}[${JSON.stringify(
99
102
  chunkGraph.getModuleId(importedModule)
@@ -130,6 +133,7 @@ const generateImportObject = (
130
133
  "};"
131
134
  ];
132
135
  } else {
136
+ /** @type {Map<string, Array<{ name: string, value: string }>>} */
133
137
  const propertiesByModule = new Map();
134
138
  for (const p of properties) {
135
139
  let list = propertiesByModule.get(p.module);
@@ -225,20 +229,23 @@ class WasmChunkLoadingRuntimeModule extends RuntimeModule {
225
229
  * @returns {string} runtime code
226
230
  */
227
231
  generate() {
228
- const { chunkGraph, compilation, chunk, mangleImports } = this;
229
- const { moduleGraph, outputOptions } = compilation;
230
232
  const fn = RuntimeGlobals.ensureChunkHandlers;
231
233
  const withHmr = this._runtimeRequirements.has(
232
234
  RuntimeGlobals.hmrDownloadUpdateHandlers
233
235
  );
236
+ const compilation = /** @type {Compilation} */ (this.compilation);
237
+ const { moduleGraph, outputOptions } = compilation;
238
+ const chunkGraph = /** @type {ChunkGraph} */ (this.chunkGraph);
239
+ const chunk = /** @type {Chunk} */ (this.chunk);
234
240
  const wasmModules = getAllWasmModules(moduleGraph, chunkGraph, chunk);
241
+ const { mangleImports } = this;
235
242
  /** @type {string[]} */
236
243
  const declarations = [];
237
244
  const importObjects = wasmModules.map(module => {
238
245
  return generateImportObject(
239
246
  chunkGraph,
240
247
  module,
241
- this.mangleImports,
248
+ mangleImports,
242
249
  declarations,
243
250
  chunk.runtime
244
251
  );
@@ -11,6 +11,7 @@ const UnsupportedWebAssemblyFeatureError = require("./UnsupportedWebAssemblyFeat
11
11
  /** @typedef {import("../Compiler")} Compiler */
12
12
  /** @typedef {import("../Dependency")} Dependency */
13
13
  /** @typedef {import("../Module")} Module */
14
+ /** @typedef {import("../Module").BuildMeta} BuildMeta */
14
15
 
15
16
  class WasmFinalizeExportsPlugin {
16
17
  /**
@@ -27,7 +28,8 @@ class WasmFinalizeExportsPlugin {
27
28
  // 1. if a WebAssembly module
28
29
  if (module.type.startsWith("webassembly") === true) {
29
30
  const jsIncompatibleExports =
30
- module.buildMeta.jsIncompatibleExports;
31
+ /** @type {BuildMeta} */
32
+ (module.buildMeta).jsIncompatibleExports;
31
33
 
32
34
  if (jsIncompatibleExports === undefined) {
33
35
  continue;
@@ -174,6 +174,7 @@ const createDefaultInitForGlobal = globalType => {
174
174
  */
175
175
  const rewriteImportedGlobals = state => bin => {
176
176
  const additionalInitCode = state.additionalInitCode;
177
+ /** @type {Array<t.Global>} */
177
178
  const newGlobals = [];
178
179
 
179
180
  bin = editWithAST(state.ast, bin, {
@@ -14,6 +14,8 @@ const WebAssemblyExportImportedDependency = require("../dependencies/WebAssembly
14
14
  const WebAssemblyImportDependency = require("../dependencies/WebAssemblyImportDependency");
15
15
 
16
16
  /** @typedef {import("../Module")} Module */
17
+ /** @typedef {import("../Module").BuildInfo} BuildInfo */
18
+ /** @typedef {import("../Module").BuildMeta} BuildMeta */
17
19
  /** @typedef {import("../Parser").ParserState} ParserState */
18
20
  /** @typedef {import("../Parser").PreparsedAst} PreparsedAst */
19
21
 
@@ -81,8 +83,10 @@ class WebAssemblyParser extends Parser {
81
83
  }
82
84
 
83
85
  // flag it as ESM
84
- state.module.buildInfo.strict = true;
85
- state.module.buildMeta.exportsType = "namespace";
86
+ /** @type {BuildInfo} */
87
+ (state.module.buildInfo).strict = true;
88
+ /** @type {BuildMeta} */
89
+ (state.module.buildMeta).exportsType = "namespace";
86
90
 
87
91
  // parse it
88
92
  const program = decode(source, decoderOpts);
@@ -14,6 +14,7 @@ const { getInitialChunkIds } = require("../javascript/StartupHelpers");
14
14
  const compileBooleanMatcher = require("../util/compileBooleanMatcher");
15
15
 
16
16
  /** @typedef {import("../Chunk")} Chunk */
17
+ /** @typedef {import("../ChunkGraph")} ChunkGraph */
17
18
 
18
19
  /**
19
20
  * @typedef {Object} JsonpCompilationPluginHooks
@@ -72,7 +73,7 @@ class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
72
73
  * @returns {string} runtime code
73
74
  */
74
75
  generate() {
75
- const { chunkGraph, compilation, chunk } = this;
76
+ const compilation = /** @type {Compilation} */ (this.compilation);
76
77
  const {
77
78
  runtimeTemplate,
78
79
  outputOptions: {
@@ -108,9 +109,14 @@ class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
108
109
  const withPreload = this._runtimeRequirements.has(
109
110
  RuntimeGlobals.preloadChunkHandlers
110
111
  );
112
+ const withFetchPriority = this._runtimeRequirements.has(
113
+ RuntimeGlobals.hasFetchPriority
114
+ );
111
115
  const chunkLoadingGlobalExpr = `${globalObject}[${JSON.stringify(
112
116
  chunkLoadingGlobal
113
117
  )}]`;
118
+ const chunkGraph = /** @type {ChunkGraph} */ (this.chunkGraph);
119
+ const chunk = /** @type {Chunk} */ (this.chunk);
114
120
  const conditionMap = chunkGraph.getChunkConditionMap(chunk, chunkHasJs);
115
121
  const hasJsMatcher = compileBooleanMatcher(conditionMap);
116
122
  const initialChunkIds = getInitialChunkIds(chunk, chunkGraph, chunkHasJs);
@@ -138,7 +144,7 @@ class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
138
144
  withLoading
139
145
  ? Template.asString([
140
146
  `${fn}.j = ${runtimeTemplate.basicFunction(
141
- "chunkId, promises",
147
+ `chunkId, promises${withFetchPriority ? ", fetchPriority" : ""}`,
142
148
  hasJsMatcher !== false
143
149
  ? Template.indent([
144
150
  "// JSONP chunk loading for javascript",
@@ -190,7 +196,11 @@ class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
190
196
  "}"
191
197
  ]
192
198
  )};`,
193
- `${RuntimeGlobals.loadScript}(url, loadingEnded, "chunk-" + chunkId, chunkId);`
199
+ `${
200
+ RuntimeGlobals.loadScript
201
+ }(url, loadingEnded, "chunk-" + chunkId, chunkId${
202
+ withFetchPriority ? ", fetchPriority" : ""
203
+ });`
194
204
  ]),
195
205
  hasJsMatcher === true
196
206
  ? "}"