webpack 5.107.1 → 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 (360) 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 +52 -14
  10. package/lib/ConcatenationScope.js +10 -3
  11. package/lib/ContextExclusionPlugin.js +1 -0
  12. package/lib/ContextModule.js +92 -47
  13. package/lib/ContextModuleFactory.js +45 -38
  14. package/lib/ContextReplacementPlugin.js +4 -0
  15. package/lib/DefinePlugin.js +89 -15
  16. package/lib/Dependency.js +111 -7
  17. package/lib/EntryOptionPlugin.js +39 -2
  18. package/lib/EntryPlugin.js +2 -0
  19. package/lib/ExportsInfo.js +314 -73
  20. package/lib/ExternalModule.js +82 -34
  21. package/lib/ExternalModuleFactoryPlugin.js +1 -0
  22. package/lib/ExternalsPlugin.js +1 -0
  23. package/lib/FileSystemInfo.js +173 -23
  24. package/lib/FlagAllModulesAsUsedPlugin.js +1 -5
  25. package/lib/FlagDependencyExportsPlugin.js +23 -0
  26. package/lib/FlagDependencyUsagePlugin.js +87 -5
  27. package/lib/FlagEntryExportAsUsedPlugin.js +2 -0
  28. package/lib/Generator.js +8 -0
  29. package/lib/HotModuleReplacementPlugin.js +65 -28
  30. package/lib/IgnorePlugin.js +1 -0
  31. package/lib/InitFragment.js +5 -0
  32. package/lib/JavascriptMetaInfoPlugin.js +7 -5
  33. package/lib/LazyBarrel.js +361 -0
  34. package/lib/LoaderTargetPlugin.js +1 -0
  35. package/lib/Module.js +21 -42
  36. package/lib/ModuleGraph.js +3 -2
  37. package/lib/ModuleProfile.js +27 -1
  38. package/lib/ModuleTemplate.js +2 -0
  39. package/lib/MultiCompiler.js +16 -0
  40. package/lib/MultiStats.js +1 -0
  41. package/lib/MultiWatching.js +2 -0
  42. package/lib/NodeStuffPlugin.js +22 -17
  43. package/lib/NormalModule.js +557 -77
  44. package/lib/NormalModuleReplacementPlugin.js +2 -0
  45. package/lib/PrefetchPlugin.js +2 -0
  46. package/lib/ProgressPlugin.js +9 -1
  47. package/lib/ProvidePlugin.js +1 -0
  48. package/lib/RawModule.js +20 -16
  49. package/lib/RecordIdsPlugin.js +1 -0
  50. package/lib/RuntimeGlobals.js +5 -0
  51. package/lib/RuntimePlugin.js +58 -26
  52. package/lib/RuntimeTemplate.js +278 -21
  53. package/lib/SelfModuleFactory.js +1 -0
  54. package/lib/SourceMapDevToolPlugin.js +105 -30
  55. package/lib/Stats.js +1 -0
  56. package/lib/Template.js +8 -2
  57. package/lib/TemplatedPathPlugin.js +473 -131
  58. package/lib/WarnCaseSensitiveModulesPlugin.js +1 -0
  59. package/lib/WarnDeprecatedOptionPlugin.js +4 -0
  60. package/lib/WarnNoModeSetPlugin.js +1 -0
  61. package/lib/WatchIgnorePlugin.js +1 -0
  62. package/lib/Watching.js +9 -0
  63. package/lib/WebpackOptionsApply.js +50 -5
  64. package/lib/asset/AssetBytesGenerator.js +11 -3
  65. package/lib/asset/AssetGenerator.js +47 -22
  66. package/lib/asset/AssetModule.js +47 -0
  67. package/lib/asset/AssetModulesPlugin.js +14 -14
  68. package/lib/asset/AssetParser.js +2 -2
  69. package/lib/asset/AssetSourceGenerator.js +8 -0
  70. package/lib/asset/RawDataUrlModule.js +12 -13
  71. package/lib/buildChunkGraph.js +88 -9
  72. package/lib/bun/BunTargetPlugin.js +48 -0
  73. package/lib/cache/AddBuildDependenciesPlugin.js +1 -0
  74. package/lib/cache/AddManagedPathsPlugin.js +3 -0
  75. package/lib/cache/IdleFileCachePlugin.js +4 -0
  76. package/lib/cache/MemoryWithGcCachePlugin.js +1 -0
  77. package/lib/cache/PackFileCacheStrategy.js +1 -0
  78. package/lib/cache/ResolverCachePlugin.js +2 -0
  79. package/lib/cache/getLazyHashedEtag.js +9 -2
  80. package/lib/cache/mergeEtags.js +2 -0
  81. package/lib/cli.js +109 -19
  82. package/lib/config/browserslistTargetHandler.js +99 -0
  83. package/lib/config/defaults.js +147 -7
  84. package/lib/config/defineConfig.js +31 -0
  85. package/lib/config/normalization.js +5 -0
  86. package/lib/config/target.js +181 -2
  87. package/lib/container/ContainerEntryModule.js +15 -14
  88. package/lib/container/ContainerExposedDependency.js +2 -2
  89. package/lib/container/ContainerReferencePlugin.js +1 -1
  90. package/lib/container/FallbackDependency.js +5 -7
  91. package/lib/container/FallbackModule.js +10 -9
  92. package/lib/container/RemoteModule.js +20 -10
  93. package/lib/container/RemoteRuntimeModule.js +14 -12
  94. package/lib/css/CssGenerator.js +353 -327
  95. package/lib/css/CssInjectStyleRuntimeModule.js +36 -8
  96. package/lib/css/CssLoadingRuntimeModule.js +118 -47
  97. package/lib/css/CssModule.js +52 -23
  98. package/lib/css/CssModulesPlugin.js +107 -124
  99. package/lib/css/CssParser.js +2759 -2205
  100. package/lib/css/syntax.js +2859 -0
  101. package/lib/debug/ProfilingPlugin.js +2 -0
  102. package/lib/deno/DenoTargetPlugin.js +47 -0
  103. package/lib/dependencies/AMDDefineDependency.js +22 -17
  104. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +1 -0
  105. package/lib/dependencies/AMDRequireArrayDependency.js +7 -11
  106. package/lib/dependencies/AMDRequireContextDependency.js +7 -11
  107. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +1 -0
  108. package/lib/dependencies/AMDRequireDependency.js +24 -20
  109. package/lib/dependencies/CachedConstDependency.js +3 -0
  110. package/lib/dependencies/CommonJsDependencyHelpers.js +1 -0
  111. package/lib/dependencies/CommonJsExportRequireDependency.js +79 -31
  112. package/lib/dependencies/CommonJsExportsDependency.js +21 -16
  113. package/lib/dependencies/CommonJsExportsParserPlugin.js +230 -7
  114. package/lib/dependencies/CommonJsFullRequireDependency.js +27 -19
  115. package/lib/dependencies/CommonJsImportsParserPlugin.js +51 -16
  116. package/lib/dependencies/CommonJsPlugin.js +1 -1
  117. package/lib/dependencies/CommonJsRequireContextDependency.js +10 -13
  118. package/lib/dependencies/CommonJsRequireDependency.js +42 -11
  119. package/lib/dependencies/CommonJsSelfReferenceDependency.js +22 -14
  120. package/lib/dependencies/ConstDependency.js +16 -11
  121. package/lib/dependencies/ContextDependency.js +4 -0
  122. package/lib/dependencies/ContextDependencyTemplateAsId.js +1 -1
  123. package/lib/dependencies/ContextElementDependency.js +23 -14
  124. package/lib/dependencies/CreateRequireParserPlugin.js +1 -0
  125. package/lib/dependencies/CreateScriptUrlDependency.js +5 -7
  126. package/lib/dependencies/CriticalDependencyWarning.js +1 -0
  127. package/lib/dependencies/CssIcssExportDependency.js +512 -574
  128. package/lib/dependencies/CssIcssImportDependency.js +9 -9
  129. package/lib/dependencies/CssIcssSymbolDependency.js +22 -15
  130. package/lib/dependencies/CssImportDependency.js +25 -1
  131. package/lib/dependencies/CssUrlDependency.js +23 -14
  132. package/lib/dependencies/DllEntryDependency.js +9 -13
  133. package/lib/dependencies/ExportBindingInitFragment.js +164 -0
  134. package/lib/dependencies/ExportsInfoDependency.js +12 -12
  135. package/lib/dependencies/ExternalModuleDependency.js +8 -5
  136. package/lib/dependencies/ExternalModuleInitFragment.js +7 -5
  137. package/lib/dependencies/ExternalModuleInitFragmentDependency.js +13 -10
  138. package/lib/dependencies/HarmonyAcceptDependency.js +11 -11
  139. package/lib/dependencies/HarmonyAcceptImportDependency.js +1 -0
  140. package/lib/dependencies/HarmonyDetectionParserPlugin.js +47 -22
  141. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +28 -2
  142. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +46 -22
  143. package/lib/dependencies/HarmonyExportExpressionDependency.js +107 -30
  144. package/lib/dependencies/HarmonyExportHeaderDependency.js +7 -9
  145. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +109 -31
  146. package/lib/dependencies/HarmonyExportInitFragment.js +22 -20
  147. package/lib/dependencies/HarmonyExportSpecifierDependency.js +83 -18
  148. package/lib/dependencies/HarmonyExports.js +4 -1
  149. package/lib/dependencies/HarmonyImportDependency.js +24 -0
  150. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +110 -74
  151. package/lib/dependencies/HarmonyImportGuard.js +254 -0
  152. package/lib/dependencies/HarmonyImportSideEffectDependency.js +18 -1
  153. package/lib/dependencies/HarmonyImportSpecifierDependency.js +118 -14
  154. package/lib/dependencies/HarmonyLinkingError.js +1 -0
  155. package/lib/dependencies/HarmonyModulesPlugin.js +1 -0
  156. package/lib/dependencies/{HtmlScriptSrcDependency.js → HtmlEntryDependency.js} +267 -154
  157. package/lib/dependencies/HtmlInlineHtmlDependency.js +107 -0
  158. package/lib/dependencies/HtmlInlineScriptDependency.js +20 -27
  159. package/lib/dependencies/HtmlInlineStyleDependency.js +62 -11
  160. package/lib/dependencies/HtmlSourceDependency.js +18 -0
  161. package/lib/dependencies/ImportContextDependency.js +5 -9
  162. package/lib/dependencies/ImportDependency.js +44 -2
  163. package/lib/dependencies/ImportMetaHotAcceptDependency.js +1 -0
  164. package/lib/dependencies/ImportMetaHotDeclineDependency.js +1 -0
  165. package/lib/dependencies/ImportMetaPlugin.js +74 -30
  166. package/lib/dependencies/ImportParserPlugin.js +19 -0
  167. package/lib/dependencies/ImportWeakDependency.js +1 -0
  168. package/lib/dependencies/JsonExportsDependency.js +9 -9
  169. package/lib/dependencies/LoaderImportDependency.js +1 -0
  170. package/lib/dependencies/LocalModule.js +11 -12
  171. package/lib/dependencies/LocalModuleDependency.js +11 -13
  172. package/lib/dependencies/ModuleDecoratorDependency.js +9 -9
  173. package/lib/dependencies/ModuleDependency.js +7 -0
  174. package/lib/dependencies/ModuleHotAcceptDependency.js +1 -0
  175. package/lib/dependencies/ModuleHotDeclineDependency.js +1 -0
  176. package/lib/dependencies/ModuleInitFragmentDependency.js +15 -11
  177. package/lib/dependencies/ProvidedDependency.js +31 -27
  178. package/lib/dependencies/PureExpressionDependency.js +7 -9
  179. package/lib/dependencies/RequireEnsureDependency.js +12 -13
  180. package/lib/dependencies/RequireHeaderDependency.js +3 -4
  181. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +3 -0
  182. package/lib/dependencies/RequireResolveContextDependency.js +7 -11
  183. package/lib/dependencies/RequireResolveDependency.js +1 -0
  184. package/lib/dependencies/RequireResolveHeaderDependency.js +3 -5
  185. package/lib/dependencies/RuntimeRequirementsDependency.js +6 -7
  186. package/lib/dependencies/StaticExportsDependency.js +10 -10
  187. package/lib/dependencies/SystemPlugin.js +2 -0
  188. package/lib/dependencies/URLContextDependency.js +5 -7
  189. package/lib/dependencies/URLDependency.js +14 -16
  190. package/lib/dependencies/UnsupportedDependency.js +8 -13
  191. package/lib/dependencies/WebAssemblyExportImportedDependency.js +11 -16
  192. package/lib/dependencies/WebAssemblyImportDependency.js +14 -16
  193. package/lib/dependencies/WebpackIsIncludedDependency.js +1 -0
  194. package/lib/dependencies/WorkerDependency.js +19 -8
  195. package/lib/dependencies/WorkerPlugin.js +40 -10
  196. package/lib/dependencies/processExportInfo.js +13 -11
  197. package/lib/dll/DelegatedModule.js +29 -15
  198. package/lib/dll/DelegatedModuleFactoryPlugin.js +1 -0
  199. package/lib/dll/DelegatedPlugin.js +1 -0
  200. package/lib/dll/DllEntryPlugin.js +3 -0
  201. package/lib/dll/DllModule.js +3 -2
  202. package/lib/dll/DllPlugin.js +16 -0
  203. package/lib/dll/DllReferencePlugin.js +3 -0
  204. package/lib/dll/LibManifestPlugin.js +1 -0
  205. package/lib/electron/ElectronTargetPlugin.js +22 -4
  206. package/lib/errors/ConcurrentCompilationError.js +1 -0
  207. package/lib/errors/HookWebpackError.js +11 -13
  208. package/lib/errors/IgnoreErrorModuleFactory.js +1 -0
  209. package/lib/errors/InvalidDependenciesModuleWarning.js +2 -0
  210. package/lib/errors/JSONParseError.js +9 -8
  211. package/lib/errors/ModuleBuildError.js +16 -13
  212. package/lib/errors/ModuleDependencyError.js +8 -1
  213. package/lib/errors/ModuleDependencyWarning.js +8 -1
  214. package/lib/errors/ModuleError.js +5 -11
  215. package/lib/errors/ModuleHashingError.js +4 -0
  216. package/lib/errors/ModuleNotFoundError.js +3 -0
  217. package/lib/errors/ModuleParseError.js +5 -11
  218. package/lib/errors/ModuleRestoreError.js +2 -0
  219. package/lib/errors/ModuleStoreError.js +3 -0
  220. package/lib/errors/ModuleWarning.js +7 -11
  221. package/lib/errors/NodeStuffInWebError.js +1 -0
  222. package/lib/errors/NonErrorEmittedError.js +2 -0
  223. package/lib/errors/UnhandledSchemeError.js +1 -0
  224. package/lib/esm/ModuleChunkLoadingPlugin.js +0 -1
  225. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +28 -23
  226. package/lib/hmr/HotModuleReplacement.runtime.js +175 -30
  227. package/lib/hmr/HotModuleReplacementRuntimeModule.js +7 -0
  228. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +173 -26
  229. package/lib/hmr/LazyCompilationPlugin.js +134 -6
  230. package/lib/html/HtmlGenerator.js +292 -50
  231. package/lib/html/HtmlModule.js +40 -0
  232. package/lib/html/HtmlModulesPlugin.js +287 -60
  233. package/lib/html/HtmlParser.js +1108 -1099
  234. package/lib/html/{walkHtmlTokens.js → syntax.js} +4701 -212
  235. package/lib/ids/IdHelpers.js +4 -2
  236. package/lib/index.js +19 -0
  237. package/lib/javascript/BasicEvaluatedExpression.js +1 -0
  238. package/lib/javascript/EnableChunkLoadingPlugin.js +1 -0
  239. package/lib/javascript/JavascriptGenerator.js +6 -2
  240. package/lib/javascript/JavascriptModule.js +54 -0
  241. package/lib/javascript/JavascriptModulesPlugin.js +257 -102
  242. package/lib/javascript/JavascriptParser.js +286 -159
  243. package/lib/json/JsonModule.js +40 -0
  244. package/lib/json/JsonModulesPlugin.js +7 -0
  245. package/lib/json/JsonParser.js +4 -2
  246. package/lib/library/AssignLibraryPlugin.js +5 -3
  247. package/lib/library/ExportPropertyLibraryPlugin.js +1 -0
  248. package/lib/library/FalseIIFEUmdWarning.js +1 -0
  249. package/lib/library/ModuleLibraryPlugin.js +54 -29
  250. package/lib/library/SystemLibraryPlugin.js +3 -3
  251. package/lib/node/NodeTargetPlugin.js +1 -0
  252. package/lib/node/NodeWatchFileSystem.js +38 -22
  253. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +10 -9
  254. package/lib/node/RequireChunkLoadingRuntimeModule.js +18 -16
  255. package/lib/optimize/ConcatenatedModule.js +397 -78
  256. package/lib/optimize/ConstExportsPlugin.js +211 -0
  257. package/lib/optimize/InlineExports.js +178 -0
  258. package/lib/optimize/InnerGraph.js +372 -275
  259. package/lib/optimize/InnerGraphPlugin.js +196 -99
  260. package/lib/optimize/ModuleConcatenationPlugin.js +56 -25
  261. package/lib/optimize/RealContentHashPlugin.js +14 -1
  262. package/lib/optimize/SideEffectsFlagPlugin.js +234 -64
  263. package/lib/runtime/AsyncModuleRuntimeModule.js +32 -30
  264. package/lib/runtime/AutoPublicPathRuntimeModule.js +11 -5
  265. package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +1 -1
  266. package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +6 -4
  267. package/lib/runtime/DefinePropertyGettersRuntimeModule.js +33 -4
  268. package/lib/runtime/GetChunkFilenameRuntimeModule.js +82 -3
  269. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +1 -1
  270. package/lib/runtime/HasOwnPropertyRuntimeModule.js +1 -1
  271. package/lib/runtime/LoadScriptRuntimeModule.js +18 -13
  272. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +39 -26
  273. package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +1 -1
  274. package/lib/runtime/OnChunksLoadedRuntimeModule.js +4 -4
  275. package/lib/runtime/RelativeUrlRuntimeModule.js +3 -2
  276. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +1 -1
  277. package/lib/runtime/StartupEntrypointRuntimeModule.js +4 -3
  278. package/lib/runtime/WorkerRuntimeModule.js +33 -0
  279. package/lib/schemes/HttpUriPlugin.js +3 -2
  280. package/lib/serialization/AggregateErrorSerializer.js +7 -6
  281. package/lib/serialization/ArraySerializer.js +4 -8
  282. package/lib/serialization/BinaryMiddleware.js +538 -468
  283. package/lib/serialization/DateObjectSerializer.js +2 -2
  284. package/lib/serialization/ErrorObjectSerializer.js +7 -6
  285. package/lib/serialization/MapObjectSerializer.js +5 -9
  286. package/lib/serialization/NullPrototypeObjectSerializer.js +7 -9
  287. package/lib/serialization/ObjectMiddleware.js +50 -13
  288. package/lib/serialization/PlainObjectSerializer.js +9 -8
  289. package/lib/serialization/RegExpObjectSerializer.js +2 -2
  290. package/lib/serialization/Serializer.js +1 -0
  291. package/lib/serialization/SetObjectSerializer.js +4 -8
  292. package/lib/sharing/ConsumeSharedModule.js +6 -7
  293. package/lib/sharing/ConsumeSharedPlugin.js +1 -0
  294. package/lib/sharing/ConsumeSharedRuntimeModule.js +46 -41
  295. package/lib/sharing/ProvideSharedDependency.js +30 -15
  296. package/lib/sharing/ProvideSharedModule.js +30 -11
  297. package/lib/sharing/ProvideSharedPlugin.js +4 -2
  298. package/lib/sharing/SharePlugin.js +3 -0
  299. package/lib/sharing/ShareRuntimeModule.js +18 -16
  300. package/lib/sharing/resolveMatchedConfigs.js +2 -1
  301. package/lib/sharing/utils.js +1 -1
  302. package/lib/stats/DefaultStatsFactoryPlugin.js +4 -6
  303. package/lib/stats/DefaultStatsPrinterPlugin.js +14 -14
  304. package/lib/stats/StatsFactory.js +11 -9
  305. package/lib/stats/StatsPrinter.js +9 -2
  306. package/lib/url/URLParserPlugin.js +5 -2
  307. package/lib/util/AsyncQueue.js +10 -0
  308. package/lib/util/LazyBucketSortedSet.js +5 -0
  309. package/lib/util/LazySet.js +6 -4
  310. package/lib/util/LocConverter.js +11 -1
  311. package/lib/util/Semaphore.js +1 -0
  312. package/lib/util/SourceProcessor.js +106 -0
  313. package/lib/util/TupleSet.js +1 -0
  314. package/lib/util/WeakTupleMap.js +27 -1
  315. package/lib/util/chainedImports.js +3 -3
  316. package/lib/util/comparators.js +2 -2
  317. package/lib/util/concatenate.js +31 -7
  318. package/lib/util/createHash.js +0 -1
  319. package/lib/util/deterministicGrouping.js +19 -12
  320. package/lib/util/extractSourceMap.js +1 -1
  321. package/lib/util/findGraphRoots.js +2 -0
  322. package/lib/util/fs.js +16 -6
  323. package/lib/util/hash/DebugHash.js +1 -0
  324. package/lib/util/hash/hash-digest.js +24 -15
  325. package/lib/util/identifier.js +7 -0
  326. package/lib/util/internalSerializables.js +11 -2
  327. package/lib/util/magicComment.js +42 -0
  328. package/lib/util/makeSerializable.js +1 -0
  329. package/lib/util/nonNumericOnlyHash.js +30 -1
  330. package/lib/util/property.js +7 -1
  331. package/lib/util/publicPathPlaceholder.js +64 -0
  332. package/lib/util/registerExternalSerializer.js +4 -4
  333. package/lib/wasm-async/AsyncWasmModule.js +77 -0
  334. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +1 -1
  335. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +1 -96
  336. package/lib/wasm-async/AsyncWebAssemblyParser.js +1 -1
  337. package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +1 -1
  338. package/lib/wasm-sync/SyncWasmModule.js +39 -0
  339. package/lib/wasm-sync/UnsupportedWebAssemblyFeatureError.js +1 -0
  340. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +6 -3
  341. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +2 -1
  342. package/lib/wasm-sync/WebAssemblyGenerator.js +1 -0
  343. package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +2 -0
  344. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +10 -0
  345. package/lib/wasm-sync/WebAssemblyParser.js +7 -3
  346. package/lib/web/JsonpChunkLoadingRuntimeModule.js +45 -39
  347. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +11 -10
  348. package/package.json +36 -28
  349. package/schemas/WebpackOptions.check.js +1 -1
  350. package/schemas/WebpackOptions.json +212 -3
  351. package/schemas/plugins/HtmlGeneratorOptions.check.js +1 -1
  352. package/schemas/plugins/HtmlParserOptions.check.d.ts +7 -0
  353. package/schemas/plugins/HtmlParserOptions.check.js +6 -0
  354. package/schemas/plugins/HtmlParserOptions.json +3 -0
  355. package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.js +1 -1
  356. package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
  357. package/schemas/plugins/css/CssParserOptions.check.js +1 -1
  358. package/types.d.ts +1592 -314
  359. package/lib/css/walkCssTokens.js +0 -2020
  360. package/lib/util/AppendOnlyStackedSet.js +0 -93
