webpack 5.99.7 → 5.99.9

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.
Files changed (152) hide show
  1. package/README.md +0 -3
  2. package/lib/CacheFacade.js +2 -1
  3. package/lib/ChunkGraph.js +0 -1
  4. package/lib/ChunkGroup.js +13 -6
  5. package/lib/Compilation.js +22 -33
  6. package/lib/ConstPlugin.js +61 -43
  7. package/lib/ContextModule.js +1 -1
  8. package/lib/ContextModuleFactory.js +1 -2
  9. package/lib/ContextReplacementPlugin.js +2 -1
  10. package/lib/CssModule.js +0 -1
  11. package/lib/DefinePlugin.js +2 -2
  12. package/lib/DelegatedModule.js +18 -8
  13. package/lib/DelegatedModuleFactoryPlugin.js +9 -7
  14. package/lib/Dependency.js +10 -11
  15. package/lib/EvalSourceMapDevToolPlugin.js +1 -1
  16. package/lib/ExportsInfo.js +35 -16
  17. package/lib/ExternalModule.js +6 -5
  18. package/lib/FileSystemInfo.js +2 -4
  19. package/lib/LibManifestPlugin.js +2 -2
  20. package/lib/ModuleFilenameHelpers.js +8 -4
  21. package/lib/NormalModule.js +38 -19
  22. package/lib/NormalModuleFactory.js +23 -18
  23. package/lib/RuntimePlugin.js +1 -1
  24. package/lib/SourceMapDevToolPlugin.js +2 -3
  25. package/lib/WebpackOptionsApply.js +1 -4
  26. package/lib/asset/AssetGenerator.js +13 -12
  27. package/lib/asset/AssetSourceGenerator.js +7 -5
  28. package/lib/config/defaults.js +10 -6
  29. package/lib/config/normalization.js +5 -5
  30. package/lib/css/CssModulesPlugin.js +2 -2
  31. package/lib/debug/ProfilingPlugin.js +18 -21
  32. package/lib/dependencies/CommonJsImportsParserPlugin.js +1 -1
  33. package/lib/dependencies/ContextElementDependency.js +1 -1
  34. package/lib/dependencies/CssLocalIdentifierDependency.js +2 -2
  35. package/lib/dependencies/CssUrlDependency.js +1 -1
  36. package/lib/dependencies/ModuleDependency.js +1 -1
  37. package/lib/dependencies/RequireContextPlugin.js +2 -1
  38. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +3 -0
  39. package/lib/dependencies/URLDependency.js +1 -1
  40. package/lib/dependencies/WorkerPlugin.js +2 -2
  41. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +3 -3
  42. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +0 -1
  43. package/lib/index.js +11 -0
  44. package/lib/javascript/JavascriptModulesPlugin.js +2 -2
  45. package/lib/javascript/JavascriptParser.js +19 -5
  46. package/lib/json/JsonModulesPlugin.js +4 -4
  47. package/lib/library/AbstractLibraryPlugin.js +1 -1
  48. package/lib/library/ModuleLibraryPlugin.js +4 -1
  49. package/lib/node/nodeConsole.js +3 -2
  50. package/lib/optimize/AggressiveSplittingPlugin.js +1 -1
  51. package/lib/optimize/ConcatenatedModule.js +3 -1
  52. package/lib/optimize/ModuleConcatenationPlugin.js +2 -2
  53. package/lib/optimize/RuntimeChunkPlugin.js +5 -6
  54. package/lib/optimize/SideEffectsFlagPlugin.js +12 -7
  55. package/lib/optimize/SplitChunksPlugin.js +2 -2
  56. package/lib/rules/BasicEffectRulePlugin.js +1 -2
  57. package/lib/rules/ObjectMatcherRulePlugin.js +2 -1
  58. package/lib/rules/RuleSetCompiler.js +19 -5
  59. package/lib/rules/UseEffectRulePlugin.js +4 -6
  60. package/lib/schemes/DataUriPlugin.js +3 -1
  61. package/lib/schemes/HttpUriPlugin.js +154 -149
  62. package/lib/sharing/ProvideSharedPlugin.js +3 -1
  63. package/lib/stats/DefaultStatsPrinterPlugin.js +13 -13
  64. package/lib/util/createHash.js +3 -3
  65. package/package.json +45 -40
  66. package/schemas/WebpackOptions.check.d.ts +1 -1
  67. package/schemas/WebpackOptions.check.js +2 -2
  68. package/schemas/WebpackOptions.json +243 -24
  69. package/schemas/plugins/BannerPlugin.check.d.ts +1 -1
  70. package/schemas/plugins/BannerPlugin.check.js +1 -1
  71. package/schemas/plugins/DllPlugin.check.d.ts +1 -1
  72. package/schemas/plugins/DllPlugin.check.js +1 -1
  73. package/schemas/plugins/DllReferencePlugin.check.d.ts +1 -1
  74. package/schemas/plugins/DllReferencePlugin.check.js +1 -1
  75. package/schemas/plugins/HashedModuleIdsPlugin.check.d.ts +1 -1
  76. package/schemas/plugins/HashedModuleIdsPlugin.check.js +1 -1
  77. package/schemas/plugins/IgnorePlugin.check.d.ts +1 -1
  78. package/schemas/plugins/IgnorePlugin.check.js +1 -1
  79. package/schemas/plugins/LoaderOptionsPlugin.check.d.ts +1 -1
  80. package/schemas/plugins/LoaderOptionsPlugin.check.js +1 -1
  81. package/schemas/plugins/ProgressPlugin.check.d.ts +1 -1
  82. package/schemas/plugins/ProgressPlugin.check.js +1 -1
  83. package/schemas/plugins/SourceMapDevToolPlugin.check.d.ts +1 -1
  84. package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
  85. package/schemas/plugins/SourceMapDevToolPlugin.json +2 -2
  86. package/schemas/plugins/WatchIgnorePlugin.check.d.ts +1 -1
  87. package/schemas/plugins/WatchIgnorePlugin.check.js +1 -1
  88. package/schemas/plugins/asset/AssetGeneratorOptions.check.d.ts +1 -1
  89. package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
  90. package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.d.ts +1 -1
  91. package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.js +1 -1
  92. package/schemas/plugins/asset/AssetParserOptions.check.d.ts +1 -1
  93. package/schemas/plugins/asset/AssetParserOptions.check.js +1 -1
  94. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.d.ts +1 -1
  95. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
  96. package/schemas/plugins/container/ContainerPlugin.check.d.ts +1 -1
  97. package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
  98. package/schemas/plugins/container/ContainerReferencePlugin.check.d.ts +1 -1
  99. package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
  100. package/schemas/plugins/container/ExternalsType.check.d.ts +1 -1
  101. package/schemas/plugins/container/ExternalsType.check.js +1 -1
  102. package/schemas/plugins/container/ModuleFederationPlugin.check.d.ts +1 -1
  103. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  104. package/schemas/plugins/css/CssAutoGeneratorOptions.check.d.ts +1 -1
  105. package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +1 -1
  106. package/schemas/plugins/css/CssAutoParserOptions.check.d.ts +1 -1
  107. package/schemas/plugins/css/CssAutoParserOptions.check.js +1 -1
  108. package/schemas/plugins/css/CssGeneratorOptions.check.d.ts +1 -1
  109. package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -1
  110. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.d.ts +1 -1
  111. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +1 -1
  112. package/schemas/plugins/css/CssGlobalParserOptions.check.d.ts +1 -1
  113. package/schemas/plugins/css/CssGlobalParserOptions.check.js +1 -1
  114. package/schemas/plugins/css/CssModuleGeneratorOptions.check.d.ts +1 -1
  115. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
  116. package/schemas/plugins/css/CssModuleParserOptions.check.d.ts +1 -1
  117. package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
  118. package/schemas/plugins/css/CssParserOptions.check.d.ts +1 -1
  119. package/schemas/plugins/css/CssParserOptions.check.js +1 -1
  120. package/schemas/plugins/debug/ProfilingPlugin.check.d.ts +1 -1
  121. package/schemas/plugins/debug/ProfilingPlugin.check.js +1 -1
  122. package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.check.d.ts +1 -1
  123. package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.check.js +1 -1
  124. package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.check.d.ts +1 -1
  125. package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.check.js +1 -1
  126. package/schemas/plugins/json/JsonModulesPluginGenerator.check.d.ts +7 -0
  127. package/schemas/plugins/{JsonModulesPluginGenerator.check.js → json/JsonModulesPluginGenerator.check.js} +1 -1
  128. package/schemas/plugins/json/JsonModulesPluginGenerator.json +3 -0
  129. package/schemas/plugins/json/JsonModulesPluginParser.check.d.ts +7 -0
  130. package/schemas/plugins/{JsonModulesPluginParser.check.js → json/JsonModulesPluginParser.check.js} +1 -1
  131. package/schemas/plugins/json/JsonModulesPluginParser.json +3 -0
  132. package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.d.ts +1 -1
  133. package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +1 -1
  134. package/schemas/plugins/optimize/LimitChunkCountPlugin.check.d.ts +1 -1
  135. package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +1 -1
  136. package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.d.ts +1 -1
  137. package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.js +1 -1
  138. package/schemas/plugins/optimize/MinChunkSizePlugin.check.d.ts +1 -1
  139. package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +1 -1
  140. package/schemas/plugins/schemes/HttpUriPlugin.check.d.ts +1 -1
  141. package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
  142. package/schemas/plugins/sharing/ConsumeSharedPlugin.check.d.ts +1 -1
  143. package/schemas/plugins/sharing/ConsumeSharedPlugin.check.js +1 -1
  144. package/schemas/plugins/sharing/ProvideSharedPlugin.check.d.ts +1 -1
  145. package/schemas/plugins/sharing/ProvideSharedPlugin.check.js +1 -1
  146. package/schemas/plugins/sharing/SharePlugin.check.d.ts +1 -1
  147. package/schemas/plugins/sharing/SharePlugin.check.js +1 -1
  148. package/types.d.ts +468 -156
  149. package/schemas/plugins/JsonModulesPluginGenerator.check.d.ts +0 -7
  150. package/schemas/plugins/JsonModulesPluginGenerator.json +0 -11
  151. package/schemas/plugins/JsonModulesPluginParser.check.d.ts +0 -7
  152. package/schemas/plugins/JsonModulesPluginParser.json +0 -16
