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
@@ -8,6 +8,7 @@
8
8
  const { UsageState } = require("../ExportsInfo");
9
9
  const JavascriptParser = require("../javascript/JavascriptParser");
10
10
 
11
+ /** @typedef {import("../Compilation")} Compilation */
11
12
  /** @typedef {import("../Dependency")} Dependency */
12
13
  /** @typedef {import("../Dependency").GetConditionFn} GetConditionFn */
13
14
  /** @typedef {import("../Module")} Module */
@@ -15,11 +16,12 @@ const JavascriptParser = require("../javascript/JavascriptParser");
15
16
  /** @typedef {import("../Parser").ParserState} ParserState */
16
17
  /** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
17
18
 
19
+ /** @typedef {boolean | ((compilation: Compilation, module: Module) => boolean)} PureCondition */
18
20
  /** @typedef {Set<string | TopLevelSymbol>} InnerGraphValueSet */
19
21
  /** @typedef {InnerGraphValueSet | true} InnerGraphValue */
20
22
  /** @typedef {TopLevelSymbol | null} InnerGraphKey */
21
23
  /** @typedef {Map<InnerGraphKey, InnerGraphValue | undefined>} InnerGraph */
22
- /** @typedef {(value: boolean | Set<string> | undefined) => void} UsageCallback */
24
+ /** @typedef {(value: boolean | Set<string> | undefined, module: Module) => void} UsageCallback */
23
25
 
24
26
  /**
25
27
  * Defines the state object type used by this module.
@@ -30,225 +32,398 @@ const JavascriptParser = require("../javascript/JavascriptParser");
30
32
  */
31
33
 
32
34
  /** @typedef {false | StateObject} State */
35
+ /** @typedef {string | TopLevelSymbol | true} Usage */
36
+ /** @typedef {Set<string> | boolean} UsedByExports */
37
+ /** @typedef {Dependency & { usedByExports: UsedByExports | undefined }} DependencyWithUsedByExports */
33
38
 
34
39
  class TopLevelSymbol {
35
40
  /**
36
41
  * Creates an instance of TopLevelSymbol.
37
42
  * @param {string} name name of the variable
43
+ * @param {PureCondition=} pure pure condition
38
44
  */
39
- constructor(name) {
45
+ constructor(name, pure = false) {
40
46
  /** @type {string} */
41
47
  this.name = name;
42
- }
43
- }
44
48
 
45
- module.exports.TopLevelSymbol = TopLevelSymbol;
49
+ /** @type {boolean} */
50
+ this.conditional = false;
51
+ /** @type {boolean} */
52
+ this._pure = false;
53
+ /** @type {((compilation: Compilation, module: Module) => boolean) | undefined} */
54
+ this.pureFn = undefined;
46
55
 
47
- /** @type {WeakMap<ParserState, State>} */
48
- const parserStateMap = new WeakMap();
49
- const topLevelSymbolTag = Symbol("top level symbol");
56
+ this.setPure(pure);
57
+ }
50
58
 
51
- /**
52
- * Returns state.
53
- * @param {ParserState} parserState parser state
54
- * @returns {State | undefined} state
55
- */
56
- function getState(parserState) {
57
- return parserStateMap.get(parserState);
58
- }
59
+ /**
60
+ * Sets the pure condition
61
+ * @param {PureCondition} pure pure condition
62
+ * @returns {void}
63
+ */
64
+ setPure(pure) {
65
+ this.conditional = typeof pure === "function";
66
+ this._pure = pure === true;
67
+ this.pureFn = typeof pure === "function" ? pure : undefined;
68
+ }
59
69
 
