webpack 5.107.2 → 5.108.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (357) hide show
  1. package/hot/dev-server.js +2 -0
  2. package/lib/APIPlugin.js +8 -4
  3. package/lib/CacheFacade.js +7 -0
  4. package/lib/Chunk.js +4 -0
  5. package/lib/ChunkGraph.js +30 -9
  6. package/lib/CircularModulesPlugin.js +190 -0
  7. package/lib/CleanPlugin.js +2 -1
  8. package/lib/Compilation.js +396 -65
  9. package/lib/Compiler.js +25 -11
  10. package/lib/ConcatenationScope.js +10 -3
  11. package/lib/ContextExclusionPlugin.js +1 -0
  12. package/lib/ContextModule.js +92 -47
  13. package/lib/ContextReplacementPlugin.js +4 -0
  14. package/lib/DefinePlugin.js +89 -15
  15. package/lib/Dependency.js +111 -7
  16. package/lib/EntryOptionPlugin.js +39 -2
  17. package/lib/EntryPlugin.js +2 -0
  18. package/lib/ExportsInfo.js +314 -73
  19. package/lib/ExternalModule.js +82 -34
  20. package/lib/ExternalModuleFactoryPlugin.js +1 -0
  21. package/lib/ExternalsPlugin.js +1 -0
  22. package/lib/FileSystemInfo.js +173 -23
  23. package/lib/FlagAllModulesAsUsedPlugin.js +1 -5
  24. package/lib/FlagDependencyExportsPlugin.js +23 -0
  25. package/lib/FlagDependencyUsagePlugin.js +87 -5
  26. package/lib/FlagEntryExportAsUsedPlugin.js +2 -0
  27. package/lib/Generator.js +8 -0
  28. package/lib/HotModuleReplacementPlugin.js +65 -28
  29. package/lib/IgnorePlugin.js +1 -0
  30. package/lib/InitFragment.js +5 -0
  31. package/lib/JavascriptMetaInfoPlugin.js +7 -5
  32. package/lib/LazyBarrel.js +361 -0
  33. package/lib/LoaderTargetPlugin.js +1 -0
  34. package/lib/Module.js +21 -42
  35. package/lib/ModuleGraph.js +3 -2
  36. package/lib/ModuleProfile.js +27 -1
  37. package/lib/ModuleTemplate.js +2 -0
  38. package/lib/MultiCompiler.js +2 -0
  39. package/lib/MultiStats.js +1 -0
  40. package/lib/MultiWatching.js +2 -0
  41. package/lib/NodeStuffPlugin.js +22 -17
  42. package/lib/NormalModule.js +142 -80
  43. package/lib/NormalModuleReplacementPlugin.js +2 -0
  44. package/lib/PrefetchPlugin.js +2 -0
  45. package/lib/ProgressPlugin.js +8 -0
  46. package/lib/ProvidePlugin.js +1 -0
  47. package/lib/RawModule.js +20 -16
  48. package/lib/RecordIdsPlugin.js +1 -0
  49. package/lib/RuntimeGlobals.js +5 -0
  50. package/lib/RuntimePlugin.js +58 -26
  51. package/lib/RuntimeTemplate.js +278 -21
  52. package/lib/SelfModuleFactory.js +1 -0
  53. package/lib/SourceMapDevToolPlugin.js +3 -5
  54. package/lib/Stats.js +1 -0
  55. package/lib/Template.js +8 -2
  56. package/lib/TemplatedPathPlugin.js +473 -131
  57. package/lib/WarnCaseSensitiveModulesPlugin.js +1 -0
  58. package/lib/WarnDeprecatedOptionPlugin.js +4 -0
  59. package/lib/WarnNoModeSetPlugin.js +1 -0
  60. package/lib/WatchIgnorePlugin.js +1 -0
  61. package/lib/Watching.js +9 -0
  62. package/lib/WebpackOptionsApply.js +50 -5
  63. package/lib/asset/AssetBytesGenerator.js +11 -3
  64. package/lib/asset/AssetGenerator.js +47 -22
  65. package/lib/asset/AssetModule.js +47 -0
  66. package/lib/asset/AssetModulesPlugin.js +14 -14
  67. package/lib/asset/AssetParser.js +2 -2
  68. package/lib/asset/AssetSourceGenerator.js +8 -0
  69. package/lib/asset/RawDataUrlModule.js +12 -13
  70. package/lib/buildChunkGraph.js +64 -7
  71. package/lib/bun/BunTargetPlugin.js +48 -0
  72. package/lib/cache/AddBuildDependenciesPlugin.js +1 -0
  73. package/lib/cache/AddManagedPathsPlugin.js +3 -0
  74. package/lib/cache/IdleFileCachePlugin.js +4 -0
  75. package/lib/cache/MemoryWithGcCachePlugin.js +1 -0
  76. package/lib/cache/PackFileCacheStrategy.js +1 -0
  77. package/lib/cache/ResolverCachePlugin.js +2 -0
  78. package/lib/cache/mergeEtags.js +2 -0
  79. package/lib/cli.js +109 -19
  80. package/lib/config/browserslistTargetHandler.js +99 -0
  81. package/lib/config/defaults.js +147 -7
  82. package/lib/config/defineConfig.js +31 -0
  83. package/lib/config/normalization.js +5 -0
  84. package/lib/config/target.js +181 -2
  85. package/lib/container/ContainerEntryModule.js +15 -14
  86. package/lib/container/ContainerExposedDependency.js +2 -2
  87. package/lib/container/ContainerReferencePlugin.js +1 -1
  88. package/lib/container/FallbackDependency.js +5 -7
  89. package/lib/container/FallbackModule.js +10 -9
  90. package/lib/container/RemoteModule.js +20 -10
  91. package/lib/container/RemoteRuntimeModule.js +14 -12
  92. package/lib/css/CssGenerator.js +353 -327
  93. package/lib/css/CssInjectStyleRuntimeModule.js +36 -8
  94. package/lib/css/CssLoadingRuntimeModule.js +118 -47
  95. package/lib/css/CssModule.js +52 -23
  96. package/lib/css/CssModulesPlugin.js +107 -124
  97. package/lib/css/CssParser.js +2759 -2205
  98. package/lib/css/syntax.js +2859 -0
  99. package/lib/debug/ProfilingPlugin.js +2 -0
  100. package/lib/deno/DenoTargetPlugin.js +47 -0
  101. package/lib/dependencies/AMDDefineDependency.js +22 -17
  102. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +1 -0
  103. package/lib/dependencies/AMDRequireArrayDependency.js +7 -11
  104. package/lib/dependencies/AMDRequireContextDependency.js +7 -11
  105. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +1 -0
  106. package/lib/dependencies/AMDRequireDependency.js +24 -20
  107. package/lib/dependencies/CachedConstDependency.js +3 -0
  108. package/lib/dependencies/CommonJsDependencyHelpers.js +1 -0
  109. package/lib/dependencies/CommonJsExportRequireDependency.js +79 -31
  110. package/lib/dependencies/CommonJsExportsDependency.js +21 -16
  111. package/lib/dependencies/CommonJsExportsParserPlugin.js +230 -7
  112. package/lib/dependencies/CommonJsFullRequireDependency.js +27 -19
  113. package/lib/dependencies/CommonJsImportsParserPlugin.js +51 -16
  114. package/lib/dependencies/CommonJsPlugin.js +1 -1
  115. package/lib/dependencies/CommonJsRequireContextDependency.js +10 -13
  116. package/lib/dependencies/CommonJsRequireDependency.js +42 -11
  117. package/lib/dependencies/CommonJsSelfReferenceDependency.js +22 -14
  118. package/lib/dependencies/ConstDependency.js +16 -11
  119. package/lib/dependencies/ContextDependency.js +4 -0
  120. package/lib/dependencies/ContextDependencyTemplateAsId.js +1 -1
  121. package/lib/dependencies/ContextElementDependency.js +23 -14
  122. package/lib/dependencies/CreateRequireParserPlugin.js +1 -0
  123. package/lib/dependencies/CreateScriptUrlDependency.js +5 -7
  124. package/lib/dependencies/CriticalDependencyWarning.js +1 -0
  125. package/lib/dependencies/CssIcssExportDependency.js +512 -574
  126. package/lib/dependencies/CssIcssImportDependency.js +9 -9
  127. package/lib/dependencies/CssIcssSymbolDependency.js +22 -15
  128. package/lib/dependencies/CssImportDependency.js +25 -1
  129. package/lib/dependencies/CssUrlDependency.js +23 -14
  130. package/lib/dependencies/DllEntryDependency.js +9 -13
  131. package/lib/dependencies/ExportBindingInitFragment.js +164 -0
  132. package/lib/dependencies/ExportsInfoDependency.js +12 -12
  133. package/lib/dependencies/ExternalModuleDependency.js +8 -5
  134. package/lib/dependencies/ExternalModuleInitFragment.js +7 -5
  135. package/lib/dependencies/ExternalModuleInitFragmentDependency.js +13 -10
  136. package/lib/dependencies/HarmonyAcceptDependency.js +11 -11
  137. package/lib/dependencies/HarmonyAcceptImportDependency.js +1 -0
  138. package/lib/dependencies/HarmonyDetectionParserPlugin.js +47 -22
  139. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +28 -2
  140. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +46 -22
  141. package/lib/dependencies/HarmonyExportExpressionDependency.js +107 -30
  142. package/lib/dependencies/HarmonyExportHeaderDependency.js +7 -9
  143. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +109 -31
  144. package/lib/dependencies/HarmonyExportInitFragment.js +18 -15
  145. package/lib/dependencies/HarmonyExportSpecifierDependency.js +83 -18
  146. package/lib/dependencies/HarmonyExports.js +4 -1
  147. package/lib/dependencies/HarmonyImportDependency.js +24 -0
  148. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +110 -74
  149. package/lib/dependencies/HarmonyImportGuard.js +254 -0
  150. package/lib/dependencies/HarmonyImportSideEffectDependency.js +18 -1
  151. package/lib/dependencies/HarmonyImportSpecifierDependency.js +118 -14
  152. package/lib/dependencies/HarmonyLinkingError.js +1 -0
  153. package/lib/dependencies/HarmonyModulesPlugin.js +1 -0
  154. package/lib/dependencies/{HtmlScriptSrcDependency.js → HtmlEntryDependency.js} +261 -109
  155. package/lib/dependencies/HtmlInlineHtmlDependency.js +107 -0
  156. package/lib/dependencies/HtmlInlineScriptDependency.js +17 -13
  157. package/lib/dependencies/HtmlInlineStyleDependency.js +45 -11
  158. package/lib/dependencies/ImportContextDependency.js +5 -9
  159. package/lib/dependencies/ImportDependency.js +44 -2
  160. package/lib/dependencies/ImportMetaHotAcceptDependency.js +1 -0
  161. package/lib/dependencies/ImportMetaHotDeclineDependency.js +1 -0
  162. package/lib/dependencies/ImportMetaPlugin.js +74 -30
  163. package/lib/dependencies/ImportParserPlugin.js +19 -0
  164. package/lib/dependencies/ImportWeakDependency.js +1 -0
  165. package/lib/dependencies/JsonExportsDependency.js +9 -9
  166. package/lib/dependencies/LoaderImportDependency.js +1 -0
  167. package/lib/dependencies/LocalModule.js +11 -12
  168. package/lib/dependencies/LocalModuleDependency.js +11 -13
  169. package/lib/dependencies/ModuleDecoratorDependency.js +9 -9
  170. package/lib/dependencies/ModuleDependency.js +7 -0
  171. package/lib/dependencies/ModuleHotAcceptDependency.js +1 -0
  172. package/lib/dependencies/ModuleHotDeclineDependency.js +1 -0
  173. package/lib/dependencies/ModuleInitFragmentDependency.js +15 -11
  174. package/lib/dependencies/ProvidedDependency.js +31 -27
  175. package/lib/dependencies/PureExpressionDependency.js +7 -9
  176. package/lib/dependencies/RequireEnsureDependency.js +12 -13
  177. package/lib/dependencies/RequireHeaderDependency.js +3 -4
  178. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +3 -0
  179. package/lib/dependencies/RequireResolveContextDependency.js +7 -11
  180. package/lib/dependencies/RequireResolveDependency.js +1 -0
  181. package/lib/dependencies/RequireResolveHeaderDependency.js +3 -5
  182. package/lib/dependencies/RuntimeRequirementsDependency.js +6 -7
  183. package/lib/dependencies/StaticExportsDependency.js +10 -10
  184. package/lib/dependencies/SystemPlugin.js +2 -0
  185. package/lib/dependencies/URLContextDependency.js +5 -7
  186. package/lib/dependencies/URLDependency.js +14 -16
  187. package/lib/dependencies/UnsupportedDependency.js +8 -13
  188. package/lib/dependencies/WebAssemblyExportImportedDependency.js +11 -16
  189. package/lib/dependencies/WebAssemblyImportDependency.js +14 -16
  190. package/lib/dependencies/WebpackIsIncludedDependency.js +1 -0
  191. package/lib/dependencies/WorkerDependency.js +19 -8
  192. package/lib/dependencies/WorkerPlugin.js +22 -6
  193. package/lib/dependencies/processExportInfo.js +13 -11
  194. package/lib/dll/DelegatedModule.js +29 -15
  195. package/lib/dll/DelegatedModuleFactoryPlugin.js +1 -0
  196. package/lib/dll/DelegatedPlugin.js +1 -0
  197. package/lib/dll/DllEntryPlugin.js +3 -0
  198. package/lib/dll/DllModule.js +3 -2
  199. package/lib/dll/DllPlugin.js +16 -0
  200. package/lib/dll/DllReferencePlugin.js +3 -0
  201. package/lib/dll/LibManifestPlugin.js +1 -0
  202. package/lib/electron/ElectronTargetPlugin.js +22 -4
  203. package/lib/errors/ConcurrentCompilationError.js +1 -0
  204. package/lib/errors/HookWebpackError.js +11 -13
  205. package/lib/errors/IgnoreErrorModuleFactory.js +1 -0
  206. package/lib/errors/InvalidDependenciesModuleWarning.js +2 -0
  207. package/lib/errors/JSONParseError.js +9 -8
  208. package/lib/errors/ModuleBuildError.js +16 -13
  209. package/lib/errors/ModuleDependencyError.js +8 -1
  210. package/lib/errors/ModuleDependencyWarning.js +8 -1
  211. package/lib/errors/ModuleError.js +5 -11
  212. package/lib/errors/ModuleHashingError.js +4 -0
  213. package/lib/errors/ModuleNotFoundError.js +3 -0
  214. package/lib/errors/ModuleParseError.js +5 -11
  215. package/lib/errors/ModuleRestoreError.js +2 -0
  216. package/lib/errors/ModuleStoreError.js +3 -0
  217. package/lib/errors/ModuleWarning.js +7 -11
  218. package/lib/errors/NodeStuffInWebError.js +1 -0
  219. package/lib/errors/NonErrorEmittedError.js +2 -0
  220. package/lib/errors/UnhandledSchemeError.js +1 -0
  221. package/lib/esm/ModuleChunkLoadingPlugin.js +0 -1
  222. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +28 -23
  223. package/lib/hmr/HotModuleReplacement.runtime.js +175 -30
  224. package/lib/hmr/HotModuleReplacementRuntimeModule.js +7 -0
  225. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +173 -26
  226. package/lib/hmr/LazyCompilationPlugin.js +30 -6
  227. package/lib/html/HtmlGenerator.js +217 -23
  228. package/lib/html/HtmlModule.js +40 -0
  229. package/lib/html/HtmlModulesPlugin.js +219 -55
  230. package/lib/html/HtmlParser.js +1108 -1099
  231. package/lib/html/{walkHtmlTokens.js → syntax.js} +4701 -212
  232. package/lib/ids/IdHelpers.js +4 -2
  233. package/lib/index.js +19 -0
  234. package/lib/javascript/BasicEvaluatedExpression.js +1 -0
  235. package/lib/javascript/EnableChunkLoadingPlugin.js +1 -0
  236. package/lib/javascript/JavascriptGenerator.js +6 -2
  237. package/lib/javascript/JavascriptModule.js +54 -0
  238. package/lib/javascript/JavascriptModulesPlugin.js +257 -102
  239. package/lib/javascript/JavascriptParser.js +285 -158
  240. package/lib/json/JsonModule.js +40 -0
  241. package/lib/json/JsonModulesPlugin.js +7 -0
  242. package/lib/json/JsonParser.js +4 -2
  243. package/lib/library/AssignLibraryPlugin.js +5 -3
  244. package/lib/library/ExportPropertyLibraryPlugin.js +1 -0
  245. package/lib/library/FalseIIFEUmdWarning.js +1 -0
  246. package/lib/library/ModuleLibraryPlugin.js +24 -5
  247. package/lib/library/SystemLibraryPlugin.js +3 -3
  248. package/lib/node/NodeTargetPlugin.js +1 -0
  249. package/lib/node/NodeWatchFileSystem.js +1 -0
  250. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +10 -9
  251. package/lib/node/RequireChunkLoadingRuntimeModule.js +18 -16
  252. package/lib/optimize/ConcatenatedModule.js +395 -77
  253. package/lib/optimize/ConstExportsPlugin.js +211 -0
  254. package/lib/optimize/InlineExports.js +178 -0
  255. package/lib/optimize/InnerGraph.js +372 -275
  256. package/lib/optimize/InnerGraphPlugin.js +196 -99
  257. package/lib/optimize/ModuleConcatenationPlugin.js +56 -25
  258. package/lib/optimize/RealContentHashPlugin.js +14 -1
  259. package/lib/optimize/SideEffectsFlagPlugin.js +234 -64
  260. package/lib/runtime/AsyncModuleRuntimeModule.js +32 -30
  261. package/lib/runtime/AutoPublicPathRuntimeModule.js +11 -5
  262. package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +1 -1
  263. package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +6 -4
  264. package/lib/runtime/DefinePropertyGettersRuntimeModule.js +33 -4
  265. package/lib/runtime/GetChunkFilenameRuntimeModule.js +82 -3
  266. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +1 -1
  267. package/lib/runtime/HasOwnPropertyRuntimeModule.js +1 -1
  268. package/lib/runtime/LoadScriptRuntimeModule.js +18 -13
  269. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +39 -26
  270. package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +1 -1
  271. package/lib/runtime/OnChunksLoadedRuntimeModule.js +4 -4
  272. package/lib/runtime/RelativeUrlRuntimeModule.js +3 -2
  273. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +1 -1
  274. package/lib/runtime/StartupEntrypointRuntimeModule.js +4 -3
  275. package/lib/runtime/WorkerRuntimeModule.js +33 -0
  276. package/lib/schemes/HttpUriPlugin.js +3 -2
  277. package/lib/serialization/AggregateErrorSerializer.js +7 -6
  278. package/lib/serialization/ArraySerializer.js +4 -8
  279. package/lib/serialization/BinaryMiddleware.js +538 -468
  280. package/lib/serialization/DateObjectSerializer.js +2 -2
  281. package/lib/serialization/ErrorObjectSerializer.js +7 -6
  282. package/lib/serialization/MapObjectSerializer.js +5 -9
  283. package/lib/serialization/NullPrototypeObjectSerializer.js +7 -9
  284. package/lib/serialization/ObjectMiddleware.js +50 -13
  285. package/lib/serialization/PlainObjectSerializer.js +9 -8
  286. package/lib/serialization/RegExpObjectSerializer.js +2 -2
  287. package/lib/serialization/Serializer.js +1 -0
  288. package/lib/serialization/SetObjectSerializer.js +4 -8
  289. package/lib/sharing/ConsumeSharedModule.js +6 -7
  290. package/lib/sharing/ConsumeSharedPlugin.js +1 -0
  291. package/lib/sharing/ConsumeSharedRuntimeModule.js +46 -41
  292. package/lib/sharing/ProvideSharedDependency.js +30 -15
  293. package/lib/sharing/ProvideSharedModule.js +30 -11
  294. package/lib/sharing/ProvideSharedPlugin.js +4 -2
  295. package/lib/sharing/SharePlugin.js +3 -0
  296. package/lib/sharing/ShareRuntimeModule.js +18 -16
  297. package/lib/sharing/resolveMatchedConfigs.js +2 -1
  298. package/lib/sharing/utils.js +1 -1
  299. package/lib/stats/DefaultStatsFactoryPlugin.js +4 -6
  300. package/lib/stats/DefaultStatsPrinterPlugin.js +14 -14
  301. package/lib/stats/StatsFactory.js +11 -9
  302. package/lib/stats/StatsPrinter.js +9 -2
  303. package/lib/url/URLParserPlugin.js +5 -2
  304. package/lib/util/AsyncQueue.js +10 -0
  305. package/lib/util/LazyBucketSortedSet.js +5 -0
  306. package/lib/util/LazySet.js +6 -4
  307. package/lib/util/LocConverter.js +11 -1
  308. package/lib/util/Semaphore.js +1 -0
  309. package/lib/util/SourceProcessor.js +106 -0
  310. package/lib/util/TupleSet.js +1 -0
  311. package/lib/util/WeakTupleMap.js +27 -1
  312. package/lib/util/chainedImports.js +3 -3
  313. package/lib/util/comparators.js +2 -2
  314. package/lib/util/concatenate.js +31 -7
  315. package/lib/util/createHash.js +0 -1
  316. package/lib/util/deterministicGrouping.js +19 -12
  317. package/lib/util/extractSourceMap.js +1 -1
  318. package/lib/util/findGraphRoots.js +2 -0
  319. package/lib/util/fs.js +10 -5
  320. package/lib/util/hash/DebugHash.js +1 -0
  321. package/lib/util/hash/hash-digest.js +24 -15
  322. package/lib/util/identifier.js +7 -0
  323. package/lib/util/internalSerializables.js +11 -2
  324. package/lib/util/magicComment.js +42 -0
  325. package/lib/util/makeSerializable.js +1 -0
  326. package/lib/util/nonNumericOnlyHash.js +30 -1
  327. package/lib/util/property.js +7 -1
  328. package/lib/util/publicPathPlaceholder.js +64 -0
  329. package/lib/util/registerExternalSerializer.js +4 -4
  330. package/lib/wasm-async/AsyncWasmModule.js +77 -0
  331. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +1 -1
  332. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +1 -96
  333. package/lib/wasm-async/AsyncWebAssemblyParser.js +1 -1
  334. package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +1 -1
  335. package/lib/wasm-sync/SyncWasmModule.js +39 -0
  336. package/lib/wasm-sync/UnsupportedWebAssemblyFeatureError.js +1 -0
  337. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +6 -3
  338. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +2 -1
  339. package/lib/wasm-sync/WebAssemblyGenerator.js +1 -0
  340. package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +2 -0
  341. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +10 -0
  342. package/lib/wasm-sync/WebAssemblyParser.js +7 -3
  343. package/lib/web/JsonpChunkLoadingRuntimeModule.js +45 -39
  344. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +11 -10
  345. package/package.json +35 -27
  346. package/schemas/WebpackOptions.check.js +1 -1
  347. package/schemas/WebpackOptions.json +212 -3
  348. package/schemas/plugins/HtmlGeneratorOptions.check.js +1 -1
  349. package/schemas/plugins/HtmlParserOptions.check.d.ts +7 -0
  350. package/schemas/plugins/HtmlParserOptions.check.js +6 -0
  351. package/schemas/plugins/HtmlParserOptions.json +3 -0
  352. package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.js +1 -1
  353. package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
  354. package/schemas/plugins/css/CssParserOptions.check.js +1 -1
  355. package/types.d.ts +1456 -290
  356. package/lib/css/walkCssTokens.js +0 -2020
  357. package/lib/util/AppendOnlyStackedSet.js +0 -93
