webpack 5.107.2 → 5.108.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 (357) hide show
  1. package/hot/dev-server.js +2 -0
  2. package/lib/APIPlugin.js +8 -4
  3. package/lib/CacheFacade.js +7 -0
  4. package/lib/Chunk.js +4 -0
  5. package/lib/ChunkGraph.js +30 -9
  6. package/lib/CircularModulesPlugin.js +190 -0
  7. package/lib/CleanPlugin.js +2 -1
  8. package/lib/Compilation.js +396 -65
  9. package/lib/Compiler.js +25 -11
  10. package/lib/ConcatenationScope.js +10 -3
  11. package/lib/ContextExclusionPlugin.js +1 -0
  12. package/lib/ContextModule.js +92 -47
  13. package/lib/ContextReplacementPlugin.js +4 -0
  14. package/lib/DefinePlugin.js +89 -15
  15. package/lib/Dependency.js +111 -7
  16. package/lib/EntryOptionPlugin.js +39 -2
  17. package/lib/EntryPlugin.js +2 -0
  18. package/lib/ExportsInfo.js +314 -73
  19. package/lib/ExternalModule.js +82 -34
  20. package/lib/ExternalModuleFactoryPlugin.js +1 -0
  21. package/lib/ExternalsPlugin.js +1 -0
  22. package/lib/FileSystemInfo.js +173 -23
  23. package/lib/FlagAllModulesAsUsedPlugin.js +1 -5
  24. package/lib/FlagDependencyExportsPlugin.js +23 -0
  25. package/lib/FlagDependencyUsagePlugin.js +87 -5
  26. package/lib/FlagEntryExportAsUsedPlugin.js +2 -0
  27. package/lib/Generator.js +8 -0
  28. package/lib/HotModuleReplacementPlugin.js +65 -28
  29. package/lib/IgnorePlugin.js +1 -0
  30. package/lib/InitFragment.js +5 -0
  31. package/lib/JavascriptMetaInfoPlugin.js +7 -5
  32. package/lib/LazyBarrel.js +361 -0
  33. package/lib/LoaderTargetPlugin.js +1 -0
  34. package/lib/Module.js +21 -42
  35. package/lib/ModuleGraph.js +3 -2
  36. package/lib/ModuleProfile.js +27 -1
  37. package/lib/ModuleTemplate.js +2 -0
  38. package/lib/MultiCompiler.js +2 -0
  39. package/lib/MultiStats.js +1 -0
  40. package/lib/MultiWatching.js +2 -0
  41. package/lib/NodeStuffPlugin.js +22 -17
  42. package/lib/NormalModule.js +142 -80
  43. package/lib/NormalModuleReplacementPlugin.js +2 -0
  44. package/lib/PrefetchPlugin.js +2 -0
  45. package/lib/ProgressPlugin.js +8 -0
  46. package/lib/ProvidePlugin.js +1 -0
  47. package/lib/RawModule.js +20 -16
  48. package/lib/RecordIdsPlugin.js +1 -0
  49. package/lib/RuntimeGlobals.js +5 -0
  50. package/lib/RuntimePlugin.js +58 -26
  51. package/lib/RuntimeTemplate.js +278 -21
  52. package/lib/SelfModuleFactory.js +1 -0
  53. package/lib/SourceMapDevToolPlugin.js +3 -5
  54. package/lib/Stats.js +1 -0
  55. package/lib/Template.js +8 -2
  56. package/lib/TemplatedPathPlugin.js +473 -131
  57. package/lib/WarnCaseSensitiveModulesPlugin.js +1 -0
  58. package/lib/WarnDeprecatedOptionPlugin.js +4 -0
  59. package/lib/WarnNoModeSetPlugin.js +1 -0
  60. package/lib/WatchIgnorePlugin.js +1 -0
  61. package/lib/Watching.js +9 -0
  62. package/lib/WebpackOptionsApply.js +50 -5
  63. package/lib/asset/AssetBytesGenerator.js +11 -3
  64. package/lib/asset/AssetGenerator.js +47 -22
  65. package/lib/asset/AssetModule.js +47 -0
  66. package/lib/asset/AssetModulesPlugin.js +14 -14
  67. package/lib/asset/AssetParser.js +2 -2
  68. package/lib/asset/AssetSourceGenerator.js +8 -0
  69. package/lib/asset/RawDataUrlModule.js +12 -13
  70. package/lib/buildChunkGraph.js +64 -7
  71. package/lib/bun/BunTargetPlugin.js +48 -0
  72. package/lib/cache/AddBuildDependenciesPlugin.js +1 -0
  73. package/lib/cache/AddManagedPathsPlugin.js +3 -0
  74. package/lib/cache/IdleFileCachePlugin.js +4 -0
  75. package/lib/cache/MemoryWithGcCachePlugin.js +1 -0
  76. package/lib/cache/PackFileCacheStrategy.js +1 -0
  77. package/lib/cache/ResolverCachePlugin.js +2 -0
  78. package/lib/cache/mergeEtags.js +2 -0
  79. package/lib/cli.js +109 -19
  80. package/lib/config/browserslistTargetHandler.js +99 -0
  81. package/lib/config/defaults.js +147 -7
  82. package/lib/config/defineConfig.js +31 -0
  83. package/lib/config/normalization.js +5 -0
  84. package/lib/config/target.js +181 -2
  85. package/lib/container/ContainerEntryModule.js +15 -14
  86. package/lib/container/ContainerExposedDependency.js +2 -2
  87. package/lib/container/ContainerReferencePlugin.js +1 -1
  88. package/lib/container/FallbackDependency.js +5 -7
  89. package/lib/container/FallbackModule.js +10 -9
  90. package/lib/container/RemoteModule.js +20 -10
  91. package/lib/container/RemoteRuntimeModule.js +14 -12
  92. package/lib/css/CssGenerator.js +353 -327
  93. package/lib/css/CssInjectStyleRuntimeModule.js +36 -8
  94. package/lib/css/CssLoadingRuntimeModule.js +118 -47
  95. package/lib/css/CssModule.js +52 -23
  96. package/lib/css/CssModulesPlugin.js +107 -124
  97. package/lib/css/CssParser.js +2759 -2205
  98. package/lib/css/syntax.js +2859 -0
  99. package/lib/debug/ProfilingPlugin.js +2 -0
  100. package/lib/deno/DenoTargetPlugin.js +47 -0
  101. package/lib/dependencies/AMDDefineDependency.js +22 -17
  102. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +1 -0
  103. package/lib/dependencies/AMDRequireArrayDependency.js +7 -11
  104. package/lib/dependencies/AMDRequireContextDependency.js +7 -11
  105. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +1 -0
  106. package/lib/dependencies/AMDRequireDependency.js +24 -20
  107. package/lib/dependencies/CachedConstDependency.js +3 -0
  108. package/lib/dependencies/CommonJsDependencyHelpers.js +1 -0
  109. package/lib/dependencies/CommonJsExportRequireDependency.js +79 -31
  110. package/lib/dependencies/CommonJsExportsDependency.js +21 -16
  111. package/lib/dependencies/CommonJsExportsParserPlugin.js +230 -7
  112. package/lib/dependencies/CommonJsFullRequireDependency.js +27 -19
  113. package/lib/dependencies/CommonJsImportsParserPlugin.js +51 -16
  114. package/lib/dependencies/CommonJsPlugin.js +1 -1
  115. package/lib/dependencies/CommonJsRequireContextDependency.js +10 -13
  116. package/lib/dependencies/CommonJsRequireDependency.js +42 -11
  117. package/lib/dependencies/CommonJsSelfReferenceDependency.js +22 -14
  118. package/lib/dependencies/ConstDependency.js +16 -11
  119. package/lib/dependencies/ContextDependency.js +4 -0
  120. package/lib/dependencies/ContextDependencyTemplateAsId.js +1 -1
  121. package/lib/dependencies/ContextElementDependency.js +23 -14
  122. package/lib/dependencies/CreateRequireParserPlugin.js +1 -0
  123. package/lib/dependencies/CreateScriptUrlDependency.js +5 -7
  124. package/lib/dependencies/CriticalDependencyWarning.js +1 -0
  125. package/lib/dependencies/CssIcssExportDependency.js +512 -574
  126. package/lib/dependencies/CssIcssImportDependency.js +9 -9
  127. package/lib/dependencies/CssIcssSymbolDependency.js +22 -15
  128. package/lib/dependencies/CssImportDependency.js +25 -1
  129. package/lib/dependencies/CssUrlDependency.js +23 -14
  130. package/lib/dependencies/DllEntryDependency.js +9 -13
  131. package/lib/dependencies/ExportBindingInitFragment.js +164 -0
  132. package/lib/dependencies/ExportsInfoDependency.js +12 -12
  133. package/lib/dependencies/ExternalModuleDependency.js +8 -5
  134. package/lib/dependencies/ExternalModuleInitFragment.js +7 -5
  135. package/lib/dependencies/ExternalModuleInitFragmentDependency.js +13 -10
  136. package/lib/dependencies/HarmonyAcceptDependency.js +11 -11
  137. package/lib/dependencies/HarmonyAcceptImportDependency.js +1 -0
  138. package/lib/dependencies/HarmonyDetectionParserPlugin.js +47 -22
  139. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +28 -2
  140. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +46 -22
  141. package/lib/dependencies/HarmonyExportExpressionDependency.js +107 -30
  142. package/lib/dependencies/HarmonyExportHeaderDependency.js +7 -9
  143. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +109 -31
  144. package/lib/dependencies/HarmonyExportInitFragment.js +18 -15
  145. package/lib/dependencies/HarmonyExportSpecifierDependency.js +83 -18
  146. package/lib/dependencies/HarmonyExports.js +4 -1
  147. package/lib/dependencies/HarmonyImportDependency.js +24 -0
  148. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +110 -74
  149. package/lib/dependencies/HarmonyImportGuard.js +254 -0
  150. package/lib/dependencies/HarmonyImportSideEffectDependency.js +18 -1
  151. package/lib/dependencies/HarmonyImportSpecifierDependency.js +118 -14
  152. package/lib/dependencies/HarmonyLinkingError.js +1 -0
  153. package/lib/dependencies/HarmonyModulesPlugin.js +1 -0
  154. package/lib/dependencies/{HtmlScriptSrcDependency.js → HtmlEntryDependency.js} +261 -109
  155. package/lib/dependencies/HtmlInlineHtmlDependency.js +107 -0
  156. package/lib/dependencies/HtmlInlineScriptDependency.js +17 -13
  157. package/lib/dependencies/HtmlInlineStyleDependency.js +45 -11
  158. package/lib/dependencies/ImportContextDependency.js +5 -9
  159. package/lib/dependencies/ImportDependency.js +44 -2
  160. package/lib/dependencies/ImportMetaHotAcceptDependency.js +1 -0
  161. package/lib/dependencies/ImportMetaHotDeclineDependency.js +1 -0
  162. package/lib/dependencies/ImportMetaPlugin.js +74 -30
  163. package/lib/dependencies/ImportParserPlugin.js +19 -0
  164. package/lib/dependencies/ImportWeakDependency.js +1 -0
  165. package/lib/dependencies/JsonExportsDependency.js +9 -9
  166. package/lib/dependencies/LoaderImportDependency.js +1 -0
  167. package/lib/dependencies/LocalModule.js +11 -12
  168. package/lib/dependencies/LocalModuleDependency.js +11 -13
  169. package/lib/dependencies/ModuleDecoratorDependency.js +9 -9
  170. package/lib/dependencies/ModuleDependency.js +7 -0
  171. package/lib/dependencies/ModuleHotAcceptDependency.js +1 -0
  172. package/lib/dependencies/ModuleHotDeclineDependency.js +1 -0
  173. package/lib/dependencies/ModuleInitFragmentDependency.js +15 -11
  174. package/lib/dependencies/ProvidedDependency.js +31 -27
  175. package/lib/dependencies/PureExpressionDependency.js +7 -9
  176. package/lib/dependencies/RequireEnsureDependency.js +12 -13
  177. package/lib/dependencies/RequireHeaderDependency.js +3 -4
  178. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +3 -0
  179. package/lib/dependencies/RequireResolveContextDependency.js +7 -11
  180. package/lib/dependencies/RequireResolveDependency.js +1 -0
  181. package/lib/dependencies/RequireResolveHeaderDependency.js +3 -5
  182. package/lib/dependencies/RuntimeRequirementsDependency.js +6 -7
  183. package/lib/dependencies/StaticExportsDependency.js +10 -10
  184. package/lib/dependencies/SystemPlugin.js +2 -0
  185. package/lib/dependencies/URLContextDependency.js +5 -7
  186. package/lib/dependencies/URLDependency.js +14 -16
  187. package/lib/dependencies/UnsupportedDependency.js +8 -13
  188. package/lib/dependencies/WebAssemblyExportImportedDependency.js +11 -16
  189. package/lib/dependencies/WebAssemblyImportDependency.js +14 -16
  190. package/lib/dependencies/WebpackIsIncludedDependency.js +1 -0
  191. package/lib/dependencies/WorkerDependency.js +19 -8
  192. package/lib/dependencies/WorkerPlugin.js +22 -6
  193. package/lib/dependencies/processExportInfo.js +13 -11
  194. package/lib/dll/DelegatedModule.js +29 -15
  195. package/lib/dll/DelegatedModuleFactoryPlugin.js +1 -0
  196. package/lib/dll/DelegatedPlugin.js +1 -0
  197. package/lib/dll/DllEntryPlugin.js +3 -0
  198. package/lib/dll/DllModule.js +3 -2
  199. package/lib/dll/DllPlugin.js +16 -0
  200. package/lib/dll/DllReferencePlugin.js +3 -0
  201. package/lib/dll/LibManifestPlugin.js +1 -0
  202. package/lib/electron/ElectronTargetPlugin.js +22 -4
  203. package/lib/errors/ConcurrentCompilationError.js +1 -0
  204. package/lib/errors/HookWebpackError.js +11 -13
  205. package/lib/errors/IgnoreErrorModuleFactory.js +1 -0
  206. package/lib/errors/InvalidDependenciesModuleWarning.js +2 -0
  207. package/lib/errors/JSONParseError.js +9 -8
  208. package/lib/errors/ModuleBuildError.js +16 -13
  209. package/lib/errors/ModuleDependencyError.js +8 -1
  210. package/lib/errors/ModuleDependencyWarning.js +8 -1
  211. package/lib/errors/ModuleError.js +5 -11
  212. package/lib/errors/ModuleHashingError.js +4 -0
  213. package/lib/errors/ModuleNotFoundError.js +3 -0
  214. package/lib/errors/ModuleParseError.js +5 -11
  215. package/lib/errors/ModuleRestoreError.js +2 -0
  216. package/lib/errors/ModuleStoreError.js +3 -0
  217. package/lib/errors/ModuleWarning.js +7 -11
  218. package/lib/errors/NodeStuffInWebError.js +1 -0
  219. package/lib/errors/NonErrorEmittedError.js +2 -0
  220. package/lib/errors/UnhandledSchemeError.js +1 -0
  221. package/lib/esm/ModuleChunkLoadingPlugin.js +0 -1
  222. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +28 -23
  223. package/lib/hmr/HotModuleReplacement.runtime.js +175 -30
  224. package/lib/hmr/HotModuleReplacementRuntimeModule.js +7 -0
  225. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +173 -26
  226. package/lib/hmr/LazyCompilationPlugin.js +30 -6
  227. package/lib/html/HtmlGenerator.js +217 -23
  228. package/lib/html/HtmlModule.js +40 -0
  229. package/lib/html/HtmlModulesPlugin.js +219 -55
  230. package/lib/html/HtmlParser.js +1108 -1099
  231. package/lib/html/{walkHtmlTokens.js → syntax.js} +4701 -212
  232. package/lib/ids/IdHelpers.js +4 -2
  233. package/lib/index.js +19 -0
  234. package/lib/javascript/BasicEvaluatedExpression.js +1 -0
  235. package/lib/javascript/EnableChunkLoadingPlugin.js +1 -0
  236. package/lib/javascript/JavascriptGenerator.js +6 -2
  237. package/lib/javascript/JavascriptModule.js +54 -0
  238. package/lib/javascript/JavascriptModulesPlugin.js +257 -102
  239. package/lib/javascript/JavascriptParser.js +285 -158
  240. package/lib/json/JsonModule.js +40 -0
  241. package/lib/json/JsonModulesPlugin.js +7 -0
  242. package/lib/json/JsonParser.js +4 -2
  243. package/lib/library/AssignLibraryPlugin.js +5 -3
  244. package/lib/library/ExportPropertyLibraryPlugin.js +1 -0
  245. package/lib/library/FalseIIFEUmdWarning.js +1 -0
  246. package/lib/library/ModuleLibraryPlugin.js +24 -5
  247. package/lib/library/SystemLibraryPlugin.js +3 -3
  248. package/lib/node/NodeTargetPlugin.js +1 -0
  249. package/lib/node/NodeWatchFileSystem.js +1 -0
  250. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +10 -9
  251. package/lib/node/RequireChunkLoadingRuntimeModule.js +18 -16
  252. package/lib/optimize/ConcatenatedModule.js +395 -77
  253. package/lib/optimize/ConstExportsPlugin.js +211 -0
  254. package/lib/optimize/InlineExports.js +178 -0
  255. package/lib/optimize/InnerGraph.js +372 -275
  256. package/lib/optimize/InnerGraphPlugin.js +196 -99
  257. package/lib/optimize/ModuleConcatenationPlugin.js +56 -25
  258. package/lib/optimize/RealContentHashPlugin.js +14 -1
  259. package/lib/optimize/SideEffectsFlagPlugin.js +234 -64
  260. package/lib/runtime/AsyncModuleRuntimeModule.js +32 -30
  261. package/lib/runtime/AutoPublicPathRuntimeModule.js +11 -5
  262. package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +1 -1
  263. package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +6 -4
  264. package/lib/runtime/DefinePropertyGettersRuntimeModule.js +33 -4
  265. package/lib/runtime/GetChunkFilenameRuntimeModule.js +82 -3
  266. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +1 -1
  267. package/lib/runtime/HasOwnPropertyRuntimeModule.js +1 -1
  268. package/lib/runtime/LoadScriptRuntimeModule.js +18 -13
  269. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +39 -26
  270. package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +1 -1
  271. package/lib/runtime/OnChunksLoadedRuntimeModule.js +4 -4
  272. package/lib/runtime/RelativeUrlRuntimeModule.js +3 -2
  273. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +1 -1
  274. package/lib/runtime/StartupEntrypointRuntimeModule.js +4 -3
  275. package/lib/runtime/WorkerRuntimeModule.js +33 -0
  276. package/lib/schemes/HttpUriPlugin.js +3 -2
  277. package/lib/serialization/AggregateErrorSerializer.js +7 -6
  278. package/lib/serialization/ArraySerializer.js +4 -8
  279. package/lib/serialization/BinaryMiddleware.js +538 -468
  280. package/lib/serialization/DateObjectSerializer.js +2 -2
  281. package/lib/serialization/ErrorObjectSerializer.js +7 -6
  282. package/lib/serialization/MapObjectSerializer.js +5 -9
  283. package/lib/serialization/NullPrototypeObjectSerializer.js +7 -9
  284. package/lib/serialization/ObjectMiddleware.js +50 -13
  285. package/lib/serialization/PlainObjectSerializer.js +9 -8
  286. package/lib/serialization/RegExpObjectSerializer.js +2 -2
  287. package/lib/serialization/Serializer.js +1 -0
  288. package/lib/serialization/SetObjectSerializer.js +4 -8
  289. package/lib/sharing/ConsumeSharedModule.js +6 -7
  290. package/lib/sharing/ConsumeSharedPlugin.js +1 -0
  291. package/lib/sharing/ConsumeSharedRuntimeModule.js +46 -41
  292. package/lib/sharing/ProvideSharedDependency.js +30 -15
  293. package/lib/sharing/ProvideSharedModule.js +30 -11
  294. package/lib/sharing/ProvideSharedPlugin.js +4 -2
  295. package/lib/sharing/SharePlugin.js +3 -0
  296. package/lib/sharing/ShareRuntimeModule.js +18 -16
  297. package/lib/sharing/resolveMatchedConfigs.js +2 -1
  298. package/lib/sharing/utils.js +1 -1
  299. package/lib/stats/DefaultStatsFactoryPlugin.js +4 -6
  300. package/lib/stats/DefaultStatsPrinterPlugin.js +14 -14
  301. package/lib/stats/StatsFactory.js +11 -9
  302. package/lib/stats/StatsPrinter.js +9 -2
  303. package/lib/url/URLParserPlugin.js +5 -2
  304. package/lib/util/AsyncQueue.js +10 -0
  305. package/lib/util/LazyBucketSortedSet.js +5 -0
  306. package/lib/util/LazySet.js +6 -4
  307. package/lib/util/LocConverter.js +11 -1
  308. package/lib/util/Semaphore.js +1 -0
  309. package/lib/util/SourceProcessor.js +106 -0
  310. package/lib/util/TupleSet.js +1 -0
  311. package/lib/util/WeakTupleMap.js +27 -1
  312. package/lib/util/chainedImports.js +3 -3
  313. package/lib/util/comparators.js +2 -2
  314. package/lib/util/concatenate.js +31 -7
  315. package/lib/util/createHash.js +0 -1
  316. package/lib/util/deterministicGrouping.js +19 -12
  317. package/lib/util/extractSourceMap.js +1 -1
  318. package/lib/util/findGraphRoots.js +2 -0
  319. package/lib/util/fs.js +10 -5
  320. package/lib/util/hash/DebugHash.js +1 -0
  321. package/lib/util/hash/hash-digest.js +24 -15
  322. package/lib/util/identifier.js +7 -0
  323. package/lib/util/internalSerializables.js +11 -2
  324. package/lib/util/magicComment.js +42 -0
  325. package/lib/util/makeSerializable.js +1 -0
  326. package/lib/util/nonNumericOnlyHash.js +30 -1
  327. package/lib/util/property.js +7 -1
  328. package/lib/util/publicPathPlaceholder.js +64 -0
  329. package/lib/util/registerExternalSerializer.js +4 -4
  330. package/lib/wasm-async/AsyncWasmModule.js +77 -0
  331. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +1 -1
  332. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +1 -96
  333. package/lib/wasm-async/AsyncWebAssemblyParser.js +1 -1
  334. package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +1 -1
  335. package/lib/wasm-sync/SyncWasmModule.js +39 -0
  336. package/lib/wasm-sync/UnsupportedWebAssemblyFeatureError.js +1 -0
  337. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +6 -3
  338. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +2 -1
  339. package/lib/wasm-sync/WebAssemblyGenerator.js +1 -0
  340. package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +2 -0
  341. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +10 -0
  342. package/lib/wasm-sync/WebAssemblyParser.js +7 -3
  343. package/lib/web/JsonpChunkLoadingRuntimeModule.js +45 -39
  344. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +11 -10
  345. package/package.json +35 -27
  346. package/schemas/WebpackOptions.check.js +1 -1
  347. package/schemas/WebpackOptions.json +212 -3
  348. package/schemas/plugins/HtmlGeneratorOptions.check.js +1 -1
  349. package/schemas/plugins/HtmlParserOptions.check.d.ts +7 -0
  350. package/schemas/plugins/HtmlParserOptions.check.js +6 -0
  351. package/schemas/plugins/HtmlParserOptions.json +3 -0
  352. package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.js +1 -1
  353. package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
  354. package/schemas/plugins/css/CssParserOptions.check.js +1 -1
  355. package/types.d.ts +1456 -290
  356. package/lib/css/walkCssTokens.js +0 -2020
  357. package/lib/util/AppendOnlyStackedSet.js +0 -93
