webpack 5.111.1 → 5.112.1

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 (793) hide show
  1. package/README.md +1 -1
  2. package/bin/webpack.js +13 -7
  3. package/lib/Chunk.js +3 -966
  4. package/lib/Compilation.js +373 -163
  5. package/lib/Compiler.js +31 -44
  6. package/lib/Dependency.js +3 -551
  7. package/lib/DependencyTemplate.js +3 -70
  8. package/lib/EntryPlugin.js +3 -68
  9. package/lib/Entrypoint.js +3 -121
  10. package/lib/ExternalsPlugin.js +3 -92
  11. package/lib/FileSystemInfo.js +3 -4629
  12. package/lib/InitFragment.js +3 -204
  13. package/lib/LibraryTemplatePlugin.js +3 -46
  14. package/lib/ModuleFilenameHelpers.js +3 -400
  15. package/lib/ModuleNotFoundError.js +2 -2
  16. package/lib/MultiCompiler.js +37 -8
  17. package/lib/NormalModule.js +3 -2242
  18. package/lib/NullFactory.js +3 -22
  19. package/lib/ProgressPlugin.js +3 -908
  20. package/lib/RawModule.js +3 -197
  21. package/lib/RequestShortener.js +3 -37
  22. package/lib/SingleEntryPlugin.js +1 -1
  23. package/lib/WebpackError.js +2 -2
  24. package/lib/asset/AssetBytesGenerator.js +21 -13
  25. package/lib/asset/AssetBytesParser.js +12 -10
  26. package/lib/asset/AssetGenerator.js +71 -69
  27. package/lib/asset/AssetModule.js +13 -2
  28. package/lib/asset/AssetModulesPlugin.js +10 -12
  29. package/lib/asset/AssetParser.js +10 -10
  30. package/lib/asset/AssetSourceGenerator.js +23 -15
  31. package/lib/asset/AssetSourceParser.js +12 -10
  32. package/lib/asset/RawDataUrlModule.js +17 -10
  33. package/lib/asset/WebManifestGenerator.js +17 -12
  34. package/lib/asset/WebManifestParser.js +8 -8
  35. package/lib/async-modules/AsyncModuleHelpers.js +12 -5
  36. package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -4
  37. package/lib/async-modules/InferAsyncModulesPlugin.js +9 -3
  38. package/lib/async-modules/isGeneratorLowered.js +3 -3
  39. package/lib/bun/BunTargetPlugin.js +1 -1
  40. package/lib/cache/AddBuildDependenciesPlugin.js +2 -19
  41. package/lib/{Cache.js → cache/Cache.js} +1 -1
  42. package/lib/{CacheFacade.js → cache/CacheFacade.js} +6 -6
  43. package/lib/cache/IdleFileCachePlugin.js +2 -2
  44. package/lib/cache/MemoryCachePlugin.js +2 -2
  45. package/lib/cache/MemoryWithGcCachePlugin.js +2 -2
  46. package/lib/cache/PackFileCacheStrategy.js +13 -19
  47. package/lib/cache/ResolverCachePlugin.js +65 -11
  48. package/lib/cache/mergeEtags.js +1 -1
  49. package/lib/{OptionsApply.js → config/OptionsApply.js} +3 -3
  50. package/lib/{PlatformPlugin.js → config/PlatformPlugin.js} +2 -2
  51. package/lib/{WebpackOptionsApply.js → config/WebpackOptionsApply.js} +209 -212
  52. package/lib/{WebpackOptionsDefaulter.js → config/WebpackOptionsDefaulter.js} +3 -3
  53. package/lib/config/browserslistTargetHandler.js +1 -1
  54. package/lib/{cli.js → config/cli.js} +14 -164
  55. package/lib/config/defaults.js +166 -59
  56. package/lib/config/getClaimedAssetTypes.js +22 -14
  57. package/lib/config/normalization.js +18 -7
  58. package/lib/config/target.js +11 -1
  59. package/lib/container/ContainerEntryDependency.js +1 -1
  60. package/lib/container/ContainerEntryModule.js +13 -11
  61. package/lib/container/ContainerEntryModuleFactory.js +2 -2
  62. package/lib/container/ContainerExposedDependency.js +1 -1
  63. package/lib/container/ContainerPlugin.js +178 -5
  64. package/lib/container/ContainerReferencePlugin.js +75 -14
  65. package/lib/container/FallbackDependency.js +1 -1
  66. package/lib/container/FallbackItemDependency.js +1 -1
  67. package/lib/container/FallbackModule.js +12 -10
  68. package/lib/container/FallbackModuleFactory.js +2 -2
  69. package/lib/container/HoistContainerReferencesPlugin.js +10 -11
  70. package/lib/container/ModuleFederationPlugin.js +306 -7
  71. package/lib/container/RemoteModule.js +14 -10
  72. package/lib/container/RemoteRuntimeModule.js +5 -5
  73. package/lib/container/RemoteToExternalDependency.js +1 -1
  74. package/lib/container/moduleFederationHooks.js +1 -1
  75. package/lib/context/ContextModule.js +37 -26
  76. package/lib/context/ContextModuleFactory.js +14 -11
  77. package/lib/context/ContextReplacementPlugin.js +6 -12
  78. package/lib/css/CssGenerator.js +78 -68
  79. package/lib/css/CssInjectStyleRuntimeModule.js +36 -30
  80. package/lib/css/CssLoadingRuntimeModule.js +77 -44
  81. package/lib/css/CssModule.js +37 -29
  82. package/lib/css/CssModulesPlugin.js +129 -45
  83. package/lib/css/CssParser.js +714 -322
  84. package/lib/css/CssServerStylesRuntimeModule.js +3 -3
  85. package/lib/{util → css}/conventions.js +1 -1
  86. package/lib/css/cssMinify.js +110 -37
  87. package/lib/css/data.js +6990 -5125
  88. package/lib/css/syntax-parser.js +20734 -0
  89. package/lib/css/syntax-printer.js +6092 -0
  90. package/lib/css/syntax.js +37 -18686
  91. package/lib/debug/ProfilingPlugin.js +106 -51
  92. package/lib/{DefinePlugin.js → define/DefinePlugin.js} +416 -55
  93. package/lib/{DotenvPlugin.js → define/DotenvPlugin.js} +19 -15
  94. package/lib/{EnvironmentPlugin.js → define/EnvironmentPlugin.js} +6 -4
  95. package/lib/deno/DenoTargetPlugin.js +1 -1
  96. package/lib/dependencies/ConstDependency.js +3 -120
  97. package/lib/dependencies/ContextElementDependency.js +5 -172
  98. package/lib/dependencies/NullDependency.js +3 -37
  99. package/lib/dependencies/{AMDDefineDependency.js → amd/AMDDefineDependency.js} +12 -11
  100. package/lib/dependencies/{AMDDefineDependencyParserPlugin.js → amd/AMDDefineDependencyParserPlugin.js} +10 -11
  101. package/lib/dependencies/{AMDPlugin.js → amd/AMDPlugin.js} +11 -11
  102. package/lib/dependencies/{AMDRequireArrayDependency.js → amd/AMDRequireArrayDependency.js} +15 -13
  103. package/lib/dependencies/{AMDRequireContextDependency.js → amd/AMDRequireContextDependency.js} +11 -10
  104. package/lib/dependencies/{AMDRequireDependenciesBlock.js → amd/AMDRequireDependenciesBlock.js} +7 -6
  105. package/lib/dependencies/{AMDRequireDependenciesBlockParserPlugin.js → amd/AMDRequireDependenciesBlockParserPlugin.js} +14 -11
  106. package/lib/dependencies/{AMDRequireDependency.js → amd/AMDRequireDependency.js} +13 -12
  107. package/lib/dependencies/{AMDRequireItemDependency.js → amd/AMDRequireItemDependency.js} +8 -7
  108. package/lib/dependencies/{AMDRuntimeModules.js → amd/AMDRuntimeModules.js} +3 -3
  109. package/lib/dependencies/{LocalModule.js → amd/LocalModule.js} +8 -4
  110. package/lib/dependencies/{LocalModuleDependency.js → amd/LocalModuleDependency.js} +17 -10
  111. package/lib/dependencies/{LocalModulesHelpers.js → amd/LocalModulesHelpers.js} +1 -1
  112. package/lib/dependencies/{RequireJsStuffPlugin.js → amd/RequireJsStuffPlugin.js} +9 -9
  113. package/lib/dependencies/{UnsupportedDependency.js → amd/UnsupportedDependency.js} +11 -10
  114. package/lib/dependencies/{CommonJsDependencyHelpers.js → commonjs/CommonJsDependencyHelpers.js} +8 -9
  115. package/lib/dependencies/{CommonJsExportRequireDependency.js → commonjs/CommonJsExportRequireDependency.js} +166 -36
  116. package/lib/dependencies/{CommonJsExportsDependency.js → commonjs/CommonJsExportsDependency.js} +15 -14
  117. package/lib/dependencies/{CommonJsExportsParserPlugin.js → commonjs/CommonJsExportsParserPlugin.js} +154 -92
  118. package/lib/dependencies/{CommonJsFullRequireDependency.js → commonjs/CommonJsFullRequireDependency.js} +32 -24
  119. package/lib/dependencies/{CommonJsImportsParserPlugin.js → commonjs/CommonJsImportsParserPlugin.js} +36 -33
  120. package/lib/dependencies/{CommonJsObjectExportDependency.js → commonjs/CommonJsObjectExportDependency.js} +17 -16
  121. package/lib/dependencies/{CommonJsPlugin.js → commonjs/CommonJsPlugin.js} +48 -39
  122. package/lib/dependencies/{CommonJsRequireContextDependency.js → commonjs/CommonJsRequireContextDependency.js} +15 -14
  123. package/lib/dependencies/{CommonJsRequireDependency.js → commonjs/CommonJsRequireDependency.js} +33 -25
  124. package/lib/dependencies/{CommonJsSelfReferenceDependency.js → commonjs/CommonJsSelfReferenceDependency.js} +17 -16
  125. package/lib/dependencies/{ModuleDecoratorDependency.js → commonjs/ModuleDecoratorDependency.js} +16 -15
  126. package/lib/dependencies/{RequireEnsureDependenciesBlock.js → commonjs/RequireEnsureDependenciesBlock.js} +8 -7
  127. package/lib/dependencies/{RequireEnsureDependenciesBlockParserPlugin.js → commonjs/RequireEnsureDependenciesBlockParserPlugin.js} +9 -6
  128. package/lib/dependencies/{RequireEnsureDependency.js → commonjs/RequireEnsureDependency.js} +13 -12
  129. package/lib/dependencies/{RequireEnsureItemDependency.js → commonjs/RequireEnsureItemDependency.js} +7 -6
  130. package/lib/dependencies/{RequireEnsurePlugin.js → commonjs/RequireEnsurePlugin.js} +8 -8
  131. package/lib/dependencies/{RequireHeaderDependency.js → commonjs/RequireHeaderDependency.js} +14 -13
  132. package/lib/dependencies/{RequireIncludeDependency.js → commonjs/RequireIncludeDependency.js} +13 -12
  133. package/lib/dependencies/{RequireIncludeDependencyParserPlugin.js → commonjs/RequireIncludeDependencyParserPlugin.js} +3 -27
  134. package/lib/dependencies/{RequireIncludePlugin.js → commonjs/RequireIncludePlugin.js} +4 -4
  135. package/lib/dependencies/{RequireResolveContextDependency.js → commonjs/RequireResolveContextDependency.js} +11 -10
  136. package/lib/dependencies/{RequireResolveDependency.js → commonjs/RequireResolveDependency.js} +12 -11
  137. package/lib/dependencies/{RequireResolveHeaderDependency.js → commonjs/RequireResolveHeaderDependency.js} +13 -12
  138. package/lib/dependencies/commonjs/TopLevelThisParserPlugin.js +59 -0
  139. package/lib/dependencies/{ContextDependency.js → context/ContextDependency.js} +15 -14
  140. package/lib/dependencies/{ContextDependencyHelpers.js → context/ContextDependencyHelpers.js} +31 -9
  141. package/lib/dependencies/{ContextDependencyTemplateAsId.js → context/ContextDependencyTemplateAsId.js} +3 -3
  142. package/lib/dependencies/{ContextDependencyTemplateAsRequireCall.js → context/ContextDependencyTemplateAsRequireCall.js} +3 -3
  143. package/lib/dependencies/context/ContextElementDependency.js +198 -0
  144. package/lib/dependencies/{ImportMetaContextDependency.js → context/ImportMetaContextDependency.js} +7 -6
  145. package/lib/dependencies/{ImportMetaContextDependencyParserPlugin.js → context/ImportMetaContextDependencyParserPlugin.js} +10 -11
  146. package/lib/dependencies/{ImportMetaContextPlugin.js → context/ImportMetaContextPlugin.js} +5 -5
  147. package/lib/dependencies/{ImportMetaGlobDependency.js → context/ImportMetaGlobDependency.js} +7 -6
  148. package/lib/dependencies/{ImportMetaGlobDependencyParserPlugin.js → context/ImportMetaGlobDependencyParserPlugin.js} +7 -10
  149. package/lib/dependencies/{ImportMetaGlobHelpers.js → context/ImportMetaGlobHelpers.js} +17 -19
  150. package/lib/dependencies/{RequireContextDependency.js → context/RequireContextDependency.js} +7 -6
  151. package/lib/dependencies/{RequireContextDependencyParserPlugin.js → context/RequireContextDependencyParserPlugin.js} +2 -2
  152. package/lib/dependencies/{RequireContextPlugin.js → context/RequireContextPlugin.js} +5 -5
  153. package/lib/dependencies/{CachedConstDependency.js → core/CachedConstDependency.js} +21 -17
  154. package/lib/dependencies/core/ConstDependency.js +131 -0
  155. package/lib/dependencies/{ImportPhase.js → core/ImportPhase.js} +5 -4
  156. package/lib/dependencies/{ModuleDependency.js → core/ModuleDependency.js} +10 -7
  157. package/lib/dependencies/{ModuleDependencyTemplateAsId.js → core/ModuleDependencyTemplateAsId.js} +3 -3
  158. package/lib/dependencies/{ModuleDependencyTemplateAsRequireId.js → core/ModuleDependencyTemplateAsRequireId.js} +2 -2
  159. package/lib/dependencies/{ModuleInitFragmentDependency.js → core/ModuleInitFragmentDependency.js} +10 -9
  160. package/lib/dependencies/core/NullDependency.js +44 -0
  161. package/lib/dependencies/{RuntimeRequirementsDependency.js → core/RuntimeRequirementsDependency.js} +10 -9
  162. package/lib/dependencies/{StaticExportsDependency.js → core/StaticExportsDependency.js} +15 -8
  163. package/lib/dependencies/{CssIcssExportDependency.js → css/CssIcssExportDependency.js} +375 -99
  164. package/lib/dependencies/{CssIcssImportDependency.js → css/CssIcssImportDependency.js} +24 -19
  165. package/lib/dependencies/{CssIcssSymbolDependency.js → css/CssIcssSymbolDependency.js} +13 -12
  166. package/lib/dependencies/{CssImportDependency.js → css/CssImportDependency.js} +15 -11
  167. package/lib/dependencies/{CssUrlDependency.js → css/CssUrlDependency.js} +25 -22
  168. package/lib/dependencies/{CreateRequireParserPlugin.js → esm/CreateRequireParserPlugin.js} +9 -9
  169. package/lib/dependencies/{HarmonyAcceptDependency.js → esm/ESMAcceptDependency.js} +41 -38
  170. package/lib/dependencies/esm/ESMAcceptImportDependency.js +39 -0
  171. package/lib/dependencies/{HarmonyCompatibilityDependency.js → esm/ESMCompatibilityDependency.js} +29 -21
  172. package/lib/dependencies/{HarmonyDetectionParserPlugin.js → esm/ESMDetectionParserPlugin.js} +20 -20
  173. package/lib/dependencies/{HarmonyEvaluatedImportSpecifierDependency.js → esm/ESMEvaluatedImportSpecifierDependency.js} +33 -30
  174. package/lib/dependencies/{HarmonyExportDependencyParserPlugin.js → esm/ESMExportDependencyParserPlugin.js} +60 -89
  175. package/lib/dependencies/{HarmonyExportExpressionDependency.js → esm/ESMExportExpressionDependency.js} +80 -45
  176. package/lib/dependencies/{HarmonyExportHeaderDependency.js → esm/ESMExportHeaderDependency.js} +17 -15
  177. package/lib/dependencies/esm/ESMExportImportedSideEffectDependency.js +37 -0
  178. package/lib/dependencies/{HarmonyExportImportedSpecifierDependency.js → esm/ESMExportImportedSpecifierDependency.js} +146 -133
  179. package/lib/dependencies/{HarmonyExportInitFragment.js → esm/ESMExportInitFragment.js} +48 -30
  180. package/lib/dependencies/{HarmonyExportSpecifierDependency.js → esm/ESMExportSpecifierDependency.js} +78 -37
  181. package/lib/dependencies/{HarmonyExports.js → esm/ESMExports.js} +4 -12
  182. package/lib/dependencies/{HarmonyImportBareSideEffectDependency.js → esm/ESMImportBareSideEffectDependency.js} +21 -13
  183. package/lib/dependencies/{HarmonyImportDependency.js → esm/ESMImportDependency.js} +86 -68
  184. package/lib/dependencies/{HarmonyImportDependencyParserPlugin.js → esm/ESMImportDependencyParserPlugin.js} +104 -100
  185. package/lib/dependencies/{HarmonyImportGuard.js → esm/ESMImportGuard.js} +36 -51
  186. package/lib/dependencies/{HarmonyImportSideEffectDependency.js → esm/ESMImportSideEffectDependency.js} +83 -39
  187. package/lib/dependencies/{HarmonyImportSpecifierDependency.js → esm/ESMImportSpecifierDependency.js} +98 -60
  188. package/lib/dependencies/esm/ESMLiveExportDependency.js +311 -0
  189. package/lib/dependencies/esm/ESMLiveExportParserPlugin.js +862 -0
  190. package/lib/dependencies/esm/ESMModulesPlugin.js +205 -0
  191. package/lib/dependencies/{HarmonyTopLevelThisParserPlugin.js → esm/ESMTopLevelThisParserPlugin.js} +7 -7
  192. package/lib/dependencies/{TopLevelAwaitDependency.js → esm/TopLevelAwaitDependency.js} +12 -18
  193. package/lib/dependencies/{DynamicExports.js → helpers/DynamicExports.js} +5 -7
  194. package/lib/{util → dependencies/helpers}/chainedImports.js +5 -5
  195. package/lib/dependencies/{processExportInfo.js → helpers/processExportInfo.js} +4 -4
  196. package/lib/{util → dependencies/helpers}/traverseDestructuringAssignmentProperties.js +1 -1
  197. package/lib/dependencies/{ImportMetaHotAcceptDependency.js → hmr/ImportMetaHotAcceptDependency.js} +8 -7
  198. package/lib/dependencies/{ImportMetaHotDeclineDependency.js → hmr/ImportMetaHotDeclineDependency.js} +8 -7
  199. package/lib/dependencies/{ModuleHotAcceptDependency.js → hmr/ModuleHotAcceptDependency.js} +8 -7
  200. package/lib/dependencies/{ModuleHotDeclineDependency.js → hmr/ModuleHotDeclineDependency.js} +8 -7
  201. package/lib/dependencies/{HtmlEntryDependency.js → html/HtmlEntryDependency.js} +52 -151
  202. package/lib/dependencies/{HtmlInlineHtmlDependency.js → html/HtmlInlineHtmlDependency.js} +13 -15
  203. package/lib/dependencies/{HtmlInlineScriptDependency.js → html/HtmlInlineScriptDependency.js} +69 -23
  204. package/lib/dependencies/{HtmlInlineStyleDependency.js → html/HtmlInlineStyleDependency.js} +50 -18
  205. package/lib/dependencies/{HtmlSourceDependency.js → html/HtmlSourceDependency.js} +23 -16
  206. package/lib/dependencies/{ImportContextDependency.js → import/ImportContextDependency.js} +24 -10
  207. package/lib/dependencies/{ImportDependency.js → import/ImportDependency.js} +26 -18
  208. package/lib/dependencies/{ImportEagerDependency.js → import/ImportEagerDependency.js} +18 -10
  209. package/lib/dependencies/{ImportParserPlugin.js → import/ImportParserPlugin.js} +22 -25
  210. package/lib/dependencies/{ImportPlugin.js → import/ImportPlugin.js} +4 -4
  211. package/lib/dependencies/{ImportWeakDependency.js → import/ImportWeakDependency.js} +18 -10
  212. package/lib/dependencies/{importOptionsCheck.js → import/importOptionsCheck.js} +2 -2
  213. package/lib/dependencies/{BuildTimeConstDependency.js → import-meta/BuildTimeConstDependency.js} +12 -11
  214. package/lib/dependencies/{ImportMetaMainDependency.js → import-meta/ImportMetaMainDependency.js} +12 -11
  215. package/lib/dependencies/{ImportMetaPlugin.js → import-meta/ImportMetaPlugin.js} +122 -103
  216. package/lib/dependencies/{SystemPlugin.js → system/SystemPlugin.js} +11 -38
  217. package/lib/dependencies/{SystemRuntimeModule.js → system/SystemRuntimeModule.js} +3 -3
  218. package/lib/dependencies/{ImportMetaResolveDependency.js → url/ImportMetaResolveDependency.js} +9 -8
  219. package/lib/dependencies/{URLContextDependency.js → url/URLContextDependency.js} +11 -10
  220. package/lib/dependencies/{URLDependency.js → url/URLDependency.js} +28 -20
  221. package/lib/{url → dependencies/url}/URLParserPlugin.js +17 -19
  222. package/lib/dependencies/{URLPlugin.js → url/URLPlugin.js} +6 -7
  223. package/lib/dependencies/{WebAssemblyExportImportedDependency.js → wasm/WebAssemblyExportImportedDependency.js} +18 -11
  224. package/lib/dependencies/{WebAssemblyImportDependency.js → wasm/WebAssemblyImportDependency.js} +19 -12
  225. package/lib/dependencies/{CreateScriptUrlDependency.js → worker/CreateScriptUrlDependency.js} +12 -11
  226. package/lib/dependencies/{WorkerAndWorkletPlugin.js → worker/WorkerAndWorkletPlugin.js} +82 -53
  227. package/lib/dependencies/{WorkerDependency.js → worker/WorkerDependency.js} +22 -15
  228. package/lib/dependencies/{WorkletDependency.js → worker/WorkletDependency.js} +19 -18
  229. package/lib/{EvalDevToolModulePlugin.js → devtool/EvalDevToolModulePlugin.js} +20 -6
  230. package/lib/{EvalSourceMapDevToolPlugin.js → devtool/EvalSourceMapDevToolPlugin.js} +32 -24
  231. package/lib/devtool/ModuleFilenameHelpers.js +413 -0
  232. package/lib/{SourceMapDevToolModuleOptionsPlugin.js → devtool/SourceMapDevToolModuleOptionsPlugin.js} +10 -3
  233. package/lib/{SourceMapDevToolPlugin.js → devtool/SourceMapDevToolPlugin.js} +155 -27
  234. package/lib/{util → devtool}/generateDebugId.js +1 -1
  235. package/lib/{IgnoreWarningsPlugin.js → diagnostics/IgnoreWarningsPlugin.js} +2 -2
  236. package/lib/{NoEmitOnErrorsPlugin.js → diagnostics/NoEmitOnErrorsPlugin.js} +1 -1
  237. package/lib/diagnostics/WarnCaseSensitiveModulesPlugin.js +64 -0
  238. package/lib/{WarnDeprecatedOptionPlugin.js → diagnostics/WarnDeprecatedOptionPlugin.js} +2 -22
  239. package/lib/diagnostics/WarnNoModeSetPlugin.js +27 -0
  240. package/lib/dll/DelegatedModule.js +23 -21
  241. package/lib/dll/DelegatedModuleFactoryPlugin.js +2 -2
  242. package/lib/dll/DelegatedPlugin.js +1 -1
  243. package/lib/{dependencies → dll}/DelegatedSourceDependency.js +5 -4
  244. package/lib/{dependencies → dll}/DllEntryDependency.js +6 -5
  245. package/lib/dll/DllEntryPlugin.js +3 -3
  246. package/lib/dll/DllModule.js +14 -10
  247. package/lib/dll/DllModuleFactory.js +3 -3
  248. package/lib/dll/DllPlugin.js +18 -6
  249. package/lib/dll/DllReferencePlugin.js +103 -30
  250. package/lib/dll/LibManifestPlugin.js +9 -7
  251. package/lib/electron/ElectronTargetPlugin.js +2 -2
  252. package/lib/{DynamicEntryPlugin.js → entry/DynamicEntryPlugin.js} +3 -3
  253. package/lib/{dependencies → entry}/EntryDependency.js +11 -2
  254. package/lib/{EntryOptionPlugin.js → entry/EntryOptionPlugin.js} +6 -6
  255. package/lib/entry/EntryPlugin.js +75 -0
  256. package/lib/errors/AbstractMethodError.js +1 -1
  257. package/lib/{performance → errors}/AssetsOverSizeLimitWarning.js +2 -2
  258. package/lib/errors/AsyncDependencyToInitialChunkError.js +2 -2
  259. package/lib/errors/BuildCycleError.js +1 -1
  260. package/lib/{WarnCaseSensitiveModulesPlugin.js → errors/CaseSensitiveModulesWarning.js} +4 -56
  261. package/lib/errors/ChunkRenderError.js +1 -1
  262. package/lib/errors/CodeGenerationError.js +1 -1
  263. package/lib/errors/CommentCompilationWarning.js +1 -1
  264. package/lib/errors/ConflictingEntryExportsWarning.js +38 -0
  265. package/lib/{dependencies → errors}/CriticalDependencyWarning.js +4 -3
  266. package/lib/errors/DeprecatedOptionWarning.js +30 -0
  267. package/lib/errors/DllManifestError.js +26 -0
  268. package/lib/{performance → errors}/DuplicatePackagesWarning.js +6 -6
  269. package/lib/{dependencies/HarmonyLinkingError.js → errors/ESMLinkingError.js} +4 -4
  270. package/lib/{performance → errors}/EntrypointsOverSizeLimitWarning.js +2 -2
  271. package/lib/errors/EnvironmentNotSupportAsyncWarning.js +2 -2
  272. package/lib/{ErrorHelpers.js → errors/ErrorHelpers.js} +9 -6
  273. package/lib/errors/ExternalStarReexportError.js +2 -2
  274. package/lib/{library → errors}/FalseIIFEUmdWarning.js +1 -1
  275. package/lib/errors/HookWebpackError.js +6 -5
  276. package/lib/errors/IgnoreErrorModuleFactory.js +3 -3
  277. package/lib/errors/InvalidDependenciesModuleWarning.js +1 -1
  278. package/lib/errors/JSONParseError.js +4 -4
  279. package/lib/{optimize → errors}/MinMaxSizeWarning.js +1 -1
  280. package/lib/errors/ModuleBuildError.js +1 -1
  281. package/lib/errors/ModuleDependencyError.js +2 -2
  282. package/lib/errors/ModuleDependencyWarning.js +2 -2
  283. package/lib/errors/ModuleError.js +1 -1
  284. package/lib/errors/ModuleHashingError.js +1 -1
  285. package/lib/errors/ModuleNotFoundError.js +3 -3
  286. package/lib/errors/ModuleParseError.js +1 -1
  287. package/lib/errors/ModuleRestoreError.js +1 -1
  288. package/lib/errors/ModuleStoreError.js +1 -1
  289. package/lib/errors/ModuleWarning.js +1 -1
  290. package/lib/{performance → errors}/NoAsyncChunksWarning.js +1 -1
  291. package/lib/{WarnNoModeSetPlugin.js → errors/NoModeWarning.js} +2 -19
  292. package/lib/errors/NodeStuffInWebError.js +7 -2
  293. package/lib/errors/PathVariableError.js +31 -0
  294. package/lib/errors/RequireIncludeDeprecationWarning.js +40 -0
  295. package/lib/{performance → errors}/RuntimeInLargeChunkWarning.js +1 -1
  296. package/lib/errors/RuntimeModuleGenerationError.js +51 -0
  297. package/lib/errors/SSRManifestAutoPublicPathWarning.js +24 -0
  298. package/lib/errors/SystemImportDeprecationWarning.js +43 -0
  299. package/lib/errors/UnmergeableEntryExportsError.js +34 -0
  300. package/lib/errors/UnsupportedFeatureWarning.js +1 -1
  301. package/lib/{wasm-sync → errors}/UnsupportedWebAssemblyFeatureError.js +1 -1
  302. package/lib/{wasm-sync → errors}/WebAssemblyInInitialChunkError.js +7 -5
  303. package/lib/errors/WebpackError.js +13 -3
  304. package/lib/esm/ExportWebpackRequireRuntimeModule.js +2 -2
  305. package/lib/esm/ModuleChunkFormatPlugin.js +55 -20
  306. package/lib/esm/ModuleChunkLoadingPlugin.js +3 -3
  307. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +8 -8
  308. package/lib/{ExternalModule.js → externals/ExternalModule.js} +90 -63
  309. package/lib/{ExternalModuleFactoryPlugin.js → externals/ExternalModuleFactoryPlugin.js} +42 -41
  310. package/lib/externals/ExternalsPlugin.js +99 -0
  311. package/lib/fs/FileSystemInfo.js +4642 -0
  312. package/lib/{util → fs}/fs.js +22 -9
  313. package/lib/{AsyncDependenciesBlock.js → graph/AsyncDependenciesBlock.js} +27 -4
  314. package/lib/graph/Chunk.js +985 -0
  315. package/lib/{ChunkGraph.js → graph/ChunkGraph.js} +192 -80
  316. package/lib/{ChunkGroup.js → graph/ChunkGroup.js} +11 -3
  317. package/lib/{DependenciesBlock.js → graph/DependenciesBlock.js} +16 -4
  318. package/lib/graph/Dependency.js +634 -0
  319. package/lib/graph/Entrypoint.js +136 -0
  320. package/lib/{ExportsInfo.js → graph/ExportsInfo.js} +131 -83
  321. package/lib/{HotUpdateChunk.js → graph/HotUpdateChunk.js} +8 -0
  322. package/lib/{ModuleGraph.js → graph/ModuleGraph.js} +44 -33
  323. package/lib/{ModuleGraphConnection.js → graph/ModuleGraphConnection.js} +2 -2
  324. package/lib/{buildChunkGraph.js → graph/buildChunkGraph.js} +169 -76
  325. package/lib/{util → graph}/findGraphRoots.js +15 -9
  326. package/lib/graph/isDependencyKind.js +23 -0
  327. package/lib/hmr/HotModuleReplacement.runtime.js +12 -11
  328. package/lib/{HotModuleReplacementPlugin.js → hmr/HotModuleReplacementPlugin.js} +51 -57
  329. package/lib/hmr/HotModuleReplacementRuntimeModule.js +3 -3
  330. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +25 -26
  331. package/lib/hmr/JavascriptHotModuleReplacementHelper.js +2 -2
  332. package/lib/hmr/LazyCompilationPlugin.js +32 -28
  333. package/lib/html/HtmlGenerator.js +132 -60
  334. package/lib/html/HtmlModule.js +16 -2
  335. package/lib/html/HtmlModulesPlugin.js +184 -87
  336. package/lib/html/HtmlParser.js +511 -160
  337. package/lib/html/builtinEmbeddedRenderer.js +70 -25
  338. package/lib/html/data.js +44 -22
  339. package/lib/html/htmlMinify.js +114 -41
  340. package/lib/html/syntax-parser.js +15795 -0
  341. package/lib/html/syntax-printer.js +1033 -0
  342. package/lib/html/syntax.js +37 -13952
  343. package/lib/html/xmlMinify.js +70 -0
  344. package/lib/ids/ChunkModuleIdRangePlugin.js +2 -2
  345. package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
  346. package/lib/ids/HashedModuleIdsPlugin.js +32 -5
  347. package/lib/ids/IdHelpers.js +4 -4
  348. package/lib/ids/NaturalChunkIdsPlugin.js +1 -1
  349. package/lib/ids/OccurrenceChunkIdsPlugin.js +6 -5
  350. package/lib/ids/OccurrenceModuleIdsPlugin.js +6 -5
  351. package/lib/{RecordIdsPlugin.js → ids/RecordIdsPlugin.js} +5 -5
  352. package/lib/ids/SyncModuleIdsPlugin.js +3 -3
  353. package/lib/{util → ids}/numberHash.js +1 -1
  354. package/lib/index.js +312 -105
  355. package/lib/{APIPlugin.js → javascript/APIPlugin.js} +31 -37
  356. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +4 -5
  357. package/lib/javascript/BasicEvaluatedExpression.js +9 -9
  358. package/lib/javascript/ChunkHelpers.js +64 -4
  359. package/lib/javascript/CommonJsChunkFormatPlugin.js +5 -13
  360. package/lib/{CompatibilityPlugin.js → javascript/CompatibilityPlugin.js} +7 -7
  361. package/lib/{ConstPlugin.js → javascript/ConstPlugin.js} +75 -8
  362. package/lib/{ExportsInfoApiPlugin.js → javascript/ExportsInfoApiPlugin.js} +5 -5
  363. package/lib/{dependencies → javascript}/ExportsInfoDependency.js +10 -9
  364. package/lib/javascript/JavascriptGenerator.js +32 -27
  365. package/lib/{JavascriptMetaInfoPlugin.js → javascript/JavascriptMetaInfoPlugin.js} +8 -20
  366. package/lib/javascript/JavascriptModule.js +14 -3
  367. package/lib/javascript/JavascriptModulesPlugin.js +441 -214
  368. package/lib/javascript/JavascriptParser.js +318 -144
  369. package/lib/javascript/JavascriptParserHelpers.js +1 -1
  370. package/lib/javascript/MergedEntryExports.js +196 -0
  371. package/lib/javascript/ScopeAnalyzer.js +3924 -13
  372. package/lib/javascript/StartupHelpers.js +6 -6
  373. package/lib/{UseStrictPlugin.js → javascript/UseStrictPlugin.js} +13 -19
  374. package/lib/{dependencies → javascript}/WebpackIsIncludedDependency.js +10 -9
  375. package/lib/{WebpackIsIncludedPlugin.js → javascript/WebpackIsIncludedPlugin.js} +8 -8
  376. package/lib/javascript/data.js +533 -122
  377. package/lib/javascript/jsMinify.js +272 -0
  378. package/lib/javascript/regexp.js +67 -32
  379. package/lib/javascript/syntax-parser.js +19169 -0
  380. package/lib/javascript/syntax-printer-data.js +1099 -0
  381. package/lib/javascript/syntax-printer.js +53878 -0
  382. package/lib/javascript/syntax.js +20 -11274
  383. package/lib/json/JsonData.js +1 -1
  384. package/lib/{dependencies → json}/JsonExportsDependency.js +8 -7
  385. package/lib/json/JsonGenerator.js +24 -16
  386. package/lib/json/JsonModule.js +13 -2
  387. package/lib/json/JsonModulesPlugin.js +1 -1
  388. package/lib/json/JsonParser.js +11 -10
  389. package/lib/json/jsonMinify.js +69 -0
  390. package/lib/library/AbstractLibraryPlugin.js +28 -15
  391. package/lib/library/AmdLibraryPlugin.js +4 -4
  392. package/lib/library/AssignLibraryPlugin.js +28 -12
  393. package/lib/library/EnableLibraryPlugin.js +1 -1
  394. package/lib/library/ExportPropertyLibraryPlugin.js +4 -4
  395. package/lib/library/JsonpLibraryPlugin.js +2 -2
  396. package/lib/library/LibraryTemplatePlugin.js +53 -0
  397. package/lib/library/ModuleLibraryPlugin.js +557 -187
  398. package/lib/library/SystemLibraryPlugin.js +6 -8
  399. package/lib/library/UmdLibraryPlugin.js +3 -4
  400. package/lib/{dependencies → loaders}/LoaderDependency.js +3 -3
  401. package/lib/{dependencies → loaders}/LoaderImportDependency.js +9 -3
  402. package/lib/{LoaderOptionsPlugin.js → loaders/LoaderOptionsPlugin.js} +30 -12
  403. package/lib/{dependencies → loaders}/LoaderPlugin.js +2 -2
  404. package/lib/loaders/LoaderRunner.js +94 -46
  405. package/lib/{LoaderTargetPlugin.js → loaders/LoaderTargetPlugin.js} +2 -2
  406. package/lib/loaders/loadLoader.js +16 -10
  407. package/lib/logging/Logger.js +7 -9
  408. package/lib/logging/ProgressPlugin.js +957 -0
  409. package/lib/{CodeGenerationResults.js → module/CodeGenerationResults.js} +7 -7
  410. package/lib/{Generator.js → module/Generator.js} +33 -23
  411. package/lib/{Module.js → module/Module.js} +121 -53
  412. package/lib/{ModuleFactory.js → module/ModuleFactory.js} +3 -3
  413. package/lib/module/NormalModule.js +2350 -0
  414. package/lib/{NormalModuleFactory.js → module/NormalModuleFactory.js} +64 -71
  415. package/lib/module/NullFactory.js +29 -0
  416. package/lib/{Parser.js → module/Parser.js} +12 -5
  417. package/lib/module/RawModule.js +208 -0
  418. package/lib/{SelfModuleFactory.js → module/SelfModuleFactory.js} +1 -1
  419. package/lib/{util → module}/extractSourceMap.js +71 -20
  420. package/lib/{util → module}/findCaseMismatch.js +4 -4
  421. package/lib/node/CommonJsChunkLoadingPlugin.js +3 -3
  422. package/lib/{dependencies → node}/ExternalModuleDependency.js +8 -7
  423. package/lib/{dependencies → node}/ExternalModuleInitFragment.js +7 -6
  424. package/lib/{dependencies → node}/ExternalModuleInitFragmentDependency.js +14 -9
  425. package/lib/node/NodeEnvironmentPlugin.js +11 -1
  426. package/lib/{NodeStuffPlugin.js → node/NodeStuffPlugin.js} +17 -17
  427. package/lib/node/NodeTargetPlugin.js +1 -1
  428. package/lib/node/NodeWatchFileSystem.js +58 -6
  429. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +7 -7
  430. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +13 -19
  431. package/lib/node/ReadFileCompileWasmPlugin.js +9 -11
  432. package/lib/node/RequireChunkLoadingRuntimeModule.js +7 -7
  433. package/lib/node/nodeConsole.js +6 -7
  434. package/lib/optimize/AggressiveMergingPlugin.js +2 -2
  435. package/lib/optimize/AggressiveSplittingPlugin.js +12 -8
  436. package/lib/{CircularModulesPlugin.js → optimize/CircularModulesPlugin.js} +14 -14
  437. package/lib/optimize/ConcatenatedModule.js +231 -220
  438. package/lib/{ConcatenationScope.js → optimize/ConcatenationScope.js} +39 -6
  439. package/lib/optimize/ConstExportsPlugin.js +7 -7
  440. package/lib/optimize/EnsureChunkConditionsPlugin.js +3 -3
  441. package/lib/{FlagAllModulesAsUsedPlugin.js → optimize/FlagAllModulesAsUsedPlugin.js} +3 -3
  442. package/lib/{FlagDependencyExportsPlugin.js → optimize/FlagDependencyExportsPlugin.js} +23 -28
  443. package/lib/{FlagDependencyUsagePlugin.js → optimize/FlagDependencyUsagePlugin.js} +44 -19
  444. package/lib/{FlagEntryExportAsUsedPlugin.js → optimize/FlagEntryExportAsUsedPlugin.js} +2 -2
  445. package/lib/optimize/FlagIncludedChunksPlugin.js +2 -2
  446. package/lib/optimize/InlineExports.js +12 -7
  447. package/lib/optimize/InnerGraph.js +5 -13
  448. package/lib/optimize/InnerGraphPlugin.js +10 -10
  449. package/lib/optimize/LazyBarrels.js +620 -0
  450. package/lib/{util → optimize}/LazyBucketSortedSet.js +2 -2
  451. package/lib/optimize/LimitChunkCountPlugin.js +16 -7
  452. package/lib/optimize/MangleExportsPlugin.js +5 -5
  453. package/lib/optimize/MergeDuplicateChunksPlugin.js +7 -6
  454. package/lib/optimize/MinChunkSizePlugin.js +9 -6
  455. package/lib/optimize/ModuleConcatenationPlugin.js +28 -22
  456. package/lib/{dependencies → optimize}/PureExpressionDependency.js +11 -10
  457. package/lib/optimize/RealContentHashPlugin.js +18 -13
  458. package/lib/optimize/RemoveEmptyChunksPlugin.js +2 -2
  459. package/lib/optimize/RemoveParentModulesPlugin.js +4 -4
  460. package/lib/optimize/SideEffectsFlagPlugin.js +24 -38
  461. package/lib/optimize/SplitChunksPlugin.js +719 -174
  462. package/lib/{util → optimize}/TupleQueue.js +9 -9
  463. package/lib/optimize/chunkSetIntersections.js +437 -0
  464. package/lib/{util → optimize}/deterministicGrouping.js +17 -17
  465. package/lib/{BannerPlugin.js → output/BannerPlugin.js} +82 -14
  466. package/lib/{CleanPlugin.js → output/CleanPlugin.js} +69 -25
  467. package/lib/{CopyPlugin.js → output/CopyPlugin.js} +144 -70
  468. package/lib/{ManifestPlugin.js → output/ManifestPlugin.js} +91 -17
  469. package/lib/output/SSRManifestPlugin.js +349 -0
  470. package/lib/performance/AnalyzableBailoutsPlugin.js +1 -1
  471. package/lib/performance/AsyncChunkWaterfallsPlugin.js +1 -1
  472. package/lib/performance/BroadContextsPlugin.js +4 -4
  473. package/lib/performance/CacheEffectivenessPlugin.js +2 -3
  474. package/lib/performance/ConflictingResourceHintsPlugin.js +1 -1
  475. package/lib/performance/DuplicateModulesPlugin.js +3 -4
  476. package/lib/performance/DuplicatePackagesPlugin.js +3 -3
  477. package/lib/performance/DynamicExportsPlugin.js +2 -2
  478. package/lib/performance/EvalUsagePlugin.js +4 -6
  479. package/lib/performance/HotspotsPlugin.js +39 -14
  480. package/lib/performance/LargeModulesPlugin.js +2 -3
  481. package/lib/performance/LegacyJavascriptPlugin.js +1 -2
  482. package/lib/performance/MissingSideEffectsPlugin.js +2 -3
  483. package/lib/performance/MissingSourceMapsPlugin.js +5 -6
  484. package/lib/performance/PureAnnotationsPlugin.js +19 -13
  485. package/lib/performance/RedundantDynamicImportsPlugin.js +6 -8
  486. package/lib/performance/ScopeHoistingBailoutsPlugin.js +2 -2
  487. package/lib/performance/SizeLimitsPlugin.js +11 -12
  488. package/lib/performance/TopLevelThisPlugin.js +22 -13
  489. package/lib/performance/UnsplitVendorsPlugin.js +1 -2
  490. package/lib/performance/UnusedAliasesPlugin.js +6 -7
  491. package/lib/performance/UnusedAssetsPlugin.js +5 -5
  492. package/lib/performance/UnusedDefinesPlugin.js +2 -2
  493. package/lib/performance/UnusedExternalsPlugin.js +3 -4
  494. package/lib/performance/UnusedFederationPlugin.js +2 -4
  495. package/lib/performance/UnusedModulesPlugin.js +5 -4
  496. package/lib/performance/getModuleSize.js +1 -1
  497. package/lib/performance/hasOnlyUnusedExports.js +4 -4
  498. package/lib/performance/isOnlyReexported.js +7 -6
  499. package/lib/{AutomaticPrefetchPlugin.js → prefetch/AutomaticPrefetchPlugin.js} +4 -5
  500. package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +2 -2
  501. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +1 -1
  502. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +4 -4
  503. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +4 -4
  504. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +4 -4
  505. package/lib/{dependencies → prefetch}/PrefetchDependency.js +1 -1
  506. package/lib/{PrefetchPlugin.js → prefetch/PrefetchPlugin.js} +2 -2
  507. package/lib/prefetch/ResourceHintPlugin.js +66 -45
  508. package/lib/prefetch/ResourceHintRuntimeModule.js +3 -3
  509. package/lib/prefetch/StartupAssetHintRuntimeModule.js +3 -3
  510. package/lib/prefetch/parseResourceHintOptions.js +4 -3
  511. package/lib/{ProvidePlugin.js → provide/ProvidePlugin.js} +7 -7
  512. package/lib/{dependencies → provide}/ProvidedDependency.js +50 -17
  513. package/lib/{IgnorePlugin.js → resolve/IgnorePlugin.js} +30 -13
  514. package/lib/{NormalModuleReplacementPlugin.js → resolve/NormalModuleReplacementPlugin.js} +4 -4
  515. package/lib/{ResolverFactory.js → resolve/ResolverFactory.js} +18 -5
  516. package/lib/resolve/getResolveOptionsKey.js +59 -0
  517. package/lib/rules/BasicEffectRulePlugin.js +1 -1
  518. package/lib/rules/RuleSetCompiler.js +42 -51
  519. package/lib/rules/UseEffectRulePlugin.js +1 -3
  520. package/lib/runtime/AsyncModuleGeneratorRuntimeModule.js +2 -2
  521. package/lib/runtime/AsyncModuleRuntimeModule.js +14 -5
  522. package/lib/runtime/AutoPublicPathRuntimeModule.js +5 -5
  523. package/lib/runtime/BaseUriRuntimeModule.js +3 -3
  524. package/lib/runtime/ChunkNameRuntimeModule.js +2 -2
  525. package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +2 -2
  526. package/lib/runtime/CompatRuntimeModule.js +4 -4
  527. package/lib/runtime/ConcatenationWrapRuntimeModule.js +2 -2
  528. package/lib/runtime/ConstructRequireRuntimeModule.js +2 -2
  529. package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +2 -2
  530. package/lib/runtime/CreateScriptRuntimeModule.js +2 -2
  531. package/lib/runtime/CreateScriptUrlRuntimeModule.js +2 -2
  532. package/lib/runtime/DefinePropertyGettersRuntimeModule.js +6 -6
  533. package/lib/runtime/EnsureChunkRuntimeModule.js +4 -4
  534. package/lib/runtime/GetChunkFilenameRuntimeModule.js +7 -11
  535. package/lib/runtime/GetFullHashRuntimeModule.js +2 -2
  536. package/lib/runtime/GetMainFilenameRuntimeModule.js +4 -4
  537. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +3 -3
  538. package/lib/runtime/GetWorkletBootstrapRuntimeModule.js +3 -3
  539. package/lib/runtime/GlobalRuntimeModule.js +3 -3
  540. package/lib/runtime/HasOwnPropertyRuntimeModule.js +3 -3
  541. package/lib/runtime/HelperRuntimeModule.js +16 -1
  542. package/lib/runtime/LoadScriptRuntimeModule.js +3 -3
  543. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +80 -17
  544. package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +2 -2
  545. package/lib/runtime/NonceRuntimeModule.js +2 -2
  546. package/lib/runtime/OnChunksLoadedRuntimeModule.js +4 -4
  547. package/lib/runtime/PublicPathRuntimeModule.js +2 -2
  548. package/lib/runtime/RelativeUrlRuntimeModule.js +2 -2
  549. package/lib/{RuntimeGlobals.js → runtime/RuntimeGlobals.js} +24 -1
  550. package/lib/runtime/RuntimeIdRuntimeModule.js +4 -4
  551. package/lib/{RuntimeModule.js → runtime/RuntimeModule.js} +36 -21
  552. package/lib/{RuntimePlugin.js → runtime/RuntimePlugin.js} +50 -50
  553. package/lib/runtime/SetAnonymousDefaultNameRuntimeModule.js +2 -2
  554. package/lib/runtime/SpecNamespaceObjectRuntimeModule.js +2 -2
  555. package/lib/runtime/StartupChunkDependenciesPlugin.js +2 -2
  556. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +5 -5
  557. package/lib/runtime/StartupEntrypointRuntimeModule.js +3 -3
  558. package/lib/runtime/SystemContextRuntimeModule.js +2 -2
  559. package/lib/runtime/ToBinaryRuntimeModule.js +3 -3
  560. package/lib/runtime/WorkerRuntimeModule.js +1 -1
  561. package/lib/runtime/baseUri.js +1 -1
  562. package/lib/schemes/DataUriPlugin.js +1 -1
  563. package/lib/schemes/HttpUriPlugin.js +68 -13
  564. package/lib/schemes/VirtualUrlPlugin.js +52 -16
  565. package/lib/serialization/AggregateErrorSerializer.js +4 -4
  566. package/lib/serialization/BinaryMiddleware.js +4 -1
  567. package/lib/serialization/ErrorObjectSerializer.js +2 -5
  568. package/lib/serialization/FileMiddleware.js +3 -3
  569. package/lib/serialization/ObjectMiddleware.js +62 -29
  570. package/lib/serialization/PlainObjectSerializer.js +3 -7
  571. package/lib/serialization/Serializer.js +21 -11
  572. package/lib/serialization/SerializerMiddleware.js +10 -8
  573. package/lib/serialization/SingleItemMiddleware.js +4 -2
  574. package/lib/sharing/ConsumeSharedFallbackDependency.js +9 -1
  575. package/lib/sharing/ConsumeSharedModule.js +18 -14
  576. package/lib/sharing/ConsumeSharedPlugin.js +148 -42
  577. package/lib/sharing/ConsumeSharedRuntimeModule.js +8 -8
  578. package/lib/sharing/ProvideForSharedDependency.js +9 -1
  579. package/lib/sharing/ProvideSharedDependency.js +1 -1
  580. package/lib/sharing/ProvideSharedModule.js +11 -9
  581. package/lib/sharing/ProvideSharedModuleFactory.js +2 -2
  582. package/lib/sharing/ProvideSharedPlugin.js +111 -20
  583. package/lib/sharing/SharePlugin.js +102 -9
  584. package/lib/sharing/ShareRuntimeModule.js +6 -6
  585. package/lib/sharing/resolveMatchedConfigs.js +1 -1
  586. package/lib/{util → sharing}/semver.js +14 -16
  587. package/lib/sharing/utils.js +59 -2
  588. package/lib/stats/DefaultStatsFactoryPlugin.js +57 -54
  589. package/lib/stats/DefaultStatsPresetPlugin.js +3 -7
  590. package/lib/stats/DefaultStatsPrinterPlugin.js +15 -14
  591. package/lib/{MultiStats.js → stats/MultiStats.js} +4 -4
  592. package/lib/{Stats.js → stats/Stats.js} +4 -4
  593. package/lib/stats/StatsFactory.js +208 -37
  594. package/lib/stats/StatsPrinter.js +126 -13
  595. package/lib/{ChunkTemplate.js → template/ChunkTemplate.js} +7 -7
  596. package/lib/{ConditionalInitFragment.js → template/ConditionalInitFragment.js} +3 -3
  597. package/lib/template/DependencyTemplate.js +77 -0
  598. package/lib/{DependencyTemplates.js → template/DependencyTemplates.js} +9 -4
  599. package/lib/template/InitFragment.js +223 -0
  600. package/lib/{MainTemplate.js → template/MainTemplate.js} +11 -11
  601. package/lib/{ModuleInfoHeaderPlugin.js → template/ModuleInfoHeaderPlugin.js} +30 -8
  602. package/lib/{ModuleTemplate.js → template/ModuleTemplate.js} +6 -6
  603. package/lib/{RuntimeTemplate.js → template/RuntimeTemplate.js} +158 -95
  604. package/lib/{Template.js → template/Template.js} +14 -12
  605. package/lib/{TemplatedPathPlugin.js → template/TemplatedPathPlugin.js} +19 -23
  606. package/lib/typescript/TypeScriptPlugin.js +3 -3
  607. package/lib/util/RequestShortener.js +44 -0
  608. package/lib/util/SortableSet.js +87 -22
  609. package/lib/util/SourceProcessor.js +439 -51
  610. package/lib/util/TupleSet.js +27 -27
  611. package/lib/util/WeakTupleMap.js +20 -16
  612. package/lib/util/buildDiagnostics.js +2 -2
  613. package/lib/util/cleverMerge.js +61 -33
  614. package/lib/util/comparators.js +19 -15
  615. package/lib/util/concatenate.js +28 -147
  616. package/lib/util/createMappings.js +111 -0
  617. package/lib/util/dataURL.js +96 -15
  618. package/lib/util/deprecation.js +5 -4
  619. package/lib/util/extractComments.js +118 -0
  620. package/lib/util/formatLocation.js +1 -1
  621. package/lib/util/globUtils.js +198 -20
  622. package/lib/util/haltVisitors.js +51 -0
  623. package/lib/util/handlerKeys.js +2 -2
  624. package/lib/util/identifier.js +117 -1
  625. package/lib/util/implicitTypeLoaderFallback.js +6 -4
  626. package/lib/util/internalSerializables.js +296 -102
  627. package/lib/util/magicComment.js +12 -7
  628. package/lib/util/makeSerializable.js +28 -7
  629. package/lib/util/memoize.js +1 -1
  630. package/lib/util/parseJson.js +2 -2
  631. package/lib/util/preloadModuleType.js +5 -2
  632. package/lib/util/registerExternalSerializer.js +2 -2
  633. package/lib/util/removeBOM.js +1 -1
  634. package/lib/util/runtime.js +1 -1
  635. package/lib/util/serialization.js +35 -28
  636. package/lib/util/source.js +2 -2
  637. package/lib/util/terminalColors.js +161 -0
  638. package/lib/{wasm-async → wasm}/AsyncWasmCompileRuntimeModule.js +5 -5
  639. package/lib/{wasm-async → wasm}/AsyncWasmLoadingRuntimeModule.js +5 -5
  640. package/lib/{wasm-async → wasm}/AsyncWasmModule.js +19 -5
  641. package/lib/{wasm-async → wasm}/AsyncWebAssemblyGenerator.js +17 -9
  642. package/lib/{wasm-async → wasm}/AsyncWebAssemblyJavascriptGenerator.js +24 -15
  643. package/lib/{wasm-async → wasm}/AsyncWebAssemblyModulesPlugin.js +26 -10
  644. package/lib/{wasm-async → wasm}/AsyncWebAssemblyParser.js +14 -12
  645. package/lib/wasm/EnableWasmLoadingPlugin.js +1 -1
  646. package/lib/{wasm-async → wasm}/UniversalCompileAsyncWasmPlugin.js +11 -13
  647. package/lib/wasm/wasmModuleFilename.js +2 -2
  648. package/lib/wasm-sync/SyncWasmModule.js +18 -3
  649. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +8 -8
  650. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +3 -3
  651. package/lib/wasm-sync/WebAssemblyGenerator.js +22 -16
  652. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +28 -21
  653. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +9 -7
  654. package/lib/wasm-sync/WebAssemblyParser.js +15 -17
  655. package/lib/wasm-sync/WebAssemblyUtils.js +6 -5
  656. package/lib/{MultiWatching.js → watch/MultiWatching.js} +3 -3
  657. package/lib/{WatchIgnorePlugin.js → watch/WatchIgnorePlugin.js} +43 -9
  658. package/lib/{Watching.js → watch/Watching.js} +8 -8
  659. package/lib/web/FetchCompileAsyncWasmPlugin.js +12 -18
  660. package/lib/web/FetchCompileWasmPlugin.js +8 -10
  661. package/lib/web/JsonpChunkLoadingPlugin.js +3 -3
  662. package/lib/web/JsonpChunkLoadingRuntimeModule.js +6 -6
  663. package/lib/web/JsonpTemplatePlugin.js +1 -1
  664. package/lib/webpack.js +27 -17
  665. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +3 -3
  666. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +6 -6
  667. package/package.json +57 -36
  668. package/schemas/WebpackOptions.check.js +4 -3
  669. package/schemas/WebpackOptions.d.json.ts +2 -0
  670. package/schemas/WebpackOptions.json +295 -75
  671. package/schemas/plugins/BannerPlugin.check.js +4 -3
  672. package/schemas/plugins/BannerPlugin.json +29 -2
  673. package/schemas/plugins/HtmlGeneratorOptions.check.js +4 -3
  674. package/schemas/plugins/HtmlParserOptions.check.js +4 -3
  675. package/schemas/plugins/IgnorePlugin.check.js +4 -3
  676. package/schemas/plugins/IgnorePlugin.d.json.ts +2 -0
  677. package/schemas/plugins/IgnorePlugin.json +1 -1
  678. package/schemas/plugins/LoaderOptionsPlugin.check.js +4 -3
  679. package/schemas/plugins/ManifestPlugin.check.js +4 -3
  680. package/schemas/plugins/ManifestPlugin.json +3 -3
  681. package/schemas/plugins/ProgressPlugin.check.js +4 -3
  682. package/schemas/plugins/ProgressPlugin.json +2 -7
  683. package/schemas/plugins/SSRManifestPlugin.check.js +7 -0
  684. package/schemas/plugins/SSRManifestPlugin.json +20 -0
  685. package/schemas/plugins/SourceMapDevToolPlugin.check.js +4 -3
  686. package/schemas/plugins/SourceMapDevToolPlugin.json +44 -12
  687. package/schemas/plugins/WatchIgnorePlugin.check.js +4 -3
  688. package/schemas/plugins/WatchIgnorePlugin.json +12 -3
  689. package/schemas/plugins/asset/AssetGeneratorOptions.check.js +4 -3
  690. package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.js +4 -3
  691. package/schemas/plugins/asset/AssetParserOptions.check.js +4 -3
  692. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +4 -3
  693. package/schemas/plugins/container/ContainerPlugin.check.js +4 -3
  694. package/schemas/plugins/container/ContainerPlugin.json +8 -0
  695. package/schemas/plugins/container/ContainerReferencePlugin.check.js +4 -3
  696. package/schemas/plugins/container/ExternalsType.check.js +4 -3
  697. package/schemas/plugins/container/ModuleFederationPlugin.check.js +4 -3
  698. package/schemas/plugins/container/ModuleFederationPlugin.json +40 -0
  699. package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.js +4 -3
  700. package/schemas/plugins/css/CssGeneratorOptions.check.js +4 -3
  701. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +4 -3
  702. package/schemas/plugins/css/CssModuleParserOptions.check.js +4 -3
  703. package/schemas/plugins/css/CssParserOptions.check.js +4 -3
  704. package/schemas/plugins/debug/ProfilingPlugin.check.js +4 -3
  705. package/schemas/plugins/define/DotenvPluginOptions.check.js +7 -0
  706. package/schemas/plugins/define/DotenvPluginOptions.json +3 -0
  707. package/schemas/plugins/dll/DllPlugin.check.js +4 -3
  708. package/schemas/plugins/dll/DllReferencePlugin.check.js +4 -3
  709. package/schemas/plugins/dll/DllReferencePlugin.json +3 -18
  710. package/schemas/plugins/ids/HashedModuleIdsPlugin.check.js +4 -3
  711. package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.check.js +4 -3
  712. package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.check.js +4 -3
  713. package/schemas/plugins/json/JsonModulesPluginGenerator.check.js +4 -3
  714. package/schemas/plugins/json/JsonModulesPluginParser.check.js +4 -3
  715. package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +4 -3
  716. package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +4 -3
  717. package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.js +4 -3
  718. package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +4 -3
  719. package/schemas/plugins/output/CleanOptions.check.js +7 -0
  720. package/schemas/plugins/output/CleanOptions.json +3 -0
  721. package/schemas/plugins/schemes/HttpUriPlugin.check.js +4 -3
  722. package/schemas/plugins/schemes/VirtualUrlPlugin.check.js +4 -3
  723. package/schemas/plugins/sharing/ConsumeSharedPlugin.check.js +4 -3
  724. package/schemas/plugins/sharing/ConsumeSharedPlugin.json +32 -0
  725. package/schemas/plugins/sharing/ProvideSharedPlugin.check.js +4 -3
  726. package/schemas/plugins/sharing/ProvideSharedPlugin.json +32 -0
  727. package/schemas/plugins/sharing/SharePlugin.check.js +4 -3
  728. package/schemas/plugins/sharing/SharePlugin.json +32 -0
  729. package/types.d.ts +20780 -14174
  730. package/lib/LazyBarrel.js +0 -388
  731. package/lib/dependencies/HarmonyAcceptImportDependency.js +0 -39
  732. package/lib/dependencies/HarmonyModulesPlugin.js +0 -192
  733. package/lib/javascript/ChunkFormatHelpers.js +0 -72
  734. package/lib/javascript/grammar.js +0 -5546
  735. package/lib/javascript/parser.js +0 -1500
  736. package/lib/javascript/regexpData.js +0 -51
  737. package/lib/performance/getSourceModules.js +0 -22
  738. package/lib/util/Semaphore.js +0 -65
  739. package/lib/util/objectToMap.js +0 -15
  740. package/schemas/WebpackOptions.check.d.ts +0 -7
  741. package/schemas/_container.json +0 -155
  742. package/schemas/_sharing.json +0 -118
  743. package/schemas/plugins/BannerPlugin.check.d.ts +0 -7
  744. package/schemas/plugins/HtmlGeneratorOptions.check.d.ts +0 -7
  745. package/schemas/plugins/HtmlParserOptions.check.d.ts +0 -7
  746. package/schemas/plugins/IgnorePlugin.check.d.ts +0 -7
  747. package/schemas/plugins/LoaderOptionsPlugin.check.d.ts +0 -7
  748. package/schemas/plugins/ManifestPlugin.check.d.ts +0 -7
  749. package/schemas/plugins/ProgressPlugin.check.d.ts +0 -7
  750. package/schemas/plugins/SourceMapDevToolPlugin.check.d.ts +0 -7
  751. package/schemas/plugins/WatchIgnorePlugin.check.d.ts +0 -7
  752. package/schemas/plugins/asset/AssetGeneratorOptions.check.d.ts +0 -7
  753. package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.d.ts +0 -7
  754. package/schemas/plugins/asset/AssetParserOptions.check.d.ts +0 -7
  755. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.d.ts +0 -7
  756. package/schemas/plugins/container/ContainerPlugin.check.d.ts +0 -7
  757. package/schemas/plugins/container/ContainerReferencePlugin.check.d.ts +0 -7
  758. package/schemas/plugins/container/ExternalsType.check.d.ts +0 -7
  759. package/schemas/plugins/container/ModuleFederationPlugin.check.d.ts +0 -7
  760. package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.d.ts +0 -7
  761. package/schemas/plugins/css/CssGeneratorOptions.check.d.ts +0 -7
  762. package/schemas/plugins/css/CssModuleGeneratorOptions.check.d.ts +0 -7
  763. package/schemas/plugins/css/CssModuleParserOptions.check.d.ts +0 -7
  764. package/schemas/plugins/css/CssParserOptions.check.d.ts +0 -7
  765. package/schemas/plugins/debug/ProfilingPlugin.check.d.ts +0 -7
  766. package/schemas/plugins/dll/DllPlugin.check.d.ts +0 -7
  767. package/schemas/plugins/dll/DllReferencePlugin.check.d.ts +0 -7
  768. package/schemas/plugins/ids/HashedModuleIdsPlugin.check.d.ts +0 -7
  769. package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.check.d.ts +0 -7
  770. package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.check.d.ts +0 -7
  771. package/schemas/plugins/json/JsonModulesPluginGenerator.check.d.ts +0 -7
  772. package/schemas/plugins/json/JsonModulesPluginParser.check.d.ts +0 -7
  773. package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.d.ts +0 -7
  774. package/schemas/plugins/optimize/LimitChunkCountPlugin.check.d.ts +0 -7
  775. package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.d.ts +0 -7
  776. package/schemas/plugins/optimize/MinChunkSizePlugin.check.d.ts +0 -7
  777. package/schemas/plugins/schemes/HttpUriPlugin.check.d.ts +0 -7
  778. package/schemas/plugins/schemes/VirtualUrlPlugin.check.d.ts +0 -7
  779. package/schemas/plugins/sharing/ConsumeSharedPlugin.check.d.ts +0 -7
  780. package/schemas/plugins/sharing/ProvideSharedPlugin.check.d.ts +0 -7
  781. package/schemas/plugins/sharing/SharePlugin.check.d.ts +0 -7
  782. /package/lib/{validateSchema.js → config/validateSchema.js} +0 -0
  783. /package/lib/{util → css}/topologicalSort.js +0 -0
  784. /package/lib/dependencies/{getFunctionExpression.js → helpers/getFunctionExpression.js} +0 -0
  785. /package/lib/{util → externals}/extractUrlAndGlobal.js +0 -0
  786. /package/lib/{util → fs}/StackedCacheMap.js +0 -0
  787. /package/lib/{util → javascript}/StackedMap.js +0 -0
  788. /package/lib/{ModuleProfile.js → module/ModuleProfile.js} +0 -0
  789. /package/lib/{ModuleSourceTypeConstants.js → module/ModuleSourceTypeConstants.js} +0 -0
  790. /package/lib/{ModuleTypeConstants.js → module/ModuleTypeConstants.js} +0 -0
  791. /package/lib/{OptimizationStages.js → optimize/OptimizationStages.js} +0 -0
  792. /package/lib/{util → optimize}/Queue.js +0 -0
  793. /package/lib/{util → stats}/smartGrouping.js +0 -0
