webpack 5.90.3 → 5.92.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 (257) hide show
  1. package/README.md +5 -5
  2. package/bin/webpack.js +6 -3
  3. package/lib/APIPlugin.js +14 -6
  4. package/lib/AutomaticPrefetchPlugin.js +1 -1
  5. package/lib/BannerPlugin.js +3 -1
  6. package/lib/Cache.js +8 -2
  7. package/lib/CacheFacade.js +3 -3
  8. package/lib/Chunk.js +7 -4
  9. package/lib/ChunkGraph.js +52 -25
  10. package/lib/ChunkGroup.js +23 -17
  11. package/lib/CleanPlugin.js +8 -6
  12. package/lib/Compilation.js +295 -120
  13. package/lib/Compiler.js +223 -87
  14. package/lib/ConcatenationScope.js +3 -3
  15. package/lib/ConditionalInitFragment.js +4 -5
  16. package/lib/ContextModule.js +95 -41
  17. package/lib/ContextModuleFactory.js +4 -2
  18. package/lib/ContextReplacementPlugin.js +3 -2
  19. package/lib/DefinePlugin.js +18 -6
  20. package/lib/Dependency.js +12 -10
  21. package/lib/DependencyTemplate.js +17 -7
  22. package/lib/DllModule.js +1 -0
  23. package/lib/DllReferencePlugin.js +7 -3
  24. package/lib/EntryOptionPlugin.js +4 -1
  25. package/lib/EntryPlugin.js +6 -1
  26. package/lib/Entrypoint.js +1 -1
  27. package/lib/EvalDevToolModulePlugin.js +11 -0
  28. package/lib/ExportsInfo.js +23 -8
  29. package/lib/ExternalModule.js +160 -35
  30. package/lib/ExternalModuleFactoryPlugin.js +37 -2
  31. package/lib/FileSystemInfo.js +69 -42
  32. package/lib/FlagDependencyExportsPlugin.js +21 -7
  33. package/lib/Generator.js +4 -4
  34. package/lib/HookWebpackError.js +2 -2
  35. package/lib/HotModuleReplacementPlugin.js +108 -45
  36. package/lib/IgnorePlugin.js +4 -1
  37. package/lib/InitFragment.js +5 -3
  38. package/lib/LibManifestPlugin.js +17 -9
  39. package/lib/Module.js +41 -14
  40. package/lib/ModuleFactory.js +3 -3
  41. package/lib/ModuleFilenameHelpers.js +30 -17
  42. package/lib/ModuleGraph.js +60 -31
  43. package/lib/ModuleGraphConnection.js +2 -1
  44. package/lib/MultiCompiler.js +62 -9
  45. package/lib/NodeStuffPlugin.js +14 -3
  46. package/lib/NormalModule.js +13 -13
  47. package/lib/NormalModuleFactory.js +18 -9
  48. package/lib/NormalModuleReplacementPlugin.js +5 -1
  49. package/lib/Parser.js +1 -1
  50. package/lib/PlatformPlugin.js +39 -0
  51. package/lib/ProgressPlugin.js +1 -1
  52. package/lib/ProvidePlugin.js +3 -1
  53. package/lib/RawModule.js +2 -1
  54. package/lib/RecordIdsPlugin.js +4 -4
  55. package/lib/ResolverFactory.js +6 -4
  56. package/lib/RuntimeModule.js +4 -4
  57. package/lib/RuntimePlugin.js +1 -0
  58. package/lib/RuntimeTemplate.js +124 -52
  59. package/lib/SourceMapDevToolPlugin.js +4 -1
  60. package/lib/Stats.js +11 -4
  61. package/lib/Template.js +5 -5
  62. package/lib/TemplatedPathPlugin.js +48 -7
  63. package/lib/Watching.js +67 -60
  64. package/lib/WebpackError.js +6 -6
  65. package/lib/WebpackOptionsApply.js +18 -5
  66. package/lib/asset/AssetGenerator.js +15 -0
  67. package/lib/asset/RawDataUrlModule.js +3 -1
  68. package/lib/async-modules/AwaitDependenciesInitFragment.js +2 -2
  69. package/lib/buildChunkGraph.js +120 -67
  70. package/lib/cache/IdleFileCachePlugin.js +8 -3
  71. package/lib/cache/MemoryCachePlugin.js +1 -1
  72. package/lib/cache/MemoryWithGcCachePlugin.js +6 -2
  73. package/lib/cache/PackFileCacheStrategy.js +51 -18
  74. package/lib/cache/ResolverCachePlugin.js +22 -14
  75. package/lib/cache/getLazyHashedEtag.js +2 -2
  76. package/lib/cli.js +5 -5
  77. package/lib/config/browserslistTargetHandler.js +7 -1
  78. package/lib/config/defaults.js +108 -34
  79. package/lib/config/normalization.js +3 -1
  80. package/lib/config/target.js +18 -11
  81. package/lib/container/ContainerEntryDependency.js +2 -1
  82. package/lib/container/ContainerEntryModule.js +4 -2
  83. package/lib/container/ContainerPlugin.js +14 -10
  84. package/lib/container/FallbackModule.js +1 -1
  85. package/lib/container/RemoteRuntimeModule.js +12 -3
  86. package/lib/css/CssExportsGenerator.js +68 -25
  87. package/lib/css/CssGenerator.js +34 -6
  88. package/lib/css/CssLoadingRuntimeModule.js +217 -98
  89. package/lib/css/CssModulesPlugin.js +238 -107
  90. package/lib/css/CssParser.js +24 -15
  91. package/lib/css/walkCssTokens.js +1 -1
  92. package/lib/debug/ProfilingPlugin.js +28 -3
  93. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +9 -5
  94. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +4 -1
  95. package/lib/dependencies/CommonJsDependencyHelpers.js +2 -1
  96. package/lib/dependencies/CommonJsExportRequireDependency.js +33 -18
  97. package/lib/dependencies/CommonJsExportsDependency.js +13 -5
  98. package/lib/dependencies/CommonJsExportsParserPlugin.js +20 -15
  99. package/lib/dependencies/CommonJsImportsParserPlugin.js +1 -2
  100. package/lib/dependencies/ContextDependencyHelpers.js +49 -29
  101. package/lib/dependencies/ContextElementDependency.js +8 -1
  102. package/lib/dependencies/CssExportDependency.js +2 -2
  103. package/lib/dependencies/CssLocalIdentifierDependency.js +71 -9
  104. package/lib/dependencies/CssUrlDependency.js +10 -7
  105. package/lib/dependencies/ExportsInfoDependency.js +5 -4
  106. package/lib/dependencies/ExternalModuleDependency.js +4 -2
  107. package/lib/dependencies/ExternalModuleInitFragment.js +5 -3
  108. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +4 -4
  109. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +43 -23
  110. package/lib/dependencies/HarmonyExportHeaderDependency.js +1 -1
  111. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +73 -32
  112. package/lib/dependencies/HarmonyExportInitFragment.js +10 -2
  113. package/lib/dependencies/HarmonyImportDependency.js +28 -12
  114. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +70 -19
  115. package/lib/dependencies/HarmonyImportSideEffectDependency.js +7 -6
  116. package/lib/dependencies/HarmonyImportSpecifierDependency.js +47 -35
  117. package/lib/dependencies/ImportDependency.js +9 -2
  118. package/lib/dependencies/ImportEagerDependency.js +4 -2
  119. package/lib/dependencies/ImportMetaContextDependency.js +7 -0
  120. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +25 -14
  121. package/lib/dependencies/ImportMetaPlugin.js +1 -1
  122. package/lib/dependencies/ImportParserPlugin.js +15 -5
  123. package/lib/dependencies/ImportWeakDependency.js +4 -2
  124. package/lib/dependencies/LoaderDependency.js +2 -1
  125. package/lib/dependencies/LoaderImportDependency.js +2 -1
  126. package/lib/dependencies/LoaderPlugin.js +2 -2
  127. package/lib/dependencies/ModuleDependency.js +4 -5
  128. package/lib/dependencies/PureExpressionDependency.js +64 -47
  129. package/lib/dependencies/RequireContextPlugin.js +1 -1
  130. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +26 -14
  131. package/lib/dependencies/RequireEnsureDependency.js +1 -1
  132. package/lib/dependencies/URLDependency.js +7 -4
  133. package/lib/dependencies/WorkerDependency.js +1 -1
  134. package/lib/dependencies/WorkerPlugin.js +2 -1
  135. package/lib/dependencies/getFunctionExpression.js +3 -1
  136. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +92 -3
  137. package/lib/hmr/LazyCompilationPlugin.js +2 -2
  138. package/lib/ids/ChunkModuleIdRangePlugin.js +1 -1
  139. package/lib/ids/DeterministicChunkIdsPlugin.js +1 -1
  140. package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
  141. package/lib/ids/IdHelpers.js +6 -6
  142. package/lib/ids/NamedChunkIdsPlugin.js +1 -1
  143. package/lib/ids/NamedModuleIdsPlugin.js +1 -1
  144. package/lib/ids/SyncModuleIdsPlugin.js +2 -2
  145. package/lib/index.js +11 -0
  146. package/lib/javascript/BasicEvaluatedExpression.js +2 -2
  147. package/lib/javascript/ChunkHelpers.js +2 -2
  148. package/lib/javascript/CommonJsChunkFormatPlugin.js +1 -1
  149. package/lib/javascript/JavascriptGenerator.js +0 -1
  150. package/lib/javascript/JavascriptModulesPlugin.js +174 -17
  151. package/lib/javascript/JavascriptParser.js +204 -71
  152. package/lib/javascript/JavascriptParserHelpers.js +1 -1
  153. package/lib/javascript/StartupHelpers.js +22 -5
  154. package/lib/library/AbstractLibraryPlugin.js +2 -2
  155. package/lib/library/AmdLibraryPlugin.js +2 -2
  156. package/lib/library/AssignLibraryPlugin.js +3 -3
  157. package/lib/library/ExportPropertyLibraryPlugin.js +2 -2
  158. package/lib/library/JsonpLibraryPlugin.js +2 -2
  159. package/lib/library/ModuleLibraryPlugin.js +2 -2
  160. package/lib/library/SystemLibraryPlugin.js +2 -2
  161. package/lib/library/UmdLibraryPlugin.js +33 -12
  162. package/lib/logging/Logger.js +27 -2
  163. package/lib/logging/createConsoleLogger.js +13 -9
  164. package/lib/node/CommonJsChunkLoadingPlugin.js +2 -1
  165. package/lib/node/NodeEnvironmentPlugin.js +14 -8
  166. package/lib/node/NodeTemplatePlugin.js +1 -1
  167. package/lib/node/NodeWatchFileSystem.js +37 -26
  168. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +2 -1
  169. package/lib/node/ReadFileCompileWasmPlugin.js +1 -1
  170. package/lib/node/RequireChunkLoadingRuntimeModule.js +2 -1
  171. package/lib/node/nodeConsole.js +24 -1
  172. package/lib/optimize/AggressiveMergingPlugin.js +1 -1
  173. package/lib/optimize/AggressiveSplittingPlugin.js +1 -0
  174. package/lib/optimize/ConcatenatedModule.js +140 -121
  175. package/lib/optimize/EnsureChunkConditionsPlugin.js +1 -1
  176. package/lib/optimize/InnerGraph.js +8 -3
  177. package/lib/optimize/InnerGraphPlugin.js +36 -13
  178. package/lib/optimize/LimitChunkCountPlugin.js +1 -2
  179. package/lib/optimize/ModuleConcatenationPlugin.js +13 -3
  180. package/lib/optimize/RealContentHashPlugin.js +3 -3
  181. package/lib/optimize/RemoveParentModulesPlugin.js +1 -0
  182. package/lib/optimize/RuntimeChunkPlugin.js +6 -1
  183. package/lib/optimize/SideEffectsFlagPlugin.js +48 -17
  184. package/lib/optimize/SplitChunksPlugin.js +10 -10
  185. package/lib/performance/SizeLimitsPlugin.js +13 -2
  186. package/lib/rules/ObjectMatcherRulePlugin.js +15 -1
  187. package/lib/rules/RuleSetCompiler.js +9 -7
  188. package/lib/runtime/EnsureChunkRuntimeModule.js +2 -1
  189. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +2 -1
  190. package/lib/runtime/LoadScriptRuntimeModule.js +1 -1
  191. package/lib/runtime/StartupChunkDependenciesPlugin.js +1 -1
  192. package/lib/schemes/HttpUriPlugin.js +1 -1
  193. package/lib/serialization/BinaryMiddleware.js +4 -4
  194. package/lib/serialization/FileMiddleware.js +4 -3
  195. package/lib/serialization/NullPrototypeObjectSerializer.js +2 -2
  196. package/lib/serialization/ObjectMiddleware.js +8 -5
  197. package/lib/serialization/PlainObjectSerializer.js +2 -2
  198. package/lib/serialization/Serializer.js +19 -0
  199. package/lib/serialization/SerializerMiddleware.js +2 -2
  200. package/lib/serialization/SingleItemMiddleware.js +2 -2
  201. package/lib/serialization/types.js +1 -1
  202. package/lib/sharing/ConsumeSharedModule.js +2 -2
  203. package/lib/sharing/ConsumeSharedPlugin.js +17 -3
  204. package/lib/sharing/ConsumeSharedRuntimeModule.js +9 -2
  205. package/lib/sharing/ProvideSharedPlugin.js +13 -6
  206. package/lib/sharing/resolveMatchedConfigs.js +3 -3
  207. package/lib/sharing/utils.js +13 -6
  208. package/lib/stats/DefaultStatsFactoryPlugin.js +20 -20
  209. package/lib/stats/DefaultStatsPrinterPlugin.js +1 -1
  210. package/lib/stats/StatsFactory.js +2 -2
  211. package/lib/stats/StatsPrinter.js +6 -6
  212. package/lib/util/ArrayQueue.js +14 -21
  213. package/lib/util/AsyncQueue.js +1 -1
  214. package/lib/util/Queue.js +8 -2
  215. package/lib/util/SortableSet.js +16 -4
  216. package/lib/util/StackedCacheMap.js +26 -0
  217. package/lib/util/TupleQueue.js +8 -2
  218. package/lib/util/WeakTupleMap.js +57 -13
  219. package/lib/util/binarySearchBounds.js +1 -1
  220. package/lib/util/cleverMerge.js +26 -13
  221. package/lib/util/comparators.js +37 -15
  222. package/lib/util/conventions.js +129 -0
  223. package/lib/util/createHash.js +3 -5
  224. package/lib/util/deprecation.js +3 -3
  225. package/lib/util/deterministicGrouping.js +2 -2
  226. package/lib/util/findGraphRoots.js +1 -1
  227. package/lib/util/fs.js +383 -69
  228. package/lib/util/hash/BatchedHash.js +3 -0
  229. package/lib/util/hash/xxhash64.js +2 -2
  230. package/lib/util/identifier.js +5 -5
  231. package/lib/util/mergeScope.js +79 -0
  232. package/lib/util/runtime.js +2 -17
  233. package/lib/util/semver.js +3 -0
  234. package/lib/util/smartGrouping.js +3 -3
  235. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +4 -2
  236. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +1 -1
  237. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +4 -2
  238. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +3 -3
  239. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +16 -7
  240. package/lib/wasm-sync/WebAssemblyGenerator.js +40 -19
  241. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +1 -1
  242. package/lib/wasm-sync/WebAssemblyParser.js +7 -4
  243. package/lib/wasm-sync/WebAssemblyUtils.js +2 -1
  244. package/lib/web/FetchCompileWasmPlugin.js +1 -1
  245. package/lib/web/JsonpChunkLoadingRuntimeModule.js +3 -2
  246. package/lib/webpack.js +19 -6
  247. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +2 -1
  248. package/package.json +40 -39
  249. package/schemas/WebpackOptions.check.js +1 -1
  250. package/schemas/WebpackOptions.json +97 -8
  251. package/schemas/plugins/BannerPlugin.check.js +1 -1
  252. package/schemas/plugins/BannerPlugin.json +5 -1
  253. package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +1 -1
  254. package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -1
  255. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +1 -1
  256. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
  257. package/types.d.ts +1826 -639
