webpack 5.90.2 → 5.91.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 (182) hide show
  1. package/README.md +5 -5
  2. package/bin/webpack.js +5 -1
  3. package/lib/APIPlugin.js +8 -4
  4. package/lib/AutomaticPrefetchPlugin.js +1 -1
  5. package/lib/BannerPlugin.js +3 -1
  6. package/lib/Cache.js +7 -1
  7. package/lib/CacheFacade.js +3 -3
  8. package/lib/ChunkGraph.js +32 -18
  9. package/lib/ChunkGroup.js +14 -14
  10. package/lib/CleanPlugin.js +7 -5
  11. package/lib/Compilation.js +263 -94
  12. package/lib/Compiler.js +199 -83
  13. package/lib/ConditionalInitFragment.js +4 -5
  14. package/lib/ContextModule.js +4 -1
  15. package/lib/ContextModuleFactory.js +4 -2
  16. package/lib/ContextReplacementPlugin.js +3 -2
  17. package/lib/CssModule.js +0 -3
  18. package/lib/DefinePlugin.js +4 -2
  19. package/lib/DelegatedModule.js +2 -1
  20. package/lib/Dependency.js +4 -2
  21. package/lib/DependencyTemplate.js +7 -2
  22. package/lib/DllModule.js +3 -1
  23. package/lib/DllReferencePlugin.js +6 -2
  24. package/lib/EntryOptionPlugin.js +4 -1
  25. package/lib/EntryPlugin.js +6 -1
  26. package/lib/Entrypoint.js +1 -1
  27. package/lib/ExportsInfo.js +1 -4
  28. package/lib/ExternalModule.js +120 -25
  29. package/lib/ExternalModuleFactoryPlugin.js +37 -2
  30. package/lib/FileSystemInfo.js +1 -1
  31. package/lib/Generator.js +2 -1
  32. package/lib/HookWebpackError.js +2 -2
  33. package/lib/InitFragment.js +5 -3
  34. package/lib/LibManifestPlugin.js +15 -7
  35. package/lib/Module.js +54 -5
  36. package/lib/ModuleFilenameHelpers.js +1 -1
  37. package/lib/ModuleGraph.js +56 -27
  38. package/lib/ModuleGraphConnection.js +2 -1
  39. package/lib/MultiCompiler.js +61 -17
  40. package/lib/NodeStuffPlugin.js +14 -3
  41. package/lib/NormalModule.js +239 -86
  42. package/lib/NormalModuleFactory.js +163 -32
  43. package/lib/NormalModuleReplacementPlugin.js +5 -1
  44. package/lib/ProvidePlugin.js +3 -1
  45. package/lib/RawModule.js +4 -2
  46. package/lib/ResolverFactory.js +5 -1
  47. package/lib/RuntimeModule.js +6 -5
  48. package/lib/RuntimePlugin.js +1 -0
  49. package/lib/RuntimeTemplate.js +102 -34
  50. package/lib/SourceMapDevToolPlugin.js +4 -1
  51. package/lib/Stats.js +12 -5
  52. package/lib/TemplatedPathPlugin.js +32 -6
  53. package/lib/Watching.js +67 -60
  54. package/lib/WebpackError.js +6 -6
  55. package/lib/WebpackOptionsApply.js +18 -5
  56. package/lib/asset/RawDataUrlModule.js +5 -2
  57. package/lib/async-modules/AwaitDependenciesInitFragment.js +2 -2
  58. package/lib/buildChunkGraph.js +220 -392
  59. package/lib/cache/IdleFileCachePlugin.js +8 -3
  60. package/lib/cache/MemoryCachePlugin.js +1 -1
  61. package/lib/cache/MemoryWithGcCachePlugin.js +6 -2
  62. package/lib/cache/PackFileCacheStrategy.js +49 -16
  63. package/lib/cache/ResolverCachePlugin.js +14 -6
  64. package/lib/cache/getLazyHashedEtag.js +1 -1
  65. package/lib/config/defaults.js +24 -1
  66. package/lib/config/normalization.js +3 -1
  67. package/lib/container/ContainerEntryDependency.js +2 -1
  68. package/lib/container/ContainerEntryModule.js +5 -2
  69. package/lib/container/ContainerPlugin.js +14 -10
  70. package/lib/container/FallbackModule.js +3 -2
  71. package/lib/container/RemoteModule.js +2 -1
  72. package/lib/container/RemoteRuntimeModule.js +12 -3
  73. package/lib/css/CssExportsGenerator.js +34 -17
  74. package/lib/css/CssGenerator.js +20 -2
  75. package/lib/css/CssLoadingRuntimeModule.js +212 -96
  76. package/lib/css/CssModulesPlugin.js +47 -13
  77. package/lib/debug/ProfilingPlugin.js +27 -2
  78. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +9 -5
  79. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +4 -1
  80. package/lib/dependencies/CommonJsDependencyHelpers.js +2 -1
  81. package/lib/dependencies/CommonJsExportRequireDependency.js +33 -18
  82. package/lib/dependencies/CommonJsExportsDependency.js +13 -5
  83. package/lib/dependencies/CommonJsExportsParserPlugin.js +20 -15
  84. package/lib/dependencies/CommonJsImportsParserPlugin.js +1 -2
  85. package/lib/dependencies/ContextDependencyHelpers.js +49 -29
  86. package/lib/dependencies/ContextElementDependency.js +8 -1
  87. package/lib/dependencies/CssLocalIdentifierDependency.js +63 -8
  88. package/lib/dependencies/CssUrlDependency.js +5 -3
  89. package/lib/dependencies/ExportsInfoDependency.js +4 -3
  90. package/lib/dependencies/ExternalModuleInitFragment.js +5 -3
  91. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +4 -4
  92. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +43 -23
  93. package/lib/dependencies/HarmonyExportHeaderDependency.js +1 -1
  94. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +73 -32
  95. package/lib/dependencies/HarmonyExportInitFragment.js +10 -2
  96. package/lib/dependencies/HarmonyImportDependency.js +28 -12
  97. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +44 -16
  98. package/lib/dependencies/HarmonyImportSideEffectDependency.js +7 -6
  99. package/lib/dependencies/HarmonyImportSpecifierDependency.js +21 -10
  100. package/lib/dependencies/ImportDependency.js +9 -2
  101. package/lib/dependencies/ImportEagerDependency.js +4 -2
  102. package/lib/dependencies/ImportMetaContextDependency.js +7 -0
  103. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +25 -14
  104. package/lib/dependencies/ImportParserPlugin.js +12 -4
  105. package/lib/dependencies/ImportWeakDependency.js +4 -2
  106. package/lib/dependencies/LoaderDependency.js +2 -1
  107. package/lib/dependencies/LoaderImportDependency.js +2 -1
  108. package/lib/dependencies/ModuleDependency.js +4 -5
  109. package/lib/dependencies/PureExpressionDependency.js +4 -1
  110. package/lib/dependencies/RequireContextPlugin.js +1 -1
  111. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +26 -14
  112. package/lib/dependencies/RequireEnsureDependency.js +1 -1
  113. package/lib/dependencies/URLDependency.js +7 -4
  114. package/lib/dependencies/WorkerDependency.js +1 -1
  115. package/lib/dependencies/WorkerPlugin.js +6 -5
  116. package/lib/dependencies/getFunctionExpression.js +3 -1
  117. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +2 -1
  118. package/lib/hmr/LazyCompilationPlugin.js +2 -1
  119. package/lib/javascript/BasicEvaluatedExpression.js +2 -2
  120. package/lib/javascript/ChunkHelpers.js +2 -2
  121. package/lib/javascript/JavascriptParser.js +169 -57
  122. package/lib/javascript/JavascriptParserHelpers.js +1 -1
  123. package/lib/javascript/StartupHelpers.js +22 -5
  124. package/lib/logging/Logger.js +27 -2
  125. package/lib/logging/createConsoleLogger.js +11 -7
  126. package/lib/node/NodeEnvironmentPlugin.js +13 -7
  127. package/lib/node/NodeWatchFileSystem.js +37 -26
  128. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +2 -1
  129. package/lib/node/RequireChunkLoadingRuntimeModule.js +2 -1
  130. package/lib/node/nodeConsole.js +24 -1
  131. package/lib/optimize/AggressiveSplittingPlugin.js +1 -0
  132. package/lib/optimize/ConcatenatedModule.js +140 -55
  133. package/lib/optimize/EnsureChunkConditionsPlugin.js +1 -1
  134. package/lib/optimize/InnerGraph.js +7 -2
  135. package/lib/optimize/InnerGraphPlugin.js +36 -13
  136. package/lib/optimize/ModuleConcatenationPlugin.js +12 -2
  137. package/lib/optimize/RemoveParentModulesPlugin.js +1 -0
  138. package/lib/optimize/RuntimeChunkPlugin.js +6 -1
  139. package/lib/optimize/SideEffectsFlagPlugin.js +46 -15
  140. package/lib/optimize/SplitChunksPlugin.js +2 -2
  141. package/lib/performance/SizeLimitsPlugin.js +11 -0
  142. package/lib/rules/ObjectMatcherRulePlugin.js +4 -0
  143. package/lib/runtime/EnsureChunkRuntimeModule.js +2 -1
  144. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +2 -1
  145. package/lib/serialization/FileMiddleware.js +1 -0
  146. package/lib/serialization/ObjectMiddleware.js +2 -0
  147. package/lib/serialization/Serializer.js +19 -0
  148. package/lib/sharing/ConsumeSharedModule.js +3 -2
  149. package/lib/sharing/ConsumeSharedPlugin.js +17 -3
  150. package/lib/sharing/ConsumeSharedRuntimeModule.js +9 -2
  151. package/lib/sharing/ProvideSharedModule.js +2 -1
  152. package/lib/sharing/ProvideSharedPlugin.js +12 -5
  153. package/lib/sharing/resolveMatchedConfigs.js +2 -2
  154. package/lib/sharing/utils.js +13 -6
  155. package/lib/util/StackedCacheMap.js +26 -0
  156. package/lib/util/WeakTupleMap.js +57 -13
  157. package/lib/util/cleverMerge.js +24 -11
  158. package/lib/util/comparators.js +34 -14
  159. package/lib/util/conventions.js +129 -0
  160. package/lib/util/fs.js +379 -65
  161. package/lib/util/hash/BatchedHash.js +3 -0
  162. package/lib/util/hash/xxhash64.js +2 -2
  163. package/lib/util/memoize.js +2 -0
  164. package/lib/util/runtime.js +1 -1
  165. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +4 -2
  166. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +15 -6
  167. package/lib/wasm-sync/WebAssemblyGenerator.js +27 -6
  168. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +2 -1
  169. package/lib/wasm-sync/WebAssemblyParser.js +7 -4
  170. package/lib/web/JsonpChunkLoadingRuntimeModule.js +2 -1
  171. package/lib/webpack.js +11 -5
  172. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +2 -1
  173. package/package.json +25 -26
  174. package/schemas/WebpackOptions.check.js +1 -1
  175. package/schemas/WebpackOptions.json +69 -8
  176. package/schemas/plugins/BannerPlugin.check.js +1 -1
  177. package/schemas/plugins/BannerPlugin.json +5 -1
  178. package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +1 -1
  179. package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -1
  180. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +1 -1
  181. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
  182. package/types.d.ts +1772 -673