@@ -38,6 +38,8 @@ const chooseDeferredInfix = (input) => {
38
38
  };
39
39
 
40
40
  const DEFERRED_ID_RE = /^\d+$/;
41
+ // A character a stylesheet's bytes cannot spell without naming an encoding.
42
+ const NON_ASCII_RE = /[^\0-\u007F]/;
41
43
 
42
44
  /**
43
45
  * Read the deferred write standing at `start`, if one does.
@@ -117,10 +119,10 @@ const declineDeferredWrites = (text, writes) =>
117
119
  );
118
120
 
119
121
  /**
120
- * Babel-style visitor map keyed by a numeric node-type discriminator; a bucket
122
+ * Visitor map keyed by a numeric node-type discriminator; a bucket
121
123
  * is a function (enter-only) or `{ enter?, exit? }`.
122
124
  *
123
- * A visitor receives a single `path` argument (the Babel `path` shape): the
125
+ * A visitor receives a single `path` argument: the
124
126
  * language's AST accessor with the current position on it — `path.node`,
125
127
  * `path.parent` (null at a root) — plus `path.skipChildren()` (enter only)
126
128
  * to stop the walk descending, and every field-read method (which defaults
@@ -130,6 +132,122 @@ const declineDeferredWrites = (text, writes) =>
130
132
  * @template TPath
131
133
  * @typedef {(path: TPath) => void} VisitorFn
132
134
  */
