@depup/webpack 5.110.3-depup.0 → 5.111.1-depup.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 (283) hide show
  1. package/README.md +7 -8
  2. package/changes.json +7 -11
  3. package/lib/APIPlugin.js +26 -11
  4. package/lib/AutomaticPrefetchPlugin.js +1 -1
  5. package/lib/Cache.js +8 -3
  6. package/lib/CacheFacade.js +1 -1
  7. package/lib/CircularModulesPlugin.js +157 -55
  8. package/lib/CleanPlugin.js +2 -2
  9. package/lib/CompatibilityPlugin.js +3 -4
  10. package/lib/Compilation.js +336 -337
  11. package/lib/Compiler.js +213 -51
  12. package/lib/ConstPlugin.js +16 -132
  13. package/lib/CopyPlugin.js +1054 -0
  14. package/lib/DefinePlugin.js +24 -8
  15. package/lib/DependencyTemplate.js +2 -1
  16. package/lib/DotenvPlugin.js +24 -28
  17. package/lib/ErrorHelpers.js +113 -0
  18. package/lib/ExportsInfo.js +20 -16
  19. package/lib/ExternalModule.js +47 -22
  20. package/lib/FileSystemInfo.js +17 -14
  21. package/lib/FlagDependencyExportsPlugin.js +53 -34
  22. package/lib/FlagDependencyUsagePlugin.js +9 -13
  23. package/lib/Generator.js +24 -2
  24. package/lib/HotModuleReplacementPlugin.js +55 -7
  25. package/lib/IgnorePlugin.js +1 -1
  26. package/lib/JavascriptMetaInfoPlugin.js +5 -3
  27. package/lib/LoaderOptionsPlugin.js +1 -1
  28. package/lib/MainTemplate.js +5 -1
  29. package/lib/Module.js +19 -10
  30. package/lib/ModuleGraph.js +6 -9
  31. package/lib/MultiCompiler.js +7 -17
  32. package/lib/MultiWatching.js +1 -1
  33. package/lib/NormalModule.js +135 -50
  34. package/lib/NormalModuleFactory.js +1 -1
  35. package/lib/RuntimeGlobals.js +21 -7
  36. package/lib/RuntimeModule.js +28 -12
  37. package/lib/RuntimePlugin.js +30 -3
  38. package/lib/RuntimeTemplate.js +813 -518
  39. package/lib/SourceMapDevToolPlugin.js +54 -104
  40. package/lib/TemplatedPathPlugin.js +16 -59
  41. package/lib/Watching.js +9 -0
  42. package/lib/WebpackOptionsApply.js +84 -91
  43. package/lib/asset/AssetBytesGenerator.js +7 -1
  44. package/lib/asset/AssetGenerator.js +50 -24
  45. package/lib/asset/AssetModule.js +3 -0
  46. package/lib/asset/AssetSourceGenerator.js +7 -1
  47. package/lib/asset/WebManifestParser.js +7 -5
  48. package/lib/buildChunkGraph.js +11 -15
  49. package/lib/cache/AddBuildDependenciesPlugin.js +33 -4
  50. package/lib/cache/IdleFileCachePlugin.js +2 -2
  51. package/lib/cache/MemoryCachePlugin.js +4 -4
  52. package/lib/cache/MemoryWithGcCachePlugin.js +7 -8
  53. package/lib/cache/PackFileCacheStrategy.js +17 -19
  54. package/lib/cache/getLazyHashedEtag.js +3 -5
  55. package/lib/config/browserslistTargetHandler.js +17 -4
  56. package/lib/config/defaults.js +138 -128
  57. package/lib/config/getClaimedAssetTypes.js +10 -11
  58. package/lib/config/normalization.js +82 -12
  59. package/lib/config/target.js +13 -4
  60. package/lib/container/ContainerReferencePlugin.js +6 -0
  61. package/lib/container/RemoteRuntimeModule.js +9 -0
  62. package/lib/container/declaredRemotes.js +39 -0
  63. package/lib/{ContextExclusionPlugin.js → context/ContextExclusionPlugin.js} +1 -1
  64. package/lib/{ContextModule.js → context/ContextModule.js} +54 -115
  65. package/lib/{ContextModuleFactory.js → context/ContextModuleFactory.js} +19 -21
  66. package/lib/{ContextReplacementPlugin.js → context/ContextReplacementPlugin.js} +4 -4
  67. package/lib/css/CssGenerator.js +27 -11
  68. package/lib/css/CssInjectStyleRuntimeModule.js +9 -0
  69. package/lib/css/CssLoadingRuntimeModule.js +94 -36
  70. package/lib/css/CssModule.js +1 -1
  71. package/lib/css/CssModulesPlugin.js +7 -6
  72. package/lib/css/CssParser.js +162 -31
  73. package/lib/css/CssServerStylesRuntimeModule.js +9 -0
  74. package/lib/css/cssMinify.js +43 -32
  75. package/lib/css/data.js +3514 -869
  76. package/lib/css/syntax.js +6370 -1220
  77. package/lib/debug/ProfilingPlugin.js +7 -4
  78. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +6 -3
  79. package/lib/dependencies/AMDRuntimeModules.js +18 -0
  80. package/lib/dependencies/CommonJsExportRequireDependency.js +13 -12
  81. package/lib/dependencies/CommonJsExportsParserPlugin.js +12 -13
  82. package/lib/dependencies/CommonJsImportsParserPlugin.js +5 -5
  83. package/lib/dependencies/CommonJsPlugin.js +19 -3
  84. package/lib/dependencies/CommonJsRequireDependency.js +14 -5
  85. package/lib/dependencies/CommonJsSelfReferenceDependency.js +2 -4
  86. package/lib/dependencies/ContextDependency.js +1 -1
  87. package/lib/dependencies/ContextDependencyHelpers.js +3 -9
  88. package/lib/dependencies/ContextElementDependency.js +1 -1
  89. package/lib/dependencies/CssIcssExportDependency.js +13 -9
  90. package/lib/dependencies/CssIcssImportDependency.js +3 -6
  91. package/lib/dependencies/CssUrlDependency.js +3 -5
  92. package/lib/dependencies/HarmonyCompatibilityDependency.js +67 -22
  93. package/lib/dependencies/HarmonyDetectionParserPlugin.js +3 -4
  94. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +10 -7
  95. package/lib/dependencies/HarmonyExportExpressionDependency.js +47 -33
  96. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +74 -17
  97. package/lib/dependencies/HarmonyExportInitFragment.js +110 -23
  98. package/lib/dependencies/HarmonyExportSpecifierDependency.js +25 -58
  99. package/lib/dependencies/HarmonyImportBareSideEffectDependency.js +59 -0
  100. package/lib/dependencies/HarmonyImportDependency.js +6 -1
  101. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +111 -17
  102. package/lib/dependencies/HarmonyImportSideEffectDependency.js +3 -4
  103. package/lib/dependencies/HarmonyImportSpecifierDependency.js +40 -3
  104. package/lib/dependencies/HarmonyModulesPlugin.js +20 -0
  105. package/lib/dependencies/HtmlEntryDependency.js +124 -102
  106. package/lib/dependencies/HtmlInlineScriptDependency.js +3 -4
  107. package/lib/dependencies/HtmlInlineStyleDependency.js +3 -4
  108. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -1
  109. package/lib/dependencies/ImportMetaGlobHelpers.js +1 -1
  110. package/lib/dependencies/ImportMetaMainDependency.js +104 -0
  111. package/lib/dependencies/ImportMetaPlugin.js +67 -25
  112. package/lib/dependencies/ImportParserPlugin.js +1 -1
  113. package/lib/dependencies/LoaderPlugin.js +26 -1
  114. package/lib/dependencies/RequireContextDependencyParserPlugin.js +1 -1
  115. package/lib/dependencies/SystemRuntimeModule.js +9 -0
  116. package/lib/dependencies/URLContextDependency.js +1 -1
  117. package/lib/dependencies/URLDependency.js +6 -5
  118. package/lib/dependencies/WorkerAndWorkletPlugin.js +15 -21
  119. package/lib/dependencies/WorkerDependency.js +7 -7
  120. package/lib/dependencies/WorkletDependency.js +7 -11
  121. package/lib/dll/DelegatedModule.js +18 -1
  122. package/lib/dll/DllReferencePlugin.js +11 -8
  123. package/lib/dll/LibManifestPlugin.js +1 -1
  124. package/lib/errors/AnalyzableBailoutsWarning.js +41 -0
  125. package/lib/errors/DuplicateModulesWarning.js +12 -7
  126. package/lib/errors/EmptyCopyPatternWarning.js +26 -0
  127. package/lib/errors/ExternalStarReexportError.js +44 -0
  128. package/lib/errors/HookWebpackError.js +3 -2
  129. package/lib/errors/MissingSourceMapsWarning.js +36 -0
  130. package/lib/errors/ModuleParseError.js +2 -1
  131. package/lib/errors/UnusedAssetsWarning.js +36 -0
  132. package/lib/errors/UnusedFederationWarning.js +35 -0
  133. package/lib/errors/UnusedModulesWarning.js +38 -0
  134. package/lib/esm/ExportWebpackRequireRuntimeModule.js +9 -0
  135. package/lib/esm/ModuleChunkFormatPlugin.js +28 -3
  136. package/lib/esm/ModuleChunkLoadingPlugin.js +30 -11
  137. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +92 -60
  138. package/lib/hmr/HotModuleReplacement.runtime.js +8 -2
  139. package/lib/hmr/HotModuleReplacementRuntimeModule.js +9 -0
  140. package/lib/hmr/LazyCompilationPlugin.js +3 -5
  141. package/lib/html/HtmlGenerator.js +72 -87
  142. package/lib/html/HtmlModulesPlugin.js +418 -200
  143. package/lib/html/HtmlParser.js +110 -147
  144. package/lib/html/builtinEmbeddedRenderer.js +107 -0
  145. package/lib/html/data.js +142 -7
  146. package/lib/html/htmlMinify.js +92 -122
  147. package/lib/html/syntax.js +1618 -1391
  148. package/lib/ids/HashedModuleIdsPlugin.js +2 -1
  149. package/lib/index.js +49 -3
  150. package/lib/javascript/ChunkFormatHelpers.js +4 -3
  151. package/lib/javascript/JavascriptGenerator.js +8 -1
  152. package/lib/javascript/JavascriptModule.js +1 -0
  153. package/lib/javascript/JavascriptModulesPlugin.js +73 -72
  154. package/lib/javascript/JavascriptParser.js +1970 -900
  155. package/lib/javascript/StartupHelpers.js +27 -3
  156. package/lib/javascript/data.js +172 -0
  157. package/lib/javascript/grammar.js +5546 -0
  158. package/lib/javascript/parser.js +1500 -0
  159. package/lib/javascript/regexp.js +1762 -0
  160. package/lib/javascript/regexpData.js +51 -0
  161. package/lib/javascript/syntax.js +9061 -5262
  162. package/lib/json/JsonGenerator.js +7 -1
  163. package/lib/library/ModuleLibraryPlugin.js +171 -132
  164. package/lib/loaders/LoaderRunner.js +137 -9
  165. package/lib/node/NodeWatchFileSystem.js +3 -9
  166. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +22 -0
  167. package/lib/node/RequireChunkLoadingRuntimeModule.js +22 -0
  168. package/lib/optimize/AggressiveMergingPlugin.js +3 -5
  169. package/lib/optimize/ConcatenatedModule.js +178 -120
  170. package/lib/optimize/ConstExportsPlugin.js +50 -39
  171. package/lib/optimize/FlagIncludedChunksPlugin.js +3 -11
  172. package/lib/optimize/InlineExports.js +20 -123
  173. package/lib/optimize/InnerGraphPlugin.js +7 -13
  174. package/lib/optimize/LimitChunkCountPlugin.js +5 -8
  175. package/lib/optimize/MangleExportsPlugin.js +13 -4
  176. package/lib/optimize/ModuleConcatenationPlugin.js +27 -5
  177. package/lib/optimize/RealContentHashPlugin.js +68 -9
  178. package/lib/optimize/SideEffectsFlagPlugin.js +24 -28
  179. package/lib/optimize/SplitChunksPlugin.js +2 -4
  180. package/lib/performance/AnalyzableBailoutsPlugin.js +115 -0
  181. package/lib/performance/BroadContextsPlugin.js +1 -1
  182. package/lib/performance/CacheEffectivenessPlugin.js +7 -7
  183. package/lib/performance/DuplicateModulesPlugin.js +57 -13
  184. package/lib/performance/EvalUsagePlugin.js +5 -2
  185. package/lib/performance/MissingSourceMapsPlugin.js +115 -0
  186. package/lib/performance/PureAnnotationsPlugin.js +6 -3
  187. package/lib/performance/SizeLimitsPlugin.js +2 -4
  188. package/lib/performance/TopLevelThisPlugin.js +5 -4
  189. package/lib/performance/UnusedAssetsPlugin.js +109 -0
  190. package/lib/performance/UnusedFederationPlugin.js +147 -0
  191. package/lib/performance/UnusedModulesPlugin.js +141 -0
  192. package/lib/performance/UnusedReexportsPlugin.js +1 -55
  193. package/lib/performance/isOnlyReexported.js +65 -0
  194. package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +25 -5
  195. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +8 -8
  196. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +9 -0
  197. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +9 -0
  198. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +9 -0
  199. package/lib/prefetch/ResourceHintPlugin.js +18 -23
  200. package/lib/prefetch/ResourceHintRuntimeModule.js +9 -0
  201. package/lib/prefetch/StartupAssetHintRuntimeModule.js +16 -10
  202. package/lib/rules/RuleSetCompiler.js +211 -4
  203. package/lib/runtime/AsyncModuleRuntimeModule.js +98 -66
  204. package/lib/runtime/AutoPublicPathRuntimeModule.js +9 -0
  205. package/lib/runtime/BaseUriRuntimeModule.js +9 -0
  206. package/lib/runtime/ChunkNameRuntimeModule.js +9 -0
  207. package/lib/runtime/EnsureChunkRuntimeModule.js +35 -16
  208. package/lib/runtime/GetChunkFilenameRuntimeModule.js +12 -4
  209. package/lib/runtime/GetFullHashRuntimeModule.js +9 -0
  210. package/lib/runtime/GetMainFilenameRuntimeModule.js +9 -0
  211. package/lib/runtime/GetWorkletBootstrapRuntimeModule.js +9 -0
  212. package/lib/runtime/GlobalRuntimeModule.js +11 -4
  213. package/lib/runtime/HasOwnPropertyRuntimeModule.js +9 -0
  214. package/lib/runtime/HelperRuntimeModule.js +10 -0
  215. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +305 -224
  216. package/lib/runtime/NonceRuntimeModule.js +9 -0
  217. package/lib/runtime/OnChunksLoadedRuntimeModule.js +67 -20
  218. package/lib/runtime/PublicPathRuntimeModule.js +9 -0
  219. package/lib/runtime/RuntimeIdRuntimeModule.js +9 -0
  220. package/lib/runtime/SpecNamespaceObjectRuntimeModule.js +90 -0
  221. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +9 -0
  222. package/lib/runtime/StartupEntrypointRuntimeModule.js +9 -0
  223. package/lib/runtime/SystemContextRuntimeModule.js +9 -0
  224. package/lib/runtime/ToBinaryRuntimeModule.js +9 -0
  225. package/lib/schemes/DataUriPlugin.js +3 -6
  226. package/lib/schemes/VirtualUrlPlugin.js +1 -1
  227. package/lib/serialization/BinaryMiddleware.js +9 -9
  228. package/lib/serialization/FileMiddleware.js +16 -16
  229. package/lib/serialization/ObjectMiddleware.js +168 -139
  230. package/lib/sharing/ConsumeSharedPlugin.js +12 -0
  231. package/lib/sharing/ConsumeSharedRuntimeModule.js +11 -0
  232. package/lib/sharing/ShareRuntimeModule.js +9 -0
  233. package/lib/sharing/declaredShared.js +47 -0
  234. package/lib/stats/DefaultStatsFactoryPlugin.js +6 -5
  235. package/lib/stats/DefaultStatsPrinterPlugin.js +3 -0
  236. package/lib/typescript/TypeScriptPlugin.js +2 -3
  237. package/lib/url/URLParserPlugin.js +6 -8
  238. package/lib/util/LocConverter.js +4 -7
  239. package/lib/util/SourceProcessor.js +91 -91
  240. package/lib/util/async.js +292 -0
  241. package/lib/util/buildDiagnostics.js +69 -0
  242. package/lib/util/chainedImports.js +3 -4
  243. package/lib/util/concatenate.js +4 -4
  244. package/lib/util/createHooksRegistry.js +1 -2
  245. package/lib/util/dataURL.js +2 -3
  246. package/lib/util/deterministicGrouping.js +8 -13
  247. package/lib/util/findGraphRoots.js +6 -13
  248. package/lib/util/fs.js +27 -1
  249. package/lib/util/globUtils.js +1 -1
  250. package/lib/util/handlerKeys.js +40 -0
  251. package/lib/util/hash/wasm-hash.js +3 -4
  252. package/lib/util/identifier.js +20 -0
  253. package/lib/util/internalSerializables.js +5 -1
  254. package/lib/util/registerExternalSerializer.js +6 -45
  255. package/lib/util/semver.js +5 -3
  256. package/lib/wasm-async/AsyncWasmCompileRuntimeModule.js +9 -0
  257. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +9 -0
  258. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +6 -1
  259. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +5 -1
  260. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +12 -4
  261. package/lib/wasm-sync/WebAssemblyGenerator.js +6 -1
  262. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +5 -1
  263. package/lib/wasm-sync/WebAssemblyUtils.js +2 -4
  264. package/lib/web/JsonpChunkLoadingRuntimeModule.js +36 -0
  265. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +19 -0
  266. package/package.json +55 -46
  267. package/schemas/WebpackOptions.check.js +1 -1
  268. package/schemas/WebpackOptions.json +379 -66
  269. package/schemas/plugins/LoaderOptionsPlugin.check.js +1 -1
  270. package/schemas/plugins/ManifestPlugin.check.js +1 -1
  271. package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
  272. package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
  273. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
  274. package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
  275. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  276. package/schemas/plugins/debug/ProfilingPlugin.check.js +1 -1
  277. package/schemas/plugins/dll/DllReferencePlugin.check.js +1 -1
  278. package/schemas/plugins/ids/HashedModuleIdsPlugin.check.js +1 -1
  279. package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
  280. package/types.d.ts +1723 -604
  281. package/lib/dependencies/ExportBindingInitFragment.js +0 -191
  282. package/lib/errors/EntrypointOverlapWarning.js +0 -45
  283. package/lib/performance/EntrypointOverlapPlugin.js +0 -122
