webpack 5.110.3 → 5.111.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 (208) hide show
  1. package/README.md +5 -0
  2. package/lib/APIPlugin.js +23 -7
  3. package/lib/AutomaticPrefetchPlugin.js +1 -1
  4. package/lib/Cache.js +8 -3
  5. package/lib/CacheFacade.js +1 -1
  6. package/lib/CircularModulesPlugin.js +157 -55
  7. package/lib/CleanPlugin.js +2 -2
  8. package/lib/Compilation.js +320 -302
  9. package/lib/Compiler.js +209 -46
  10. package/lib/ContextModule.js +17 -81
  11. package/lib/ContextModuleFactory.js +1 -1
  12. package/lib/CopyPlugin.js +1054 -0
  13. package/lib/DefinePlugin.js +24 -8
  14. package/lib/ExternalModule.js +41 -14
  15. package/lib/FileSystemInfo.js +17 -14
  16. package/lib/FlagDependencyExportsPlugin.js +45 -21
  17. package/lib/HotModuleReplacementPlugin.js +53 -7
  18. package/lib/JavascriptMetaInfoPlugin.js +5 -3
  19. package/lib/MainTemplate.js +5 -1
  20. package/lib/Module.js +16 -7
  21. package/lib/MultiCompiler.js +1 -1
  22. package/lib/MultiWatching.js +1 -1
  23. package/lib/NormalModule.js +45 -12
  24. package/lib/NormalModuleFactory.js +1 -1
  25. package/lib/RuntimeGlobals.js +21 -7
  26. package/lib/RuntimeModule.js +28 -12
  27. package/lib/RuntimePlugin.js +30 -3
  28. package/lib/RuntimeTemplate.js +780 -475
  29. package/lib/SourceMapDevToolPlugin.js +1 -1
  30. package/lib/Watching.js +9 -0
  31. package/lib/WebpackOptionsApply.js +84 -91
  32. package/lib/asset/AssetGenerator.js +25 -8
  33. package/lib/asset/AssetModule.js +3 -0
  34. package/lib/asset/WebManifestParser.js +7 -5
  35. package/lib/cache/AddBuildDependenciesPlugin.js +33 -4
  36. package/lib/cache/IdleFileCachePlugin.js +2 -2
  37. package/lib/cache/PackFileCacheStrategy.js +14 -1
  38. package/lib/config/browserslistTargetHandler.js +19 -0
  39. package/lib/config/defaults.js +86 -50
  40. package/lib/config/normalization.js +82 -12
  41. package/lib/config/target.js +10 -0
  42. package/lib/container/ContainerReferencePlugin.js +6 -0
  43. package/lib/container/RemoteRuntimeModule.js +9 -0
  44. package/lib/container/declaredRemotes.js +39 -0
  45. package/lib/css/CssGenerator.js +8 -0
  46. package/lib/css/CssInjectStyleRuntimeModule.js +9 -0
  47. package/lib/css/CssLoadingRuntimeModule.js +94 -36
  48. package/lib/css/CssModule.js +1 -1
  49. package/lib/css/CssModulesPlugin.js +7 -6
  50. package/lib/css/CssParser.js +144 -11
  51. package/lib/css/CssServerStylesRuntimeModule.js +9 -0
  52. package/lib/css/cssMinify.js +11 -3
  53. package/lib/css/data.js +2814 -678
  54. package/lib/css/syntax.js +4082 -248
  55. package/lib/debug/ProfilingPlugin.js +4 -0
  56. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +6 -3
  57. package/lib/dependencies/AMDRuntimeModules.js +18 -0
  58. package/lib/dependencies/CommonJsExportRequireDependency.js +3 -1
  59. package/lib/dependencies/CommonJsExportsParserPlugin.js +12 -13
  60. package/lib/dependencies/CommonJsImportsParserPlugin.js +1 -0
  61. package/lib/dependencies/CommonJsPlugin.js +19 -3
  62. package/lib/dependencies/CommonJsRequireDependency.js +14 -5
  63. package/lib/dependencies/CssIcssExportDependency.js +7 -1
  64. package/lib/dependencies/HarmonyCompatibilityDependency.js +58 -4
  65. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +8 -3
  66. package/lib/dependencies/HarmonyExportExpressionDependency.js +44 -29
  67. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +71 -13
  68. package/lib/dependencies/HarmonyExportInitFragment.js +99 -19
  69. package/lib/dependencies/HarmonyExportSpecifierDependency.js +18 -30
  70. package/lib/dependencies/HarmonyImportBareSideEffectDependency.js +59 -0
  71. package/lib/dependencies/HarmonyImportDependency.js +6 -1
  72. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +8 -1
  73. package/lib/dependencies/HarmonyImportSpecifierDependency.js +24 -1
  74. package/lib/dependencies/HarmonyModulesPlugin.js +20 -0
  75. package/lib/dependencies/HtmlEntryDependency.js +50 -0
  76. package/lib/dependencies/ImportMetaMainDependency.js +104 -0
  77. package/lib/dependencies/ImportMetaPlugin.js +59 -15
  78. package/lib/dependencies/SystemRuntimeModule.js +9 -0
  79. package/lib/dependencies/WorkerDependency.js +1 -2
  80. package/lib/dependencies/WorkletDependency.js +1 -2
  81. package/lib/dll/DelegatedModule.js +18 -1
  82. package/lib/dll/DllReferencePlugin.js +11 -8
  83. package/lib/dll/LibManifestPlugin.js +1 -1
  84. package/lib/errors/AnalyzableBailoutsWarning.js +41 -0
  85. package/lib/errors/DuplicateModulesWarning.js +12 -7
  86. package/lib/errors/EmptyCopyPatternWarning.js +26 -0
  87. package/lib/errors/ExternalStarReexportError.js +44 -0
  88. package/lib/errors/MissingSourceMapsWarning.js +36 -0
  89. package/lib/errors/ModuleParseError.js +2 -1
  90. package/lib/errors/UnusedAssetsWarning.js +36 -0
  91. package/lib/errors/UnusedFederationWarning.js +35 -0
  92. package/lib/errors/UnusedModulesWarning.js +38 -0
  93. package/lib/esm/ExportWebpackRequireRuntimeModule.js +9 -0
  94. package/lib/esm/ModuleChunkFormatPlugin.js +28 -3
  95. package/lib/esm/ModuleChunkLoadingPlugin.js +30 -11
  96. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +92 -60
  97. package/lib/hmr/HotModuleReplacement.runtime.js +8 -2
  98. package/lib/hmr/HotModuleReplacementRuntimeModule.js +9 -0
  99. package/lib/html/HtmlGenerator.js +11 -5
  100. package/lib/html/HtmlModulesPlugin.js +331 -62
  101. package/lib/html/HtmlParser.js +13 -6
  102. package/lib/html/builtinEmbeddedRenderer.js +107 -0
  103. package/lib/html/data.js +121 -7
  104. package/lib/html/htmlMinify.js +84 -113
  105. package/lib/html/syntax.js +763 -426
  106. package/lib/ids/HashedModuleIdsPlugin.js +2 -1
  107. package/lib/index.js +3 -0
  108. package/lib/javascript/JavascriptModule.js +1 -0
  109. package/lib/javascript/JavascriptModulesPlugin.js +52 -24
  110. package/lib/javascript/JavascriptParser.js +1255 -728
  111. package/lib/javascript/StartupHelpers.js +27 -3
  112. package/lib/javascript/data.js +172 -0
  113. package/lib/javascript/grammar.js +5546 -0
  114. package/lib/javascript/parser.js +1494 -0
  115. package/lib/javascript/regexp.js +1762 -0
  116. package/lib/javascript/regexpData.js +51 -0
  117. package/lib/javascript/syntax.js +8696 -5225
  118. package/lib/library/ModuleLibraryPlugin.js +116 -5
  119. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +22 -0
  120. package/lib/node/RequireChunkLoadingRuntimeModule.js +22 -0
  121. package/lib/optimize/ConcatenatedModule.js +97 -20
  122. package/lib/optimize/ConstExportsPlugin.js +50 -39
  123. package/lib/optimize/InlineExports.js +20 -123
  124. package/lib/optimize/MangleExportsPlugin.js +10 -0
  125. package/lib/optimize/ModuleConcatenationPlugin.js +24 -1
  126. package/lib/optimize/RealContentHashPlugin.js +68 -9
  127. package/lib/optimize/SideEffectsFlagPlugin.js +17 -9
  128. package/lib/performance/AnalyzableBailoutsPlugin.js +115 -0
  129. package/lib/performance/CacheEffectivenessPlugin.js +4 -3
  130. package/lib/performance/DuplicateModulesPlugin.js +57 -13
  131. package/lib/performance/EvalUsagePlugin.js +5 -2
  132. package/lib/performance/MissingSourceMapsPlugin.js +115 -0
  133. package/lib/performance/PureAnnotationsPlugin.js +6 -3
  134. package/lib/performance/TopLevelThisPlugin.js +5 -4
  135. package/lib/performance/UnusedAssetsPlugin.js +109 -0
  136. package/lib/performance/UnusedFederationPlugin.js +147 -0
  137. package/lib/performance/UnusedModulesPlugin.js +141 -0
  138. package/lib/performance/UnusedReexportsPlugin.js +1 -55
  139. package/lib/performance/isOnlyReexported.js +65 -0
  140. package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +25 -5
  141. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +2 -0
  142. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +9 -0
  143. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +9 -0
  144. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +9 -0
  145. package/lib/prefetch/ResourceHintPlugin.js +1 -2
  146. package/lib/prefetch/ResourceHintRuntimeModule.js +9 -0
  147. package/lib/prefetch/StartupAssetHintRuntimeModule.js +9 -0
  148. package/lib/rules/RuleSetCompiler.js +211 -4
  149. package/lib/runtime/AsyncModuleRuntimeModule.js +100 -66
  150. package/lib/runtime/AutoPublicPathRuntimeModule.js +9 -0
  151. package/lib/runtime/BaseUriRuntimeModule.js +9 -0
  152. package/lib/runtime/ChunkNameRuntimeModule.js +9 -0
  153. package/lib/runtime/EnsureChunkRuntimeModule.js +35 -16
  154. package/lib/runtime/GetChunkFilenameRuntimeModule.js +9 -0
  155. package/lib/runtime/GetFullHashRuntimeModule.js +9 -0
  156. package/lib/runtime/GetMainFilenameRuntimeModule.js +9 -0
  157. package/lib/runtime/GetWorkletBootstrapRuntimeModule.js +9 -0
  158. package/lib/runtime/GlobalRuntimeModule.js +9 -0
  159. package/lib/runtime/HasOwnPropertyRuntimeModule.js +9 -0
  160. package/lib/runtime/HelperRuntimeModule.js +10 -0
  161. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +330 -219
  162. package/lib/runtime/NonceRuntimeModule.js +9 -0
  163. package/lib/runtime/OnChunksLoadedRuntimeModule.js +67 -20
  164. package/lib/runtime/PublicPathRuntimeModule.js +9 -0
  165. package/lib/runtime/RuntimeIdRuntimeModule.js +9 -0
  166. package/lib/runtime/SpecNamespaceObjectRuntimeModule.js +90 -0
  167. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +9 -0
  168. package/lib/runtime/StartupEntrypointRuntimeModule.js +9 -0
  169. package/lib/runtime/SystemContextRuntimeModule.js +9 -0
  170. package/lib/runtime/ToBinaryRuntimeModule.js +9 -0
  171. package/lib/serialization/ObjectMiddleware.js +138 -106
  172. package/lib/sharing/ConsumeSharedPlugin.js +12 -0
  173. package/lib/sharing/ConsumeSharedRuntimeModule.js +11 -0
  174. package/lib/sharing/ShareRuntimeModule.js +9 -0
  175. package/lib/sharing/declaredShared.js +47 -0
  176. package/lib/stats/DefaultStatsFactoryPlugin.js +3 -1
  177. package/lib/stats/DefaultStatsPrinterPlugin.js +3 -0
  178. package/lib/util/SourceProcessor.js +76 -69
  179. package/lib/util/async.js +292 -0
  180. package/lib/util/buildDiagnostics.js +69 -0
  181. package/lib/util/fs.js +27 -1
  182. package/lib/util/handlerKeys.js +40 -0
  183. package/lib/util/identifier.js +20 -0
  184. package/lib/util/internalSerializables.js +4 -0
  185. package/lib/util/registerExternalSerializer.js +6 -45
  186. package/lib/wasm-async/AsyncWasmCompileRuntimeModule.js +9 -0
  187. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +9 -0
  188. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +9 -0
  189. package/lib/web/JsonpChunkLoadingRuntimeModule.js +36 -0
  190. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +19 -0
  191. package/package.json +22 -16
  192. package/schemas/WebpackOptions.check.js +1 -1
  193. package/schemas/WebpackOptions.json +379 -66
  194. package/schemas/plugins/LoaderOptionsPlugin.check.js +1 -1
  195. package/schemas/plugins/ManifestPlugin.check.js +1 -1
  196. package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
  197. package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
  198. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
  199. package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
  200. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  201. package/schemas/plugins/debug/ProfilingPlugin.check.js +1 -1
  202. package/schemas/plugins/dll/DllReferencePlugin.check.js +1 -1
  203. package/schemas/plugins/ids/HashedModuleIdsPlugin.check.js +1 -1
  204. package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
  205. package/types.d.ts +1414 -314
  206. package/lib/dependencies/ExportBindingInitFragment.js +0 -191
  207. package/lib/errors/EntrypointOverlapWarning.js +0 -45
  208. package/lib/performance/EntrypointOverlapPlugin.js +0 -122
