webpack 5.112.0 → 5.112.2

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 (263) hide show
  1. package/bin/webpack.js +13 -7
  2. package/lib/Compilation.js +198 -61
  3. package/lib/Compiler.js +12 -25
  4. package/lib/asset/AssetBytesGenerator.js +14 -6
  5. package/lib/asset/AssetBytesParser.js +10 -8
  6. package/lib/asset/AssetGenerator.js +36 -48
  7. package/lib/asset/AssetModule.js +11 -0
  8. package/lib/asset/AssetModulesPlugin.js +5 -4
  9. package/lib/asset/AssetParser.js +8 -8
  10. package/lib/asset/AssetSourceGenerator.js +16 -8
  11. package/lib/asset/AssetSourceParser.js +10 -8
  12. package/lib/asset/WebManifestGenerator.js +11 -6
  13. package/lib/asset/WebManifestParser.js +3 -3
  14. package/lib/async-modules/AsyncModuleHelpers.js +8 -2
  15. package/lib/async-modules/InferAsyncModulesPlugin.js +7 -2
  16. package/lib/cache/CacheFacade.js +1 -1
  17. package/lib/cache/PackFileCacheStrategy.js +6 -10
  18. package/lib/cache/ResolverCachePlugin.js +58 -8
  19. package/lib/config/WebpackOptionsApply.js +8 -28
  20. package/lib/config/cli.js +9 -6
  21. package/lib/config/defaults.js +24 -13
  22. package/lib/config/getClaimedAssetTypes.js +2 -2
  23. package/lib/config/target.js +1 -1
  24. package/lib/context/ContextModule.js +1 -1
  25. package/lib/context/ContextModuleFactory.js +1 -1
  26. package/lib/context/ContextReplacementPlugin.js +3 -9
  27. package/lib/css/CssGenerator.js +40 -47
  28. package/lib/css/CssModule.js +10 -0
  29. package/lib/css/CssModulesPlugin.js +13 -6
  30. package/lib/css/CssParser.js +33 -32
  31. package/lib/css/conventions.js +1 -1
  32. package/lib/css/data.js +224 -219
  33. package/lib/css/syntax-parser.js +1312 -312
  34. package/lib/css/syntax-printer.js +1142 -1025
  35. package/lib/debug/ProfilingPlugin.js +65 -43
  36. package/lib/define/DefinePlugin.js +10 -15
  37. package/lib/define/DotenvPlugin.js +10 -6
  38. package/lib/define/EnvironmentPlugin.js +4 -2
  39. package/lib/dependencies/amd/AMDDefineDependencyParserPlugin.js +1 -2
  40. package/lib/dependencies/amd/AMDRequireDependenciesBlockParserPlugin.js +4 -1
  41. package/lib/dependencies/commonjs/CommonJsExportRequireDependency.js +1 -4
  42. package/lib/dependencies/commonjs/CommonJsExportsParserPlugin.js +18 -33
  43. package/lib/dependencies/commonjs/CommonJsImportsParserPlugin.js +1 -3
  44. package/lib/dependencies/commonjs/CommonJsObjectExportDependency.js +4 -4
  45. package/lib/dependencies/commonjs/CommonJsPlugin.js +2 -5
  46. package/lib/dependencies/commonjs/RequireEnsureDependenciesBlockParserPlugin.js +4 -1
  47. package/lib/dependencies/context/ImportMetaContextDependencyParserPlugin.js +1 -2
  48. package/lib/dependencies/context/ImportMetaGlobDependencyParserPlugin.js +4 -7
  49. package/lib/dependencies/context/ImportMetaGlobHelpers.js +8 -10
  50. package/lib/dependencies/core/CachedConstDependency.js +9 -6
  51. package/lib/dependencies/css/CssIcssExportDependency.js +6 -7
  52. package/lib/dependencies/css/CssIcssImportDependency.js +1 -3
  53. package/lib/dependencies/css/CssUrlDependency.js +2 -6
  54. package/lib/dependencies/esm/ESMDetectionParserPlugin.js +2 -4
  55. package/lib/dependencies/esm/ESMExportExpressionDependency.js +2 -2
  56. package/lib/dependencies/esm/ESMExportImportedSpecifierDependency.js +16 -18
  57. package/lib/dependencies/esm/ESMExportSpecifierDependency.js +20 -3
  58. package/lib/dependencies/esm/ESMExports.js +2 -10
  59. package/lib/dependencies/esm/ESMImportDependency.js +17 -2
  60. package/lib/dependencies/esm/ESMImportDependencyParserPlugin.js +6 -17
  61. package/lib/dependencies/esm/ESMImportGuard.js +11 -23
  62. package/lib/dependencies/esm/ESMImportSideEffectDependency.js +1 -1
  63. package/lib/dependencies/esm/ESMImportSpecifierDependency.js +4 -1
  64. package/lib/dependencies/esm/ESMLiveExportDependency.js +311 -0
  65. package/lib/dependencies/esm/ESMLiveExportParserPlugin.js +862 -0
  66. package/lib/dependencies/esm/ESMModulesPlugin.js +1 -3
  67. package/lib/dependencies/esm/TopLevelAwaitDependency.js +1 -8
  68. package/lib/dependencies/helpers/DynamicExports.js +4 -6
  69. package/lib/dependencies/html/HtmlEntryDependency.js +5 -14
  70. package/lib/dependencies/html/HtmlInlineHtmlDependency.js +1 -4
  71. package/lib/dependencies/html/HtmlInlineScriptDependency.js +2 -6
  72. package/lib/dependencies/html/HtmlInlineStyleDependency.js +1 -4
  73. package/lib/dependencies/import/ImportParserPlugin.js +3 -6
  74. package/lib/dependencies/import-meta/ImportMetaPlugin.js +4 -6
  75. package/lib/dependencies/url/URLParserPlugin.js +1 -1
  76. package/lib/dependencies/worker/WorkerAndWorkletPlugin.js +51 -20
  77. package/lib/devtool/ModuleFilenameHelpers.js +1 -1
  78. package/lib/devtool/SourceMapDevToolPlugin.js +1 -1
  79. package/lib/dll/DelegatedModule.js +3 -3
  80. package/lib/dll/DllModule.js +3 -1
  81. package/lib/dll/DllReferencePlugin.js +1 -4
  82. package/lib/errors/AbstractMethodError.js +1 -1
  83. package/lib/errors/ErrorHelpers.js +2 -1
  84. package/lib/errors/HookWebpackError.js +2 -1
  85. package/lib/errors/JSONParseError.js +4 -4
  86. package/lib/errors/WebpackError.js +3 -2
  87. package/lib/esm/ModuleChunkFormatPlugin.js +36 -1
  88. package/lib/externals/ExternalModule.js +12 -9
  89. package/lib/externals/ExternalModuleFactoryPlugin.js +1 -2
  90. package/lib/externals/ExternalsPlugin.js +1 -1
  91. package/lib/fs/FileSystemInfo.js +4 -4
  92. package/lib/graph/AsyncDependenciesBlock.js +1 -1
  93. package/lib/graph/ChunkGraph.js +5 -0
  94. package/lib/graph/Dependency.js +8 -2
  95. package/lib/graph/ExportsInfo.js +1 -1
  96. package/lib/graph/ModuleGraph.js +14 -3
  97. package/lib/graph/buildChunkGraph.js +17 -19
  98. package/lib/graph/findGraphRoots.js +1 -1
  99. package/lib/hmr/HotModuleReplacement.runtime.js +10 -9
  100. package/lib/hmr/HotModuleReplacementPlugin.js +5 -11
  101. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +16 -19
  102. package/lib/hmr/LazyCompilationPlugin.js +1 -7
  103. package/lib/html/HtmlGenerator.js +25 -17
  104. package/lib/html/HtmlModule.js +11 -1
  105. package/lib/html/HtmlModulesPlugin.js +12 -11
  106. package/lib/html/HtmlParser.js +10 -9
  107. package/lib/html/builtinEmbeddedRenderer.js +31 -33
  108. package/lib/html/data.js +42 -21
  109. package/lib/html/htmlMinify.js +4 -1
  110. package/lib/html/syntax-parser.js +34 -35
  111. package/lib/html/syntax-printer.js +2 -3
  112. package/lib/html/xmlMinify.js +4 -1
  113. package/lib/ids/HashedModuleIdsPlugin.js +1 -1
  114. package/lib/index.js +13 -12
  115. package/lib/javascript/APIPlugin.js +7 -13
  116. package/lib/javascript/BasicEvaluatedExpression.js +5 -5
  117. package/lib/javascript/CommonJsChunkFormatPlugin.js +2 -7
  118. package/lib/javascript/ConstPlugin.js +1 -1
  119. package/lib/javascript/JavascriptGenerator.js +16 -11
  120. package/lib/javascript/JavascriptMetaInfoPlugin.js +3 -15
  121. package/lib/javascript/JavascriptModule.js +10 -0
  122. package/lib/javascript/JavascriptModulesPlugin.js +2 -4
  123. package/lib/javascript/JavascriptParser.js +99 -11
  124. package/lib/javascript/ScopeAnalyzer.js +183 -107
  125. package/lib/javascript/UseStrictPlugin.js +2 -5
  126. package/lib/javascript/jsMinify.js +1 -1
  127. package/lib/javascript/regexp.js +2 -2
  128. package/lib/javascript/syntax-parser.js +2114 -1506
  129. package/lib/javascript/syntax-printer-data.js +167 -1
  130. package/lib/javascript/syntax-printer.js +9554 -2782
  131. package/lib/json/JsonGenerator.js +15 -7
  132. package/lib/json/JsonModule.js +11 -0
  133. package/lib/json/JsonParser.js +7 -6
  134. package/lib/library/AssignLibraryPlugin.js +1 -1
  135. package/lib/library/JsonpLibraryPlugin.js +1 -1
  136. package/lib/library/ModuleLibraryPlugin.js +399 -23
  137. package/lib/loaders/LoaderRunner.js +76 -38
  138. package/lib/loaders/loadLoader.js +16 -10
  139. package/lib/module/Generator.js +17 -9
  140. package/lib/module/Module.js +2 -2
  141. package/lib/module/NormalModule.js +7 -5
  142. package/lib/module/NormalModuleFactory.js +11 -17
  143. package/lib/module/Parser.js +9 -2
  144. package/lib/module/extractSourceMap.js +69 -18
  145. package/lib/module/findCaseMismatch.js +2 -2
  146. package/lib/node/ExternalModuleInitFragment.js +2 -2
  147. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +4 -12
  148. package/lib/node/ReadFileCompileWasmPlugin.js +2 -6
  149. package/lib/node/nodeConsole.js +4 -3
  150. package/lib/optimize/CircularModulesPlugin.js +1 -1
  151. package/lib/optimize/ConcatenatedModule.js +4 -8
  152. package/lib/optimize/FlagDependencyExportsPlugin.js +6 -11
  153. package/lib/optimize/FlagDependencyUsagePlugin.js +28 -3
  154. package/lib/optimize/InlineExports.js +4 -7
  155. package/lib/optimize/LazyBarrels.js +41 -5
  156. package/lib/optimize/ModuleConcatenationPlugin.js +8 -10
  157. package/lib/optimize/RealContentHashPlugin.js +2 -6
  158. package/lib/optimize/SideEffectsFlagPlugin.js +7 -21
  159. package/lib/optimize/SplitChunksPlugin.js +11 -24
  160. package/lib/optimize/TupleQueue.js +1 -1
  161. package/lib/output/CleanPlugin.js +3 -1
  162. package/lib/output/CopyPlugin.js +3 -4
  163. package/lib/performance/EvalUsagePlugin.js +1 -3
  164. package/lib/performance/HotspotsPlugin.js +33 -9
  165. package/lib/performance/PureAnnotationsPlugin.js +16 -10
  166. package/lib/performance/TopLevelThisPlugin.js +17 -9
  167. package/lib/prefetch/ResourceHintPlugin.js +1 -1
  168. package/lib/provide/ProvidedDependency.js +36 -4
  169. package/lib/rules/BasicEffectRulePlugin.js +1 -1
  170. package/lib/rules/RuleSetCompiler.js +15 -5
  171. package/lib/rules/UseEffectRulePlugin.js +1 -3
  172. package/lib/runtime/AsyncModuleRuntimeModule.js +7 -1
  173. package/lib/runtime/GetChunkFilenameRuntimeModule.js +1 -5
  174. package/lib/runtime/RuntimeGlobals.js +6 -0
  175. package/lib/runtime/RuntimePlugin.js +2 -0
  176. package/lib/schemes/HttpUriPlugin.js +1 -2
  177. package/lib/schemes/VirtualUrlPlugin.js +3 -1
  178. package/lib/serialization/AggregateErrorSerializer.js +3 -3
  179. package/lib/serialization/BinaryMiddleware.js +4 -1
  180. package/lib/serialization/ErrorObjectSerializer.js +2 -5
  181. package/lib/serialization/ObjectMiddleware.js +17 -15
  182. package/lib/serialization/PlainObjectSerializer.js +3 -7
  183. package/lib/serialization/Serializer.js +21 -11
  184. package/lib/serialization/SerializerMiddleware.js +8 -6
  185. package/lib/stats/DefaultStatsFactoryPlugin.js +35 -35
  186. package/lib/stats/DefaultStatsPresetPlugin.js +2 -6
  187. package/lib/stats/DefaultStatsPrinterPlugin.js +12 -11
  188. package/lib/stats/StatsFactory.js +194 -24
  189. package/lib/stats/StatsPrinter.js +126 -13
  190. package/lib/template/DependencyTemplate.js +1 -1
  191. package/lib/template/RuntimeTemplate.js +13 -32
  192. package/lib/template/Template.js +1 -1
  193. package/lib/util/SourceProcessor.js +146 -29
  194. package/lib/util/WeakTupleMap.js +10 -4
  195. package/lib/util/cleverMerge.js +61 -33
  196. package/lib/util/comparators.js +9 -5
  197. package/lib/util/dataURL.js +2 -0
  198. package/lib/util/deprecation.js +4 -3
  199. package/lib/util/globUtils.js +1 -4
  200. package/lib/util/internalSerializables.js +2 -0
  201. package/lib/util/makeSerializable.js +6 -4
  202. package/lib/util/memoize.js +1 -1
  203. package/lib/util/parseJson.js +2 -2
  204. package/lib/util/serialization.js +31 -27
  205. package/lib/wasm/AsyncWasmModule.js +12 -2
  206. package/lib/wasm/AsyncWebAssemblyGenerator.js +12 -4
  207. package/lib/wasm/AsyncWebAssemblyJavascriptGenerator.js +13 -5
  208. package/lib/wasm/AsyncWebAssemblyParser.js +7 -5
  209. package/lib/wasm/UniversalCompileAsyncWasmPlugin.js +2 -6
  210. package/lib/wasm-sync/SyncWasmModule.js +16 -1
  211. package/lib/wasm-sync/WebAssemblyGenerator.js +15 -10
  212. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +13 -5
  213. package/lib/wasm-sync/WebAssemblyParser.js +10 -12
  214. package/lib/web/FetchCompileAsyncWasmPlugin.js +4 -12
  215. package/lib/web/FetchCompileWasmPlugin.js +2 -6
  216. package/package.json +18 -19
  217. package/schemas/WebpackOptions.check.js +3 -3
  218. package/schemas/WebpackOptions.json +2 -2
  219. package/schemas/plugins/BannerPlugin.check.js +3 -3
  220. package/schemas/plugins/HtmlGeneratorOptions.check.js +3 -3
  221. package/schemas/plugins/HtmlParserOptions.check.js +3 -3
  222. package/schemas/plugins/IgnorePlugin.check.js +3 -3
  223. package/schemas/plugins/LoaderOptionsPlugin.check.js +3 -3
  224. package/schemas/plugins/ManifestPlugin.check.js +3 -3
  225. package/schemas/plugins/ProgressPlugin.check.js +3 -3
  226. package/schemas/plugins/SSRManifestPlugin.check.js +3 -3
  227. package/schemas/plugins/SourceMapDevToolPlugin.check.js +3 -3
  228. package/schemas/plugins/WatchIgnorePlugin.check.js +3 -3
  229. package/schemas/plugins/asset/AssetGeneratorOptions.check.js +3 -3
  230. package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.js +3 -3
  231. package/schemas/plugins/asset/AssetParserOptions.check.js +3 -3
  232. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +3 -3
  233. package/schemas/plugins/container/ContainerPlugin.check.js +3 -3
  234. package/schemas/plugins/container/ContainerReferencePlugin.check.js +3 -3
  235. package/schemas/plugins/container/ExternalsType.check.js +3 -3
  236. package/schemas/plugins/container/ModuleFederationPlugin.check.js +3 -3
  237. package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.js +3 -3
  238. package/schemas/plugins/css/CssGeneratorOptions.check.js +3 -3
  239. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +3 -3
  240. package/schemas/plugins/css/CssModuleParserOptions.check.js +3 -3
  241. package/schemas/plugins/css/CssParserOptions.check.js +3 -3
  242. package/schemas/plugins/debug/ProfilingPlugin.check.js +3 -3
  243. package/schemas/plugins/define/DotenvPluginOptions.check.js +7 -0
  244. package/schemas/plugins/define/DotenvPluginOptions.json +3 -0
  245. package/schemas/plugins/dll/DllPlugin.check.js +3 -3
  246. package/schemas/plugins/dll/DllReferencePlugin.check.js +3 -3
  247. package/schemas/plugins/ids/HashedModuleIdsPlugin.check.js +3 -3
  248. package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.check.js +3 -3
  249. package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.check.js +3 -3
  250. package/schemas/plugins/json/JsonModulesPluginGenerator.check.js +3 -3
  251. package/schemas/plugins/json/JsonModulesPluginParser.check.js +3 -3
  252. package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +3 -3
  253. package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +3 -3
  254. package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.js +3 -3
  255. package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +3 -3
  256. package/schemas/plugins/output/CleanOptions.check.js +7 -0
  257. package/schemas/plugins/output/CleanOptions.json +3 -0
  258. package/schemas/plugins/schemes/HttpUriPlugin.check.js +3 -3
  259. package/schemas/plugins/schemes/VirtualUrlPlugin.check.js +3 -3
  260. package/schemas/plugins/sharing/ConsumeSharedPlugin.check.js +3 -3
  261. package/schemas/plugins/sharing/ProvideSharedPlugin.check.js +3 -3
  262. package/schemas/plugins/sharing/SharePlugin.check.js +3 -3
  263. package/types.d.ts +1482 -358