135
+ /**
136
+ * The members every language's `path` has under the same name and meaning, so
137
+ * a visitor written against it reads any grammar; see `docs/syntax.md`.
138
+ * @template TNode
139
+ * @template [TValue=unknown]
140
+ * @typedef {NodePathReads<TNode, TValue> & NodePathFields<TNode>} NodePath
141
+ */
142
+ /**
143
+ * @template TNode
144
+ * @template [TValue=unknown]
145
+ * @typedef {object} NodePathReads
146
+ * @property {TNode} node the current node
147
+ * @property {TNode | null} parent the enclosing node (null at a root)
148
+ * @property {number} index the current node's index among its siblings
149
+ * @property {() => void} skipChildren stop the walk descending into the current node (enter only)
150
+ * @property {() => void} stop end the walk: no visitor fires after the current one returns, and a print still completes
151
+ * @property {unknown} state the run's state, as `process` was given it
152
+ * @property {(n?: TNode) => number} type the node's `NodeType`
153
+ * @property {(n?: TNode) => [number, number]} range start and end offsets in the input
154
+ * @property {(n?: TNode) => number} start where the node starts in the input
155
+ * @property {(n?: TNode) => number} end where the node ends in the input
156
+ * @property {(n?: TNode) => [number, number, number, number]} loc start line and column, end line and column (lines from 1, columns from 0)
157
+ * @property {(n?: TNode | number, end?: number) => string} source the node's source text, or the input between two offsets
158
+ * @property {(n?: TNode) => string} name the node's name as the language defines it, decoded ("" when it has none)
159
+ * @property {(n?: TNode) => TValue} value the node's value as the language defines it, decoded
160
+ * @property {(n?: TNode) => number} childCount number of children
161
+ * @property {(i: number, n?: TNode) => TNode} child the i-th child
162
+ * @property {(n?: TNode) => TNode[]} children every child as a new array
163
+ */
164
+ /**
165
+ * Structure read through a language's `Field`, `Flag` and `Part`. Declared as
166
+ * methods so a language's path may accept only the parts each node type has.
167
+ * @template TNode
168
+ * @typedef {{
169
+ * field(i: number, field: number, n?: TNode): TNode,
170
+ * fieldCount(field: number, n?: TNode): number,
171
+ * fieldNamed(field: number, name: string, n?: TNode): TNode,
172
+ * flag(flag: number, n?: TNode): boolean,
173
+ * rangeOf(part: number, n?: TNode): [number, number] | null,
174
+ * startOf(part: number, n?: TNode): number,
175
+ * endOf(part: number, n?: TNode): number,
176
+ * textOf(part: number, n?: TNode): string | null,
177
+ * within(type: number): boolean,
178
+ * }} NodePathFields
179
+ */
180
+ /**
181
+ * A node that also says which `NodeType` it is, so reading a part that type
182
+ * lacks fails to type-check; a plain `TNode` can be any node.
183
+ * @template TNode
184
+ * @template T
185
+ * @typedef {TNode & { readonly __nodeType: T }} TypedNode
186
+ */
187
+ /**
188
+ * What part `M` gives the node type `R` says it is; every part `D` when `R`
189
+ * says none (a plain node reads `number` there).
190
+ * @template R
191
+ * @template {Record<number, number>} M
192
+ * @template D
193
+ * @typedef {number extends (R & { readonly __nodeType: number })["__nodeType"] ? D : M[(R & { readonly __nodeType: number })["__nodeType"]]} PartOf
194
+ */
195
+ /**
196
+ * A language's parts, by node type: what its `Field`s and `Flag`s apply to.
197
+ * @typedef {object} NodeParts
198
+ * @property {number} types every `NodeType` member
199
+ * @property {number} field every `Field`
200
+ * @property {number} flag every `Flag`
201
+ * @property {number} part every `Part` with a position
202
+ * @property {number} text every `Part` with text beyond the name and value
203
+ * @property {Record<number, number>} fields the `Field`s of each node type
204
+ * @property {Record<number, number>} flags the `Flag`s of each node type
205
+ * @property {Record<number, number>} parts the `Part`s with a position, by node type
206
+ * @property {Record<number, number>} texts the `Part`s with text, by node type
207
+ * @property {Record<number, number>} items the node type of each `Field`'s items
208
+ */
209
+ /**
210
+ * The path a visitor of node type `T` receives: its structure reads take only
211
+ * the parts that type has, and its `state` is the run's.
212
+ * @template TPath
213
+ * @template TNode
214
+ * @template {NodeParts} P
215
+ * @template T
216
+ * @template [S=unknown]
217
+ * @typedef {Omit<TPath, "node" | "state" | "within" | "field" | "fieldCount" | "fieldNamed" | "flag" | "rangeOf" | "startOf" | "endOf" | "textOf"> & {
218
+ * readonly node: TypedNode<TNode, T>,
219
+ * readonly state: S,
220
+ * within(type: P["types"]): boolean,
221
+ * field<R extends TNode = TypedNode<TNode, T>, F extends number = number>(i: number, field: F & PartOf<R, P["fields"], P["field"]>, n?: R): TypedNode<TNode, P["items"][F]>,
222
+ * fieldCount<R extends TNode = TypedNode<TNode, T>>(field: PartOf<R, P["fields"], P["field"]>, n?: R): number,
223
+ * fieldNamed<R extends TNode = TypedNode<TNode, T>, F extends number = number>(field: F & PartOf<R, P["fields"], P["field"]>, name: string, n?: R): TypedNode<TNode, P["items"][F]>,
224
+ * flag<R extends TNode = TypedNode<TNode, T>>(flag: PartOf<R, P["flags"], P["flag"]>, n?: R): boolean,
225
+ * rangeOf<R extends TNode = TypedNode<TNode, T>>(part: PartOf<R, P["parts"], P["part"]>, n?: R): [number, number] | null,
226
+ * startOf<R extends TNode = TypedNode<TNode, T>>(part: PartOf<R, P["parts"], P["part"]>, n?: R): number,
227
+ * endOf<R extends TNode = TypedNode<TNode, T>>(part: PartOf<R, P["parts"], P["part"]>, n?: R): number,
228
+ * textOf<R extends TNode = TypedNode<TNode, T>>(part: PartOf<R, P["texts"], P["text"]>, n?: R): string | null
229
+ * }} TypedNodePath
230
+ */
231
+ /**
232
+ * The parts of a language that names none: every node type has every part.
233
+ * @typedef {{
234
+ * types: number,
235
+ * field: number,
236
+ * flag: number,
237
+ * part: number,
238
+ * text: number,
239
+ * fields: Record<number, number>,
240
+ * flags: Record<number, number>,
241
+ * parts: Record<number, number>,
242
+ * texts: Record<number, number>,
243
+ * items: Record<number, number>,
244
+ * }} AnyParts
245
+ */
246
+ /**
247
+ * @template S
248
+ * @typedef {{ state?: S }} RunState what a run hands its visitors as `path.state`
249
+ */
250
+
133
251
  /**
134
252
  * @template TPath
135
253
  * @typedef {VisitorFn<TPath> | { enter?: VisitorFn<TPath>, exit?: VisitorFn<TPath> }} VisitorBucket
@@ -154,15 +272,35 @@ const declineDeferredWrites = (text, writes) =>
154
272
  * typedef HTML also depends on.
155
273
  * @typedef {{ mode: "minify" | "beautify" }} PrintOptions
156
274
  */
