webpack 5.110.2 → 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 (226) hide show
  1. package/README.md +5 -2
  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/ChunkGraph.js +20 -18
  7. package/lib/CircularModulesPlugin.js +157 -55
  8. package/lib/CleanPlugin.js +2 -2
  9. package/lib/Compilation.js +321 -303
  10. package/lib/Compiler.js +209 -46
  11. package/lib/ConcatenationScope.js +25 -35
  12. package/lib/ContextModule.js +17 -81
  13. package/lib/ContextModuleFactory.js +1 -1
  14. package/lib/CopyPlugin.js +1054 -0
  15. package/lib/DefinePlugin.js +24 -8
  16. package/lib/DotenvPlugin.js +41 -13
  17. package/lib/ExternalModule.js +41 -14
  18. package/lib/FileSystemInfo.js +17 -14
  19. package/lib/FlagDependencyExportsPlugin.js +45 -21
  20. package/lib/FlagDependencyUsagePlugin.js +8 -2
  21. package/lib/HotModuleReplacementPlugin.js +53 -7
  22. package/lib/JavascriptMetaInfoPlugin.js +5 -3
  23. package/lib/MainTemplate.js +5 -1
  24. package/lib/Module.js +16 -7
  25. package/lib/MultiCompiler.js +1 -1
  26. package/lib/MultiWatching.js +1 -1
  27. package/lib/NormalModule.js +58 -32
  28. package/lib/NormalModuleFactory.js +1 -1
  29. package/lib/RuntimeGlobals.js +21 -7
  30. package/lib/RuntimeModule.js +28 -12
  31. package/lib/RuntimePlugin.js +33 -3
  32. package/lib/RuntimeTemplate.js +794 -477
  33. package/lib/SourceMapDevToolPlugin.js +1 -1
  34. package/lib/Watching.js +9 -0
  35. package/lib/WebpackOptionsApply.js +84 -91
  36. package/lib/asset/AssetGenerator.js +25 -8
  37. package/lib/asset/AssetModule.js +3 -0
  38. package/lib/asset/WebManifestParser.js +7 -5
  39. package/lib/async-modules/AsyncModuleHelpers.js +10 -4
  40. package/lib/cache/AddBuildDependenciesPlugin.js +33 -4
  41. package/lib/cache/IdleFileCachePlugin.js +2 -2
  42. package/lib/cache/PackFileCacheStrategy.js +14 -1
  43. package/lib/config/browserslistTargetHandler.js +19 -0
  44. package/lib/config/defaults.js +110 -64
  45. package/lib/config/normalization.js +100 -20
  46. package/lib/config/target.js +10 -0
  47. package/lib/container/ContainerReferencePlugin.js +6 -0
  48. package/lib/container/RemoteRuntimeModule.js +9 -0
  49. package/lib/container/declaredRemotes.js +39 -0
  50. package/lib/css/CssGenerator.js +8 -0
  51. package/lib/css/CssInjectStyleRuntimeModule.js +9 -0
  52. package/lib/css/CssLoadingRuntimeModule.js +94 -36
  53. package/lib/css/CssModule.js +1 -1
  54. package/lib/css/CssModulesPlugin.js +7 -6
  55. package/lib/css/CssParser.js +144 -11
  56. package/lib/css/CssServerStylesRuntimeModule.js +9 -0
  57. package/lib/css/cssMinify.js +11 -3
  58. package/lib/css/data.js +2814 -678
  59. package/lib/css/syntax.js +4082 -248
  60. package/lib/debug/ProfilingPlugin.js +4 -0
  61. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +6 -3
  62. package/lib/dependencies/AMDRuntimeModules.js +18 -0
  63. package/lib/dependencies/CommonJsExportRequireDependency.js +3 -1
  64. package/lib/dependencies/CommonJsExportsParserPlugin.js +12 -13
  65. package/lib/dependencies/CommonJsImportsParserPlugin.js +1 -0
  66. package/lib/dependencies/CommonJsPlugin.js +19 -3
  67. package/lib/dependencies/CommonJsRequireDependency.js +32 -9
  68. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +20 -7
  69. package/lib/dependencies/CssIcssExportDependency.js +7 -1
  70. package/lib/dependencies/HarmonyCompatibilityDependency.js +58 -4
  71. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +8 -3
  72. package/lib/dependencies/HarmonyExportExpressionDependency.js +44 -29
  73. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +171 -32
  74. package/lib/dependencies/HarmonyExportInitFragment.js +99 -19
  75. package/lib/dependencies/HarmonyExportSpecifierDependency.js +18 -30
  76. package/lib/dependencies/HarmonyImportBareSideEffectDependency.js +59 -0
  77. package/lib/dependencies/HarmonyImportDependency.js +99 -41
  78. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +20 -3
  79. package/lib/dependencies/HarmonyImportSpecifierDependency.js +24 -1
  80. package/lib/dependencies/HarmonyModulesPlugin.js +20 -0
  81. package/lib/dependencies/HtmlEntryDependency.js +62 -2
  82. package/lib/dependencies/ImportContextDependency.js +43 -3
  83. package/lib/dependencies/ImportDependency.js +8 -29
  84. package/lib/dependencies/ImportMetaMainDependency.js +104 -0
  85. package/lib/dependencies/ImportMetaPlugin.js +59 -15
  86. package/lib/dependencies/ImportParserPlugin.js +24 -14
  87. package/lib/dependencies/RequireHeaderDependency.js +20 -21
  88. package/lib/dependencies/SystemRuntimeModule.js +9 -0
  89. package/lib/dependencies/WorkerDependency.js +1 -2
  90. package/lib/dependencies/WorkletDependency.js +1 -2
  91. package/lib/dependencies/importOptionsCheck.js +47 -0
  92. package/lib/dll/DelegatedModule.js +18 -1
  93. package/lib/dll/DllReferencePlugin.js +11 -8
  94. package/lib/dll/LibManifestPlugin.js +1 -1
  95. package/lib/errors/AnalyzableBailoutsWarning.js +41 -0
  96. package/lib/errors/DotenvFileError.js +29 -0
  97. package/lib/errors/DuplicateModulesWarning.js +12 -7
  98. package/lib/errors/EmptyCopyPatternWarning.js +26 -0
  99. package/lib/errors/ExternalStarReexportError.js +44 -0
  100. package/lib/errors/ImportedBindingAssignmentError.js +30 -0
  101. package/lib/errors/MissingSourceMapsWarning.js +36 -0
  102. package/lib/errors/ModuleParseError.js +2 -1
  103. package/lib/errors/UnusedAssetsWarning.js +36 -0
  104. package/lib/errors/UnusedFederationWarning.js +35 -0
  105. package/lib/errors/UnusedModulesWarning.js +38 -0
  106. package/lib/esm/ExportWebpackRequireRuntimeModule.js +9 -0
  107. package/lib/esm/ModuleChunkFormatPlugin.js +28 -3
  108. package/lib/esm/ModuleChunkLoadingPlugin.js +30 -11
  109. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +92 -60
  110. package/lib/hmr/HotModuleReplacement.runtime.js +8 -2
  111. package/lib/hmr/HotModuleReplacementRuntimeModule.js +9 -0
  112. package/lib/html/HtmlGenerator.js +11 -5
  113. package/lib/html/HtmlModulesPlugin.js +360 -84
  114. package/lib/html/HtmlParser.js +13 -6
  115. package/lib/html/builtinEmbeddedRenderer.js +107 -0
  116. package/lib/html/data.js +121 -7
  117. package/lib/html/htmlMinify.js +84 -113
  118. package/lib/html/syntax.js +1067 -569
  119. package/lib/ids/HashedModuleIdsPlugin.js +2 -1
  120. package/lib/index.js +3 -0
  121. package/lib/javascript/JavascriptModule.js +1 -0
  122. package/lib/javascript/JavascriptModulesPlugin.js +52 -22
  123. package/lib/javascript/JavascriptParser.js +1255 -728
  124. package/lib/javascript/StartupHelpers.js +27 -3
  125. package/lib/javascript/data.js +172 -0
  126. package/lib/javascript/grammar.js +5546 -0
  127. package/lib/javascript/parser.js +1494 -0
  128. package/lib/javascript/regexp.js +1762 -0
  129. package/lib/javascript/regexpData.js +51 -0
  130. package/lib/javascript/syntax.js +8696 -5225
  131. package/lib/library/ModuleLibraryPlugin.js +116 -5
  132. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +22 -0
  133. package/lib/node/RequireChunkLoadingRuntimeModule.js +22 -0
  134. package/lib/optimize/ConcatenatedModule.js +133 -25
  135. package/lib/optimize/ConstExportsPlugin.js +50 -39
  136. package/lib/optimize/InlineExports.js +20 -123
  137. package/lib/optimize/MangleExportsPlugin.js +10 -0
  138. package/lib/optimize/ModuleConcatenationPlugin.js +24 -1
  139. package/lib/optimize/RealContentHashPlugin.js +68 -9
  140. package/lib/optimize/SideEffectsFlagPlugin.js +17 -9
  141. package/lib/performance/AnalyzableBailoutsPlugin.js +115 -0
  142. package/lib/performance/CacheEffectivenessPlugin.js +4 -3
  143. package/lib/performance/DuplicateModulesPlugin.js +57 -13
  144. package/lib/performance/EvalUsagePlugin.js +5 -2
  145. package/lib/performance/MissingSourceMapsPlugin.js +115 -0
  146. package/lib/performance/PureAnnotationsPlugin.js +6 -3
  147. package/lib/performance/TopLevelThisPlugin.js +5 -4
  148. package/lib/performance/UnusedAssetsPlugin.js +109 -0
  149. package/lib/performance/UnusedFederationPlugin.js +147 -0
  150. package/lib/performance/UnusedModulesPlugin.js +141 -0
  151. package/lib/performance/UnusedReexportsPlugin.js +1 -55
  152. package/lib/performance/isOnlyReexported.js +65 -0
  153. package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +25 -5
  154. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +2 -0
  155. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +9 -0
  156. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +9 -0
  157. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +9 -0
  158. package/lib/prefetch/ResourceHintPlugin.js +7 -3
  159. package/lib/prefetch/ResourceHintRuntimeModule.js +9 -0
  160. package/lib/prefetch/StartupAssetHintRuntimeModule.js +9 -0
  161. package/lib/rules/RuleSetCompiler.js +211 -4
  162. package/lib/runtime/AsyncModuleRuntimeModule.js +105 -67
  163. package/lib/runtime/AutoPublicPathRuntimeModule.js +9 -0
  164. package/lib/runtime/BaseUriRuntimeModule.js +9 -0
  165. package/lib/runtime/ChunkNameRuntimeModule.js +9 -0
  166. package/lib/runtime/EnsureChunkRuntimeModule.js +35 -16
  167. package/lib/runtime/GetChunkFilenameRuntimeModule.js +9 -0
  168. package/lib/runtime/GetFullHashRuntimeModule.js +9 -0
  169. package/lib/runtime/GetMainFilenameRuntimeModule.js +9 -0
  170. package/lib/runtime/GetWorkletBootstrapRuntimeModule.js +9 -0
  171. package/lib/runtime/GlobalRuntimeModule.js +9 -0
  172. package/lib/runtime/HasOwnPropertyRuntimeModule.js +9 -0
  173. package/lib/runtime/HelperRuntimeModule.js +10 -0
  174. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +338 -217
  175. package/lib/runtime/NonceRuntimeModule.js +9 -0
  176. package/lib/runtime/OnChunksLoadedRuntimeModule.js +67 -20
  177. package/lib/runtime/PublicPathRuntimeModule.js +9 -0
  178. package/lib/runtime/RuntimeIdRuntimeModule.js +9 -0
  179. package/lib/runtime/SpecNamespaceObjectRuntimeModule.js +90 -0
  180. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +9 -0
  181. package/lib/runtime/StartupEntrypointRuntimeModule.js +9 -0
  182. package/lib/runtime/SystemContextRuntimeModule.js +9 -0
  183. package/lib/runtime/ToBinaryRuntimeModule.js +9 -0
  184. package/lib/schemes/HttpUriPlugin.js +22 -5
  185. package/lib/serialization/FileMiddleware.js +15 -2
  186. package/lib/serialization/ObjectMiddleware.js +138 -106
  187. package/lib/sharing/ConsumeSharedPlugin.js +12 -0
  188. package/lib/sharing/ConsumeSharedRuntimeModule.js +11 -0
  189. package/lib/sharing/ShareRuntimeModule.js +9 -0
  190. package/lib/sharing/declaredShared.js +47 -0
  191. package/lib/stats/DefaultStatsFactoryPlugin.js +3 -1
  192. package/lib/stats/DefaultStatsPrinterPlugin.js +3 -0
  193. package/lib/util/ArrayQueue.js +3 -3
  194. package/lib/util/SourceProcessor.js +76 -69
  195. package/lib/util/URLAbsoluteSpecifier.js +3 -1
  196. package/lib/util/async.js +292 -0
  197. package/lib/util/buildDiagnostics.js +69 -0
  198. package/lib/util/conventions.js +5 -1
  199. package/lib/util/fs.js +27 -1
  200. package/lib/util/handlerKeys.js +40 -0
  201. package/lib/util/identifier.js +20 -0
  202. package/lib/util/internalSerializables.js +6 -0
  203. package/lib/util/registerExternalSerializer.js +6 -45
  204. package/lib/wasm-async/AsyncWasmCompileRuntimeModule.js +9 -0
  205. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +9 -0
  206. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +9 -0
  207. package/lib/web/JsonpChunkLoadingRuntimeModule.js +36 -0
  208. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +19 -0
  209. package/package.json +22 -16
  210. package/schemas/WebpackOptions.check.js +1 -1
  211. package/schemas/WebpackOptions.json +388 -76
  212. package/schemas/plugins/LoaderOptionsPlugin.check.js +1 -1
  213. package/schemas/plugins/ManifestPlugin.check.js +1 -1
  214. package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
  215. package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
  216. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
  217. package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
  218. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  219. package/schemas/plugins/debug/ProfilingPlugin.check.js +1 -1
  220. package/schemas/plugins/dll/DllReferencePlugin.check.js +1 -1
  221. package/schemas/plugins/ids/HashedModuleIdsPlugin.check.js +1 -1
  222. package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
  223. package/types.d.ts +1440 -331
  224. package/lib/dependencies/ExportBindingInitFragment.js +0 -191
  225. package/lib/errors/EntrypointOverlapWarning.js +0 -45
  226. 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