@@ -20,6 +20,7 @@ const {
20
20
  SourceMapSource
21
21
  } = require("webpack-sources");
22
22
  const Compilation = require("./Compilation");
23
+ const Dependency = require("./Dependency");
23
24
  const Module = require("./Module");
24
25
  const ModuleGraphConnection = require("./ModuleGraphConnection");
25
26
  const { JAVASCRIPT_MODULE_TYPE_AUTO } = require("./ModuleTypeConstants");
@@ -35,8 +36,6 @@ const LazySet = require("./util/LazySet");
35
36
  const { isSubset } = require("./util/SetHelpers");
36
37
  const { getScheme } = require("./util/URLAbsoluteSpecifier");
37
38
  const {
38
- compareLocations,
39
- compareSelect,
40
39
  concatComparators,
41
40
  keepOriginalOrder,
42
41
  sortWithSourceOrder
@@ -46,6 +45,7 @@ const { createFakeHook } = require("./util/deprecation");
46
45
  const formatLocation = require("./util/formatLocation");
47
46
  const { join } = require("./util/fs");
48
47
  const {
48
+ ABSOLUTE_PATH_REGEXP,
49
49
  absolutify,
50
50
  contextify,
51
51
  makePathsRelative
@@ -61,12 +61,13 @@ const parseJson = require("./util/parseJson");
61
61
  /** @typedef {import("../declarations/WebpackOptions").ResolveOptions} ResolveOptions */
62
62
  /** @typedef {import("../declarations/WebpackOptions").NoParse} NoParse */
63
63
  /** @typedef {import("./config/defaults").WebpackOptionsNormalizedWithDefaults} WebpackOptions */
64
- /** @typedef {import("./Dependency")} Dependency */
65
64
  /** @typedef {import("./Dependency").UpdateHashContext} UpdateHashContext */
66
65
  /** @typedef {import("./Generator")} Generator */
67
66
  /** @typedef {import("./Generator").GenerateErrorFn} GenerateErrorFn */
67
+ /** @typedef {import("./FileSystemInfo").Snapshot} Snapshot */
68
68
  /** @typedef {import("./Module").BuildInfo} BuildInfo */
69
69
  /** @typedef {import("./Module").FileSystemDependencies} FileSystemDependencies */
70
+ /** @typedef {import("./Module").ValueCacheVersions} ValueCacheVersions */
70
71
  /** @typedef {import("./Module").BuildMeta} BuildMeta */
71
72
  /** @typedef {import("./Module").CodeGenerationContext} CodeGenerationContext */
72
73
  /** @typedef {import("./Module").CodeGenerationResult} CodeGenerationResult */
@@ -86,7 +87,6 @@ const parseJson = require("./util/parseJson");
86
87
  /** @typedef {import("./Module").UnsafeCacheData} UnsafeCacheData */
87
88
  /** @typedef {import("./ModuleGraph")} ModuleGraph */
88
89
  /** @typedef {import("./ModuleGraphConnection").ConnectionState} ConnectionState */
89
- /** @typedef {Iterator<SideEffectsWalk, ConnectionState, ConnectionState>} SideEffectsWalk */
90
90
  /** @typedef {import("./NormalModuleFactory")} NormalModuleFactory */
91
91
  /** @typedef {import("./NormalModuleFactory").NormalModuleTypes} NormalModuleTypes */
92
92
  /** @typedef {import("./NormalModuleFactory").ParserByType} ParserByType */
@@ -156,27 +156,407 @@ const recordSideEffectsBailout = (mod, moduleGraph, dep) => {
156
156
  );
157
157
  };
158
158
 
159
+ // Maximum recursive descent depth before switching to the iterative walker.
160
+ // #20986 reported overflow around 1300 modules in webpack 5.107.0 where each
161
+ // step consumed two stack frames (`NormalModule.getSideEffectsConnectionState`
162
+ // plus `HarmonyImportSideEffectDependency.getModuleEvaluationSideEffectsState`).
163
+ // `walkSideEffectsRecursive` folds the second call into the first and uses
164
+ // one frame per module, so this limit caps the native stack at half the depth
165
+ // where the original code overflowed — well within the safe range across
166
+ // platforms while keeping the common (shallow) case purely recursive.
167
+ const SIDE_EFFECTS_RECURSION_LIMIT = 2000;
168
+
159
169
  /**
160
- * Generator form of `getSideEffectsConnectionState` descends through
161
- * `HarmonyImportSideEffectDependency` via `yield` so the trampoline in
162
- * `getSideEffectsConnectionState` can drive the walk iteratively (#20986).
163
- * @param {NormalModule} mod the module being evaluated
170
+ * Iterative form of the side-effects walker. Used as a fallback once the
171
+ * recursive form reaches `SIDE_EFFECTS_RECURSION_LIMIT` so deep chains
172
+ * (#20986) don't overflow V8's stack. Safe to enter while ancestors set
173
+ * `_isEvaluatingSideEffects` on their own modules those are treated as
174
+ * `CIRCULAR_CONNECTION` if revisited, matching the original recursive
175
+ * behavior.
176
+ * @param {NormalModule} rootMod the module to walk
164
177
  * @param {ModuleGraph} moduleGraph the module graph
165
- * @returns {SideEffectsWalk} the generator
178
+ * @param {SideEffectsWalkContext} ctx per-walk cycle-tracking context
179
+ * @returns {ConnectionState} the side-effects connection state
166
180
  */
167
- function* walkSideEffects(mod, moduleGraph) {
168
- if (mod.factoryMeta !== undefined) {
169
- if (mod.factoryMeta.sideEffectFree) return false;
170
- if (mod.factoryMeta.sideEffectFree === false) return true;
181
+ const walkSideEffectsIterative = (rootMod, moduleGraph, ctx) => {
182
+ const SideEffectDep = getHarmonyImportSideEffectDependency();
183
+
184
+ /** @type {NormalModule[]} */
185
+ const modStack = [rootMod];
186
+ /** @type {Dependency[][]} */
187
+ const depsStack = [rootMod.dependencies];
188
+ const indexStack = [0];
189
+ /** @type {ConnectionState[]} */
190
+ const currentStack = [false];
191
+ rootMod._isEvaluatingSideEffects = true;
192
+
193
+ /**
194
+ * Result from a just-popped child frame, to be applied to the new
195
+ * top's current dep. `undefined` means "no pending; advance".
196
+ * @type {ConnectionState | undefined}
197
+ */
198
+ let pending;
199
+
200
+ while (modStack.length > 0) {
201
+ const top = modStack.length - 1;
202
+ const topMod = modStack[top];
203
+ const deps = depsStack[top];
204
+ let index = indexStack[top];
205
+ let current = currentStack[top];
206
+
207
+ if (pending !== undefined) {
208
+ const state = pending;
209
+ pending = undefined;
210
+ const dep = deps[index];
211
+
212
+ if (state === true) {
213
+ recordSideEffectsBailout(topMod, moduleGraph, dep);
214
+ topMod._isEvaluatingSideEffects = false;
215
+ // `true` is monotonic — safe to memoize regardless of cycle
216
+ // status, matching the direct-bailout branch below.
217
+ topMod._sideEffectsStateGraph = moduleGraph;
218
+ topMod._sideEffectsStateValue = true;
219
+ modStack.pop();
220
+ depsStack.pop();
221
+ indexStack.pop();
222
+ currentStack.pop();
223
+ pending = true;
224
+ continue;
225
+ }
226
+ if (state !== ModuleGraphConnection.CIRCULAR_CONNECTION) {
227
+ current = ModuleGraphConnection.addConnectionStates(current, state);
228
+ }
229
+ index++;
230
+ }
231
+
232
+ let descended = false;
233
+ const depCount = deps.length;
234
+ while (index < depCount) {
235
+ const dep = deps[index];
236
+ /** @type {ConnectionState} */
237
+ let state;
238
+
239
+ if (dep instanceof SideEffectDep) {
240
+ const refModule = moduleGraph.getModule(dep);
241
+ if (!refModule) {
242
+ state = true;
243
+ } else if (refModule instanceof NormalModule) {
244
+ // Cache hit
245
+ if (refModule._sideEffectsStateGraph === moduleGraph) {
246
+ state = /** @type {ConnectionState} */ (
247
+ refModule._sideEffectsStateValue
248
+ );
249
+ }
250
+ // Fast-path checks inlined to avoid the helper call.
251
+ else if (refModule.factoryMeta !== undefined) {
252
+ if (refModule.factoryMeta.sideEffectFree) {
253
+ state = false;
254
+ } else if (refModule.factoryMeta.sideEffectFree === false) {
255
+ state = true;
256
+ } else if (
257
+ !(
258
+ refModule.buildMeta !== undefined &&
259
+ refModule.buildMeta.sideEffectFree
260
+ )
261
+ ) {
262
+ state = true;
263
+ } else if (refModule._isEvaluatingSideEffects) {
264
+ ctx.circular = true;
265
+ state = ModuleGraphConnection.CIRCULAR_CONNECTION;
266
+ } else {
267
+ // Descend
268
+ indexStack[top] = index;
269
+ currentStack[top] = current;
270
+ refModule._isEvaluatingSideEffects = true;
271
+ modStack.push(refModule);
272
+ depsStack.push(refModule.dependencies);
273
+ indexStack.push(0);
274
+ currentStack.push(false);
275
+ descended = true;
276
+ break;
277
+ }
278
+ } else if (
279
+ !(
280
+ refModule.buildMeta !== undefined &&
281
+ refModule.buildMeta.sideEffectFree
282
+ )
283
+ ) {
284
+ state = true;
285
+ } else if (refModule._isEvaluatingSideEffects) {
286
+ ctx.circular = true;
287
+ state = ModuleGraphConnection.CIRCULAR_CONNECTION;
288
+ } else {
289
+ // Descend
290
+ indexStack[top] = index;
291
+ currentStack[top] = current;
292
+ refModule._isEvaluatingSideEffects = true;
293
+ modStack.push(refModule);
294
+ depsStack.push(refModule.dependencies);
295
+ indexStack.push(0);
296
+ currentStack.push(false);
297
+ descended = true;
298
+ break;
299
+ }
300
+ } else {
301
+ ctx.circular = true;
302
+ state = refModule.getSideEffectsConnectionState(moduleGraph);
303
+ }
304
+ } else {
305
+ state = dep.getModuleEvaluationSideEffectsState(moduleGraph);
306
+ }
307
+
308
+ if (state === true) {
309
+ recordSideEffectsBailout(topMod, moduleGraph, dep);
310
+ topMod._isEvaluatingSideEffects = false;
311
+ topMod._sideEffectsStateGraph = moduleGraph;
312
+ topMod._sideEffectsStateValue = true;
313
+ modStack.pop();
314
+ depsStack.pop();
315
+ indexStack.pop();
316
+ currentStack.pop();
317
+ pending = true;
318
+ descended = true;
319
+ break;
320
+ }
321
+ if (state !== ModuleGraphConnection.CIRCULAR_CONNECTION) {
322
+ current = ModuleGraphConnection.addConnectionStates(current, state);
323
+ }
324
+ index++;
325
+ }
326
+
327
+ if (descended) continue;
328
+
329
+ topMod._isEvaluatingSideEffects = false;
330
+ if (!ctx.circular) {
331
+ topMod._sideEffectsStateGraph = moduleGraph;
332
+ topMod._sideEffectsStateValue = current;
333
+ }
334
+ pending = current;
335
+ modStack.pop();
336
+ depsStack.pop();
337
+ indexStack.pop();
338
+ currentStack.pop();
171
339
  }
172
- if (!(mod.buildMeta !== undefined && mod.buildMeta.sideEffectFree)) {
173
- return true;
340
+
341
+ return /** @type {ConnectionState} */ (pending);
342
+ };
343
+
344
+ /**
345
+ * @typedef {object} SideEffectsWalkContext
346
+ * @property {boolean} circular whether a cycle was seen anywhere in this walk
347
+ */
348
+
349
+ /**
350
+ * Walks back up a stack of linear-chain ancestors, applying the result
351
+ * `state` of the chain's tail to each ancestor. Each ancestor in the
352
+ * stack had exactly one `HarmonyImportSideEffectDependency` returning
353
+ * `state`, so its result is just `state` (with the usual aggregation
354
+ * rules) and we can avoid building per-frame `current` accumulators.
355
+ * @param {(NormalModule | Dependency)[] | null} ancestors interleaved stack of `[mod, sideEffectDep, mod, sideEffectDep, …]` in descent order; `null` if there were none
356
+ * @param {ConnectionState} state result from the chain's tail
357
+ * @param {ModuleGraph} moduleGraph the module graph
358
+ * @param {SideEffectsWalkContext} ctx per-walk cycle-tracking context
359
+ * @returns {ConnectionState} the root ancestor's result
360
+ */
361
+ const propagateLinearResult = (ancestors, state, moduleGraph, ctx) => {
362
+ if (ancestors === null) return state;
363
+ while (ancestors.length > 0) {
364
+ const dep = /** @type {Dependency} */ (ancestors.pop());
365
+ const ancestor = /** @type {NormalModule} */ (ancestors.pop());
366
+ ancestor._isEvaluatingSideEffects = false;
367
+
368
+ if (state === true) {
369
+ recordSideEffectsBailout(ancestor, moduleGraph, dep);
370
+ // `true` is monotonic — safe to cache regardless of cycle status.
371
+ ancestor._sideEffectsStateGraph = moduleGraph;
372
+ ancestor._sideEffectsStateValue = true;
373
+ } else if (state === ModuleGraphConnection.CIRCULAR_CONNECTION) {
374
+ // CIRCULAR_CONNECTION is filtered before folding into `current`,
375
+ // so the ancestor's `current` stays at its initial `false`. From
376
+ // this point upward the propagated state is `false`, and the
377
+ // cycle taint prevents memoization further up (handled by
378
+ // `ctx.circular`).
379
+ state = false;
380
+ } else if (!ctx.circular) {
381
+ ancestor._sideEffectsStateGraph = moduleGraph;
382
+ ancestor._sideEffectsStateValue = state;
383
+ }
174
384
  }
175
- if (mod._isEvaluatingSideEffects) {
176
- return ModuleGraphConnection.CIRCULAR_CONNECTION;
385
+ return state;
386
+ };
387
+
388
+ /**
389
+ * Recursive form of the side-effects walker. Folds the descent through
390
+ * `HarmonyImportSideEffectDependency.getModuleEvaluationSideEffectsState`
391
+ * directly into the loop so each module costs only one V8 stack frame
392
+ * (vs. two in the original recursive code).
393
+ *
394
+ * Linear-chain heads (modules with exactly one
395
+ * `HarmonyImportSideEffectDependency` to another `NormalModule`) are
396
+ * walked iteratively inside the function via an explicit
397
+ * `linearAncestors` stack — no additional V8 frame per descent — and
398
+ * their results are propagated back up by `propagateLinearResult`. This
399
+ * keeps stack consumption at O(1) for the common deep-import-chain
400
+ * pattern that motivated #20986 and also avoids the heavier iterative
401
+ * fallback.
402
+ *
403
+ * Falls back to `walkSideEffectsIterative` only when a *non-linear*
404
+ * walk reaches `SIDE_EFFECTS_RECURSION_LIMIT` — i.e. a deep tree, where
405
+ * each level genuinely needs its own recursion frame.
406
+ *
407
+ * Caches the result on the module when the walk did not encounter a
408
+ * cycle, so subsequent queries (e.g. repeated lookups during
409
+ * `SideEffectsFlagPlugin`'s incoming-connection optimization and its
410
+ * `exportInfo.getTarget` callbacks) return in O(1).
411
+ * @param {NormalModule} mod the module being walked
412
+ * @param {ModuleGraph} moduleGraph the module graph
413
+ * @param {number} depth current recursion depth (only counts true V8 frames)
414
+ * @param {EXPECTED_ANY} SideEffectDep `HarmonyImportSideEffectDependency` constructor, resolved once at the public entry to avoid repeated `require` lookups in the recursive call
415
+ * @param {SideEffectsWalkContext} ctx per-walk cycle-tracking context
416
+ * @returns {ConnectionState} the side-effects connection state
417
+ */
418
+ const walkSideEffectsRecursive = (
419
+ mod,
420
+ moduleGraph,
421
+ depth,
422
+ SideEffectDep,
423
+ ctx
424
+ ) => {
425
+ // Interleaved `[mod, linearDep, mod, linearDep, …]` for the linear
426
+ // chain head; `null` until the first descent.
427
+ /** @type {(NormalModule | Dependency)[] | null} */
428
+ let linearAncestors = null;
429
+
430
+ // Walk the linear-chain head iteratively. Every loop iteration peels
431
+ // off one module without consuming a V8 stack frame.
432
+ while (true) {
433
+ if (mod._sideEffectsStateGraph === moduleGraph) {
434
+ return propagateLinearResult(
435
+ linearAncestors,
436
+ /** @type {ConnectionState} */ (mod._sideEffectsStateValue),
437
+ moduleGraph,
438
+ ctx
439
+ );
440
+ }
441
+
442
+ if (mod.factoryMeta !== undefined) {
443
+ if (mod.factoryMeta.sideEffectFree) {
444
+ return propagateLinearResult(linearAncestors, false, moduleGraph, ctx);
445
+ }
446
+ if (mod.factoryMeta.sideEffectFree === false) {
447
+ return propagateLinearResult(linearAncestors, true, moduleGraph, ctx);
448
+ }
449
+ }
450
+ if (!(mod.buildMeta !== undefined && mod.buildMeta.sideEffectFree)) {
451
+ return propagateLinearResult(linearAncestors, true, moduleGraph, ctx);
452
+ }
453
+ if (mod._isEvaluatingSideEffects) {
454
+ ctx.circular = true;
455
+ return propagateLinearResult(
456
+ linearAncestors,
457
+ ModuleGraphConnection.CIRCULAR_CONNECTION,
458
+ moduleGraph,
459
+ ctx
460
+ );
461
+ }
462
+
463
+ // A real ESM module's `dependencies` typically include one
464
+ // `HarmonyImportSideEffectDependency` plus several non-recursive deps
465
+ // (export specifiers, const dependencies, …) that report
466
+ // `false`/`CIRCULAR_CONNECTION` from
467
+ // `getModuleEvaluationSideEffectsState`. Walk the deps in order
468
+ // here: as long as at most one is a `SideEffectDep` and no
469
+ // non-recursive dep triggers a bailout or contributes a non-`false`
470
+ // state, we can still tail-call iteratively through that one
471
+ // `SideEffectDep` — no V8 frame needed. This is what keeps the
472
+ // 1300-module cyclic chain from #20986 from overflowing V8's stack
473
+ // even though each generated module has multiple `dependencies`.
474
+ const deps = mod.dependencies;
475
+ /** @type {Dependency | null} */
476
+ let linearDep = null;
477
+ /** @type {ConnectionState} */
478
+ let nonRecursiveCurrent = false;
479
+ let linearOk = true;
480
+ for (let i = 0; i < deps.length; i++) {
481
+ const dep = deps[i];
482
+ if (dep instanceof SideEffectDep) {
483
+ if (linearDep !== null) {
484
+ // Two `SideEffectDep`s in the same module — fall back to
485
+ // the general walk so each can recurse normally.
486
+ linearOk = false;
487
+ break;
488
+ }
489
+ linearDep = dep;
490
+ } else {
491
+ const state = dep.getModuleEvaluationSideEffectsState(moduleGraph);
492
+ if (state === true) {
493
+ recordSideEffectsBailout(mod, moduleGraph, dep);
494
+ mod._sideEffectsStateGraph = moduleGraph;
495
+ mod._sideEffectsStateValue = true;
496
+ return propagateLinearResult(linearAncestors, true, moduleGraph, ctx);
497
+ }
498
+ if (state !== ModuleGraphConnection.CIRCULAR_CONNECTION) {
499
+ nonRecursiveCurrent = ModuleGraphConnection.addConnectionStates(
500
+ nonRecursiveCurrent,
501
+ state
502
+ );
503
+ }
504
+ }
505
+ }
506
+
507
+ if (!linearOk || nonRecursiveCurrent !== false) {
508
+ // Multiple `SideEffectDep`s, or a non-recursive dep contributed
509
+ // a non-`false` state (e.g. `TRANSITIVE_ONLY`). The linear
510
+ // propagation rule "ancestor's current = chain state" no longer
511
+ // holds, so fall back to the general walk.
512
+ break;
513
+ }
514
+
515
+ if (linearDep === null) {
516
+ // No `SideEffectDep` — the module is a leaf as far as the
517
+ // side-effects graph is concerned. Cache and propagate `false`.
518
+ if (!ctx.circular) {
519
+ mod._sideEffectsStateGraph = moduleGraph;
520
+ mod._sideEffectsStateValue = false;
521
+ }
522
+ return propagateLinearResult(linearAncestors, false, moduleGraph, ctx);
523
+ }
524
+
525
+ const refModule = moduleGraph.getModule(linearDep);
526
+ if (!refModule) {
527
+ recordSideEffectsBailout(mod, moduleGraph, linearDep);
528
+ mod._sideEffectsStateGraph = moduleGraph;
529
+ mod._sideEffectsStateValue = true;
530
+ return propagateLinearResult(linearAncestors, true, moduleGraph, ctx);
531
+ }
532
+ if (!(refModule instanceof NormalModule)) {
533
+ // Non-NormalModule's `getSideEffectsConnectionState` re-enters
534
+ // the public method; defer to the general walk for safety.
535
+ break;
536
+ }
537
+
538
+ mod._isEvaluatingSideEffects = true;
539
+ if (linearAncestors === null) linearAncestors = [];
540
+ // Push (mod, linearDep) so `propagateLinearResult` records bailouts
541
+ // against the actual `SideEffectDep` that triggered the descent —
542
+ // which may not be `dependencies[0]` when the module also has
543
+ // export / const dependencies.
544
+ linearAncestors.push(mod, linearDep);
545
+ mod = refModule;
546
+ continue;
547
+ }
548
+
549
+ // Non-linear walk. Each genuine recursive call costs one V8 frame, so
550
+ // honour the depth limit here.
551
+ if (depth >= SIDE_EFFECTS_RECURSION_LIMIT) {
552
+ return propagateLinearResult(
553
+ linearAncestors,
554
+ walkSideEffectsIterative(mod, moduleGraph, ctx),
555
+ moduleGraph,
556
+ ctx
557
+ );
177
558
  }
178
559
 
179
- const SideEffectDep = getHarmonyImportSideEffectDependency();
180
560
  mod._isEvaluatingSideEffects = true;
181
561
  /** @type {ConnectionState} */
182
562
  let current = false;
@@ -189,8 +569,22 @@ function* walkSideEffects(mod, moduleGraph) {
189
569
  if (!refModule) {
190
570
  state = true;
191
571
  } else if (refModule instanceof NormalModule) {
192
- state = yield walkSideEffects(refModule, moduleGraph);
572
+ state = walkSideEffectsRecursive(
573
+ refModule,
574
+ moduleGraph,
575
+ depth + 1,
576
+ SideEffectDep,
577
+ ctx
578
+ );
193
579
  } else {
580
+ // Non-NormalModule's `getSideEffectsConnectionState` (notably
581
+ // `ConcatenatedModule` delegating to its root) re-enters the
582
+ // public method and may walk through modules that the outer
583
+ // walk has marked as evaluating. We can't observe whether
584
+ // the inner walk hit a cycle that reflected the outer's
585
+ // state, so treat the walk as cycle-tainted and skip the
586
+ // cache for safety.
587
+ ctx.circular = true;
194
588
  state = refModule.getSideEffectsConnectionState(moduleGraph);
195
589
  }
196
590
  } else {
@@ -200,7 +594,12 @@ function* walkSideEffects(mod, moduleGraph) {
200
594
  if (state === true) {
201
595
  recordSideEffectsBailout(mod, moduleGraph, dep);
202
596
  mod._isEvaluatingSideEffects = false;
203
- return true;
597
+ // `true` is monotonic — once any dep declares side effects, the
598
+ // answer is `true` regardless of how cycles resolve, so it's
599
+ // always safe to memoize.
600
+ mod._sideEffectsStateGraph = moduleGraph;
601
+ mod._sideEffectsStateValue = true;
602
+ return propagateLinearResult(linearAncestors, true, moduleGraph, ctx);
204
603
  }
205
604
  if (state !== ModuleGraphConnection.CIRCULAR_CONNECTION) {
206
605
  current = ModuleGraphConnection.addConnectionStates(current, state);
@@ -208,12 +607,19 @@ function* walkSideEffects(mod, moduleGraph) {
208
607
  }
209
608
 
210
609
  mod._isEvaluatingSideEffects = false;
211
- // When caching is implemented here, make sure to not cache when
212
- // at least one circular connection was folded into `current`.
213
- return current;
214
- }
215
610
 
216
- const ABSOLUTE_PATH_REGEX = /^(?:[a-z]:\\|\\\\|\/)/i;
611
+ // Only memoize when no cycle has been observed anywhere in the walk
612
+ // since the public entry. A cycle anywhere can affect any ancestor's
613
+ // result (the back-edge target's contribution is hidden by
614
+ // CIRCULAR_CONNECTION short-circuiting), so this single flag is the
615
+ // conservative-but-cheap approximation of "this subtree's result is
616
+ // independent of cycle context". The public entry resets the flag.
617
+ if (!ctx.circular) {
618
+ mod._sideEffectsStateGraph = moduleGraph;
619
+ mod._sideEffectsStateValue = current;
620
+ }
621
+ return propagateLinearResult(linearAncestors, current, moduleGraph, ctx);
622
+ };
217
623
 
218
624
  /**
219
625
  * @typedef {object} LoaderItem
@@ -340,6 +746,22 @@ const asBuffer = (input) => {
340
746
  * @typedef {(resourcePath: string, getLoaderContext: (resourcePath: string) => AnyLoaderContext) => Promise<string | Buffer<ArrayBufferLike>>} ReadResource
341
747
  */
342
748
 
749
+ /**
750
+ * Defines the build info properties of normal modules (filesystem-backed, loader-processed).
751
+ * @typedef {object} KnownNormalModuleBuildInfo
752
+ * @property {boolean=} parsed
753
+ * @property {string=} hash
754
+ * @property {FileSystemDependencies=} fileDependencies
755
+ * @property {FileSystemDependencies=} contextDependencies
756
+ * @property {FileSystemDependencies=} missingDependencies
757
+ * @property {FileSystemDependencies=} buildDependencies
758
+ * @property {ValueCacheVersions=} valueDependencies
759
+ * @property {(Snapshot | null)=} snapshot
760
+ * @property {string=} resourceIntegrity using in HttpUriPlugin
761
+ */
762
+
763
+ /** @typedef {BuildInfo & KnownNormalModuleBuildInfo} NormalModuleBuildInfo */
764
+
343
765
  /** @type {WeakMap<Compilation, NormalModuleCompilationHooks>} */
344
766
  const compilationHooksMap = new WeakMap();
345
767
 
@@ -463,7 +885,14 @@ class NormalModule extends Module {
463
885
  /** @type {NormalModuleCreateData['extractSourceMap']} */
464
886
  this.extractSourceMap = extractSourceMap;
465
887
 
888
+ // Set by HotModuleReplacementPlugin via NormalModuleFactory's `module` hook
889
+ /** @type {boolean} */
890
+ this.hot = false;
891
+
466
892
  // Info from Build
893
+ // Redeclared with the normal module specific shape (see KnownNormalModuleBuildInfo)
894
+ /** @type {NormalModuleBuildInfo | undefined} */
895
+ this.buildInfo = undefined;
467
896
  /** @type {Error | null} */
468
897
  this.error = null;
469
898
  /**
@@ -500,6 +929,18 @@ class NormalModule extends Module {
500
929
  * @type {WeakSet<ModuleGraph> | undefined}
501
930
  */
502
931
  this._addedSideEffectsBailout = undefined;
932
+ /**
933
+ * Memoizes the result of `getSideEffectsConnectionState`. The
934
+ * graph slot keys the cached value to the `ModuleGraph` it was
935
+ * computed against so stale values never leak across compilations
936
+ * — a walk that targets a different graph just overwrites both
937
+ * slots. Populated only for results computed without encountering
938
+ * a circular connection (see `walkSideEffectsRecursive`).
939
+ * @type {ModuleGraph | undefined}
940
+ */
941
+ this._sideEffectsStateGraph = undefined;
942
+ /** @type {ConnectionState | undefined} */
943
+ this._sideEffectsStateValue = undefined;
503
944
  /**
504
945
  * @private
505
946
  * @type {CodeGenerationResultData}
@@ -607,6 +1048,11 @@ class NormalModule extends Module {
607
1048
  this.parserOptions = undefined;
608
1049
  this.generator = undefined;
609
1050
  this.generatorOptions = undefined;
1051
+ // Drop the side-effects memoization so a long-lived module doesn't
1052
+ // strong-reference a stale `ModuleGraph`/`Compilation` for graphs
1053
+ // that never get re-queried with a fresh one.
1054
+ this._sideEffectsStateGraph = undefined;
1055
+ this._sideEffectsStateValue = undefined;
610
1056
  }
611
1057
 
612
1058
  /**
@@ -779,11 +1225,8 @@ class NormalModule extends Module {
779
1225
  /** @type {NormalModuleLoaderContext<T>} */
780
1226
  const loaderContext = {
781
1227
  version: 2,
782
- /**
783
- * @param {import("../declarations/LoaderContext").Schema=} schema schema
784
- * @returns {T} options
785
- */
786
- getOptions: (schema) => {
1228
+ /** @type {LoaderContext<EXPECTED_ANY>["getOptions"]} */
1229
+ getOptions: (/** @type {EXPECTED_ANY} */ schema = undefined) => {
787
1230
  const loader = this.getCurrentLoader(
788
1231
  /** @type {AnyLoaderContext} */
789
1232
  (loaderContext)
@@ -830,6 +1273,7 @@ class NormalModule extends Module {
830
1273
 
831
1274
  return /** @type {T} */ (options);
832
1275
  },
1276
+ /** @type {LoaderContext<EXPECTED_ANY>["emitWarning"]} */
833
1277
  emitWarning: (warning) => {
834
1278
  if (!(warning instanceof Error)) {
835
1279
  warning = new NonErrorEmittedError(warning);
@@ -840,6 +1284,7 @@ class NormalModule extends Module {
840
1284
  })
841
1285
  );
842
1286
  },
1287
+ /** @type {LoaderContext<EXPECTED_ANY>["emitError"]} */
843
1288
  emitError: (error) => {
844
1289
  if (!(error instanceof Error)) {
845
1290
  error = new NonErrorEmittedError(error);
@@ -850,6 +1295,7 @@ class NormalModule extends Module {
850
1295
  })
851
1296
  );
852
1297
  },
1298
+ /** @type {LoaderContext<EXPECTED_ANY>["getLogger"]} */
853
1299
  getLogger: (name) => {
854
1300
  const currentLoader = this.getCurrentLoader(
855
1301
  /** @type {AnyLoaderContext} */
@@ -861,9 +1307,11 @@ class NormalModule extends Module {
861
1307
  .join("|")
862
1308
  );
863
1309
  },
1310
+ /** @type {LoaderContext<EXPECTED_ANY>["resolve"]} */
864
1311
  resolve(context, request, callback) {
865
1312
  resolver.resolve({}, context, request, getResolveContext(), callback);
866
1313
  },
1314
+ /** @type {LoaderContext<EXPECTED_ANY>["getResolve"]} */
867
1315
  getResolve(options) {
868
1316
  const child = options ? resolver.withOptions(options) : resolver;
869
1317
  return /** @type {ReturnType<import("../declarations/LoaderContext").NormalModuleLoaderContext<T>["getResolve"]>} */ (
@@ -893,8 +1341,9 @@ class NormalModule extends Module {
893
1341
  }
894
1342
  );
895
1343
  },
1344
+ /** @type {LoaderContext<EXPECTED_ANY>["emitFile"]} */
896
1345
  emitFile: (name, content, sourceMap, assetInfo) => {
897
- const buildInfo = /** @type {BuildInfo} */ (this.buildInfo);
1346
+ const buildInfo = /** @type {NormalModuleBuildInfo} */ (this.buildInfo);
898
1347
 
899
1348
  if (!buildInfo.assets) {
900
1349
  buildInfo.assets = Object.create(null);
@@ -918,7 +1367,7 @@ class NormalModule extends Module {
918
1367
  assetsInfo.set(name, assetInfo);
919
1368
  },
920
1369
  addBuildDependency: (dep) => {
921
- const buildInfo = /** @type {BuildInfo} */ (this.buildInfo);
1370
+ const buildInfo = /** @type {NormalModuleBuildInfo} */ (this.buildInfo);
922
1371
 
923
1372
  if (buildInfo.buildDependencies === undefined) {
924
1373
  buildInfo.buildDependencies = new LazySet();
@@ -1091,7 +1540,7 @@ class NormalModule extends Module {
1091
1540
  return callback();
1092
1541
  };
1093
1542
 
1094
- const buildInfo = /** @type {BuildInfo} */ (this.buildInfo);
1543
+ const buildInfo = /** @type {NormalModuleBuildInfo} */ (this.buildInfo);
1095
1544
 
1096
1545
  buildInfo.fileDependencies = new LazySet();
1097
1546
  buildInfo.contextDependencies = new LazySet();
@@ -1111,7 +1560,7 @@ class NormalModule extends Module {
1111
1560
  }
1112
1561
 
1113
1562
  if (this.loaders.length > 0) {
1114
- /** @type {BuildInfo} */
1563
+ /** @type {NormalModuleBuildInfo} */
1115
1564
  (this.buildInfo).buildDependencies = new LazySet();
1116
1565
  }
1117
1566
 
@@ -1207,7 +1656,7 @@ class NormalModule extends Module {
1207
1656
  (undefined);
1208
1657
 
1209
1658
  if (!result) {
1210
- /** @type {BuildInfo} */
1659
+ /** @type {NormalModuleBuildInfo} */
1211
1660
  (this.buildInfo).cacheable = false;
1212
1661
  return processResult(
1213
1662
  err || new Error("No result from loader-runner processing"),
@@ -1215,16 +1664,16 @@ class NormalModule extends Module {
1215
1664
  );
1216
1665
  }
1217
1666
 
1218
- const buildInfo = /** @type {BuildInfo} */ (this.buildInfo);
1667
+ const buildInfo = /** @type {NormalModuleBuildInfo} */ (this.buildInfo);
1219
1668
 
1220
1669
  const fileDependencies =
1221
- /** @type {NonNullable<KnownBuildInfo["fileDependencies"]>} */
1670
+ /** @type {NonNullable<KnownNormalModuleBuildInfo["fileDependencies"]>} */
1222
1671
  (buildInfo.fileDependencies);
1223
1672
  const contextDependencies =
1224
- /** @type {NonNullable<KnownBuildInfo["contextDependencies"]>} */
1673
+ /** @type {NonNullable<KnownNormalModuleBuildInfo["contextDependencies"]>} */
1225
1674
  (buildInfo.contextDependencies);
1226
1675
  const missingDependencies =
1227
- /** @type {NonNullable<KnownBuildInfo["missingDependencies"]>} */
1676
+ /** @type {NonNullable<KnownNormalModuleBuildInfo["missingDependencies"]>} */
1228
1677
  (buildInfo.missingDependencies);
1229
1678
 
1230
1679
  fileDependencies.addAll(result.fileDependencies);
@@ -1232,7 +1681,7 @@ class NormalModule extends Module {
1232
1681
  missingDependencies.addAll(result.missingDependencies);
1233
1682
  for (const loader of this.loaders) {
1234
1683
  const buildDependencies =
1235
- /** @type {NonNullable<KnownBuildInfo["buildDependencies"]>} */
1684
+ /** @type {NonNullable<KnownNormalModuleBuildInfo["buildDependencies"]>} */
1236
1685
  (buildInfo.buildDependencies);
1237
1686
 
1238
1687
  buildDependencies.add(loader.loader);
@@ -1314,7 +1763,7 @@ class NormalModule extends Module {
1314
1763
  }
1315
1764
  hash.update("meta");
1316
1765
  hash.update(JSON.stringify(this.buildMeta));
1317
- /** @type {BuildInfo} */
1766
+ /** @type {NormalModuleBuildInfo} */
1318
1767
  (this.buildInfo).hash = hash.digest("hex");
1319
1768
  }
1320
1769
 
@@ -1336,7 +1785,12 @@ class NormalModule extends Module {
1336
1785
  this.error = null;
1337
1786
  this.clearWarningsAndErrors();
1338
1787
  this.clearDependenciesAndBlocks();
1339
- this.buildMeta = {};
1788
+ this.buildMeta = {
1789
+ exportsType: undefined,
1790
+ defaultObject: undefined,
1791
+ strictHarmonyModule: undefined,
1792
+ async: undefined
1793
+ };
1340
1794
  this.buildInfo = {
1341
1795
  cacheable: false,
1342
1796
  parsed: true,
@@ -1347,7 +1801,16 @@ class NormalModule extends Module {
1347
1801
  valueDependencies: undefined,
1348
1802
  hash: undefined,
1349
1803
  assets: undefined,
1350
- assetsInfo: undefined
1804
+ assetsInfo: undefined,
1805
+ snapshot: undefined,
1806
+ strict: undefined,
1807
+ exportsArgument: undefined,
1808
+ moduleArgument: undefined,
1809
+ topLevelDeclarations: undefined,
1810
+ pureFunctions: undefined,
1811
+ inlineExports: undefined,
1812
+ moduleConcatenationBailout: undefined,
1813
+ needCreateRequire: undefined
1351
1814
  };
1352
1815
 
1353
1816
  const startTime = compilation.compiler.fsStartTime || Date.now();
@@ -1380,7 +1843,7 @@ class NormalModule extends Module {
1380
1843
  const handleParseResult = () => {
1381
1844
  this.dependencies.sort(
1382
1845
  concatComparators(
1383
- compareSelect((a) => a.loc, compareLocations),
1846
+ Dependency.compareLocations,
1384
1847
  keepOriginalOrder(this.dependencies)
1385
1848
  )
1386
1849
  );
@@ -1401,7 +1864,9 @@ class NormalModule extends Module {
1401
1864
  }
1402
1865
 
1403
1866
  const snapshotOptions = compilation.options.snapshot.module;
1404
- const { cacheable } = /** @type {BuildInfo} */ (this.buildInfo);
1867
+ const { cacheable } = /** @type {NormalModuleBuildInfo} */ (
1868
+ this.buildInfo
1869
+ );
1405
1870
  if (!cacheable || !snapshotOptions) {
1406
1871
  return callback();
1407
1872
  }
@@ -1414,7 +1879,7 @@ class NormalModule extends Module {
1414
1879
  */
1415
1880
  const checkDependencies = (deps) => {
1416
1881
  for (const dep of deps) {
1417
- if (!ABSOLUTE_PATH_REGEX.test(dep)) {
1882
+ if (!ABSOLUTE_PATH_REGEXP.test(dep)) {
1418
1883
  if (nonAbsoluteDependencies === undefined) {
1419
1884
  nonAbsoluteDependencies = new Set();
1420
1885
  }
@@ -1428,11 +1893,11 @@ class NormalModule extends Module {
1428
1893
  (this.context),
1429
1894
  depWithoutGlob
1430
1895
  );
1431
- if (absolute !== dep && ABSOLUTE_PATH_REGEX.test(absolute)) {
1896
+ if (absolute !== dep && ABSOLUTE_PATH_REGEXP.test(absolute)) {
1432
1897
  (depWithoutGlob !== dep
1433
- ? /** @type {NonNullable<KnownBuildInfo["contextDependencies"]>} */
1898
+ ? /** @type {NonNullable<KnownNormalModuleBuildInfo["contextDependencies"]>} */
1434
1899
  (
1435
- /** @type {BuildInfo} */
1900
+ /** @type {NormalModuleBuildInfo} */
1436
1901
  (this.buildInfo).contextDependencies
1437
1902
  )
1438
1903
  : deps
@@ -1444,15 +1909,15 @@ class NormalModule extends Module {
1444
1909
  }
1445
1910
  }
1446
1911
  };
1447
- const buildInfo = /** @type {BuildInfo} */ (this.buildInfo);
1912
+ const buildInfo = /** @type {NormalModuleBuildInfo} */ (this.buildInfo);
1448
1913
  const fileDependencies =
1449
- /** @type {NonNullable<KnownBuildInfo["fileDependencies"]>} */
1914
+ /** @type {NonNullable<KnownNormalModuleBuildInfo["fileDependencies"]>} */
1450
1915
  (buildInfo.fileDependencies);
1451
1916
  const contextDependencies =
1452
- /** @type {NonNullable<KnownBuildInfo["contextDependencies"]>} */
1917
+ /** @type {NonNullable<KnownNormalModuleBuildInfo["contextDependencies"]>} */
1453
1918
  (buildInfo.contextDependencies);
1454
1919
  const missingDependencies =
1455
- /** @type {NonNullable<KnownBuildInfo["missingDependencies"]>} */
1920
+ /** @type {NonNullable<KnownNormalModuleBuildInfo["missingDependencies"]>} */
1456
1921
  (buildInfo.missingDependencies);
1457
1922
  checkDependencies(fileDependencies);
1458
1923
  checkDependencies(missingDependencies);
@@ -1498,7 +1963,7 @@ class NormalModule extends Module {
1498
1963
  const noParseRule = options.module && options.module.noParse;
1499
1964
  if (this.shouldPreventParsing(noParseRule, this.request)) {
1500
1965
  // We assume that we need module and exports
1501
- /** @type {BuildInfo} */
1966
+ /** @type {NormalModuleBuildInfo} */
1502
1967
  (this.buildInfo).parsed = false;
1503
1968
  this._initBuildHash(compilation);
1504
1969
  return handleBuildDone();
@@ -1512,7 +1977,11 @@ class NormalModule extends Module {
1512
1977
  current: this,
1513
1978
  module: this,
1514
1979
  compilation,
1515
- options
1980
+ options,
1981
+ harmonyNamedExports: undefined,
1982
+ harmonyStarExports: undefined,
1983
+ lastHarmonyImportOrder: undefined,
1984
+ localModules: undefined
1516
1985
  });
1517
1986
  } catch (parseErr) {
1518
1987
  handleParseError(/** @type {Error} */ (parseErr));
@@ -1539,21 +2008,16 @@ class NormalModule extends Module {
1539
2008
  * @returns {ConnectionState} how this module should be connected to referencing modules when consumed for side-effects only
1540
2009
  */
1541
2010
  getSideEffectsConnectionState(moduleGraph) {
1542
- // Trampoline `walkSideEffects` so the descent doesn't consume the
1543
- // call stack (#20986).
1544
- const stack = [walkSideEffects(this, moduleGraph)];
1545
- /** @type {ConnectionState} */
1546
- let r = false;
1547
- while (stack.length > 0) {
1548
- const step = stack[stack.length - 1].next(r);
1549
- if (step.done) {
1550
- stack.pop();
1551
- r = step.value;
1552
- } else {
1553
- stack.push(step.value);
1554
- }
1555
- }
1556
- return r;
2011
+ // Fresh per-walk context; re-entrant calls (e.g.
2012
+ // `ConcatenatedModule.getSideEffectsConnectionState` delegating back
2013
+ // through here) get their own and can't clobber the outer walk.
2014
+ return walkSideEffectsRecursive(
2015
+ this,
2016
+ moduleGraph,
2017
+ 0,
2018
+ getHarmonyImportSideEffectDependency(),
2019
+ { circular: false }
2020
+ );
1557
2021
  }
1558
2022
 
1559
2023
  /**
@@ -1569,6 +2033,18 @@ class NormalModule extends Module {
1569
2033
  return this._sourceTypes;
1570
2034
  }
1571
2035
 
2036
+ /**
2037
+ * Freshly recomputed source types when they depend on incoming connections, for chunk-graph cache invalidation; undefined otherwise. #20800
2038
+ * @returns {SourceTypes | undefined} source types or undefined
2039
+ */
2040
+ getReferencedSourceTypes() {
2041
+ const generator = /** @type {Generator} */ (this.generator);
2042
+ // Bypass the _sourceTypes cache: it may be stale when the module is not rebuilt.
2043
+ return generator.getTypesDependOnIncomingConnections()
2044
+ ? generator.getTypes(this)
2045
+ : undefined;
2046
+ }
2047
+
1572
2048
  /**
1573
2049
  * Generates code and runtime requirements for this module.
1574
2050
  * @param {CodeGenerationContext} context context for code generation
@@ -1587,7 +2063,7 @@ class NormalModule extends Module {
1587
2063
  /** @type {RuntimeRequirements} */
1588
2064
  const runtimeRequirements = new Set();
1589
2065
 
1590
- const { parsed } = /** @type {BuildInfo} */ (this.buildInfo);
2066
+ const { parsed } = /** @type {NormalModuleBuildInfo} */ (this.buildInfo);
1591
2067
 
1592
2068
  if (!parsed) {
1593
2069
  runtimeRequirements.add(RuntimeGlobals.module);
@@ -1643,7 +2119,8 @@ class NormalModule extends Module {
1643
2119
  const resultEntry = {
1644
2120
  sources,
1645
2121
  runtimeRequirements,
1646
- data: this._codeGeneratorData
2122
+ data: this._codeGeneratorData,
2123
+ hash: undefined
1647
2124
  };
1648
2125
  return resultEntry;
1649
2126
  }
@@ -1679,7 +2156,7 @@ class NormalModule extends Module {
1679
2156
  if (this.error) return callback(null, true);
1680
2157
 
1681
2158
  const { cacheable, snapshot, valueDependencies } =
1682
- /** @type {BuildInfo} */ (this.buildInfo);
2159
+ /** @type {NormalModuleBuildInfo} */ (this.buildInfo);
1683
2160
 
1684
2161
  // always build when module is not cacheable
1685
2162
  if (!cacheable) return callback(null, true);
@@ -1760,7 +2237,7 @@ class NormalModule extends Module {
1760
2237
  buildDependencies
1761
2238
  ) {
1762
2239
  const { snapshot, buildDependencies: buildDeps } =
1763
- /** @type {BuildInfo} */ (this.buildInfo);
2240
+ /** @type {NormalModuleBuildInfo} */ (this.buildInfo);
1764
2241
  if (snapshot) {
1765
2242
  fileDependencies.addAll(snapshot.getFileIterable());
1766
2243
  contextDependencies.addAll(snapshot.getContextIterable());
@@ -1770,7 +2247,7 @@ class NormalModule extends Module {
1770
2247
  fileDependencies: fileDeps,
1771
2248
  contextDependencies: contextDeps,
1772
2249
  missingDependencies: missingDeps
1773
- } = /** @type {BuildInfo} */ (this.buildInfo);
2250
+ } = /** @type {NormalModuleBuildInfo} */ (this.buildInfo);
1774
2251
  if (fileDeps !== undefined) fileDependencies.addAll(fileDeps);
1775
2252
  if (contextDeps !== undefined) contextDependencies.addAll(contextDeps);
1776
2253
  if (missingDeps !== undefined) missingDependencies.addAll(missingDeps);
@@ -1787,7 +2264,7 @@ class NormalModule extends Module {
1787
2264
  * @returns {void}
1788
2265
  */
1789
2266
  updateHash(hash, context) {
1790
- const buildInfo = /** @type {BuildInfo} */ (this.buildInfo);
2267
+ const buildInfo = /** @type {NormalModuleBuildInfo} */ (this.buildInfo);
1791
2268
  hash.update(
1792
2269
  /** @type {string} */
1793
2270
  (buildInfo.hash)
@@ -1821,6 +2298,7 @@ class NormalModule extends Module {
1821
2298
  write(this._lastSuccessfulBuildMeta);
1822
2299
  write(this._forceBuild);
1823
2300
  write(this._codeGeneratorData);
2301
+ write(this.hot);
1824
2302
  super.serialize(context);
1825
2303
  }
1826
2304
 
@@ -1829,7 +2307,8 @@ class NormalModule extends Module {
1829
2307
  * @returns {NormalModule} module
1830
2308
  */
1831
2309
  static deserialize(context) {
1832
- const obj = new NormalModule({
2310
+ // `new this` so subclasses without extra constructor options inherit this method
2311
+ const obj = new this({
1833
2312
  // will be deserialized by Module
1834
2313
  layer: /** @type {EXPECTED_ANY} */ (null),
1835
2314
  type: "",
@@ -1863,6 +2342,7 @@ class NormalModule extends Module {
1863
2342
  this._lastSuccessfulBuildMeta = read();
1864
2343
  this._forceBuild = read();
1865
2344
  this._codeGeneratorData = read();
2345
+ this.hot = read();
1866
2346
  super.deserialize(context);
1867
2347
  }
1868
2348
  }