package/README.md CHANGED
@@ -9,7 +9,6 @@
9
9
 
10
10
  [![node][node]][node-url]
11
11
  [![builds1][builds1]][builds1-url]
12
- [![builds2][builds2]][builds2-url]
13
12
  [![dependency-review][dependency-review]][dependency-review-url]
14
13
  [![coverage][cover]][cover-url]
15
14
  [![PR's welcome][prs]][prs-url]
@@ -672,8 +671,6 @@ Before we started using OpenCollective, donations were made anonymously. Now tha
672
671
  [prs-url]: https://webpack.js.org/contribute/
673
672
  [builds1]: https://github.com/webpack/webpack/actions/workflows/test.yml/badge.svg
674
673
  [builds1-url]: https://github.com/webpack/webpack/actions/workflows/test.yml
675
- [builds2]: https://dev.azure.com/webpack/webpack/_apis/build/status%2Fwebpack.webpack?branchName=main
676
- [builds2-url]: https://dev.azure.com/webpack/webpack/_build/latest?definitionId=3&branchName=main
677
674
  [dependency-review-url]: https://github.com/webpack/webpack/actions/workflows/dependency-review.yml
678
675
  [dependency-review]: https://github.com/webpack/webpack/actions/workflows/dependency-review.yml/badge.svg
679
676
  [cover]: https://codecov.io/gh/webpack/webpack/graph/badge.svg?token=mDP3mQJNnn
@@ -38,8 +38,9 @@ class MultiItemCache {
38
38
  */
39
39
  constructor(items) {
40
40
  this._items = items;
41
+ // @ts-expect-error expected - returns the single ItemCacheFacade when passed an array of length 1
41
42
  // eslint-disable-next-line no-constructor-return
42
- if (items.length === 1) return /** @type {TODO} */ (items[0]);
43
+ if (items.length === 1) return /** @type {ItemCacheFacade} */ (items[0]);
43
44
  }
44
45
 
45
46
  /**
package/lib/ChunkGraph.js CHANGED
@@ -668,7 +668,6 @@ class ChunkGraph {
668
668
  if (st === undefined) return;
669
669
  if (!sourceTypes) {
670
670
  sourceTypes = st;
671
- continue;
672
671
  } else if (!newSet) {
673
672
  for (const type of st) {
674
673
  if (!newSet) {
package/lib/ChunkGroup.js CHANGED
@@ -115,16 +115,23 @@ class ChunkGroup {
115
115
  */
116
116
  addOptions(options) {
117
117
  for (const _key of Object.keys(options)) {
118
- const key = /** @type {keyof ChunkGroupOptions} */ (_key);
118
+ const key =
119
+ /** @type {keyof ChunkGroupOptions} */
120
+ (_key);
119
121
  if (this.options[key] === undefined) {
120
- /** @type {TODO} */
122
+ /** @type {EXPECTED_ANY} */
121
123
  (this.options)[key] = options[key];
122
124
  } else if (this.options[key] !== options[key]) {
123
125
  if (key.endsWith("Order")) {
124
- /** @type {TODO} */
125
- (this.options)[key] = Math.max(
126
- /** @type {number} */ (this.options[key]),
127
- /** @type {number} */ (options[key])
126
+ const orderKey =
127
+ /** @type {Exclude<keyof ChunkGroupOptions, "name" | "fetchPriority">} */
128
+ (key);
129
+
130
+ this.options[orderKey] = Math.max(
131
+ /** @type {number} */
132
+ (this.options[orderKey]),
133
+ /** @type {number} */
134
+ (options[orderKey])
128
135
  );
129
136
  } else {
130
137
  throw new Error(
@@ -130,7 +130,7 @@ const { isSourceEqual } = require("./util/source");
130
130
  /** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsModule} StatsModule */
131
131
  /** @typedef {import("./TemplatedPathPlugin").TemplatePath} TemplatePath */
132
132
  /** @typedef {import("./util/Hash")} Hash */
133
- /** @typedef {import("./util/createHash").Algorithm} Algorithm */
133
+ /** @typedef {import("../declarations/WebpackOptions").HashFunction} HashFunction */
134
134
  /**
135
135
  * @template T
136
136
  * @typedef {import("./util/deprecation").FakeHook<T>} FakeHook<T>
@@ -1520,7 +1520,8 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1520
1520
  this.options,
1521
1521
  this,
1522
1522
  this.resolverFactory.get("normal", module.resolveOptions),
1523
- /** @type {InputFileSystem} */ (this.inputFileSystem),
1523
+ /** @type {InputFileSystem} */
1524
+ (this.inputFileSystem),
1524
1525
  err => {
1525
1526
  if (currentProfile !== undefined) {
1526
1527
  currentProfile.markBuildingEnd();
@@ -2020,8 +2021,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2020
2021
  const unsafeCacheableModule =
2021
2022
  /** @type {ModuleWithRestoreFromUnsafeCache} */
2022
2023
  (module);
2023
- for (let i = 0; i < dependencies.length; i++) {
2024
- const dependency = dependencies[i];
2024
+ for (const dependency of dependencies) {
2025
2025
  moduleGraph.setResolvedModule(
2026
2026
  connectOrigin ? originModule : null,
2027
2027
  dependency,
@@ -2037,8 +2037,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2037
2037
  }
2038
2038
  } else {
2039
2039
  applyFactoryResultDependencies();
2040
- for (let i = 0; i < dependencies.length; i++) {
2041
- const dependency = dependencies[i];
2040
+ for (const dependency of dependencies) {
2042
2041
  moduleGraph.setResolvedModule(
2043
2042
  connectOrigin ? originModule : null,
2044
2043
  dependency,
@@ -2355,6 +2354,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2355
2354
  */
2356
2355
  _addEntryItem(context, entry, target, options, callback) {
2357
2356
  const { name } = options;
2357
+ /** @type {EntryData | undefined} */
2358
2358
  let entryData =
2359
2359
  name !== undefined ? this.entries.get(name) : this.globalEntry;
2360
2360
  if (entryData === undefined) {
@@ -3434,18 +3434,13 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3434
3434
  */
3435
3435
  reportDependencyErrorsAndWarnings(module, blocks) {
3436
3436
  let hasProblems = false;
3437
- for (let indexBlock = 0; indexBlock < blocks.length; indexBlock++) {
3438
- const block = blocks[indexBlock];
3437
+ for (const block of blocks) {
3439
3438
  const dependencies = block.dependencies;
3440
3439
 
3441
- for (let indexDep = 0; indexDep < dependencies.length; indexDep++) {
3442
- const d = dependencies[indexDep];
3443
-
3440
+ for (const d of dependencies) {
3444
3441
  const warnings = d.getWarnings(this.moduleGraph);
3445
3442
  if (warnings) {
3446
- for (let indexWar = 0; indexWar < warnings.length; indexWar++) {
3447
- const w = warnings[indexWar];
3448
-
3443
+ for (const w of warnings) {
3449
3444
  const warning = new ModuleDependencyWarning(module, w, d.loc);
3450
3445
  this.warnings.push(warning);
3451
3446
  hasProblems = true;
@@ -3453,9 +3448,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3453
3448
  }
3454
3449
  const errors = d.getErrors(this.moduleGraph);
3455
3450
  if (errors) {
3456
- for (let indexErr = 0; indexErr < errors.length; indexErr++) {
3457
- const e = errors[indexErr];
3458
-
3451
+ for (const e of errors) {
3459
3452
  const error = new ModuleDependencyError(module, e, d.loc);
3460
3453
  this.errors.push(error);
3461
3454
  hasProblems = true;
@@ -4160,16 +4153,14 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
4160
4153
  };
4161
4154
 
4162
4155
  const blocks = block.blocks;
4163
- for (let indexBlock = 0; indexBlock < blocks.length; indexBlock++) {
4164
- const asyncBlock = blocks[indexBlock];
4156
+ for (const asyncBlock of blocks) {
4165
4157
  const chunkGroup =
4166
4158
  /** @type {ChunkGroup} */
4167
4159
  (this.chunkGraph.getBlockChunkGroup(asyncBlock));
4168
4160
  // Grab all chunks from the first Block's AsyncDepBlock
4169
4161
  const chunks = chunkGroup.chunks;
4170
4162
  // For each chunk in chunkGroup
4171
- for (let indexChunk = 0; indexChunk < chunks.length; indexChunk++) {
4172
- const iteratedChunk = chunks[indexChunk];
4163
+ for (const iteratedChunk of chunks) {
4173
4164
  chunkGroup.removeChunk(iteratedChunk);
4174
4165
  // Recurse
4175
4166
  this.removeChunkFromDependencies(block, iteratedChunk);
@@ -4210,13 +4201,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
4210
4201
  }
4211
4202
 
4212
4203
  summarizeDependencies() {
4213
- for (
4214
- let indexChildren = 0;
4215
- indexChildren < this.children.length;
4216
- indexChildren++
4217
- ) {
4218
- const child = this.children[indexChildren];
4219
-
4204
+ for (const child of this.children) {
4220
4205
  this.fileDependencies.addAll(child.fileDependencies);
4221
4206
  this.contextDependencies.addAll(child.contextDependencies);
4222
4207
  this.missingDependencies.addAll(child.missingDependencies);
@@ -4313,7 +4298,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
4313
4298
  ) {
4314
4299
  let moduleHashDigest;
4315
4300
  try {
4316
- const moduleHash = createHash(/** @type {Algorithm} */ (hashFunction));
4301
+ const moduleHash = createHash(/** @type {HashFunction} */ (hashFunction));
4317
4302
  module.updateHash(moduleHash, {
4318
4303
  chunkGraph,
4319
4304
  runtime,
@@ -4341,7 +4326,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
4341
4326
  const hashFunction = outputOptions.hashFunction;
4342
4327
  const hashDigest = outputOptions.hashDigest;
4343
4328
  const hashDigestLength = outputOptions.hashDigestLength;
4344
- const hash = createHash(/** @type {Algorithm} */ (hashFunction));
4329
+ const hash = createHash(/** @type {HashFunction} */ (hashFunction));
4345
4330
  if (outputOptions.hashSalt) {
4346
4331
  hash.update(outputOptions.hashSalt);
4347
4332
  }
@@ -4524,7 +4509,9 @@ This prevents using hashes of each other and should be avoided.`);
4524
4509
  this.logger.timeAggregate("hashing: hash runtime modules");
4525
4510
  try {
4526
4511
  this.logger.time("hashing: hash chunks");
4527
- const chunkHash = createHash(/** @type {Algorithm} */ (hashFunction));
4512
+ const chunkHash = createHash(
4513
+ /** @type {HashFunction} */ (hashFunction)
4514
+ );
4528
4515
  if (outputOptions.hashSalt) {
4529
4516
  chunkHash.update(outputOptions.hashSalt);
4530
4517
  }
@@ -4577,7 +4564,9 @@ This prevents using hashes of each other and should be avoided.`);
4577
4564
  for (const module of /** @type {Iterable<RuntimeModule>} */ (
4578
4565
  chunkGraph.getChunkFullHashModulesIterable(chunk)
4579
4566
  )) {
4580
- const moduleHash = createHash(/** @type {Algorithm} */ (hashFunction));
4567
+ const moduleHash = createHash(
4568
+ /** @type {HashFunction} */ (hashFunction)
4569
+ );
4581
4570
  module.updateHash(moduleHash, {
4582
4571
  chunkGraph,
4583
4572
  runtime: chunk.runtime,
@@ -4599,7 +4588,7 @@ This prevents using hashes of each other and should be avoided.`);
4599
4588
  (codeGenerationJobsMap.get(oldHash)).get(module)
4600
4589
  ).hash = moduleHashDigest;
4601
4590
  }
4602
- const chunkHash = createHash(/** @type {Algorithm} */ (hashFunction));
4591
+ const chunkHash = createHash(/** @type {HashFunction} */ (hashFunction));
4603
4592
  chunkHash.update(chunk.hash);
4604
4593
  chunkHash.update(this.hash);
4605
4594
  const chunkHashDigest =
@@ -179,53 +179,21 @@ class ConstPlugin {
179
179
  ? statement.alternate
180
180
  : statement.consequent;
181
181
  if (branchToRemove) {
182
- // Before removing the dead branch, the hoisted declarations
183
- // must be collected.
184
- //
185
- // Given the following code:
186
- //
187
- // if (true) f() else g()
188
- // if (false) {
189
- // function f() {}
190
- // const g = function g() {}
191
- // if (someTest) {
192
- // let a = 1
193
- // var x, {y, z} = obj
194
- // }
195
- // } else {
196
- // …
197
- // }
198
- //
199
- // the generated code is:
200
- //
201
- // if (true) f() else {}
202
- // if (false) {
203
- // var f, x, y, z; (in loose mode)
204
- // var x, y, z; (in strict mode)
205
- // } else {
206
- // …
207
- // }
208
- //
209
- // NOTE: When code runs in strict mode, `var` declarations
210
- // are hoisted but `function` declarations don't.
211
- //
212
- const declarations = parser.scope.isStrict
213
- ? getHoistedDeclarations(branchToRemove, false)
214
- : getHoistedDeclarations(branchToRemove, true);
215
- const replacement =
216
- declarations.length > 0
217
- ? `{ var ${declarations.join(", ")}; }`
218
- : "{}";
219
- const dep = new ConstDependency(
220
- replacement,
221
- /** @type {Range} */ (branchToRemove.range)
222
- );
223
- dep.loc = /** @type {SourceLocation} */ (branchToRemove.loc);
224
- parser.state.module.addPresentationalDependency(dep);
182
+ this.eliminateUnusedStatement(parser, branchToRemove);
225
183
  }
226
184
  return bool;
227
185
  }
228
186
  });
187
+ parser.hooks.unusedStatement.tap(PLUGIN_NAME, statement => {
188
+ if (
189
+ parser.scope.isAsmJs ||
190
+ // Check top level scope here again
191
+ parser.scope.topLevelScope === true
192
+ )
193
+ return;
194
+ this.eliminateUnusedStatement(parser, statement);
195
+ return true;
196
+ });
229
197
  parser.hooks.expressionConditionalOperator.tap(
230
198
  PLUGIN_NAME,
231
199
  expression => {
@@ -534,6 +502,56 @@ class ConstPlugin {
534
502
  }
535
503
  );
536
504
  }
505
+
506
+ /**
507
+ * Eliminate an unused statement.
508
+ * @param {JavascriptParser} parser the parser
509
+ * @param {Statement} statement the statement to remove
510
+ * @returns {void}
511
+ */
512
+ eliminateUnusedStatement(parser, statement) {
513
+ // Before removing the unused branch, the hoisted declarations
514
+ // must be collected.
515
+ //
516
+ // Given the following code:
517
+ //
518
+ // if (true) f() else g()
519
+ // if (false) {
520
+ // function f() {}
521
+ // const g = function g() {}
522
+ // if (someTest) {
523
+ // let a = 1
524
+ // var x, {y, z} = obj
525
+ // }
526
+ // } else {
527
+ // …
528
+ // }
529
+ //
530
+ // the generated code is:
531
+ //
532
+ // if (true) f() else {}
533
+ // if (false) {
534
+ // var f, x, y, z; (in loose mode)
535
+ // var x, y, z; (in strict mode)
536
+ // } else {
537
+ // …
538
+ // }
539
+ //
540
+ // NOTE: When code runs in strict mode, `var` declarations
541
+ // are hoisted but `function` declarations don't.
542
+ //
543
+ const declarations = parser.scope.isStrict
544
+ ? getHoistedDeclarations(statement, false)
545
+ : getHoistedDeclarations(statement, true);
546
+ const replacement =
547
+ declarations.length > 0 ? `{ var ${declarations.join(", ")}; }` : "{}";
548
+ const dep = new ConstDependency(
549
+ `// removed by dead control flow\n${replacement}`,
550
+ /** @type {Range} */ (statement.range)
551
+ );
552
+ dep.loc = /** @type {SourceLocation} */ (statement.loc);
553
+ parser.state.module.addPresentationalDependency(dep);
554
+ }
537
555
  }
538
556
 
539
557
  module.exports = ConstPlugin;
@@ -81,7 +81,7 @@ const makeSerializable = require("./util/makeSerializable");
81
81
 
82
82
  /**
83
83
  * @typedef {object} ContextModuleOptionsExtras
84
- * @property {false|string|string[]} resource
84
+ * @property {false | string | string[]} resource
85
85
  * @property {string=} resourceQuery
86
86
  * @property {string=} resourceFragment
87
87
  * @property {ResolveOptions=} resolveOptions
@@ -397,8 +397,7 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
397
397
  /** @type {string} */
398
398
  (category),
399
399
  referencedExports,
400
- /** @type {TODO} */
401
- (obj.context),
400
+ obj.context,
402
401
  attributes
403
402
  );
404
403
  dep.optional = true;
@@ -190,7 +190,8 @@ const createResolveDependenciesFromContextMap =
190
190
  map[key] + options.resourceQuery + options.resourceFragment,
191
191
  key,
192
192
  options.typePrefix,
193
- /** @type {string} */ (options.category),
193
+ /** @type {string} */
194
+ (options.category),
194
195
  options.referencedExports
195
196
  )
196
197
  );
package/lib/CssModule.js CHANGED
@@ -158,7 +158,6 @@ class CssModule extends NormalModule {
158
158
 
159
159
  /**
160
160
  * @param {ObjectDeserializerContext} context context
161
- * @returns {TODO} Module
162
161
  */
163
162
  deserialize(context) {
164
163
  const { read } = context;
@@ -22,6 +22,7 @@ const {
22
22
  const createHash = require("./util/createHash");
23
23
 
24
24
  /** @typedef {import("estree").Expression} Expression */
25
+ /** @typedef {import("../declarations/WebpackOptions").HashFunction} HashFunction */
25
26
  /** @typedef {import("./Compiler")} Compiler */
26
27
  /** @typedef {import("./Module").BuildInfo} BuildInfo */
27
28
  /** @typedef {import("./Module").ValueCacheVersions} ValueCacheVersions */
@@ -31,7 +32,6 @@ const createHash = require("./util/createHash");
31
32
  /** @typedef {import("./javascript/JavascriptParser").DestructuringAssignmentProperty} DestructuringAssignmentProperty */
32
33
  /** @typedef {import("./javascript/JavascriptParser").Range} Range */
33
34
  /** @typedef {import("./logging/Logger").Logger} Logger */
34
- /** @typedef {import("./util/createHash").Algorithm} Algorithm */
35
35
 
36
36
  /** @typedef {null | undefined | RegExp | EXPECTED_FUNCTION | string | number | boolean | bigint | undefined} CodeValuePrimitive */
37
37
  /** @typedef {RecursiveArrayOrRecord<CodeValuePrimitive | RuntimeValue>} CodeValue */
@@ -367,7 +367,7 @@ class DefinePlugin {
367
367
  const { runtimeTemplate } = compilation;
368
368
 
369
369
  const mainHash = createHash(
370
- /** @type {Algorithm} */
370
+ /** @type {HashFunction} */
371
371
  (compilation.outputOptions.hashFunction)
372
372
  );
373
373
  mainHash.update(
@@ -16,6 +16,7 @@ const makeSerializable = require("./util/makeSerializable");
16
16
 
17
17
  /** @typedef {import("webpack-sources").Source} Source */
18
18
  /** @typedef {import("../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
19
+ /** @typedef {import("../declarations/plugins/DllReferencePlugin").DllReferencePluginOptions} DllReferencePluginOptions */
19
20
  /** @typedef {import("./ChunkGraph")} ChunkGraph */
20
21
  /** @typedef {import("./Compilation")} Compilation */
21
22
  /** @typedef {import("./Dependency").UpdateHashContext} UpdateHashContext */
@@ -23,6 +24,7 @@ const makeSerializable = require("./util/makeSerializable");
23
24
  /** @typedef {import("./Generator").SourceTypes} SourceTypes */
24
25
  /** @typedef {import("./LibManifestPlugin").ManifestModuleData} ManifestModuleData */
25
26
  /** @typedef {import("./Module").BuildCallback} BuildCallback */
27
+ /** @typedef {import("./Module").BuildMeta} BuildMeta */
26
28
  /** @typedef {import("./Module").CodeGenerationContext} CodeGenerationContext */
27
29
  /** @typedef {import("./Module").CodeGenerationResult} CodeGenerationResult */
28
30
  /** @typedef {import("./Module").LibIdentOptions} LibIdentOptions */
@@ -39,9 +41,16 @@ const makeSerializable = require("./util/makeSerializable");
39
41
  /** @typedef {import("./util/Hash")} Hash */
40
42
  /** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
41
43
 
42
- /** @typedef {string} SourceRequest */
43
- /** @typedef {"require" | "object"} Type */
44
- /** @typedef {TODO} Data */
44
+ /** @typedef {string} DelegatedModuleSourceRequest */
45
+
46
+ /** @typedef {NonNullable<DllReferencePluginOptions["type"]>} DelegatedModuleType */
47
+
48
+ /**
49
+ * @typedef {object} DelegatedModuleData
50
+ * @property {BuildMeta=} buildMeta build meta
51
+ * @property {true | string[]=} exports exports
52
+ * @property {number | string} id module id
53
+ */
45
54
 
46
55
  const RUNTIME_REQUIREMENTS = new Set([
47
56
  RuntimeGlobals.module,
@@ -50,9 +59,9 @@ const RUNTIME_REQUIREMENTS = new Set([
50
59
 
51
60
  class DelegatedModule extends Module {
52
61
  /**
53
- * @param {SourceRequest} sourceRequest source request
54
- * @param {Data} data data
55
- * @param {Type} type type
62
+ * @param {DelegatedModuleSourceRequest} sourceRequest source request
63
+ * @param {DelegatedModuleData} data data
64
+ * @param {DelegatedModuleType} type type
56
65
  * @param {string} userRequest user request
57
66
  * @param {string | Module} originalRequest original request
58
67
  */
@@ -65,7 +74,6 @@ class DelegatedModule extends Module {
65
74
  this.delegationType = type;
66
75
  this.userRequest = userRequest;
67
76
  this.originalRequest = originalRequest;
68
- /** @type {ManifestModuleData | undefined} */
69
77
  this.delegateData = data;
70
78
 
71
79
  // Build info
@@ -255,7 +263,9 @@ class DelegatedModule extends Module {
255
263
  */
256
264
  cleanupForCache() {
257
265
  super.cleanupForCache();
258
- this.delegateData = undefined;
266
+ this.delegateData =
267
+ /** @type {EXPECTED_ANY} */
268
+ (undefined);
259
269
  }
260
270
  }
261
271
 
@@ -9,15 +9,14 @@ const DelegatedModule = require("./DelegatedModule");
9
9
 
10
10
  /** @typedef {import("../declarations/plugins/DllReferencePlugin").DllReferencePluginOptions} DllReferencePluginOptions */
11
11
  /** @typedef {import("../declarations/plugins/DllReferencePlugin").DllReferencePluginOptionsContent} DllReferencePluginOptionsContent */
12
- /** @typedef {import("./DelegatedModule").Data} Data */
13
- /** @typedef {import("./DelegatedModule").SourceRequest} SourceRequest */
14
- /** @typedef {import("./DelegatedModule").Type} Type */
12
+ /** @typedef {import("./DelegatedModule").DelegatedModuleSourceRequest} DelegatedModuleSourceRequest */
13
+ /** @typedef {import("./DelegatedModule").DelegatedModuleType} DelegatedModuleType */
15
14
  /** @typedef {import("./NormalModuleFactory")} NormalModuleFactory */
16
15
  /** @typedef {import("./util/identifier").AssociatedObjectForCache} AssociatedObjectForCache */
17
16
 
18
17
  /**
19
18
  * @typedef {object} Options
20
- * @property {SourceRequest} source source
19
+ * @property {DelegatedModuleSourceRequest} source source
21
20
  * @property {NonNullable<DllReferencePluginOptions["context"]>} context absolute context path to which lib ident is relative to
22
21
  * @property {DllReferencePluginOptionsContent} content content
23
22
  * @property {DllReferencePluginOptions["type"]} type type
@@ -58,7 +57,8 @@ class DelegatedModuleFactoryPlugin {
58
57
  new DelegatedModule(
59
58
  this.options.source,
60
59
  resolved,
61
- /** @type {Type} */ (this.options.type),
60
+ /** @type {DelegatedModuleType} */
61
+ (this.options.type),
62
62
  innerRequest,
63
63
  request
64
64
  )
@@ -77,7 +77,8 @@ class DelegatedModuleFactoryPlugin {
77
77
  new DelegatedModule(
78
78
  this.options.source,
79
79
  resolved,
80
- /** @type {Type} */ (this.options.type),
80
+ /** @type {DelegatedModuleType} */
81
+ (this.options.type),
81
82
  requestPlusExt,
82
83
  request + extension
83
84
  )
@@ -98,7 +99,8 @@ class DelegatedModuleFactoryPlugin {
98
99
  return new DelegatedModule(
99
100
  this.options.source,
100
101
  resolved,
101
- /** @type {Type} */ (this.options.type),
102
+ /** @type {DelegatedModuleType} */
103
+ (this.options.type),
102
104
  request,
103
105
  module
104
106
  );
package/lib/Dependency.js CHANGED
@@ -131,23 +131,22 @@ class Dependency {
131
131
  */
132
132
  get loc() {
133
133
  if (this._loc !== undefined) return this._loc;
134
+
134
135
  /** @type {SyntheticDependencyLocation & RealDependencyLocation} */
135
- const loc = {
136
- start: { line: 0, column: 0 },
137
- end: { line: 0, column: 0 },
138
- name: "",
139
- index: -1
140
- };
136
+ const loc = {};
137
+
141
138
  if (this._locSL > 0) {
142
139
  loc.start = { line: this._locSL, column: this._locSC };
143
140
  }
144
141
  if (this._locEL > 0) {
145
142
  loc.end = { line: this._locEL, column: this._locEC };
146
143
  }
147
-
148
- loc.name = this._locN;
149
-
150
- loc.index = this._locI;
144
+ if (this._locN !== undefined) {
145
+ loc.name = this._locN;
146
+ }
147
+ if (this._locI !== undefined) {
148
+ loc.index = this._locI;
149
+ }
151
150
 
152
151
  return (this._loc = loc);
153
152
  }
@@ -292,7 +291,7 @@ class Dependency {
292
291
 
293
292
  /**
294
293
  * @param {string} context context directory
295
- * @returns {Module | null} a module
294
+ * @returns {Module} ignored module
296
295
  */
297
296
  createIgnoredModule(context) {
298
297
  return getIgnoredModule();
@@ -39,7 +39,7 @@ const PLUGIN_NAME = "EvalSourceMapDevToolPlugin";
39
39
 
40
40
  class EvalSourceMapDevToolPlugin {
41
41
  /**
42
- * @param {SourceMapDevToolPluginOptions|string} inputOptions Options object
42
+ * @param {SourceMapDevToolPluginOptions | string} inputOptions Options object
43
43
  */
44
44
  constructor(inputOptions) {
45
45
  /** @type {SourceMapDevToolPluginOptions} */