@@ -414,11 +414,11 @@ function getGlobalObject(definition) {
414
414
 
415
415
  if (
416
416
  // identifier, we do not need real identifier regarding ECMAScript/Unicode
417
- /^[_\p{L}][_0-9\p{L}]*$/iu.test(trimmed) ||
417
+ /^[_\p{L}][_0-9\p{L}]*$/u.test(trimmed) ||
418
418
  // iife
419
419
  // call expression
420
420
  // expression in parentheses
421
- /^(?:[_\p{L}][_0-9\p{L}]*)?\(.*\)$/iu.test(trimmed)
421
+ /^(?:[_\p{L}][_0-9\p{L}]*)?\(.*\)$/u.test(trimmed)
422
422
  ) {
423
423
  return trimmed;
424
424
  }
@@ -1386,7 +1386,7 @@ class RuntimeTemplate {
1386
1386
  const spellable =
1387
1387
  this._getAnalyzableFileSpecifier(
1388
1388
  module,
1389
- /** @type {ChunkGraph} */ (chunkGraph),
1389
+ chunkGraph,
1390
1390
  [["literal", "x"]],
1391
1391
  true
1392
1392
  ) !== null;
@@ -2888,7 +2888,7 @@ class RuntimeTemplate {
2888
2888
  * @returns {boolean} true when the hash exists by the time the target is hashed
2889
2889
  */
2890
2890
  _hashRoundBefore(chunk, target) {
2891
- const chunkGraph = /** @type {ChunkGraph} */ (this.compilation.chunkGraph);
2891
+ const chunkGraph = this.compilation.chunkGraph;
2892
2892
  const round = hashRound(chunk, chunkGraph);
2893
2893
  const targetRound = hashRound(target, chunkGraph);
2894
2894
  if (round !== targetRound) return round < targetRound;
@@ -2956,8 +2956,7 @@ class RuntimeTemplate {
2956
2956
  */
2957
2957
  _settlesLate(chunk) {
2958
2958
  return (
2959
- /** @type {ChunkGraph} */
2960
- (this.compilation.chunkGraph).getChunkFullHashModulesIterable(chunk) !==
2959
+ this.compilation.chunkGraph.getChunkFullHashModulesIterable(chunk) !==
2961
2960
  undefined
2962
2961
  );
2963
2962
  }
@@ -2989,7 +2988,7 @@ class RuntimeTemplate {
2989
2988
  _markChunksSettlingLate() {
2990
2989
  this._chunksBakingFullHash = new Set();
2991
2990
  const { compilation } = this;
2992
- const chunkGraph = /** @type {ChunkGraph} */ (compilation.chunkGraph);
2991
+ const chunkGraph = compilation.chunkGraph;
2993
2992
  const results = compilation.codeGenerationResults;
2994
2993
  if (results === undefined) return;
2995
2994
  /** @type {Map<Chunk, Set<string>>} */
@@ -3234,11 +3233,7 @@ class RuntimeTemplate {
3234
3233
  const undo =
3235
3234
  shape === undefined
3236
3235
  ? null
3237
- : getUndoPath(
3238
- `${shape}x`,
3239
- /** @type {string} */ (this.outputOptions.path),
3240
- true
3241
- );
3236
+ : getUndoPath(`${shape}x`, this.outputOptions.path, true);
3242
3237
  this._publicPathClimbText = undo === "./" ? "" : undo;
3243
3238
  }
3244
3239
  return this._publicPathClimbText;
@@ -3273,11 +3268,7 @@ class RuntimeTemplate {
3273
3268
  undo:
3274
3269
  chunkName === null
3275
3270
  ? null
3276
- : getUndoPath(
3277
- chunkName,
3278
- /** @type {string} */ (outputOptions.path),
3279
- true
3280
- ),
3271
+ : getUndoPath(chunkName, outputOptions.path, true),
3281
3272
  // A chunk in an initial group and an async one both is served at two urls,
3282
3273
  // one public path apart, so no one literal in it is right for both.
3283
3274
  loaded: chunk.isOnlyInitial() ? false : chunk.canBeInitial() ? null : true
@@ -3338,11 +3329,7 @@ class RuntimeTemplate {
3338
3329
  : shape,
3339
3330
  { chunk, contentHashType: JAVASCRIPT_TYPE }
3340
3331
  );
3341
- return getUndoPath(
3342
- name,
3343
- /** @type {string} */ (this.outputOptions.path),
3344
- enforceRelative
3345
- );
3332
+ return getUndoPath(name, this.outputOptions.path, enforceRelative);
3346
3333
  }
3347
3334
 
3348
3335
  /**
@@ -3495,7 +3482,7 @@ class RuntimeTemplate {
3495
3482
  const filename =
3496
3483
  deferred && !settled
3497
3484
  ? ""
3498
- : compilation.getPath(/** @type {string} */ (template), {
3485
+ : compilation.getPath(template, {
3499
3486
  chunk,
3500
3487
  // Matches what names the asset, or a placeholder resolved here would
3501
3488
  // not be the one on disk.
@@ -4113,7 +4100,7 @@ class RuntimeTemplate {
4113
4100
  }
4114
4101
  const undo = getUndoPath(
4115
4102
  this.compilation.getPath(this._hotUpdateShapeText, { chunk }),
4116
- /** @type {string} */ (outputOptions.path),
4103
+ outputOptions.path,
4117
4104
  true
4118
4105
  );
4119
4106
  this._hotUpdateUndoByChunk.set(chunk, undo);
@@ -4131,9 +4118,7 @@ class RuntimeTemplate {
4131
4118
  */
4132
4119
  getAnalyzableWasmUrl(module, chunkGraph, runtime, runtimeRequirements) {
4133
4120
  const { compilation } = this;
4134
- const template = /** @type {string} */ (
4135
- this.outputOptions.webassemblyModuleFilename
4136
- );
4121
+ const template = this.outputOptions.webassemblyModuleFilename;
4137
4122
  // The module's own hash and id are settled here, the compilation's is not — and
4138
4123
  // a placeholder nothing answers is left in the name, so what comes back is either
4139
4124
  // the final name or a template carrying only `[fullhash]`.
@@ -4500,11 +4485,7 @@ class RuntimeTemplate {
4500
4485
  } else if (kind === "literal") {
4501
4486
  specifier += value;
4502
4487
  } else if (kind === "undo") {
4503
- specifier += getUndoPath(
4504
- assetName,
4505
- /** @type {string} */ (outputOptions.path),
4506
- true
4507
- );
4488
+ specifier += getUndoPath(assetName, outputOptions.path, true);
4508
4489
  } else if (kind === "template") {
4509
4490
  specifier += compilation.getPath(
4510
4491
  /** @type {string} */ (value),
@@ -53,7 +53,7 @@ const LINE_SEPARATOR_REGEX = /\r?\n/g;
53
53
  const IDENTIFIER_NAME_REPLACE_REGEX = /^([^a-z$_])/i;
54
54
  const IDENTIFIER_ALPHA_NUMERIC_NAME_REPLACE_REGEX = /[^a-z0-9$]+/gi;
55
55
  const COMMENT_END_REGEX = /\*\//g;
56
- const PATH_NAME_NORMALIZE_REPLACE_REGEX = /[^a-z0-9_!§$()=\-^°]+/gi;
56
+ const PATH_NAME_NORMALIZE_REPLACE_REGEX = /[^a-zA-Z0-9_!§$()=\-^°]+/g;
57
57
  const MATCH_PADDED_HYPHENS_REPLACE_REGEX = /^-|-$/g;
58
58
 
59
59
  /**
@@ -186,11 +186,11 @@ const declineDeferredWrites = (text, writes) =>
186
186
  */
187
187
  /**
188
188
  * What part `M` gives the node type `R` says it is; every part `D` when `R`
189
- * says none (a plain node reads `unknown` there).
189
+ * says none (a plain node reads `number` there).
190
190
  * @template R
191
191
  * @template {Record<number, number>} M
192
192
  * @template D
193
- * @typedef {number extends (R & { readonly __nodeType: unknown })["__nodeType"] ? D : M[(R & { readonly __nodeType: unknown })["__nodeType"] & number]} PartOf
193
+ * @typedef {number extends (R & { readonly __nodeType: number })["__nodeType"] ? D : M[(R & { readonly __nodeType: number })["__nodeType"]]} PartOf
194
194
  */
195
195
  /**
196
196
  * A language's parts, by node type: what its `Field`s and `Flag`s apply to.
@@ -281,7 +281,10 @@ const declineDeferredWrites = (text, writes) =>
281
281
  const deferredKey = (offer) => {
282
282
  let key = "";
283
283
  for (const name of Object.keys(offer).sort()) {
284
- const value = /** @type {Record<string, unknown>} */ (offer)[name];
284
+ const value =
285
+ /** @type {Record<string, DeferredWrite[keyof DeferredWrite]>} */ (offer)[
286
+ name
287
+ ];
285
288
  if (typeof value !== "function") key += `${name}\0${value}\0`;
286
289
  }
287
290
  return key;
@@ -332,7 +335,7 @@ const FLATTEN_BLOCK = 64 * 1024;
332
335
 
333
336
  // Most prints do not ask for a source map. Sharing their permanently empty
334
337
  // mapping column avoids allocating an array for every inline CSS/HTML body.
335
- /** @type {[number, number, number, number][]} */
338
+ /** @type {number[]} */
336
339
  const EMPTY_MAPPINGS = [];
337
340
 
338
341
  // Base64 VLQ, the source-map `mappings` encoding. Hand-rolled so producing a map
@@ -344,6 +347,28 @@ const _B64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
344
347
  * @returns {string} its Base64 VLQ encoding
345
348
  */
346
349
  const _vlq = (n) => {
350
+ // Most deltas are small, and each is spelled the same every time.
351
+ if (n > -_VLQ_CACHED && n < _VLQ_CACHED) {
352
+ if (_vlqCache === null) _vlqCache = Array.from({ length: _VLQ_CACHED * 2 });
353
+ const cached = _vlqCache[n + _VLQ_CACHED];
354
+ if (cached !== undefined) return cached;
355
+ return (_vlqCache[n + _VLQ_CACHED] = _encodeVlq(n));
356
+ }
357
+ return _encodeVlq(n);
358
+ };
359
+
360
+ // `_vlq` of every delta within this of zero, filled in as they are written,
361
+ // and made only once a map is.
362
+ const _VLQ_CACHED = 1024;
363
+ /** @type {(string | undefined)[] | null} */
364
+ let _vlqCache = null;
365
+
366
+ /**
367
+ * One value as a Base64 VLQ, spelled out.
368
+ * @param {number} n the value
369
+ * @returns {string} its VLQ
370
+ */
371
+ const _encodeVlq = (n) => {
347
372
  let v = n < 0 ? (-n << 1) | 1 : n << 1;
348
373
  let out = "";
349
374
  do {
@@ -402,10 +427,13 @@ class PrintContext {
402
427
  this._printer = printer;
403
428
  // Printed text by node handle, in two columns rather than one `Map`: the
404
429
  // handles are dense integers, and `_moveEpoch` keeps the live set small.
405
- /** @type {string[]} each finished node's printed text */
430
+ /** @type {(string | null)[]} each finished node's printed text */
406
431
  this._storeText = [];
407
432
  /** @type {Int32Array} the epoch each slot was written in */
408
433
  this._storeGen = new Int32Array(0);
434
+ // A slot holding `null` prints as its source, read only once asked for.
435
+ /** @type {((node: TNode) => string) | undefined} reads a `null` slot's text */
436
+ this._sourceText = undefined;
409
437
  /** @type {number} current epoch; a slot from an older one reads as absent */
410
438
  this._gen = 1;
411
439
  /** @type {number} lowest slot written since the epoch last moved */
@@ -417,6 +445,8 @@ class PrintContext {
417
445
  // for retractable text alone, so no other emit pays for that ability.
418
446
  /** @type {string[]} pieces already cut off, in output order */
419
447
  this._chunks = [];
448
+ /** @type {Map<number, { readonly text: string }> | null} pieces whose text is read only once the output is */
449
+ this._deferred = null;
420
450
  /** @type {string} output after the last cut piece */
421
451
  this._tail = "";
422
452
  /** @type {number} characters in `_tail`, so its length is not read off a rope */
@@ -428,9 +458,11 @@ class PrintContext {
428
458
  /** @type {boolean} whether {@link sourceMap} can still be asked for one */
429
459
  this.mapWanted =
430
460
  /** @type {{ source?: string }} */ (options).source !== undefined;
431
- /** @type {[number, number, number, number][]} `[chunkIndex, offsetInChunk, srcLine, srcCol]`, output-ordered; a `srcLine` of -1 is one {@link retract} took back with its piece */
461
+ // Flat rather than one array per mapping: a stylesheet anchors every rule,
462
+ // and those arrays live as long as the print does.
463
+ /** @type {number[]} `chunkIndex, offsetInChunk, srcLine, srcCol` per mapping, output-ordered; a `srcLine` of -1 is one {@link retract} took back with its piece */
432
464
  this._mappings = this.mapWanted ? [] : EMPTY_MAPPINGS;
433
- /** @type {number[] | null} by retractable piece index, the mapping anchored to it, so taking the piece back takes its mapping too */
465
+ /** @type {number[] | null} by retractable piece index, the index in `_mappings` of the mapping anchored to it, so taking the piece back takes its mapping too */
434
466
  this._retractableMappings = null;
435
467
  /** @type {[number, string][]} source-anchored literals to keep (comments), source-ordered */
436
468
  this._inserts = [];
@@ -593,6 +625,7 @@ class PrintContext {
593
625
  * @param {number} charCode the character to drop
594
626
  */
595
627
  dropTrailing(from, charCode) {
628
+ this._settleDeferred();
596
629
  const chunks = this._chunks;
597
630
  for (let i = chunks.length; i >= from; i--) {
598
631
  let text = i === chunks.length ? this._tail : chunks[i];
@@ -622,6 +655,7 @@ class PrintContext {
622
655
  * @returns {boolean} true when the output ended that way and was rewritten
623
656
  */
624
657
  replaceEnd(printed, text, closer) {
658
+ this._settleDeferred();
625
659
  this._cutTail();
626
660
  const chunks = this._chunks;
627
661
  // Joined once: this runs only where a value ran into the end of the input.
@@ -641,9 +675,14 @@ class PrintContext {
641
675
  remove -= chunks[i].length - kept;
642
676
  chunks[i] = chunks[i].slice(0, kept);
643
677
  // A mapping into what went would point past its piece.
644
- this._mappings = this._mappings.filter(
645
- ([chunk, offset]) => chunk !== i || offset <= kept
646
- );
678
+ const mappings = this._mappings;
679
+ let to = 0;
680
+ for (let at = 0; at < mappings.length; at += 4) {
681
+ if (mappings[at] === i && mappings[at + 1] > kept) continue;
682
+ for (let k = 0; k < 4; k++) mappings[to + k] = mappings[at + k];
683
+ to += 4;
684
+ }
685
+ mappings.length = to;
647
686
  }
648
687
  this._emit(text);
649
688
  return true;
@@ -656,7 +695,16 @@ class PrintContext {
656
695
  * @param {TPath} path the language accessor, positioned on `node`
657
696
  */
658
697
  printNode(node, path) {
659
- const text = this._printer(path, this);
698
+ this.printedAs(node, this._printer(path, this));
699
+ }
700
+
701
+ /**
702
+ * Store `text` as what `node` printed, where the grammar already knows what
703
+ * the node printer would return and so does not call it.
704
+ * @param {TNode} node the finished node
705
+ * @param {string} text its printed text
706
+ */
707
+ printedAs(node, text) {
660
708
  const n = /** @type {number} */ (node);
661
709
  if (n >= this._storeText.length) this._growStore(n + 1);
662
710
  this._storeText[n] = text;
@@ -665,6 +713,22 @@ class PrintContext {
665
713
  if (n > this._storeHigh) this._storeHigh = n;
666
714
  }
667
715
 
716
+ /**
717
+ * Store that `node` printed as its source, which `sourceText` reads only once
718
+ * something asks for its text.
719
+ * @param {TNode} node the finished node
720
+ * @param {(node: TNode) => string} sourceText reads a node's source
721
+ */
722
+ printedSource(node, sourceText) {
723
+ const n = /** @type {number} */ (node);
724
+ if (n >= this._storeText.length) this._growStore(n + 1);
725
+ this._sourceText = sourceText;
726
+ this._storeText[n] = null;
727
+ this._storeGen[n] = this._gen;
728
+ if (n < this._storeLow) this._storeLow = n;
729
+ if (n > this._storeHigh) this._storeHigh = n;
730
+ }
731
+
668
732
  /**
669
733
  * Print one node and hand its text straight back — for a node inside one being
670
734
  * printed in pieces, whose text is emitted as it is printed, so the store
@@ -682,9 +746,16 @@ class PrintContext {
682
746
  */
683
747
  get(node) {
684
748
  const n = /** @type {number} */ (node);
685
- return /** @type {string} */ (
686
- this._storeGen[n] === this._gen ? this._storeText[n] : undefined
749
+ if (this._storeGen[n] !== this._gen) {
750
+ return /** @type {string} */ (/** @type {unknown} */ (undefined));
751
+ }
752
+ const text = this._storeText[n];
753
+ if (text !== null) return text;
754
+ const source = /** @type {(node: TNode) => string} */ (this._sourceText)(
755
+ node
687
756
  );
757
+ this._storeText[n] = source;
758
+ return source;
688
759
  }
689
760
 
690
761
  /**
@@ -742,10 +813,11 @@ class PrintContext {
742
813
  * @param {number} index the piece's index, from {@link emitRetractable}
743
814
  */
744
815
  retract(index) {
816
+ if (this._deferred !== null) this._deferred.delete(index);
745
817
  this._chunks[index] = "";
746
818
  if (this._retractableMappings === null) return;
747
819
  const mapping = this._retractableMappings[index];
748
- if (mapping !== undefined) this._mappings[mapping][2] = -1;
820
+ if (mapping !== undefined) this._mappings[mapping + 2] = -1;
749
821
  }
750
822
 
751
823
  /**
@@ -755,6 +827,7 @@ class PrintContext {
755
827
  * @returns {boolean} true when it does
756
828
  */
757
829
  writesNonAscii(index) {
830
+ this._settleDeferred();
758
831
  const chunks = this._chunks;
759
832
  for (let i = index + 1; i < chunks.length; i++) {
760
833
  if (NON_ASCII_RE.test(chunks[i])) return true;
@@ -776,6 +849,7 @@ class PrintContext {
776
849
  * @param {string} text what to fold in, its own closer included
777
850
  */
778
851
  foldIntoRetractable(index, text) {
852
+ this._settleDeferred();
779
853
  const piece = this._chunks[index];
780
854
  this._chunks[index] = `${piece.slice(0, -1)}${text}`;
781
855
  }
@@ -788,9 +862,31 @@ class PrintContext {
788
862
  * @param {string} text what the piece says now
789
863
  */
790
864
  rewriteRetractable(index, text) {
865
+ if (this._deferred !== null) this._deferred.delete(index);
791
866
  this._chunks[index] = text;
792
867
  }
793
868
 
869
+ /**
870
+ * {@link rewriteRetractable} with text that is asked for only once the output
871
+ * is read: a piece rewritten many times over is then built once, not each time.
872
+ * @param {number} index the piece's index, from {@link emitRetractable}
873
+ * @param {{ readonly text: string }} source what holds the piece's text
874
+ */
875
+ deferRetractable(index, source) {
876
+ if (this._deferred === null) this._deferred = new Map();
877
+ this._deferred.set(index, source);
878
+ }
879
+
880
+ /**
881
+ * Write every deferred piece's text in, before anything reads the pieces.
882
+ */
883
+ _settleDeferred() {
884
+ const deferred = this._deferred;
885
+ if (deferred === null) return;
886
+ this._deferred = null;
887
+ for (const [index, source] of deferred) this._chunks[index] = source.text;
888
+ }
889
+
794
890
  /**
795
891
  * {@link take} for a top-level node a later sibling may still make dead — the
796
892
  * unprefixed twin of a vendor-prefixed rule, which can stand anywhere after
@@ -856,12 +952,12 @@ class PrintContext {
856
952
  if (srcLine !== undefined && this.mapWanted) {
857
953
  // `_chunks.length` is where the tail will land once it is cut off, so
858
954
  // this stays right whether or not a piece is cut after it.
859
- this._mappings.push([
955
+ this._mappings.push(
860
956
  this._chunks.length,
861
957
  this._tailLength,
862
958
  srcLine,
863
959
  /** @type {number} */ (srcCol)
864
- ]);
960
+ );
865
961
  }
866
962
  }
867
963
 
@@ -953,6 +1049,7 @@ class PrintContext {
953
1049
  * @returns {SourceMap} the input->output source map
954
1050
  */
955
1051
  sourceMap(options, code) {
1052
+ this._settleDeferred();
956
1053
  let out = "";
957
1054
  let genLine = 0;
958
1055
  let genCol = 0;
@@ -971,7 +1068,12 @@ class PrintContext {
971
1068
  // Offset of the next newline at or after the cursor, `-1` for none left.
972
1069
  // Carried rather than searched for per mapping: `indexOf` has no end bound.
973
1070
  let nextNewline = text.indexOf("\n");
974
- for (const [chunkIndex, chunkOffset, sl, sc] of this._mappings) {
1071
+ const mappings = this._mappings;
1072
+ for (let at = 0; at < mappings.length; at += 4) {
1073
+ const chunkIndex = mappings[at];
1074
+ const chunkOffset = mappings[at + 1];
1075
+ const sl = mappings[at + 2];
1076
+ const sc = mappings[at + 3];
975
1077
  // Its piece was taken back, so there is no output left to anchor.
976
1078
  if (sl === -1) continue;
977
1079
  // A piece's length is stored, so summing them costs nothing per byte.
@@ -1024,6 +1126,7 @@ class PrintContext {
1024
1126
  * @returns {void}
1025
1127
  */
1026
1128
  substitute(resolve, infix) {
1129
+ this._settleDeferred();
1027
1130
  const chunks = this._chunks;
1028
1131
  const mappings = this._mappings;
1029
1132
  // Both pieces and mappings are output-ordered, so one cursor walks them
@@ -1031,7 +1134,7 @@ class PrintContext {
1031
1134
  let at = 0;
1032
1135
  for (let i = 0; i <= chunks.length; i++) {
1033
1136
  const text = i === chunks.length ? this._tail : chunks[i];
1034
- while (at < mappings.length && mappings[at][0] < i) at++;
1137
+ while (at < mappings.length && mappings[at] < i) at += 4;
1035
1138
  let start = text.indexOf(DEFERRED_MARKER);
1036
1139
  if (start === -1) continue;
1037
1140
  let out = "";
@@ -1070,9 +1173,9 @@ class PrintContext {
1070
1173
  chunks[i] = out;
1071
1174
  }
1072
1175
  let s = 0;
1073
- for (let k = at; k < mappings.length && mappings[k][0] === i; k++) {
1074
- while (s < shifts.length && shifts[s][0] <= mappings[k][1]) s++;
1075
- if (s !== 0) mappings[k][1] += shifts[s - 1][1];
1176
+ for (let k = at; k < mappings.length && mappings[k] === i; k += 4) {
1177
+ while (s < shifts.length && shifts[s][0] <= mappings[k + 1]) s++;
1178
+ if (s !== 0) mappings[k + 1] += shifts[s - 1][1];
1076
1179
  }
1077
1180
  }
1078
1181
  }
@@ -1086,6 +1189,7 @@ class PrintContext {
1086
1189
  * @param {string} text the output to keep instead
1087
1190
  */
1088
1191
  replaceAll(text) {
1192
+ this._deferred = null;
1089
1193
  this._chunks.length = 0;
1090
1194
  this._tail = text;
1091
1195
  this._tailLength = text.length;
@@ -1097,6 +1201,7 @@ class PrintContext {
1097
1201
  }
1098
1202
 
1099
1203
  result() {
1204
+ this._settleDeferred();
1100
1205
  // Trailing kept comments (after the last top-level node) flush here.
1101
1206
  if (this._insertIdx < this._inserts.length) this._flushBefore(Infinity);
1102
1207
  // Nothing was ever cut into its own piece, so there is nothing to join.
@@ -1175,8 +1280,8 @@ class SourceProcessor {
1175
1280
  * @returns {SourceProcessor<TPath, TNode, TProcessOptions, TPrintOptions, TParts, TState, TVisitors>} `this`, for chaining
1176
1281
  */
1177
1282
  /**
1178
- * @param {EXPECTED_ANY} map visitor map, or the node types `bucket` visits
1179
- * @param {VisitorBucket<EXPECTED_ANY>=} bucket the visitor, with an array of types
1283
+ * @param {number[] | TVisitors | VisitorMap<TPath>} map visitor map, or the node types `bucket` visits
1284
+ * @param {VisitorBucket<TypedNodePath<TPath, TNode, TParts, number, TState>>=} bucket the visitor, with an array of types
1180
1285
  * @returns {SourceProcessor<TPath, TNode, TProcessOptions, TPrintOptions, TParts, TState, TVisitors>} `this`, for chaining
1181
1286
  */
1182
1287
  use(map, bucket) {
@@ -1186,14 +1291,23 @@ class SourceProcessor {
1186
1291
  "SourceProcessor.use(types, bucket): a visitor is required"
1187
1292
  );
1188
1293
  }
1189
- for (let i = 0; i < map.length; i++) this._add(map[i], bucket);
1294
+ for (let i = 0; i < map.length; i++) {
1295
+ this._add(
1296
+ map[i],
1297
+ /** @type {VisitorBucket<TPath>} */ (
1298
+ /** @type {VisitorBucket<TPath> | VisitorBucket<TypedNodePath<TPath, TNode, TParts, number, TState>>} */ (
1299
+ bucket
1300
+ )
1301
+ )
1302
+ );
1303
+ }
1190
1304
  return this;
1191
1305
  }
1192
1306
  // `map`'s keys are node-type enum members; `Object.keys` stringifies them,
1193
1307
  // so index the compiled array by the number to match the numeric `node.type`.
1194
- for (const type of Object.keys(map)) {
1308
+ for (const type of Object.keys(/** @type {VisitorMap<TPath>} */ (map))) {
1195
1309
  const key = Number(type);
1196
- this._add(key, map[key]);
1310
+ this._add(key, /** @type {VisitorMap<TPath>} */ (map)[key]);
1197
1311
  }
1198
1312
  return this;
1199
1313
  }
@@ -1291,9 +1405,9 @@ class SourceProcessor {
1291
1405
  // along is inert, since a printer reads only what its own type declares.
1292
1406
  const ctx = new PrintContext(
1293
1407
  /** @type {PrintOptions & TPrintOptions} */ (
1294
- /** @type {unknown} */ (opts)
1408
+ /** @type {typeof opts | (PrintOptions & TPrintOptions)} */ (opts)
1295
1409
  ),
1296
- /** @type {NodePrinter<TPath, TNode, TPrintOptions>} */ (this._printer)
1410
+ this._printer
1297
1411
  );
1298
1412
  this._run(input, ctx, opts);
1299
1413
  const name = /** @type {{ source?: string, content?: string }} */ (opts);
@@ -1343,7 +1457,10 @@ class SourceProcessor {
1343
1457
  // renderer's answer widened, which `Omit` cannot say and nothing reads.
1344
1458
  const opts =
1345
1459
  /** @type {TProcessOptions & { mode: PrintOptions["mode"] }} */
1346
- (/** @type {unknown} */ (options));
1460
+ (
1461
+ /** @type {typeof options | (TProcessOptions & { mode: PrintOptions["mode"] })} */
1462
+ (options)
1463
+ );
1347
1464
 
1348
1465
  if (render === undefined) {
1349
1466
  return /** @type {{ code: string, map: SourceMap | undefined }} */ (
@@ -5,10 +5,16 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ /**
9
+ * A value one position of a tuple key may hold: a primitive kept in a `Map`, or
10
+ * an object (functions included) kept in a `WeakMap`.
11
+ * @typedef {string | number | bigint | boolean | symbol | EXPECTED_OBJECT | null | undefined} TupleElement
12
+ */
13
+
8
14
  /**
9
15
  * Strong-key child map used for tuple elements that cannot be stored in a
10
16
  * `WeakMap`.
11
- * @template {EXPECTED_ANY[]} T
17
+ * @template {TupleElement[]} T
12
18
  * @template V
13
19
  * @typedef {Map<ArrayElement<T>, WeakTupleMap<T, V>>} M
14
20
  */
@@ -16,7 +22,7 @@
16
22
  /**
17
23
  * Weak-key child map used for tuple elements that are objects and can be held
18
24
  * without preventing garbage collection.
19
- * @template {EXPECTED_ANY[]} T
25
+ * @template {TupleElement[]} T
20
26
  * @template V
21
27
  * @typedef {WeakMap<ArrayElement<T> & EXPECTED_OBJECT, WeakTupleMap<T, V>>} W
22
28
  */
@@ -31,14 +37,14 @@ const isWeakKey = (thing) => typeof thing === "object" && thing !== null;
31
37
 
32
38
  /**
33
39
  * Extracts the element type from a tuple-like array.
34
- * @template {unknown[]} T
40
+ * @template T
35
41
  * @typedef {T extends ReadonlyArray<infer ElementType> ? ElementType : never} ArrayElement
36
42
  */
37
43
 
38
44
  /**
39
45
  * Stores values by tuple keys while using `WeakMap` for object elements so the
40
46
  * cache can release entries when those objects are collected.
41
- * @template {EXPECTED_ANY[]} K
47
+ * @template {TupleElement[]} K
42
48
  * @template V
43
49
  */
44
50
  class WeakTupleMap {