@@ -8,11 +8,17 @@
8
8
  const Dependency = require("../Dependency");
9
9
  const InitFragment = require("../InitFragment");
10
10
  const Template = require("../Template");
11
+ const {
12
+ InlinedUsedName,
13
+ isExportInlined,
14
+ isInlineExportsEnabled
15
+ } = require("../optimize/InlineExports");
11
16
  const {
12
17
  getDependencyUsedByExportsCondition
13
18
  } = require("../optimize/InnerGraph");
14
19
  const { getTrimmedIdsAndRange } = require("../util/chainedImports");
15
20
  const makeSerializable = require("../util/makeSerializable");
21
+ const memoize = require("../util/memoize");
16
22
  const { propertyAccess } = require("../util/property");
17
23
  const traverseDestructuringAssignmentProperties = require("../util/traverseDestructuringAssignmentProperties");
18
24
  const HarmonyImportDependency = require("./HarmonyImportDependency");
@@ -39,6 +45,10 @@ const { ImportPhaseUtils } = require("./ImportPhase");
39
45
  /** @typedef {import("./HarmonyImportDependency").ExportPresenceMode} ExportPresenceMode */
40
46
  /** @typedef {HarmonyImportDependency.Ids} Ids */
41
47
  /** @typedef {import("./ImportPhase").ImportPhaseType} ImportPhaseType */
