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
@@ -37,7 +37,9 @@ const {
37
37
  subtractRuntimeCondition
38
38
  } = require("../util/runtime");
39
39
 
40
+ /** @typedef {import("eslint-scope").Reference} Reference */
40
41
  /** @typedef {import("eslint-scope").Scope} Scope */
42
+ /** @typedef {import("eslint-scope").Variable} Variable */
41
43
  /** @typedef {import("webpack-sources").Source} Source */
42
44
  /** @typedef {import("../../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
43
45
  /** @typedef {import("../ChunkGraph")} ChunkGraph */
@@ -48,10 +50,13 @@ const {
48
50
  /** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
49
51
  /** @typedef {import("../DependencyTemplates")} DependencyTemplates */
50
52
  /** @typedef {import("../ExportsInfo").ExportInfo} ExportInfo */
51
- /** @template T @typedef {import("../InitFragment")<T>} InitFragment */
53
+ /** @typedef {import("../Module").BuildInfo} BuildInfo */
54
+ /** @typedef {import("../Module").BuildMeta} BuildMeta */
52
55
  /** @typedef {import("../Module").CodeGenerationContext} CodeGenerationContext */
53
56
  /** @typedef {import("../Module").CodeGenerationResult} CodeGenerationResult */
54
57
  /** @typedef {import("../Module").LibIdentOptions} LibIdentOptions */
58
+ /** @typedef {import("../Module").ReadOnlyRuntimeRequirements} ReadOnlyRuntimeRequirements */
59
+ /** @typedef {import("../Module").SourceTypes} SourceTypes */
55
60
  /** @typedef {import("../ModuleGraph")} ModuleGraph */
56
61
  /** @typedef {import("../ModuleGraphConnection")} ModuleGraphConnection */
57
62
  /** @typedef {import("../ModuleGraphConnection").ConnectionState} ConnectionState */
@@ -60,14 +65,27 @@ const {
60
65
  /** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
61
66
  /** @typedef {import("../WebpackError")} WebpackError */
62
67
  /** @typedef {import("../javascript/JavascriptModulesPlugin").ChunkRenderContext} ChunkRenderContext */
68
+ /** @typedef {import("../javascript/JavascriptParser").Program} Program */
69
+ /** @typedef {import("../javascript/JavascriptParser").Range} Range */
70
+ /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
63
71
  /** @typedef {import("../util/Hash")} Hash */
64
72
  /** @typedef {typeof import("../util/Hash")} HashConstructor */
65
73
  /** @typedef {import("../util/fs").InputFileSystem} InputFileSystem */
66
74
  /** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
67
75
 
76
+ /**
77
+ * @template T
78
+ * @typedef {import("../InitFragment")<T>} InitFragment
79
+ */
80
+
81
+ /**
82
+ * @template T
83
+ * @typedef {import("../util/comparators").Comparator<T>} Comparator
84
+ */
85
+
68
86
  // fix eslint-scope to support class properties correctly
69
87
  // cspell:word Referencer
70
- const ReferencerClass = Referencer;
88
+ const ReferencerClass = /** @type {any} */ (Referencer);
71
89
  if (!ReferencerClass.prototype.PropertyDefinition) {
72
90
  ReferencerClass.prototype.PropertyDefinition =
73
91
  ReferencerClass.prototype.Property;
@@ -107,24 +125,24 @@ if (!ReferencerClass.prototype.PropertyDefinition) {
107
125
  * @property {"concatenated"} type
108
126
  * @property {Module} module
109
127
  * @property {number} index
110
- * @property {Object} ast
128
+ * @property {Program | undefined} ast
111
129
  * @property {Source} internalSource
112
130
  * @property {ReplaceSource} source
113
131
  * @property {InitFragment<ChunkRenderContext>[]=} chunkInitFragments
114
- * @property {Iterable<string>} runtimeRequirements
132
+ * @property {ReadOnlyRuntimeRequirements} runtimeRequirements
115
133
  * @property {Scope} globalScope
116
134
  * @property {Scope} moduleScope
117
135
  * @property {Map<string, string>} internalNames
118
- * @property {Map<string, string>} exportMap
119
- * @property {Map<string, string>} rawExportMap
136
+ * @property {Map<string, string> | undefined} exportMap
137
+ * @property {Map<string, string> | undefined} rawExportMap
120
138
  * @property {string=} namespaceExportSymbol
121
- * @property {string} namespaceObjectName
139
+ * @property {string | undefined} namespaceObjectName
122
140
  * @property {boolean} interopNamespaceObjectUsed
123
- * @property {string} interopNamespaceObjectName
141
+ * @property {string | undefined} interopNamespaceObjectName
124
142
  * @property {boolean} interopNamespaceObject2Used
125
- * @property {string} interopNamespaceObject2Name
143
+ * @property {string | undefined} interopNamespaceObject2Name
126
144
  * @property {boolean} interopDefaultAccessUsed
127
- * @property {string} interopDefaultAccessName
145
+ * @property {string | undefined} interopDefaultAccessName
128
146
  */
129
147
 
130
148
  /**
@@ -149,6 +167,8 @@ if (!ReferencerClass.prototype.PropertyDefinition) {
149
167
  * @property {ConcatenatedModuleInfo | ExternalModuleInfo} target
150
168
  */
151
169
 
170
+ /** @typedef {Set<string>} UsedNames */
171
+
152
172
  const RESERVED_NAMES = new Set(
153
173
  [
154
174
  // internal names (should always be renamed)
@@ -189,6 +209,12 @@ const RESERVED_NAMES = new Set(
189
209
 
190
210
  const createComparator = (property, comparator) => (a, b) =>
191
211
  comparator(a[property], b[property]);
212
+
213
+ /**
214
+ * @param {number} a a
215
+ * @param {number} b b
216
+ * @returns {0 | 1 | -1} result
217
+ */
192
218
  const compareNumbers = (a, b) => {
193
219
  if (isNaN(a)) {
194
220
  if (!isNaN(b)) {
@@ -207,6 +233,10 @@ const compareNumbers = (a, b) => {
207
233
  const bySourceOrder = createComparator("sourceOrder", compareNumbers);
208
234
  const byRangeStart = createComparator("rangeStart", compareNumbers);
209
235
 
236
+ /**
237
+ * @param {Iterable<string>} iterable iterable object
238
+ * @returns {string} joined iterable object
239
+ */
210
240
  const joinIterableWithComma = iterable => {
211
241
  // This is more performant than Array.from().join(", ")
212
242
  // as it doesn't create an array
@@ -240,7 +270,7 @@ const joinIterableWithComma = iterable => {
240
270
  * @param {RuntimeTemplate} runtimeTemplate the runtime template
241
271
  * @param {Set<ConcatenatedModuleInfo>} neededNamespaceObjects modules for which a namespace object should be generated
242
272
  * @param {boolean} asCall asCall
243
- * @param {boolean} strictHarmonyModule strictHarmonyModule
273
+ * @param {boolean | undefined} strictHarmonyModule strictHarmonyModule
244
274
  * @param {boolean | undefined} asiSafe asiSafe
245
275
  * @param {Set<ExportInfo>} alreadyVisited alreadyVisited
246
276
  * @returns {Binding} the final variable
@@ -269,7 +299,7 @@ const getFinalBinding = (
269
299
  info.interopNamespaceObject2Used = true;
270
300
  return {
271
301
  info,
272
- rawName: info.interopNamespaceObject2Name,
302
+ rawName: /** @type {string} */ (info.interopNamespaceObject2Name),
273
303
  ids: exportName,
274
304
  exportName
275
305
  };
@@ -277,7 +307,7 @@ const getFinalBinding = (
277
307
  info.interopNamespaceObjectUsed = true;
278
308
  return {
279
309
  info,
280
- rawName: info.interopNamespaceObjectName,
310
+ rawName: /** @type {string} */ (info.interopNamespaceObjectName),
281
311
  ids: exportName,
282
312
  exportName
283
313
  };
@@ -365,7 +395,7 @@ const getFinalBinding = (
365
395
  neededNamespaceObjects.add(info);
366
396
  return {
367
397
  info,
368
- rawName: info.namespaceObjectName,
398
+ rawName: /** @type {string} */ (info.namespaceObjectName),
369
399
  ids: exportName,
370
400
  exportName
371
401
  };
@@ -392,7 +422,7 @@ const getFinalBinding = (
392
422
  neededNamespaceObjects.add(info);
393
423
  return {
394
424
  info,
395
- rawName: info.namespaceObjectName,
425
+ rawName: /** @type {string} */ (info.namespaceObjectName),
396
426
  ids: exportName,
397
427
  exportName
398
428
  };
@@ -444,7 +474,7 @@ const getFinalBinding = (
444
474
  const refInfo = moduleToInfoMap.get(reexport.module);
445
475
  return getFinalBinding(
446
476
  moduleGraph,
447
- refInfo,
477
+ /** @type {ModuleInfo} */ (refInfo),
448
478
  reexport.export
449
479
  ? [...reexport.export, ...exportName.slice(1)]
450
480
  : exportName.slice(1),
@@ -454,7 +484,8 @@ const getFinalBinding = (
454
484
  runtimeTemplate,
455
485
  neededNamespaceObjects,
456
486
  asCall,
457
- info.module.buildMeta.strictHarmonyModule,
487
+ /** @type {BuildMeta} */
488
+ (info.module.buildMeta).strictHarmonyModule,
458
489
  asiSafe,
459
490
  alreadyVisited
460
491
  );
@@ -465,7 +496,7 @@ const getFinalBinding = (
465
496
  );
466
497
  return {
467
498
  info,
468
- rawName: info.namespaceObjectName,
499
+ rawName: /** @type {string} */ (info.namespaceObjectName),
469
500
  ids: usedName,
470
501
  exportName
471
502
  };
@@ -507,8 +538,8 @@ const getFinalBinding = (
507
538
  * @param {RuntimeTemplate} runtimeTemplate the runtime template
508
539
  * @param {Set<ConcatenatedModuleInfo>} neededNamespaceObjects modules for which a namespace object should be generated
509
540
  * @param {boolean} asCall asCall
510
- * @param {boolean} callContext callContext
511
- * @param {boolean} strictHarmonyModule strictHarmonyModule
541
+ * @param {boolean | undefined} callContext callContext
542
+ * @param {boolean | undefined} strictHarmonyModule strictHarmonyModule
512
543
  * @param {boolean | undefined} asiSafe asiSafe
513
544
  * @returns {string} the final name
514
545
  */
@@ -575,6 +606,12 @@ const getFinalName = (
575
606
  }
576
607
  };
577
608
 
609
+ /**
610
+ * @param {Scope | null} s scope
611
+ * @param {UsedNames} nameSet name set
612
+ * @param {TODO} scopeSet1 scope set 1
613
+ * @param {TODO} scopeSet2 scope set 2
614
+ */
578
615
  const addScopeSymbols = (s, nameSet, scopeSet1, scopeSet2) => {
579
616
  let scope = s;
580
617
  while (scope) {
@@ -588,6 +625,10 @@ const addScopeSymbols = (s, nameSet, scopeSet1, scopeSet2) => {
588
625
  }
589
626
  };
590
627
 
628
+ /**
629
+ * @param {Variable} variable variable
630
+ * @returns {Reference[]} references
631
+ */
591
632
  const getAllReferences = variable => {
592
633
  let set = variable.references;
593
634
  // Look for inner scope variables too (like in class Foo { t() { Foo } })
@@ -603,6 +644,11 @@ const getAllReferences = variable => {
603
644
  return set;
604
645
  };
605
646
 
647
+ /**
648
+ * @param {TODO} ast ast
649
+ * @param {TODO} node node
650
+ * @returns {TODO} result
651
+ */
606
652
  const getPathInAst = (ast, node) => {
607
653
  if (ast === node) {
608
654
  return [];
@@ -710,7 +756,7 @@ class ConcatenatedModule extends Module {
710
756
  }
711
757
 
712
758
  /**
713
- * @returns {Set<string>} types available (do not mutate)
759
+ * @returns {SourceTypes} types available (do not mutate)
714
760
  */
715
761
  getSourceTypes() {
716
762
  return TYPES;
@@ -771,11 +817,14 @@ class ConcatenatedModule extends Module {
771
817
  */
772
818
  build(options, compilation, resolver, fs, callback) {
773
819
  const { rootModule } = this;
820
+ const { moduleArgument, exportsArgument } =
821
+ /** @type {BuildInfo} */
822
+ (rootModule.buildInfo);
774
823
  this.buildInfo = {
775
824
  strict: true,
776
825
  cacheable: true,
777
- moduleArgument: rootModule.buildInfo.moduleArgument,
778
- exportsArgument: rootModule.buildInfo.exportsArgument,
826
+ moduleArgument,
827
+ exportsArgument,
779
828
  fileDependencies: new LazySet(),
780
829
  contextDependencies: new LazySet(),
781
830
  missingDependencies: new LazySet(),
@@ -788,7 +837,7 @@ class ConcatenatedModule extends Module {
788
837
 
789
838
  for (const m of this._modules) {
790
839
  // populate cacheable
791
- if (!m.buildInfo.cacheable) {
840
+ if (!(/** @type {BuildInfo} */ (m.buildInfo).cacheable)) {
792
841
  this.buildInfo.cacheable = false;
793
842
  }
794
843
 
@@ -796,7 +845,9 @@ class ConcatenatedModule extends Module {
796
845
  for (const d of m.dependencies.filter(
797
846
  dep =>
798
847
  !(dep instanceof HarmonyImportDependency) ||
799
- !this._modules.has(compilation.moduleGraph.getModule(dep))
848
+ !this._modules.has(
849
+ /** @type {Module} */ (compilation.moduleGraph.getModule(dep))
850
+ )
800
851
  )) {
801
852
  this.dependencies.push(d);
802
853
  }
@@ -821,11 +872,14 @@ class ConcatenatedModule extends Module {
821
872
  }
822
873
  }
823
874
 
875
+ const { assets, assetsInfo, topLevelDeclarations } =
876
+ /** @type {BuildInfo} */ (m.buildInfo);
877
+
824
878
  // populate topLevelDeclarations
825
- if (m.buildInfo.topLevelDeclarations) {
879
+ if (topLevelDeclarations) {
826
880
  const topLevelDeclarations = this.buildInfo.topLevelDeclarations;
827
881
  if (topLevelDeclarations !== undefined) {
828
- for (const decl of m.buildInfo.topLevelDeclarations) {
882
+ for (const decl of topLevelDeclarations) {
829
883
  topLevelDeclarations.add(decl);
830
884
  }
831
885
  }
@@ -834,17 +888,17 @@ class ConcatenatedModule extends Module {
834
888
  }
835
889
 
836
890
  // populate assets
837
- if (m.buildInfo.assets) {
891
+ if (assets) {
838
892
  if (this.buildInfo.assets === undefined) {
839
893
  this.buildInfo.assets = Object.create(null);
840
894
  }
841
- Object.assign(this.buildInfo.assets, m.buildInfo.assets);
895
+ Object.assign(/** @type {BuildInfo} */ (this.buildInfo).assets, assets);
842
896
  }
843
- if (m.buildInfo.assetsInfo) {
897
+ if (assetsInfo) {
844
898
  if (this.buildInfo.assetsInfo === undefined) {
845
899
  this.buildInfo.assetsInfo = new Map();
846
900
  }
847
- for (const [key, value] of m.buildInfo.assetsInfo) {
901
+ for (const [key, value] of assetsInfo) {
848
902
  this.buildInfo.assetsInfo.set(key, value);
849
903
  }
850
904
  }
@@ -1055,7 +1109,7 @@ class ConcatenatedModule extends Module {
1055
1109
  hashFunction = "md4"
1056
1110
  ) {
1057
1111
  const cachedMakePathsRelative = makePathsRelative.bindContextCache(
1058
- rootModule.context,
1112
+ /** @type {string} */ (rootModule.context),
1059
1113
  associatedObjectForCache
1060
1114
  );
1061
1115
  let identifiers = [];
@@ -1138,12 +1192,12 @@ class ConcatenatedModule extends Module {
1138
1192
  const topLevelDeclarations = new Set();
1139
1193
 
1140
1194
  // List of additional names in scope for module references
1141
- /** @type {Map<string, { usedNames: Set<string>, alreadyCheckedScopes: Set<TODO> }>} */
1195
+ /** @type {Map<string, { usedNames: UsedNames, alreadyCheckedScopes: Set<TODO> }>} */
1142
1196
  const usedNamesInScopeInfo = new Map();
1143
1197
  /**
1144
1198
  * @param {string} module module identifier
1145
1199
  * @param {string} id export id
1146
- * @returns {{ usedNames: Set<string>, alreadyCheckedScopes: Set<TODO> }} info
1200
+ * @returns {{ usedNames: UsedNames, alreadyCheckedScopes: Set<TODO> }} info
1147
1201
  */
1148
1202
  const getUsedNamesInScopeInfo = (module, id) => {
1149
1203
  const key = `${module}-${id}`;
@@ -1173,6 +1227,10 @@ class ConcatenatedModule extends Module {
1173
1227
  // We get ranges of all super class expressions to make
1174
1228
  // renaming to work correctly
1175
1229
  const superClassCache = new WeakMap();
1230
+ /**
1231
+ * @param {Scope} scope scope
1232
+ * @returns {TODO} result
1233
+ */
1176
1234
  const getSuperClassExpressions = scope => {
1177
1235
  const cacheEntry = superClassCache.get(scope);
1178
1236
  if (cacheEntry !== undefined) return cacheEntry;
@@ -1215,7 +1273,8 @@ class ConcatenatedModule extends Module {
1215
1273
  runtimeTemplate,
1216
1274
  neededNamespaceObjects,
1217
1275
  false,
1218
- info.module.buildMeta.strictHarmonyModule,
1276
+ /** @type {BuildMeta} */
1277
+ (info.module.buildMeta).strictHarmonyModule,
1219
1278
  true
1220
1279
  );
1221
1280
  if (!binding.ids) continue;
@@ -1226,8 +1285,10 @@ class ConcatenatedModule extends Module {
1226
1285
  );
1227
1286
  for (const expr of getSuperClassExpressions(reference.from)) {
1228
1287
  if (
1229
- expr.range[0] <= reference.identifier.range[0] &&
1230
- expr.range[1] >= reference.identifier.range[1]
1288
+ expr.range[0] <=
1289
+ /** @type {Range} */ (reference.identifier.range)[0] &&
1290
+ expr.range[1] >=
1291
+ /** @type {Range} */ (reference.identifier.range)[1]
1231
1292
  ) {
1232
1293
  for (const variable of expr.variables) {
1233
1294
  usedNames.add(variable.name);
@@ -1286,7 +1347,7 @@ class ConcatenatedModule extends Module {
1286
1347
  references.map(r => r.identifier).concat(variable.identifiers)
1287
1348
  );
1288
1349
  for (const identifier of allIdentifiers) {
1289
- const r = identifier.range;
1350
+ const r = /** @type {Range} */ (identifier.range);
1290
1351
  const path = getPathInAst(info.ast, identifier);
1291
1352
  if (path && path.length > 1) {
1292
1353
  const maybeProperty =
@@ -1324,7 +1385,9 @@ class ConcatenatedModule extends Module {
1324
1385
  );
1325
1386
  allUsedNames.add(namespaceObjectName);
1326
1387
  }
1327
- info.namespaceObjectName = namespaceObjectName;
1388
+ info.namespaceObjectName =
1389
+ /** @type {string} */
1390
+ (namespaceObjectName);
1328
1391
  topLevelDeclarations.add(namespaceObjectName);
1329
1392
  break;
1330
1393
  }
@@ -1341,7 +1404,8 @@ class ConcatenatedModule extends Module {
1341
1404
  break;
1342
1405
  }
1343
1406
  }
1344
- if (info.module.buildMeta.exportsType !== "namespace") {
1407
+ const buildMeta = /** @type {BuildMeta} */ (info.module.buildMeta);
1408
+ if (buildMeta.exportsType !== "namespace") {
1345
1409
  const externalNameInterop = this.findNewName(
1346
1410
  "namespaceObject",
1347
1411
  allUsedNames,
@@ -1353,8 +1417,8 @@ class ConcatenatedModule extends Module {
1353
1417
  topLevelDeclarations.add(externalNameInterop);
1354
1418
  }
1355
1419
  if (
1356
- info.module.buildMeta.exportsType === "default" &&
1357
- info.module.buildMeta.defaultObject !== "redirect"
1420
+ buildMeta.exportsType === "default" &&
1421
+ buildMeta.defaultObject !== "redirect"
1358
1422
  ) {
1359
1423
  const externalNameInterop = this.findNewName(
1360
1424
  "namespaceObject2",
@@ -1366,10 +1430,7 @@ class ConcatenatedModule extends Module {
1366
1430
  info.interopNamespaceObject2Name = externalNameInterop;
1367
1431
  topLevelDeclarations.add(externalNameInterop);
1368
1432
  }
1369
- if (
1370
- info.module.buildMeta.exportsType === "dynamic" ||
1371
- !info.module.buildMeta.exportsType
1372
- ) {
1433
+ if (buildMeta.exportsType === "dynamic" || !buildMeta.exportsType) {
1373
1434
  const externalNameInterop = this.findNewName(
1374
1435
  "default",
1375
1436
  allUsedNames,
@@ -1403,10 +1464,11 @@ class ConcatenatedModule extends Module {
1403
1464
  neededNamespaceObjects,
1404
1465
  match.call,
1405
1466
  !match.directImport,
1406
- info.module.buildMeta.strictHarmonyModule,
1467
+ /** @type {BuildMeta} */
1468
+ (info.module.buildMeta).strictHarmonyModule,
1407
1469
  match.asiSafe
1408
1470
  );
1409
- const r = reference.identifier.range;
1471
+ const r = /** @type {Range} */ (reference.identifier.range);
1410
1472
  const source = info.source;
1411
1473
  // range is extended by 2 chars to cover the appended "._"
1412
1474
  source.replace(r[0], r[1] + 1, finalName);
@@ -1426,7 +1488,9 @@ class ConcatenatedModule extends Module {
1426
1488
  const rootInfo = /** @type {ConcatenatedModuleInfo} */ (
1427
1489
  moduleToInfoMap.get(this.rootModule)
1428
1490
  );
1429
- const strictHarmonyModule = rootInfo.module.buildMeta.strictHarmonyModule;
1491
+ const strictHarmonyModule =
1492
+ /** @type {BuildMeta} */
1493
+ (rootInfo.module.buildMeta).strictHarmonyModule;
1430
1494
  const exportsInfo = moduleGraph.getExportsInfo(rootInfo.module);
1431
1495
  for (const exportInfo of exportsInfo.orderedExports) {
1432
1496
  const name = exportInfo.name;
@@ -1456,7 +1520,9 @@ class ConcatenatedModule extends Module {
1456
1520
  exportInfo.isReexport() ? "reexport" : "binding"
1457
1521
  } */ ${finalName}`;
1458
1522
  } catch (e) {
1459
- e.message += `\nwhile generating the root export '${name}' (used name: '${used}')`;
1523
+ /** @type {Error} */
1524
+ (e).message +=
1525
+ `\nwhile generating the root export '${name}' (used name: '${used}')`;
1460
1526
  throw e;
1461
1527
  }
1462
1528
  });
@@ -1526,7 +1592,8 @@ class ConcatenatedModule extends Module {
1526
1592
  neededNamespaceObjects,
1527
1593
  false,
1528
1594
  undefined,
1529
- info.module.buildMeta.strictHarmonyModule,
1595
+ /** @type {BuildMeta} */
1596
+ (info.module.buildMeta).strictHarmonyModule,
1530
1597
  true
1531
1598
  );
1532
1599
  nsObj.push(
@@ -1697,7 +1764,9 @@ ${defineGetters}`
1697
1764
  codeGenerationResults,
1698
1765
  sourceTypes: TYPES
1699
1766
  });
1700
- const source = codeGenResult.sources.get("javascript");
1767
+ const source = /** @type {Source} */ (
1768
+ codeGenResult.sources.get("javascript")
1769
+ );
1701
1770
  const data = codeGenResult.data;
1702
1771
  const chunkInitFragments = data && data.get("chunkInitFragments");
1703
1772
  const code = source.source().toString();
@@ -1729,7 +1798,7 @@ ${defineGetters}`
1729
1798
  ignoreEval: true,
1730
1799
  impliedStrict: true
1731
1800
  });
1732
- const globalScope = scopeManager.acquire(ast);
1801
+ const globalScope = /** @type {Scope} */ (scopeManager.acquire(ast));
1733
1802
  const moduleScope = globalScope.childScopes[0];
1734
1803
  const resultSource = new ReplaceSource(source);
1735
1804
  info.runtimeRequirements = codeGenResult.runtimeRequirements;
@@ -1740,7 +1809,9 @@ ${defineGetters}`
1740
1809
  info.globalScope = globalScope;
1741
1810
  info.moduleScope = moduleScope;
1742
1811
  } catch (err) {
1743
- err.message += `\nwhile analyzing module ${m.identifier()} for concatenation`;
1812
+ /** @type {Error} */
1813
+ (err).message +=
1814
+ `\nwhile analyzing module ${m.identifier()} for concatenation`;
1744
1815
  throw err;
1745
1816
  }
1746
1817
  }
@@ -1808,7 +1879,10 @@ ${defineGetters}`
1808
1879
  `Unsupported concatenation entry type ${info.type}`
1809
1880
  );
1810
1881
  }
1811
- map.set(item.module, item);
1882
+ map.set(
1883
+ /** @type {ModuleInfo} */ (item).module,
1884
+ /** @type {ModuleInfo} */ (item)
1885
+ );
1812
1886
  return item;
1813
1887
  } else {
1814
1888
  /** @type {ReferenceToModuleInfo} */
@@ -1823,6 +1897,13 @@ ${defineGetters}`
1823
1897
  return [list, map];
1824
1898
  }
1825
1899
 
1900
+ /**
1901
+ * @param {string} oldName old name
1902
+ * @param {UsedNames} usedNamed1 used named 1
1903
+ * @param {UsedNames} usedNamed2 used named 2
1904
+ * @param {string} extraInfo extra info
1905
+ * @returns {string} found new name
1906
+ */
1826
1907
  findNewName(oldName, usedNamed1, usedNamed2, extraInfo) {
1827
1908
  let name = oldName;
1828
1909
 
@@ -1888,6 +1969,10 @@ ${defineGetters}`
1888
1969
  super.updateHash(hash, context);
1889
1970
  }
1890
1971
 
1972
+ /**
1973
+ * @param {ObjectDeserializerContext} context context
1974
+ * @returns {ConcatenatedModule} ConcatenatedModule
1975
+ */
1891
1976
  static deserialize(context) {
1892
1977
  const obj = new ConcatenatedModule({
1893
1978
  identifier: undefined,
@@ -56,7 +56,7 @@ class EnsureChunkConditionsPlugin {
56
56
  // We reached the entrypoint: fail
57
57
  if (chunkGroup.isInitial()) {
58
58
  throw new Error(
59
- "Cannot fullfil chunk condition of " + module.identifier()
59
+ "Cannot fulfil chunk condition of " + module.identifier()
60
60
  );
61
61
  }
62
62
  // Try placing in all parents
@@ -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 */
@@ -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) {