60
- /**
61
- * Processes the provided state.
62
- * @param {ParserState} state parser state
63
- * @param {TopLevelSymbol | null} symbol the symbol, or null for all symbols
64
- * @param {Usage} usage usage data
65
- * @returns {void}
66
- */
67
- module.exports.addUsage = (state, symbol, usage) => {
68
- const innerGraphState = getState(state);
69
-
70
- if (innerGraphState) {
71
- const { innerGraph } = innerGraphState;
72
- const info = innerGraph.get(symbol);
73
- if (usage === true) {
74
- innerGraph.set(symbol, true);
75
- } else if (info === undefined) {
76
- innerGraph.set(symbol, new Set([usage]));
77
- } else if (info !== true) {
78
- info.add(usage);
79
- }
70
+ /**
71
+ * @param {Compilation} compilation compilation
72
+ * @param {Module} module module
73
+ * @returns {boolean} if the symbol is pure
74
+ */
75
+ isPure(compilation, module) {
76
+ if (!this.conditional) return this._pure;
77
+
78
+ const pureFn =
79
+ /** @type {(compilation: Compilation, module: Module) => boolean} */ (
80
+ this.pureFn
81
+ );
82
+ return pureFn(compilation, module);
80
83
  }
81
- };
84
+ }
82
85
 
83
- /** @typedef {string | TopLevelSymbol | true} Usage */
86
+ module.exports.TopLevelSymbol = TopLevelSymbol;
84
87
 
85
- /**
86
- * Processes the provided parser.
87
- * @param {JavascriptParser} parser the parser
88
- * @param {string} name name of variable
89
- * @param {Usage} usage usage data
90
- * @returns {void}
91
- */
92
- module.exports.addVariableUsage = (parser, name, usage) => {
93
- const symbol =
94
- /** @type {TopLevelSymbol} */ (
95
- parser.getTagData(name, topLevelSymbolTag)
96
- ) || module.exports.tagTopLevelSymbol(parser, name);
97
- if (symbol) {
98
- module.exports.addUsage(parser.state, symbol, usage);
99
- }
100
- };
88
+ const topLevelSymbolTag = Symbol("top level symbol");
101
89
 
102
- /**
103
- * Processes the provided parser state.
104
- * @param {ParserState} parserState parser state
105
- * @returns {void}
106
- */
107
- module.exports.bailout = (parserState) => {
108
- parserStateMap.set(parserState, false);
109
- };
90
+ /** @type {WeakMap<Compilation, InnerGraphUtils>} */
91
+ const innerGraphByCompilation = new WeakMap();
110
92
 
111
93
  /**
112
- * Processes the provided parser state.
113
- * @param {ParserState} parserState parser state
114
- * @returns {void}
94
+ * @typedef {object} InnerGraphUtils
95
+ * @property {(parserState: ParserState) => void} enable
96
+ * @property {(parserState: ParserState) => void} bailout
97
+ * @property {(parserState: ParserState) => boolean} isEnabled
98
+ * @property {(parserState: ParserState, symbol: TopLevelSymbol | null, usage: Usage) => void} addUsage
99
+ * @property {(parserState: ParserState, onUsageCallback: UsageCallback) => void} onUsage
100
+ * @property {(parserState: ParserState, symbol: TopLevelSymbol | undefined) => void} setTopLevelSymbol
101
+ * @property {(parserState: ParserState) => TopLevelSymbol | void} getTopLevelSymbol
102
+ * @property {(parser: JavascriptParser, name: string, pure?: PureCondition) => TopLevelSymbol | undefined} tagTopLevelSymbol
103
+ * @property {(parser: JavascriptParser, name: string, usage: Usage) => void} addVariableUsage
104
+ * @property {(module: Module) => void} inferDependencyUsage
105
+ * @property {(module: Module) => void} release
115
106
  */
116
- module.exports.enable = (parserState) => {
117
- const state = parserStateMap.get(parserState);
118
- if (state === false) {
119
- return;
120
- }
121
- parserStateMap.set(parserState, {
122
- innerGraph: new Map(),
123
- currentTopLevelSymbol: undefined,
124
- usageCallbackMap: new Map()
125
- });
126
- };
127
-
128
- /** @typedef {Set<string> | boolean} UsedByExports */
129
107
 
130
108
  /**
131
- * Usage callback map.
109
+ * Returns false, when unused. Otherwise true.
132
110
  * @param {Dependency} dependency the dependency
133
111
  * @param {UsedByExports | undefined} usedByExports usedByExports info
134
112
  * @param {ModuleGraph} moduleGraph moduleGraph
135
- * @returns {null | false | GetConditionFn} function to determine if the connection is active
113
+ * @param {RuntimeSpec} runtime runtime
114
+ * @returns {boolean} false, when unused. Otherwise true
136
115
  */