@@ -12,6 +12,7 @@ const {
12
12
  WEBASSEMBLY_MODULES
13
13
  } = require("../ModuleTypeConstants");
14
14
  const { dirname, mkdirpSync } = require("../util/fs");
15
+ const { fileUrlToPath } = require("../util/identifier");
15
16
 
16
17
  /** @import { Session } from "inspector" */
17
18
  /** @import { FullTap } from "tapable" */
@@ -258,6 +259,9 @@ class ProfilingPlugin {
258
259
  * @param {ProfilingPluginOptions=} options options object
259
260
  */
260
261
  constructor(options = {}) {
262
+ if (typeof options.outputPath === "string") {
263
+ options.outputPath = fileUrlToPath(options.outputPath);
264
+ }
261
265
  /** @type {ProfilingPluginOptions} */
262
266
  this.options = options;
263
267
  }
@@ -6,6 +6,7 @@
6
6
  "use strict";
7
7
 
8
8
  const RuntimeGlobals = require("../RuntimeGlobals");
9
+ const { recordOptimizationBailout } = require("../util/buildDiagnostics");
9
10
  const AMDDefineDependency = require("./AMDDefineDependency");
10
11
  const AMDRequireArrayDependency = require("./AMDRequireArrayDependency");
11
12
  const AMDRequireContextDependency = require("./AMDRequireContextDependency");
@@ -35,6 +36,7 @@ const { addLocalModule, getLocalModule } = require("./LocalModulesHelpers");
35
36
  * } from "../../declarations/WebpackOptions"