48
+ /** @typedef {import("./HarmonyImportGuard").DependencyGuard} DependencyGuard */
49
+ /** @typedef {import("../javascript/JavascriptModule").JavascriptModuleBuildMeta} JavascriptModuleBuildMeta */
50
+
51
+ const getHarmonyImportGuard = memoize(() => require("./HarmonyImportGuard"));
42
52
 
43
53
  const idsSymbol = /** @type {symbol} */ (
44
54
  Symbol("HarmonyImportSpecifierDependency.ids")
@@ -71,10 +81,14 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
71
81
  idRanges // TODO webpack 6 make this non-optional. It must always be set to properly trim ids.
72
82
  ) {
73
83
  super(request, sourceOrder, phase, attributes);
84
+ /** @type {Ids} */
74
85
  this.ids = ids;
86
+ /** @type {string} */
75
87
  this.name = name;
76
88
  this.range = range;
89
+ /** @type {IdRanges | undefined} */
77
90
  this.idRanges = idRanges;
91
+ /** @type {ExportPresenceMode} */
78
92
  this.exportPresenceMode = exportPresenceMode;
79
93
  /** @type {undefined | boolean} */
80
94
  this.namespaceObjectAsContext = false;
@@ -90,6 +104,8 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
90
104
  this.usedByExports = undefined;
91
105
  /** @type {DestructuringAssignmentProperties | undefined} */
92
106
  this.referencedPropertiesInDestructuring = undefined;
107
+ /** @type {DependencyGuard[] | undefined} */
108
+ this.branchGuards = undefined;
93
109
  }