@@ -20,6 +20,7 @@ const HarmonyImportGuard = require("./HarmonyImportGuard");
20
20
  const ModuleDependency = require("./ModuleDependency");
21
21
 
22
22
  /** @import { ReplaceSource } from "webpack-sources" */
23
+ /** @import ConcatenationScope from "../ConcatenationScope" */
23
24
  /**
24
25
  * @import {
25
26
  * GetConditionFn,
@@ -30,12 +31,13 @@ const ModuleDependency = require("./ModuleDependency");
30
31
  /** @import { DependencyTemplateContext } from "../DependencyTemplate" */
31
32
  /** @import Module from "../Module" */
32
33
  /** @import ModuleGraph from "../ModuleGraph" */
34
+ /** @import ModuleGraphConnection from "../ModuleGraphConnection" */
33
35
  /** @import { Range } from "../javascript/JavascriptParser" */
34
36
  /** @import { UsedByExports } from "../optimize/InnerGraph" */
35
37
  /** @import { RuntimeSpec } from "../util/runtime" */
36
38
  /** @import { DependencyGuard } from "./HarmonyImportGuard" */
37
- /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext<[RawReferencedExports | null, Range | undefined, DependencyGuard[] | undefined, boolean, boolean, UsedByExports | undefined]>} ObjectDeserializerContext */
38
- /** @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 */
39
41
 