137
- module.exports.getDependencyUsedByExportsCondition = (
116
+ function isDependencyUsedByExports(
138
117
  dependency,
139
118
  usedByExports,
140
- moduleGraph
141
- ) => {
119
+ moduleGraph,
120
+ runtime
121
+ ) {
142
122
  if (usedByExports === false) return false;
143
123
  if (usedByExports !== true && usedByExports !== undefined) {
144
124
  const selfModule =
145
125
  /** @type {Module} */
146
126
  (moduleGraph.getParentModule(dependency));
147
127
  const exportsInfo = moduleGraph.getExportsInfo(selfModule);
148
- return (_connections, runtime) => {
149
- for (const exportName of usedByExports) {
150
- if (exportsInfo.getUsed(exportName, runtime) !== UsageState.Unused) {
151
- return true;
152
- }
128
+ for (const exportName of usedByExports) {
129
+ if (exportsInfo.getUsed(exportName, runtime) !== UsageState.Unused) {
130
+ return true;
153
131
  }
154
- return false;
155
- };
132
+ }
133
+ return false;
156
134
  }
157
- return null;
158
- };
135
+ return true;
136
+ }
159
137
 
160
138
  /**
161
- * Returns usage data.
162
- * @param {ParserState} state parser state
163
- * @returns {TopLevelSymbol | void} usage data
139
+ * Returns dependency condition
140
+ * @param {Dependency} dependency the dependency
141
+ * @param {ModuleGraph} moduleGraph moduleGraph
142
+ * @returns {null | false | GetConditionFn} function to determine if the connection is active
164
143
  */
165
- module.exports.getTopLevelSymbol = (state) => {
166
- const innerGraphState = getState(state);
167
-
168
- if (innerGraphState) {
169
- return innerGraphState.currentTopLevelSymbol;
144
+ module.exports.getDependencyUsedByExportsCondition = (
145
+ dependency,
146
+ moduleGraph
147
+ ) => {
148
+ switch (
149
+ /** @type {DependencyWithUsedByExports} */ (dependency).usedByExports
150
+ ) {
151
+ case false:
152
+ return false;
153
+ case true:
154
+ return null;
155
+ default:
156
+ return (_connections, runtime) =>
157
+ isDependencyUsedByExports(
158
+ dependency,
159
+ /** @type {DependencyWithUsedByExports} */ (dependency).usedByExports,
160
+ moduleGraph,
161
+ runtime
162
+ );
170
163
  }
171
164
  };
172
165
 
173
166
  /**
174
- * Processes the provided state.
175
- * @param {ParserState} state parser state
176
- * @returns {void}
167
+ * Returns the InnerGraph utils scoped to a single compilation.
168
+ * @param {Compilation} compilation the compilation
169
+ * @returns {InnerGraphUtils} utils
177
170
  */
178
- module.exports.inferDependencyUsage = (state) => {
179
- const innerGraphState = getState(state);
171
+ module.exports.getInnerGraphUtils = (compilation) => {
172
+ let utils = innerGraphByCompilation.get(compilation);
173
+ if (utils) return utils;
174
+
175
+ /** @type {WeakMap<Module, State>} */
176
+ const states = new WeakMap();
177
+
178
+ /**
179
+ * @param {ParserState} parserState parser state
180
+ * @returns {State | undefined} state
181
+ */
182
+ function getState(parserState) {
183
+ return states.get(parserState.module);
184
+ }
185
+
186
+ /**
187
+ * @param {ParserState} parserState parser state
188
+ * @returns {void}
189
+ */
190
+ function enable(parserState) {
191
+ const state = states.get(parserState.module);
192
+ if (state === false) {
193
+ return;
194
+ }
195
+ states.set(parserState.module, {
196
+ innerGraph: new Map(),
197
+ currentTopLevelSymbol: undefined,
198
+ usageCallbackMap: new Map()
199
+ });
200
+ }
201
+
202
+ /**
203
+ * @param {ParserState} parserState parser state
204
+ * @returns {void}
205
+ */
206
+ function bailout(parserState) {
207
+ states.set(parserState.module, false);
208
+ }
209
+
210
+ /**
211
+ * @param {ParserState} parserState parser state
212
+ * @returns {boolean} true, when enabled
213
+ */
214
+ function isEnabled(parserState) {
215
+ return Boolean(states.get(parserState.module));
216
+ }
217
+
218
+ /**
219
+ * @param {ParserState} state parser state
220
+ * @param {TopLevelSymbol | null} symbol the symbol, or null for all symbols
221
+ * @param {Usage} usage usage data
222
+ * @returns {void}
223
+ */
224
+ function addUsage(state, symbol, usage) {
225
+ const innerGraphState = getState(state);
226
+
227
+ if (innerGraphState) {
228
+ const { innerGraph } = innerGraphState;
229
+ const info = innerGraph.get(symbol);
230
+ if (usage === true) {
231
+ innerGraph.set(symbol, true);
232
+ } else if (info === undefined) {
233
+ innerGraph.set(symbol, new Set([usage]));
234
+ } else if (info !== true) {
235
+ info.add(usage);
236
+ }
237
+ }
238
+ }
239
+
240
+ /**
241
+ * @param {JavascriptParser} parser the parser
242
+ * @param {string} name name of variable
243
+ * @param {Usage} usage usage data
244
+ * @returns {void}
245
+ */
246
+ function addVariableUsage(parser, name, usage) {
247
+ const symbol =
248
+ /** @type {TopLevelSymbol} */ (
249
+ parser.getTagData(name, topLevelSymbolTag)
250
+ ) || tagTopLevelSymbol(parser, name);
251
+ if (symbol) {
252
+ addUsage(parser.state, symbol, usage);
253
+ }
254
+ }
255
+
256
+ /**
257
+ * @param {ParserState} state parser state
258
+ * @returns {TopLevelSymbol | void} usage data
259
+ */
260
+ function getTopLevelSymbol(state) {
261
+ const innerGraphState = getState(state);
262
+
263
+ if (innerGraphState) {
264
+ return innerGraphState.currentTopLevelSymbol;
265
+ }
266
+ }
180
267
 
181
- if (!innerGraphState) {
182
- return;
268
+ /**
269
+ * @param {ParserState} state parser state
270
+ * @param {TopLevelSymbol | undefined} symbol the symbol
271
+ */
272
+ function setTopLevelSymbol(state, symbol) {
273
+ const innerGraphState = getState(state);
274
+
275
+ if (innerGraphState) {
276
+ innerGraphState.currentTopLevelSymbol = symbol;
277
+ }
183
278
  }
184
279
 
185
- const { innerGraph, usageCallbackMap } = innerGraphState;
186
- /** @type {Map<InnerGraphKey, InnerGraphValueSet | undefined>} */
187
- const processed = new Map();
188
- // flatten graph to terminal nodes (string, undefined or true)
189
- const nonTerminal = new Set(innerGraph.keys());
190
- while (nonTerminal.size > 0) {
191
- for (const key of nonTerminal) {
192
- /** @type {InnerGraphValue} */
193
- let newSet = new Set();
194
- let isTerminal = true;
195
- const value = innerGraph.get(key);
196
- let alreadyProcessed = processed.get(key);
197
- if (alreadyProcessed === undefined) {
198
- /** @type {InnerGraphValueSet} */
199
- alreadyProcessed = new Set();
200
- processed.set(key, alreadyProcessed);
280
+ /**
281
+ * @param {ParserState} state parser state
282
+ * @param {UsageCallback} onUsageCallback on usage callback
283
+ */
284
+ function onUsage(state, onUsageCallback) {
285
+ const innerGraphState = getState(state);
286
+
287
+ if (innerGraphState) {
288
+ const { usageCallbackMap, currentTopLevelSymbol } = innerGraphState;
289
+ if (currentTopLevelSymbol) {
290
+ let callbacks = usageCallbackMap.get(currentTopLevelSymbol);
291
+
292
+ if (callbacks === undefined) {
293
+ /** @type {Set<UsageCallback>} */
294
+ callbacks = new Set();
295
+ usageCallbackMap.set(currentTopLevelSymbol, callbacks);
296
+ }
297
+
298
+ callbacks.add(onUsageCallback);
299
+ } else {
300
+ onUsageCallback(true, state.module);
201
301
  }
202
- if (value !== true && value !== undefined) {
203
- for (const item of value) {
204
- alreadyProcessed.add(item);
302
+ } else {
303
+ onUsageCallback(undefined, state.module);
304
+ }
305
+ }
306
+
307
+ /**
308
+ * @param {JavascriptParser} parser parser
309
+ * @param {string} name name of variable
310
+ * @param {PureCondition=} pure pure condition
311
+ * @returns {TopLevelSymbol=} symbol
312
+ */
313
+ function tagTopLevelSymbol(parser, name, pure) {
314
+ const innerGraphState = getState(parser.state);
315
+ if (!innerGraphState) return;
316
+
317
+ parser.defineVariable(name);
318
+
319
+ const existingTag = /** @type {TopLevelSymbol} */ (
320
+ parser.getTagData(name, topLevelSymbolTag)
321
+ );
322
+ if (existingTag) {
323
+ if (pure !== undefined) {
324
+ existingTag.setPure(pure);
325
+ }
326
+ return existingTag;
327
+ }
328
+
329
+ const symbol = new TopLevelSymbol(name, pure);
330
+ parser.tagVariable(
331
+ name,
332
+ topLevelSymbolTag,
333
+ symbol,
334
+ JavascriptParser.VariableInfoFlags.Normal
335
+ );
336
+ return symbol;
337
+ }
338
+
339
+ /**
340
+ * @param {Module} module module
341
+ * @returns {void}
342
+ */
343
+ function inferDependencyUsage(module) {
344
+ const innerGraphState = states.get(module);
345
+
346
+ if (!innerGraphState) {
347
+ return;
348
+ }
349
+
350
+ const { innerGraph, usageCallbackMap } = innerGraphState;
351
+ /** @type {Map<InnerGraphKey, InnerGraphValueSet | undefined>} */
352
+ const processed = new Map();
353
+ // flatten graph to terminal nodes (string, undefined or true)
354
+ const nonTerminal = new Set(innerGraph.keys());
355
+ while (nonTerminal.size > 0) {
356
+ for (const key of nonTerminal) {
357
+ if (key !== null && !key.isPure(compilation, module)) {
358
+ innerGraph.set(key, true);
359
+ nonTerminal.delete(key);
360
+ continue;
205
361
  }
206
- for (const item of value) {
207
- if (typeof item === "string") {
208
- newSet.add(item);
209
- } else {
210
- const itemValue = innerGraph.get(item);
211
- if (itemValue === true) {
362
+
363
+ /** @type {InnerGraphValue} */
364
+ let newSet = new Set();
365
+ let isTerminal = true;
366
+ const value = innerGraph.get(key);
367
+ let alreadyProcessed = processed.get(key);
368
+ if (alreadyProcessed === undefined) {
369
+ /** @type {InnerGraphValueSet} */
370
+ alreadyProcessed = new Set();
371
+ processed.set(key, alreadyProcessed);
372
+ }
373
+ if (value !== true && value !== undefined) {
374
+ for (const item of value) {
375
+ alreadyProcessed.add(item);
376
+ }
377
+ for (const item of value) {
378
+ if (typeof item === "string") {
379
+ newSet.add(item);
380
+ } else if (!item.isPure(compilation, module)) {
212
381
  newSet = true;
213
382
  break;
214
- }
215
- if (itemValue !== undefined) {
216
- for (const i of itemValue) {
217
- if (i === key) continue;
218
- if (alreadyProcessed.has(i)) continue;
219
- newSet.add(i);
220
- if (typeof i !== "string") {
221
- isTerminal = false;
383
+ } else {
384
+ const itemValue = innerGraph.get(item);
385
+ if (itemValue === true) {
386
+ newSet = true;
387
+ break;
388
+ }
389
+ if (itemValue !== undefined) {
390
+ for (const i of itemValue) {
391
+ if (i === key) continue;
392
+ if (alreadyProcessed.has(i)) continue;
393
+ newSet.add(i);
394
+ if (typeof i !== "string") {
395
+ isTerminal = false;
396
+ }
222
397
  }
223
398
  }
224
399
  }
225
400
  }
401
+ if (newSet === true) {
402
+ innerGraph.set(key, true);
403
+ } else if (newSet.size === 0) {
404
+ innerGraph.set(key, undefined);
405
+ } else {
406
+ innerGraph.set(key, newSet);
407
+ }
226
408
  }
227
- if (newSet === true) {
228
- innerGraph.set(key, true);
229
- } else if (newSet.size === 0) {
230
- innerGraph.set(key, undefined);
231
- } else {
232
- innerGraph.set(key, newSet);
233
- }
234
- }
235
- if (isTerminal) {
236
- nonTerminal.delete(key);
237
-
238
- // For the global key, merge with all other keys
239
- if (key === null) {
240
- const globalValue = innerGraph.get(null);
241
- if (globalValue) {
242
- for (const [key, value] of innerGraph) {
243
- if (key !== null && value !== true) {
244
- if (globalValue === true) {
245
- innerGraph.set(key, true);
246
- } else {
247
- const newSet = new Set(value);
248
- for (const item of globalValue) {
249
- newSet.add(item);
409
+ if (isTerminal) {
410
+ nonTerminal.delete(key);
411
+
412
+ // For the global key, merge with all other keys
413
+ if (key === null) {
414
+ const globalValue = innerGraph.get(null);
415
+ if (globalValue) {
416
+ for (const [key, value] of innerGraph) {
417
+ if (key !== null && value !== true) {
418
+ if (globalValue === true) {
419
+ innerGraph.set(key, true);
420
+ } else {
421
+ const newSet = new Set(value);
422
+ for (const item of globalValue) {
423
+ newSet.add(item);
424
+ }
425
+ innerGraph.set(key, newSet);
250
426
  }
251
- innerGraph.set(key, newSet);
252
427
  }
253
428
  }
254
429
  }
@@ -256,128 +431,50 @@ module.exports.inferDependencyUsage = (state) => {
256
431
  }
257
432
  }
258
433
  }
259
- }
260
434
 
261
- /** @type {Map<Dependency, true | Set<string>>} */
262
- for (const [symbol, callbacks] of usageCallbackMap) {
263
- const usage = /** @type {true | Set<string> | undefined} */ (
264
- innerGraph.get(symbol)
265
- );
266
- for (const callback of callbacks) {
267
- callback(usage === undefined ? false : usage);
268
- }
269
- }
270
- };
435
+ /** @type {Map<Dependency, true | Set<string>>} */
436
+ for (const [symbol, callbacks] of usageCallbackMap) {
437
+ const usage = symbol.isPure(compilation, module)
438
+ ? /** @type {true | Set<string> | undefined} */ (innerGraph.get(symbol))
439
+ : true;
271
440
 
272
- /**
273
- * Returns false, when unused. Otherwise true.
274
- * @param {Dependency} dependency the dependency
275
- * @param {UsedByExports | undefined} usedByExports usedByExports info
276
- * @param {ModuleGraph} moduleGraph moduleGraph
277
- * @param {RuntimeSpec} runtime runtime
278
- * @returns {boolean} false, when unused. Otherwise true
279
- */
280
- module.exports.isDependencyUsedByExports = (
281
- dependency,
282
- usedByExports,
283
- moduleGraph,
284
- runtime
285
- ) => {
286
- if (usedByExports === false) return false;
287
- if (usedByExports !== true && usedByExports !== undefined) {
288
- const selfModule =
289
- /** @type {Module} */
290
- (moduleGraph.getParentModule(dependency));
291
- const exportsInfo = moduleGraph.getExportsInfo(selfModule);
292
- let used = false;
293
- for (const exportName of usedByExports) {
294
- if (exportsInfo.getUsed(exportName, runtime) !== UsageState.Unused) {
295
- used = true;
441
+ for (const callback of callbacks) {
442
+ callback(usage === undefined ? false : usage, module);
296
443
  }
297
444
  }
298
- if (!used) return false;
299
445
  }
300
- return true;
301
- };
302
-
303
- /**
304
- * Returns true, when enabled.
305
- * @param {ParserState} parserState parser state
306
- * @returns {boolean} true, when enabled
307
- */
308
- module.exports.isEnabled = (parserState) => {
309
- const state = parserStateMap.get(parserState);
310
- return Boolean(state);
311
- };
312
-
313
- /**
314
- * Processes the provided state.
315
- * @param {ParserState} state parser state
316
- * @param {UsageCallback} onUsageCallback on usage callback
317
- */
318
- module.exports.onUsage = (state, onUsageCallback) => {
319
- const innerGraphState = getState(state);
320
-
321
- if (innerGraphState) {
322
- const { usageCallbackMap, currentTopLevelSymbol } = innerGraphState;
323
- if (currentTopLevelSymbol) {
324
- let callbacks = usageCallbackMap.get(currentTopLevelSymbol);
325
-
326
- if (callbacks === undefined) {
327
- /** @type {Set<UsageCallback>} */
328
- callbacks = new Set();
329
- usageCallbackMap.set(currentTopLevelSymbol, callbacks);
330
- }
331
446
 
332
- callbacks.add(onUsageCallback);
333
- } else {
334
- onUsageCallback(true);
335
- }
336
- } else {
337
- onUsageCallback(undefined);
447
+ /**
448
+ * @param {Module} module module
449
+ * @returns {void}
450
+ */
451
+ function release(module) {
452
+ states.delete(module);
338
453
  }
339
- };
340
-
341
- /**
342
- * Processes the provided state.
343
- * @param {ParserState} state parser state
344
- * @param {TopLevelSymbol | undefined} symbol the symbol
345
- */
346
- module.exports.setTopLevelSymbol = (state, symbol) => {
347
- const innerGraphState = getState(state);
348
454
 
349
- if (innerGraphState) {
350
- innerGraphState.currentTopLevelSymbol = symbol;
351
- }
455
+ utils = {
456
+ enable,
457
+ bailout,
458
+ isEnabled,
459
+ addUsage,
460
+ addVariableUsage,
461
+ getTopLevelSymbol,
462
+ setTopLevelSymbol,
463
+ onUsage,
464
+ tagTopLevelSymbol,
465
+ inferDependencyUsage,
466
+ release
467
+ };
468
+ innerGraphByCompilation.set(compilation, utils);
469
+ return utils;
352
470
  };
353
471
 
354
472
  /**
355
- * Returns symbol.
356
- * @param {JavascriptParser} parser parser
357
- * @param {string} name name of variable
358
- * @returns {TopLevelSymbol | undefined} symbol
473
+ * Usage callback map.
474
+ * @param {Dependency} dependency the dependency
475
+ * @param {UsedByExports | undefined} usedByExports usedByExports info
476
+ * @param {ModuleGraph} moduleGraph moduleGraph
477
+ * @returns {null | false | GetConditionFn} function to determine if the connection is active
359
478
  */
360
- module.exports.tagTopLevelSymbol = (parser, name) => {
361
- const innerGraphState = getState(parser.state);
362
- if (!innerGraphState) return;
363
-
364
- parser.defineVariable(name);
365
-
366
- const existingTag = /** @type {TopLevelSymbol} */ (
367
- parser.getTagData(name, topLevelSymbolTag)
368
- );
369
- if (existingTag) {
370
- return existingTag;
371
- }
372
-
373
- const symbol = new TopLevelSymbol(name);
374
- parser.tagVariable(
375
- name,
376
- topLevelSymbolTag,
377
- symbol,
378
- JavascriptParser.VariableInfoFlags.Normal
379
- );
380
- return symbol;
381
- };
382
479
 
383
480
  module.exports.topLevelSymbolTag = topLevelSymbolTag;