@depup/webpack 5.110.1-depup.0 → 5.111.1-depup.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (304) hide show
  1. package/README.md +7 -8
  2. package/changes.json +7 -11
  3. package/lib/APIPlugin.js +26 -11
  4. package/lib/AutomaticPrefetchPlugin.js +1 -1
  5. package/lib/Cache.js +8 -3
  6. package/lib/CacheFacade.js +1 -1
  7. package/lib/ChunkGraph.js +20 -18
  8. package/lib/CircularModulesPlugin.js +157 -55
  9. package/lib/CleanPlugin.js +2 -2
  10. package/lib/CompatibilityPlugin.js +3 -4
  11. package/lib/Compilation.js +337 -338
  12. package/lib/Compiler.js +213 -51
  13. package/lib/ConcatenationScope.js +25 -35
  14. package/lib/ConstPlugin.js +16 -132
  15. package/lib/CopyPlugin.js +1054 -0
  16. package/lib/DefinePlugin.js +24 -8
  17. package/lib/DependencyTemplate.js +2 -1
  18. package/lib/DotenvPlugin.js +64 -40
  19. package/lib/ErrorHelpers.js +113 -0
  20. package/lib/ExportsInfo.js +30 -16
  21. package/lib/ExternalModule.js +47 -22
  22. package/lib/FileSystemInfo.js +17 -14
  23. package/lib/FlagDependencyExportsPlugin.js +53 -34
  24. package/lib/FlagDependencyUsagePlugin.js +17 -15
  25. package/lib/Generator.js +24 -2
  26. package/lib/HotModuleReplacementPlugin.js +55 -7
  27. package/lib/IgnorePlugin.js +1 -1
  28. package/lib/JavascriptMetaInfoPlugin.js +5 -3
  29. package/lib/LoaderOptionsPlugin.js +1 -1
  30. package/lib/MainTemplate.js +5 -1
  31. package/lib/Module.js +19 -10
  32. package/lib/ModuleGraph.js +6 -9
  33. package/lib/MultiCompiler.js +7 -17
  34. package/lib/MultiWatching.js +1 -1
  35. package/lib/NormalModule.js +148 -70
  36. package/lib/NormalModuleFactory.js +1 -1
  37. package/lib/RuntimeGlobals.js +21 -7
  38. package/lib/RuntimeModule.js +28 -12
  39. package/lib/RuntimePlugin.js +33 -3
  40. package/lib/RuntimeTemplate.js +1147 -847
  41. package/lib/SourceMapDevToolPlugin.js +54 -104
  42. package/lib/TemplatedPathPlugin.js +16 -59
  43. package/lib/Watching.js +9 -0
  44. package/lib/WebpackOptionsApply.js +84 -91
  45. package/lib/asset/AssetBytesGenerator.js +7 -1
  46. package/lib/asset/AssetGenerator.js +50 -24
  47. package/lib/asset/AssetModule.js +3 -0
  48. package/lib/asset/AssetSourceGenerator.js +7 -1
  49. package/lib/asset/WebManifestParser.js +7 -5
  50. package/lib/async-modules/AsyncModuleHelpers.js +10 -4
  51. package/lib/buildChunkGraph.js +11 -15
  52. package/lib/cache/AddBuildDependenciesPlugin.js +33 -4
  53. package/lib/cache/IdleFileCachePlugin.js +2 -2
  54. package/lib/cache/MemoryCachePlugin.js +4 -4
  55. package/lib/cache/MemoryWithGcCachePlugin.js +7 -8
  56. package/lib/cache/PackFileCacheStrategy.js +17 -19
  57. package/lib/cache/getLazyHashedEtag.js +3 -5
  58. package/lib/config/browserslistTargetHandler.js +17 -4
  59. package/lib/config/defaults.js +162 -142
  60. package/lib/config/getClaimedAssetTypes.js +10 -11
  61. package/lib/config/normalization.js +100 -20
  62. package/lib/config/target.js +13 -4
  63. package/lib/container/ContainerReferencePlugin.js +6 -0
  64. package/lib/container/RemoteRuntimeModule.js +9 -0
  65. package/lib/container/declaredRemotes.js +39 -0
  66. package/lib/{ContextExclusionPlugin.js → context/ContextExclusionPlugin.js} +1 -1
  67. package/lib/{ContextModule.js → context/ContextModule.js} +54 -115
  68. package/lib/{ContextModuleFactory.js → context/ContextModuleFactory.js} +19 -21
  69. package/lib/{ContextReplacementPlugin.js → context/ContextReplacementPlugin.js} +4 -4
  70. package/lib/css/CssGenerator.js +27 -11
  71. package/lib/css/CssInjectStyleRuntimeModule.js +9 -0
  72. package/lib/css/CssLoadingRuntimeModule.js +92 -15
  73. package/lib/css/CssModule.js +1 -1
  74. package/lib/css/CssModulesPlugin.js +3 -10
  75. package/lib/css/CssParser.js +162 -31
  76. package/lib/css/CssServerStylesRuntimeModule.js +9 -0
  77. package/lib/css/cssMinify.js +43 -32
  78. package/lib/css/data.js +3526 -871
  79. package/lib/css/syntax.js +6455 -1237
  80. package/lib/debug/ProfilingPlugin.js +7 -4
  81. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +6 -3
  82. package/lib/dependencies/AMDRuntimeModules.js +18 -0
  83. package/lib/dependencies/CommonJsExportRequireDependency.js +13 -12
  84. package/lib/dependencies/CommonJsExportsParserPlugin.js +12 -13
  85. package/lib/dependencies/CommonJsImportsParserPlugin.js +5 -5
  86. package/lib/dependencies/CommonJsPlugin.js +19 -3
  87. package/lib/dependencies/CommonJsRequireDependency.js +32 -9
  88. package/lib/dependencies/CommonJsSelfReferenceDependency.js +2 -4
  89. package/lib/dependencies/ContextDependency.js +1 -1
  90. package/lib/dependencies/ContextDependencyHelpers.js +3 -9
  91. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +20 -7
  92. package/lib/dependencies/ContextElementDependency.js +1 -1
  93. package/lib/dependencies/CssIcssExportDependency.js +13 -9
  94. package/lib/dependencies/CssIcssImportDependency.js +3 -6
  95. package/lib/dependencies/CssUrlDependency.js +3 -5
  96. package/lib/dependencies/HarmonyCompatibilityDependency.js +67 -22
  97. package/lib/dependencies/HarmonyDetectionParserPlugin.js +3 -4
  98. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +10 -4
  99. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +12 -7
  100. package/lib/dependencies/HarmonyExportExpressionDependency.js +47 -33
  101. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +217 -34
  102. package/lib/dependencies/HarmonyExportInitFragment.js +110 -23
  103. package/lib/dependencies/HarmonyExportSpecifierDependency.js +25 -58
  104. package/lib/dependencies/HarmonyImportBareSideEffectDependency.js +59 -0
  105. package/lib/dependencies/HarmonyImportDependency.js +99 -41
  106. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +198 -25
  107. package/lib/dependencies/HarmonyImportSideEffectDependency.js +117 -4
  108. package/lib/dependencies/HarmonyImportSpecifierDependency.js +40 -3
  109. package/lib/dependencies/HarmonyModulesPlugin.js +20 -0
  110. package/lib/dependencies/HtmlEntryDependency.js +136 -104
  111. package/lib/dependencies/HtmlInlineScriptDependency.js +3 -4
  112. package/lib/dependencies/HtmlInlineStyleDependency.js +3 -4
  113. package/lib/dependencies/ImportContextDependency.js +43 -3
  114. package/lib/dependencies/ImportDependency.js +8 -29
  115. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -1
  116. package/lib/dependencies/ImportMetaGlobHelpers.js +1 -1
  117. package/lib/dependencies/ImportMetaMainDependency.js +104 -0
  118. package/lib/dependencies/ImportMetaPlugin.js +67 -25
  119. package/lib/dependencies/ImportParserPlugin.js +25 -15
  120. package/lib/dependencies/LoaderPlugin.js +26 -1
  121. package/lib/dependencies/RequireContextDependencyParserPlugin.js +1 -1
  122. package/lib/dependencies/RequireHeaderDependency.js +20 -21
  123. package/lib/dependencies/SystemRuntimeModule.js +9 -0
  124. package/lib/dependencies/URLContextDependency.js +1 -1
  125. package/lib/dependencies/URLDependency.js +6 -5
  126. package/lib/dependencies/WorkerAndWorkletPlugin.js +16 -21
  127. package/lib/dependencies/WorkerDependency.js +12 -18
  128. package/lib/dependencies/WorkletDependency.js +12 -20
  129. package/lib/dependencies/importOptionsCheck.js +47 -0
  130. package/lib/dll/DelegatedModule.js +18 -1
  131. package/lib/dll/DllReferencePlugin.js +11 -8
  132. package/lib/dll/LibManifestPlugin.js +1 -1
  133. package/lib/errors/AnalyzableBailoutsWarning.js +41 -0
  134. package/lib/errors/DotenvFileError.js +29 -0
  135. package/lib/errors/DuplicateModulesWarning.js +12 -7
  136. package/lib/errors/EmptyCopyPatternWarning.js +26 -0
  137. package/lib/errors/ExternalStarReexportError.js +44 -0
  138. package/lib/errors/HookWebpackError.js +3 -2
  139. package/lib/errors/ImportedBindingAssignmentError.js +30 -0
  140. package/lib/errors/MissingSourceMapsWarning.js +36 -0
  141. package/lib/errors/ModuleParseError.js +2 -1
  142. package/lib/errors/UnusedAssetsWarning.js +36 -0
  143. package/lib/errors/UnusedFederationWarning.js +35 -0
  144. package/lib/errors/UnusedModulesWarning.js +38 -0
  145. package/lib/esm/ExportWebpackRequireRuntimeModule.js +9 -0
  146. package/lib/esm/ModuleChunkFormatPlugin.js +28 -3
  147. package/lib/esm/ModuleChunkLoadingPlugin.js +21 -5
  148. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +91 -53
  149. package/lib/hmr/HotModuleReplacement.runtime.js +8 -2
  150. package/lib/hmr/HotModuleReplacementRuntimeModule.js +9 -0
  151. package/lib/hmr/LazyCompilationPlugin.js +3 -5
  152. package/lib/html/HtmlGenerator.js +72 -87
  153. package/lib/html/HtmlModulesPlugin.js +479 -215
  154. package/lib/html/HtmlParser.js +110 -147
  155. package/lib/html/builtinEmbeddedRenderer.js +107 -0
  156. package/lib/html/data.js +142 -7
  157. package/lib/html/htmlMinify.js +92 -122
  158. package/lib/html/syntax.js +2031 -1556
  159. package/lib/ids/HashedModuleIdsPlugin.js +2 -1
  160. package/lib/index.js +49 -3
  161. package/lib/javascript/ChunkFormatHelpers.js +4 -3
  162. package/lib/javascript/JavascriptGenerator.js +8 -1
  163. package/lib/javascript/JavascriptModule.js +1 -0
  164. package/lib/javascript/JavascriptModulesPlugin.js +76 -80
  165. package/lib/javascript/JavascriptParser.js +1970 -900
  166. package/lib/javascript/StartupHelpers.js +27 -3
  167. package/lib/javascript/data.js +172 -0
  168. package/lib/javascript/grammar.js +5546 -0
  169. package/lib/javascript/parser.js +1500 -0
  170. package/lib/javascript/regexp.js +1762 -0
  171. package/lib/javascript/regexpData.js +51 -0
  172. package/lib/javascript/syntax.js +9061 -5262
  173. package/lib/json/JsonGenerator.js +7 -1
  174. package/lib/library/ModuleLibraryPlugin.js +171 -132
  175. package/lib/loaders/LoaderRunner.js +170 -14
  176. package/lib/node/NodeWatchFileSystem.js +3 -9
  177. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +22 -0
  178. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +8 -15
  179. package/lib/node/RequireChunkLoadingRuntimeModule.js +22 -0
  180. package/lib/optimize/AggressiveMergingPlugin.js +3 -5
  181. package/lib/optimize/ConcatenatedModule.js +222 -125
  182. package/lib/optimize/ConstExportsPlugin.js +50 -34
  183. package/lib/optimize/FlagIncludedChunksPlugin.js +3 -11
  184. package/lib/optimize/InlineExports.js +20 -2
  185. package/lib/optimize/InnerGraphPlugin.js +7 -13
  186. package/lib/optimize/LimitChunkCountPlugin.js +5 -8
  187. package/lib/optimize/MangleExportsPlugin.js +13 -4
  188. package/lib/optimize/ModuleConcatenationPlugin.js +27 -5
  189. package/lib/optimize/RealContentHashPlugin.js +179 -44
  190. package/lib/optimize/SideEffectsFlagPlugin.js +24 -28
  191. package/lib/optimize/SplitChunksPlugin.js +2 -4
  192. package/lib/performance/AnalyzableBailoutsPlugin.js +115 -0
  193. package/lib/performance/BroadContextsPlugin.js +1 -1
  194. package/lib/performance/CacheEffectivenessPlugin.js +7 -7
  195. package/lib/performance/DuplicateModulesPlugin.js +57 -13
  196. package/lib/performance/EvalUsagePlugin.js +5 -2
  197. package/lib/performance/MissingSourceMapsPlugin.js +115 -0
  198. package/lib/performance/PureAnnotationsPlugin.js +6 -3
  199. package/lib/performance/SizeLimitsPlugin.js +2 -4
  200. package/lib/performance/TopLevelThisPlugin.js +5 -4
  201. package/lib/performance/UnusedAssetsPlugin.js +109 -0
  202. package/lib/performance/UnusedFederationPlugin.js +147 -0
  203. package/lib/performance/UnusedModulesPlugin.js +141 -0
  204. package/lib/performance/UnusedReexportsPlugin.js +1 -55
  205. package/lib/performance/isOnlyReexported.js +65 -0
  206. package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +25 -5
  207. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +8 -8
  208. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +9 -0
  209. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +9 -0
  210. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +9 -0
  211. package/lib/prefetch/ResourceHintPlugin.js +29 -35
  212. package/lib/prefetch/ResourceHintRuntimeModule.js +9 -0
  213. package/lib/prefetch/StartupAssetHintRuntimeModule.js +16 -10
  214. package/lib/rules/RuleSetCompiler.js +211 -4
  215. package/lib/runtime/AsyncModuleRuntimeModule.js +103 -67
  216. package/lib/runtime/AutoPublicPathRuntimeModule.js +9 -0
  217. package/lib/runtime/BaseUriRuntimeModule.js +9 -0
  218. package/lib/runtime/ChunkNameRuntimeModule.js +9 -0
  219. package/lib/runtime/EnsureChunkRuntimeModule.js +35 -16
  220. package/lib/runtime/GetChunkFilenameRuntimeModule.js +12 -4
  221. package/lib/runtime/GetFullHashRuntimeModule.js +9 -0
  222. package/lib/runtime/GetMainFilenameRuntimeModule.js +9 -0
  223. package/lib/runtime/GetWorkletBootstrapRuntimeModule.js +9 -0
  224. package/lib/runtime/GlobalRuntimeModule.js +11 -4
  225. package/lib/runtime/HasOwnPropertyRuntimeModule.js +9 -0
  226. package/lib/runtime/HelperRuntimeModule.js +10 -0
  227. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +313 -222
  228. package/lib/runtime/NonceRuntimeModule.js +9 -0
  229. package/lib/runtime/OnChunksLoadedRuntimeModule.js +67 -20
  230. package/lib/runtime/PublicPathRuntimeModule.js +9 -0
  231. package/lib/runtime/RuntimeIdRuntimeModule.js +9 -0
  232. package/lib/runtime/SpecNamespaceObjectRuntimeModule.js +90 -0
  233. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +9 -0
  234. package/lib/runtime/StartupEntrypointRuntimeModule.js +9 -0
  235. package/lib/runtime/SystemContextRuntimeModule.js +9 -0
  236. package/lib/runtime/ToBinaryRuntimeModule.js +9 -0
  237. package/lib/schemes/DataUriPlugin.js +3 -6
  238. package/lib/schemes/HttpUriPlugin.js +22 -5
  239. package/lib/schemes/VirtualUrlPlugin.js +1 -1
  240. package/lib/serialization/BinaryMiddleware.js +9 -9
  241. package/lib/serialization/FileMiddleware.js +31 -18
  242. package/lib/serialization/ObjectMiddleware.js +168 -139
  243. package/lib/sharing/ConsumeSharedPlugin.js +12 -0
  244. package/lib/sharing/ConsumeSharedRuntimeModule.js +11 -0
  245. package/lib/sharing/ShareRuntimeModule.js +9 -0
  246. package/lib/sharing/declaredShared.js +47 -0
  247. package/lib/stats/DefaultStatsFactoryPlugin.js +6 -5
  248. package/lib/stats/DefaultStatsPrinterPlugin.js +3 -0
  249. package/lib/typescript/TypeScriptPlugin.js +10 -13
  250. package/lib/url/URLParserPlugin.js +6 -8
  251. package/lib/util/ArrayQueue.js +3 -3
  252. package/lib/util/LocConverter.js +4 -7
  253. package/lib/util/SourceProcessor.js +115 -99
  254. package/lib/util/URLAbsoluteSpecifier.js +3 -1
  255. package/lib/util/async.js +292 -0
  256. package/lib/util/buildDiagnostics.js +69 -0
  257. package/lib/util/chainedImports.js +3 -4
  258. package/lib/util/concatenate.js +4 -4
  259. package/lib/util/conventions.js +5 -1
  260. package/lib/util/createHooksRegistry.js +1 -2
  261. package/lib/util/createMappings.js +25 -3
  262. package/lib/util/dataURL.js +2 -3
  263. package/lib/util/deterministicGrouping.js +8 -13
  264. package/lib/util/findGraphRoots.js +6 -13
  265. package/lib/util/fs.js +27 -1
  266. package/lib/util/globUtils.js +1 -1
  267. package/lib/util/handlerKeys.js +40 -0
  268. package/lib/util/hash/wasm-hash.js +3 -4
  269. package/lib/util/identifier.js +20 -0
  270. package/lib/util/internalSerializables.js +7 -1
  271. package/lib/util/registerExternalSerializer.js +6 -45
  272. package/lib/util/removeBOM.js +82 -1
  273. package/lib/util/semver.js +5 -3
  274. package/lib/wasm-async/AsyncWasmCompileRuntimeModule.js +14 -3
  275. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +14 -3
  276. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +6 -1
  277. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +5 -1
  278. package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +7 -12
  279. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +12 -4
  280. package/lib/wasm-sync/WebAssemblyGenerator.js +6 -1
  281. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +5 -1
  282. package/lib/wasm-sync/WebAssemblyUtils.js +2 -4
  283. package/lib/web/FetchCompileAsyncWasmPlugin.js +10 -6
  284. package/lib/web/FetchCompileWasmPlugin.js +4 -2
  285. package/lib/web/JsonpChunkLoadingRuntimeModule.js +36 -0
  286. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +19 -0
  287. package/package.json +55 -46
  288. package/schemas/WebpackOptions.check.js +1 -1
  289. package/schemas/WebpackOptions.json +388 -76
  290. package/schemas/plugins/LoaderOptionsPlugin.check.js +1 -1
  291. package/schemas/plugins/ManifestPlugin.check.js +1 -1
  292. package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
  293. package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
  294. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
  295. package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
  296. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  297. package/schemas/plugins/debug/ProfilingPlugin.check.js +1 -1
  298. package/schemas/plugins/dll/DllReferencePlugin.check.js +1 -1
  299. package/schemas/plugins/ids/HashedModuleIdsPlugin.check.js +1 -1
  300. package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
  301. package/types.d.ts +1795 -608
  302. package/lib/dependencies/ExportBindingInitFragment.js +0 -191
  303. package/lib/errors/EntrypointOverlapWarning.js +0 -45
  304. package/lib/performance/EntrypointOverlapPlugin.js +0 -122