@@ -9,6 +9,7 @@ const { UsageState } = require("../ExportsInfo");
9
9
 
10
10
  /** @typedef {import("estree").Node} AnyNode */
11
11
  /** @typedef {import("../Dependency")} Dependency */
12
+ /** @typedef {import("../Module")} Module */
12
13
  /** @typedef {import("../ModuleGraph")} ModuleGraph */
13
14
  /** @typedef {import("../ModuleGraphConnection")} ModuleGraphConnection */
14
15
  /** @typedef {import("../ModuleGraphConnection").ConnectionState} ConnectionState */
@@ -20,7 +21,7 @@ const { UsageState } = require("../ExportsInfo");
20
21
  /** @typedef {function(boolean | Set<string> | undefined): void} UsageCallback */
21
22
 
22
23
  /**
23
- * @typedef {Object} StateObject
24
+ * @typedef {object} StateObject
24
25
  * @property {InnerGraph} innerGraph
25
26
  * @property {TopLevelSymbol=} currentTopLevelSymbol
26
27
  * @property {Map<TopLevelSymbol, Set<UsageCallback>>} usageCallbackMap
@@ -295,7 +296,9 @@ exports.isDependencyUsedByExports = (
295
296
  ) => {
296
297
  if (usedByExports === false) return false;
297
298
  if (usedByExports !== true && usedByExports !== undefined) {
298
- const selfModule = moduleGraph.getParentModule(dependency);
299
+ const selfModule =
300
+ /** @type {Module} */
301
+ (moduleGraph.getParentModule(dependency));
299
302
  const exportsInfo = moduleGraph.getExportsInfo(selfModule);