@@ -1689,8 +1689,8 @@ class DefaultStatsPrinterPlugin {
1689
1689
  Object.keys(COMPILATION_SIMPLE_PRINTERS)
1690
1690
  )) {
1691
1691
  stats.hooks.print.for(key).tap(PLUGIN_NAME, (obj, ctx) =>
1692
- /** @type {EXPECTED_ANY} */
1693
- (COMPILATION_SIMPLE_PRINTERS)[key](
1692
+ /** @type {NonNullable<CompilationSimplePrinters[keyof CompilationSimplePrinters]>} */
1693
+ (COMPILATION_SIMPLE_PRINTERS[key])(
1694
1694
  obj,
1695
1695
  /** @type {DefineStatsPrinterContext<"compilation">} */
1696
1696
  (ctx),
@@ -1717,8 +1717,8 @@ class DefaultStatsPrinterPlugin {
1717
1717
  Object.keys(MODULE_SIMPLE_PRINTERS)
1718
1718
  )) {
1719
1719
  stats.hooks.print.for(key).tap(PLUGIN_NAME, (obj, ctx) =>
1720
- /** @type {EXPECTED_ANY} */
1721
- (MODULE_SIMPLE_PRINTERS)[key](
1720
+ /** @type {SimplePrinter<EXPECTED_ANY, "module">} */
1721
+ (MODULE_SIMPLE_PRINTERS[key])(
1722
1722
  obj,
1723
1723
  /** @type {DefineStatsPrinterContext<"module">} */
1724
1724
  (ctx),
@@ -1745,8 +1745,8 @@ class DefaultStatsPrinterPlugin {
1745
1745
  Object.keys(MODULE_REASON_PRINTERS)
1746
1746
  )) {
1747
1747
  stats.hooks.print.for(key).tap(PLUGIN_NAME, (obj, ctx) =>
1748
- /** @type {EXPECTED_ANY} */
1749
- (MODULE_REASON_PRINTERS)[key](
1748
+ /** @type {SimplePrinter<EXPECTED_ANY, "moduleReason">} */
1749
+ (MODULE_REASON_PRINTERS[key])(
1750
1750
  obj,
1751
1751
  /** @type {DefineStatsPrinterContext<"moduleReason">} */
1752
1752
  (ctx),
@@ -1773,8 +1773,8 @@ class DefaultStatsPrinterPlugin {
1773
1773
  Object.keys(CHUNK_GROUP_PRINTERS)
1774
1774
  )) {
1775
1775
  stats.hooks.print.for(key).tap(PLUGIN_NAME, (obj, ctx) =>
1776
- /** @type {EXPECTED_ANY} */
1777
- (CHUNK_GROUP_PRINTERS)[key](
1776
+ /** @type {SimplePrinter<EXPECTED_ANY, "chunkGroupKind" | "chunkGroup">} */
1777
+ (CHUNK_GROUP_PRINTERS[key])(
1778
1778
  obj,
1779
1779
  /** @type {DefineStatsPrinterContext<"chunkGroupKind" | "chunkGroup">} */
1780
1780
  (ctx),
@@ -1787,8 +1787,8 @@ class DefaultStatsPrinterPlugin {
1787
1787
  Object.keys(CHUNK_PRINTERS)
1788
1788
  )) {
1789
1789
  stats.hooks.print.for(key).tap(PLUGIN_NAME, (obj, ctx) =>
1790
- /** @type {EXPECTED_ANY} */
1791
- (CHUNK_PRINTERS)[key](
1790
+ /** @type {SimplePrinter<EXPECTED_ANY, "chunk">} */
1791
+ (CHUNK_PRINTERS[key])(
1792
1792
  obj,
1793
1793
  /** @type {DefineStatsPrinterContext<"chunk">} */
1794
1794
  (ctx),
@@ -1801,8 +1801,8 @@ class DefaultStatsPrinterPlugin {
1801
1801
  Object.keys(ERROR_PRINTERS)
1802
1802
  )) {
1803
1803
  stats.hooks.print.for(key).tap(PLUGIN_NAME, (obj, ctx) =>
1804
- /** @type {EXPECTED_ANY} */
1805
- (ERROR_PRINTERS)[key](
1804
+ /** @type {SimplePrinter<EXPECTED_ANY, "error">} */
1805
+ (ERROR_PRINTERS[key])(
1806
1806
  obj,
1807
1807
  /** @type {DefineStatsPrinterContext<"error">} */
1808
1808
  (ctx),
@@ -1815,8 +1815,8 @@ class DefaultStatsPrinterPlugin {
1815
1815
  Object.keys(LOG_ENTRY_PRINTERS)
1816
1816
  )) {
1817
1817
  stats.hooks.print.for(key).tap(PLUGIN_NAME, (obj, ctx) =>
1818
- /** @type {EXPECTED_ANY} */
1819
- (LOG_ENTRY_PRINTERS)[key](
1818
+ /** @type {SimplePrinter<EXPECTED_ANY, "logging">} */
1819
+ (LOG_ENTRY_PRINTERS[key])(
1820
1820
  obj,
1821
1821
  /** @type {DefineStatsPrinterContext<"logging">} */
1822
1822
  (ctx),
@@ -131,10 +131,11 @@ class StatsFactory {
131
131
  });
132
132
  const hooks = this.hooks;
133
133
  this._caches =
134
- /** @type {{ [Key in keyof StatsFactoryHooks]: Map<string, SyncBailHook<EXPECTED_ANY, EXPECTED_ANY>[]> }} */ ({});
134
+ /** @type {{ [Key in keyof StatsFactoryHooks]: StatsFactoryHooks[Key] extends HookMap<infer H> ? Map<string, H[]> : never }} */ ({});
135
135
  for (const key of Object.keys(hooks)) {
136
136
  this._caches[/** @type {keyof StatsFactoryHooks} */ (key)] = new Map();
137
137
  }
138
+ /** @type {boolean} */
138
139
  this._inCreate = false;
139
140
  }
140
141
 
@@ -169,7 +170,7 @@ class StatsFactory {
169
170
  * Returns hook.
170
171
  * @template {StatsFactoryHooks[keyof StatsFactoryHooks]} HM
171
172
  * @template {HM extends HookMap<infer H> ? H : never} H
172
- * @template {H extends import("tapable").Hook<EXPECTED_ANY, infer R> ? R : never} R
173
+ * @template {H extends import("tapable").Hook<infer A, infer R> ? R : never} R
173
174
  * @param {HM} hookMap hook map
174
175
  * @param {Caches<H>} cache cache
175
176
  * @param {string} type type
@@ -188,12 +189,13 @@ class StatsFactory {
188
189
  * For each level waterfall.
189
190
  * @template {StatsFactoryHooks[keyof StatsFactoryHooks]} HM
190
191
  * @template {HM extends HookMap<infer H> ? H : never} H
192
+ * @template [D=EXPECTED_ANY]
191
193
  * @param {HM} hookMap hook map
192
194
  * @param {Caches<H>} cache cache
193
195
  * @param {string} type type
194
- * @param {FactoryData} data data
195
- * @param {(hook: H, factoryData: FactoryData) => FactoryData} fn fn
196
- * @returns {FactoryData} data
196
+ * @param {D} data data
197
+ * @param {(hook: H, data: D) => D} fn fn
198
+ * @returns {D} data
197
199
  * @private
198
200
  */
199
201
  _forEachLevelWaterfall(hookMap, cache, type, data, fn) {
@@ -207,14 +209,14 @@ class StatsFactory {
207
209
  * For each level filter.
208
210
  * @template {StatsFactoryHooks[keyof StatsFactoryHooks]} T
209
211
  * @template {T extends HookMap<infer H> ? H : never} H
210
- * @template {H extends import("tapable").Hook<EXPECTED_ANY, infer R> ? R : never} R
212
+ * @template [D=EXPECTED_ANY]
211
213
  * @param {T} hookMap hook map
212
214
  * @param {Caches<H>} cache cache
213
215
  * @param {string} type type
214
- * @param {FactoryData[]} items items
215
- * @param {(hook: H, item: R, idx: number, i: number) => R | undefined} fn fn
216
+ * @param {D[]} items items
217
+ * @param {(hook: H, item: D, idx: number, i: number) => boolean | void} fn fn
216
218
  * @param {boolean} forceClone force clone
217
- * @returns {R[]} result for each level
219
+ * @returns {D[]} result for each level
218
220
  * @private
219
221
  */
220
222
  _forEachLevelFilter(hookMap, cache, type, items, fn, forceClone) {
@@ -73,6 +73,12 @@ const { HookMap, SyncBailHook, SyncWaterfallHook } = require("tapable");
73
73
  * @property {(message: string) => string=} formatError
74
74
  */
75
75
 
76
+ /**
77
+ * Extracts the inner hook type held by a `HookMap`.
78
+ * @template T
79
+ * @typedef {T extends HookMap<infer H> ? H : never} HookMapHook
80
+ */
81
+
76
82
  /** @typedef {KnownStatsPrinterColorFunctions & KnownStatsPrinterFormatters & KnownStatsPrinterContext & Record<string, EXPECTED_ANY>} StatsPrinterContext */
77
83
  /** @typedef {StatsPrinterContext & Required<KnownStatsPrinterColorFunctions> & Required<KnownStatsPrinterFormatters> & { type: string }} StatsPrinterContextWithExtra */
78
84
  /** @typedef {EXPECTED_ANY} PrintObject */
@@ -107,8 +113,9 @@ class StatsPrinter {
107
113
  print: new HookMap(() => new SyncBailHook(["object", "context"])),
108
114
  result: new HookMap(() => new SyncWaterfallHook(["result", "context"]))
109
115
  });
110
- /** @type {Map<StatsPrintHooks[keyof StatsPrintHooks], Map<string, import("tapable").Hook<EXPECTED_ANY, EXPECTED_ANY>[]>>} */
116
+ /** @type {Map<StatsPrintHooks[keyof StatsPrintHooks], Map<string, HookMapHook<StatsPrintHooks[keyof StatsPrintHooks]>[]>>} */
111
117
  this._levelHookCache = new Map();
118
+ /** @type {boolean} */
112
119
  this._inPrint = false;
113
120
  }
114
121
 
@@ -149,7 +156,7 @@ class StatsPrinter {
149
156
  * @private
150
157
  * @template {StatsPrintHooks[keyof StatsPrintHooks]} HM
151
158
  * @template {HM extends HookMap<infer H> ? H : never} H
152
- * @template {H extends import("tapable").Hook<EXPECTED_ANY, infer R> ? R : never} R
159
+ * @template {H extends import("tapable").Hook<infer A, infer R> ? R : never} R
153
160
  * @param {HM} hookMap hook map
154
161
  * @param {string} type type
155
162
  * @param {(hooK: H) => R | undefined | void} fn fn
@@ -15,7 +15,7 @@ const CommentCompilationWarning = require("../errors/CommentCompilationWarning")
15
15
  const UnsupportedFeatureWarning = require("../errors/UnsupportedFeatureWarning");
16
16
  const BasicEvaluatedExpression = require("../javascript/BasicEvaluatedExpression");
17
17
  const { approve } = require("../javascript/JavascriptParserHelpers");
18
- const InnerGraph = require("../optimize/InnerGraph");
18
+ const { getInnerGraphUtils } = require("../optimize/InnerGraph");
19
19
 
20
20
  /** @typedef {import("estree").MemberExpression} MemberExpression */
21
21
  /** @typedef {import("estree").NewExpression} NewExpressionNode */
@@ -189,7 +189,10 @@ class URLParserPlugin {
189
189
  );
190
190
  dep.loc = /** @type {DependencyLocation} */ (expr.loc);
191
191
  parser.state.current.addDependency(dep);
192
- InnerGraph.onUsage(parser.state, (e) => (dep.usedByExports = e));
192
+ getInnerGraphUtils(parser.state.compilation).onUsage(
193
+ parser.state,
194
+ (e) => (dep.usedByExports = e)
195
+ );
193
196
  return true;
194
197
  }
195
198
 
@@ -38,6 +38,7 @@ class AsyncQueueEntry {
38
38
  * @param {Callback<R>} callback the callback
39
39
  */
40
40
  constructor(item, callback) {
41
+ /** @type {T} */
41
42
  this.item = item;
42
43
  /** @type {typeof QUEUED_STATE | typeof PROCESSING_STATE | typeof DONE_STATE} */
43
44
  this.state = QUEUED_STATE;
@@ -82,10 +83,15 @@ class AsyncQueue {
82
83
  * @param {Processor<T, R>} options.processor async function to process items
83
84
  */
84
85
  constructor({ name, context, parallelism, parent, processor, getKey }) {
86
+ /** @type {string | undefined} */
85
87
  this._name = name;
88
+ /** @type {string} */
86
89
  this._context = context || "normal";
90
+ /** @type {number} */
87
91
  this._parallelism = parallelism || 1;
92
+ /** @type {Processor<T, R>} */
88
93
  this._processor = processor;
94
+ /** @type {getKey<T, K>} */
89
95
  this._getKey =
90
96
  getKey ||
91
97
  /** @type {getKey<T, K>} */ ((item) => /** @type {T & K} */ (item));
@@ -95,9 +101,13 @@ class AsyncQueue {
95
101
  this._queued = new ArrayQueue();
96
102
  /** @type {AsyncQueue<T, K, R>[] | undefined} */
97
103
  this._children = undefined;
104
+ /** @type {number} */
98
105
  this._activeTasks = 0;
106
+ /** @type {boolean} */
99
107
  this._willEnsureProcessing = false;
108
+ /** @type {boolean} */
100
109
  this._needProcessing = false;
110
+ /** @type {boolean} */
101
111
  this._stopped = false;
102
112
  /** @type {AsyncQueue<T, K, R>} */
103
113
  this._root = parent ? parent._root : this;
@@ -57,14 +57,19 @@ class LazyBucketSortedSet {
57
57
  * @param {...Arg<T, K>} args more pairs of getKey and comparator plus optional final comparator for the last layer
58
58
  */
59
59
  constructor(getKey, comparator, ...args) {
60
+ /** @type {GetKey<T, K>} */
60
61
  this._getKey = getKey;
62
+ /** @type {Arg<T, K>[]} */
61
63
  this._innerArgs = args;
64
+ /** @type {boolean} */
62
65
  this._leaf = args.length <= 1;
66
+ /** @type {SortableSet<K>} */
63
67
  this._keys = new SortableSet(undefined, comparator);
64
68
  /** @type {Map<K, Entry<T, K>>} */
65
69
  this._map = new Map();
66
70
  /** @type {Set<T>} */
67
71
  this._unsortedItems = new Set();
72
+ /** @type {number} */
68
73
  this.size = 0;
69
74
  }
70
75
 
@@ -67,7 +67,9 @@ class LazySet {
67
67
  this._toMerge = new Set();
68
68
  /** @type {LazySet<T>[]} */
69
69
  this._toDeepMerge = [];
70
+ /** @type {boolean} */
70
71
  this._needMerge = false;
72
+ /** @type {boolean} */
71
73
  this._deopt = false;
72
74
  }
73
75
 
@@ -245,7 +247,7 @@ class LazySet {
245
247
  /**
246
248
  * Serializes the fully materialized set contents into webpack's object
247
249
  * serialization stream.
248
- * @param {import("../serialization/ObjectMiddleware").ObjectSerializerContext} context context
250
+ * @param {import("../serialization/ObjectMiddleware").ObjectSerializerContext<(number | T)[]>} context context
249
251
  */
250
252
  serialize({ write }) {
251
253
  if (this._needMerge) this._merge();
@@ -256,15 +258,15 @@ class LazySet {
256
258
  /**
257
259
  * Restores a `LazySet` from serialized item data.
258
260
  * @template T
259
- * @param {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} context context
261
+ * @param {import("../serialization/ObjectMiddleware").ObjectDeserializerContext<(number | T)[]>} context context
260
262
  * @returns {LazySet<T>} lazy set
261
263
  */
262
264
  static deserialize({ read }) {
263
- const count = read();
265
+ const count = /** @type {number} */ (read());
264
266
  /** @type {T[]} */
265
267
  const items = [];
266
268
  for (let i = 0; i < count; i++) {
267
- items.push(read());
269
+ items.push(/** @type {T} */ (read()));
268
270
  }
269
271
  return new LazySet(items);
270
272
  }
@@ -11,9 +11,13 @@ class LocConverter {
11
11
  * @param {string} input input
12
12
  */
13
13
  constructor(input) {
14
+ /** @type {string} */
14
15
  this._input = input;
16
+ /** @type {number} */
15
17
  this.line = 1;
18
+ /** @type {number} */
16
19
  this.column = 0;
20
+ /** @type {number} */
17
21
  this.pos = 0;
18
22
  }
19
23
 
@@ -37,7 +41,13 @@ class LocConverter {
37
41
  }
38
42
  }
39
43
  } else {
40
- let i = this._input.lastIndexOf("\n", this.pos);
44
+ // Retreat: count newlines crossed in (pos, this.pos), i.e.
45
+ // exclude the newline at `this.pos` itself. By convention a
46
+ // `\n` is the last column of its line, so when `this.pos`
47
+ // sits on one we're already on the line containing it; only
48
+ // newlines strictly **before** `this.pos` and at-or-after
49
+ // `pos` represent crossed line boundaries.
50
+ let i = this._input.lastIndexOf("\n", this.pos - 1);
41
51
  while (i >= pos) {
42
52
  this.line--;
43
53
  i = i > 0 ? this._input.lastIndexOf("\n", i - 1) : -1;
@@ -17,6 +17,7 @@ class Semaphore {
17
17
  * in the Semaphore
18
18
  */
19
19
  constructor(available) {
20
+ /** @type {number} */
20
21
  this.available = available;
21
22
  /** @type {(() => void)[]} */
22
23
  this.waiters = [];
@@ -0,0 +1,106 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ */
4
+
5
+ "use strict";
6
+
7
+ /**
8
+ * Babel-style visitor map keyed by a numeric node-type discriminator; a bucket
9
+ * is a function (enter-only) or `{ enter?, exit? }`. `ctx.skipChildren()`
10
+ * (enter only) stops the walker descending into the node's children.
11
+ * @typedef {{ skipChildren(): void }} VisitorContext
12
+ */
13
+ /**
14
+ * @template TNode
15
+ * @typedef {(node: TNode, parent: TNode | null, ctx: VisitorContext) => void} VisitorFn
16
+ */
17
+ /**
18
+ * @template TNode
19
+ * @typedef {VisitorFn<TNode> | { enter?: VisitorFn<TNode>, exit?: VisitorFn<TNode> }} VisitorBucket
20
+ */
21
+ /**
22
+ * @template TNode
23
+ * @typedef {{ [nodeType: number]: VisitorBucket<TNode> }} VisitorMap
24
+ */
25
+ /**
26
+ * @template TNode
27
+ * @typedef {{ enter: VisitorFn<TNode>[], exit: VisitorFn<TNode>[] }} CompiledVisitorBucket
28
+ */
29
+ /**
30
+ * @template TNode
31
+ * @typedef {CompiledVisitorBucket<TNode>[]} CompiledVisitorMap a sparse array indexed by node type
32
+ */
33
+ /**
34
+ * A language grammar: parse `input` and fire the compiled visitors in source
35
+ * order (the grammar owns tokenizing, parsing, and walking).
36
+ * @template TNode
37
+ * @template TProcessOptions
38
+ * @typedef {(input: string, visitors: CompiledVisitorMap<TNode>, options: TProcessOptions) => void} Grammar
39
+ */
40
+
41
+ /**
42
+ * Visitor coordinator: owns the visitor registry and drives a language
43
+ * `grammar` over the source. Language-agnostic — each syntax (CSS, HTML, …)
44
+ * binds its own grammar and node-type enum. Babel-style usage:
45
+ *
46
+ * ```
47
+ * processor.use({ [NodeType.X]: (node) => {}, [NodeType.Y]: { enter, exit } });
48
+ * processor.process(source);
49
+ * ```
50
+ * @template TNode
51
+ * @template [TProcessOptions=object]
52
+ */
53
+ class SourceProcessor {
54
+ /**
55
+ * @param {Grammar<TNode, TProcessOptions>} grammar the grammar to drive over the source
56
+ */
57
+ constructor(grammar) {
58
+ /** @type {Grammar<TNode, TProcessOptions>} */
59
+ this._grammar = grammar;
60
+ /** @type {CompiledVisitorMap<TNode>} */
61
+ this._visitors = [];
62
+ }
63
+
64
+ /**
65
+ * Register a Babel-style visitor map; calls accumulate per node type.
66
+ * A bucket is a function (= `{ enter }`) or `{ enter?, exit? }`.
67
+ * @param {VisitorMap<TNode>} map visitor map keyed by node type
68
+ * @returns {SourceProcessor<TNode, TProcessOptions>} `this`, for chaining
69
+ */
70
+ use(map) {
71
+ // `map`'s keys are node-type enum members; `Object.keys` stringifies them,
72
+ // so index the compiled array by the number to match the numeric `node.type`.
73
+ for (const type of Object.keys(map)) {
74
+ const key = Number(type);
75
+ const v = map[key];
76
+ let bucket = this._visitors[key];
77
+ if (!bucket) {
78
+ bucket = { enter: [], exit: [] };
79
+ this._visitors[key] = bucket;
80
+ }
81
+ if (typeof v === "function") {
82
+ bucket.enter.push(v);
83
+ } else {
84
+ if (v.enter) bucket.enter.push(v.enter);
85
+ if (v.exit) bucket.exit.push(v.exit);
86
+ }
87
+ }
88
+ return this;
89
+ }
90
+
91
+ /**
92
+ * Run the grammar over `input`, firing visitors in source order. No
93
+ * AST retained.
94
+ * @param {string} input source text
95
+ * @param {TProcessOptions=} options grammar-specific options
96
+ */
97
+ process(input, options) {
98
+ this._grammar(
99
+ input,
100
+ this._visitors,
101
+ options || /** @type {TProcessOptions} */ ({})
102
+ );
103
+ }
104
+ }
105
+
106
+ module.exports = SourceProcessor;
@@ -27,6 +27,7 @@ class TupleSet {
27
27
  constructor(init) {
28
28
  /** @type {InnerMap<T, V>} */
29
29
  this._map = new Map();
30
+ /** @type {number} */
30
31
  this.size = 0;
31
32
  if (init) {
32
33
  for (const tuple of init) {
@@ -45,7 +45,10 @@ class WeakTupleMap {
45
45
  * Initializes an empty tuple trie node with optional value and child maps.
46
46
  */
47
47
  constructor() {
48
- /** @private */
48
+ /**
49
+ * @private
50
+ * @type {number}
51
+ */
49
52
  this.f = 0;
50
53
  /**
51
54
  * @private
@@ -127,6 +130,29 @@ class WeakTupleMap {
127
130
  return newValue;
128
131
  }
129
132
 
133
+ /**
134
+ * Memoizes `compute(thisArg, ...args)` under the tuple key `[compute,
135
+ * ...args]`, computing it on a miss. Equivalent to `provide(compute, ...args,
136
+ * () => compute(thisArg, ...args))` but without allocating that closure (or an
137
+ * extra rest array) on every call — `ModuleGraph#cached` runs this on hot
138
+ * paths where most calls hit the cache and the closure would be pure waste.
139
+ * @param {(thisArg: EXPECTED_ANY, ...args: K) => V} compute computer, also the first key element
140
+ * @param {EXPECTED_ANY} thisArg first argument passed to `compute`
141
+ * @param {K} args remaining key elements, also passed to `compute`
142
+ * @returns {V} the value
143
+ */
144
+ cachedProvide(compute, thisArg, args) {
145
+ /** @type {WeakTupleMap<K, V>} */
146
+ let node = this._get(/** @type {ArrayElement<K>} */ (compute));
147
+ for (let i = 0; i < args.length; i++) {
148
+ node = node._get(/** @type {ArrayElement<K>} */ (args[i]));
149
+ }
150
+ if (node._hasValue()) return /** @type {V} */ (node._getValue());
151
+ const newValue = compute(thisArg, ...args);
152
+ node._setValue(newValue);
153
+ return newValue;
154
+ }
155
+
130
156
  /**
131
157
  * Removes the value stored for the tuple key without pruning the trie.
132
158
  * @param {K} args tuple
@@ -71,8 +71,8 @@ module.exports.getTrimmedIdsAndRange = (
71
71
  * @returns {string[]} trimmed ids
72
72
  */
73
73
  function trimIdsToThoseImported(ids, moduleGraph, dependency) {
74
- /** @type {string[]} */
75
- let trimmedIds = [];
74
+ /** @type {string[] | undefined} */
75
+ let trimmedIds;
76
76
  let currentExportsInfo = moduleGraph.getExportsInfo(
77
77
  /** @type {Module} */ (moduleGraph.getModule(dependency))
78
78
  );
@@ -95,5 +95,5 @@ function trimIdsToThoseImported(ids, moduleGraph, dependency) {
95
95
  currentExportsInfo = nestedInfo;
96
96
  }
97
97
  // Never trim to nothing. This can happen for invalid imports (e.g. import { notThere } from "./module", or import { anything } from "./missingModule")
98
- return trimmedIds.length ? trimmedIds : ids;
98
+ return trimmedIds !== undefined && trimmedIds.length ? trimmedIds : ids;
99
99
  }
@@ -61,13 +61,13 @@ const createCachedParameterizedComparator = (fn) => {
61
61
  return (arg) => {
62
62
  const cachedResult = map.get(arg);
63
63
  if (cachedResult !== undefined) return cachedResult;
64
+ // arrow closure dispatches faster than a bound function on the sort hot path
64
65
  /**
65
- * Returns compare result.
66
66
  * @param {T} a first item
67
67
  * @param {T} b second item
68
68
  * @returns {-1 | 0 | 1} compare result
69
69
  */
70
- const result = fn.bind(null, arg);
70
+ const result = (a, b) => fn(arg, a, b);
71
71
  map.set(arg, result);
72
72
  return result;
73
73
  };
@@ -68,9 +68,28 @@ const getPathInAst = (ast, node) => {
68
68
  };
69
69
 
70
70
  if (Array.isArray(ast)) {
71
- for (let i = 0; i < ast.length; i++) {
72
- const enterResult = enterNode(ast[i]);
73
- if (enterResult !== undefined) return enterResult;
71
+ // sibling ranges are ordered and disjoint; binary search the container
72
+ let lo = 0;
73
+ let hi = ast.length - 1;
74
+ while (lo <= hi) {
75
+ const mid = (lo + hi) >> 1;
76
+ const item = ast[mid];
77
+ const r = item && item.range;
78
+ if (!r) {
79
+ // holes or range-less nodes: scan the remaining window linearly
80
+ for (let i = lo; i <= hi; i++) {
81
+ const enterResult = enterNode(ast[i]);
82
+ if (enterResult !== undefined) return enterResult;
83
+ }
84
+ return;
85
+ }
86
+ if (r[0] > nr[0]) {
87
+ hi = mid - 1;
88
+ } else if (nr[0] >= r[1]) {
89
+ lo = mid + 1;
90
+ } else {
91
+ return r[1] >= nr[1] ? enterNode(item) : undefined;
92
+ }
74
93
  }
75
94
  } else if (ast && typeof ast === "object") {
76
95
  const keys =
@@ -204,7 +223,7 @@ const RESERVED_NAMES = new Set(
204
223
  );
205
224
 
206
225
  /** @typedef {{ usedNames: UsedNames, alreadyCheckedScopes: ScopeSet }} ScopeInfo */
207
- /** @typedef {Map<string, ScopeInfo>} UsedNamesInScopeInfo */
226
+ /** @typedef {Map<string, Map<string, ScopeInfo>>} UsedNamesInScopeInfo */
208
227
 
209
228
  /**
210
229
  * Gets used names in scope info.
@@ -214,14 +233,19 @@ const RESERVED_NAMES = new Set(
214
233
  * @returns {ScopeInfo} info
215
234
  */
216
235
  const getUsedNamesInScopeInfo = (usedNamesInScopeInfo, module, id) => {
217
- const key = `${module}-${id}`;
218
- let info = usedNamesInScopeInfo.get(key);
236
+ // nested maps avoid building a `${module}-${id}` key string per lookup
237
+ let byId = usedNamesInScopeInfo.get(module);
238
+ if (byId === undefined) {
239
+ byId = new Map();
240
+ usedNamesInScopeInfo.set(module, byId);
241
+ }
242
+ let info = byId.get(id);
219
243
  if (info === undefined) {
220
244
  info = {
221
245
  usedNames: new Set(),
222
246
  alreadyCheckedScopes: new Set()
223
247
  };
224
- usedNamesInScopeInfo.set(key, info);
248
+ byId.set(id, info);
225
249
  }
226
250
  return info;
227
251
  };
@@ -35,7 +35,6 @@ module.exports = (algorithm) => {
35
35
  return new BulkUpdateHash(() => new algorithm());
36
36
  }
37
37
  switch (algorithm) {
38
- // TODO add non-cryptographic algorithm here
39
38
  case "debug":
40
39
  if (DebugHash === undefined) {
41
40
  DebugHash = require("./hash/DebugHash");