@@ -257,10 +257,9 @@ class URLParserPlugin {
257
257
  relative
258
258
  );
259
259
  dep.loc = parser.getLocation(expr);
260
- // `parser.javascript.urlHints` provides project-wide defaults
261
- // (resolved per-request, with `test` / `include` / `exclude`
262
- // matching); a per-URL magic comment for the same hint wins
263
- // when both are set.
260
+ // `parser.javascript.urlHints` gives the project-wide defaults,
261
+ // resolved per request; a per-URL magic comment for the same hint
262
+ // wins where both are set.
264
263
  ResourceHintPlugin.applyResourceHints(
265
264
  dep,
266
265
  this.options.urlHints,
@@ -270,10 +269,9 @@ class URLParserPlugin {
270
269
  parser.getLocation(expr)
271
270
  );
272
271
  parser.state.current.addDependency(dep);
273
- // For ESM module output the template embeds the asset's resolved
274
- // filename, so the asset must be code-generated first. Only added in
275
- // that mode — a code-gen dependency on an asset that a later watch
276
- // rebuild leaves unaffected can otherwise deadlock the scheduler.
272
+ // The ESM template embeds the asset's resolved filename, so the asset
273
+ // must be code-generated first. Added in that mode only: elsewhere the
274
+ // extra code-gen dependency can deadlock a watch rebuild.
277
275
  if (parser.state.compilation.options.output.module) {
278
276
  parser.state.module.addCodeGenerationDependency(dep);
279
277
  }
@@ -90,11 +90,11 @@ class ArrayQueue {
90
90
  [Symbol.iterator]() {
91
91
  return {
92
92
  next: () => {
93
- const item = this.dequeue();
94
- if (item) {
93
+ // length, not truthiness: a queued `0`/`false`/`undefined` is a value
94
+ if (this.length > 0) {
95
95
  return {
96
96
  done: false,
97
- value: item
97
+ value: /** @type {T} */ (this.dequeue())
98
98
  };
99
99
  }
100
100
  return {
@@ -63,13 +63,10 @@ class LocConverter {
63
63
  // Retreat on line 1: no `\n` precedes `pos`, the cache stays valid.
64
64
  this.column = pos;
65
65
  } else {
66
- // Retreat: count newlines crossed in (pos, this.pos), i.e.
67
- // exclude the newline at `this.pos` itself. By convention a
68
- // `\n` is the last column of its line, so when `this.pos`
69
- // sits on one we're already on the line containing it; only
70
- // newlines strictly **before** `this.pos` and at-or-after
71
- // `pos` represent crossed line boundaries. The smallest
72
- // crossed one is the next newline after the new position.
66
+ // WHY: A `\n` counts as the last column of its own line here, so a
67
+ // `this.pos` sitting on one is already on that line. Retreating
68
+ // therefore crosses only the newlines at or after `pos` and strictly
69
+ // before `this.pos` — the newline at `this.pos` is not one of them.
73
70
  let i = input.lastIndexOf("\n", this.pos - 1);
74
71
  while (i >= pos) {
75
72
  this._nextNewline = i;
@@ -99,6 +99,23 @@ const expandDeferredWrites = (text, resolve, infix) => {
99
99
  return out + text.slice(from);
100
100
  };
101
101
 
102
+ /**
103
+ * The text this print spells with every deferred write declined: each marker
104
+ * replaced by what would stand there had no renderer answered. What a print
105
+ * verifying itself by re-parsing has to read, since a marker otherwise parses
106
+ * as text where its node stood. `build` rather than `source` so a write inside
107
+ * an attribute comes back escaped for where it sits.
108
+ * @param {string} text the printed output, holding this print's markers
109
+ * @param {DeferredWrite[]} writes what the print deferred, indexed by id
110
+ * @returns {string} the text with every marker put back
111
+ */
112
+ const declineDeferredWrites = (text, writes) =>
113
+ expandDeferredWrites(
114
+ text,
115
+ (id) => (id < writes.length ? writes[id].build(undefined) : undefined),
116
+ deferredInfix
117
+ );
118
+
102
119
  /**
103
120
  * Babel-style visitor map keyed by a numeric node-type discriminator; a bucket
104
121
  * is a function (enter-only) or `{ enter?, exit? }`.
@@ -244,20 +261,20 @@ class PrintContext {
244
261
  /** @type {NodePrinter<TPath, TNode, TPrintOptions>} */
245
262
  this._printer = printer;
246
263
  // Printed text by node handle, in two columns rather than one `Map`: the
247
- // handles are dense integers, and a stylesheet prints ~300k nodes through
248
- // a store that never holds more than a few dozen of them at once.
264
+ // handles are dense integers, and `_moveEpoch` keeps the live set small.
249
265
  /** @type {string[]} each finished node's printed text */
250
266
  this._storeText = [];
251
267
  /** @type {Int32Array} the epoch each slot was written in */
252
268
  this._storeGen = new Int32Array(0);
253
269
  /** @type {number} current epoch; a slot from an older one reads as absent */
254
270
  this._gen = 1;
255
- // Output accumulates into `_tail`, a plain string append, so printing that
256
- // never takes anything back costs exactly what appending to one string
257
- // costs. A piece is cut off into `_chunks` only for text that may still be
258
- // taken back ({@link emitRetractable}) — that is what lets a printer emit
259
- // before it knows a later sibling overrides it, without every other emit
260
- // paying for the ability. The output is `_chunks` joined, then `_tail`.
271
+ /** @type {number} lowest slot written since the epoch last moved */
272
+ this._storeLow = 0x7fffffff;
273
+ /** @type {number} highest slot written since the epoch last moved */
274
+ this._storeHigh = -1;
275
+ // Output is `_chunks` joined, then `_tail`. Printing that never takes
276
+ // anything back only appends to `_tail`; a piece is cut off into `_chunks`
277
+ // for retractable text alone, so no other emit pays for that ability.
261
278
  /** @type {string[]} pieces already cut off, in output order */
262
279
  this._chunks = [];
263
280
  /** @type {string} output after the last cut piece */
@@ -268,7 +285,7 @@ class PrintContext {
268
285
  this._flattened = 0;
269
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 */
270
287
  this._mappings = [];
271
- /** @type {Map<number, number> | null} a retractable piece -> the mapping anchored to it, so taking the piece back takes its mapping too */
288
+ /** @type {number[] | null} by retractable piece index, the mapping anchored to it, so taking the piece back takes its mapping too */
272
289
  this._retractableMappings = null;
273
290
  // A map is built only for a caller that named the input, and that is known
274
291
  // before printing — so a print nobody asks a map of collects none.
@@ -279,10 +296,9 @@ class PrintContext {
279
296
  this._inserts = [];
280
297
  /** @type {number} next `_inserts` entry not yet flushed */
281
298
  this._insertIdx = 0;
282
- // Openers of the nodes being printed in pieces, innermost last, held back
283
- // until one of them turns out to have content: a node whose children all
284
- // print to nothing can then still be dropped whole, which is the one thing
285
- // emitting an opener eagerly would give up.
299
+ // Openers of the nodes printed in pieces, innermost last, held back until
300
+ // one has content — which is what lets a node whose children all print to
301
+ // nothing still be dropped whole.
286
302
  /** @type {string[]} openers not yet emitted, outermost first */
287
303
  this._pending = [];
288
304
  /** @type {[number | undefined, number | undefined, number | undefined] | null} anchor for the first pending opener */
@@ -389,16 +405,14 @@ class PrintContext {
389
405
  _growStore(need) {
390
406
  // From empty: a context that prints one inline `style=""` must not pay for
391
407
  // a stylesheet's worth of columns.
392
- const size = Math.max(need, this._storeText.length * 2, 16);
393
- // Appended, which keeps the column packed for the read every composed child
394
- // makes, and carries what it already holds across in the same pass.
395
- const held = this._storeText;
396
- const text = [];
397
- for (let i = 0; i < held.length; i++) text.push(held[i]);
398
- for (let i = held.length; i < size; i++) text.push("");
408
+ const text = this._storeText;
409
+ const size = Math.max(need, text.length * 2, 16);
410
+ // Appended in place: `push` keeps the column packed for the read every
411
+ // composed child makes, and what it already holds never moves — where
412
+ // filling a second array would copy every slot again at each growth.
413
+ for (let i = text.length; i < size; i++) text.push("");
399
414
  const gen = new Int32Array(size);
400
415
  gen.set(this._storeGen);
401
- this._storeText = text;
402
416
  this._storeGen = gen;
403
417
  }
404
418
 
@@ -409,8 +423,25 @@ class PrintContext {
409
423
  * node's text.
410
424
  */
411
425
  dropStore() {
412
- // Bumping the epoch invalidates every slot at once, so this stays O(1) —
413
- // it runs per node, and clearing a column by length would not.
426
+ this._moveEpoch();
427
+ }
428
+
429
+ /**
430
+ * Move the epoch on and release the text every slot written under the old one
431
+ * holds. Only the range actually written is walked, so the drop stays O(1)
432
+ * per node.
433
+ * @returns {void}
434
+ */
435
+ _moveEpoch() {
436
+ const high = this._storeHigh;
437
+ if (high !== -1) {
438
+ // `""` rather than a hole: the column is packed, and a hole in it would
439
+ // cost every read after this one.
440
+ const text = this._storeText;
441
+ for (let i = this._storeLow; i <= high; i++) text[i] = "";
442
+ this._storeLow = 0x7fffffff;
443
+ this._storeHigh = -1;
444
+ }
414
445
  this._gen++;
415
446
  }
416
447
 
@@ -454,6 +485,8 @@ class PrintContext {
454
485
  if (n >= this._storeText.length) this._growStore(n + 1);
455
486
  this._storeText[n] = text;
456
487
  this._storeGen[n] = this._gen;
488
+ if (n < this._storeLow) this._storeLow = n;
489
+ if (n > this._storeHigh) this._storeHigh = n;
457
490
  }
458
491
 
459
492
  /**
@@ -487,14 +520,12 @@ class PrintContext {
487
520
  _emit(text) {
488
521
  this._tail += text;
489
522
  this._tailLength += text.length;
490
- // A printer returns its text as a rope of its children's pieces, and
491
- // appending a rope onto a rope keeps every fragment of every node reachable
492
- // until the output is finally flattened — on a stylesheet of many top-level
493
- // rules, a second copy of the whole output. So cut the tail off once it has
494
- // grown past a block and force that block flat, which drops every fragment
495
- // behind it. Per block rather than per piece: the flattening copy is one
496
- // the result would have paid for anyway, but paying it per piece means an
497
- // allocation for each, and the pieces are small.
523
+ // WHY: A printer returns a rope of its children's pieces, and appending a
524
+ // rope onto a rope keeps every fragment reachable until the output is
525
+ // flattened — a second copy of a large stylesheet. Cutting the tail once it
526
+ // passes a block forces that block flat and drops the fragments behind it.
527
+ // Per block rather than per piece: the copy is one the result pays anyway,
528
+ // while per piece it would be an allocation each, and the pieces are small.
498
529
  if (this._tailLength >= FLATTEN_BLOCK) this._cutTail();
499
530
  }
500
531
 
@@ -537,7 +568,7 @@ class PrintContext {
537
568
  retract(index) {
538
569
  this._chunks[index] = "";
539
570
  if (this._retractableMappings === null) return;
540
- const mapping = this._retractableMappings.get(index);
571
+ const mapping = this._retractableMappings[index];
541
572
  if (mapping !== undefined) this._mappings[mapping][2] = -1;
542
573
  }
543
574
 
@@ -583,12 +614,12 @@ class PrintContext {
583
614
  this.anchor(srcOffset, srcLine, srcCol);
584
615
  const mapping = this._mappings.length > before ? before : -1;
585
616
  const at = this.emitRetractable(text === undefined ? this.get(node) : text);
586
- this._gen++;
617
+ this._moveEpoch();
587
618
  if (mapping !== -1) {
588
- if (this._retractableMappings === null) {
589
- this._retractableMappings = new Map();
590
- }
591
- this._retractableMappings.set(at, mapping);
619
+ // Indexed by piece rather than a `Map`: pieces are dense integers, and
620
+ // nearly every rule minifying goes out as one.
621
+ if (this._retractableMappings === null) this._retractableMappings = [];
622
+ this._retractableMappings[at] = mapping;
592
623
  }
593
624
  return at;
594
625
  }
@@ -612,7 +643,7 @@ class PrintContext {
612
643
  this._emit(
613
644
  text === undefined ? this.get(/** @type {TNode} */ (node)) : text
614
645
  );
615
- this._gen++;
646
+ this._moveEpoch();
616
647
  }
617
648
 
618
649
  /**
@@ -724,68 +755,44 @@ class PrintContext {
724
755
 
725
756
  /**
726
757
  * @param {SourceMapOptions} options the input's name / content
758
+ * @param {string=} code the output {@link result} built, walked for its line breaks
727
759
  * @returns {SourceMap} the input->output source map
728
760
  */
729
- sourceMap(options) {
761
+ sourceMap(options, code) {
730
762
  let out = "";
731
763
  let genLine = 0;
732
764
  let genCol = 0;
733
765
  let srcLine = 0;
734
766
  let srcCol = 0;
735
767
  let atLineStart = true;
736
- // Where each anchor landed, walked once alongside the mappings — both are
737
- // in output order, so this is one pass over the output, not a position
738
- // recomputed per mapping. An anchor can sit inside a piece rather than at
739
- // its start, since output accumulates into the piece it is appending to.
768
+ // Walked over the flat output rather than piece by piece: a piece is a rope
769
+ // until something reads it, and reading each one flattens each one.
770
+ const text = code === undefined ? this.result() : code;
740
771
  const chunks = this._chunks;
741
- const tail = this._tail;
742
- /**
743
- * @param {number} i piece index, `chunks.length` being the tail
744
- * @returns {string} that piece
745
- */
746
- const pieceAt = (i) => (i === chunks.length ? tail : chunks[i]);
747
772
  let atChunk = 0;
773
+ let chunkStart = 0;
748
774
  let atOffset = 0;
749
775
  let atLine = 0;
750
776
  let atCol = 0;
751
- // Offset of the next newline at or after the cursor, `-1` for none left in
752
- // this piece. Carried rather than searched for per mapping: `indexOf` has no
753
- // end bound, so asking it again for each of a piece's mappings scans again to
754
- // the end of the piece every time — and minified output, the case with no
755
- // newlines at all, is the one where that is the whole piece.
756
- let nextNewline = pieceAt(0).indexOf("\n");
757
- /**
758
- * @param {string} text the piece to walk
759
- * @param {number} to offset to walk to
760
- */
761
- const advanceOver = (text, to) => {
762
- while (nextNewline !== -1 && nextNewline < to) {
763
- atLine++;
764
- atCol = 0;
765
- atOffset = nextNewline + 1;
766
- nextNewline = text.indexOf("\n", atOffset);
767
- }
768
- atCol += to - atOffset;
769
- atOffset = to;
770
- };
771
- /**
772
- * @param {number} chunk piece index to advance to
773
- * @param {number} offset offset within it
774
- */
775
- const advanceTo = (chunk, offset) => {
776
- while (atChunk < chunk) {
777
- const text = pieceAt(atChunk);
778
- advanceOver(text, text.length);
779
- atChunk++;
780
- atOffset = 0;
781
- nextNewline = pieceAt(atChunk).indexOf("\n");
782
- }
783
- if (offset > atOffset) advanceOver(pieceAt(atChunk), offset);
784
- };
777
+ // Offset of the next newline at or after the cursor, `-1` for none left.
778
+ // Carried rather than searched for per mapping: `indexOf` has no end bound.
779
+ let nextNewline = text.indexOf("\n");
785
780
  for (const [chunkIndex, chunkOffset, sl, sc] of this._mappings) {
786
781
  // Its piece was taken back, so there is no output left to anchor.
787
782
  if (sl === -1) continue;
788
- advanceTo(chunkIndex, chunkOffset);
783
+ // A piece's length is stored, so summing them costs nothing per byte.
784
+ while (atChunk < chunkIndex) chunkStart += chunks[atChunk++].length;
785
+ const to = chunkStart + chunkOffset;
786
+ if (to > atOffset) {
787
+ while (nextNewline !== -1 && nextNewline < to) {
788
+ atLine++;
789
+ atCol = 0;
790
+ atOffset = nextNewline + 1;
791
+ nextNewline = text.indexOf("\n", atOffset);
792
+ }
793
+ atCol += to - atOffset;
794
+ atOffset = to;
795
+ }
789
796
  const gl = atLine;
790
797
  const gc = atCol;
791
798
  while (genLine < gl) {
@@ -900,7 +907,11 @@ class PrintContext {
900
907
  if (this._insertIdx < this._inserts.length) this._flushBefore(Infinity);
901
908
  // Nothing was ever cut into its own piece, so there is nothing to join.
902
909
  const chunks = this._chunks;
903
- return chunks.length === 0 ? this._tail : chunks.join("") + this._tail;
910
+ if (chunks.length === 0) return this._tail;
911
+ // The tail joins as a piece of its own, so the output comes back flat
912
+ // rather than as a rope over the join that every reader flattens again.
913
+ this._cutTail();
914
+ return chunks.join("");
904
915
  }
905
916
  }
906
917
 
@@ -1003,10 +1014,9 @@ class SourceProcessor {
1003
1014
  this._grammar(input, this._visitors, undefined, opts);
1004
1015
  return undefined;
1005
1016
  }
1006
- // Handed over whole rather than copied entry by entry: which of them are
1007
- // print options is the language's to say, and listing them here is what
1008
- // made every new one an edit to this file. A grammar-only entry riding
1009
- // along is inert — a printer reads only what its own type declares.
1017
+ // Handed over whole rather than copied entry by entry: which entries are
1018
+ // print options is the language's to say, and a grammar-only one riding
1019
+ // along is inert, since a printer reads only what its own type declares.
1010
1020
  const ctx = new PrintContext(
1011
1021
  /** @type {PrintOptions & TPrintOptions} */ (
1012
1022
  /** @type {unknown} */ ({ ...opts, mode: asked })
@@ -1015,16 +1025,21 @@ class SourceProcessor {
1015
1025
  );
1016
1026
  this._grammar(input, this._visitors, ctx, opts);
1017
1027
  const name = /** @type {{ source?: string, content?: string }} */ (opts);
1018
- const build = () => ({
1019
- code: ctx.result(),
1020
- // Built only for a caller that named the input: building one walks the
1021
- // whole output for its line breaks, and the minifier prints an inline
1022
- // `style=""` — which asks for no map — thousands of times a document.
1023
- map:
1024
- name.source === undefined
1025
- ? undefined
1026
- : ctx.sourceMap({ source: name.source, content: name.content })
1027
- });
1028
+ const build = () => {
1029
+ const code = ctx.result();
1030
+ return {
1031
+ code,
1032
+ // Built only for a caller that named the input: a map walks the whole
1033
+ // output, and an inline `style=""` asks for none thousands of times a page.
1034
+ map:
1035
+ name.source === undefined
1036
+ ? undefined
1037
+ : ctx.sourceMap(
1038
+ { source: name.source, content: name.content },
1039
+ code
1040
+ )
1041
+ };
1042
+ };
1028
1043
  if (this._deferred !== null) {
1029
1044
  const finish = this._deferred;
1030
1045
 
@@ -1142,4 +1157,5 @@ class SourceProcessor {
1142
1157
  SourceProcessor.PrintContext = PrintContext;
1143
1158
 
1144
1159
  module.exports = SourceProcessor;
1160
+ module.exports.declineDeferredWrites = declineDeferredWrites;
1145
1161
  module.exports.deferredWrite = deferredWrite;
@@ -17,6 +17,7 @@ const _0CharCode = "0".charCodeAt(0);
17
17
  const _9CharCode = "9".charCodeAt(0);
18
18
  const plusCharCode = "+".charCodeAt(0);
19
19
  const hyphenCharCode = "-".charCodeAt(0);
20
+ const dotCharCode = ".".charCodeAt(0);
20
21
  const colonCharCode = ":".charCodeAt(0);
21
22
  const hashCharCode = "#".charCodeAt(0);
22
23
  const queryCharCode = "?".charCodeAt(0);
@@ -46,7 +47,8 @@ function getScheme(specifier) {
46
47
  (ch >= aUpperCaseCharCode && ch <= zUpperCaseCharCode) ||
47
48
  (ch >= _0CharCode && ch <= _9CharCode) ||
48
49
  ch === plusCharCode ||
49
- ch === hyphenCharCode
50
+ ch === hyphenCharCode ||
51
+ ch === dotCharCode
50
52
  ) {
51
53
  if (++i === specifier.length) return;
52
54
  ch = specifier.charCodeAt(i);