40
42
  /**
41
43
  * Trims a member-access path at the first segment that is definitively not a
@@ -91,6 +93,10 @@ class CommonJsRequireDependency extends ModuleDependency {
91
93
  // `new require(...)`; see the template for the return-value rule
92
94
  /** @type {boolean} */
93
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;
94
100
  }
95
101
 
96
102
  get type() {
@@ -200,6 +206,19 @@ class CommonJsRequireDependency extends ModuleDependency {
200
206
  return concatenateCommonJsModules && this._canConcatenate;
201
207
  }
202
208
 
209
+ /**
210
+ * @param {ModuleGraphConnection} connection the active connection of this dependency
211
+ * @param {ConcatenationScope} concatenationScope the concatenation scope
212
+ * @returns {boolean} true when the call becomes a module reference
213
+ */
214
+ rendersAsConcatenatedReference(connection, concatenationScope) {
215
+ return (
216
+ this._canConcatenate &&
217
+ this.valueRange !== undefined &&
218
+ concatenationScope.isModuleInScope(connection.module)
219
+ );
220
+ }
221
+
203
222
  /**
204
223
  * Serializes this instance into the provided serializer context.
205
224
  * @param {ObjectSerializerContext} context context
@@ -211,7 +230,8 @@ class CommonJsRequireDependency extends ModuleDependency {
211
230
  .write(this.branchGuards)
212
231
  .write(this._canConcatenate)
213
232
  .write(this.callNew)
214
- .write(this.usedByExports);
233
+ .write(this.usedByExports)
234
+ .write(this.asiSafe);
215
235
  super.serialize(context);
216
236
  }
217
237
 
@@ -231,7 +251,9 @@ class CommonJsRequireDependency extends ModuleDependency {
231
251
  this.callNew = c4.read();
232
252
  const c5 = c4.rest;
233
253
  this.usedByExports = c5.read();
234
- super.deserialize(c5.rest);
254
+ const c6 = c5.rest;
255
+ this.asiSafe = c6.read();
256
+ super.deserialize(c6.rest);
235
257
  }
236
258
  }
237
259
 
@@ -278,9 +300,9 @@ CommonJsRequireDependency.Template = class CommonJsRequireDependencyTemplate ext
278
300
  if (
279
301
  connection &&
280
302
  concatenationScope !== undefined &&
281
- dep.valueRange !== undefined &&
282
- concatenationScope.isModuleInScope(connection.module)
303
+ dep.rendersAsConcatenatedReference(connection, concatenationScope)
283
304
  ) {
305
+ const valueRange = /** @type {Range} */ (dep.valueRange);
284
306
  let content = concatenationScope.createModuleReference(
285
307
  connection.module,
286
308
  {
@@ -288,7 +310,9 @@ CommonJsRequireDependency.Template = class CommonJsRequireDependencyTemplate ext
288
310
  ids: isRequireEsmModuleExportsModule(connection.module, moduleGraph)
289
311
  ? [ESM_MODULE_EXPORTS_NAME]
290
312
  : undefined,
291
- 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,
292
316
  moduleExportsAccess: true
293
317
  }
294
318
  );
@@ -300,8 +324,7 @@ CommonJsRequireDependency.Template = class CommonJsRequireDependencyTemplate ext
300
324
  );