36
37
  */
37
38
  /** @import Dependency from "../Dependency" */
39
+ /** @import { BuildInfo } from "../Module" */
38
40
  /** @import BasicEvaluatedExpression from "../javascript/BasicEvaluatedExpression" */
39
41
  /**
40
42
  * @import JavascriptParser, {
@@ -353,9 +355,10 @@ class AMDDefineDependencyParserPlugin {
353
355
  return;
354
356
  }
355
357
  DynamicExports.bailout(parser.state);
356
- parser.state.compilation.moduleGraph
357
- .getOptimizationBailout(parser.state.module)
358
- .push("AMD bailout: define() prevents static exports analysis");
358
+ recordOptimizationBailout(
359
+ /** @type {BuildInfo} */ (parser.state.module.buildInfo),
360
+ "AMD bailout: define() prevents static exports analysis"
361
+ );
359
362
  /** @type {Identifier[] | null} */
360
363
  let fnParams = null;
361
364
  let fnParamsOffset = 0;
@@ -25,6 +25,15 @@ class AMDDefineRuntimeModule extends RuntimeModule {
25
25
  return false;
26
26
  }
27
27
 
28
+ /**
29
+ * The `[handlerMap, key]` pairs this module installs onto a chunk handler map
30
+ * such as `__webpack_require__.f`, or `null` where it cannot name them.
31
+ * @returns {[string, string][] | null} installed chunk handlers (do not mutate)
32
+ */
33
+ getInstalledChunkHandlers() {
34
+ return RuntimeModule.NO_CHUNK_HANDLERS;
35
+ }
36
+
28
37
  /**
29
38
  * Generates runtime code for this runtime module.
30
39
  * @returns {string | null} runtime code
@@ -58,6 +67,15 @@ class AMDOptionsRuntimeModule extends RuntimeModule {
58
67
  this.options = options;
59
68
  }
60
69
 
70
+ /**
71
+ * The `[handlerMap, key]` pairs this module installs onto a chunk handler map
72
+ * such as `__webpack_require__.f`, or `null` where it cannot name them.
73
+ * @returns {[string, string][] | null} installed chunk handlers (do not mutate)
74
+ */
75
+ getInstalledChunkHandlers() {
76
+ return RuntimeModule.NO_CHUNK_HANDLERS;
77
+ }
78
+
61
79
  /**
62
80
  * Generates runtime code for this runtime module.
63
81
  * @returns {string | null} runtime code
@@ -528,7 +528,9 @@ CommonJsExportRequireDependency.Template = class CommonJsExportRequireDependency
528
528
  : ids;
529
529
  requireExpr = concatenationScope.createModuleReference(importedModule, {
530
530
  ids: requestedIds.length > 0 ? requestedIds : undefined,
531
- asiSafe: true,
531
+ // a used reexport keeps its assignment, so only an unused one is
532
+ // left standing where the original statement began
533
+ asiSafe: used ? true : dep.asiSafe,
532
534
  moduleExportsAccess: true
533
535
  });
534
536
  } else {
@@ -7,6 +7,7 @@
7
7
 
8
8
  const RuntimeGlobals = require("../RuntimeGlobals");
9
9
  const { evaluateToString } = require("../javascript/JavascriptParserHelpers");
10
+ const { recordOptimizationBailout } = require("../util/buildDiagnostics");
10
11
  const formatLocation = require("../util/formatLocation");
11
12
  const { propertyAccess } = require("../util/property");
12
13
  const CommonJsExportRequireDependency = require("./CommonJsExportRequireDependency");
@@ -38,7 +39,7 @@ const FUNCTION_PROPERTY_DROP_HEAD =
38
39
  * } from "estree"
39
40
  */