94
110
 
95
111
  // TODO webpack 6 remove
@@ -123,6 +139,14 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
123
139
  return "harmony import specifier";
124
140
  }
125
141
 
142
+ /**
143
+ * Returns the export name this dependency requests from its target module (lazy barrel optimization).
144
+ * @returns {string | true | null} export name, true for all exports, null for none
145
+ */
146
+ getForwardId() {
147
+ return this.ids.length > 0 ? this.ids[0] : true;
148
+ }
149
+
126
150
  /**
127
151
  * Returns the imported ids.
128
152
  * @param {ModuleGraph} moduleGraph the module graph
@@ -151,11 +175,41 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
151
175
  * @returns {null | false | GetConditionFn} function to determine if the connection is active
152
176
  */
153
177
  getCondition(moduleGraph) {
154
- return getDependencyUsedByExportsCondition(
178
+ const usedByExportsCondition = getDependencyUsedByExportsCondition(
155
179
  this,
156
- this.usedByExports,
157
180
  moduleGraph
158
181
  );
182
+ if (usedByExportsCondition === false) return false;
183
+ // Keep the connection unconditional (fast path) when nothing can deactivate it
184
+ if (
185
+ usedByExportsCondition === null &&
186
+ this.branchGuards === undefined &&
187
+ !isInlineExportsEnabled(moduleGraph)
188
+ ) {
189
+ return null;
190
+ }
191
+ const dep = this;
192
+ return (connection, runtime) => {
193
+ if (usedByExportsCondition !== null) {
194
+ const result = usedByExportsCondition(connection, runtime);
195
+ if (result === false) return false;
196
+ }
197
+ const ids = dep.getIds(moduleGraph);
198
+ if (
199
+ ids.length > 0 &&
200
+ isExportInlined(moduleGraph, connection.module, ids, runtime)
201
+ ) {
202
+ return false;
203
+ }
204
+ const guards = dep.branchGuards;
205
+ if (
206
+ guards !== undefined &&
207
+ getHarmonyImportGuard().isDeadByGuards(guards, moduleGraph, runtime)
208
+ ) {
209
+ return false;
210
+ }
211
+ return true;
212
+ };
159
213
  }
160
214
 
161
215
  /**
@@ -175,7 +229,16 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
175
229
  */
176
230
  getReferencedExports(moduleGraph, runtime) {
177
231
  let ids = this.getIds(moduleGraph);
178
- if (ids.length === 0) return this._getReferencedExportsInDestructuring();
232
+ if (ids.length === 0) {
233
+ const refs = this._getReferencedExportsInDestructuring();
234
+ // The whole namespace object is used as a value (no destructuring): it
235
+ // can be rendered as a decoupled namespace object, keeping the module's
236
+ // exports mangleable. Deferred imports keep their special namespace.
237
+ return refs === Dependency.EXPORTS_OBJECT_REFERENCED &&
238
+ !ImportPhaseUtils.isDefer(this.phase)
239
+ ? Dependency.EXPORTS_OBJECT_REFERENCED_MANGLEABLE
240
+ : refs;
241
+ }
179
242
  let namespaceObjectAsContext = this.namespaceObjectAsContext;
180
243
  if (ids[0] === "default") {
181
244
  const selfModule =
@@ -219,7 +282,7 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
219
282
  /**
220
283
  * Get referenced exports in destructuring.
221
284
  * @param {Ids=} ids ids
222
- * @returns {RawReferencedExports} referenced exports
285
+ * @returns {ReferencedExports} referenced exports
223
286
  */
224
287
  _getReferencedExportsInDestructuring(ids) {
225
288
  if (this.referencedPropertiesInDestructuring) {
@@ -229,14 +292,27 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
229
292
  this.referencedPropertiesInDestructuring,
230
293
  (stack) => refsInDestructuring.push(stack.map((p) => p.id))
231
294
  );
232
- /** @type {RawReferencedExports} */
295
+ /** @type {ReferencedExports} */
233
296
  const refs = [];
234
297
  for (const idsInDestructuring of refsInDestructuring) {
235
- refs.push(ids ? [...ids, ...idsInDestructuring] : idsInDestructuring);
298
+ // Destructuring consumer can't accept an inlined literal
299
+ refs.push({
300
+ name: ids ? [...ids, ...idsInDestructuring] : idsInDestructuring,
301
+ canInline: false
302
+ });
236
303
  }
237
304
  return refs;
238
305
  }
239
- return ids ? [ids] : Dependency.EXPORTS_OBJECT_REFERENCED;
306
+ return ids
307
+ ? [
308
+ {
309
+ name: ids,
310
+ canMangle: true,
311
+ // Need access the export value to trigger side effects for deferred module
312
+ canInline: !ImportPhaseUtils.isDefer(this.phase)
313
+ }
314
+ ]
315
+ : Dependency.EXPORTS_OBJECT_REFERENCED;
240
316
  }
241
317
 
242
318
  /**
@@ -249,7 +325,7 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
249
325
  return this.exportPresenceMode;
250
326
  }
251
327
  const buildMeta =
252
- /** @type {BuildMeta} */
328
+ /** @type {JavascriptModuleBuildMeta} */
253
329
  (
254
330
  /** @type {Module} */
255
331
  (moduleGraph.getParentModule(this)).buildMeta
@@ -325,6 +401,7 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
325
401
  write(this.asiSafe);
326
402
  write(this.usedByExports);
327
403
  write(this.referencedPropertiesInDestructuring);
404
+ write(this.branchGuards);
328
405
  super.serialize(context);
329
406
  }
330
407
 
@@ -346,6 +423,7 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
346
423
  this.asiSafe = read();
347
424
  this.usedByExports = read();
348
425
  this.referencedPropertiesInDestructuring = read();
426
+ this.branchGuards = read();
349
427
  super.deserialize(context);
350
428
  }
351
429
  }