301
325
  content = `${RuntimeGlobals.constructRequire}(${content})`;
302
326
  }
303
- source.replace(dep.valueRange[0], dep.valueRange[1] - 1, content);
304
- concatenationScope.registerReplacedRequire(dep.valueRange);
327
+ source.replace(valueRange[0], valueRange[1] - 1, content);
305
328
  return;
306
329
  }
307
330
  const importedModule = /** @type {Module} */ (moduleGraph.getModule(dep));
@@ -22,11 +22,9 @@ class ContextDependencyTemplateAsRequireCall
22
22
  * @param {DependencyTemplateContext} templateContext the context object
23
23
  * @returns {void}
24
24
  */
25
- apply(
26
- dependency,
27
- source,
28
- { runtimeTemplate, moduleGraph, chunkGraph, runtimeRequirements }
29
- ) {
25
+ apply(dependency, source, templateContext) {
26
+ const { runtimeTemplate, moduleGraph, chunkGraph, runtimeRequirements } =
27
+ templateContext;
30
28
  const dep = /** @type {ContextDependency} */ (dependency);
31
29
  let moduleExports = runtimeTemplate.moduleExports({
32
30
  module: moduleGraph.getModule(dep),
@@ -49,8 +47,7 @@ class ContextDependencyTemplateAsRequireCall
49
47
  source.replace(rep.range[0], rep.range[1] - 1, rep.value);
50
48
  }
51
49
  }
52
- source.replace(dep.valueRange[1], range[1] - 1, ")");
53
- source.replace(range[0], dep.valueRange[0] - 1, `${moduleExports}(`);
50
+ this.replaceCall(dep, source, moduleExports, templateContext);
54
51
  } else {
55
52
  source.replace(range[0], range[1] - 1, moduleExports);
56
53
  }
@@ -58,6 +55,22 @@ class ContextDependencyTemplateAsRequireCall
58
55
  source.replace(range[0], range[1] - 1, moduleExports);
59
56
  }
60
57
  }
58
+
59
+ /**
60
+ * Rewrites the call around its request, dropping anything the original one
61
+ * carried after it. Overridden where a later argument must be kept.
62
+ * @param {ContextDependency} dep the dependency
63
+ * @param {ReplaceSource} source the current replace source which can be modified
64
+ * @param {string} moduleExports the expression the request is passed to
65
+ * @param {DependencyTemplateContext} templateContext the context object
66
+ * @returns {void}
67
+ */
68
+ replaceCall(dep, source, moduleExports, templateContext) {
69
+ const range = /** @type {Range} */ (dep.range);
70
+ const valueRange = /** @type {Range} */ (dep.valueRange);
71
+ source.replace(valueRange[1], range[1] - 1, ")");
72
+ source.replace(range[0], valueRange[0] - 1, `${moduleExports}(`);
73
+ }
61
74
  }
62
75
 
63
76
  module.exports = ContextDependencyTemplateAsRequireCall;
@@ -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,