275
+ /**
276
+ * What names one offer whatever print made it: every field but the functions,
277
+ * so the second print of `processAsync` finds the first one's answer by it.
278
+ * @param {Omit<DeferredWrite, "build">} offer an offer, `build` and all or without it
279
+ * @returns {string} its key
280
+ */
281
+ const deferredKey = (offer) => {
282
+ let key = "";
283
+ for (const name of Object.keys(offer).sort()) {
284
+ const value =
285
+ /** @type {Record<string, DeferredWrite[keyof DeferredWrite]>} */ (offer)[
286
+ name
287
+ ];
288
+ if (typeof value !== "function") key += `${name}\0${value}\0`;
289
+ }
290
+ return key;
291
+ };
292
+
157
293
  /**
158
294
  * One write the print left a marker for, collected into the `deferEmbeddedSource`
159
295
  * print option by whichever grammar offered it — the other half of
160
- * {@link deferredWrite}. `source` is the text offered and `build` spells what is
161
- * printed around the answer, an untapped run's spelling where there is none. A
162
- * grammar carries whatever else describes the offer (`type`, `hostType`, `as`,
296
+ * {@link deferredWrite}. `source` is the text offered, `build` spells what is
297
+ * printed around the answer (an untapped run's spelling where there is none), and
298
+ * `decides` says whether the answer overturns a choice the print made without it.
299
+ * A grammar carries whatever else describes the offer (`type`, `hostType`, `as`,
163
300
  * …) on the same object.
164
- * @typedef {{ source: string, build: (answer: string | undefined) => string }} DeferredWrite
301
+ * @typedef {{ source: string, build: (answer: string | undefined) => string, decides?: (answer: string | undefined) => boolean }} DeferredWrite
165
302
  */
