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
@@ -290,7 +290,17 @@ class MakeOptimizedDeferredNamespaceObjectRuntimeModule extends HelperRuntimeMod
290
290
  ]),
291
291
  "};",
292
292
  hasAsync
293
- ? `if(isAsync) obj[${RuntimeGlobals.deferredModuleAsyncTransitiveDependenciesSymbol}] = asyncDeps;`
293
+ ? // `evaluating` is on the stack, so awaiting it would deadlock;
294
+ // `evaluating-async` is suspended and must still be awaited.
295
+ `if(isAsync) obj[${RuntimeGlobals.deferredModuleAsyncTransitiveDependenciesSymbol}] = asyncDeps.filter(${runtimeTemplate.basicFunction(
296
+ "id",
297
+ [
298
+ `${cst} dep = __webpack_module_cache__[id];`,
299
+ "if (dep && dep.evaluating) return false;",
300
+ "r(id);",
301
+ "return true;"
302
+ ]
303
+ )});`
294
304
  : "",
295
305
  "return obj;"
296
306
  ]),
@@ -312,11 +322,17 @@ class MakeDeferredNamespaceObjectRuntimeModule extends HelperRuntimeModule {
312
322
 
313
323
  /**
314
324
  * @param {boolean} hasAsyncRuntime if async module is used.
325
+ * @param {boolean} sealed a call site builds a namespace from a known export list
326
+ * @param {boolean} synthesized a call site builds one from the module's exports
315
327
  */
316
- constructor(hasAsyncRuntime) {
328
+ constructor(hasAsyncRuntime, sealed, synthesized) {
317
329
  super("make deferred namespace object");
318
330
  /** @type {boolean} */
319
331
  this.hasAsyncRuntime = hasAsyncRuntime;
332
+ /** @type {boolean} */
333
+ this.sealed = sealed;
334
+ /** @type {boolean} */
335
+ this.synthesized = synthesized;
320
336
  }
321
337
 
322
338
  /**
@@ -330,237 +346,342 @@ class MakeDeferredNamespaceObjectRuntimeModule extends HelperRuntimeModule {
330
346
  const lt = runtimeTemplate.renderLet();
331
347
  const fn = RuntimeGlobals.makeDeferredNamespaceObject;
332
348
  const hasAsync = this.hasAsyncRuntime;
349
+ // A build reaches only the shapes its call sites ask for, so the other
350
+ // one's branches are dead weight in every bundle that ships this runtime.
351
+ const sealed = this.sealed;
352
+ const synthesized = this.synthesized;
333
353
  const init = `${runtimeTemplate.optionalChaining("init", "()")};`;
334
- return `${fn} = ${runtimeTemplate.basicFunction("moduleId, mode", [
335
- // Per the TC39 import-defer spec, deferred namespaces are
336
- // distinct from their eager counterparts and the same module
337
- // referenced from multiple defer-import sites must yield the
338
- // same object. Cache the Proxy / fake namespace per-moduleId so
339
- // repeated calls (including across files) share identity.
340
- //
341
- // Bit 16 (`createFakeNamespaceObject`'s "return value when
342
- // it's Promise-like" flag added by
343
- // `RuntimeTemplate.moduleNamespacePromise` for dynamic
344
- // imports) is irrelevant for deferred namespaces — the value
345
- // passed into `createFakeNamespaceObject` here is always the
346
- // resolved module exports (after unwrapping the async-module
347
- // export symbol when present), never a Promise. Strip it
348
- // once so all downstream behavior, the cache key, and the
349
- // `createFakeNamespaceObject` call below see the same shape
350
- // mode. This keeps static defer (mode 8) and dynamic
351
- // `await import.defer` (mode 8 | 16) sharing the same
352
- // Deferred Module Namespace object, while still keying by
353
- // `(moduleId, mode)` so distinct exports-type shapes
354
- // (e.g. one importer treats a CJS module as
355
- // "default-with-named", another as "namespace") get
356
- // distinct cache entries.
357
- "mode &= ~16;",
358
- `${lt} byMode = __webpack_module_deferred_namespace_cache__[moduleId];`,
359
- "if (byMode && byMode[mode] !== undefined) return byMode[mode];",
360
- "if (!byMode) byMode = __webpack_module_deferred_namespace_cache__[moduleId] = {};",
361
- `${cst} cachedModule = __webpack_module_cache__[moduleId];`,
362
- "if (cachedModule && cachedModule.error === undefined && !(mode & 8)) {",
363
- Template.indent([
364
- `${lt} exports = cachedModule.exports;`,
365
- hasAsync
366
- ? `if (${RuntimeGlobals.asyncModuleExportSymbol} in exports) exports = exports[${RuntimeGlobals.asyncModuleExportSymbol}];`
354
+ return `${fn} = ${runtimeTemplate.basicFunction(
355
+ "moduleId, mode, exportNames",
356
+ [
357
+ // Per the TC39 import-defer spec, deferred namespaces are
358
+ // distinct from their eager counterparts and the same module
359
+ // referenced from multiple defer-import sites must yield the
360
+ // same object. Cache the Proxy / fake namespace per-moduleId so
361
+ // repeated calls (including across files) share identity.
362
+ //
363
+ // Bit 16 (`createFakeNamespaceObject`'s "return value when
364
+ // it's Promise-like" flag added by
365
+ // `RuntimeTemplate.moduleNamespacePromise` for dynamic
366
+ // imports) is irrelevant for deferred namespaces — the value
367
+ // passed into `createFakeNamespaceObject` here is always the
368
+ // resolved module exports (after unwrapping the async-module
369
+ // export symbol when present), never a Promise. Strip it
370
+ // once so all downstream behavior, the cache key, and the
371
+ // `createFakeNamespaceObject` call below see the same shape
372
+ // mode. This keeps static defer (mode 8) and dynamic
373
+ // `await import.defer` (mode 8 | 16) sharing the same
374
+ // Deferred Module Namespace object, while still keying by
375
+ // `(moduleId, mode)` so distinct exports-type shapes
376
+ // (e.g. one importer treats a CJS module as
377
+ // "default-with-named", another as "namespace") get
378
+ // distinct cache entries.
379
+ "mode &= ~16;",
380
+ // Only a real ES module namespace has the spec's exotic shape; a
381
+ // synthesized one (JSON, asset, CommonJS interop) keeps the old form.
382
+ sealed && synthesized
383
+ ? "if (!(mode & 8)) exportNames = undefined;"
367
384
  : "",
368
- `return byMode[mode] = ${RuntimeGlobals.createFakeNamespaceObject}(exports, mode);`
369
- ]),
370
- "}",
371
- "",
372
- `${lt} init = ${runtimeTemplate.basicFunction("", [
373
- // A deferred namespace that forces evaluation of a module that is
374
- // already evaluating (a cycle) must throw rather than expose its
375
- // partial exports.
376
- `${cst} evaluatingModule = __webpack_module_cache__[moduleId];`,
377
- 'if (evaluatingModule !== undefined && (evaluatingModule.evaluating || evaluatingModule.evaluatingAsync)) throw new TypeError("Cannot access a deferred module namespace while the module is being evaluated");',
378
- `ns = ${RuntimeGlobals.require}(moduleId);`,
379
- hasAsync
380
- ? `if (${RuntimeGlobals.asyncModuleExportSymbol} in ns) ns = ns[${RuntimeGlobals.asyncModuleExportSymbol}];`
385
+ `${lt} byMode = __webpack_module_deferred_namespace_cache__[moduleId];`,
386
+ "if (byMode && byMode[mode] !== undefined) return byMode[mode];",
387
+ "if (!byMode) byMode = __webpack_module_deferred_namespace_cache__[moduleId] = {};",
388
+ synthesized
389
+ ? `${cst} cachedModule = __webpack_module_cache__[moduleId];`
381
390
  : "",
382
- "init = null;",
383
- "if (mode & 8 || mode & 4 && ns.__esModule && typeof ns === 'object') {",
384
- Template.indent([
385
- // Drop only the read-side traps after init: with the
386
- // resolved namespace's own keys mirrored onto
387
- // `ns_target` below, the default `Reflect` behavior
388
- // returns the right values via the live-binding
389
- // getters, so we no longer need to intercept `get` /
390
- // `has` / `ownKeys` / `getOwnPropertyDescriptor`.
391
- //
392
- // The mutation traps (`set`, `deleteProperty`,
393
- // `defineProperty`) are kept because per the TC39
394
- // import-defer spec, `[[Set]]` / `[[Delete]]` /
395
- // `[[DefineOwnProperty]]` on a Deferred Module
396
- // Namespace Exotic Object never succeed — and the
397
- // proxy target itself remains extensible
398
- // (architecturally we cannot freeze it up-front),
399
- // so without these traps `ns.notExported = "x"`
400
- // after evaluation would silently create a property
401
- // on the target instead of returning false.
402
- "delete handler.get;",
403
- "delete handler.has;",
404
- "delete handler.ownKeys;",
405
- "delete handler.getOwnPropertyDescriptor;"
406
- ]),
407
- "} else {",
408
- Template.indent([
409
- `ns = ${RuntimeGlobals.createFakeNamespaceObject}(ns, mode);`
410
- ]),
411
- "}",
412
- // Mirror own properties from the resolved namespace onto the proxy
413
- // target so that proxy invariants hold for callers that structurally
414
- // introspect via `Object.keys` / `Object.getOwnPropertyNames` /
415
- // `Object.getOwnPropertyDescriptor`: when our trap reports a
416
- // non-configurable descriptor for a key, the target must also have
417
- // that key with a matching descriptor.
418
- //
419
- // `__esModule` and `Symbol.toStringTag` are intentionally skipped:
420
- // the proxy synthesizes "Deferred Module" / true regardless of what
421
- // the underlying namespace exposes (per the TC39 import-defer
422
- // proposal, the [[StringTag]] of a Deferred Module Namespace
423
- // Exotic Object is "Deferred Module"), and the target was already
424
- // pre-populated with those values below.
425
- `${cst} keys = Reflect.ownKeys(ns);`,
426
- "for (var i = 0; i < keys.length; i++) {",
427
- Template.indent([
428
- `${cst} k = keys[i];`,
429
- 'if (k === "__esModule" || k === Symbol.toStringTag) continue;',
430
- `if (!${runtimeTemplate.objectHasOwn("ns_target", "k")}) {`,
431
- Template.indent([
432
- "try { Object.defineProperty(ns_target, k, Reflect.getOwnPropertyDescriptor(ns, k)); } catch (_) {}"
433
- ]),
434
- "}"
435
- ]),
436
- "}"
437
- ])};`,
438
- "",
439
- // The proxy target is a fresh placeholder, separate from
440
- // `__webpack_module_deferred_exports__[moduleId]` (which is reused
441
- // by `__webpack_require__` as `module.exports` for deferred-loaded
442
- // modules and would conflict with our pre-populated synthetic
443
- // `__esModule` / `Symbol.toStringTag` non-configurable properties).
444
- // Using a dedicated target keeps the proxy invariant-compliant
445
- // without interfering with the module's own exports object.
446
- `${cst} ns_target = { __proto__: null };`,
447
- // Pre-populate the synthetic deferred-namespace properties with
448
- // fully non-configurable, non-writable, non-enumerable descriptors
449
- // (matching the TC39 import-defer spec for Module Namespace
450
- // Exotic Objects). The trap returns the same descriptors below.
451
- 'Object.defineProperty(ns_target, "__esModule", { value: true });',
452
- 'Object.defineProperty(ns_target, Symbol.toStringTag, { value: "Deferred Module" });',
453
- `${lt} ns = ns_target;`,
454
- `${cst} handler = {`,
455
- Template.indent([
456
- "__proto__: null,",
457
- // Per the TC39 import-defer proposal, `IsSymbolLikeNamespaceKey`
458
- // returns true for any Symbol-keyed access (and for "then"); such
459
- // accesses go through `OrdinaryGetOwnProperty` and must not
460
- // trigger evaluation of the deferred module. The Symbol checks
461
- // below short-circuit to the pre-populated target without
462
- // running `init()`.
463
- `${runtimeTemplate.method("get", "_, name", [
464
- "switch (name) {",
465
- Template.indent([
466
- 'case "__esModule": return true;',
467
- 'case Symbol.toStringTag: return "Deferred Module";',
468
- 'case "then": return undefined;'
469
- ]),
470
- "}",
471
- 'if (typeof name === "symbol") return ns_target[name];',
472
- init,
473
- "return ns[name];"
474
- ])},`,
475
- `${runtimeTemplate.method("has", "_, name", [
476
- "switch (name) {",
477
- Template.indent(
478
- [
479
- 'case "__esModule":',
480
- "case Symbol.toStringTag:",
391
+ synthesized
392
+ ? "if (cachedModule && cachedModule.error === undefined && !(mode & 8)) {"
393
+ : "",
394
+ synthesized
395
+ ? Template.indent([
396
+ `${lt} exports = cachedModule.exports;`,
481
397
  hasAsync
482
- ? `case ${RuntimeGlobals.deferredModuleAsyncTransitiveDependenciesSymbol}:`
398
+ ? `if (${RuntimeGlobals.asyncModuleExportSymbol} in exports) exports = exports[${RuntimeGlobals.asyncModuleExportSymbol}];`
483
399
  : "",
484
- Template.indent("return true;"),
485
- 'case "then":',
486
- Template.indent("return false;")
487
- ].filter(Boolean)
488
- ),
489
- "}",
490
- 'if (typeof name === "symbol") return name in ns_target;',
491
- init,
492
- "return name in ns;"
493
- ])},`,
494
- `${runtimeTemplate.method("ownKeys", "", [
495
- init,
496
- `${cst} filtered = Reflect.ownKeys(ns).filter(${runtimeTemplate.expressionFunction(
497
- 'x !== "then" && x !== Symbol.toStringTag',
498
- "x"
499
- )});`,
500
- `${cst} keys = ${
501
- runtimeTemplate.supportsSpread()
502
- ? "[...filtered, Symbol.toStringTag]"
503
- : "filtered.concat([Symbol.toStringTag])"
504
- };`,
505
- "return keys;"
506
- ])},`,
507
- `${runtimeTemplate.method("getOwnPropertyDescriptor", "_, name", [
508
- "switch (name) {",
400
+ `return byMode[mode] = ${RuntimeGlobals.createFakeNamespaceObject}(exports, mode);`
401
+ ])
402
+ : "",
403
+ synthesized ? "}" : "",
404
+ "",
405
+ `${lt} init = ${runtimeTemplate.basicFunction("", [
406
+ // A deferred namespace that forces evaluation of a module that is
407
+ // already evaluating (a cycle) must throw rather than expose its
408
+ // partial exports.
409
+ `${cst} evaluatingModule = __webpack_module_cache__[moduleId];`,
410
+ 'if (evaluatingModule !== undefined && (evaluatingModule.evaluating || evaluatingModule.evaluatingAsync)) throw new TypeError("Cannot access a deferred module namespace while the module is being evaluated");',
411
+ `ns = ${RuntimeGlobals.require}(moduleId);`,
412
+ hasAsync
413
+ ? `if (${RuntimeGlobals.asyncModuleExportSymbol} in ns) ns = ns[${RuntimeGlobals.asyncModuleExportSymbol}];`
414
+ : "",
415
+ "init = null;",
416
+ synthesized
417
+ ? "if (mode & 8 || mode & 4 && ns.__esModule && typeof ns === 'object') {"
418
+ : "",
509
419
  Template.indent([
510
- // Match the descriptors actually defined on `ns_target`
511
- // (non-configurable, non-writable, non-enumerable) so the
512
- // proxy invariant holds for both the trap result and any
513
- // post-init forwarding via the deleted-handler path.
514
- 'case "__esModule": return { value: true, writable: false, enumerable: false, configurable: false };',
515
- 'case Symbol.toStringTag: return { value: "Deferred Module", writable: false, enumerable: false, configurable: false };',
516
- 'case "then": return undefined;'
420
+ // Drop only the read-side traps after init: with the
421
+ // resolved namespace's own keys mirrored onto
422
+ // `ns_target` below, the default `Reflect` behavior
423
+ // returns the right values via the live-binding
424
+ // getters, so we no longer need to intercept `get` /
425
+ // `has` / `ownKeys` / `getOwnPropertyDescriptor`.
426
+ //
427
+ // The mutation traps (`set`, `deleteProperty`,
428
+ // `defineProperty`) are kept because per the TC39
429
+ // import-defer spec, `[[Set]]` / `[[Delete]]` /
430
+ // `[[DefineOwnProperty]]` on a Deferred Module
431
+ // Namespace Exotic Object never succeed — and the
432
+ // proxy target itself remains extensible
433
+ // (architecturally we cannot freeze it up-front),
434
+ // so without these traps `ns.notExported = "x"`
435
+ // after evaluation would silently create a property
436
+ // on the target instead of returning false.
437
+ // A sealed target holds placeholder values, so the read traps stay to
438
+ // keep the live bindings visible.
439
+ sealed && synthesized ? "if (!exportNames) {" : "",
440
+ synthesized
441
+ ? Template.indent([
442
+ "delete handler.get;",
443
+ "delete handler.has;",
444
+ "delete handler.ownKeys;",
445
+ "delete handler.getOwnPropertyDescriptor;"
446
+ ])
447
+ : "",
448
+ sealed && synthesized ? "}" : ""
517
449
  ]),
518
- "}",
519
- 'if (typeof name === "symbol") return Reflect.getOwnPropertyDescriptor(ns_target, name);',
520
- init,
521
- `${lt} desc = Reflect.getOwnPropertyDescriptor(ns, name);`,
522
- 'if (mode & 2 && name == "default" && !desc) {',
523
- Template.indent("desc = { value: ns, configurable: true };"),
524
- "}",
525
- "return desc;"
526
- ])},`,
527
- // `defineProperty` always rejects, but per the TC39 spec it
528
- // must still trigger evaluation for string keys (the spec
529
- // algorithm calls `[[GetOwnProperty]]` first, which forces
530
- // evaluation on a deferred namespace). Symbol keys go through
531
- // OrdinaryDefineOwnProperty and do not trigger eval.
532
- `${runtimeTemplate.method("defineProperty", "_, name", [
533
- 'if (typeof name === "symbol" || name === "then") return false;',
534
- init,
535
- "return false;"
536
- ])},`,
537
- // `deleteProperty` rejects, but per the TC39 spec it must
538
- // still trigger evaluation for string keys (the spec
539
- // algorithm calls `GetModuleExportsList` for non-symbol-like
540
- // keys, forcing evaluation on a deferred namespace).
541
- `${runtimeTemplate.method("deleteProperty", "_, name", [
542
- 'if (typeof name === "symbol" || name === "then") return false;',
543
- init,
544
- "return false;"
545
- ])},`,
546
- // `set` always returns false without triggering evaluation —
547
- // the spec [[Set]] algorithm for Module Namespaces is just
548
- // "return false" (no [[GetOwnProperty]], no eval).
549
- `set: ${runtimeTemplate.returningFunction("false")},`
550
- ]),
551
- "}",
552
- // we don't fully emulate ES Module semantics in this Proxy to align with normal webpack esm namespace object.
553
- "return byMode[mode] = new Proxy(ns_target, handler);"
554
- ])};`;
450
+ synthesized ? "} else {" : "",
451
+ synthesized
452
+ ? Template.indent([
453
+ `ns = ${RuntimeGlobals.createFakeNamespaceObject}(ns, mode);`
454
+ ])
455
+ : "",
456
+ synthesized ? "}" : "",
457
+ // Mirror own properties from the resolved namespace onto the proxy
458
+ // target so that proxy invariants hold for callers that structurally
459
+ // introspect via `Object.keys` / `Object.getOwnPropertyNames` /
460
+ // `Object.getOwnPropertyDescriptor`: when our trap reports a
461
+ // non-configurable descriptor for a key, the target must also have
462
+ // that key with a matching descriptor.
463
+ //
464
+ // `__esModule` and `Symbol.toStringTag` are intentionally skipped:
465
+ // the proxy synthesizes "Deferred Module" / true regardless of what
466
+ // the underlying namespace exposes (per the TC39 import-defer
467
+ // proposal, the [[StringTag]] of a Deferred Module Namespace
468
+ // Exotic Object is "Deferred Module"), and the target was already
469
+ // pre-populated with those values below.
470
+ synthesized
471
+ ? `${cst} keys = ${sealed ? "exportNames ? [] : " : ""}Reflect.ownKeys(ns);`
472
+ : "",
473
+ synthesized ? "for (var i = 0; i < keys.length; i++) {" : "",
474
+ synthesized
475
+ ? Template.indent([
476
+ `${cst} k = keys[i];`,
477
+ 'if (k === "__esModule" || k === Symbol.toStringTag) continue;',
478
+ `if (!${runtimeTemplate.objectHasOwn("ns_target", "k")}) {`,
479
+ Template.indent([
480
+ "try { Object.defineProperty(ns_target, k, Reflect.getOwnPropertyDescriptor(ns, k)); } catch (_) {}"
481
+ ]),
482
+ "}"
483
+ ])
484
+ : "",
485
+ synthesized ? "}" : ""
486
+ ])};`,
487
+ "",
488
+ // The proxy target is a fresh placeholder, separate from
489
+ // `__webpack_module_deferred_exports__[moduleId]` (which is reused
490
+ // by `__webpack_require__` as `module.exports` for deferred-loaded
491
+ // modules and would conflict with our pre-populated synthetic
492
+ // `__esModule` / `Symbol.toStringTag` non-configurable properties).
493
+ // Using a dedicated target keeps the proxy invariant-compliant
494
+ // without interfering with the module's own exports object.
495
+ `${cst} ns_target = { __proto__: null };`,
496
+ // With the export list known at build time the target carries the spec's
497
+ // keys and is sealed, so `[[IsExtensible]]` is false up front.
498
+ sealed
499
+ ? `${synthesized ? "if (exportNames) " : ""}for (var e = 0; e < exportNames.length; e++) ns_target[exportNames[e]] = undefined;`
500
+ : "",
501
+ // Pre-populate the synthetic deferred-namespace properties with
502
+ // fully non-configurable, non-writable, non-enumerable descriptors
503
+ // (matching the TC39 import-defer spec for Module Namespace
504
+ // Exotic Objects). The trap returns the same descriptors below.
505
+ // `__esModule` is not one of the spec's keys, so a sealed namespace omits
506
+ // it; the synthesized form keeps it for interop.
507
+ synthesized
508
+ ? `${sealed ? "if (!exportNames) " : ""}Object.defineProperty(ns_target, "__esModule", { value: true });`
509
+ : "",
510
+ 'Object.defineProperty(ns_target, Symbol.toStringTag, { value: "Deferred Module" });',
511
+ sealed
512
+ ? `${synthesized ? "if (exportNames) " : ""}Object.seal(ns_target);`
513
+ : "",
514
+ `${lt} ns = ns_target;`,
515
+ `${cst} handler = {`,
516
+ Template.indent([
517
+ "__proto__: null,",
518
+ // Per the TC39 import-defer proposal, `IsSymbolLikeNamespaceKey`
519
+ // returns true for any Symbol-keyed access (and for "then"); such
520
+ // accesses go through `OrdinaryGetOwnProperty` and must not
521
+ // trigger evaluation of the deferred module. The Symbol checks
522
+ // below short-circuit to the pre-populated target without
523
+ // running `init()`.
524
+ `${runtimeTemplate.method("get", "_, name", [
525
+ "switch (name) {",
526
+ Template.indent([
527
+ // webpack's interop marker, read as a property by
528
+ // `o.__esModule ? o.default : o`, so a sealed namespace
529
+ // answers it too even though it is not one of its keys.
530
+ 'case "__esModule": return true;',
531
+ 'case Symbol.toStringTag: return "Deferred Module";',
532
+ 'case "then": return undefined;'
533
+ ]),
534
+ "}",
535
+ 'if (typeof name === "symbol") return ns_target[name];',
536
+ init,
537
+ // A sealed namespace has exactly the spec's keys, so anything
538
+ // else is absent rather than read off the exports object.
539
+ sealed
540
+ ? `${synthesized ? "if (exportNames) " : ""}return name in ns_target ? ns[name] : undefined;`
541
+ : "",
542
+ synthesized ? "return ns[name];" : ""
543
+ ])},`,
544
+ `${runtimeTemplate.method("has", "_, name", [
545
+ "switch (name) {",
546
+ Template.indent(
547
+ [
548
+ synthesized
549
+ ? `case "__esModule": ${sealed ? "if (!exportNames) " : ""}return true;${sealed ? " break;" : ""}`
550
+ : "",
551
+ "case Symbol.toStringTag:",
552
+ hasAsync
553
+ ? `case ${RuntimeGlobals.deferredModuleAsyncTransitiveDependenciesSymbol}:`
554
+ : "",
555
+ Template.indent("return true;"),
556
+ 'case "then":',
557
+ Template.indent("return false;")
558
+ ].filter(Boolean)
559
+ ),
560
+ "}",
561
+ 'if (typeof name === "symbol") return name in ns_target;',
562
+ init,
563
+ sealed
564
+ ? `${synthesized ? "if (exportNames) " : ""}return name in ns_target;`
565
+ : "",
566
+ synthesized ? "return name in ns;" : ""
567
+ ])},`,
568
+ `${runtimeTemplate.method("ownKeys", "", [
569
+ init,
570
+ // The sealed target already carries the spec's keys, sorted.
571
+ sealed
572
+ ? `${synthesized ? "if (exportNames) " : ""}return Reflect.ownKeys(ns_target);`
573
+ : "",
574
+ synthesized
575
+ ? `${cst} filtered = Reflect.ownKeys(ns).filter(${runtimeTemplate.expressionFunction(
576
+ 'x !== "then" && x !== Symbol.toStringTag',
577
+ "x"
578
+ )});`
579
+ : "",
580
+ synthesized
581
+ ? `${cst} keys = ${
582
+ runtimeTemplate.supportsSpread()
583
+ ? "[...filtered, Symbol.toStringTag]"
584
+ : "filtered.concat([Symbol.toStringTag])"
585
+ };`
586
+ : "",
587
+ synthesized ? "return keys;" : ""
588
+ ])},`,
589
+ `${runtimeTemplate.method("getOwnPropertyDescriptor", "_, name", [
590
+ "switch (name) {",
591
+ Template.indent([
592
+ // Match the descriptors actually defined on `ns_target`
593
+ // (non-configurable, non-writable, non-enumerable) so the
594
+ // proxy invariant holds for both the trap result and any
595
+ // post-init forwarding via the deleted-handler path.
596
+ synthesized
597
+ ? `case "__esModule": ${sealed ? "if (!exportNames) " : ""}return { value: true, writable: false, enumerable: false, configurable: false };${sealed ? " break;" : ""}`
598
+ : "",
599
+ 'case Symbol.toStringTag: return { value: "Deferred Module", writable: false, enumerable: false, configurable: false };',
600
+ 'case "then": return undefined;'
601
+ ]),
602
+ "}",
603
+ 'if (typeof name === "symbol") return Reflect.getOwnPropertyDescriptor(ns_target, name);',
604
+ init,
605
+ // A namespace exposes data properties; webpack backs the exports
606
+ // with getters, so the spec's shape is synthesized here.
607
+ sealed
608
+ ? `${synthesized ? "if (exportNames) " : ""}return name in ns_target ? { value: ns[name], writable: true, enumerable: true, configurable: false } : undefined;`
609
+ : "",
610
+ synthesized
611
+ ? `${lt} desc = Reflect.getOwnPropertyDescriptor(ns, name);`
612
+ : "",
613
+ synthesized ? 'if (mode & 2 && name == "default" && !desc) {' : "",
614
+ synthesized
615
+ ? Template.indent("desc = { value: ns, configurable: true };")
616
+ : "",
617
+ synthesized ? "}" : "",
618
+ synthesized ? "return desc;" : ""
619
+ ])},`,
620
+ // `defineProperty` always rejects, but per the TC39 spec it
621
+ // must still trigger evaluation for string keys (the spec
622
+ // algorithm calls `[[GetOwnProperty]]` first, which forces
623
+ // evaluation on a deferred namespace). Symbol keys go through
624
+ // OrdinaryDefineOwnProperty and do not trigger eval.
625
+ `${runtimeTemplate.method("defineProperty", "_, name", [
626
+ 'if (typeof name === "symbol" || name === "then") return false;',
627
+ init,
628
+ "return false;"
629
+ ])},`,
630
+ // `deleteProperty` rejects, but per the TC39 spec it must
631
+ // still trigger evaluation for string keys (the spec
632
+ // algorithm calls `GetModuleExportsList` for non-symbol-like
633
+ // keys, forcing evaluation on a deferred namespace).
634
+ `${runtimeTemplate.method("deleteProperty", "_, name", [
635
+ 'if (typeof name === "symbol" || name === "then") return false;',
636
+ init,
637
+ "return false;"
638
+ ])},`,
639
+ // `set` always returns false without triggering evaluation —
640
+ // the spec [[Set]] algorithm for Module Namespaces is just
641
+ // "return false" (no [[GetOwnProperty]], no eval).
642
+ `set: ${runtimeTemplate.returningFunction("false")},`
643
+ ]),
644
+ "}",
645
+ // we don't fully emulate ES Module semantics in this Proxy to align with normal webpack esm namespace object.
646
+ "return byMode[mode] = new Proxy(ns_target, handler);"
647
+ ]
648
+ )};`;
555
649
  }
556
650
  }
557
651
 
652
+ /**
653
+ * The module's export names, sorted, when the graph knows them exhaustively.
654
+ * Only a `namespace` module takes the sealed path, and names are never mangled
655
+ * here: materializing a namespace clears `canMangleUse` on every export.
656
+ * @param {ModuleGraph} moduleGraph the module graph
657
+ * @param {Module} module the deferred module
658
+ * @param {ExportsType} exportsType the module's exports type
659
+ * @returns {string[] | null} sorted export names, or null when unknown
660
+ */
661
+ const getKnownExportNames = (moduleGraph, module, exportsType) => {
662
+ if (exportsType !== "namespace") return null;
663
+ const exportsInfo = moduleGraph.getExportsInfo(module);
664
+ if (exportsInfo.otherExportsInfo.provided !== false) return null;
665
+ const names = [];
666
+ for (const exportInfo of exportsInfo.orderedExports) {
667
+ // `false` is a definitive "not an export" (webpack records `__esModule`
668
+ // that way); anything but a definitive answer means the list is unknown.
669
+ if (exportInfo.provided === false) continue;
670
+ if (exportInfo.provided !== true) return null;
671
+ // A namespace never exposes `then`, so it is not one of the spec's keys.
672
+ if (exportInfo.name === "then") continue;
673
+ names.push(exportInfo.name);
674
+ }
675
+ return names.sort();
676
+ };
677
+
558
678
  module.exports.MakeDeferredNamespaceObjectRuntimeModule =
559
679
  MakeDeferredNamespaceObjectRuntimeModule;
560
680
  module.exports.MakeOptimizedDeferredNamespaceObjectRuntimeModule =
561
681
  MakeOptimizedDeferredNamespaceObjectRuntimeModule;
562
682
  module.exports.getDeferredCycleModuleIds = getDeferredCycleModuleIds;
563
683
  module.exports.getDeferredCycleModules = getDeferredCycleModules;
684
+ module.exports.getKnownExportNames = getKnownExportNames;
564
685
  module.exports.getMakeDeferredNamespaceModeFromExportsType =
565
686
  getMakeDeferredNamespaceModeFromExportsType;
566
687
  module.exports.getOptimizedDeferredModule = getOptimizedDeferredModule;
@@ -23,6 +23,15 @@ class NonceRuntimeModule extends RuntimeModule {
23
23
  return false;
24
24
  }
25
25
 
26
+ /**
27
+ * The `[handlerMap, key]` pairs this module installs onto a chunk handler map
28
+ * such as `__webpack_require__.f`, or `null` where it cannot name them.
29
+ * @returns {[string, string][] | null} installed chunk handlers (do not mutate)
30
+ */
31
+ getInstalledChunkHandlers() {
32
+ return RuntimeModule.NO_CHUNK_HANDLERS;
33
+ }
34
+
26
35
  /**
27
36
  * Generates runtime code for this runtime module.
28
37
  * @returns {string | null} runtime code