40
41
  /** @import { ExportInfoName } from "../Dependency" */
41
- /** @import ModuleGraph from "../ModuleGraph" */
42
+ /** @import { BuildInfo } from "../Module" */
42
43
  /** @import BasicEvaluatedExpression from "../javascript/BasicEvaluatedExpression" */
43
44
  /**
44
45
  * @import JavascriptParser, {
@@ -357,15 +358,6 @@ const getObjectExportKind = (property) => {
357
358
  const PLUGIN_NAME = "CommonJsExportsParserPlugin";
358
359
 
359
360
  class CommonJsExportsParserPlugin {
360
- /**
361
- * Creates an instance of CommonJsExportsParserPlugin.
362
- * @param {ModuleGraph} moduleGraph module graph
363
- */
364
- constructor(moduleGraph) {
365
- /** @type {ModuleGraph} */
366
- this.moduleGraph = moduleGraph;
367
- }
368
-
369
361
  /**
370
362
  * Applies the plugin by registering its hooks on the compiler.
371
363
  * @param {JavascriptParser} parser the parser
@@ -406,9 +398,10 @@ class CommonJsExportsParserPlugin {
406
398
  * @param {string} reason reason
407
399
  */
408
400
  const bailoutHint = (reason) => {
409
- this.moduleGraph
410
- .getOptimizationBailout(parser.state.module)
411
- .push(`CommonJS bailout: ${reason}`);
401
+ recordOptimizationBailout(
402
+ /** @type {BuildInfo} */ (parser.state.module.buildInfo),
403
+ `CommonJS bailout: ${reason}`
404
+ );
412
405
  };