@@ -19,8 +19,10 @@ const InnerGraph = require("./InnerGraph");
19
19
  /** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
20
20
  /** @typedef {import("../Compiler")} Compiler */
21
21
  /** @typedef {import("../Dependency")} Dependency */
22
+ /** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
22
23
  /** @typedef {import("../dependencies/HarmonyImportSpecifierDependency")} HarmonyImportSpecifierDependency */
23
24
  /** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
25
+ /** @typedef {import("../javascript/JavascriptParser").Range} Range */
24
26
  /** @typedef {import("./InnerGraph").InnerGraph} InnerGraph */
25
27
  /** @typedef {import("./InnerGraph").TopLevelSymbol} TopLevelSymbol */
26
28
 
@@ -123,7 +125,10 @@ class InnerGraphPlugin {
123
125
  if (parser.scope.topLevelScope === true) {
124
126
  if (
125
127
  statement.type === "ClassDeclaration" &&
126
- parser.isPure(statement, statement.range[0])
128
+ parser.isPure(
129
+ statement,
130
+ /** @type {Range} */ (statement.range)[0]
131
+ )
127
132
  ) {
128
133
  const name = statement.id ? statement.id.name : "*default*";
129
134
  const fn = InnerGraph.tagTopLevelSymbol(parser, name);
@@ -137,10 +142,12 @@ class InnerGraphPlugin {
137
142
  if (
138
143
  (decl.type === "ClassExpression" ||
139
144
  decl.type === "ClassDeclaration") &&
140
- parser.isPure(decl, decl.range[0])
145
+ parser.isPure(decl, /** @type {Range} */ (decl.range)[0])
141
146
  ) {
142
147
  classWithTopLevelSymbol.set(decl, fn);
143
- } else if (parser.isPure(decl, statement.range[0])) {
148
+ } else if (
149
+ parser.isPure(decl, /** @type {Range} */ (statement.range)[0])
150
+ ) {
144
151
  statementWithTopLevelSymbol.set(statement, fn);
145
152
  if (
146
153
  !decl.type.endsWith("FunctionExpression") &&
@@ -164,11 +171,19 @@ class InnerGraphPlugin {
164
171
  const name = decl.id.name;
165
172
  if (
166
173
  decl.init.type === "ClassExpression" &&
167
- parser.isPure(decl.init, decl.id.range[1])
174
+ parser.isPure(
175
+ decl.init,
176
+ /** @type {Range} */ (decl.id.range)[1]
177
+ )
168
178
  ) {
169
179
  const fn = InnerGraph.tagTopLevelSymbol(parser, name);
170
180
  classWithTopLevelSymbol.set(decl.init, fn);
171
- } else if (parser.isPure(decl.init, decl.id.range[1])) {
181
+ } else if (
182
+ parser.isPure(
183
+ decl.init,
184
+ /** @type {Range} */ (decl.id.range)[1]
185
+ )
186
+ ) {
172
187
  const fn = InnerGraph.tagTopLevelSymbol(parser, name);
173
188
  declWithTopLevelSymbol.set(decl, fn);
174
189
  if (
@@ -214,9 +229,11 @@ class InnerGraphPlugin {
214
229
  return;
215
230
  default: {
216
231
  const dep = new PureExpressionDependency(
217
- purePart.range
232
+ /** @type {Range} */ (purePart.range)
218
233
  );
219
- dep.loc = statement.loc;
234
+ dep.loc =
235
+ /** @type {DependencyLocation} */
236
+ (statement.loc);
220
237
  dep.usedByExports = usedByExports;
221
238
  parser.state.module.addDependency(dep);
222
239
  break;
@@ -238,7 +255,9 @@ class InnerGraphPlugin {
238
255
  fn &&
239
256
  parser.isPure(
240
257
  expr,
241
- statement.id ? statement.id.range[1] : statement.range[0]
258
+ statement.id
259
+ ? /** @type {Range} */ (statement.id.range)[1]
260
+ : /** @type {Range} */ (statement.range)[0]
242
261
  )
243
262
  ) {
244
263
  InnerGraph.setTopLevelSymbol(parser.state, fn);
@@ -272,7 +291,9 @@ class InnerGraphPlugin {
272
291
  !element.static ||
273
292
  parser.isPure(
274
293
  expression,
275
- element.key ? element.key.range[1] : element.range[0]
294
+ element.key
295
+ ? /** @type {Range} */ (element.key.range)[1]
296
+ : /** @type {Range} */ (element.range)[0]
276
297
  )
277
298
  ) {
278
299
  InnerGraph.setTopLevelSymbol(parser.state, fn);
@@ -284,9 +305,11 @@ class InnerGraphPlugin {
284
305
  return;
285
306
  default: {
286
307
  const dep = new PureExpressionDependency(
287
- expression.range
308
+ /** @type {Range} */ (expression.range)
288
309
  );
289
- dep.loc = expression.loc;
310
+ dep.loc =
311
+ /** @type {DependencyLocation} */
312
+ (expression.loc);
290
313
  dep.usedByExports = usedByExports;
291
314
  parser.state.module.addDependency(dep);
292
315
  break;
@@ -321,9 +344,9 @@ class InnerGraphPlugin {
321
344
  return;
322
345
  default: {
323
346
  const dep = new PureExpressionDependency(
324
- decl.init.range
347
+ /** @type {Range} */ (decl.init.range)
325
348
  );
326
- dep.loc = decl.loc;
349
+ dep.loc = /** @type {DependencyLocation} */ (decl.loc);
327
350
  dep.usedByExports = usedByExports;
328
351
  parser.state.module.addDependency(dep);
329
352
  break;
@@ -23,6 +23,7 @@ const ConcatenatedModule = require("./ConcatenatedModule");
23
23
  /** @typedef {import("../Compilation")} Compilation */
24
24
  /** @typedef {import("../Compiler")} Compiler */
25
25
  /** @typedef {import("../Module")} Module */
26
+ /** @typedef {import("../Module").BuildInfo} BuildInfo */
26
27
  /** @typedef {import("../RequestShortener")} RequestShortener */
27
28
  /** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
28
29
 
@@ -49,6 +50,9 @@ const formatBailoutReason = msg => {
49
50
  };
50
51
 
51
52
  class ModuleConcatenationPlugin {
53
+ /**
54
+ * @param {TODO} options options
55
+ */
52
56
  constructor(options) {
53
57
  if (typeof options !== "object") options = {};
54
58
  this.options = options;
@@ -171,7 +175,7 @@ class ModuleConcatenationPlugin {
171
175
  }
172
176
 
173
177
  // Must be in strict mode
174
- if (!module.buildInfo.strict) {
178
+ if (!(/** @type {BuildInfo} */ (module.buildInfo).strict)) {
175
179
  setBailoutReason(module, `Module is not in strict mode`);
176
180
  continue;
177
181
  }
@@ -242,7 +246,10 @@ class ModuleConcatenationPlugin {
242
246
  // this improves performance, because modules already selected as inner are skipped
243
247
  logger.time("sort relevant modules");
244
248
  relevantModules.sort((a, b) => {
245
- return moduleGraph.getDepth(a) - moduleGraph.getDepth(b);
249
+ return (
250
+ /** @type {number} */ (moduleGraph.getDepth(a)) -
251
+ /** @type {number} */ (moduleGraph.getDepth(b))
252
+ );
246
253
  });
247
254
  logger.timeEnd("sort relevant modules");
248
255
 
@@ -927,6 +934,9 @@ class ConcatConfiguration {
927
934
  return this.modules.size;
928
935
  }
929
936
 
937
+ /**
938
+ * @param {number} snapshot snapshot
939
+ */
930
940
  rollback(snapshot) {
931
941
  const modules = this.modules;
932
942
  for (const m of modules) {
@@ -77,6 +77,7 @@ class RemoveParentModulesPlugin {
77
77
 
78
78
  let nextModuleMask = ONE_BIGINT;
79
79
  const maskByModule = new WeakMap();
80
+ /** @type {Module[]} */
80
81
  const ordinalModules = [];
81
82
 
82
83
  /**
@@ -10,6 +10,9 @@
10
10
  /** @typedef {import("../Entrypoint")} Entrypoint */
11
11
 
12
12
  class RuntimeChunkPlugin {
13
+ /**
14
+ * @param {{ name?: (entrypoint: { name: string }) => string }} options options
15
+ */
13
16
  constructor(options) {
14
17
  this.options = {
15
18
  /**
@@ -37,7 +40,9 @@ class RuntimeChunkPlugin {
37
40
  (compilation.entries.get(entryName));
38
41
  if (data.options.runtime === undefined && !data.options.dependOn) {
39
42
  // Determine runtime chunk name
40
- let name = this.options.name;
43
+ let name =
44
+ /** @type {string | ((entrypoint: { name: string }) => string)} */
45
+ (this.options.name);
41
46
  if (typeof name === "function") {
42
47
  name = name({ name: entryName });
43
48
  }
@@ -20,8 +20,11 @@ const formatLocation = require("../formatLocation");
20
20
  /** @typedef {import("estree").Statement} Statement */
21
21
  /** @typedef {import("../Compiler")} Compiler */
22
22
  /** @typedef {import("../Dependency")} Dependency */
23
+ /** @typedef {import("../Dependency").DependencyLocation} DependencyLocation */
23
24
  /** @typedef {import("../Module")} Module */
25
+ /** @typedef {import("../Module").BuildMeta} BuildMeta */
24
26
  /** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
27
+ /** @typedef {import("../javascript/JavascriptParser").Range} Range */
25
28
 
26
29
  /**
27
30
  * @typedef {Object} ExportInModule
@@ -36,7 +39,9 @@ const formatLocation = require("../formatLocation");
36
39
  * @property {Map<Module, Set<string>>} dynamic
37
40
  */
38
41
 
39
- /** @type {WeakMap<any, Map<string, RegExp>>} */
42
+ /** @typedef {Map<string, RegExp>} CacheItem */
43
+
44
+ /** @type {WeakMap<any, CacheItem>} */
40
45
  const globToRegexpCache = new WeakMap();
41
46
 
42
47
  /**
@@ -96,7 +101,7 @@ class SideEffectsFlagPlugin {
96
101
  const hasSideEffects = SideEffectsFlagPlugin.moduleHasSideEffects(
97
102
  resolveData.relativePath,
98
103
  sideEffects,
99
- cache
104
+ /** @type {CacheItem} */ (cache)
100
105
  );
101
106
  module.factoryMeta.sideEffectFree = !hasSideEffects;
102
107
  }
@@ -132,7 +137,10 @@ class SideEffectsFlagPlugin {
132
137
  switch (statement.type) {
133
138
  case "ExpressionStatement":
134
139
  if (
135
- !parser.isPure(statement.expression, statement.range[0])
140
+ !parser.isPure(
141
+ statement.expression,
142
+ /** @type {Range} */ (statement.range)[0]
143
+ )
136
144
  ) {
137
145
  sideEffectsStatement = statement;
138
146
  }
@@ -140,27 +148,35 @@ class SideEffectsFlagPlugin {
140
148
  case "IfStatement":
141
149
  case "WhileStatement":
142
150
  case "DoWhileStatement":
143
- if (!parser.isPure(statement.test, statement.range[0])) {
151
+ if (
152
+ !parser.isPure(
153
+ statement.test,
154
+ /** @type {Range} */ (statement.range)[0]
155
+ )
156
+ ) {
144
157
  sideEffectsStatement = statement;
145
158
  }
146
159
  // statement hook will be called for child statements too
147
160
  break;
148
161
  case "ForStatement":
149
162
  if (
150
- !parser.isPure(statement.init, statement.range[0]) ||
163
+ !parser.isPure(
164
+ statement.init,
165
+ /** @type {Range} */ (statement.range)[0]
166
+ ) ||
151
167
  !parser.isPure(
152
168
  statement.test,
153
169
  statement.init
154
- ? statement.init.range[1]
155
- : statement.range[0]
170
+ ? /** @type {Range} */ (statement.init.range)[1]
171
+ : /** @type {Range} */ (statement.range)[0]
156
172
  ) ||
157
173
  !parser.isPure(
158
174
  statement.update,
159
175
  statement.test
160
- ? statement.test.range[1]
176
+ ? /** @type {Range} */ (statement.test.range)[1]
161
177
  : statement.init
162
- ? statement.init.range[1]
163
- : statement.range[0]
178
+ ? /** @type {Range} */ (statement.init.range)[1]
179
+ : /** @type {Range} */ (statement.range)[0]
164
180
  )
165
181
  ) {
166
182
  sideEffectsStatement = statement;
@@ -169,7 +185,10 @@ class SideEffectsFlagPlugin {
169
185
  break;
170
186
  case "SwitchStatement":
171
187
  if (
172
- !parser.isPure(statement.discriminant, statement.range[0])
188
+ !parser.isPure(
189
+ statement.discriminant,
190
+ /** @type {Range} */ (statement.range)[0]
191
+ )
173
192
  ) {
174
193
  sideEffectsStatement = statement;
175
194
  }
@@ -178,14 +197,22 @@ class SideEffectsFlagPlugin {
178
197
  case "VariableDeclaration":
179
198
  case "ClassDeclaration":
180
199
  case "FunctionDeclaration":
181
- if (!parser.isPure(statement, statement.range[0])) {
200
+ if (
201
+ !parser.isPure(
202
+ statement,
203
+ /** @type {Range} */ (statement.range)[0]
204
+ )
205
+ ) {
182
206
  sideEffectsStatement = statement;
183
207
  }
184
208
  break;
185
209
  case "ExportNamedDeclaration":
186
210
  case "ExportDefaultDeclaration":
187
211
  if (
188
- !parser.isPure(statement.declaration, statement.range[0])
212
+ !parser.isPure(
213
+ statement.declaration,
214
+ /** @type {Range} */ (statement.range)[0]
215
+ )
189
216
  ) {
190
217
  sideEffectsStatement = statement;
191
218
  }
@@ -208,7 +235,8 @@ class SideEffectsFlagPlugin {
208
235
  );
209
236
  parser.hooks.finish.tap(PLUGIN_NAME, () => {
210
237
  if (sideEffectsStatement === undefined) {
211
- parser.state.module.buildMeta.sideEffectFree = true;
238
+ /** @type {BuildMeta} */
239
+ (parser.state.module.buildMeta).sideEffectFree = true;
212
240
  } else {
213
241
  const { loc, type } = sideEffectsStatement;
214
242
  moduleGraph
@@ -216,7 +244,7 @@ class SideEffectsFlagPlugin {
216
244
  .push(
217
245
  () =>
218
246
  `Statement (${type}) with side effects in source code at ${formatLocation(
219
- loc
247
+ /** @type {DependencyLocation} */ (loc)
220
248
  )}`
221
249
  );
222
250
  }
@@ -246,6 +274,9 @@ class SideEffectsFlagPlugin {
246
274
 
247
275
  const optimizedModules = new Set();
248
276
 
277
+ /**
278
+ * @param {Module} module module
279
+ */
249
280
  const optimizeIncomingConnections = module => {
250
281
  if (optimizedModules.has(module)) return;
251
282
  optimizedModules.add(module);
@@ -160,7 +160,7 @@ const MinMaxSizeWarning = require("./MinMaxSizeWarning");
160
160
  * @property {string} name
161
161
  * @property {Record<string, number>} sizes
162
162
  * @property {Set<Chunk>} chunks
163
- * @property {Set<Chunk>} reuseableChunks
163
+ * @property {Set<Chunk>} reusableChunks
164
164
  * @property {Set<bigint | Chunk>} chunksKeys
165
165
  */
166
166
 
@@ -1177,7 +1177,7 @@ module.exports = class SplitChunksPlugin {
1177
1177
  name,
1178
1178
  sizes: {},
1179
1179
  chunks: new Set(),
1180
- reuseableChunks: new Set(),
1180
+ reusableChunks: new Set(),
1181
1181
  chunksKeys: new Set()
1182
1182
  })
1183
1183
  );
@@ -13,6 +13,7 @@ const NoAsyncChunksWarning = require("./NoAsyncChunksWarning");
13
13
  /** @typedef {import("webpack-sources").Source} Source */
14
14
  /** @typedef {import("../../declarations/WebpackOptions").PerformanceOptions} PerformanceOptions */
15
15
  /** @typedef {import("../ChunkGroup")} ChunkGroup */
16
+ /** @typedef {import("../Compilation").Asset} Asset */
16
17
  /** @typedef {import("../Compiler")} Compiler */
17
18
  /** @typedef {import("../Entrypoint")} Entrypoint */
18
19
  /** @typedef {import("../WebpackError")} WebpackError */
@@ -32,6 +33,12 @@ const NoAsyncChunksWarning = require("./NoAsyncChunksWarning");
32
33
 
33
34
  const isOverSizeLimitSet = new WeakSet();
34
35
 
36
+ /**
37
+ * @param {Asset["name"]} name the name
38
+ * @param {Asset["source"]} source the source
39
+ * @param {Asset["info"]} info the info
40
+ * @returns {boolean} result
41
+ */
35
42
  const excludeSourceMap = (name, source, info) => !info.development;
36
43
 
37
44
  module.exports = class SizeLimitsPlugin {
@@ -104,6 +111,10 @@ module.exports = class SizeLimitsPlugin {
104
111
  }
105
112
  }
106
113
 
114
+ /**
115
+ * @param {Asset["name"]} name the name
116
+ * @returns {boolean | undefined} result
117
+ */
107
118
  const fileFilter = name => {
108
119
  const asset = compilation.getAsset(name);
109
120
  return asset && assetFilter(asset.name, asset.source, asset.info);
@@ -9,6 +9,10 @@
9
9
  /** @typedef {import("./RuleSetCompiler").RuleCondition} RuleCondition */
10
10
 
11
11
  class ObjectMatcherRulePlugin {
12
+ /**
13
+ * @param {string} ruleProperty the rule property
14
+ * @param {string=} dataProperty the data property
15
+ */
12
16
  constructor(ruleProperty, dataProperty) {
13
17
  this.ruleProperty = ruleProperty;
14
18
  this.dataProperty = dataProperty || ruleProperty;
@@ -9,10 +9,11 @@ const RuntimeModule = require("../RuntimeModule");
9
9
  const Template = require("../Template");
10
10
 
11
11
  /** @typedef {import("../Compilation")} Compilation */
12
+ /** @typedef {import("../Module").ReadOnlyRuntimeRequirements} ReadOnlyRuntimeRequirements */
12
13
 
13
14
  class EnsureChunkRuntimeModule extends RuntimeModule {
14
15
  /**
15
- * @param {ReadonlySet<string>} runtimeRequirements runtime requirements
16
+ * @param {ReadOnlyRuntimeRequirements} runtimeRequirements runtime requirements
16
17
  */
17
18
  constructor(runtimeRequirements) {
18
19
  super("ensure chunk");
@@ -9,10 +9,11 @@ const Template = require("../Template");
9
9
  const HelperRuntimeModule = require("./HelperRuntimeModule");
10
10
 
11
11
  /** @typedef {import("../Compilation")} Compilation */
12
+ /** @typedef {import("../Module").ReadOnlyRuntimeRequirements} ReadOnlyRuntimeRequirements */
12
13
 
13
14
  class GetTrustedTypesPolicyRuntimeModule extends HelperRuntimeModule {
14
15
  /**
15
- * @param {ReadonlySet<string>} runtimeRequirements runtime requirements
16
+ * @param {ReadOnlyRuntimeRequirements} runtimeRequirements runtime requirements
16
17
  */
17
18
  constructor(runtimeRequirements) {
18
19
  super("trusted types policy");
@@ -576,6 +576,7 @@ class FileMiddleware extends SerializerMiddleware {
576
576
  /** @type {number | undefined} */
577
577
  let currentBufferUsed;
578
578
  const buf = [];
579
+ /** @type {import("zlib").Zlib & import("stream").Transform | undefined} */
579
580
  let decompression;
580
581
  if (file.endsWith(".gz")) {
581
582
  decompression = createGunzip({
@@ -46,6 +46,8 @@ Technically any value can be used.
46
46
  /**
47
47
  * @typedef {Object} ObjectSerializerContext
48
48
  * @property {function(any): void} write
49
+ * @property {(function(any): void)=} writeLazy
50
+ * @property {(function(any, object=): (() => Promise<any> | any))=} writeSeparate
49
51
  * @property {function(any): void} setCircularReference
50
52
  */
51
53
 
@@ -4,13 +4,27 @@
4
4
 
5
5
  "use strict";
6
6
 
7
+ /**
8
+ * @template T, K
9
+ * @typedef {import("./SerializerMiddleware")<T, K>} SerializerMiddleware
10
+ */
11
+
7
12
  class Serializer {
13
+ /**
14
+ * @param {SerializerMiddleware<any, any>[]} middlewares serializer middlewares
15
+ * @param {TODO=} context context
16
+ */
8
17
  constructor(middlewares, context) {
9
18
  this.serializeMiddlewares = middlewares.slice();
10
19
  this.deserializeMiddlewares = middlewares.slice().reverse();
11
20
  this.context = context;
12
21
  }
13
22
 
23
+ /**
24
+ * @param {any} obj object
25
+ * @param {TODO} context content
26
+ * @returns {Promise<any>} result
27
+ */
14
28
  serialize(obj, context) {
15
29
  const ctx = { ...context, ...this.context };
16
30
  let current = obj;
@@ -28,6 +42,11 @@ class Serializer {
28
42
  return current;
29
43
  }
30
44
 
45
+ /**
46
+ * @param {any} value value
47
+ * @param {TODO} context context
48
+ * @returns {Promise<any>} result
49
+ */
31
50
  deserialize(value, context) {
32
51
  const ctx = { ...context, ...this.context };
33
52
  /** @type {any} */
@@ -25,6 +25,7 @@ const ConsumeSharedFallbackDependency = require("./ConsumeSharedFallbackDependen
25
25
  /** @typedef {import("../Module").CodeGenerationResult} CodeGenerationResult */
26
26
  /** @typedef {import("../Module").LibIdentOptions} LibIdentOptions */
27
27
  /** @typedef {import("../Module").NeedBuildContext} NeedBuildContext */
28
+ /** @typedef {import("../Module").SourceTypes} SourceTypes */
28
29
  /** @typedef {import("../RequestShortener")} RequestShortener */
29
30
  /** @typedef {import("../ResolverFactory").ResolverWithOptions} ResolverWithOptions */
30
31
  /** @typedef {import("../WebpackError")} WebpackError */
@@ -41,7 +42,7 @@ const ConsumeSharedFallbackDependency = require("./ConsumeSharedFallbackDependen
41
42
  * @property {string} shareKey global share key
42
43
  * @property {string} shareScope share scope
43
44
  * @property {SemVerRange | false | undefined} requiredVersion version requirement
44
- * @property {string} packageName package name to determine required version automatically
45
+ * @property {string=} packageName package name to determine required version automatically
45
46
  * @property {boolean} strictVersion don't use shared version even if version isn't valid
46
47
  * @property {boolean} singleton use single global version
47
48
  * @property {boolean} eager include the fallback module in a sync way
@@ -147,7 +148,7 @@ class ConsumeSharedModule extends Module {
147
148
  }
148
149
 
149
150
  /**
150
- * @returns {Set<string>} types available (do not mutate)
151
+ * @returns {SourceTypes} types available (do not mutate)
151
152
  */
152
153
  getSourceTypes() {
153
154
  return TYPES;
@@ -117,7 +117,12 @@ class ConsumeSharedPlugin {
117
117
  normalModuleFactory
118
118
  );
119
119
 
120
- let unresolvedConsumes, resolvedConsumes, prefixedConsumes;
120
+ /** @type {Map<string, ConsumeOptions>} */
121
+ let unresolvedConsumes;
122
+ /** @type {Map<string, ConsumeOptions>} */
123
+ let resolvedConsumes;
124
+ /** @type {Map<string, ConsumeOptions>} */
125
+ let prefixedConsumes;
121
126
  const promise = resolveMatchedConfigs(compilation, this._consumes).then(
122
127
  ({ resolved, unresolved, prefixed }) => {
123
128
  resolvedConsumes = resolved;
@@ -138,6 +143,9 @@ class ConsumeSharedPlugin {
138
143
  * @returns {Promise<ConsumeSharedModule>} create module
139
144
  */
140
145
  const createConsumeSharedModule = (context, request, config) => {
146
+ /**
147
+ * @param {string} details details
148
+ */
141
149
  const requiredVersionWarning = details => {
142
150
  const error = new WebpackError(
143
151
  `No required version specified and unable to automatically determine one. ${details}`
@@ -293,9 +301,15 @@ class ConsumeSharedPlugin {
293
301
  ) {
294
302
  return Promise.resolve();
295
303
  }
296
- const options = resolvedConsumes.get(resource);
304
+ const options = resolvedConsumes.get(
305
+ /** @type {string} */ (resource)
306
+ );
297
307
  if (options !== undefined) {
298
- return createConsumeSharedModule(context, resource, options);
308
+ return createConsumeSharedModule(
309
+ context,
310
+ /** @type {string} */ (resource),
311
+ options
312
+ );
299
313
  }
300
314
  return Promise.resolve();
301
315
  }
@@ -17,14 +17,16 @@ const {
17
17
 
18
18
  /** @typedef {import("webpack-sources").Source} Source */
19
19
  /** @typedef {import("../Chunk")} Chunk */
20
+ /** @typedef {import("../Chunk").ChunkId} ChunkId */
20
21
  /** @typedef {import("../ChunkGraph")} ChunkGraph */
21
22
  /** @typedef {import("../Compilation")} Compilation */
22
23
  /** @typedef {import("../Module")} Module */
24
+ /** @typedef {import("../Module").ReadOnlyRuntimeRequirements} ReadOnlyRuntimeRequirements */
23
25
  /** @typedef {import("./ConsumeSharedModule")} ConsumeSharedModule */
24
26
 
25
27
  class ConsumeSharedRuntimeModule extends RuntimeModule {
26
28
  /**
27
- * @param {ReadonlySet<string>} runtimeRequirements runtime requirements
29
+ * @param {ReadOnlyRuntimeRequirements} runtimeRequirements runtime requirements
28
30
  */
29
31
  constructor(runtimeRequirements) {
30
32
  super("consumes", RuntimeModule.STAGE_ATTACH);
@@ -38,6 +40,7 @@ class ConsumeSharedRuntimeModule extends RuntimeModule {
38
40
  const compilation = /** @type {Compilation} */ (this.compilation);
39
41
  const chunkGraph = /** @type {ChunkGraph} */ (this.chunkGraph);
40
42
  const { runtimeTemplate, codeGenerationResults } = compilation;
43
+ /** @type {Record<ChunkId, (string | number)[]>} */
41
44
  const chunkToModuleMapping = {};
42
45
  /** @type {Map<string | number, Source>} */
43
46
  const moduleIdToSourceMapping = new Map();
@@ -70,7 +73,11 @@ class ConsumeSharedRuntimeModule extends RuntimeModule {
70
73
  "consume-shared"
71
74
  );
72
75
  if (!modules) continue;
73
- addModules(modules, chunk, (chunkToModuleMapping[chunk.id] = []));
76
+ addModules(
77
+ modules,
78
+ chunk,
79
+ (chunkToModuleMapping[/** @type {ChunkId} */ (chunk.id)] = [])
80
+ );
74
81
  }
75
82
  for (const chunk of /** @type {Chunk} */ (
76
83
  this.chunk
@@ -21,6 +21,7 @@ const ProvideForSharedDependency = require("./ProvideForSharedDependency");
21
21
  /** @typedef {import("../Module").CodeGenerationResult} CodeGenerationResult */
22
22
  /** @typedef {import("../Module").LibIdentOptions} LibIdentOptions */
23
23
  /** @typedef {import("../Module").NeedBuildContext} NeedBuildContext */
24
+ /** @typedef {import("../Module").SourceTypes} SourceTypes */
24
25
  /** @typedef {import("../RequestShortener")} RequestShortener */
25
26
  /** @typedef {import("../ResolverFactory").ResolverWithOptions} ResolverWithOptions */
26
27
  /** @typedef {import("../WebpackError")} WebpackError */
@@ -120,7 +121,7 @@ class ProvideSharedModule extends Module {
120
121
  }
121
122
 
122
123
  /**
123
- * @returns {Set<string>} types available (do not mutate)
124
+ * @returns {SourceTypes} types available (do not mutate)
124
125
  */
125
126
  getSourceTypes() {
126
127
  return TYPES;