webpack 5.59.0 → 5.94.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.
Files changed (570) hide show
  1. package/README.md +48 -38
  2. package/bin/webpack.js +34 -10
  3. package/hot/dev-server.js +19 -5
  4. package/hot/lazy-compilation-node.js +13 -1
  5. package/hot/lazy-compilation-web.js +9 -0
  6. package/hot/log-apply-result.js +5 -0
  7. package/hot/log.js +23 -4
  8. package/hot/only-dev-server.js +3 -2
  9. package/hot/poll.js +5 -2
  10. package/hot/signal.js +6 -2
  11. package/lib/APIPlugin.js +226 -122
  12. package/lib/AbstractMethodError.js +10 -5
  13. package/lib/AsyncDependenciesBlock.js +13 -5
  14. package/lib/AutomaticPrefetchPlugin.js +2 -1
  15. package/lib/BannerPlugin.js +33 -12
  16. package/lib/Cache.js +16 -12
  17. package/lib/CacheFacade.js +13 -16
  18. package/lib/CaseSensitiveModulesWarning.js +8 -8
  19. package/lib/Chunk.js +60 -33
  20. package/lib/ChunkGraph.js +207 -72
  21. package/lib/ChunkGroup.js +40 -20
  22. package/lib/ChunkTemplate.js +43 -0
  23. package/lib/CleanPlugin.js +117 -32
  24. package/lib/CodeGenerationResults.js +8 -7
  25. package/lib/CommentCompilationWarning.js +0 -1
  26. package/lib/CompatibilityPlugin.js +85 -46
  27. package/lib/Compilation.js +712 -392
  28. package/lib/Compiler.js +393 -172
  29. package/lib/ConcatenationScope.js +10 -13
  30. package/lib/ConditionalInitFragment.js +22 -14
  31. package/lib/ConstPlugin.js +104 -64
  32. package/lib/ContextExclusionPlugin.js +3 -3
  33. package/lib/ContextModule.js +283 -108
  34. package/lib/ContextModuleFactory.js +151 -63
  35. package/lib/ContextReplacementPlugin.js +25 -10
  36. package/lib/CssModule.js +166 -0
  37. package/lib/DefinePlugin.js +254 -148
  38. package/lib/DelegatedModule.js +29 -6
  39. package/lib/DelegatedModuleFactoryPlugin.js +42 -22
  40. package/lib/DelegatedPlugin.js +4 -0
  41. package/lib/DependenciesBlock.js +17 -2
  42. package/lib/Dependency.js +58 -29
  43. package/lib/DependencyTemplate.js +24 -3
  44. package/lib/DependencyTemplates.js +2 -2
  45. package/lib/DllEntryPlugin.js +18 -1
  46. package/lib/DllModule.js +21 -4
  47. package/lib/DllModuleFactory.js +2 -1
  48. package/lib/DllPlugin.js +9 -7
  49. package/lib/DllReferencePlugin.js +50 -19
  50. package/lib/EntryOptionPlugin.js +6 -1
  51. package/lib/EntryPlugin.js +7 -4
  52. package/lib/Entrypoint.js +2 -2
  53. package/lib/EnvironmentNotSupportAsyncWarning.js +52 -0
  54. package/lib/EnvironmentPlugin.js +5 -2
  55. package/lib/ErrorHelpers.js +65 -26
  56. package/lib/EvalDevToolModulePlugin.js +37 -13
  57. package/lib/EvalSourceMapDevToolPlugin.js +50 -20
  58. package/lib/ExportsInfo.js +234 -133
  59. package/lib/ExportsInfoApiPlugin.js +31 -15
  60. package/lib/ExternalModule.js +391 -129
  61. package/lib/ExternalModuleFactoryPlugin.js +65 -17
  62. package/lib/FileSystemInfo.js +1038 -523
  63. package/lib/FlagAllModulesAsUsedPlugin.js +27 -27
  64. package/lib/FlagDependencyExportsPlugin.js +352 -349
  65. package/lib/FlagDependencyUsagePlugin.js +10 -10
  66. package/lib/FlagEntryExportAsUsedPlugin.js +26 -23
  67. package/lib/Generator.js +16 -8
  68. package/lib/GraphHelpers.js +3 -2
  69. package/lib/HookWebpackError.js +11 -13
  70. package/lib/HotModuleReplacementPlugin.js +221 -128
  71. package/lib/IgnoreErrorModuleFactory.js +4 -4
  72. package/lib/IgnorePlugin.js +5 -4
  73. package/lib/IgnoreWarningsPlugin.js +6 -9
  74. package/lib/InitFragment.js +39 -15
  75. package/lib/JavascriptMetaInfoPlugin.js +27 -15
  76. package/lib/LibManifestPlugin.js +45 -16
  77. package/lib/LoaderOptionsPlugin.js +13 -3
  78. package/lib/MainTemplate.js +74 -21
  79. package/lib/Module.js +155 -34
  80. package/lib/ModuleBuildError.js +13 -11
  81. package/lib/ModuleDependencyError.js +6 -4
  82. package/lib/ModuleDependencyWarning.js +6 -4
  83. package/lib/ModuleError.js +10 -5
  84. package/lib/ModuleFactory.js +4 -4
  85. package/lib/ModuleFilenameHelpers.js +164 -54
  86. package/lib/ModuleGraph.js +93 -53
  87. package/lib/ModuleGraphConnection.js +27 -13
  88. package/lib/ModuleHashingError.js +29 -0
  89. package/lib/ModuleInfoHeaderPlugin.js +92 -33
  90. package/lib/ModuleNotFoundError.js +5 -2
  91. package/lib/ModuleParseError.js +17 -9
  92. package/lib/ModuleProfile.js +1 -0
  93. package/lib/ModuleRestoreError.js +3 -1
  94. package/lib/ModuleStoreError.js +3 -2
  95. package/lib/ModuleTemplate.js +33 -1
  96. package/lib/ModuleTypeConstants.js +168 -0
  97. package/lib/ModuleWarning.js +10 -5
  98. package/lib/MultiCompiler.js +115 -38
  99. package/lib/MultiStats.js +75 -33
  100. package/lib/MultiWatching.js +6 -2
  101. package/lib/NodeStuffPlugin.js +136 -37
  102. package/lib/NormalModule.js +437 -194
  103. package/lib/NormalModuleFactory.js +313 -116
  104. package/lib/NormalModuleReplacementPlugin.js +10 -4
  105. package/lib/NullFactory.js +1 -1
  106. package/lib/OptimizationStages.js +3 -3
  107. package/lib/Parser.js +1 -1
  108. package/lib/PlatformPlugin.js +39 -0
  109. package/lib/PrefetchPlugin.js +4 -0
  110. package/lib/ProgressPlugin.js +83 -28
  111. package/lib/ProvidePlugin.js +37 -19
  112. package/lib/RawModule.js +18 -5
  113. package/lib/RecordIdsPlugin.js +8 -8
  114. package/lib/RequireJsStuffPlugin.js +22 -15
  115. package/lib/ResolverFactory.js +8 -4
  116. package/lib/RuntimeGlobals.js +99 -65
  117. package/lib/RuntimeModule.js +17 -15
  118. package/lib/RuntimePlugin.js +116 -13
  119. package/lib/RuntimeTemplate.js +304 -102
  120. package/lib/SelfModuleFactory.js +12 -0
  121. package/lib/SizeFormatHelpers.js +2 -4
  122. package/lib/SourceMapDevToolModuleOptionsPlugin.js +4 -0
  123. package/lib/SourceMapDevToolPlugin.js +89 -42
  124. package/lib/Stats.js +12 -7
  125. package/lib/Template.js +30 -33
  126. package/lib/TemplatedPathPlugin.js +102 -34
  127. package/lib/UseStrictPlugin.js +37 -12
  128. package/lib/WarnCaseSensitiveModulesPlugin.js +12 -0
  129. package/lib/WarnDeprecatedOptionPlugin.js +6 -0
  130. package/lib/WatchIgnorePlugin.js +46 -13
  131. package/lib/Watching.js +139 -76
  132. package/lib/WebpackError.js +14 -5
  133. package/lib/WebpackIsIncludedPlugin.js +22 -13
  134. package/lib/WebpackOptionsApply.js +162 -56
  135. package/lib/WebpackOptionsDefaulter.js +10 -3
  136. package/lib/asset/AssetGenerator.js +351 -99
  137. package/lib/asset/AssetModulesPlugin.js +57 -33
  138. package/lib/asset/AssetParser.js +15 -6
  139. package/lib/asset/AssetSourceGenerator.js +30 -10
  140. package/lib/asset/AssetSourceParser.js +8 -2
  141. package/lib/asset/RawDataUrlModule.js +162 -0
  142. package/lib/async-modules/AwaitDependenciesInitFragment.js +16 -13
  143. package/lib/async-modules/InferAsyncModulesPlugin.js +1 -1
  144. package/lib/buildChunkGraph.js +376 -420
  145. package/lib/cache/AddManagedPathsPlugin.js +6 -1
  146. package/lib/cache/IdleFileCachePlugin.js +26 -13
  147. package/lib/cache/MemoryCachePlugin.js +1 -1
  148. package/lib/cache/MemoryWithGcCachePlugin.js +13 -7
  149. package/lib/cache/PackFileCacheStrategy.js +172 -94
  150. package/lib/cache/ResolverCachePlugin.js +115 -43
  151. package/lib/cache/getLazyHashedEtag.js +2 -2
  152. package/lib/cache/mergeEtags.js +16 -21
  153. package/lib/cli.js +195 -110
  154. package/lib/config/browserslistTargetHandler.js +106 -41
  155. package/lib/config/defaults.js +572 -154
  156. package/lib/config/normalization.js +361 -322
  157. package/lib/config/target.js +105 -66
  158. package/lib/container/ContainerEntryDependency.js +2 -1
  159. package/lib/container/ContainerEntryModule.js +27 -11
  160. package/lib/container/ContainerEntryModuleFactory.js +1 -1
  161. package/lib/container/ContainerExposedDependency.js +9 -0
  162. package/lib/container/ContainerPlugin.js +18 -12
  163. package/lib/container/ContainerReferencePlugin.js +1 -1
  164. package/lib/container/FallbackDependency.js +13 -0
  165. package/lib/container/FallbackItemDependency.js +3 -0
  166. package/lib/container/FallbackModule.js +19 -8
  167. package/lib/container/FallbackModuleFactory.js +1 -1
  168. package/lib/container/ModuleFederationPlugin.js +2 -0
  169. package/lib/container/RemoteModule.js +17 -4
  170. package/lib/container/RemoteRuntimeModule.js +31 -17
  171. package/lib/container/RemoteToExternalDependency.js +3 -0
  172. package/lib/container/options.js +18 -4
  173. package/lib/css/CssExportsGenerator.js +203 -0
  174. package/lib/css/CssGenerator.js +151 -0
  175. package/lib/css/CssLoadingRuntimeModule.js +592 -0
  176. package/lib/css/CssModulesPlugin.js +888 -0
  177. package/lib/css/CssParser.js +1049 -0
  178. package/lib/css/walkCssTokens.js +775 -0
  179. package/lib/debug/ProfilingPlugin.js +102 -54
  180. package/lib/dependencies/AMDDefineDependency.js +54 -10
  181. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +204 -61
  182. package/lib/dependencies/AMDPlugin.js +44 -24
  183. package/lib/dependencies/AMDRequireArrayDependency.js +34 -10
  184. package/lib/dependencies/AMDRequireContextDependency.js +15 -0
  185. package/lib/dependencies/AMDRequireDependenciesBlock.js +6 -0
  186. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +185 -54
  187. package/lib/dependencies/AMDRequireDependency.js +21 -6
  188. package/lib/dependencies/AMDRequireItemDependency.js +6 -0
  189. package/lib/dependencies/AMDRuntimeModules.js +4 -4
  190. package/lib/dependencies/CachedConstDependency.js +22 -1
  191. package/lib/dependencies/CommonJsDependencyHelpers.js +16 -2
  192. package/lib/dependencies/CommonJsExportRequireDependency.js +77 -47
  193. package/lib/dependencies/CommonJsExportsDependency.js +28 -5
  194. package/lib/dependencies/CommonJsExportsParserPlugin.js +111 -39
  195. package/lib/dependencies/CommonJsFullRequireDependency.js +42 -8
  196. package/lib/dependencies/CommonJsImportsParserPlugin.js +530 -130
  197. package/lib/dependencies/CommonJsPlugin.js +51 -26
  198. package/lib/dependencies/CommonJsRequireContextDependency.js +23 -2
  199. package/lib/dependencies/CommonJsRequireDependency.js +9 -1
  200. package/lib/dependencies/CommonJsSelfReferenceDependency.js +22 -8
  201. package/lib/dependencies/ConstDependency.js +12 -3
  202. package/lib/dependencies/ContextDependency.js +32 -5
  203. package/lib/dependencies/ContextDependencyHelpers.js +92 -62
  204. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +4 -1
  205. package/lib/dependencies/ContextElementDependency.js +41 -4
  206. package/lib/dependencies/CreateScriptUrlDependency.js +22 -1
  207. package/lib/dependencies/CriticalDependencyWarning.js +4 -1
  208. package/lib/dependencies/CssExportDependency.js +156 -0
  209. package/lib/dependencies/CssImportDependency.js +125 -0
  210. package/lib/dependencies/CssLocalIdentifierDependency.js +245 -0
  211. package/lib/dependencies/CssSelfLocalIdentifierDependency.js +111 -0
  212. package/lib/dependencies/CssUrlDependency.js +164 -0
  213. package/lib/dependencies/DelegatedSourceDependency.js +3 -0
  214. package/lib/dependencies/DllEntryDependency.js +14 -0
  215. package/lib/dependencies/DynamicExports.js +15 -11
  216. package/lib/dependencies/ExportsInfoDependency.js +26 -5
  217. package/lib/dependencies/ExternalModuleDependency.js +109 -0
  218. package/lib/dependencies/ExternalModuleInitFragment.js +133 -0
  219. package/lib/dependencies/HarmonyAcceptDependency.js +11 -2
  220. package/lib/dependencies/HarmonyAcceptImportDependency.js +9 -4
  221. package/lib/dependencies/HarmonyCompatibilityDependency.js +6 -5
  222. package/lib/dependencies/HarmonyDetectionParserPlugin.js +29 -3
  223. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +152 -0
  224. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +96 -51
  225. package/lib/dependencies/HarmonyExportExpressionDependency.js +21 -4
  226. package/lib/dependencies/HarmonyExportHeaderDependency.js +13 -0
  227. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +216 -108
  228. package/lib/dependencies/HarmonyExportInitFragment.js +21 -9
  229. package/lib/dependencies/HarmonyExportSpecifierDependency.js +12 -0
  230. package/lib/dependencies/HarmonyExports.js +13 -7
  231. package/lib/dependencies/HarmonyImportDependency.js +65 -19
  232. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +268 -74
  233. package/lib/dependencies/HarmonyImportSideEffectDependency.js +11 -5
  234. package/lib/dependencies/HarmonyImportSpecifierDependency.js +180 -36
  235. package/lib/dependencies/HarmonyModulesPlugin.js +33 -5
  236. package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +15 -3
  237. package/lib/dependencies/ImportContextDependency.js +15 -2
  238. package/lib/dependencies/ImportDependency.js +50 -12
  239. package/lib/dependencies/ImportEagerDependency.js +11 -6
  240. package/lib/dependencies/ImportMetaContextDependency.js +42 -0
  241. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +301 -0
  242. package/lib/dependencies/ImportMetaContextPlugin.js +72 -0
  243. package/lib/dependencies/ImportMetaHotAcceptDependency.js +6 -0
  244. package/lib/dependencies/ImportMetaHotDeclineDependency.js +6 -0
  245. package/lib/dependencies/ImportMetaPlugin.js +128 -59
  246. package/lib/dependencies/ImportParserPlugin.js +153 -83
  247. package/lib/dependencies/ImportPlugin.js +21 -7
  248. package/lib/dependencies/ImportWeakDependency.js +11 -6
  249. package/lib/dependencies/JsonExportsDependency.js +38 -30
  250. package/lib/dependencies/LoaderDependency.js +14 -0
  251. package/lib/dependencies/LoaderImportDependency.js +14 -0
  252. package/lib/dependencies/LoaderPlugin.js +54 -40
  253. package/lib/dependencies/LocalModule.js +17 -1
  254. package/lib/dependencies/LocalModuleDependency.js +15 -0
  255. package/lib/dependencies/LocalModulesHelpers.js +22 -4
  256. package/lib/dependencies/ModuleDecoratorDependency.js +9 -1
  257. package/lib/dependencies/ModuleDependency.js +24 -7
  258. package/lib/dependencies/ModuleDependencyTemplateAsId.js +2 -1
  259. package/lib/dependencies/ModuleHotAcceptDependency.js +6 -0
  260. package/lib/dependencies/ModuleHotDeclineDependency.js +6 -0
  261. package/lib/dependencies/PrefetchDependency.js +3 -0
  262. package/lib/dependencies/ProvidedDependency.js +43 -8
  263. package/lib/dependencies/PureExpressionDependency.js +73 -39
  264. package/lib/dependencies/RequireContextDependency.js +6 -16
  265. package/lib/dependencies/RequireContextDependencyParserPlugin.js +14 -6
  266. package/lib/dependencies/RequireContextPlugin.js +20 -7
  267. package/lib/dependencies/RequireEnsureDependenciesBlock.js +7 -0
  268. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +29 -12
  269. package/lib/dependencies/RequireEnsureDependency.js +16 -2
  270. package/lib/dependencies/RequireEnsureItemDependency.js +3 -0
  271. package/lib/dependencies/RequireEnsurePlugin.js +27 -7
  272. package/lib/dependencies/RequireHeaderDependency.js +14 -1
  273. package/lib/dependencies/RequireIncludeDependency.js +6 -1
  274. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +29 -5
  275. package/lib/dependencies/RequireIncludePlugin.js +25 -5
  276. package/lib/dependencies/RequireResolveContextDependency.js +19 -2
  277. package/lib/dependencies/RequireResolveDependency.js +8 -1
  278. package/lib/dependencies/RequireResolveHeaderDependency.js +18 -0
  279. package/lib/dependencies/RuntimeRequirementsDependency.js +9 -1
  280. package/lib/dependencies/StaticExportsDependency.js +8 -0
  281. package/lib/dependencies/SystemPlugin.js +49 -22
  282. package/lib/dependencies/SystemRuntimeModule.js +1 -1
  283. package/lib/dependencies/URLDependency.js +20 -13
  284. package/lib/dependencies/URLPlugin.js +115 -27
  285. package/lib/dependencies/UnsupportedDependency.js +13 -0
  286. package/lib/dependencies/WebAssemblyExportImportedDependency.js +14 -0
  287. package/lib/dependencies/WebAssemblyImportDependency.js +9 -1
  288. package/lib/dependencies/WebpackIsIncludedDependency.js +6 -1
  289. package/lib/dependencies/WorkerDependency.js +47 -3
  290. package/lib/dependencies/WorkerPlugin.js +143 -59
  291. package/lib/dependencies/getFunctionExpression.js +9 -0
  292. package/lib/dependencies/processExportInfo.js +3 -1
  293. package/lib/electron/ElectronTargetPlugin.js +1 -0
  294. package/lib/esm/ExportWebpackRequireRuntimeModule.js +3 -2
  295. package/lib/esm/ModuleChunkFormatPlugin.js +92 -55
  296. package/lib/esm/ModuleChunkLoadingPlugin.js +12 -1
  297. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +141 -25
  298. package/lib/formatLocation.js +1 -2
  299. package/lib/hmr/HotModuleReplacement.runtime.js +37 -25
  300. package/lib/hmr/HotModuleReplacementRuntimeModule.js +2 -1
  301. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +13 -15
  302. package/lib/hmr/LazyCompilationPlugin.js +94 -41
  303. package/lib/hmr/lazyCompilationBackend.js +107 -44
  304. package/lib/ids/ChunkModuleIdRangePlugin.js +12 -3
  305. package/lib/ids/DeterministicChunkIdsPlugin.js +13 -6
  306. package/lib/ids/DeterministicModuleIdsPlugin.js +59 -35
  307. package/lib/ids/HashedModuleIdsPlugin.js +24 -16
  308. package/lib/ids/IdHelpers.js +59 -49
  309. package/lib/ids/NamedChunkIdsPlugin.js +13 -1
  310. package/lib/ids/NamedModuleIdsPlugin.js +20 -12
  311. package/lib/ids/NaturalModuleIdsPlugin.js +10 -13
  312. package/lib/ids/OccurrenceChunkIdsPlugin.js +6 -2
  313. package/lib/ids/OccurrenceModuleIdsPlugin.js +14 -11
  314. package/lib/ids/SyncModuleIdsPlugin.js +146 -0
  315. package/lib/index.js +44 -5
  316. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +9 -7
  317. package/lib/javascript/BasicEvaluatedExpression.js +133 -19
  318. package/lib/javascript/ChunkHelpers.js +33 -0
  319. package/lib/javascript/CommonJsChunkFormatPlugin.js +18 -15
  320. package/lib/javascript/EnableChunkLoadingPlugin.js +11 -6
  321. package/lib/javascript/JavascriptGenerator.js +37 -6
  322. package/lib/javascript/JavascriptModulesPlugin.js +523 -295
  323. package/lib/javascript/JavascriptParser.js +1591 -574
  324. package/lib/javascript/JavascriptParserHelpers.js +58 -37
  325. package/lib/javascript/StartupHelpers.js +69 -47
  326. package/lib/json/JsonData.js +33 -0
  327. package/lib/json/JsonGenerator.js +29 -21
  328. package/lib/json/JsonModulesPlugin.js +13 -7
  329. package/lib/json/JsonParser.js +30 -16
  330. package/lib/library/AbstractLibraryPlugin.js +6 -2
  331. package/lib/library/AmdLibraryPlugin.js +34 -18
  332. package/lib/library/AssignLibraryPlugin.js +68 -32
  333. package/lib/library/EnableLibraryPlugin.js +39 -14
  334. package/lib/library/ExportPropertyLibraryPlugin.js +14 -5
  335. package/lib/library/JsonpLibraryPlugin.js +4 -3
  336. package/lib/library/ModernModuleLibraryPlugin.js +144 -0
  337. package/lib/library/ModuleLibraryPlugin.js +12 -7
  338. package/lib/library/SystemLibraryPlugin.js +6 -4
  339. package/lib/library/UmdLibraryPlugin.js +119 -100
  340. package/lib/logging/Logger.js +59 -6
  341. package/lib/logging/createConsoleLogger.js +25 -40
  342. package/lib/logging/runtime.js +8 -9
  343. package/lib/logging/truncateArgs.js +9 -8
  344. package/lib/node/CommonJsChunkLoadingPlugin.js +18 -2
  345. package/lib/node/NodeEnvironmentPlugin.js +14 -8
  346. package/lib/node/NodeTargetPlugin.js +7 -0
  347. package/lib/node/NodeTemplatePlugin.js +10 -2
  348. package/lib/node/NodeWatchFileSystem.js +100 -50
  349. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +51 -26
  350. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +13 -2
  351. package/lib/node/ReadFileCompileWasmPlugin.js +21 -3
  352. package/lib/node/RequireChunkLoadingRuntimeModule.js +49 -26
  353. package/lib/node/nodeConsole.js +48 -31
  354. package/lib/optimize/AggressiveMergingPlugin.js +10 -4
  355. package/lib/optimize/AggressiveSplittingPlugin.js +26 -21
  356. package/lib/optimize/ConcatenatedModule.js +353 -212
  357. package/lib/optimize/EnsureChunkConditionsPlugin.js +4 -1
  358. package/lib/optimize/FlagIncludedChunksPlugin.js +14 -8
  359. package/lib/optimize/InnerGraph.js +30 -25
  360. package/lib/optimize/InnerGraphPlugin.js +105 -64
  361. package/lib/optimize/LimitChunkCountPlugin.js +32 -9
  362. package/lib/optimize/MangleExportsPlugin.js +7 -2
  363. package/lib/optimize/MinMaxSizeWarning.js +6 -1
  364. package/lib/optimize/ModuleConcatenationPlugin.js +150 -83
  365. package/lib/optimize/RealContentHashPlugin.js +99 -43
  366. package/lib/optimize/RemoveParentModulesPlugin.js +131 -48
  367. package/lib/optimize/RuntimeChunkPlugin.js +15 -2
  368. package/lib/optimize/SideEffectsFlagPlugin.js +119 -63
  369. package/lib/optimize/SplitChunksPlugin.js +129 -78
  370. package/lib/performance/SizeLimitsPlugin.js +22 -8
  371. package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +4 -2
  372. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +4 -1
  373. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +8 -5
  374. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +5 -3
  375. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +5 -3
  376. package/lib/rules/BasicEffectRulePlugin.js +7 -1
  377. package/lib/rules/BasicMatcherRulePlugin.js +8 -1
  378. package/lib/rules/ObjectMatcherRulePlugin.js +19 -2
  379. package/lib/rules/RuleSetCompiler.js +53 -32
  380. package/lib/rules/UseEffectRulePlugin.js +42 -36
  381. package/lib/runtime/AsyncModuleRuntimeModule.js +56 -69
  382. package/lib/runtime/AutoPublicPathRuntimeModule.js +25 -9
  383. package/lib/runtime/BaseUriRuntimeModule.js +35 -0
  384. package/lib/runtime/ChunkNameRuntimeModule.js +1 -1
  385. package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +5 -2
  386. package/lib/runtime/CompatRuntimeModule.js +7 -2
  387. package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +7 -4
  388. package/lib/runtime/CreateScriptRuntimeModule.js +38 -0
  389. package/lib/runtime/CreateScriptUrlRuntimeModule.js +13 -36
  390. package/lib/runtime/DefinePropertyGettersRuntimeModule.js +6 -3
  391. package/lib/runtime/EnsureChunkRuntimeModule.js +29 -15
  392. package/lib/runtime/GetChunkFilenameRuntimeModule.js +56 -43
  393. package/lib/runtime/GetFullHashRuntimeModule.js +4 -3
  394. package/lib/runtime/GetMainFilenameRuntimeModule.js +5 -2
  395. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +98 -0
  396. package/lib/runtime/GlobalRuntimeModule.js +1 -1
  397. package/lib/runtime/HasOwnPropertyRuntimeModule.js +5 -2
  398. package/lib/runtime/LoadScriptRuntimeModule.js +61 -45
  399. package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +5 -2
  400. package/lib/runtime/NonceRuntimeModule.js +24 -0
  401. package/lib/runtime/OnChunksLoadedRuntimeModule.js +4 -2
  402. package/lib/runtime/PublicPathRuntimeModule.js +9 -2
  403. package/lib/runtime/RelativeUrlRuntimeModule.js +5 -2
  404. package/lib/runtime/RuntimeIdRuntimeModule.js +6 -2
  405. package/lib/runtime/StartupChunkDependenciesPlugin.js +15 -0
  406. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +36 -28
  407. package/lib/runtime/StartupEntrypointRuntimeModule.js +13 -9
  408. package/lib/runtime/SystemContextRuntimeModule.js +1 -1
  409. package/lib/schemes/DataUriPlugin.js +16 -3
  410. package/lib/schemes/HttpUriPlugin.js +336 -120
  411. package/lib/serialization/ArraySerializer.js +22 -6
  412. package/lib/serialization/BinaryMiddleware.js +212 -33
  413. package/lib/serialization/DateObjectSerializer.js +16 -4
  414. package/lib/serialization/ErrorObjectSerializer.js +23 -6
  415. package/lib/serialization/FileMiddleware.js +187 -86
  416. package/lib/serialization/MapObjectSerializer.js +25 -8
  417. package/lib/serialization/NullPrototypeObjectSerializer.js +26 -8
  418. package/lib/serialization/ObjectMiddleware.js +96 -66
  419. package/lib/serialization/PlainObjectSerializer.js +51 -14
  420. package/lib/serialization/RegExpObjectSerializer.js +17 -5
  421. package/lib/serialization/Serializer.js +23 -5
  422. package/lib/serialization/SerializerMiddleware.js +8 -8
  423. package/lib/serialization/SetObjectSerializer.js +22 -6
  424. package/lib/serialization/SingleItemMiddleware.js +2 -2
  425. package/lib/serialization/types.js +2 -2
  426. package/lib/sharing/ConsumeSharedFallbackDependency.js +3 -0
  427. package/lib/sharing/ConsumeSharedModule.js +40 -17
  428. package/lib/sharing/ConsumeSharedPlugin.js +139 -102
  429. package/lib/sharing/ConsumeSharedRuntimeModule.js +144 -130
  430. package/lib/sharing/ProvideForSharedDependency.js +0 -1
  431. package/lib/sharing/ProvideSharedDependency.js +17 -0
  432. package/lib/sharing/ProvideSharedModule.js +19 -6
  433. package/lib/sharing/ProvideSharedModuleFactory.js +1 -1
  434. package/lib/sharing/ProvideSharedPlugin.js +37 -30
  435. package/lib/sharing/SharePlugin.js +2 -2
  436. package/lib/sharing/ShareRuntimeModule.js +20 -10
  437. package/lib/sharing/resolveMatchedConfigs.js +6 -5
  438. package/lib/sharing/utils.js +338 -34
  439. package/lib/stats/DefaultStatsFactoryPlugin.js +660 -396
  440. package/lib/stats/DefaultStatsPresetPlugin.js +85 -25
  441. package/lib/stats/DefaultStatsPrinterPlugin.js +525 -145
  442. package/lib/stats/StatsFactory.js +128 -57
  443. package/lib/stats/StatsPrinter.js +77 -46
  444. package/lib/util/ArrayHelpers.js +35 -1
  445. package/lib/util/ArrayQueue.js +15 -22
  446. package/lib/util/AsyncQueue.js +37 -16
  447. package/lib/util/IterableHelpers.js +3 -4
  448. package/lib/util/LazyBucketSortedSet.js +60 -44
  449. package/lib/util/LazySet.js +11 -2
  450. package/lib/util/MapHelpers.js +17 -5
  451. package/lib/util/ParallelismFactorCalculator.js +11 -1
  452. package/lib/util/Queue.js +9 -3
  453. package/lib/util/Semaphore.js +4 -7
  454. package/lib/util/SetHelpers.js +5 -5
  455. package/lib/util/SortableSet.js +19 -6
  456. package/lib/util/StackedCacheMap.js +33 -3
  457. package/lib/util/StackedMap.js +1 -3
  458. package/lib/util/StringXor.js +46 -0
  459. package/lib/util/TupleQueue.js +9 -3
  460. package/lib/util/TupleSet.js +15 -5
  461. package/lib/util/URLAbsoluteSpecifier.js +8 -8
  462. package/lib/util/WeakTupleMap.js +70 -28
  463. package/lib/util/binarySearchBounds.js +51 -9
  464. package/lib/util/chainedImports.js +97 -0
  465. package/lib/util/cleverMerge.js +51 -36
  466. package/lib/util/comparators.js +146 -83
  467. package/lib/util/compileBooleanMatcher.js +35 -7
  468. package/lib/util/conventions.js +126 -0
  469. package/lib/util/create-schema-validation.js +9 -2
  470. package/lib/util/createHash.js +49 -14
  471. package/lib/util/deprecation.js +48 -15
  472. package/lib/util/deterministicGrouping.js +71 -39
  473. package/lib/util/extractUrlAndGlobal.js +3 -0
  474. package/lib/util/findGraphRoots.js +7 -5
  475. package/lib/util/fs.js +419 -94
  476. package/lib/util/hash/BatchedHash.js +10 -4
  477. package/lib/util/hash/md4.js +20 -0
  478. package/lib/util/hash/wasm-hash.js +163 -0
  479. package/lib/util/hash/xxhash64.js +7 -141
  480. package/lib/util/identifier.js +140 -93
  481. package/lib/util/internalSerializables.js +22 -0
  482. package/lib/util/makeSerializable.js +7 -0
  483. package/lib/util/memoize.js +10 -10
  484. package/lib/util/mergeScope.js +76 -0
  485. package/lib/util/nonNumericOnlyHash.js +22 -0
  486. package/lib/util/numberHash.js +84 -34
  487. package/lib/util/objectToMap.js +0 -1
  488. package/lib/util/processAsyncTree.js +7 -1
  489. package/lib/util/propertyAccess.js +7 -55
  490. package/lib/util/propertyName.js +77 -0
  491. package/lib/util/registerExternalSerializer.js +2 -2
  492. package/lib/util/runtime.js +188 -133
  493. package/lib/util/semver.js +64 -56
  494. package/lib/util/serialization.js +26 -1
  495. package/lib/util/smartGrouping.js +10 -10
  496. package/lib/util/source.js +1 -1
  497. package/lib/validateSchema.js +6 -2
  498. package/lib/wasm/EnableWasmLoadingPlugin.js +9 -4
  499. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +70 -30
  500. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +9 -1
  501. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +34 -16
  502. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +32 -12
  503. package/lib/wasm-async/AsyncWebAssemblyParser.js +17 -4
  504. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +72 -31
  505. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +17 -6
  506. package/lib/wasm-sync/WebAssemblyGenerator.js +72 -52
  507. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +5 -4
  508. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +53 -43
  509. package/lib/wasm-sync/WebAssemblyParser.js +23 -9
  510. package/lib/wasm-sync/WebAssemblyUtils.js +5 -4
  511. package/lib/web/FetchCompileAsyncWasmPlugin.js +11 -1
  512. package/lib/web/FetchCompileWasmPlugin.js +59 -42
  513. package/lib/web/JsonpChunkLoadingPlugin.js +9 -0
  514. package/lib/web/JsonpChunkLoadingRuntimeModule.js +71 -41
  515. package/lib/webpack.js +43 -12
  516. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +15 -12
  517. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +55 -40
  518. package/module.d.ts +233 -0
  519. package/package.json +85 -139
  520. package/schemas/WebpackOptions.check.js +1 -1
  521. package/schemas/WebpackOptions.json +679 -47
  522. package/schemas/plugins/BannerPlugin.check.js +1 -1
  523. package/schemas/plugins/BannerPlugin.json +9 -1
  524. package/schemas/plugins/DllReferencePlugin.check.js +1 -1
  525. package/schemas/plugins/HashedModuleIdsPlugin.check.js +1 -1
  526. package/schemas/plugins/ProgressPlugin.check.js +1 -1
  527. package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
  528. package/schemas/plugins/SourceMapDevToolPlugin.json +4 -0
  529. package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
  530. package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.js +1 -1
  531. package/schemas/plugins/asset/AssetParserOptions.check.js +1 -1
  532. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
  533. package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
  534. package/schemas/plugins/container/ContainerPlugin.json +10 -1
  535. package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
  536. package/schemas/plugins/container/ContainerReferencePlugin.json +2 -0
  537. package/schemas/plugins/container/ExternalsType.check.js +1 -1
  538. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  539. package/schemas/plugins/container/ModuleFederationPlugin.json +12 -1
  540. package/schemas/plugins/css/CssAutoGeneratorOptions.check.d.ts +7 -0
  541. package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +6 -0
  542. package/schemas/plugins/css/CssAutoGeneratorOptions.json +3 -0
  543. package/schemas/plugins/css/CssAutoParserOptions.check.d.ts +7 -0
  544. package/schemas/plugins/css/CssAutoParserOptions.check.js +6 -0
  545. package/schemas/plugins/css/CssAutoParserOptions.json +3 -0
  546. package/schemas/plugins/css/CssGeneratorOptions.check.d.ts +7 -0
  547. package/schemas/plugins/css/CssGeneratorOptions.check.js +6 -0
  548. package/schemas/plugins/css/CssGeneratorOptions.json +3 -0
  549. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.d.ts +7 -0
  550. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +6 -0
  551. package/schemas/plugins/css/CssGlobalGeneratorOptions.json +3 -0
  552. package/schemas/plugins/css/CssGlobalParserOptions.check.d.ts +7 -0
  553. package/schemas/plugins/css/CssGlobalParserOptions.check.js +6 -0
  554. package/schemas/plugins/css/CssGlobalParserOptions.json +3 -0
  555. package/schemas/plugins/css/CssModuleGeneratorOptions.check.d.ts +7 -0
  556. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +6 -0
  557. package/schemas/plugins/css/CssModuleGeneratorOptions.json +3 -0
  558. package/schemas/plugins/css/CssModuleParserOptions.check.d.ts +7 -0
  559. package/schemas/plugins/css/CssModuleParserOptions.check.js +6 -0
  560. package/schemas/plugins/css/CssModuleParserOptions.json +3 -0
  561. package/schemas/plugins/css/CssParserOptions.check.d.ts +7 -0
  562. package/schemas/plugins/css/CssParserOptions.check.js +6 -0
  563. package/schemas/plugins/css/CssParserOptions.json +3 -0
  564. package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +1 -1
  565. package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +1 -1
  566. package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +1 -1
  567. package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
  568. package/schemas/plugins/schemes/HttpUriPlugin.json +4 -0
  569. package/schemas/plugins/sharing/SharePlugin.check.js +1 -1
  570. package/types.d.ts +5026 -1756