413
406
  /** @type {unknown} */
414
407
  let keptAllExportsForState;
@@ -479,6 +472,9 @@ class CommonJsExportsParserPlugin {
479
472
  requireCall.ids,
480
473
  !parser.isStatementLevelExpression(expr)
481
474
  );
475
+ dep.asiSafe = !parser.isAsiPosition(
476
+ /** @type {Range} */ (expr.range)[0]
477
+ );
482
478
  dep.loc = parser.getLocation(expr);
483
479
  dep.optional = Boolean(parser.scope.inTry);
484
480
  parser.state.module.addDependency(dep);
@@ -670,6 +666,9 @@ class CommonJsExportsParserPlugin {
670
666
  false
671
667
  );
672
668
  dep.getter = reexport.getter;
669
+ dep.asiSafe = !parser.isAsiPosition(
670
+ /** @type {Range} */ (expr.range)[0]
671
+ );
673
672
  dep.loc = parser.getLocation(expr);
674
673
  dep.optional = Boolean(parser.scope.inTry);
675
674
  parser.state.module.addDependency(dep);
@@ -212,6 +212,7 @@ const createRequireCallHandler = (
212
212
  /** @type {Range} */ (expr.range)
213
213
  );
214
214
  if (binding) binding.dep = dep;
215
+ dep.asiSafe = !parser.isAsiPosition(/** @type {Range} */ (expr.range)[0]);
215
216
  dep.loc = parser.getLocation(expr);
216
217
  dep.optional = Boolean(parser.scope.inTry);
217
218
  parser.state.current.addDependency(dep);
@@ -254,9 +254,7 @@ class CommonJsPlugin {
254
254
  );
255
255
 
256
256
  new CommonJsImportsParserPlugin(parserOptions).apply(parser);
257
- new CommonJsExportsParserPlugin(compilation.moduleGraph).apply(
258
- parser
259
- );
257
+ new CommonJsExportsParserPlugin().apply(parser);
260
258
  };
261
259
 
262
260
  normalModuleFactory.hooks.parser
@@ -285,6 +283,15 @@ class HarmonyModuleDecoratorRuntimeModule extends RuntimeModule {
285
283
  return false;
286
284
  }
287
285
 
286
+ /**
287
+ * The `[handlerMap, key]` pairs this module installs onto a chunk handler map
288
+ * such as `__webpack_require__.f`, or `null` where it cannot name them.
289
+ * @returns {[string, string][] | null} installed chunk handlers (do not mutate)
290
+ */
291
+ getInstalledChunkHandlers() {
292
+ return RuntimeModule.NO_CHUNK_HANDLERS;
293
+ }
294
+
288
295
  /**
289
296
  * Generates runtime code for this runtime module.
290
297
  * @returns {string | null} runtime code
@@ -326,6 +333,15 @@ class NodeModuleDecoratorRuntimeModule extends RuntimeModule {
326
333
  return false;
327
334
  }
328
335
 
336
+ /**
337
+ * The `[handlerMap, key]` pairs this module installs onto a chunk handler map
338
+ * such as `__webpack_require__.f`, or `null` where it cannot name them.
339
+ * @returns {[string, string][] | null} installed chunk handlers (do not mutate)
340
+ */
341
+ getInstalledChunkHandlers() {
342
+ return RuntimeModule.NO_CHUNK_HANDLERS;
343
+ }
344
+
329
345
  /**
330
346
  * Generates runtime code for this runtime module.
331
347
  * @returns {string | null} runtime code
@@ -36,8 +36,8 @@ const ModuleDependency = require("./ModuleDependency");
36
36
  /** @import { UsedByExports } from "../optimize/InnerGraph" */
37
37
  /** @import { RuntimeSpec } from "../util/runtime" */
38
38
  /** @import { DependencyGuard } from "./HarmonyImportGuard" */
39
- /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext<[RawReferencedExports | null, Range | undefined, DependencyGuard[] | undefined, boolean, boolean, UsedByExports | undefined]>} ObjectDeserializerContext */
40
- /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext<[RawReferencedExports | null, Range | undefined, DependencyGuard[] | undefined, boolean, boolean, UsedByExports | undefined]>} ObjectSerializerContext */
39
+ /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext<[RawReferencedExports | null, Range | undefined, DependencyGuard[] | undefined, boolean, boolean, UsedByExports | undefined, boolean | undefined]>} ObjectDeserializerContext */
40
+ /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext<[RawReferencedExports | null, Range | undefined, DependencyGuard[] | undefined, boolean, boolean, UsedByExports | undefined, boolean | undefined]>} ObjectSerializerContext */
41
41
 