303
+ /** @import { DeferredEmbeddedSource } from "./dataURL" */
166
304
  /**
167
305
  * A version-3 source map. Written structurally (with the `3` literal) so it
168
306
  * satisfies both `webpack-sources` and the minimizer plugin's map types without
@@ -195,6 +333,11 @@ const _makeMap = (options, mappings) => ({
195
333
  // small enough that the un-flattened fragments behind it stay bounded.
196
334
  const FLATTEN_BLOCK = 64 * 1024;
197
335
 
336
+ // Most prints do not ask for a source map. Sharing their permanently empty
337
+ // mapping column avoids allocating an array for every inline CSS/HTML body.
338
+ /** @type {[number, number, number, number][]} */
339
+ const EMPTY_MAPPINGS = [];
340
+
198
341
  // Base64 VLQ, the source-map `mappings` encoding. Hand-rolled so producing a map
199
342
  // pulls in no dependency (`source-map` is not a webpack dep).
200
343
  const _B64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
@@ -262,10 +405,13 @@ class PrintContext {
262
405
  this._printer = printer;
263
406
  // Printed text by node handle, in two columns rather than one `Map`: the
264
407
  // handles are dense integers, and `_moveEpoch` keeps the live set small.
265
- /** @type {string[]} each finished node's printed text */
408
+ /** @type {(string | null)[]} each finished node's printed text */
266
409
  this._storeText = [];
267
410
  /** @type {Int32Array} the epoch each slot was written in */
268
411
  this._storeGen = new Int32Array(0);
412
+ // A slot holding `null` prints as its source, read only once asked for.
413
+ /** @type {((node: TNode) => string) | undefined} reads a `null` slot's text */
414
+ this._sourceText = undefined;
269
415
  /** @type {number} current epoch; a slot from an older one reads as absent */
270
416
  this._gen = 1;
271
417
  /** @type {number} lowest slot written since the epoch last moved */
@@ -277,21 +423,23 @@ class PrintContext {
277
423
  // for retractable text alone, so no other emit pays for that ability.
278
424
  /** @type {string[]} pieces already cut off, in output order */
279
425
  this._chunks = [];
426
+ /** @type {Map<number, { readonly text: string }> | null} pieces whose text is read only once the output is */
427
+ this._deferred = null;
280
428
  /** @type {string} output after the last cut piece */
281
429
  this._tail = "";
282
430
  /** @type {number} characters in `_tail`, so its length is not read off a rope */
283
431
  this._tailLength = 0;
284
432
  /** @type {number} scratch for the flattening read in {@link _cutTail} */
285
433
  this._flattened = 0;
286
- /** @type {[number, number, number, number][]} `[chunkIndex, offsetInChunk, srcLine, srcCol]`, output-ordered; a `srcLine` of -1 is one {@link retract} took back with its piece */
287
- this._mappings = [];
288
- /** @type {number[] | null} by retractable piece index, the mapping anchored to it, so taking the piece back takes its mapping too */
289
- this._retractableMappings = null;
290
434
  // A map is built only for a caller that named the input, and that is known
291
435
  // before printing — so a print nobody asks a map of collects none.
292
436
  /** @type {boolean} whether {@link sourceMap} can still be asked for one */
293
437
  this.mapWanted =
294
438
  /** @type {{ source?: string }} */ (options).source !== undefined;
439
+ /** @type {[number, number, number, number][]} `[chunkIndex, offsetInChunk, srcLine, srcCol]`, output-ordered; a `srcLine` of -1 is one {@link retract} took back with its piece */
440
+ this._mappings = this.mapWanted ? [] : EMPTY_MAPPINGS;
441
+ /** @type {number[] | null} by retractable piece index, the mapping anchored to it, so taking the piece back takes its mapping too */
442
+ this._retractableMappings = null;
295
443
  /** @type {[number, string][]} source-anchored literals to keep (comments), source-ordered */
296
444
  this._inserts = [];
297
445
  /** @type {number} next `_inserts` entry not yet flushed */
@@ -453,6 +601,7 @@ class PrintContext {
453
601
  * @param {number} charCode the character to drop
454
602
  */
455
603
  dropTrailing(from, charCode) {
604
+ this._settleDeferred();
456
605
  const chunks = this._chunks;
457
606
  for (let i = chunks.length; i >= from; i--) {
458
607
  let text = i === chunks.length ? this._tail : chunks[i];
@@ -473,6 +622,43 @@ class PrintContext {
473
622
  }
474
623
  }
475
624
 
625
+ /**
626
+ * Stand `text` in place of the output's end, where that is `printed` followed
627
+ * only by `closer`s — what the printer wrote after a value the input ran out in.
628
+ * @param {string} printed the text the output must end with, before the closers
629
+ * @param {string} text what to write in place of it and them
630
+ * @param {number} closer the character that may follow `printed`
631
+ * @returns {boolean} true when the output ended that way and was rewritten
632
+ */
633
+ replaceEnd(printed, text, closer) {
634
+ this._settleDeferred();
635
+ this._cutTail();
636
+ const chunks = this._chunks;
637
+ // Joined once: this runs only where a value ran into the end of the input.
638
+ const output = chunks.join("");
639
+ let end = output.length;
640
+ while (end > 0 && output.charCodeAt(end - 1) === closer) end--;
641
+ // The closers the printed text wrote itself are its own, not the blocks'.
642
+ let own = printed.length;
643
+ while (own > 0 && printed.charCodeAt(own - 1) === closer) own--;
644
+ end += printed.length - own;
645
+ if (end > output.length || !output.slice(0, end).endsWith(printed)) {
646
+ return false;
647
+ }
648
+ let remove = output.length - end + printed.length;
649
+ for (let i = chunks.length - 1; remove > 0; i--) {
650
+ const kept = Math.max(0, chunks[i].length - remove);
651
+ remove -= chunks[i].length - kept;
652
+ chunks[i] = chunks[i].slice(0, kept);
653
+ // A mapping into what went would point past its piece.
654
+ this._mappings = this._mappings.filter(
655
+ ([chunk, offset]) => chunk !== i || offset <= kept
656
+ );
657
+ }
658
+ this._emit(text);
659
+ return true;
660
+ }
661
+
476
662
  /**
477
663
  * Run the node printer for `node` and store what it returns (the grammar calls
478
664
  * this once the node's visitors and children are done). `path` is on `node`.
@@ -480,8 +666,17 @@ class PrintContext {
480
666
  * @param {TPath} path the language accessor, positioned on `node`
481
667
  */
482
668
  printNode(node, path) {
483
- const text = this._printer(path, this);
484
- const n = /** @type {EXPECTED_ANY} */ (node);
669
+ this.printedAs(node, this._printer(path, this));
670
+ }
671
+
672
+ /**
673
+ * Store `text` as what `node` printed, where the grammar already knows what
674
+ * the node printer would return and so does not call it.
675
+ * @param {TNode} node the finished node
676
+ * @param {string} text its printed text
677
+ */
678
+ printedAs(node, text) {
679
+ const n = /** @type {number} */ (node);
485
680
  if (n >= this._storeText.length) this._growStore(n + 1);
486
681
  this._storeText[n] = text;
487
682
  this._storeGen[n] = this._gen;
@@ -489,6 +684,22 @@ class PrintContext {
489
684
  if (n > this._storeHigh) this._storeHigh = n;
490
685
  }
491
686
 
687
+ /**
688
+ * Store that `node` printed as its source, which `sourceText` reads only once
689
+ * something asks for its text.
690
+ * @param {TNode} node the finished node
691
+ * @param {(node: TNode) => string} sourceText reads a node's source
692
+ */
693
+ printedSource(node, sourceText) {
694
+ const n = /** @type {number} */ (node);
695
+ if (n >= this._storeText.length) this._growStore(n + 1);
696
+ this._sourceText = sourceText;
697
+ this._storeText[n] = null;
698
+ this._storeGen[n] = this._gen;
699
+ if (n < this._storeLow) this._storeLow = n;
700
+ if (n > this._storeHigh) this._storeHigh = n;
701
+ }
702
+
492
703
  /**
493
704
  * Print one node and hand its text straight back — for a node inside one being
494
705
  * printed in pieces, whose text is emitted as it is printed, so the store
@@ -505,10 +716,17 @@ class PrintContext {
505
716
  * @returns {string} its printed text
506
717
  */
507
718
  get(node) {
508
- const n = /** @type {EXPECTED_ANY} */ (node);
509
- return /** @type {string} */ (
510
- this._storeGen[n] === this._gen ? this._storeText[n] : undefined
719
+ const n = /** @type {number} */ (node);
720
+ if (this._storeGen[n] !== this._gen) {
721
+ return /** @type {string} */ (/** @type {unknown} */ (undefined));
722
+ }
723
+ const text = this._storeText[n];
724
+ if (text !== null) return text;
725
+ const source = /** @type {(node: TNode) => string} */ (this._sourceText)(
726
+ node
511
727
  );
728
+ this._storeText[n] = source;
729
+ return source;
512
730
  }
513
731
 
514
732
  /**
@@ -566,12 +784,32 @@ class PrintContext {
566
784
  * @param {number} index the piece's index, from {@link emitRetractable}
567
785
  */
568
786
  retract(index) {
787
+ if (this._deferred !== null) this._deferred.delete(index);
569
788
  this._chunks[index] = "";
570
789
  if (this._retractableMappings === null) return;
571
790
  const mapping = this._retractableMappings[index];
572
791
  if (mapping !== undefined) this._mappings[mapping][2] = -1;
573
792
  }
574
793
 
794
+ /**
795
+ * Whether the output after a piece holds a character outside ASCII, the
796
+ * comments still waiting to be placed included.
797
+ * @param {number} index the piece's index, from {@link emitRetractable}
798
+ * @returns {boolean} true when it does
799
+ */
800
+ writesNonAscii(index) {
801
+ this._settleDeferred();
802
+ const chunks = this._chunks;
803
+ for (let i = index + 1; i < chunks.length; i++) {
804
+ if (NON_ASCII_RE.test(chunks[i])) return true;
805
+ }
806
+ const inserts = this._inserts;
807
+ for (let i = this._insertIdx; i < inserts.length; i++) {
808
+ if (NON_ASCII_RE.test(inserts[i][1])) return true;
809
+ }
810
+ return NON_ASCII_RE.test(this._tail);
811
+ }
812
+
575
813
  /**
576
814
  * Fold `text` into an already-emitted piece, in front of the character it ends
577
815
  * with — a later sibling whose body belongs inside that piece, as a repeated
@@ -582,6 +820,7 @@ class PrintContext {
582
820
  * @param {string} text what to fold in, its own closer included
583
821
  */
584
822
  foldIntoRetractable(index, text) {
823
+ this._settleDeferred();
585
824
  const piece = this._chunks[index];
586
825
  this._chunks[index] = `${piece.slice(0, -1)}${text}`;
587
826
  }
@@ -594,9 +833,31 @@ class PrintContext {
594
833
  * @param {string} text what the piece says now
595
834
  */
596
835
  rewriteRetractable(index, text) {
836
+ if (this._deferred !== null) this._deferred.delete(index);
597
837
  this._chunks[index] = text;
598
838
  }
599
839
 
840
+ /**
841
+ * {@link rewriteRetractable} with text that is asked for only once the output
842
+ * is read: a piece rewritten many times over is then built once, not each time.
843
+ * @param {number} index the piece's index, from {@link emitRetractable}
844
+ * @param {{ readonly text: string }} source what holds the piece's text
845
+ */
846
+ deferRetractable(index, source) {
847
+ if (this._deferred === null) this._deferred = new Map();
848
+ this._deferred.set(index, source);
849
+ }
850
+
851
+ /**
852
+ * Write every deferred piece's text in, before anything reads the pieces.
853
+ */
854
+ _settleDeferred() {
855
+ const deferred = this._deferred;
856
+ if (deferred === null) return;
857
+ this._deferred = null;
858
+ for (const [index, source] of deferred) this._chunks[index] = source.text;
859
+ }
860
+
600
861
  /**
601
862
  * {@link take} for a top-level node a later sibling may still make dead — the
602
863
  * unprefixed twin of a vendor-prefixed rule, which can stand anywhere after
@@ -759,6 +1020,7 @@ class PrintContext {
759
1020
  * @returns {SourceMap} the input->output source map
760
1021
  */
761
1022
  sourceMap(options, code) {
1023
+ this._settleDeferred();
762
1024
  let out = "";
763
1025
  let genLine = 0;
764
1026
  let genCol = 0;
@@ -830,6 +1092,7 @@ class PrintContext {
830
1092
  * @returns {void}
831
1093
  */
832
1094
  substitute(resolve, infix) {
1095
+ this._settleDeferred();
833
1096
  const chunks = this._chunks;
834
1097
  const mappings = this._mappings;
835
1098
  // Both pieces and mappings are output-ordered, so one cursor walks them
@@ -892,6 +1155,7 @@ class PrintContext {
892
1155
  * @param {string} text the output to keep instead
893
1156
  */
894
1157
  replaceAll(text) {
1158
+ this._deferred = null;
895
1159
  this._chunks.length = 0;
896
1160
  this._tail = text;
897
1161
  this._tailLength = text.length;
@@ -903,6 +1167,7 @@ class PrintContext {
903
1167
  }
904
1168
 
905
1169
  result() {
1170
+ this._settleDeferred();
906
1171
  // Trailing kept comments (after the last top-level node) flush here.
907
1172
  if (this._insertIdx < this._inserts.length) this._flushBefore(Infinity);
908
1173
  // Nothing was ever cut into its own piece, so there is nothing to join.
@@ -919,29 +1184,38 @@ class PrintContext {
919
1184
  * Visitor coordinator: owns the visitor registry and drives a language
920
1185
  * `grammar` over the source. Language-agnostic — each syntax (CSS, HTML, …)
921
1186
  * binds its own grammar, node-type enum and (optionally) node printer.
922
- * Babel-style usage:
1187
+ * Usage:
923
1188
  *
924
1189
  * ```
925
1190
  * processor.use({ [NodeType.X]: (path) => {}, [NodeType.Y]: { enter, exit } });
926
1191
  * processor.process(source);
927
1192
  * ```
928
- * @template TPath
1193
+ * @template {NodePath<TNode>} TPath
929
1194
  * @template TNode
930
1195
  * @template [TProcessOptions=object]
931
1196
  * @template [TPrintOptions=object]
1197
+ * @template {NodeParts} [TParts=AnyParts] the language's parts, which type each visitor's path by node type
1198
+ * @template [TState=unknown] what `process` hands every visitor as `path.state`
1199
+ * @template [TVisitors=VisitorMap<TPath>] the language's visitor map, each path typed by its key and with `TState`
932
1200
  */
933
1201
  class SourceProcessor {
934
1202
  /**
935
1203
  * @param {Grammar<TPath, TNode, TProcessOptions, TPrintOptions>} grammar the grammar to drive over the source
936
1204
  * @param {NodePrinter<TPath, TNode, TPrintOptions>=} printer the node printer, fired per node once its visitors and children are done; the same `path` a visitor gets plus the print context as its writer. Required to print (e.g. `mode`); a future API can let a developer supply their own
1205
+ * @param {(() => NodePrinter<TPath, TNode, TPrintOptions>)=} loadPrinter asked for the printer the first time something prints, for a language that keeps its printer in a module of its own — so a walk that never prints never loads it
1206
+ * @param {TPath=} path the path the grammar hands its visitors, whose `state` a run sets
937
1207
  */
938
- constructor(grammar, printer) {
1208
+ constructor(grammar, printer, loadPrinter, path) {
939
1209
  /** @type {Grammar<TPath, TNode, TProcessOptions, TPrintOptions>} */
940
1210
  this._grammar = grammar;
941
1211
  /** @type {CompiledVisitorMap<TPath>} */
942
1212
  this._visitors = [];
943
1213
  /** @type {NodePrinter<TPath, TNode, TPrintOptions> | undefined} */
944
1214
  this._printer = printer;
1215
+ /** @type {(() => NodePrinter<TPath, TNode, TPrintOptions>) | undefined} */
1216
+ this._loadPrinter = loadPrinter;
1217
+ /** @type {TPath | undefined} */
1218
+ this._path = path;
945
1219
  // Set for the one print {@link processDeferred} holds open, so `process`
946
1220
  // hands it the context instead of building the output straight away.
947
1221
  /** @type {((ctx: PrintContext<TPath, TNode, TPrintOptions>, build: () => { code: string, map: SourceMap | undefined }) => void) | null} */
@@ -949,32 +1223,101 @@ class SourceProcessor {
949
1223
  }
950
1224
 
951
1225
  /**
952
- * Register a Babel-style visitor map; calls accumulate per node type.
1226
+ * Register one bucket for several node types, as a map naming each would;
1227
+ * its path takes only the parts those types have.
1228
+ * @template {number} T
1229
+ * @overload
1230
+ * @param {T[]} types the node types the bucket visits
1231
+ * @param {VisitorBucket<TypedNodePath<TPath, TNode, TParts, T, TState>>} bucket the visitor
1232
+ * @returns {SourceProcessor<TPath, TNode, TProcessOptions, TPrintOptions, TParts, TState, TVisitors>} `this`, for chaining
1233
+ */
1234
+ /**
1235
+ * Register a visitor map; calls accumulate per node type, and each
1236
+ * visitor's path takes only its type's parts.
953
1237
  * A bucket is a function (= `{ enter }`) or `{ enter?, exit? }`.
1238
+ * @overload
1239
+ * @param {TVisitors} map visitor map keyed by node type
1240
+ * @returns {SourceProcessor<TPath, TNode, TProcessOptions, TPrintOptions, TParts, TState, TVisitors>} `this`, for chaining
1241
+ */
1242
+ /**
1243
+ * Register a visitor map built at runtime, keyed by any node type.
1244
+ * @overload
954
1245
  * @param {VisitorMap<TPath>} map visitor map keyed by node type
955
- * @returns {SourceProcessor<TPath, TNode, TProcessOptions, TPrintOptions>} `this`, for chaining
1246
+ * @returns {SourceProcessor<TPath, TNode, TProcessOptions, TPrintOptions, TParts, TState, TVisitors>} `this`, for chaining
1247
+ */
1248
+ /**
1249
+ * @param {number[] | TVisitors | VisitorMap<TPath>} map visitor map, or the node types `bucket` visits
1250
+ * @param {VisitorBucket<TypedNodePath<TPath, TNode, TParts, number, TState>>=} bucket the visitor, with an array of types
1251
+ * @returns {SourceProcessor<TPath, TNode, TProcessOptions, TPrintOptions, TParts, TState, TVisitors>} `this`, for chaining
956
1252
  */
957
- use(map) {
1253
+ use(map, bucket) {
1254
+ if (Array.isArray(map)) {
1255
+ if (bucket === undefined) {
1256
+ throw new TypeError(
1257
+ "SourceProcessor.use(types, bucket): a visitor is required"
1258
+ );
1259
+ }
1260
+ for (let i = 0; i < map.length; i++) {
1261
+ this._add(
1262
+ map[i],
1263
+ /** @type {VisitorBucket<TPath>} */ (
1264
+ /** @type {VisitorBucket<TPath> | VisitorBucket<TypedNodePath<TPath, TNode, TParts, number, TState>>} */ (
1265
+ bucket
1266
+ )
1267
+ )
1268
+ );
1269
+ }
1270
+ return this;
1271
+ }
958
1272
  // `map`'s keys are node-type enum members; `Object.keys` stringifies them,
959
1273
  // so index the compiled array by the number to match the numeric `node.type`.
960
- for (const type of Object.keys(map)) {
1274
+ for (const type of Object.keys(/** @type {VisitorMap<TPath>} */ (map))) {
961
1275
  const key = Number(type);
962
- const v = map[key];
963
- let bucket = this._visitors[key];
964
- if (!bucket) {
965
- bucket = { enter: [], exit: [] };
966
- this._visitors[key] = bucket;
967
- }
968
- if (typeof v === "function") {
969
- bucket.enter.push(v);
970
- } else {
971
- if (v.enter) bucket.enter.push(v.enter);
972
- if (v.exit) bucket.exit.push(v.exit);
973
- }
1276
+ this._add(key, /** @type {VisitorMap<TPath>} */ (map)[key]);
974
1277
  }
975
1278
  return this;
976
1279
  }
977
1280
 
1281
+ /**
1282
+ * @param {number} type node type
1283
+ * @param {VisitorBucket<TPath>} visitor its visitor
1284
+ */
1285
+ _add(type, visitor) {
1286
+ let compiled = this._visitors[type];
1287
+ if (!compiled) {
1288
+ compiled = { enter: [], exit: [] };
1289
+ this._visitors[type] = compiled;
1290
+ }
1291
+ if (typeof visitor === "function") {
1292
+ compiled.enter.push(visitor);
1293
+ } else {
1294
+ if (visitor.enter) compiled.enter.push(visitor.enter);
1295
+ if (visitor.exit) compiled.exit.push(visitor.exit);
1296
+ }
1297
+ }
1298
+
1299
+ /**
1300
+ * Run the grammar with the path's `state` set to the run's, put back after so
1301
+ * a run nested in a visitor leaves its caller's.
1302
+ * @param {string} input the source
1303
+ * @param {PrintContext<TPath, TNode, TPrintOptions> | undefined} ctx the print context, when printing
1304
+ * @param {TProcessOptions} opts process options
1305
+ */
1306
+ _run(input, ctx, opts) {
1307
+ const path = this._path;
1308
+ if (path === undefined) {
1309
+ this._grammar(input, this._visitors, ctx, opts);
1310
+ return;
1311
+ }
1312
+ const outer = path.state;
1313
+ path.state = /** @type {RunState<TState>} */ (opts).state;
1314
+ try {
1315
+ this._grammar(input, this._visitors, ctx, opts);
1316
+ } finally {
1317
+ path.state = outer;
1318
+ }
1319
+ }
1320
+
978
1321
  /**
979
1322
  * Parse `input` once and fire the visitors in source order. Asking for output
980
1323
  * — `mode`, the one thing that names it — makes the same walk print, given a
@@ -987,31 +1330,40 @@ class SourceProcessor {
987
1330
  * never re-parses; all configuration is per-call.
988
1331
  * @overload
989
1332
  * @param {string} input the source
990
- * @param {TProcessOptions & { mode: PrintOptions["mode"] } & { source: string, content?: string }} options process options, naming the input so a map is built
1333
+ * @param {TProcessOptions & RunState<TState> & { mode: PrintOptions["mode"] } & { source: string, content?: string }} options process options, naming the input so a map is built
991
1334
  * @returns {{ code: string, map: SourceMap }} the output and its map
992
1335
  */
993
1336
  /**
994
1337
  * @overload
995
1338
  * @param {string} input the source
996
- * @param {TProcessOptions & { mode: PrintOptions["mode"] }} options process options, asking for output but no map
1339
+ * @param {TProcessOptions & RunState<TState> & { mode: PrintOptions["mode"] }} options process options, asking for output but no map
997
1340
  * @returns {{ code: string, map: undefined }} the output alone
998
1341
  */
999
1342
  /**
1000
1343
  * @overload
1001
1344
  * @param {string} input the source
1002
- * @param {TProcessOptions=} options process options, asking for no output
1345
+ * @param {(TProcessOptions & RunState<TState>)=} options process options, asking for no output
1003
1346
  * @returns {undefined} nothing — the walk alone
1004
1347
  */
1005
1348
  /**
1006
1349
  * @param {string} input source text
1007
- * @param {TProcessOptions=} options grammar-specific options (`skip`, …) plus `mode` and, for the map, `source` / `content`
1008
- * @returns {EXPECTED_ANY} `{ code, map }` when printing, else `undefined` — see the overloads
1350
+ * @param {(TProcessOptions & RunState<TState>)=} options grammar-specific options (`skip`, …) plus `mode`, for the map `source` / `content`, and the visitors' `state`
1351
+ * @returns {{ code: string, map: SourceMap | undefined } | undefined} `{ code, map }` when printing, else `undefined` — see the overloads
1009
1352
  */
1010
1353
  process(input, options) {
1011
1354
  const opts = options || /** @type {TProcessOptions} */ ({});
1012
1355
  const asked = /** @type {{ mode?: PrintOptions["mode"] }} */ (opts).mode;
1356
+ // Asked for once per `process` and never per node, which is what lets a
1357
+ // language hold its printer back until something actually prints.
1358
+ if (
1359
+ this._printer === undefined &&
1360
+ asked !== undefined &&
1361
+ this._loadPrinter
1362
+ ) {
1363
+ this._printer = this._loadPrinter();
1364
+ }
1013
1365
  if (this._printer === undefined || asked === undefined) {
1014
- this._grammar(input, this._visitors, undefined, opts);
1366
+ this._run(input, undefined, opts);
1015
1367
  return undefined;
1016
1368
  }
1017
1369
  // Handed over whole rather than copied entry by entry: which entries are
@@ -1019,11 +1371,11 @@ class SourceProcessor {
1019
1371
  // along is inert, since a printer reads only what its own type declares.
1020
1372
  const ctx = new PrintContext(
1021
1373
  /** @type {PrintOptions & TPrintOptions} */ (
1022
- /** @type {unknown} */ ({ ...opts, mode: asked })
1374
+ /** @type {typeof opts | (PrintOptions & TPrintOptions)} */ (opts)
1023
1375
  ),
1024
- /** @type {NodePrinter<TPath, TNode, TPrintOptions>} */ (this._printer)
1376
+ this._printer
1025
1377
  );
1026
- this._grammar(input, this._visitors, ctx, opts);
1378
+ this._run(input, ctx, opts);
1027
1379
  const name = /** @type {{ source?: string, content?: string }} */ (opts);
1028
1380
  const build = () => {
1029
1381
  const code = ctx.result();
@@ -1061,7 +1413,7 @@ class SourceProcessor {
1061
1413
  * This is the shape `process` itself takes once it is async: how the answers
1062
1414
  * are waited for is this method's business, so nothing above it changes.
1063
1415
  * @param {string} input the source
1064
- * @param {Omit<TProcessOptions, "renderEmbeddedSource"> & { mode: PrintOptions["mode"] } & { source?: string, content?: string, renderEmbeddedSource?: (source: string, hole: EXPECTED_ANY) => Promise<string | undefined> | string | undefined }} options process options; a print, so `mode` names which one, and naming the input builds a map. `renderEmbeddedSource` is the grammar's own option with a wider answer — it may answer asynchronously, and is handed each {@link DeferredWrite} whole. Absent, this is `process` with a promise around it
1416
+ * @param {Omit<TProcessOptions, "renderEmbeddedSource"> & RunState<TState> & { mode: PrintOptions["mode"] } & { source?: string, content?: string, renderEmbeddedSource?: (source: string, hole: DeferredEmbeddedSource) => Promise<string | undefined> | string | undefined }} options process options; a print, so `mode` names which one, and naming the input builds a map. `renderEmbeddedSource` is the grammar's own option with a wider answer — it may answer asynchronously, and is handed each {@link DeferredWrite} whole. Absent, this is `process` with a promise around it
1065
1417
  * @returns {Promise<{ code: string, map: SourceMap | undefined }>} the output and its map
1066
1418
  */
1067
1419
  async processAsync(input, options) {
@@ -1071,7 +1423,10 @@ class SourceProcessor {
1071
1423
  // renderer's answer widened, which `Omit` cannot say and nothing reads.
1072
1424
  const opts =
1073
1425
  /** @type {TProcessOptions & { mode: PrintOptions["mode"] }} */
1074
- (/** @type {unknown} */ (options));
1426
+ (
1427
+ /** @type {typeof options | (TProcessOptions & { mode: PrintOptions["mode"] })} */
1428
+ (options)
1429
+ );
1075
1430
 
1076
1431
  if (render === undefined) {
1077
1432
  return /** @type {{ code: string, map: SourceMap | undefined }} */ (
@@ -1079,7 +1434,7 @@ class SourceProcessor {
1079
1434
  );
1080
1435
  }
1081
1436
 
1082
- /** @type {DeferredWrite[]} */
1437
+ /** @type {DeferredEmbeddedSource[]} */
1083
1438
  const deferred = [];
1084
1439
  const { finish } = this._processDeferred(input, {
1085
1440
  ...opts,
@@ -1094,10 +1449,43 @@ class SourceProcessor {
1094
1449
  deferred.map((hole) => render(hole.source, hole))
1095
1450
  );
1096
1451
 
1097
- return finish((id) => {
1098
- const hole = deferred[id];
1452
+ if (
1453
+ !deferred.some(
1454
+ (hole, id) => hole.decides !== undefined && hole.decides(answers[id])
1455
+ )
1456
+ ) {
1457
+ return finish((id) => {
1458
+ const hole = deferred[id];
1459
+
1460
+ return hole === undefined ? undefined : hole.build(answers[id]);
1461
+ });
1462
+ }
1463
+
1464
+ // An answer overturned a choice the print made on the source, so it runs
1465
+ // again with every answer in hand. Nothing is asked twice: this print offers
1466
+ // a subset of the first's, and an offer it alone made is left as written.
1467
+ /** @type {Map<string, string | undefined>} */
1468
+ const known = new Map();
1469
+ for (let id = 0; id < deferred.length; id++) {
1470
+ known.set(deferredKey(deferred[id]), answers[id]);
1471
+ }
1472
+ /**
1473
+ * @param {Omit<DeferredWrite, "build">} offer an offer, `build` and all or without it
1474
+ * @returns {string | undefined} what the first print was answered for it
1475
+ */
1476
+ const embeddedAnswers = (offer) => known.get(deferredKey(offer));
1477
+ /** @type {DeferredWrite[]} */
1478
+ const again = [];
1479
+ const reprint = this._processDeferred(input, {
1480
+ ...opts,
1481
+ renderEmbeddedSource: undefined,
1482
+ deferEmbeddedSource: again,
1483
+ embeddedAnswers
1484
+ });
1485
+ return reprint.finish((id) => {
1486
+ const hole = again[id];
1099
1487
 
1100
- return hole === undefined ? undefined : hole.build(answers[id]);
1488
+ return hole === undefined ? undefined : hole.build(embeddedAnswers(hole));
1101
1489
  });
1102
1490
  }
1103
1491
 
@@ -1108,7 +1496,7 @@ class SourceProcessor {
1108
1496
  * {@link processAsync} is built on, and private for that reason: a caller
1109
1497
  * asks for an asynchronous print, not for the way one is arranged.
1110
1498
  * @param {string} input the source
1111
- * @param {TProcessOptions & { mode: PrintOptions["mode"] } & { source?: string, content?: string }} options process options; a print, so `mode` names which one, and naming the input builds a map
1499
+ * @param {TProcessOptions & RunState<TState> & { mode: PrintOptions["mode"] } & { source?: string, content?: string }} options process options; a print, so `mode` names which one, and naming the input builds a map
1112
1500
  * @returns {{ finish: (resolve: (id: number) => string | undefined) => { code: string, map: SourceMap | undefined } }} the deferred print
1113
1501
  */
1114
1502
  _processDeferred(input, options) {