@@ -369,9 +447,13 @@ HarmonyImportSpecifierDependency.Template = class HarmonyImportSpecifierDependen
369
447
  const dep = /** @type {HarmonyImportSpecifierDependency} */ (dependency);
370
448
  const { moduleGraph, runtime, initFragments } = templateContext;
371
449
  const connection = moduleGraph.getConnection(dep);
450
+ const ids = dep.getIds(moduleGraph);
372
451
 
373
- // Only render declaration for import specifier when the dependency is conditional
374
- if (connection && !connection.isTargetActive(runtime)) {
452
+ if (
453
+ connection &&
454
+ !connection.isTargetActive(runtime) &&
455
+ !isExportInlined(moduleGraph, connection.module, ids, runtime)
456
+ ) {
375
457
  initFragments.push(
376
458
  new InitFragment(
377
459
  `/* unused harmony import specifier */ var ${dep.name};\n`,
@@ -384,7 +466,6 @@ HarmonyImportSpecifierDependency.Template = class HarmonyImportSpecifierDependen
384
466
  return;
385
467
  }
386
468
 
387
- const ids = dep.getIds(moduleGraph);
388
469
  const {
389
470
  trimmedRange: [trimmedRangeStart, trimmedRangeEnd],
390
471
  trimmedIds
@@ -447,7 +528,16 @@ HarmonyImportSpecifierDependency.Template = class HarmonyImportSpecifierDependen
447
528
  const used = moduleGraph
448
529
  .getExportsInfo(module)
449
530
  .getUsedName(concatedIds, runtime);
450
- if (!used) return;
531
+ if (!used) {
532
+ return;
533
+ } else if (used instanceof InlinedUsedName) {
534
+ throw new Error(
535
+ `Should not inline for destructuring name ${concatedIds.join(".")}`
536
+ );
537
+ }
538
+ // Destructuring can't consume an inlined literal — should be unreachable
539
+ // because the consumer-side canInline=false suppresses inlining there.
540
+ if (!Array.isArray(used)) continue;
451
541
  const newName = used[used.length - 1];
452
542
  const name = concatedIds[concatedIds.length - 1];
453
543
  if (newName === name) continue;
@@ -477,6 +567,7 @@ HarmonyImportSpecifierDependency.Template = class HarmonyImportSpecifierDependen
477
567
  const connection = moduleGraph.getConnection(dep);
478
568
  /** @type {string} */
479
569
  let exportExpr;
570
+
480
571
  if (
481
572
  connection &&
482
573
  concatenationScope &&
@@ -487,7 +578,13 @@ HarmonyImportSpecifierDependency.Template = class HarmonyImportSpecifierDependen
487
578
  connection.module,
488
579
  {
489
580
  asiSafe: dep.asiSafe,
490
- deferredImport: ImportPhaseUtils.isDefer(dep.phase)
581
+ deferredImport: ImportPhaseUtils.isDefer(dep.phase),
582
+ // A bare namespace value that isn't destructured may escape, so
583
+ // allow a decoupled namespace object that keeps the original names.
584
+ // Deferred imports keep their special namespace object.
585
+ mangleableNamespace:
586
+ !dep.referencedPropertiesInDestructuring &&
587
+ !ImportPhaseUtils.isDefer(dep.phase)
491
588
  }
492
589
  );
493
590
  } else if (dep.namespaceObjectAsContext && ids.length === 1) {
@@ -529,7 +626,14 @@ HarmonyImportSpecifierDependency.Template = class HarmonyImportSpecifierDependen
529
626
  initFragments,
530
627
  runtime,
531
628
  runtimeRequirements,
532
- dependency: dep
629
+ dependency: dep,
630
+ // A bare namespace value that isn't destructured may escape, so allow a
631
+ // decoupled namespace object that keeps the original export names.
632
+ // Deferred imports keep their special namespace object.
633
+ mangleableNamespace:
634
+ ids.length === 0 &&
635
+ !dep.referencedPropertiesInDestructuring &&
636
+ !ImportPhaseUtils.isDefer(dep.phase)
533
637
  });
534
638
  }
535
639
  return exportExpr;
@@ -12,6 +12,7 @@ class HarmonyLinkingError extends WebpackError {
12
12
  super(message);
13
13
  /** @type {string} */
14
14
  this.name = "HarmonyLinkingError";
15
+ /** @type {boolean} */
15
16
  this.hideStack = true;
16
17
  }
17
18
  }
@@ -44,6 +44,7 @@ class HarmonyModulesPlugin {
44
44
  * @param {HarmonyModulesPluginOptions} options options
45
45
  */
46
46
  constructor(options) {
47
+ /** @type {HarmonyModulesPluginOptions} */
47
48
  this.options = options;
48
49
  }
49
50