42
42
  /**
43
43
  * Trims a member-access path at the first segment that is definitively not a
@@ -93,6 +93,10 @@ class CommonJsRequireDependency extends ModuleDependency {
93
93
  // `new require(...)`; see the template for the return-value rule
94
94
  /** @type {boolean} */
95
95
  this.callNew = false;
96
+ // whether the position the call sits at cannot be joined to what precedes
97
+ // it by ASI; only meaningful once the call renders as a module reference
98
+ /** @type {boolean | undefined} */
99
+ this.asiSafe = undefined;
96
100
  }
97
101
 
98
102
  get type() {
@@ -226,7 +230,8 @@ class CommonJsRequireDependency extends ModuleDependency {
226
230
  .write(this.branchGuards)
227
231
  .write(this._canConcatenate)
228
232
  .write(this.callNew)
229
- .write(this.usedByExports);
233
+ .write(this.usedByExports)
234
+ .write(this.asiSafe);
230
235
  super.serialize(context);
231
236
  }
232
237
 
@@ -246,7 +251,9 @@ class CommonJsRequireDependency extends ModuleDependency {
246
251
  this.callNew = c4.read();
247
252
  const c5 = c4.rest;
248
253
  this.usedByExports = c5.read();
249
- super.deserialize(c5.rest);
254
+ const c6 = c5.rest;
255
+ this.asiSafe = c6.read();
256
+ super.deserialize(c6.rest);
250
257
  }
251
258
  }
252
259
 
@@ -303,7 +310,9 @@ CommonJsRequireDependency.Template = class CommonJsRequireDependencyTemplate ext
303
310
  ids: isRequireEsmModuleExportsModule(connection.module, moduleGraph)
304
311
  ? [ESM_MODULE_EXPORTS_NAME]
305
312
  : undefined,
306
- asiSafe: true,
313
+ // `new` wraps the reference in a call, so only a plain
314
+ // replacement inherits the original call's position
315
+ asiSafe: dep.callNew ? true : dep.asiSafe,
307
316
  moduleExportsAccess: true
308
317
  }
309
318
  );
@@ -916,7 +916,13 @@ CssIcssExportDependency.Template = class CssIcssExportDependencyTemplate extends
916
916
  }
917
917
 
918
918
  if (entry.exportType === EXPORT_TYPE.GRID_CUSTOM_IDENTIFIER) {
919
- value += `-${entry.name}`;
919
+ // The suffix names what the identifier was built from, so it follows a
920
+ // `@value` to its resolved name — both spellings select the same line.
921
+ value += `-${
922
+ isReference
923
+ ? /** @type {string[]} */ (entry.value)[0]
924
+ : /** @type {string} */ (entry.value)
925
+ }`;
920
926
  }
921
927
 
