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
@@ -290,13 +290,13 @@ class MakeOptimizedDeferredNamespaceObjectRuntimeModule extends HelperRuntimeMod
290
290
  ]),
291
291
  "};",
292
292
  hasAsync
293
- ? // `GatherAsynchronousTransitiveDependencies` skips a module that is
294
- // already evaluating, and evaluates the rest right here.
293
+ ? // `evaluating` is on the stack, so awaiting it would deadlock;
294
+ // `evaluating-async` is suspended and must still be awaited.
295
295
  `if(isAsync) obj[${RuntimeGlobals.deferredModuleAsyncTransitiveDependenciesSymbol}] = asyncDeps.filter(${runtimeTemplate.basicFunction(
296
296
  "id",
297
297
  [
298
298
  `${cst} dep = __webpack_module_cache__[id];`,
299
- "if (dep && (dep.evaluating || dep.evaluatingAsync)) return false;",
299
+ "if (dep && dep.evaluating) return false;",
300
300
  "r(id);",
301
301
  "return true;"
302
302
  ]
@@ -322,11 +322,17 @@ class MakeDeferredNamespaceObjectRuntimeModule extends HelperRuntimeModule {
322
322
 
323
323
  /**
324
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
325
327
  */
326
- constructor(hasAsyncRuntime) {
328
+ constructor(hasAsyncRuntime, sealed, synthesized) {
327
329
  super("make deferred namespace object");
328
330
  /** @type {boolean} */
329
331
  this.hasAsyncRuntime = hasAsyncRuntime;
332
+ /** @type {boolean} */
333
+ this.sealed = sealed;
334
+ /** @type {boolean} */
335
+ this.synthesized = synthesized;
330
336
  }
331
337
 
332
338
  /**
@@ -340,237 +346,342 @@ class MakeDeferredNamespaceObjectRuntimeModule extends HelperRuntimeModule {
340
346
  const lt = runtimeTemplate.renderLet();
341
347
  const fn = RuntimeGlobals.makeDeferredNamespaceObject;
342
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;
343
353
  const init = `${runtimeTemplate.optionalChaining("init", "()")};`;
344
- return `${fn} = ${runtimeTemplate.basicFunction("moduleId, mode", [
345
- // Per the TC39 import-defer spec, deferred namespaces are
346
- // distinct from their eager counterparts and the same module
347
- // referenced from multiple defer-import sites must yield the
348
- // same object. Cache the Proxy / fake namespace per-moduleId so
349
- // repeated calls (including across files) share identity.
350
- //
351
- // Bit 16 (`createFakeNamespaceObject`'s "return value when
352
- // it's Promise-like" flag added by
353
- // `RuntimeTemplate.moduleNamespacePromise` for dynamic
354
- // imports) is irrelevant for deferred namespaces — the value
355
- // passed into `createFakeNamespaceObject` here is always the
356
- // resolved module exports (after unwrapping the async-module
357
- // export symbol when present), never a Promise. Strip it
358
- // once so all downstream behavior, the cache key, and the
359
- // `createFakeNamespaceObject` call below see the same shape
360
- // mode. This keeps static defer (mode 8) and dynamic
361
- // `await import.defer` (mode 8 | 16) sharing the same
362
- // Deferred Module Namespace object, while still keying by
363
- // `(moduleId, mode)` so distinct exports-type shapes
364
- // (e.g. one importer treats a CJS module as
365
- // "default-with-named", another as "namespace") get
366
- // distinct cache entries.
367
- "mode &= ~16;",
368
- `${lt} byMode = __webpack_module_deferred_namespace_cache__[moduleId];`,
369
- "if (byMode && byMode[mode] !== undefined) return byMode[mode];",
370
- "if (!byMode) byMode = __webpack_module_deferred_namespace_cache__[moduleId] = {};",
371
- `${cst} cachedModule = __webpack_module_cache__[moduleId];`,
372
- "if (cachedModule && cachedModule.error === undefined && !(mode & 8)) {",
373
- Template.indent([
374
- `${lt} exports = cachedModule.exports;`,
375
- hasAsync
376
- ? `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;"
377
384
  : "",
378
- `return byMode[mode] = ${RuntimeGlobals.createFakeNamespaceObject}(exports, mode);`
379
- ]),
380
- "}",
381
- "",
382
- `${lt} init = ${runtimeTemplate.basicFunction("", [
383
- // A deferred namespace that forces evaluation of a module that is
384
- // already evaluating (a cycle) must throw rather than expose its
385
- // partial exports.
386
- `${cst} evaluatingModule = __webpack_module_cache__[moduleId];`,
387
- 'if (evaluatingModule !== undefined && (evaluatingModule.evaluating || evaluatingModule.evaluatingAsync)) throw new TypeError("Cannot access a deferred module namespace while the module is being evaluated");',
388
- `ns = ${RuntimeGlobals.require}(moduleId);`,
389
- hasAsync
390
- ? `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];`
391
390
  : "",
392
- "init = null;",
393
- "if (mode & 8 || mode & 4 && ns.__esModule && typeof ns === 'object') {",
394
- Template.indent([
395
- // Drop only the read-side traps after init: with the
396
- // resolved namespace's own keys mirrored onto
397
- // `ns_target` below, the default `Reflect` behavior
398
- // returns the right values via the live-binding
399
- // getters, so we no longer need to intercept `get` /
400
- // `has` / `ownKeys` / `getOwnPropertyDescriptor`.
401
- //
402
- // The mutation traps (`set`, `deleteProperty`,
403
- // `defineProperty`) are kept because per the TC39
404
- // import-defer spec, `[[Set]]` / `[[Delete]]` /
405
- // `[[DefineOwnProperty]]` on a Deferred Module
406
- // Namespace Exotic Object never succeed — and the
407
- // proxy target itself remains extensible
408
- // (architecturally we cannot freeze it up-front),
409
- // so without these traps `ns.notExported = "x"`
410
- // after evaluation would silently create a property
411
- // on the target instead of returning false.
412
- "delete handler.get;",
413
- "delete handler.has;",
414
- "delete handler.ownKeys;",
415
- "delete handler.getOwnPropertyDescriptor;"
416
- ]),
417
- "} else {",
418
- Template.indent([
419
- `ns = ${RuntimeGlobals.createFakeNamespaceObject}(ns, mode);`
420
- ]),
421
- "}",
422
- // Mirror own properties from the resolved namespace onto the proxy
423
- // target so that proxy invariants hold for callers that structurally
424
- // introspect via `Object.keys` / `Object.getOwnPropertyNames` /
425
- // `Object.getOwnPropertyDescriptor`: when our trap reports a
426
- // non-configurable descriptor for a key, the target must also have
427
- // that key with a matching descriptor.
428
- //
429
- // `__esModule` and `Symbol.toStringTag` are intentionally skipped:
430
- // the proxy synthesizes "Deferred Module" / true regardless of what
431
- // the underlying namespace exposes (per the TC39 import-defer
432
- // proposal, the [[StringTag]] of a Deferred Module Namespace
433
- // Exotic Object is "Deferred Module"), and the target was already
434
- // pre-populated with those values below.
435
- `${cst} keys = Reflect.ownKeys(ns);`,
436
- "for (var i = 0; i < keys.length; i++) {",
437
- Template.indent([
438
- `${cst} k = keys[i];`,
439
- 'if (k === "__esModule" || k === Symbol.toStringTag) continue;',
440
- `if (!${runtimeTemplate.objectHasOwn("ns_target", "k")}) {`,
441
- Template.indent([
442
- "try { Object.defineProperty(ns_target, k, Reflect.getOwnPropertyDescriptor(ns, k)); } catch (_) {}"
443
- ]),
444
- "}"
445
- ]),
446
- "}"
447
- ])};`,
448
- "",
449
- // The proxy target is a fresh placeholder, separate from
450
- // `__webpack_module_deferred_exports__[moduleId]` (which is reused
451
- // by `__webpack_require__` as `module.exports` for deferred-loaded
452
- // modules and would conflict with our pre-populated synthetic
453
- // `__esModule` / `Symbol.toStringTag` non-configurable properties).
454
- // Using a dedicated target keeps the proxy invariant-compliant
455
- // without interfering with the module's own exports object.
456
- `${cst} ns_target = { __proto__: null };`,
457
- // Pre-populate the synthetic deferred-namespace properties with
458
- // fully non-configurable, non-writable, non-enumerable descriptors
459
- // (matching the TC39 import-defer spec for Module Namespace
460
- // Exotic Objects). The trap returns the same descriptors below.
461
- 'Object.defineProperty(ns_target, "__esModule", { value: true });',
462
- 'Object.defineProperty(ns_target, Symbol.toStringTag, { value: "Deferred Module" });',
463
- `${lt} ns = ns_target;`,
464
- `${cst} handler = {`,
465
- Template.indent([
466
- "__proto__: null,",
467
- // Per the TC39 import-defer proposal, `IsSymbolLikeNamespaceKey`
468
- // returns true for any Symbol-keyed access (and for "then"); such
469
- // accesses go through `OrdinaryGetOwnProperty` and must not
470
- // trigger evaluation of the deferred module. The Symbol checks
471
- // below short-circuit to the pre-populated target without
472
- // running `init()`.
473
- `${runtimeTemplate.method("get", "_, name", [
474
- "switch (name) {",
475
- Template.indent([
476
- 'case "__esModule": return true;',
477
- 'case Symbol.toStringTag: return "Deferred Module";',
478
- 'case "then": return undefined;'
479
- ]),
480
- "}",
481
- 'if (typeof name === "symbol") return ns_target[name];',
482
- init,
483
- "return ns[name];"
484
- ])},`,
485
- `${runtimeTemplate.method("has", "_, name", [
486
- "switch (name) {",
487
- Template.indent(
488
- [
489
- 'case "__esModule":',
490
- "case Symbol.toStringTag:",
391
+ synthesized
392
+ ? "if (cachedModule && cachedModule.error === undefined && !(mode & 8)) {"
393
+ : "",
394
+ synthesized
395
+ ? Template.indent([
396
+ `${lt} exports = cachedModule.exports;`,
491
397
  hasAsync
492
- ? `case ${RuntimeGlobals.deferredModuleAsyncTransitiveDependenciesSymbol}:`
398
+ ? `if (${RuntimeGlobals.asyncModuleExportSymbol} in exports) exports = exports[${RuntimeGlobals.asyncModuleExportSymbol}];`
493
399
  : "",
494
- Template.indent("return true;"),
495
- 'case "then":',
496
- Template.indent("return false;")
497
- ].filter(Boolean)
498
- ),
499
- "}",
500
- 'if (typeof name === "symbol") return name in ns_target;',
501
- init,
502
- "return name in ns;"
503
- ])},`,
504
- `${runtimeTemplate.method("ownKeys", "", [
505
- init,
506
- `${cst} filtered = Reflect.ownKeys(ns).filter(${runtimeTemplate.expressionFunction(
507
- 'x !== "then" && x !== Symbol.toStringTag',
508
- "x"
509
- )});`,
510
- `${cst} keys = ${
511
- runtimeTemplate.supportsSpread()
512
- ? "[...filtered, Symbol.toStringTag]"
513
- : "filtered.concat([Symbol.toStringTag])"
514
- };`,
515
- "return keys;"
516
- ])},`,
517
- `${runtimeTemplate.method("getOwnPropertyDescriptor", "_, name", [
518
- "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
+ : "",
519
419
  Template.indent([
520
- // Match the descriptors actually defined on `ns_target`
521
- // (non-configurable, non-writable, non-enumerable) so the
522
- // proxy invariant holds for both the trap result and any
523
- // post-init forwarding via the deleted-handler path.
524
- 'case "__esModule": return { value: true, writable: false, enumerable: false, configurable: false };',
525
- 'case Symbol.toStringTag: return { value: "Deferred Module", writable: false, enumerable: false, configurable: false };',
526
- '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 ? "}" : ""
527
449
  ]),
528
- "}",
529
- 'if (typeof name === "symbol") return Reflect.getOwnPropertyDescriptor(ns_target, name);',
530
- init,
531
- `${lt} desc = Reflect.getOwnPropertyDescriptor(ns, name);`,
532
- 'if (mode & 2 && name == "default" && !desc) {',
533
- Template.indent("desc = { value: ns, configurable: true };"),
534
- "}",
535
- "return desc;"
536
- ])},`,
537
- // `defineProperty` always rejects, but per the TC39 spec it
538
- // must still trigger evaluation for string keys (the spec
539
- // algorithm calls `[[GetOwnProperty]]` first, which forces
540
- // evaluation on a deferred namespace). Symbol keys go through
541
- // OrdinaryDefineOwnProperty and do not trigger eval.
542
- `${runtimeTemplate.method("defineProperty", "_, name", [
543
- 'if (typeof name === "symbol" || name === "then") return false;',
544
- init,
545
- "return false;"
546
- ])},`,
547
- // `deleteProperty` rejects, but per the TC39 spec it must
548
- // still trigger evaluation for string keys (the spec
549
- // algorithm calls `GetModuleExportsList` for non-symbol-like
550
- // keys, forcing evaluation on a deferred namespace).
551
- `${runtimeTemplate.method("deleteProperty", "_, name", [
552
- 'if (typeof name === "symbol" || name === "then") return false;',
553
- init,
554
- "return false;"
555
- ])},`,
556
- // `set` always returns false without triggering evaluation —
557
- // the spec [[Set]] algorithm for Module Namespaces is just
558
- // "return false" (no [[GetOwnProperty]], no eval).
559
- `set: ${runtimeTemplate.returningFunction("false")},`
560
- ]),
561
- "}",
562
- // we don't fully emulate ES Module semantics in this Proxy to align with normal webpack esm namespace object.
563
- "return byMode[mode] = new Proxy(ns_target, handler);"
564
- ])};`;
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
+ )};`;
565
649
  }
566
650
  }
567
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
+
568
678
  module.exports.MakeDeferredNamespaceObjectRuntimeModule =
569
679
  MakeDeferredNamespaceObjectRuntimeModule;
570
680
  module.exports.MakeOptimizedDeferredNamespaceObjectRuntimeModule =
571
681
  MakeOptimizedDeferredNamespaceObjectRuntimeModule;
572
682
  module.exports.getDeferredCycleModuleIds = getDeferredCycleModuleIds;
573
683
  module.exports.getDeferredCycleModules = getDeferredCycleModules;
684
+ module.exports.getKnownExportNames = getKnownExportNames;
574
685
  module.exports.getMakeDeferredNamespaceModeFromExportsType =
575
686
  getMakeDeferredNamespaceModeFromExportsType;
576
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