@@ -164,13 +164,14 @@ const fontMimeType = (request) => {
164
164
  return getMimeTypes().lookup(resourcePath);
165
165
  };
166
166
 
167
- // Skip options for a non-CSS-Modules parse: drop the selector prelude (never
168
- // walked without modules) plus value / function-arg leaves nothing reads (the
169
- // `Ident` visitor no-ops, the `Declaration` visitor returns early, no ICSS).
170
- // `url` / functions / strings / blocks / commas are kept — they carry url()
171
- // rewrites and image-set fences. At-rule preludes are kept (`@media` / `@import`
172
- // are read). CSS-Modules parses skip nothing: selectors are walked and ICSS
173
- // `:export { k: v }` captures each value's byte range from its first / last node.
167
+ // WHY: skip options for a non-CSS-Modules parse. The selector prelude is never
168
+ // walked without modules, and the value and function-arg leaves reach nothing —
169
+ // the `Ident` visitor no-ops, the `Declaration` visitor returns early, and there
170
+ // is no ICSS. `url`, functions, strings, blocks and commas are kept, carrying
171
+ // the `url()` rewrites and image-set fences, and at-rule preludes too, since
172
+ // `@media` and `@import` are read. A CSS-Modules parse skips nothing: selectors
173
+ // are walked, and ICSS `:export { k: v }` captures each value's byte range from
174
+ // its first and last node.
174
175
  const SKIP_NON_MODULES = {
175
176
  types: buildSkipSet([
176
177
  NodeType.Number,
@@ -207,6 +208,10 @@ const VALUE_AS_ALIAS = /\s+as\s+/;
207
208
  // `@value name value`: end of the name run (first non-space followed by space).
208
209
  const VALUE_NAME_BOUNDARY = /\S\s/;
209
210
  const ONLY_WHITESPACE = /^\s+$/;
211
+ // A `@value` whose whole value is one `.class` / `#id`, the only shape whose
212
+ // localizable ident is knowable without re-parsing the substitution.
213
+ const SIMPLE_CLASS_OR_ID_VALUE =
214
+ /^([.#])(-?(?:[A-Za-z_]|[\u0080-\uFFFF])(?:[\w-]|[\u0080-\uFFFF])*)$/;
210
215
  // Relative request prefix (`./` or `../`) — `isSelfReferenceRequest` per `from`.
211
216
  const RELATIVE_REQUEST = /^\.{1,2}\//;
212
217
 
@@ -994,6 +999,19 @@ class CssParser extends Parser {
994
999
  d.entries.push(cssExportEntries.length);
995
1000
  };
996
1001
 
1002
+ // Start offsets of the idents an at-rule's own prelude handler already
1003
+ // replaced: two deps over one range concatenate rather than the later winning.
1004
+ /** @type {Set<number>} */
1005
+ const handledPreludeIdents = new Set();
1006
+ // Only a prelude is walked by both a handler and the value visitors, so
1007
+ // nothing outside one pays for the bookkeeping.
1008
+ let trackingPreludeIdents = false;
1009
+
1010
+ // Start offsets of `@value`-named dashed idents a `var()` handler already
1011
+ // scoped; only those are walked twice, so plain dashed idents cost nothing.
1012
+ /** @type {Set<number>} */
1013
+ const handledDashedValueIdents = new Set();
1014
+
997
1015
  // All `:export`-style exports are collected into a single
998
1016
  // `CssIcssExportDependency` per module (emitted at parse end) instead of one
999
1017
  // `Dependency` per export — far fewer retained objects on CSS-heavy builds.
@@ -1024,6 +1042,7 @@ class CssParser extends Parser {
1024
1042
  exportMode = CssIcssExportDependency.EXPORT_MODE.REPLACE,
1025
1043
  exportType = CssIcssExportDependency.EXPORT_TYPE.NORMAL
1026
1044
  ) => {
1045
+ if (trackingPreludeIdents && range) handledPreludeIdents.add(range[0]);
1027
1046
  // Flat location numbers — the nested loc objects were the parser's
1028
1047
  // hottest allocation (3 objects per exported name).
1029
1048
  cssExportEntries.push({
@@ -1556,13 +1575,15 @@ class CssParser extends Parser {
1556
1575
  };
1557
1576
 
1558
1577
  /**
1559
- * Emit a `CssIcssSymbolDependency` rewrite for an ident resolving to an `@value`-defined ICSS symbol (source-order semantics hold since the walker handles each `@value` before later references).
1578
+ * Emit a `CssIcssSymbolDependency` rewrite for an ident resolving to an `@value`-defined ICSS symbol (source-order semantics hold since the walker handles each `@value` before later references). A no-op for an ident an at-rule's own prelude handler already replaced.
1560
1579
  * @param {string} name ICSS symbol name
1561
1580
  * @param {number} start start position
1562
1581
  * @param {number} end end position
1563
1582
  * @returns {number} `end` of the rewritten ident range
1564
1583
  */
1565
1584
  const emitICSSSymbol = (name, start, end) => {
1585
+ if (handledPreludeIdents.has(start)) return end;
1586
+ if (trackingPreludeIdents) handledPreludeIdents.add(start);
1566
1587
  const def =
1567
1588
  /** @type {IcssDefinition} */
1568
1589
  (icssDefinitions.get(name));
@@ -1580,6 +1601,37 @@ class CssParser extends Parser {
1580
1601
  return end;
1581
1602
  };
1582
1603
 
1604
+ /**
1605
+ * The `.class` / `#id` a locally defined `@value` stands for, when its whole value is exactly one of those. Undefined for an imported value or any richer selector, which stay a plain textual substitution.
1606
+ * @param {string} name `@value` name used where a selector is expected
1607
+ * @returns {["." | "#", string] | undefined} the selector's prefix and the ident to localize
1608
+ */
1609
+ const localizableSelectorValue = (name) => {
1610
+ const def = icssDefinitions.get(name);
1611
+ if (!def || def.importName || typeof def.value !== "string") {
1612
+ return undefined;
1613
+ }
1614
+ const match = SIMPLE_CLASS_OR_ID_VALUE.exec(def.value.trim());
1615
+ return match
1616
+ ? [/** @type {"." | "#"} */ (match[1]), match[2]]
1617
+ : undefined;
1618
+ };
1619
+
1620
+ /**
1621
+ * The dashed ident a locally defined `@value` stands for, without its `--` prefix, when its whole value is exactly one. Undefined for an imported value or any richer value, which stay a plain textual substitution.
1622
+ * @param {string} name `@value` name used where a dashed ident is expected
1623
+ * @returns {string | undefined} the name to localize, sans `--`
1624
+ */
1625
+ const localizableDashedValue = (name) => {
1626
+ if (icssDefinitions.size === 0) return undefined;
1627
+ const def = icssDefinitions.get(name);
1628
+ if (!def || def.importName || typeof def.value !== "string") {
1629
+ return undefined;
1630
+ }
1631
+ const value = def.value.trim();
1632
+ return isDashedIdentifier(value) ? value.slice(2) : undefined;
1633
+ };
1634
+
1583
1635
  /**
1584
1636
  * Process a `local(...)` / `global(...)` pseudo-function: strip the call (and a leading legacy `:`) via a presentational dep, then emit `local()`'s inner top-level idents as ICSS exports.
1585
1637
  * @param {FunctionNode} fn parsed local/global function node
@@ -1740,12 +1792,12 @@ class CssParser extends Parser {
1740
1792
  : unescapeRange(identStart, identEnd).slice(2);
1741
1793
 
1742
1794
  /**
1743
- * Emit the ICSS export declaring this module exports the given custom property.
1744
- * @param {number} identStart start of the `--<name>` ident
1795
+ * Emit the ICSS export declaring this module exports the given custom property, naming it explicitly rather than reading it back from the replaced range. A `@value` standing in for a dashed ident is scoped under the name it resolves to, not the name written at the use site.
1796
+ * @param {string} identifier custom property name, sans `--`
1797
+ * @param {number} identStart start of the replaced ident
1745
1798
  * @param {number} identEnd end of the ident (exclusive)
1746
1799
  */
1747
- const emitDashedIdentExport = (identStart, identEnd) => {
1748
- const identifier = dashedIdentName(identStart, identEnd);
1800
+ const emitNamedDashedIdentExport = (identifier, identStart, identEnd) => {
1749
1801
  const { line: sl, column: sc } = locConverter.get(identStart);
1750
1802
  const { line: el, column: ec } = locConverter.get(identEnd);
1751
1803
  recordDeclaration(identifier, "custom property", sl, sc);
@@ -1763,6 +1815,19 @@ class CssParser extends Parser {
1763
1815
  );
1764
1816
  };
1765
1817
 
1818
+ /**
1819
+ * Emit the ICSS export declaring this module exports the given custom property.
1820
+ * @param {number} identStart start of the `--<name>` ident
1821
+ * @param {number} identEnd end of the ident (exclusive)
1822
+ */
1823
+ const emitDashedIdentExport = (identStart, identEnd) => {
1824
+ emitNamedDashedIdentExport(
1825
+ dashedIdentName(identStart, identEnd),
1826
+ identStart,
1827
+ identEnd
1828
+ );
1829
+ };
1830
+
1766
1831
  /**
1767
1832
  * Emit `--<name> from "<path>"` as an ICSS import + export, stripping ` from "<path>"` so the runtime sees just `--<name>` (dep ranges end at `sourceEnd - 1`, the closing quote).
1768
1833
  * @param {number} identStart start of the `--<name>` ident
@@ -1846,7 +1911,16 @@ class CssParser extends Parser {
1846
1911
 
1847
1912
  const identStart = A.start(identNode);
1848
1913
  const identEnd = A.end(identNode);
1849
- if (!rangeIsDashedIdentifier(input, identStart, identEnd)) return;
1914
+ if (!rangeIsDashedIdentifier(input, identStart, identEnd)) {
1915
+ // `var(v)` where `@value v: --foo` names the same property `var(--foo)`
1916
+ // does, so it is scoped here rather than substituted verbatim.
1917
+ const dashedName = localizableDashedValue(A.value(identNode));
1918
+ if (dashedName !== undefined) {
1919
+ handledDashedValueIdents.add(identStart);
1920
+ emitNamedDashedIdentExport(dashedName, identStart, identEnd);
1921
+ }
1922
+ return;
1923
+ }
1850
1924
 
1851
1925
  let j = identIdx + 1;
1852
1926
  while (j < fv.length && A.type(fv[j]) === NodeType.Whitespace) {
@@ -2351,12 +2425,52 @@ class CssParser extends Parser {
2351
2425
  break;
2352
2426
  }
2353
2427
  case NodeType.Ident: {
2354
- // ICSS rewrite for a bare `@value`-defined ident used as a type-style selector; only worth the slice when definitions exist.
2428
+ // A bare `@value`-defined ident stands in for a selector; only worth the slice when definitions exist.
2355
2429
  if (icssDefinitions.size === 0) break;
2356
2430
  const ident = A.value(v);
2357
- if (!isDashedIdentifier(ident) && icssDefinitions.has(ident)) {
2358
- emitICSSSymbol(ident, A.start(v), A.end(v));
2431
+ if (isDashedIdentifier(ident) || !icssDefinitions.has(ident)) {
2432
+ break;
2433
+ }
2434
+ const identStart = A.start(v);
2435
+ const identEnd = A.end(v);
2436
+ // A value naming one class / id is localized like the selector the
2437
+ // author would have written; anything else is substituted verbatim.
2438
+ const localizable =
2439
+ segmentMode === "local"
2440
+ ? localizableSelectorValue(ident)
2441
+ : undefined;
2442
+ if (localizable === undefined) {
2443
+ emitICSSSymbol(ident, identStart, identEnd);
2444
+ break;
2445
+ }
2446
+ const [prefix, localName] = localizable;
2447
+ const { line: sl, column: sc } = locConverter.get(identStart);
2448
+ const { line: el, column: ec } = locConverter.get(identEnd);
2449
+ module.addPresentationalDependency(
2450
+ new ConstDependency(prefix, [identStart, identStart])
2451
+ );
2452
+ recordDeclaration(
2453
+ localName,
2454
+ prefix === "." ? "class" : "id",
2455
+ sl,
2456
+ sc
2457
+ );
2458
+ addCssExport(
2459
+ sl,
2460
+ sc,
2461
+ el,
2462
+ ec,
2463
+ localName,
2464
+ getReexport(localName),
2465
+ [identStart, identEnd],
2466
+ true,
2467
+ CssIcssExportDependency.EXPORT_MODE.ONCE
2468
+ );
2469
+ if (prefix === ".") {
2470
+ currentRule.hasLocalAnchor = true;
2471
+ currentRule.localIdentifiers.push(localName);
2359
2472
  }
2473
+ pure.markLocal();
2360
2474
  break;
2361
2475
  }
2362
2476
  default:
@@ -4074,6 +4188,10 @@ class CssParser extends Parser {
4074
4188
  // truncates back to this length (no per-rule copy).
4075
4189
  const savedLocalIdentifierCount = currentRule.localIdentifiers.length;
4076
4190
  const name = `@${toLowerCaseIfNeeded(A.unescapedName(at))}`;
4191
+ // The dispatch below is the only place a prelude is rewritten ahead
4192
+ // of the value visitors, so the marks live exactly as long as it.
4193
+ if (handledPreludeIdents.size !== 0) handledPreludeIdents.clear();
4194
+ trackingPreludeIdents = true;
4077
4195
  switch (name) {
4078
4196
  case "@namespace": {
4079
4197
  this._emitWarning(
@@ -4173,6 +4291,7 @@ class CssParser extends Parser {
4173
4291
  )
4174
4292
  );
4175
4293
  }
4294
+ trackingPreludeIdents = false;
4176
4295
 
4177
4296
  // Prelude value-visitor context; AST-handled at-rules emit their own deps so they're excluded from the local() / global() / ICSS walks.
4178
4297
  const effectiveLocalMode = isEffectivelyLocal();
@@ -4696,13 +4815,13 @@ class CssParser extends Parser {
4696
4815
  },
4697
4816
  [NodeType.Ident](path) {
4698
4817
  const node = path.node;
4699
- // Fast exit before slicing the ident value: outside dashed-ident scoping
4700
- // and ICSS context (any non-CSS-Modules stylesheet) a bare ident carries
4701
- // no work, and idents are the most common node, so skipping the per-ident
4702
- // `value` slice matters. With no `@value`/`:import` definitions the ICSS
4703
- // probe can never hit, so it doesn't warrant the slice either. The dashed
4704
- // probe reads two char codes instead of slicing (escaped dashes don't
4705
- // match, same as the string form — cf. `processDashedIdentInVarFunction`).
4818
+ // WHY: a fast exit before slicing the ident value. Outside dashed-ident
4819
+ // scoping and ICSS context — any non-CSS-Modules stylesheet — a bare
4820
+ // ident carries no work, and idents are the most common node, so skipping
4821
+ // the per-ident `value` slice matters. With no `@value` or `:import`
4822
+ // definitions the ICSS probe can never hit, so it does not warrant the
4823
+ // slice either. The dashed probe reads two char codes instead of slicing,
4824
+ // and an escaped dash does not match, as in the string form.
4706
4825
  const dashedActive = dashed.active;
4707
4826
  const icss = icssActive() && icssDefinitions.size !== 0;
4708
4827
  if (!dashedActive && !icss) return;
@@ -4777,17 +4896,29 @@ class CssParser extends Parser {
4777
4896
  if (dashed.counterArgs) return;
4778
4897
  // Deferred: only the ICSS probe needs the ident's string value.
4779
4898
  const identValue = A.value(node);
4780
- if (icssDefinitions.has(identValue)) {
4781
- emitICSSSymbol(identValue, identStart, identEnd);
4899
+ if (!icssDefinitions.has(identValue)) return;
4900
+ // Already scoped by the enclosing `var()` handler.
4901
+ if (
4902
+ handledDashedValueIdents.size !== 0 &&
4903
+ handledDashedValueIdents.has(identStart)
4904
+ ) {
4905
+ return;
4906
+ }
4907
+ // A `@value` resolving to a dashed ident sits where `--foo` would be
4908
+ // scoped, so it is localized rather than substituted verbatim.
4909
+ if (dashedActive && dashed.emit) {
4910
+ const dashedName = localizableDashedValue(identValue);
4911
+ if (dashedName !== undefined) {
4912
+ emitNamedDashedIdentExport(dashedName, identStart, identEnd);
4913
+ return;
4914
+ }
4782
4915
  }
4916
+ emitICSSSymbol(identValue, identStart, identEnd);
4783
4917
  }
4784
4918
  };
4785
- // `as` selects the top-level production (§5.3): a `style` attribute is a
4786
- // block's contents, everything else a full stylesheet (the default). `as`
4787
- // and `skip` are per-parse config on the processor; only `locConverter`
4788
- // (per-source) is passed to `process`. One skip set: selector prelude +
4789
- // unread value leaves (non-modules only; CSS Modules needs its selectors
4790
- // and ICSS-captured values).
4919
+ // `as` selects the top-level production of §5.3: a `style` attribute is a
4920
+ // block's contents, anything else a full stylesheet. `as` and `skip` are
4921
+ // per-parse, so only the per-source `locConverter` reaches `process`.
4791
4922
  new SourceProcessor()
4792
4923
  .use(/** @type {VisitorMap} */ (visitors))
4793
4924
  .process(source, {
@@ -26,6 +26,15 @@ class CssServerStylesRuntimeModule extends RuntimeModule {
26
26
  return false;
27
27
  }
28
28
 
29
+ /**
30
+ * The `[handlerMap, key]` pairs this module installs onto a chunk handler map
31
+ * such as `__webpack_require__.f`, or `null` where it cannot name them.
32
+ * @returns {[string, string][] | null} installed chunk handlers (do not mutate)
33
+ */
34
+ getInstalledChunkHandlers() {
35
+ return RuntimeModule.NO_CHUNK_HANDLERS;
36
+ }
37
+
29
38
  /**
30
39
  * Generates runtime code for this runtime module.
31
40
  * @returns {string | null} runtime code
@@ -31,9 +31,9 @@
31
31
  * imported at module scope: `minimizer-webpack-plugin` ships this function to its
32
32
  * worker pool as source (a top-level import wouldn't survive), and `require("webpack")`
33
33
  * re-resolves in the worker — via the installed package, or the dev self-link.
34
- * @param {{ [file: string]: string }} input a single `{ filename: code }` entry
34
+ * @param {{ [file: string]: string | Buffer }} input a single `{ filename: code }` entry; a `Buffer` is read as UTF-8
35
35
  * @param {object=} sourceMap the asset's input source map — the plugin chains it onto the map returned here, so it isn't read directly
36
- * @param {{ as?: "stylesheet" | "block-contents", environment?: CssEnvironment, convertLengthUnits?: boolean, rewriteCustomProperties?: boolean, renderEmbeddedSource?: AsyncEmbeddedSourceRenderer } & CssTransformOptions=} minimizerOptions minimizer options — `environment` carries the target's CSS abilities (see `output.environment`), so a spelling the target cannot read is not reached for; the rest is `optimization.minimize.css` (e.g. `convertLengthUnits`, and the per-transform switches). `renderEmbeddedSource` minifies source this stylesheet embeds, and may be asynchronous: one parse serves both it and the output
36
+ * @param {{ as?: "stylesheet" | "block-contents", environment?: CssEnvironment, convertLengthUnits?: boolean, mergeDistantRules?: boolean, rewriteCustomProperties?: boolean, unusedSymbols?: string[], pseudoClasses?: { [name: string]: string }, renderEmbeddedSource?: AsyncEmbeddedSourceRenderer } & CssTransformOptions=} minimizerOptions minimizer options — `environment` carries the target's CSS abilities (see `output.environment`), so a spelling the target cannot read is not reached for; the rest is `optimization.minimize.css` (e.g. `convertLengthUnits`, and the per-transform switches). `renderEmbeddedSource` minifies source this stylesheet embeds, and may be asynchronous: one parse serves both it and the output
37
37
  * @returns {Promise<{ code: string, map?: SourceMap, warnings?: (Error | string)[], errors?: (Error | string)[] }>} the minified CSS, its input->output source map (one anchor for the whole of a `block-contents` print, which is emitted as one piece), and what a renderer reported over what this embeds
38
38
  */
39
39
  const cssMinify = async (input, sourceMap, minimizerOptions = {}) => {
@@ -44,36 +44,40 @@ const cssMinify = async (input, sourceMap, minimizerOptions = {}) => {
44
44
 
45
45
  // TODO expose the remaining declined transforms on `optimization.minimize.css`
46
46
  // like `convertLengthUnits` — the switches below turn off what webpack does
47
- // make, not what it declines. Each is on in other minifiers; what each costs:
48
- // - dropping a declaration a later one overrides, which loses a fallback pair
49
- // an engine that cannot read the newer spelling depends on;
50
- // - merging rules a third stands between, and merging non-adjacent `@media`,
51
- // both of which reorder the cascade (csso loses ~12,900 Tailwind classes to
52
- // it). Adjacent rules sharing a block do join, nothing being between them to
53
- // step over — only where every selector is a shape each engine parses, since
54
- // one it cannot invalidates the whole list and loses the rest with it;
55
- // - the color conversions webpack declines rather than guesses. Every polar and
56
- // Lab function converts to hex, except two cases the other minifiers convert
57
- // regardless: a channel landing near a `.5` boundary, where implementations
58
- // round opposite ways (it is why esbuild and lightningcss emit different
59
- // bytes for `hwb(194 0% 0%)`), and a Lab-family color outside the sRGB gamut,
60
- // which hex would clip to a different color rather than respell.
61
- // Which longhand families merge into their shorthand is decided in
62
- // `tooling/generate-css-data.js`, and three kinds are excluded there for good
63
- // rather than pending an option:
64
- // - a shorthand gathering a whole family (`border`, `font`, `background`,
47
+ // make, not what it declines.
48
+
49
+ // WHY: each transform webpack declines is on in other minifiers, and each costs
50
+ // something measured.
51
+ // - Dropping a declaration a later one overrides loses a fallback pair an
52
+ // engine that cannot read the newer spelling depends on.
53
+ // - Merging rules a third stands between, and merging non-adjacent `@media`,
54
+ // both reorder the cascade (csso loses ~12,900 Tailwind classes to it).
55
+ // Adjacent rules sharing a block do join, nothing being between them to step
56
+ // over — only where every selector is a shape each engine parses, since one
57
+ // it cannot invalidates the whole list and loses the rest with it.
58
+ // - Two color conversions are declined rather than guessed. Every polar and Lab
59
+ // function converts to hex, except a channel landing near a `.5` boundary,
60
+ // where implementations round opposite ways (which is why esbuild and
61
+ // lightningcss emit different bytes for `hwb(194 0% 0%)`), and a Lab-family
62
+ // color outside the sRGB gamut, which hex would clip rather than respell.
63
+
64
+ // WHY: which longhand families merge into their shorthand is decided in
65
+ // `tooling/generate-css-data.js`, where three kinds are excluded for good
66
+ // rather than pending an option.
67
+ // - A shorthand gathering a whole family (`border`, `font`, `background`,
65
68
  // `transition`, `flex`, `columns`) resets longhands `computed` does not
66
69
  // name — `border` clears `border-image`, `font` clears `font-size-adjust` —
67
- // so the merge would drop a declaration nothing in the family wrote. The
68
- // ones checked against a browser and found to reset nothing else do merge
69
- // (`FAMILY_LONGHANDS`), where each value parses back into its own slot;
70
- // - a shorthand materially newer than its longhands (`place-items`/`-content`
70
+ // so the merge would drop a declaration nothing in the family wrote. The ones
71
+ // checked against a browser and found to reset nothing else do merge
72
+ // (`FAMILY_LONGHANDS`), where each value parses back into its own slot.
73
+ // - A shorthand materially newer than its longhands (`place-items`/`-content`
71
74
  // /`-self`) would lose both declarations, not one, on a target reading only
72
- // the longhands. `output.environment` states this for `inset` alone.
73
- // `overflow` is newer only two values wide, so it merges when it collapses;
74
- // - a pair two shorthands both claim, which cannot be right for both. None
75
+ // the longhands. `output.environment` states this for `inset` alone, and
76
+ // `overflow` is newer only two values wide, so it merges when it collapses.
77
+ // - A pair two shorthands both claim, which cannot be right for both. None
75
78
  // today: `mdn-data` gave `corner-inline-start-shape` the block-start edge's
76
79
  // corners, corrected in the generator to the pair Chromium computes.
80
+
77
81
  const {
78
82
  SourceProcessor,
79
83
  askEmbeddedRenderer,
@@ -81,16 +85,20 @@ const cssMinify = async (input, sourceMap, minimizerOptions = {}) => {
81
85
  embeddedText,
82
86
  pickTransforms
83
87
  } = webpack.css.syntax;
84
- const [[file, code]] = Object.entries(input);
85
- // `process` parses once, and with `mode: "minify"` the same walk also prints
86
- // the safely minified serialization — no second parse. Naming the input with
87
- // `source` / `content` is what asks for the map, which the plugin composes
88
- // back to the original source.
88
+ const [[file, given]] = Object.entries(input);
89
+ // The plugin hands a text minifier a string; the type admits an image's bytes.
90
+ const code = typeof given === "string" ? given : given.toString("utf8");
91
+ // `process` parses once, and under `mode: "minify"` the same walk prints the
92
+ // minified serialization too. Naming the input with `source` or `content` is
93
+ // what asks for the map the plugin composes back to the original.
89
94
  const {
90
95
  as,
91
96
  environment,
92
97
  convertLengthUnits,
98
+ mergeDistantRules,
93
99
  rewriteCustomProperties,
100
+ unusedSymbols,
101
+ pseudoClasses,
94
102
  renderEmbeddedSource
95
103
  } = minimizerOptions;
96
104
  // One set of options, handed to the print. `as` names the production: a
@@ -103,7 +111,10 @@ const cssMinify = async (input, sourceMap, minimizerOptions = {}) => {
103
111
  content: code,
104
112
  environment,
105
113
  convertLengthUnits,
114
+ mergeDistantRules,
106
115
  rewriteCustomProperties,
116
+ unusedSymbols,
117
+ pseudoClasses,
107
118
  // The per-transform switches stand beside those rather than nested in
108
119
  // them, so a config names one the way it names `convertLengthUnits`;
109
120
  // `pickTransforms` is what knows which names those are.