922
928
  if (isJs && entry.exportMode !== EXPORT_MODE.NONE) {
@@ -17,11 +17,17 @@ const NullDependency = require("./NullDependency");
17
17
  const getJavascriptModulesPlugin = memoize(() =>
18
18
  require("../javascript/JavascriptModulesPlugin")
19
19
  );
20
+ // Same reason: the deferred-namespace runtime imports dependencies from here.
21
+ const getDeferredCycleHelpers = memoize(() =>
22
+ require("../runtime/MakeDeferredNamespaceObjectRuntime")
23
+ );
20
24
 
21
25
  /** @import { ReplaceSource } from "webpack-sources" */
22
26
  /** @import Dependency from "../Dependency" */
23
27
  /** @import { DependencyTemplateContext } from "../DependencyTemplate" */
24
- /** @import { BuildMeta } from "../Module" */
28
+ /** @import Module, { BuildMeta } from "../Module" */
29
+ /** @import ModuleGraph from "../ModuleGraph" */
30
+ /** @import ChunkGraph, { ModuleId } from "../ChunkGraph" */
25
31
  /**
26
32
  * @import {
27
33
  * JavascriptModuleBuildInfo
@@ -39,6 +45,39 @@ makeSerializable(
39
45
  "webpack/lib/dependencies/HarmonyCompatibilityDependency"
40
46
  );
41
47
 
48
+ /**
49
+ * Key shared by the async modules of one strongly-connected component. The spec
50
+ * records one `[[EvaluationError]]` per component, so a member that already
51
+ * fulfilled still has to report the root's error afterwards.
52
+ * @param {ModuleGraph} moduleGraph the module graph
53
+ * @param {ChunkGraph} chunkGraph the chunk graph
54
+ * @param {Module} module the async module
55
+ * @returns {ModuleId | null} the group key, or null when it is not in an async cycle
56
+ */
57
+ const getAsyncCycleGroupId = (moduleGraph, chunkGraph, module) => {
58
+ const { getDeferredCycleModules } = getDeferredCycleHelpers();
59
+ const peers = getDeferredCycleModules(moduleGraph, module);
60
+ if (peers === null) return null;
61
+ // The component's smallest async member id names the group, so every member
62
+ // emits the same key and none has to carry the whole peer list.
63
+ let groupId = null;
64
+ let asyncPeerCount = 0;
65
+ for (const peer of peers) {
66
+ if (!moduleGraph.isAsync(peer)) continue;
67
+ asyncPeerCount++;
68
+ const id = chunkGraph.getModuleId(peer);
69
+ if (id !== null && (groupId === null || `${id}` < `${groupId}`)) {
70
+ groupId = id;
71
+ }
72
+ }
73
+ if (asyncPeerCount === 0) return null;
74
+ const ownId = chunkGraph.getModuleId(module);
75
+ if (ownId !== null && (groupId === null || `${ownId}` < `${groupId}`)) {
76
+ groupId = ownId;
77
+ }
78
+ return groupId;
79
+ };
80
+
42
81
  HarmonyCompatibilityDependency.Template = class HarmonyExportDependencyTemplate extends (
43
82
  NullDependency.Template
44
83
  ) {
@@ -56,6 +95,7 @@ HarmonyCompatibilityDependency.Template = class HarmonyExportDependencyTemplate
56
95
  module,
57
96
  runtimeTemplate,
58
97
  moduleGraph,
98
+ chunkGraph,
59
99
  initFragments,
60
100
  runtimeRequirements,
61
101
  runtime,
@@ -99,9 +139,23 @@ HarmonyCompatibilityDependency.Template = class HarmonyExportDependencyTemplate
99
139
  }
100
140
  if (moduleGraph.isAsync(module)) {
101
141
  runtimeRequirements.add(RuntimeGlobals.module);
102
- const hasAwait = /** @type {BuildMeta} */ (module.buildMeta).async
103
- ? ", 1"
104
- : "";
142
+ // Only `strictModuleErrorHandling` keeps a recorded error for later
143
+ // requires, so the component's peers are worth naming only then.
144
+ const cycleGroupId = runtimeTemplate.outputOptions
145
+ .strictModuleErrorHandling
146
+ ? getAsyncCycleGroupId(moduleGraph, chunkGraph, module)
147
+ : null;
148
+ // The group is keyed by module id, so the runtime needs `module.id`.
149
+ if (cycleGroupId !== null) {
150
+ runtimeRequirements.add(RuntimeGlobals.moduleId);
151
+ }
152
+ const isAsyncBody = /** @type {BuildMeta} */ (module.buildMeta).async;
153
+ const hasAwait =
154
+ cycleGroupId === null
155
+ ? isAsyncBody
156
+ ? ", 1"
157
+ : ""
158
+ : `, ${isAsyncBody ? 1 : 0}, ${JSON.stringify(cycleGroupId)}`;
105
159
  // A module-scope `await using` is disposed when its scope ends, so the body
106
160
  // needs a block that closes before the module reports completion —
107
161
  // otherwise dependents run before disposal is awaited.
@@ -218,14 +218,19 @@ module.exports = class HarmonyExportDependencyParserPlugin {
218
218
  : undefined,
219
219
  constValue
220
220
  );
221
+ const isAnonymousClass =
222
+ (node.type === "ClassDeclaration" || node.type === "ClassExpression") &&
223
+ !node.id;
221
224
  dep.isAnonymousDefault =
222
225
  this.options.anonymousDefaultExportName !== false &&
223
226
  (node.type === "ArrowFunctionExpression" ||
227
+ isAnonymousClass ||
224
228
  ((node.type === "FunctionDeclaration" ||
225
- node.type === "FunctionExpression" ||
226
- node.type === "ClassDeclaration" ||
227
- node.type === "ClassExpression") &&
229
+ node.type === "FunctionExpression") &&
228
230
  !node.id));
231
+ // A class observes its own name from a static initializer, which runs
232
+ // before the name could be patched afterwards, so it is named in place.
233
+ dep.isAnonymousDefaultClass = dep.isAnonymousDefault && isAnonymousClass;
229
234
  dep.setLocWithIndex(parser.getLocation(statement), -1);
230
235
  parser.state.current.addDependency(dep);
231
236
  getInnerGraphUtils(parser.state.compilation).addVariableUsage(
@@ -12,8 +12,11 @@ const RuntimeGlobals = require("../RuntimeGlobals");
12
12
  const { InlinedUsedName } = require("../optimize/InlineExports");
13
13
  const makeSerializable = require("../util/makeSerializable");
14
14
  const { propertyAccess } = require("../util/property");
15
- const ExportBindingInitFragment = require("./ExportBindingInitFragment");
15
+
16
16
  const HarmonyExportInitFragment = require("./HarmonyExportInitFragment");
17
+
18
+ const { ExportBindingType } = HarmonyExportInitFragment;
19
+
17
20
  const NullDependency = require("./NullDependency");
18
21
 
19
22
  const DEFAULT_EXPORT_NAME = "default";
@@ -26,8 +29,8 @@ const DEFAULT_EXPORT_NAME = "default";
26
29
  /** @import { InlinedValue } from "../optimize/InlineExports" */
27
30
  /** @import { Range } from "../javascript/JavascriptParser" */
28
31
  /** @typedef {string | { id?: string | undefined, range: Range, prefix: string, suffix: string }} DeclarationId */
29
- /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext<[Range, Range, string, DeclarationId | undefined, boolean]>} ObjectDeserializerContext */
30
- /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext<[Range, Range, string, DeclarationId | undefined, boolean]>} ObjectSerializerContext */
32
+ /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext<[Range, Range, string, DeclarationId | undefined, boolean, boolean]>} ObjectDeserializerContext */
33
+ /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext<[Range, Range, string, DeclarationId | undefined, boolean, boolean]>} ObjectSerializerContext */
31
34
  /** @import { ExportMap } from "./HarmonyExportInitFragment" */
32
35
  /**
33
36
  * @import {
@@ -54,6 +57,8 @@ class HarmonyExportExpressionDependency extends NullDependency {
54
57
  this.constValue = constValue;
55
58
  /** @type {boolean} */
56
59
  this.isAnonymousDefault = false;
60
+ /** @type {boolean} */
61
+ this.isAnonymousDefaultClass = false;
57
62
  }
58
63
 
59
64
  get type() {
@@ -126,6 +131,7 @@ class HarmonyExportExpressionDependency extends NullDependency {
126
131
  .write(this.prefix)
127
132
  .write(this.declarationId)
128
133
  .write(this.isAnonymousDefault)
134
+ .write(this.isAnonymousDefaultClass)
129
135
  .write(this.constValue);
130
136
  super.serialize(context);
131
137
  }
@@ -145,8 +151,10 @@ class HarmonyExportExpressionDependency extends NullDependency {
145
151
  const c4 = c3.rest;
146
152
  this.isAnonymousDefault = c4.read();
147
153
  const c5 = c4.rest;
148
- this.constValue = c5.read();
149
- super.deserialize(c5.rest);
154
+ this.isAnonymousDefaultClass = c5.read();
155
+ const c6 = c5.rest;
156
+ this.constValue = c6.read();
157
+ super.deserialize(c6.rest);
150
158
  }
151
159
  }
152
160
 
@@ -208,7 +216,10 @@ HarmonyExportExpressionDependency.Template = class HarmonyExportDependencyTempla
208
216
  } else if (used) {
209
217
  /** @type {ExportMap} */
210
218
  const map = new Map();
211
- map.set(used, `/* export default binding */ ${name}`);
219
+ map.set(used, {
220
+ value: `/* export default binding */ ${name}`,
221
+ type: ExportBindingType.Getter
222
+ });
212
223
  initFragments.push(new HarmonyExportInitFragment(exportsName, map));
213
224
  }
214
225
 
@@ -253,31 +264,19 @@ HarmonyExportExpressionDependency.Template = class HarmonyExportDependencyTempla
253
264
  defaultIsUsed = true;
254
265
  runtimeRequirements.add(RuntimeGlobals.exports);
255
266
  // `export default <expr>` binds an immutable const declaration
256
- const canUseValueBinding =
267
+ const valueFormat =
257
268
  /** @type {import("../Module").BuildInfo} */ (module.buildInfo)
258
269
  .isCircular === false;
259
- if (canUseValueBinding) {
260
- initFragments.push(
261
- new ExportBindingInitFragment(
262
- exportsName,
263
- [
264
- {
265
- name: used,
266
- value: `/* export default binding */ ${name}`,
267
- bindingType: "value"
268
- }
269
- ],
270
- true
271
- )
272
- );
273
- } else {
274
- /** @type {ExportMap} */
275
- const map = new Map();
276
- map.set(used, name);
277
- initFragments.push(
278
- new HarmonyExportInitFragment(exportsName, map)
279
- );
280
- }
270
+
271
+ /** @type {ExportMap} */
272
+ const map = new Map();
273
+ map.set(used, {
274
+ value: name,
275
+ type: valueFormat
276
+ ? ExportBindingType.Value
277
+ : ExportBindingType.Getter
278
+ });
279
+ initFragments.push(new HarmonyExportInitFragment(exportsName, map));
281
280
  } else {
282
281
  content = `/* unused harmony default export */ var ${name} = `;
283
282
  }
@@ -308,6 +307,22 @@ HarmonyExportExpressionDependency.Template = class HarmonyExportDependencyTempla
308
307
  }
309
308
 
310
309
  if (dep.range) {
310
+ // `export default class {}` names the class "default", and a static
311
+ // initializer reads that name before any later fix-up could run, so
312
+ // the class is created as a property of that name instead.
313
+ if (dep.isAnonymousDefaultClass) {
314
+ source.replace(
315
+ dep.rangeStatement[0],
316
+ dep.range[0] - 1,
317
+ `${content}{ ${DEFAULT_EXPORT_NAME}: (${dep.prefix}`
318
+ );
319
+ source.replace(
320
+ dep.range[1],
321
+ dep.rangeStatement[1] - 0.5,
322
+ `) }.${DEFAULT_EXPORT_NAME};`
323
+ );
324
+ return;
325
+ }
311
326
  source.replace(
312
327
  dep.rangeStatement[0],
313
328
  dep.range[0] - 1,