300
303
  let used = false;
301
304
  for (const exportName of usedByExports) {
@@ -320,7 +323,9 @@ exports.getDependencyUsedByExportsCondition = (
320
323
  ) => {
321
324
  if (usedByExports === false) return false;
322
325
  if (usedByExports !== true && usedByExports !== undefined) {
323
- const selfModule = moduleGraph.getParentModule(dependency);
326
+ const selfModule =
327
+ /** @type {Module} */
328
+ (moduleGraph.getParentModule(dependency));
324
329
  const exportsInfo = moduleGraph.getExportsInfo(selfModule);
325
330
  return (connections, runtime) => {
326
331
  for (const exportName of usedByExports) {
@@ -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;
@@ -24,7 +24,7 @@ const validate = createSchemaValidation(
24
24
  );
25
25
 
26
26
  /**
27
- * @typedef {Object} ChunkCombination
27
+ * @typedef {object} ChunkCombination
28
28
  * @property {boolean} deleted this is set to true when combination was removed
29
29
  * @property {number} sizeDiff
30
30
  * @property {number} integratedSize
@@ -159,7 +159,6 @@ class LimitChunkCountPlugin {
159
159
  const modifiedChunks = new Set();
160
160
 
161
161
  let changed = false;
162
- // eslint-disable-next-line no-constant-condition
163
162
  loop: while (true) {
164
163
  const combination = combinations.popFirst();
165
164
  if (combination === undefined) break;
@@ -23,11 +23,12 @@ 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
 
29
30
  /**
30
- * @typedef {Object} Statistics
31
+ * @typedef {object} Statistics
31
32
  * @property {number} cached
32
33
  * @property {number} alreadyInConfig
33
34
  * @property {number} invalidModule
@@ -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) {
@@ -87,7 +87,7 @@ const toCachedSource = source => {
87
87
  /** @typedef {Set<string>} Hashes */
88
88
 
89
89
  /**
90
- * @typedef {Object} AssetInfoForRealContentHash
90
+ * @typedef {object} AssetInfoForRealContentHash
91
91
  * @property {string} name
92
92
  * @property {AssetInfo} info
93
93
  * @property {Source} source
@@ -102,7 +102,7 @@ const toCachedSource = source => {
102
102
  */
103
103
 
104
104
  /**
105
- * @typedef {Object} CompilationHooks
105
+ * @typedef {object} CompilationHooks
106
106
  * @property {SyncBailHook<[Buffer[], string], string>} updateHash
107
107
  */
108
108
 
@@ -131,7 +131,7 @@ class RealContentHashPlugin {
131
131
  }
132
132
 
133
133
  /**
134
- * @param {Object} options options object
134
+ * @param {object} options options object
135
135
  * @param {string | Hash} options.hashFunction the hash function to use
136
136
  * @param {string} options.hashDigest the hash digest to use
137
137
  */
@@ -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,23 +20,28 @@ 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
- * @typedef {Object} ExportInModule
30
+ * @typedef {object} ExportInModule
28
31
  * @property {Module} module the module
29
32
  * @property {string} exportName the name of the export
30
33
  * @property {boolean} checked if the export is conditional
31
34
  */
32
35
 
33
36
  /**
34
- * @typedef {Object} ReexportInfo
37
+ * @typedef {object} ReexportInfo
35
38
  * @property {Map<string, ExportInModule[]>} static
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);
@@ -52,7 +52,7 @@ const MinMaxSizeWarning = require("./MinMaxSizeWarning");
52
52
  */
53
53
 
54
54
  /**
55
- * @typedef {Object} CacheGroupSource
55
+ * @typedef {object} CacheGroupSource
56
56
  * @property {string=} key
57
57
  * @property {number=} priority
58
58
  * @property {GetName=} getName
@@ -75,7 +75,7 @@ const MinMaxSizeWarning = require("./MinMaxSizeWarning");
75
75
  */
76
76
 
77
77
  /**
78
- * @typedef {Object} CacheGroup
78
+ * @typedef {object} CacheGroup
79
79
  * @property {string} key
80
80
  * @property {number=} priority
81
81
  * @property {GetName=} getName
@@ -101,7 +101,7 @@ const MinMaxSizeWarning = require("./MinMaxSizeWarning");
101
101
  */
102
102
 
103
103
  /**
104
- * @typedef {Object} FallbackCacheGroup
104
+ * @typedef {object} FallbackCacheGroup
105
105
  * @property {ChunkFilterFunction} chunksFilter
106
106
  * @property {SplitChunksSizes} minSize
107
107
  * @property {SplitChunksSizes} maxAsyncSize
@@ -110,7 +110,7 @@ const MinMaxSizeWarning = require("./MinMaxSizeWarning");
110
110
  */
111
111
 
112
112
  /**
113
- * @typedef {Object} CacheGroupsContext
113
+ * @typedef {object} CacheGroupsContext
114
114
  * @property {ModuleGraph} moduleGraph
115
115
  * @property {ChunkGraph} chunkGraph
116
116
  */
@@ -131,7 +131,7 @@ const MinMaxSizeWarning = require("./MinMaxSizeWarning");
131
131
  */
132
132
 
133
133
  /**
134
- * @typedef {Object} SplitChunksOptions
134
+ * @typedef {object} SplitChunksOptions
135
135
  * @property {ChunkFilterFunction} chunksFilter
136
136
  * @property {string[]} defaultSizeTypes
137
137
  * @property {SplitChunksSizes} minSize
@@ -153,14 +153,14 @@ const MinMaxSizeWarning = require("./MinMaxSizeWarning");
153
153
  */
154
154
 
155
155
  /**
156
- * @typedef {Object} ChunksInfoItem
156
+ * @typedef {object} ChunksInfoItem
157
157
  * @property {SortableSet<Module>} modules
158
158
  * @property {CacheGroup} cacheGroup
159
159
  * @property {number} cacheGroupIndex
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
 
@@ -1023,7 +1023,7 @@ module.exports = class SplitChunksPlugin {
1023
1023
  getExportsCombinationsFactory()(key);
1024
1024
 
1025
1025
  /**
1026
- * @typedef {Object} SelectedChunksResult
1026
+ * @typedef {object} SelectedChunksResult
1027
1027
  * @property {Chunk[]} chunks the list of chunks
1028
1028
  * @property {bigint | Chunk} key a key of the list
1029
1029
  */
@@ -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
  );
@@ -1322,7 +1322,7 @@ module.exports = class SplitChunksPlugin {
1322
1322
  }
1323
1323
 
1324
1324
  /**
1325
- * @typedef {Object} MaxSizeQueueItem
1325
+ * @typedef {object} MaxSizeQueueItem
1326
1326
  * @property {SplitChunksSizes} minSize
1327
1327
  * @property {SplitChunksSizes} maxAsyncSize
1328
1328
  * @property {SplitChunksSizes} maxInitialSize
@@ -13,18 +13,19 @@ 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 */
19
20
 
20
21
  /**
21
- * @typedef {Object} AssetDetails
22
+ * @typedef {object} AssetDetails
22
23
  * @property {string} name
23
24
  * @property {number} size
24
25
  */
25
26
 
26
27
  /**
27
- * @typedef {Object} EntrypointDetails
28
+ * @typedef {object} EntrypointDetails
28
29
  * @property {string} name
29
30
  * @property {number} size
30
31
  * @property {string[]} files
@@ -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);
@@ -7,11 +7,18 @@
7
7
 
8
8
  /** @typedef {import("./RuleSetCompiler")} RuleSetCompiler */
9
9
  /** @typedef {import("./RuleSetCompiler").RuleCondition} RuleCondition */
10
+ /** @typedef {import("./RuleSetCompiler").RuleConditionFunction} RuleConditionFunction */
10
11
 
11
12
  class ObjectMatcherRulePlugin {
12
- constructor(ruleProperty, dataProperty) {
13
+ /**
14
+ * @param {string} ruleProperty the rule property
15
+ * @param {string=} dataProperty the data property
16
+ * @param {RuleConditionFunction=} additionalConditionFunction need to check
17
+ */
18
+ constructor(ruleProperty, dataProperty, additionalConditionFunction) {
13
19
  this.ruleProperty = ruleProperty;
14
20
  this.dataProperty = dataProperty || ruleProperty;
21
+ this.additionalConditionFunction = additionalConditionFunction;
15
22
  }
16
23
 
17
24
  /**
@@ -32,6 +39,13 @@ class ObjectMatcherRulePlugin {
32
39
  `${path}.${ruleProperty}.${property}`,
33
40
  value[property]
34
41
  );
42
+ if (this.additionalConditionFunction) {
43
+ result.conditions.push({
44
+ property: [dataProperty],
45
+ matchWhenEmpty: condition.matchWhenEmpty,
46
+ fn: this.additionalConditionFunction
47
+ });
48
+ }
35
49
  result.conditions.push({
36
50
  property: [dataProperty, ...nestedDataProperties],
37
51
  matchWhenEmpty: condition.matchWhenEmpty,
@@ -7,21 +7,23 @@
7
7
 
8
8
  const { SyncHook } = require("tapable");
9
9
 
10
+ /** @typedef {function(string): boolean} RuleConditionFunction */
11
+
10
12
  /**
11
- * @typedef {Object} RuleCondition
13
+ * @typedef {object} RuleCondition
12
14
  * @property {string | string[]} property
13
15
  * @property {boolean} matchWhenEmpty
14
- * @property {function(string): boolean} fn
16
+ * @property {RuleConditionFunction} fn
15
17
  */
16
18
 
17
19
  /**
18
- * @typedef {Object} Condition
20
+ * @typedef {object} Condition
19
21
  * @property {boolean} matchWhenEmpty
20
- * @property {function(string): boolean} fn
22
+ * @property {RuleConditionFunction} fn
21
23
  */
22
24
 
23
25
  /**
24
- * @typedef {Object} CompiledRule
26
+ * @typedef {object} CompiledRule
25
27
  * @property {RuleCondition[]} conditions
26
28
  * @property {(Effect|function(object): Effect[])[]} effects
27
29
  * @property {CompiledRule[]=} rules
@@ -29,13 +31,13 @@ const { SyncHook } = require("tapable");
29
31
  */
30
32
 
31
33
  /**
32
- * @typedef {Object} Effect
34
+ * @typedef {object} Effect
33
35
  * @property {string} type
34
36
  * @property {any} value
35
37
  */
36
38
 
37
39
  /**
38
- * @typedef {Object} RuleSet
40
+ * @typedef {object} RuleSet
39
41
  * @property {Map<string, any>} references map of references in the rule set (may grow over time)
40
42
  * @property {function(object): Effect[]} exec execute the rule set
41
43
  */
@@ -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");