@@ -14,6 +14,8 @@ const { forEachRuntime } = require("./util/runtime");
14
14
  /** @typedef {import("./Module")} Module */
15
15
  /** @typedef {import("./ModuleGraph")} ModuleGraph */
16
16
  /** @typedef {import("./ModuleGraphConnection")} ModuleGraphConnection */
17
+ /** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
18
+ /** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
17
19
  /** @typedef {import("./util/Hash")} Hash */
18
20
 
19
21
  /** @typedef {typeof UsageState.OnlyPropertiesUsed | typeof UsageState.NoInfo | typeof UsageState.Unknown | typeof UsageState.Used} RuntimeUsageStateType */
@@ -44,6 +46,9 @@ class RestoreProvidedData {
44
46
  this.otherTerminalBinding = otherTerminalBinding;
45
47
  }
46
48
 
49
+ /**
50
+ * @param {ObjectSerializerContext} context context
51
+ */
47
52
  serialize({ write }) {
48
53
  write(this.exports);
49
54
  write(this.otherProvided);
@@ -51,6 +56,10 @@ class RestoreProvidedData {
51
56
  write(this.otherTerminalBinding);
52
57
  }
53
58
 
59
+ /**
60
+ * @param {ObjectDeserializerContext} context context
61
+ * @returns {RestoreProvidedData} RestoreProvidedData
62
+ */
54
63
  static deserialize({ read }) {
55
64
  return new RestoreProvidedData(read(), read(), read(), read());
56
65
  }
@@ -62,9 +71,12 @@ makeSerializable(
62
71
  "RestoreProvidedData"
63
72
  );
64
73
 
74
+ /** @typedef {Map<string, ExportInfo>} Exports */
75
+ /** @typedef {string | string[] | false} UsedName */
76
+
65
77
  class ExportsInfo {
66
78
  constructor() {
67
- /** @type {Map<string, ExportInfo>} */
79
+ /** @type {Exports} */
68
80
  this._exports = new Map();
69
81
  this._otherExportsInfo = new ExportInfo(null);
70
82
  this._sideEffectsOnlyInfo = new ExportInfo("*side effects only*");
@@ -135,6 +147,10 @@ class ExportsInfo {
135
147
  return this._otherExportsInfo;
136
148
  }
137
149
 
150
+ /**
151
+ * @param {Exports} exports exports
152
+ * @private
153
+ */
138
154
  _sortExportsMap(exports) {
139
155
  if (exports.size > 1) {
140
156
  const namesInOrder = [];
@@ -150,7 +166,7 @@ class ExportsInfo {
150
166
  }
151
167
  for (; i < namesInOrder.length; i++) {
152
168
  const name = namesInOrder[i];
153
- const correctEntry = exports.get(name);
169
+ const correctEntry = /** @type {ExportInfo} */ (exports.get(name));
154
170
  exports.delete(name);
155
171
  exports.set(name, correctEntry);
156
172
  }
@@ -162,6 +178,10 @@ class ExportsInfo {
162
178
  this._exportsAreOrdered = true;
163
179
  }
164
180
 
181
+ /**
182
+ * @param {ExportsInfo | undefined} exportsInfo exports info
183
+ * @returns {boolean} result
184
+ */
165
185
  setRedirectNamedTo(exportsInfo) {
166
186
  if (this._redirectTo === exportsInfo) return false;
167
187
  this._redirectTo = exportsInfo;
@@ -198,9 +218,6 @@ class ExportsInfo {
198
218
  this._redirectTo.setHasUseInfo();
199
219
  } else {
200
220
  this._otherExportsInfo.setHasUseInfo();
201
- if (this._otherExportsInfo.canMangleUse === undefined) {
202
- this._otherExportsInfo.canMangleUse = true;
203
- }
204
221
  }
205
222
  }
206
223
 
@@ -251,7 +268,7 @@ class ExportsInfo {
251
268
  getReadOnlyExportInfoRecursive(name) {
252
269
  const exportInfo = this.getReadOnlyExportInfo(name[0]);
253
270
  if (name.length === 1) return exportInfo;
254
- if (!exportInfo.exportsInfo) return undefined;
271
+ if (!exportInfo.exportsInfo) return;
255
272
  return exportInfo.exportsInfo.getReadOnlyExportInfoRecursive(name.slice(1));
256
273
  }
257
274
 
@@ -262,7 +279,7 @@ class ExportsInfo {
262
279
  getNestedExportsInfo(name) {
263
280
  if (Array.isArray(name) && name.length > 0) {
264
281
  const info = this.getReadOnlyExportInfo(name[0]);
265
- if (!info.exportsInfo) return undefined;
282
+ if (!info.exportsInfo) return;
266
283
  return info.exportsInfo.getNestedExportsInfo(name.slice(1));
267
284
  }
268
285
  return this;
@@ -291,17 +308,22 @@ class ExportsInfo {
291
308
  }
292
309
  }
293
310
  for (const exportInfo of this._exports.values()) {
311
+ if (!canMangle && exportInfo.canMangleProvide !== false) {
312
+ exportInfo.canMangleProvide = false;
313
+ changed = true;
314
+ }
294
315
  if (excludeExports && excludeExports.has(exportInfo.name)) continue;
295
316
  if (exportInfo.provided !== true && exportInfo.provided !== null) {
296
317
  exportInfo.provided = null;
297
318
  changed = true;
298
319
  }
299
- if (!canMangle && exportInfo.canMangleProvide !== false) {
300
- exportInfo.canMangleProvide = false;
301
- changed = true;
302
- }
303
320
  if (targetKey) {
304
- exportInfo.setTarget(targetKey, targetModule, [exportInfo.name], -1);
321
+ exportInfo.setTarget(
322
+ targetKey,
323
+ /** @type {ModuleGraphConnection} */ (targetModule),
324
+ [exportInfo.name],
325
+ -1
326
+ );
305
327
  }
306
328
  }
307
329
  if (this._redirectTo !== undefined) {
@@ -331,7 +353,7 @@ class ExportsInfo {
331
353
  if (targetKey) {
332
354
  this._otherExportsInfo.setTarget(
333
355
  targetKey,
334
- targetModule,
356
+ /** @type {ModuleGraphConnection} */ (targetModule),
335
357
  undefined,
336
358
  priority
337
359
  );
@@ -436,10 +458,8 @@ class ExportsInfo {
436
458
  if (this._redirectTo.isUsed(runtime)) {
437
459
  return true;
438
460
  }
439
- } else {
440
- if (this._otherExportsInfo.getUsed(runtime) !== UsageState.Unused) {
441
- return true;
442
- }
461
+ } else if (this._otherExportsInfo.getUsed(runtime) !== UsageState.Unused) {
462
+ return true;
443
463
  }
444
464
  for (const exportInfo of this._exports.values()) {
445
465
  if (exportInfo.getUsed(runtime) !== UsageState.Unused) {
@@ -465,6 +485,7 @@ class ExportsInfo {
465
485
  * @returns {SortableSet<string> | boolean | null} set of used exports, or true (when namespace object is used), or false (when unused), or null (when unknown)
466
486
  */
467
487
  getUsedExports(runtime) {
488
+ // eslint-disable-next-line no-constant-binary-expression
468
489
  if (!this._redirectTo !== undefined) {
469
490
  switch (this._otherExportsInfo.getUsed(runtime)) {
470
491
  case UsageState.NoInfo:
@@ -506,13 +527,14 @@ class ExportsInfo {
506
527
  return false;
507
528
  }
508
529
  }
509
- return new SortableSet(array);
530
+ return /** @type {SortableSet<string>} */ (new SortableSet(array));
510
531
  }
511
532
 
512
533
  /**
513
534
  * @returns {null | true | string[]} list of exports when known
514
535
  */
515
536
  getProvidedExports() {
537
+ // eslint-disable-next-line no-constant-binary-expression
516
538
  if (!this._redirectTo !== undefined) {
517
539
  switch (this._otherExportsInfo.provided) {
518
540
  case undefined:
@@ -584,7 +606,7 @@ class ExportsInfo {
584
606
  if (info.exportsInfo && name.length > 1) {
585
607
  return info.exportsInfo.isExportProvided(name.slice(1));
586
608
  }
587
- return info.provided;
609
+ return info.provided ? name.length === 1 || undefined : info.provided;
588
610
  }
589
611
  const info = this.getReadOnlyExportInfo(name);
590
612
  return info.provided;
@@ -616,13 +638,11 @@ class ExportsInfo {
616
638
  isEquallyUsed(runtimeA, runtimeB) {
617
639
  if (this._redirectTo !== undefined) {
618
640
  if (!this._redirectTo.isEquallyUsed(runtimeA, runtimeB)) return false;
619
- } else {
620
- if (
621
- this._otherExportsInfo.getUsed(runtimeA) !==
622
- this._otherExportsInfo.getUsed(runtimeB)
623
- ) {
624
- return false;
625
- }
641
+ } else if (
642
+ this._otherExportsInfo.getUsed(runtimeA) !==
643
+ this._otherExportsInfo.getUsed(runtimeB)
644
+ ) {
645
+ return false;
626
646
  }
627
647
  if (
628
648
  this._sideEffectsOnlyInfo.getUsed(runtimeA) !==
@@ -645,20 +665,20 @@ class ExportsInfo {
645
665
  getUsed(name, runtime) {
646
666
  if (Array.isArray(name)) {
647
667
  if (name.length === 0) return this.otherExportsInfo.getUsed(runtime);
648
- let info = this.getReadOnlyExportInfo(name[0]);
668
+ const info = this.getReadOnlyExportInfo(name[0]);
649
669
  if (info.exportsInfo && name.length > 1) {
650
670
  return info.exportsInfo.getUsed(name.slice(1), runtime);
651
671
  }
652
672
  return info.getUsed(runtime);
653
673
  }
654
- let info = this.getReadOnlyExportInfo(name);
674
+ const info = this.getReadOnlyExportInfo(name);
655
675
  return info.getUsed(runtime);
656
676
  }
657
677
 
658
678
  /**
659
679
  * @param {string | string[]} name the export name
660
680
  * @param {RuntimeSpec} runtime check usage for this runtime only
661
- * @returns {string | string[] | false} the used name
681
+ * @returns {UsedName} the used name
662
682
  */
663
683
  getUsedName(name, runtime) {
664
684
  if (Array.isArray(name)) {
@@ -667,10 +687,12 @@ class ExportsInfo {
667
687
  if (!this.isUsed(runtime)) return false;
668
688
  return name;
669
689
  }
670
- let info = this.getReadOnlyExportInfo(name[0]);
690
+ const info = this.getReadOnlyExportInfo(name[0]);
671
691
  const x = info.getUsedName(name[0], runtime);
672
692
  if (x === false) return false;
673
- const arr = x === name[0] && name.length === 1 ? name : [x];
693
+ const arr =
694
+ /** @type {string[]} */
695
+ (x === name[0] && name.length === 1 ? name : [x]);
674
696
  if (name.length === 1) {
675
697
  return arr;
676
698
  }
@@ -681,14 +703,12 @@ class ExportsInfo {
681
703
  const nested = info.exportsInfo.getUsedName(name.slice(1), runtime);
682
704
  if (!nested) return false;
683
705
  return arr.concat(nested);
684
- } else {
685
- return arr.concat(name.slice(1));
686
706
  }
687
- } else {
688
- let info = this.getReadOnlyExportInfo(name);
689
- const usedName = info.getUsedName(name, runtime);
690
- return usedName;
707
+ return arr.concat(name.slice(1));
691
708
  }
709
+ const info = this.getReadOnlyExportInfo(name);
710
+ const usedName = info.getUsedName(name, runtime);
711
+ return usedName;
692
712
  }
693
713
 
694
714
  /**
@@ -721,6 +741,9 @@ class ExportsInfo {
721
741
  }
722
742
  }
723
743
 
744
+ /**
745
+ * @returns {RestoreProvidedData} restore provided data
746
+ */
724
747
  getRestoreProvidedData() {
725
748
  const otherProvided = this._otherExportsInfo.provided;
726
749
  const otherCanMangleProvide = this._otherExportsInfo.canMangleProvide;
@@ -739,7 +762,8 @@ class ExportsInfo {
739
762
  canMangleProvide: exportInfo.canMangleProvide,
740
763
  terminalBinding: exportInfo.terminalBinding,
741
764
  exportsInfo: exportInfo.exportsInfoOwned
742
- ? exportInfo.exportsInfo.getRestoreProvidedData()
765
+ ? /** @type {NonNullable<ExportInfo["exportsInfo"]>} */
766
+ (exportInfo.exportsInfo).getRestoreProvidedData()
743
767
  : undefined
744
768
  });
745
769
  }
@@ -752,6 +776,9 @@ class ExportsInfo {
752
776
  );
753
777
  }
754
778
 
779
+ /**
780
+ * @param {{ otherProvided: any, otherCanMangleProvide: any, otherTerminalBinding: any, exports: any }} data data
781
+ */
755
782
  restoreProvided({
756
783
  otherProvided,
757
784
  otherCanMangleProvide,
@@ -782,6 +809,10 @@ class ExportsInfo {
782
809
  }
783
810
  }
784
811
 
812
+ /** @typedef {{ module: Module, export: string[] }} TargetItemWithoutConnection */
813
+ /** @typedef {{ module: Module, connection: ModuleGraphConnection, export: string[] | undefined }} TargetItem */
814
+ /** @typedef {Map<any, { connection: ModuleGraphConnection | null, export: string[], priority: number }>} Target */
815
+
785
816
  class ExportInfo {
786
817
  /**
787
818
  * @param {string} name the original name of the export
@@ -790,16 +821,28 @@ class ExportInfo {
790
821
  constructor(name, initFrom) {
791
822
  /** @type {string} */
792
823
  this.name = name;
793
- /** @private @type {string | null} */
824
+ /**
825
+ * @private
826
+ * @type {string | null}
827
+ */
794
828
  this._usedName = initFrom ? initFrom._usedName : null;
795
- /** @private @type {UsageStateType} */
829
+ /**
830
+ * @private
831
+ * @type {UsageStateType | undefined}
832
+ */
796
833
  this._globalUsed = initFrom ? initFrom._globalUsed : undefined;
797
- /** @private @type {Map<string, RuntimeUsageStateType>} */
834
+ /**
835
+ * @private
836
+ * @type {Map<string, RuntimeUsageStateType>}
837
+ */
798
838
  this._usedInRuntime =
799
839
  initFrom && initFrom._usedInRuntime
800
840
  ? new Map(initFrom._usedInRuntime)
801
841
  : undefined;
802
- /** @private @type {boolean} */
842
+ /**
843
+ * @private
844
+ * @type {boolean}
845
+ */
803
846
  this._hasUseInRuntimeInfo = initFrom
804
847
  ? initFrom._hasUseInRuntimeInfo
805
848
  : false;
@@ -832,9 +875,9 @@ class ExportInfo {
832
875
  this.canMangleUse = initFrom ? initFrom.canMangleUse : undefined;
833
876
  /** @type {boolean} */
834
877
  this.exportsInfoOwned = false;
835
- /** @type {ExportsInfo=} */
878
+ /** @type {ExportsInfo | undefined} */
836
879
  this.exportsInfo = undefined;
837
- /** @type {Map<any, { connection: ModuleGraphConnection | null, export: string[], priority: number }>=} */
880
+ /** @type {Target | undefined} */
838
881
  this._target = undefined;
839
882
  if (initFrom && initFrom._target) {
840
883
  this._target = new Map();
@@ -846,19 +889,11 @@ class ExportInfo {
846
889
  });
847
890
  }
848
891
  }
849
- /** @type {Map<any, { connection: ModuleGraphConnection | null, export: string[], priority: number }>=} */
892
+ /** @type {Target | undefined} */
850
893
  this._maxTarget = undefined;
851
894
  }
852
895
 
853
896
  // TODO webpack 5 remove
854
- /** @private */
855
- get used() {
856
- throw new Error("REMOVED");
857
- }
858
- /** @private */
859
- get usedName() {
860
- throw new Error("REMOVED");
861
- }
862
897
  /**
863
898
  * @private
864
899
  * @param {*} v v
@@ -866,6 +901,14 @@ class ExportInfo {
866
901
  set used(v) {
867
902
  throw new Error("REMOVED");
868
903
  }
904
+
905
+ // TODO webpack 5 remove
906
+ /** @private */
907
+ get used() {
908
+ throw new Error("REMOVED");
909
+ }
910
+
911
+ // TODO webpack 5 remove
869
912
  /**
870
913
  * @private
871
914
  * @param {*} v v
@@ -874,6 +917,12 @@ class ExportInfo {
874
917
  throw new Error("REMOVED");
875
918
  }
876
919
 
920
+ // TODO webpack 5 remove
921
+ /** @private */
922
+ get usedName() {
923
+ throw new Error("REMOVED");
924
+ }
925
+
877
926
  get canMangle() {
878
927
  switch (this.canMangleProvide) {
879
928
  case undefined:
@@ -941,7 +990,8 @@ class ExportInfo {
941
990
  this.canMangleUse = true;
942
991
  }
943
992
  if (this.exportsInfoOwned) {
944
- this.exportsInfo.setHasUseInfo();
993
+ /** @type {ExportsInfo} */
994
+ (this.exportsInfo).setHasUseInfo();
945
995
  }
946
996
  }
947
997
 
@@ -956,25 +1006,26 @@ class ExportInfo {
956
1006
  if (this._globalUsed === undefined) {
957
1007
  this._globalUsed = newValue;
958
1008
  return true;
959
- } else {
960
- if (this._globalUsed !== newValue && condition(this._globalUsed)) {
961
- this._globalUsed = newValue;
962
- return true;
963
- }
1009
+ }
1010
+ if (this._globalUsed !== newValue && condition(this._globalUsed)) {
1011
+ this._globalUsed = newValue;
1012
+ return true;
964
1013
  }
965
1014
  } else if (this._usedInRuntime === undefined) {
966
1015
  if (newValue !== UsageState.Unused && condition(UsageState.Unused)) {
967
1016
  this._usedInRuntime = new Map();
968
1017
  forEachRuntime(runtime, runtime =>
969
- this._usedInRuntime.set(runtime, newValue)
1018
+ this._usedInRuntime.set(/** @type {string} */ (runtime), newValue)
970
1019
  );
971
1020
  return true;
972
1021
  }
973
1022
  } else {
974
1023
  let changed = false;
975
- forEachRuntime(runtime, runtime => {
976
- /** @type {UsageStateType} */
977
- let oldValue = this._usedInRuntime.get(runtime);
1024
+ forEachRuntime(runtime, _runtime => {
1025
+ const runtime = /** @type {string} */ (_runtime);
1026
+ let oldValue =
1027
+ /** @type {UsageStateType} */
1028
+ (this._usedInRuntime.get(runtime));
978
1029
  if (oldValue === undefined) oldValue = UsageState.Unused;
979
1030
  if (newValue !== oldValue && condition(oldValue)) {
980
1031
  if (newValue === UsageState.Unused) {
@@ -1008,15 +1059,17 @@ class ExportInfo {
1008
1059
  if (newValue !== UsageState.Unused) {
1009
1060
  this._usedInRuntime = new Map();
1010
1061
  forEachRuntime(runtime, runtime =>
1011
- this._usedInRuntime.set(runtime, newValue)
1062
+ this._usedInRuntime.set(/** @type {string} */ (runtime), newValue)
1012
1063
  );
1013
1064
  return true;
1014
1065
  }
1015
1066
  } else {
1016
1067
  let changed = false;
1017
- forEachRuntime(runtime, runtime => {
1018
- /** @type {UsageStateType} */
1019
- let oldValue = this._usedInRuntime.get(runtime);
1068
+ forEachRuntime(runtime, _runtime => {
1069
+ const runtime = /** @type {string} */ (_runtime);
1070
+ let oldValue =
1071
+ /** @type {UsageStateType} */
1072
+ (this._usedInRuntime.get(runtime));
1020
1073
  if (oldValue === undefined) oldValue = UsageState.Unused;
1021
1074
  if (newValue !== oldValue) {
1022
1075
  if (newValue === UsageState.Unused) {
@@ -1051,7 +1104,7 @@ class ExportInfo {
1051
1104
  /**
1052
1105
  * @param {any} key the key
1053
1106
  * @param {ModuleGraphConnection} connection the target module if a single one
1054
- * @param {string[]=} exportName the exported name
1107
+ * @param {(string[] | null)=} exportName the exported name
1055
1108
  * @param {number=} priority priority
1056
1109
  * @returns {boolean} true, if something has changed
1057
1110
  */
@@ -1059,13 +1112,21 @@ class ExportInfo {
1059
1112
  if (exportName) exportName = [...exportName];
1060
1113
  if (!this._target) {
1061
1114
  this._target = new Map();
1062
- this._target.set(key, { connection, export: exportName, priority });
1115
+ this._target.set(key, {
1116
+ connection,
1117
+ export: /** @type {string[]} */ (exportName),
1118
+ priority
1119
+ });
1063
1120
  return true;
1064
1121
  }
1065
1122
  const oldTarget = this._target.get(key);
1066
1123
  if (!oldTarget) {
1067
1124
  if (oldTarget === null && !connection) return false;
1068
- this._target.set(key, { connection, export: exportName, priority });
1125
+ this._target.set(key, {
1126
+ connection,
1127
+ export: /** @type {string[]} */ (exportName),
1128
+ priority
1129
+ });
1069
1130
  this._maxTarget = undefined;
1070
1131
  return true;
1071
1132
  }
@@ -1077,7 +1138,7 @@ class ExportInfo {
1077
1138
  : oldTarget.export)
1078
1139
  ) {
1079
1140
  oldTarget.connection = connection;
1080
- oldTarget.export = exportName;
1141
+ oldTarget.export = /** @type {string[]} */ (exportName);
1081
1142
  oldTarget.priority = priority;
1082
1143
  this._maxTarget = undefined;
1083
1144
  return true;
@@ -1107,20 +1168,20 @@ class ExportInfo {
1107
1168
  if (max < value) max = value;
1108
1169
  }
1109
1170
  return max;
1110
- } else {
1111
- /** @type {UsageStateType} */
1112
- let max = UsageState.Unused;
1113
- for (const item of runtime) {
1114
- const value = this._usedInRuntime.get(item);
1115
- if (value !== undefined) {
1116
- if (value === UsageState.Used) {
1117
- return UsageState.Used;
1118
- }
1119
- if (max < value) max = value;
1171
+ }
1172
+
1173
+ /** @type {UsageStateType} */
1174
+ let max = UsageState.Unused;
1175
+ for (const item of runtime) {
1176
+ const value = this._usedInRuntime.get(item);
1177
+ if (value !== undefined) {
1178
+ if (value === UsageState.Used) {
1179
+ return UsageState.Used;
1120
1180
  }
1181
+ if (max < value) max = value;
1121
1182
  }
1122
- return max;
1123
1183
  }
1184
+ return max;
1124
1185
  }
1125
1186
 
1126
1187
  /**
@@ -1139,19 +1200,18 @@ class ExportInfo {
1139
1200
  if (!this._usedInRuntime.has(runtime)) {
1140
1201
  return false;
1141
1202
  }
1142
- } else if (runtime !== undefined) {
1143
- if (
1144
- Array.from(runtime).every(
1145
- runtime => !this._usedInRuntime.has(runtime)
1146
- )
1147
- ) {
1148
- return false;
1149
- }
1203
+ } else if (
1204
+ runtime !== undefined &&
1205
+ Array.from(runtime).every(
1206
+ runtime => !this._usedInRuntime.has(runtime)
1207
+ )
1208
+ ) {
1209
+ return false;
1150
1210
  }
1151
1211
  }
1152
1212
  }
1153
1213
  if (this._usedName !== null) return this._usedName;
1154
- return this.name || fallbackName;
1214
+ return /** @type {string | false} */ (this.name || fallbackName);
1155
1215
  }
1156
1216
 
1157
1217
  /**
@@ -1172,13 +1232,13 @@ class ExportInfo {
1172
1232
 
1173
1233
  /**
1174
1234
  * @param {ModuleGraph} moduleGraph the module graph
1175
- * @param {function({ module: Module, export: string[] | undefined }): boolean} resolveTargetFilter filter function to further resolve target
1235
+ * @param {function(TargetItem): boolean} resolveTargetFilter filter function to further resolve target
1176
1236
  * @returns {ExportInfo | ExportsInfo | undefined} the terminal binding export(s) info if known
1177
1237
  */
1178
1238
  getTerminalBinding(moduleGraph, resolveTargetFilter = RETURNS_TRUE) {
1179
1239
  if (this.terminalBinding) return this;
1180
1240
  const target = this.getTarget(moduleGraph, resolveTargetFilter);
1181
- if (!target) return undefined;
1241
+ if (!target) return;
1182
1242
  const exportsInfo = moduleGraph.getExportsInfo(target.module);
1183
1243
  if (!target.export) return exportsInfo;
1184
1244
  return exportsInfo.getReadOnlyExportInfoRecursive(target.export);
@@ -1190,10 +1250,11 @@ class ExportInfo {
1190
1250
 
1191
1251
  _getMaxTarget() {
1192
1252
  if (this._maxTarget !== undefined) return this._maxTarget;
1193
- if (this._target.size <= 1) return (this._maxTarget = this._target);
1253
+ if (/** @type {Target} */ (this._target).size <= 1)
1254
+ return (this._maxTarget = this._target);
1194
1255
  let maxPriority = -Infinity;
1195
1256
  let minPriority = Infinity;
1196
- for (const { priority } of this._target.values()) {
1257
+ for (const { priority } of /** @type {Target} */ (this._target).values()) {
1197
1258
  if (maxPriority < priority) maxPriority = priority;
1198
1259
  if (minPriority > priority) minPriority = priority;
1199
1260
  }
@@ -1202,7 +1263,7 @@ class ExportInfo {
1202
1263
 
1203
1264
  // This is an edge case
1204
1265
  const map = new Map();
1205
- for (const [key, value] of this._target) {
1266
+ for (const [key, value] of /** @type {Target} */ (this._target)) {
1206
1267
  if (maxPriority === value.priority) {
1207
1268
  map.set(key, value);
1208
1269
  }
@@ -1214,7 +1275,7 @@ class ExportInfo {
1214
1275
  /**
1215
1276
  * @param {ModuleGraph} moduleGraph the module graph
1216
1277
  * @param {function(Module): boolean} validTargetModuleFilter a valid target module
1217
- * @returns {{ module: Module, export: string[] | undefined } | undefined | false} the target, undefined when there is no target, false when no target is valid
1278
+ * @returns {TargetItemWithoutConnection | null | undefined | false} the target, undefined when there is no target, false when no target is valid
1218
1279
  */
1219
1280
  findTarget(moduleGraph, validTargetModuleFilter) {
1220
1281
  return this._findTarget(moduleGraph, validTargetModuleFilter, new Set());
@@ -1223,14 +1284,16 @@ class ExportInfo {
1223
1284
  /**
1224
1285
  * @param {ModuleGraph} moduleGraph the module graph
1225
1286
  * @param {function(Module): boolean} validTargetModuleFilter a valid target module
1226
- * @param {Set<ExportInfo> | undefined} alreadyVisited set of already visited export info to avoid circular references
1227
- * @returns {{ module: Module, export: string[] | undefined } | undefined | false} the target, undefined when there is no target, false when no target is valid
1287
+ * @param {Set<ExportInfo>} alreadyVisited set of already visited export info to avoid circular references
1288
+ * @returns {TargetItemWithoutConnection | null | undefined | false} the target, undefined when there is no target, false when no target is valid
1228
1289
  */
1229
1290
  _findTarget(moduleGraph, validTargetModuleFilter, alreadyVisited) {
1230
- if (!this._target || this._target.size === 0) return undefined;
1231
- let rawTarget = this._getMaxTarget().values().next().value;
1232
- if (!rawTarget) return undefined;
1233
- /** @type {{ module: Module, export: string[] | undefined }} */
1291
+ if (!this._target || this._target.size === 0) return;
1292
+ const rawTarget =
1293
+ /** @type {Target} */
1294
+ (this._getMaxTarget()).values().next().value;
1295
+ if (!rawTarget) return;
1296
+ /** @type {TargetItemWithoutConnection} */
1234
1297
  let target = {
1235
1298
  module: rawTarget.connection.module,
1236
1299
  export: rawTarget.export
@@ -1261,26 +1324,26 @@ class ExportInfo {
1261
1324
 
1262
1325
  /**
1263
1326
  * @param {ModuleGraph} moduleGraph the module graph
1264
- * @param {function({ module: Module, export: string[] | undefined }): boolean} resolveTargetFilter filter function to further resolve target
1265
- * @returns {{ module: Module, export: string[] | undefined } | undefined} the target
1327
+ * @param {function(TargetItem): boolean} resolveTargetFilter filter function to further resolve target
1328
+ * @returns {TargetItem | undefined} the target
1266
1329
  */
1267
1330
  getTarget(moduleGraph, resolveTargetFilter = RETURNS_TRUE) {
1268
1331
  const result = this._getTarget(moduleGraph, resolveTargetFilter, undefined);
1269
- if (result === CIRCULAR) return undefined;
1332
+ if (result === CIRCULAR) return;
1270
1333
  return result;
1271
1334
  }
1272
1335
 
1273
1336
  /**
1274
1337
  * @param {ModuleGraph} moduleGraph the module graph
1275
- * @param {function({ module: Module, connection: ModuleGraphConnection, export: string[] | undefined }): boolean} resolveTargetFilter filter function to further resolve target
1338
+ * @param {function(TargetItem): boolean} resolveTargetFilter filter function to further resolve target
1276
1339
  * @param {Set<ExportInfo> | undefined} alreadyVisited set of already visited export info to avoid circular references
1277
- * @returns {{ module: Module, connection: ModuleGraphConnection, export: string[] | undefined } | CIRCULAR | undefined} the target
1340
+ * @returns {TargetItem | CIRCULAR | undefined} the target
1278
1341
  */
1279
1342
  _getTarget(moduleGraph, resolveTargetFilter, alreadyVisited) {
1280
1343
  /**
1281
- * @param {{ connection: ModuleGraphConnection, export: string[] | undefined } | null} inputTarget unresolved target
1344
+ * @param {TargetItem | null} inputTarget unresolved target
1282
1345
  * @param {Set<ExportInfo>} alreadyVisited set of already visited export info to avoid circular references
1283
- * @returns {{ module: Module, connection: ModuleGraphConnection, export: string[] | undefined } | CIRCULAR | null} resolved target
1346
+ * @returns {TargetItem | CIRCULAR | null} resolved target
1284
1347
  */
1285
1348
  const resolveTarget = (inputTarget, alreadyVisited) => {
1286
1349
  if (!inputTarget) return null;
@@ -1291,7 +1354,7 @@ class ExportInfo {
1291
1354
  export: undefined
1292
1355
  };
1293
1356
  }
1294
- /** @type {{ module: Module, connection: ModuleGraphConnection, export: string[] | undefined }} */
1357
+ /** @type {TargetItem} */
1295
1358
  let target = {
1296
1359
  module: inputTarget.connection.module,
1297
1360
  connection: inputTarget.connection,
@@ -1301,7 +1364,10 @@ class ExportInfo {
1301
1364
  let alreadyVisitedOwned = false;
1302
1365
  for (;;) {
1303
1366
  const exportsInfo = moduleGraph.getExportsInfo(target.module);
1304
- const exportInfo = exportsInfo.getExportInfo(target.export[0]);
1367
+ const exportInfo = exportsInfo.getExportInfo(
1368
+ /** @type {NonNullable<TargetItem["export"]>} */
1369
+ (target.export)[0]
1370
+ );
1305
1371
  if (!exportInfo) return target;
1306
1372
  if (alreadyVisited.has(exportInfo)) return CIRCULAR;
1307
1373
  const newTarget = exportInfo._getTarget(
@@ -1311,7 +1377,10 @@ class ExportInfo {
1311
1377
  );
1312
1378
  if (newTarget === CIRCULAR) return CIRCULAR;
1313
1379
  if (!newTarget) return target;
1314
- if (target.export.length === 1) {
1380
+ if (
1381
+ /** @type {NonNullable<TargetItem["export"]>} */
1382
+ (target.export).length === 1
1383
+ ) {
1315
1384
  target = newTarget;
1316
1385
  if (!target.export) return target;
1317
1386
  } else {
@@ -1319,8 +1388,12 @@ class ExportInfo {
1319
1388
  module: newTarget.module,
1320
1389
  connection: newTarget.connection,
1321
1390
  export: newTarget.export
1322
- ? newTarget.export.concat(target.export.slice(1))
1323
- : target.export.slice(1)
1391
+ ? newTarget.export.concat(
1392
+ /** @type {NonNullable<TargetItem["export"]>} */
1393
+ (target.export).slice(1)
1394
+ )
1395
+ : /** @type {NonNullable<TargetItem["export"]>} */
1396
+ (target.export).slice(1)
1324
1397
  };
1325
1398
  }
1326
1399
  if (!resolveTargetFilter(target)) return target;
@@ -1332,22 +1405,26 @@ class ExportInfo {
1332
1405
  }
1333
1406
  };
1334
1407
 
1335
- if (!this._target || this._target.size === 0) return undefined;
1408
+ if (!this._target || this._target.size === 0) return;
1336
1409
  if (alreadyVisited && alreadyVisited.has(this)) return CIRCULAR;
1337
1410
  const newAlreadyVisited = new Set(alreadyVisited);
1338
1411
  newAlreadyVisited.add(this);
1339
- const values = this._getMaxTarget().values();
1412
+ const values = /** @type {Target} */ (this._getMaxTarget()).values();
1340
1413
  const target = resolveTarget(values.next().value, newAlreadyVisited);
1341
1414
  if (target === CIRCULAR) return CIRCULAR;
1342
- if (target === null) return undefined;
1415
+ if (target === null) return;
1343
1416
  let result = values.next();
1344
1417
  while (!result.done) {
1345
1418
  const t = resolveTarget(result.value, newAlreadyVisited);
1346
1419
  if (t === CIRCULAR) return CIRCULAR;
1347
- if (t === null) return undefined;
1348
- if (t.module !== target.module) return undefined;
1349
- if (!t.export !== !target.export) return undefined;
1350
- if (target.export && !equals(t.export, target.export)) return undefined;
1420
+ if (t === null) return;
1421
+ if (t.module !== target.module) return;
1422
+ if (!t.export !== !target.export) return;
1423
+ if (
1424
+ target.export &&
1425
+ !equals(/** @type {ArrayLike<string>} */ (t.export), target.export)
1426
+ )
1427
+ return;
1351
1428
  result = values.next();
1352
1429
  }
1353
1430
  return target;
@@ -1356,34 +1433,42 @@ class ExportInfo {
1356
1433
  /**
1357
1434
  * Move the target forward as long resolveTargetFilter is fulfilled
1358
1435
  * @param {ModuleGraph} moduleGraph the module graph
1359
- * @param {function({ module: Module, export: string[] | undefined }): boolean} resolveTargetFilter filter function to further resolve target
1360
- * @param {function({ module: Module, export: string[] | undefined }): ModuleGraphConnection=} updateOriginalConnection updates the original connection instead of using the target connection
1361
- * @returns {{ module: Module, export: string[] | undefined } | undefined} the resolved target when moved
1436
+ * @param {function(TargetItem): boolean} resolveTargetFilter filter function to further resolve target
1437
+ * @param {function(TargetItem): ModuleGraphConnection=} updateOriginalConnection updates the original connection instead of using the target connection
1438
+ * @returns {TargetItem | undefined} the resolved target when moved
1362
1439
  */
1363
1440
  moveTarget(moduleGraph, resolveTargetFilter, updateOriginalConnection) {
1364
1441
  const target = this._getTarget(moduleGraph, resolveTargetFilter, undefined);
1365
- if (target === CIRCULAR) return undefined;
1366
- if (!target) return undefined;
1367
- const originalTarget = this._getMaxTarget().values().next().value;
1442
+ if (target === CIRCULAR) return;
1443
+ if (!target) return;
1444
+ const originalTarget =
1445
+ /** @type {Target} */
1446
+ (this._getMaxTarget()).values().next().value;
1368
1447
  if (
1369
1448
  originalTarget.connection === target.connection &&
1370
1449
  originalTarget.export === target.export
1371
1450
  ) {
1372
- return undefined;
1451
+ return;
1373
1452
  }
1374
- this._target.clear();
1375
- this._target.set(undefined, {
1453
+ /** @type {Target} */
1454
+ (this._target).clear();
1455
+ /** @type {Target} */
1456
+ (this._target).set(undefined, {
1376
1457
  connection: updateOriginalConnection
1377
1458
  ? updateOriginalConnection(target)
1378
1459
  : target.connection,
1379
- export: target.export,
1460
+ export: /** @type {NonNullable<TargetItem["export"]>} */ (target.export),
1380
1461
  priority: 0
1381
1462
  });
1382
1463
  return target;
1383
1464
  }
1384
1465
 
1466
+ /**
1467
+ * @returns {ExportsInfo} an exports info
1468
+ */
1385
1469
  createNestedExportsInfo() {
1386
- if (this.exportsInfoOwned) return this.exportsInfo;
1470
+ if (this.exportsInfoOwned)
1471
+ return /** @type {ExportsInfo} */ (this.exportsInfo);
1387
1472
  this.exportsInfoOwned = true;
1388
1473
  const oldExportsInfo = this.exportsInfo;
1389
1474
  this.exportsInfo = new ExportsInfo();
@@ -1398,6 +1483,11 @@ class ExportInfo {
1398
1483
  return this.exportsInfo;
1399
1484
  }
1400
1485
 
1486
+ /**
1487
+ * @param {ExportInfo} baseInfo base info
1488
+ * @param {RuntimeSpec} runtime runtime
1489
+ * @returns {boolean} true when has info, otherwise false
1490
+ */
1401
1491
  hasInfo(baseInfo, runtime) {
1402
1492
  return (
1403
1493
  (this._usedName && this._usedName !== this.name) ||
@@ -1407,10 +1497,20 @@ class ExportInfo {
1407
1497
  );
1408
1498
  }
1409
1499
 
1500
+ /**
1501
+ * @param {Hash} hash the hash
1502
+ * @param {RuntimeSpec} runtime the runtime
1503
+ * @returns {void}
1504
+ */
1410
1505
  updateHash(hash, runtime) {
1411
1506
  this._updateHash(hash, runtime, new Set());
1412
1507
  }
1413
1508
 
1509
+ /**
1510
+ * @param {Hash} hash the hash
1511
+ * @param {RuntimeSpec} runtime the runtime
1512
+ * @param {Set<ExportsInfo>} alreadyVisitedExportsInfo for circular references
1513
+ */
1414
1514
  _updateHash(hash, runtime, alreadyVisitedExportsInfo) {
1415
1515
  hash.update(
1416
1516
  `${this._usedName || this.name}${this.getUsed(runtime)}${this.provided}${
@@ -1444,6 +1544,7 @@ class ExportInfo {
1444
1544
  if (list !== undefined) list.push(runtime);
1445
1545
  else map.set(used, [runtime]);
1446
1546
  }
1547
+ // eslint-disable-next-line array-callback-return
1447
1548
  const specificInfo = Array.from(map, ([used, runtimes]) => {
1448
1549
  switch (used) {
1449
1550
  case UsageState.NoInfo: