@depup/webpack 5.110.1-depup.0 → 5.111.1-depup.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 (304) hide show
  1. package/README.md +7 -8
  2. package/changes.json +7 -11
  3. package/lib/APIPlugin.js +26 -11
  4. package/lib/AutomaticPrefetchPlugin.js +1 -1
  5. package/lib/Cache.js +8 -3
  6. package/lib/CacheFacade.js +1 -1
  7. package/lib/ChunkGraph.js +20 -18
  8. package/lib/CircularModulesPlugin.js +157 -55
  9. package/lib/CleanPlugin.js +2 -2
  10. package/lib/CompatibilityPlugin.js +3 -4
  11. package/lib/Compilation.js +337 -338
  12. package/lib/Compiler.js +213 -51
  13. package/lib/ConcatenationScope.js +25 -35
  14. package/lib/ConstPlugin.js +16 -132
  15. package/lib/CopyPlugin.js +1054 -0
  16. package/lib/DefinePlugin.js +24 -8
  17. package/lib/DependencyTemplate.js +2 -1
  18. package/lib/DotenvPlugin.js +64 -40
  19. package/lib/ErrorHelpers.js +113 -0
  20. package/lib/ExportsInfo.js +30 -16
  21. package/lib/ExternalModule.js +47 -22
  22. package/lib/FileSystemInfo.js +17 -14
  23. package/lib/FlagDependencyExportsPlugin.js +53 -34
  24. package/lib/FlagDependencyUsagePlugin.js +17 -15
  25. package/lib/Generator.js +24 -2
  26. package/lib/HotModuleReplacementPlugin.js +55 -7
  27. package/lib/IgnorePlugin.js +1 -1
  28. package/lib/JavascriptMetaInfoPlugin.js +5 -3
  29. package/lib/LoaderOptionsPlugin.js +1 -1
  30. package/lib/MainTemplate.js +5 -1
  31. package/lib/Module.js +19 -10
  32. package/lib/ModuleGraph.js +6 -9
  33. package/lib/MultiCompiler.js +7 -17
  34. package/lib/MultiWatching.js +1 -1
  35. package/lib/NormalModule.js +148 -70
  36. package/lib/NormalModuleFactory.js +1 -1
  37. package/lib/RuntimeGlobals.js +21 -7
  38. package/lib/RuntimeModule.js +28 -12
  39. package/lib/RuntimePlugin.js +33 -3
  40. package/lib/RuntimeTemplate.js +1147 -847
  41. package/lib/SourceMapDevToolPlugin.js +54 -104
  42. package/lib/TemplatedPathPlugin.js +16 -59
  43. package/lib/Watching.js +9 -0
  44. package/lib/WebpackOptionsApply.js +84 -91
  45. package/lib/asset/AssetBytesGenerator.js +7 -1
  46. package/lib/asset/AssetGenerator.js +50 -24
  47. package/lib/asset/AssetModule.js +3 -0
  48. package/lib/asset/AssetSourceGenerator.js +7 -1
  49. package/lib/asset/WebManifestParser.js +7 -5
  50. package/lib/async-modules/AsyncModuleHelpers.js +10 -4
  51. package/lib/buildChunkGraph.js +11 -15
  52. package/lib/cache/AddBuildDependenciesPlugin.js +33 -4
  53. package/lib/cache/IdleFileCachePlugin.js +2 -2
  54. package/lib/cache/MemoryCachePlugin.js +4 -4
  55. package/lib/cache/MemoryWithGcCachePlugin.js +7 -8
  56. package/lib/cache/PackFileCacheStrategy.js +17 -19
  57. package/lib/cache/getLazyHashedEtag.js +3 -5
  58. package/lib/config/browserslistTargetHandler.js +17 -4
  59. package/lib/config/defaults.js +162 -142
  60. package/lib/config/getClaimedAssetTypes.js +10 -11
  61. package/lib/config/normalization.js +100 -20
  62. package/lib/config/target.js +13 -4
  63. package/lib/container/ContainerReferencePlugin.js +6 -0
  64. package/lib/container/RemoteRuntimeModule.js +9 -0
  65. package/lib/container/declaredRemotes.js +39 -0
  66. package/lib/{ContextExclusionPlugin.js → context/ContextExclusionPlugin.js} +1 -1
  67. package/lib/{ContextModule.js → context/ContextModule.js} +54 -115
  68. package/lib/{ContextModuleFactory.js → context/ContextModuleFactory.js} +19 -21
  69. package/lib/{ContextReplacementPlugin.js → context/ContextReplacementPlugin.js} +4 -4
  70. package/lib/css/CssGenerator.js +27 -11
  71. package/lib/css/CssInjectStyleRuntimeModule.js +9 -0
  72. package/lib/css/CssLoadingRuntimeModule.js +92 -15
  73. package/lib/css/CssModule.js +1 -1
  74. package/lib/css/CssModulesPlugin.js +3 -10
  75. package/lib/css/CssParser.js +162 -31
  76. package/lib/css/CssServerStylesRuntimeModule.js +9 -0
  77. package/lib/css/cssMinify.js +43 -32
  78. package/lib/css/data.js +3526 -871
  79. package/lib/css/syntax.js +6455 -1237
  80. package/lib/debug/ProfilingPlugin.js +7 -4
  81. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +6 -3
  82. package/lib/dependencies/AMDRuntimeModules.js +18 -0
  83. package/lib/dependencies/CommonJsExportRequireDependency.js +13 -12
  84. package/lib/dependencies/CommonJsExportsParserPlugin.js +12 -13
  85. package/lib/dependencies/CommonJsImportsParserPlugin.js +5 -5
  86. package/lib/dependencies/CommonJsPlugin.js +19 -3
  87. package/lib/dependencies/CommonJsRequireDependency.js +32 -9
  88. package/lib/dependencies/CommonJsSelfReferenceDependency.js +2 -4
  89. package/lib/dependencies/ContextDependency.js +1 -1
  90. package/lib/dependencies/ContextDependencyHelpers.js +3 -9
  91. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +20 -7
  92. package/lib/dependencies/ContextElementDependency.js +1 -1
  93. package/lib/dependencies/CssIcssExportDependency.js +13 -9
  94. package/lib/dependencies/CssIcssImportDependency.js +3 -6
  95. package/lib/dependencies/CssUrlDependency.js +3 -5
  96. package/lib/dependencies/HarmonyCompatibilityDependency.js +67 -22
  97. package/lib/dependencies/HarmonyDetectionParserPlugin.js +3 -4
  98. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +10 -4
  99. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +12 -7
  100. package/lib/dependencies/HarmonyExportExpressionDependency.js +47 -33
  101. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +217 -34
  102. package/lib/dependencies/HarmonyExportInitFragment.js +110 -23
  103. package/lib/dependencies/HarmonyExportSpecifierDependency.js +25 -58
  104. package/lib/dependencies/HarmonyImportBareSideEffectDependency.js +59 -0
  105. package/lib/dependencies/HarmonyImportDependency.js +99 -41
  106. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +198 -25
  107. package/lib/dependencies/HarmonyImportSideEffectDependency.js +117 -4
  108. package/lib/dependencies/HarmonyImportSpecifierDependency.js +40 -3
  109. package/lib/dependencies/HarmonyModulesPlugin.js +20 -0
  110. package/lib/dependencies/HtmlEntryDependency.js +136 -104
  111. package/lib/dependencies/HtmlInlineScriptDependency.js +3 -4
  112. package/lib/dependencies/HtmlInlineStyleDependency.js +3 -4
  113. package/lib/dependencies/ImportContextDependency.js +43 -3
  114. package/lib/dependencies/ImportDependency.js +8 -29
  115. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -1
  116. package/lib/dependencies/ImportMetaGlobHelpers.js +1 -1
  117. package/lib/dependencies/ImportMetaMainDependency.js +104 -0
  118. package/lib/dependencies/ImportMetaPlugin.js +67 -25
  119. package/lib/dependencies/ImportParserPlugin.js +25 -15
  120. package/lib/dependencies/LoaderPlugin.js +26 -1
  121. package/lib/dependencies/RequireContextDependencyParserPlugin.js +1 -1
  122. package/lib/dependencies/RequireHeaderDependency.js +20 -21
  123. package/lib/dependencies/SystemRuntimeModule.js +9 -0
  124. package/lib/dependencies/URLContextDependency.js +1 -1
  125. package/lib/dependencies/URLDependency.js +6 -5
  126. package/lib/dependencies/WorkerAndWorkletPlugin.js +16 -21
  127. package/lib/dependencies/WorkerDependency.js +12 -18
  128. package/lib/dependencies/WorkletDependency.js +12 -20
  129. package/lib/dependencies/importOptionsCheck.js +47 -0
  130. package/lib/dll/DelegatedModule.js +18 -1
  131. package/lib/dll/DllReferencePlugin.js +11 -8
  132. package/lib/dll/LibManifestPlugin.js +1 -1
  133. package/lib/errors/AnalyzableBailoutsWarning.js +41 -0
  134. package/lib/errors/DotenvFileError.js +29 -0
  135. package/lib/errors/DuplicateModulesWarning.js +12 -7
  136. package/lib/errors/EmptyCopyPatternWarning.js +26 -0
  137. package/lib/errors/ExternalStarReexportError.js +44 -0
  138. package/lib/errors/HookWebpackError.js +3 -2
  139. package/lib/errors/ImportedBindingAssignmentError.js +30 -0
  140. package/lib/errors/MissingSourceMapsWarning.js +36 -0
  141. package/lib/errors/ModuleParseError.js +2 -1
  142. package/lib/errors/UnusedAssetsWarning.js +36 -0
  143. package/lib/errors/UnusedFederationWarning.js +35 -0
  144. package/lib/errors/UnusedModulesWarning.js +38 -0
  145. package/lib/esm/ExportWebpackRequireRuntimeModule.js +9 -0
  146. package/lib/esm/ModuleChunkFormatPlugin.js +28 -3
  147. package/lib/esm/ModuleChunkLoadingPlugin.js +21 -5
  148. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +91 -53
  149. package/lib/hmr/HotModuleReplacement.runtime.js +8 -2
  150. package/lib/hmr/HotModuleReplacementRuntimeModule.js +9 -0
  151. package/lib/hmr/LazyCompilationPlugin.js +3 -5
  152. package/lib/html/HtmlGenerator.js +72 -87
  153. package/lib/html/HtmlModulesPlugin.js +479 -215
  154. package/lib/html/HtmlParser.js +110 -147
  155. package/lib/html/builtinEmbeddedRenderer.js +107 -0
  156. package/lib/html/data.js +142 -7
  157. package/lib/html/htmlMinify.js +92 -122
  158. package/lib/html/syntax.js +2031 -1556
  159. package/lib/ids/HashedModuleIdsPlugin.js +2 -1
  160. package/lib/index.js +49 -3
  161. package/lib/javascript/ChunkFormatHelpers.js +4 -3
  162. package/lib/javascript/JavascriptGenerator.js +8 -1
  163. package/lib/javascript/JavascriptModule.js +1 -0
  164. package/lib/javascript/JavascriptModulesPlugin.js +76 -80
  165. package/lib/javascript/JavascriptParser.js +1970 -900
  166. package/lib/javascript/StartupHelpers.js +27 -3
  167. package/lib/javascript/data.js +172 -0
  168. package/lib/javascript/grammar.js +5546 -0
  169. package/lib/javascript/parser.js +1500 -0
  170. package/lib/javascript/regexp.js +1762 -0
  171. package/lib/javascript/regexpData.js +51 -0
  172. package/lib/javascript/syntax.js +9061 -5262
  173. package/lib/json/JsonGenerator.js +7 -1
  174. package/lib/library/ModuleLibraryPlugin.js +171 -132
  175. package/lib/loaders/LoaderRunner.js +170 -14
  176. package/lib/node/NodeWatchFileSystem.js +3 -9
  177. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +22 -0
  178. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +8 -15
  179. package/lib/node/RequireChunkLoadingRuntimeModule.js +22 -0
  180. package/lib/optimize/AggressiveMergingPlugin.js +3 -5
  181. package/lib/optimize/ConcatenatedModule.js +222 -125
  182. package/lib/optimize/ConstExportsPlugin.js +50 -34
  183. package/lib/optimize/FlagIncludedChunksPlugin.js +3 -11
  184. package/lib/optimize/InlineExports.js +20 -2
  185. package/lib/optimize/InnerGraphPlugin.js +7 -13
  186. package/lib/optimize/LimitChunkCountPlugin.js +5 -8
  187. package/lib/optimize/MangleExportsPlugin.js +13 -4
  188. package/lib/optimize/ModuleConcatenationPlugin.js +27 -5
  189. package/lib/optimize/RealContentHashPlugin.js +179 -44
  190. package/lib/optimize/SideEffectsFlagPlugin.js +24 -28
  191. package/lib/optimize/SplitChunksPlugin.js +2 -4
  192. package/lib/performance/AnalyzableBailoutsPlugin.js +115 -0
  193. package/lib/performance/BroadContextsPlugin.js +1 -1
  194. package/lib/performance/CacheEffectivenessPlugin.js +7 -7
  195. package/lib/performance/DuplicateModulesPlugin.js +57 -13
  196. package/lib/performance/EvalUsagePlugin.js +5 -2
  197. package/lib/performance/MissingSourceMapsPlugin.js +115 -0
  198. package/lib/performance/PureAnnotationsPlugin.js +6 -3
  199. package/lib/performance/SizeLimitsPlugin.js +2 -4
  200. package/lib/performance/TopLevelThisPlugin.js +5 -4
  201. package/lib/performance/UnusedAssetsPlugin.js +109 -0
  202. package/lib/performance/UnusedFederationPlugin.js +147 -0
  203. package/lib/performance/UnusedModulesPlugin.js +141 -0
  204. package/lib/performance/UnusedReexportsPlugin.js +1 -55
  205. package/lib/performance/isOnlyReexported.js +65 -0
  206. package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +25 -5
  207. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +8 -8
  208. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +9 -0
  209. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +9 -0
  210. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +9 -0
  211. package/lib/prefetch/ResourceHintPlugin.js +29 -35
  212. package/lib/prefetch/ResourceHintRuntimeModule.js +9 -0
  213. package/lib/prefetch/StartupAssetHintRuntimeModule.js +16 -10
  214. package/lib/rules/RuleSetCompiler.js +211 -4
  215. package/lib/runtime/AsyncModuleRuntimeModule.js +103 -67
  216. package/lib/runtime/AutoPublicPathRuntimeModule.js +9 -0
  217. package/lib/runtime/BaseUriRuntimeModule.js +9 -0
  218. package/lib/runtime/ChunkNameRuntimeModule.js +9 -0
  219. package/lib/runtime/EnsureChunkRuntimeModule.js +35 -16
  220. package/lib/runtime/GetChunkFilenameRuntimeModule.js +12 -4
  221. package/lib/runtime/GetFullHashRuntimeModule.js +9 -0
  222. package/lib/runtime/GetMainFilenameRuntimeModule.js +9 -0
  223. package/lib/runtime/GetWorkletBootstrapRuntimeModule.js +9 -0
  224. package/lib/runtime/GlobalRuntimeModule.js +11 -4
  225. package/lib/runtime/HasOwnPropertyRuntimeModule.js +9 -0
  226. package/lib/runtime/HelperRuntimeModule.js +10 -0
  227. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +313 -222
  228. package/lib/runtime/NonceRuntimeModule.js +9 -0
  229. package/lib/runtime/OnChunksLoadedRuntimeModule.js +67 -20
  230. package/lib/runtime/PublicPathRuntimeModule.js +9 -0
  231. package/lib/runtime/RuntimeIdRuntimeModule.js +9 -0
  232. package/lib/runtime/SpecNamespaceObjectRuntimeModule.js +90 -0
  233. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +9 -0
  234. package/lib/runtime/StartupEntrypointRuntimeModule.js +9 -0
  235. package/lib/runtime/SystemContextRuntimeModule.js +9 -0
  236. package/lib/runtime/ToBinaryRuntimeModule.js +9 -0
  237. package/lib/schemes/DataUriPlugin.js +3 -6
  238. package/lib/schemes/HttpUriPlugin.js +22 -5
  239. package/lib/schemes/VirtualUrlPlugin.js +1 -1
  240. package/lib/serialization/BinaryMiddleware.js +9 -9
  241. package/lib/serialization/FileMiddleware.js +31 -18
  242. package/lib/serialization/ObjectMiddleware.js +168 -139
  243. package/lib/sharing/ConsumeSharedPlugin.js +12 -0
  244. package/lib/sharing/ConsumeSharedRuntimeModule.js +11 -0
  245. package/lib/sharing/ShareRuntimeModule.js +9 -0
  246. package/lib/sharing/declaredShared.js +47 -0
  247. package/lib/stats/DefaultStatsFactoryPlugin.js +6 -5
  248. package/lib/stats/DefaultStatsPrinterPlugin.js +3 -0
  249. package/lib/typescript/TypeScriptPlugin.js +10 -13
  250. package/lib/url/URLParserPlugin.js +6 -8
  251. package/lib/util/ArrayQueue.js +3 -3
  252. package/lib/util/LocConverter.js +4 -7
  253. package/lib/util/SourceProcessor.js +115 -99
  254. package/lib/util/URLAbsoluteSpecifier.js +3 -1
  255. package/lib/util/async.js +292 -0
  256. package/lib/util/buildDiagnostics.js +69 -0
  257. package/lib/util/chainedImports.js +3 -4
  258. package/lib/util/concatenate.js +4 -4
  259. package/lib/util/conventions.js +5 -1
  260. package/lib/util/createHooksRegistry.js +1 -2
  261. package/lib/util/createMappings.js +25 -3
  262. package/lib/util/dataURL.js +2 -3
  263. package/lib/util/deterministicGrouping.js +8 -13
  264. package/lib/util/findGraphRoots.js +6 -13
  265. package/lib/util/fs.js +27 -1
  266. package/lib/util/globUtils.js +1 -1
  267. package/lib/util/handlerKeys.js +40 -0
  268. package/lib/util/hash/wasm-hash.js +3 -4
  269. package/lib/util/identifier.js +20 -0
  270. package/lib/util/internalSerializables.js +7 -1
  271. package/lib/util/registerExternalSerializer.js +6 -45
  272. package/lib/util/removeBOM.js +82 -1
  273. package/lib/util/semver.js +5 -3
  274. package/lib/wasm-async/AsyncWasmCompileRuntimeModule.js +14 -3
  275. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +14 -3
  276. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +6 -1
  277. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +5 -1
  278. package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +7 -12
  279. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +12 -4
  280. package/lib/wasm-sync/WebAssemblyGenerator.js +6 -1
  281. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +5 -1
  282. package/lib/wasm-sync/WebAssemblyUtils.js +2 -4
  283. package/lib/web/FetchCompileAsyncWasmPlugin.js +10 -6
  284. package/lib/web/FetchCompileWasmPlugin.js +4 -2
  285. package/lib/web/JsonpChunkLoadingRuntimeModule.js +36 -0
  286. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +19 -0
  287. package/package.json +55 -46
  288. package/schemas/WebpackOptions.check.js +1 -1
  289. package/schemas/WebpackOptions.json +388 -76
  290. package/schemas/plugins/LoaderOptionsPlugin.check.js +1 -1
  291. package/schemas/plugins/ManifestPlugin.check.js +1 -1
  292. package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
  293. package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
  294. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
  295. package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
  296. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  297. package/schemas/plugins/debug/ProfilingPlugin.check.js +1 -1
  298. package/schemas/plugins/dll/DllReferencePlugin.check.js +1 -1
  299. package/schemas/plugins/ids/HashedModuleIdsPlugin.check.js +1 -1
  300. package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
  301. package/types.d.ts +1795 -608
  302. package/lib/dependencies/ExportBindingInitFragment.js +0 -191
  303. package/lib/errors/EntrypointOverlapWarning.js +0 -45
  304. package/lib/performance/EntrypointOverlapPlugin.js +0 -122
@@ -263,11 +263,9 @@ class MakeOptimizedDeferredNamespaceObjectRuntimeModule extends HelperRuntimeMod
263
263
  Template.indent([
264
264
  "get a() {",
265
265
  Template.indent([
266
- // Forcing evaluation of a module that is currently evaluating
267
- // (a cycle reached through a deferred import) must throw rather
268
- // than expose its partial exports. `syncDeps` (present only for
269
- // cyclic deferred modules) carries the transitive static closure,
270
- // so an evaluating dependency is caught before any evaluation.
266
+ // Forcing a module that is already evaluating, a cycle reached
267
+ // through a deferred import, must throw rather than expose partial
268
+ // exports. `syncDeps` carries the closure that catches it first.
271
269
  `${cst} cachedModule = __webpack_module_cache__[moduleId];`,
272
270
  'if (cachedModule !== undefined && (cachedModule.evaluating || cachedModule.evaluatingAsync)) throw new TypeError("Cannot access a deferred module namespace while the module is being evaluated");',
273
271
  "if (syncDeps) for (var i = 0; i < syncDeps.length; i++) {",
@@ -290,7 +288,17 @@ class MakeOptimizedDeferredNamespaceObjectRuntimeModule extends HelperRuntimeMod
290
288
  ]),
291
289
  "};",
292
290
  hasAsync
293
- ? `if(isAsync) obj[${RuntimeGlobals.deferredModuleAsyncTransitiveDependenciesSymbol}] = asyncDeps;`
291
+ ? // `evaluating` is on the stack, so awaiting it would deadlock;
292
+ // `evaluating-async` is suspended and must still be awaited.
293
+ `if(isAsync) obj[${RuntimeGlobals.deferredModuleAsyncTransitiveDependenciesSymbol}] = asyncDeps.filter(${runtimeTemplate.basicFunction(
294
+ "id",
295
+ [
296
+ `${cst} dep = __webpack_module_cache__[id];`,
297
+ "if (dep && dep.evaluating) return false;",
298
+ "r(id);",
299
+ "return true;"
300
+ ]
301
+ )});`
294
302
  : "",
295
303
  "return obj;"
296
304
  ]),
@@ -312,11 +320,17 @@ class MakeDeferredNamespaceObjectRuntimeModule extends HelperRuntimeModule {
312
320
 
313
321
  /**
314
322
  * @param {boolean} hasAsyncRuntime if async module is used.
323
+ * @param {boolean} sealed a call site builds a namespace from a known export list
324
+ * @param {boolean} synthesized a call site builds one from the module's exports
315
325
  */
316
- constructor(hasAsyncRuntime) {
326
+ constructor(hasAsyncRuntime, sealed, synthesized) {
317
327
  super("make deferred namespace object");
318
328
  /** @type {boolean} */
319
329
  this.hasAsyncRuntime = hasAsyncRuntime;
330
+ /** @type {boolean} */
331
+ this.sealed = sealed;
332
+ /** @type {boolean} */
333
+ this.synthesized = synthesized;
320
334
  }
321
335
 
322
336
  /**
@@ -330,237 +344,314 @@ class MakeDeferredNamespaceObjectRuntimeModule extends HelperRuntimeModule {
330
344
  const lt = runtimeTemplate.renderLet();
331
345
  const fn = RuntimeGlobals.makeDeferredNamespaceObject;
332
346
  const hasAsync = this.hasAsyncRuntime;
347
+ // A build reaches only the shapes its call sites ask for, so the other
348
+ // one's branches are dead weight in every bundle that ships this runtime.
349
+ const sealed = this.sealed;
350
+ const synthesized = this.synthesized;
333
351
  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}];`
352
+ return `${fn} = ${runtimeTemplate.basicFunction(
353
+ "moduleId, mode, exportNames",
354
+ [
355
+ // WHY: the TC39 import-defer spec makes a deferred namespace distinct
356
+ // from its eager counterpart, and one module reached from several defer
357
+ // sites must yield the same object, so the Proxy is cached per moduleId.
358
+ //
359
+ // Bit 16 is `createFakeNamespaceObject`'s "return value when it's
360
+ // Promise-like" flag, which `RuntimeTemplate.moduleNamespacePromise` adds
361
+ // for a dynamic import. It is irrelevant here: what is passed in is
362
+ // always the resolved module exports, after unwrapping the async-module
363
+ // export symbol where there is one, and never a Promise. Stripping it
364
+ // once leaves the cache key, the call below and everything downstream on
365
+ // one shape mode, so static defer (mode 8) and `await import.defer`
366
+ // (mode 8 | 16) share the same object. The key stays `(moduleId, mode)`
367
+ // so two importers reading one CJS module differently — as
368
+ // "default-with-named" against "namespace" — still get distinct entries.
369
+ "mode &= ~16;",
370
+ // Only a real ES module namespace has the spec's exotic shape; a
371
+ // synthesized one (JSON, asset, CommonJS interop) keeps the old form.
372
+ sealed && synthesized
373
+ ? "if (!(mode & 8)) exportNames = undefined;"
367
374
  : "",
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}];`
375
+ `${lt} byMode = __webpack_module_deferred_namespace_cache__[moduleId];`,
376
+ "if (byMode && byMode[mode] !== undefined) return byMode[mode];",
377
+ "if (!byMode) byMode = __webpack_module_deferred_namespace_cache__[moduleId] = {};",
378
+ synthesized
379
+ ? `${cst} cachedModule = __webpack_module_cache__[moduleId];`
381
380
  : "",
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:",
381
+ synthesized
382
+ ? "if (cachedModule && cachedModule.error === undefined && !(mode & 8)) {"
383
+ : "",
384
+ synthesized
385
+ ? Template.indent([
386
+ `${lt} exports = cachedModule.exports;`,
481
387
  hasAsync
482
- ? `case ${RuntimeGlobals.deferredModuleAsyncTransitiveDependenciesSymbol}:`
388
+ ? `if (${RuntimeGlobals.asyncModuleExportSymbol} in exports) exports = exports[${RuntimeGlobals.asyncModuleExportSymbol}];`
483
389
  : "",
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) {",
390
+ `return byMode[mode] = ${RuntimeGlobals.createFakeNamespaceObject}(exports, mode);`
391
+ ])
392
+ : "",
393
+ synthesized ? "}" : "",
394
+ "",
395
+ `${lt} init = ${runtimeTemplate.basicFunction("", [
396
+ // A deferred namespace that forces evaluation of a module that is
397
+ // already evaluating (a cycle) must throw rather than expose its
398
+ // partial exports.
399
+ `${cst} evaluatingModule = __webpack_module_cache__[moduleId];`,
400
+ 'if (evaluatingModule !== undefined && (evaluatingModule.evaluating || evaluatingModule.evaluatingAsync)) throw new TypeError("Cannot access a deferred module namespace while the module is being evaluated");',
401
+ `ns = ${RuntimeGlobals.require}(moduleId);`,
402
+ hasAsync
403
+ ? `if (${RuntimeGlobals.asyncModuleExportSymbol} in ns) ns = ns[${RuntimeGlobals.asyncModuleExportSymbol}];`
404
+ : "",
405
+ "init = null;",
406
+ synthesized
407
+ ? "if (mode & 8 || mode & 4 && ns.__esModule && typeof ns === 'object') {"
408
+ : "",
509
409
  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;'
410
+ // Drop only the read traps after init: with the namespace's own keys
411
+ // mirrored onto `ns_target`, default `Reflect` behavior already
412
+ // returns the right values through the live-binding getters.
413
+
414
+ // WHY: the spec makes `[[Set]]`, `[[Delete]]` and
415
+ // `[[DefineOwnProperty]]` on a Deferred Module Namespace always
416
+ // fail, yet the target stays extensible because it cannot be frozen
417
+ // up front — so without the mutation traps `ns.notExported = "x"`
418
+ // would silently create a property instead of returning false.
419
+
420
+ // A sealed target holds placeholder values, so the read traps stay to
421
+ // keep the live bindings visible.
422
+ sealed && synthesized ? "if (!exportNames) {" : "",
423
+ synthesized
424
+ ? Template.indent([
425
+ "delete handler.get;",
426
+ "delete handler.has;",
427
+ "delete handler.ownKeys;",
428
+ "delete handler.getOwnPropertyDescriptor;"
429
+ ])
430
+ : "",
431
+ sealed && synthesized ? "}" : ""
517
432
  ]),
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
- ])};`;
433
+ synthesized ? "} else {" : "",
434
+ synthesized
435
+ ? Template.indent([
436
+ `ns = ${RuntimeGlobals.createFakeNamespaceObject}(ns, mode);`
437
+ ])
438
+ : "",
439
+ synthesized ? "}" : "",
440
+ // Mirror the resolved namespace's own properties onto the target, or
441
+ // the proxy invariants break: where a trap reports a non-configurable
442
+ // descriptor, the target must carry a matching one.
443
+
444
+ // `__esModule` and `Symbol.toStringTag` are skipped: the proxy
445
+ // synthesizes them whatever the namespace exposes, and the target is
446
+ // pre-populated with those values below.
447
+ synthesized
448
+ ? `${cst} keys = ${sealed ? "exportNames ? [] : " : ""}Reflect.ownKeys(ns);`
449
+ : "",
450
+ synthesized ? "for (var i = 0; i < keys.length; i++) {" : "",
451
+ synthesized
452
+ ? Template.indent([
453
+ `${cst} k = keys[i];`,
454
+ 'if (k === "__esModule" || k === Symbol.toStringTag) continue;',
455
+ `if (!${runtimeTemplate.objectHasOwn("ns_target", "k")}) {`,
456
+ Template.indent([
457
+ "try { Object.defineProperty(ns_target, k, Reflect.getOwnPropertyDescriptor(ns, k)); } catch (_) {}"
458
+ ]),
459
+ "}"
460
+ ])
461
+ : "",
462
+ synthesized ? "}" : ""
463
+ ])};`,
464
+ "",
465
+ // WHY: the proxy target is a fresh placeholder, separate from
466
+ // `__webpack_module_deferred_exports__[moduleId]`, which
467
+ // `__webpack_require__` reuses as `module.exports` for a deferred-loaded
468
+ // module and would conflict with the pre-populated synthetic `__esModule`
469
+ // and `Symbol.toStringTag` non-configurable properties. A dedicated
470
+ // target keeps the proxy invariant-compliant without interfering with the
471
+ // module's own exports object.
472
+ `${cst} ns_target = { __proto__: null };`,
473
+ // With the export list known at build time the target carries the spec's
474
+ // keys and is sealed, so `[[IsExtensible]]` is false up front.
475
+ sealed
476
+ ? `${synthesized ? "if (exportNames) " : ""}for (var e = 0; e < exportNames.length; e++) ns_target[exportNames[e]] = undefined;`
477
+ : "",
478
+ // Pre-populate the synthetic properties with the non-configurable,
479
+ // non-writable, non-enumerable descriptors the spec gives a Module
480
+ // Namespace, which the trap below returns unchanged.
481
+
482
+ // `__esModule` is not one of the spec's keys, so a sealed namespace omits
483
+ // it; the synthesized form keeps it for interop.
484
+ synthesized
485
+ ? `${sealed ? "if (!exportNames) " : ""}Object.defineProperty(ns_target, "__esModule", { value: true });`
486
+ : "",
487
+ 'Object.defineProperty(ns_target, Symbol.toStringTag, { value: "Deferred Module" });',
488
+ sealed
489
+ ? `${synthesized ? "if (exportNames) " : ""}Object.seal(ns_target);`
490
+ : "",
491
+ `${lt} ns = ns_target;`,
492
+ `${cst} handler = {`,
493
+ Template.indent([
494
+ "__proto__: null,",
495
+ // `IsSymbolLikeNamespaceKey` holds for any Symbol key and for `then`,
496
+ // and such a read must not evaluate the deferred module, so the checks
497
+ // below reach the pre-populated target without running `init()`.
498
+ `${runtimeTemplate.method("get", "_, name", [
499
+ "switch (name) {",
500
+ Template.indent([
501
+ // webpack's interop marker, read as a property by
502
+ // `o.__esModule ? o.default : o`, so a sealed namespace
503
+ // answers it too even though it is not one of its keys.
504
+ 'case "__esModule": return true;',
505
+ 'case Symbol.toStringTag: return "Deferred Module";',
506
+ 'case "then": return undefined;'
507
+ ]),
508
+ "}",
509
+ 'if (typeof name === "symbol") return ns_target[name];',
510
+ init,
511
+ // A sealed namespace has exactly the spec's keys, so anything
512
+ // else is absent rather than read off the exports object.
513
+ sealed
514
+ ? `${synthesized ? "if (exportNames) " : ""}return name in ns_target ? ns[name] : undefined;`
515
+ : "",
516
+ synthesized ? "return ns[name];" : ""
517
+ ])},`,
518
+ `${runtimeTemplate.method("has", "_, name", [
519
+ "switch (name) {",
520
+ Template.indent(
521
+ [
522
+ synthesized
523
+ ? `case "__esModule": ${sealed ? "if (!exportNames) " : ""}return true;${sealed ? " break;" : ""}`
524
+ : "",
525
+ "case Symbol.toStringTag:",
526
+ hasAsync
527
+ ? `case ${RuntimeGlobals.deferredModuleAsyncTransitiveDependenciesSymbol}:`
528
+ : "",
529
+ Template.indent("return true;"),
530
+ 'case "then":',
531
+ Template.indent("return false;")
532
+ ].filter(Boolean)
533
+ ),
534
+ "}",
535
+ 'if (typeof name === "symbol") return name in ns_target;',
536
+ init,
537
+ sealed
538
+ ? `${synthesized ? "if (exportNames) " : ""}return name in ns_target;`
539
+ : "",
540
+ synthesized ? "return name in ns;" : ""
541
+ ])},`,
542
+ `${runtimeTemplate.method("ownKeys", "", [
543
+ init,
544
+ // The sealed target already carries the spec's keys, sorted.
545
+ sealed
546
+ ? `${synthesized ? "if (exportNames) " : ""}return Reflect.ownKeys(ns_target);`
547
+ : "",
548
+ synthesized
549
+ ? `${cst} filtered = Reflect.ownKeys(ns).filter(${runtimeTemplate.expressionFunction(
550
+ 'x !== "then" && x !== Symbol.toStringTag',
551
+ "x"
552
+ )});`
553
+ : "",
554
+ synthesized
555
+ ? `${cst} keys = ${
556
+ runtimeTemplate.supportsSpread()
557
+ ? "[...filtered, Symbol.toStringTag]"
558
+ : "filtered.concat([Symbol.toStringTag])"
559
+ };`
560
+ : "",
561
+ synthesized ? "return keys;" : ""
562
+ ])},`,
563
+ `${runtimeTemplate.method("getOwnPropertyDescriptor", "_, name", [
564
+ "switch (name) {",
565
+ Template.indent([
566
+ // Match the descriptors actually defined on `ns_target`, so the
567
+ // proxy invariant holds both for this result and for the
568
+ // post-init forwarding through the deleted-handler path.
569
+ synthesized
570
+ ? `case "__esModule": ${sealed ? "if (!exportNames) " : ""}return { value: true, writable: false, enumerable: false, configurable: false };${sealed ? " break;" : ""}`
571
+ : "",
572
+ 'case Symbol.toStringTag: return { value: "Deferred Module", writable: false, enumerable: false, configurable: false };',
573
+ 'case "then": return undefined;'
574
+ ]),
575
+ "}",
576
+ 'if (typeof name === "symbol") return Reflect.getOwnPropertyDescriptor(ns_target, name);',
577
+ init,
578
+ // A namespace exposes data properties; webpack backs the exports
579
+ // with getters, so the spec's shape is synthesized here.
580
+ sealed
581
+ ? `${synthesized ? "if (exportNames) " : ""}return name in ns_target ? { value: ns[name], writable: true, enumerable: true, configurable: false } : undefined;`
582
+ : "",
583
+ synthesized
584
+ ? `${lt} desc = Reflect.getOwnPropertyDescriptor(ns, name);`
585
+ : "",
586
+ synthesized ? 'if (mode & 2 && name == "default" && !desc) {' : "",
587
+ synthesized
588
+ ? Template.indent("desc = { value: ns, configurable: true };")
589
+ : "",
590
+ synthesized ? "}" : "",
591
+ synthesized ? "return desc;" : ""
592
+ ])},`,
593
+ // `defineProperty` always rejects, yet must still evaluate on a string
594
+ // key, since the spec calls `[[GetOwnProperty]]` first. A Symbol key
595
+ // takes OrdinaryDefineOwnProperty and evaluates nothing.
596
+ `${runtimeTemplate.method("defineProperty", "_, name", [
597
+ 'if (typeof name === "symbol" || name === "then") return false;',
598
+ init,
599
+ "return false;"
600
+ ])},`,
601
+ // `deleteProperty` rejects too, and likewise still evaluates on a
602
+ // string key: the spec calls `GetModuleExportsList` for every
603
+ // non-symbol-like key.
604
+ `${runtimeTemplate.method("deleteProperty", "_, name", [
605
+ 'if (typeof name === "symbol" || name === "then") return false;',
606
+ init,
607
+ "return false;"
608
+ ])},`,
609
+ // `set` always returns false without triggering evaluation —
610
+ // the spec [[Set]] algorithm for Module Namespaces is just
611
+ // "return false" (no [[GetOwnProperty]], no eval).
612
+ `set: ${runtimeTemplate.returningFunction("false")},`
613
+ ]),
614
+ "}",
615
+ // we don't fully emulate ES Module semantics in this Proxy to align with normal webpack esm namespace object.
616
+ "return byMode[mode] = new Proxy(ns_target, handler);"
617
+ ]
618
+ )};`;
555
619
  }
556
620
  }
557
621
 
622
+ /**
623
+ * The module's export names, sorted, when the graph knows them exhaustively.
624
+ * Only a `namespace` module takes the sealed path, and names are never mangled
625
+ * here: materializing a namespace clears `canMangleUse` on every export.
626
+ * @param {ModuleGraph} moduleGraph the module graph
627
+ * @param {Module} module the deferred module
628
+ * @param {ExportsType} exportsType the module's exports type
629
+ * @returns {string[] | null} sorted export names, or null when unknown
630
+ */
631
+ const getKnownExportNames = (moduleGraph, module, exportsType) => {
632
+ if (exportsType !== "namespace") return null;
633
+ const exportsInfo = moduleGraph.getExportsInfo(module);
634
+ if (exportsInfo.otherExportsInfo.provided !== false) return null;
635
+ const names = [];
636
+ for (const exportInfo of exportsInfo.orderedExports) {
637
+ // `false` is a definitive "not an export" (webpack records `__esModule`
638
+ // that way); anything but a definitive answer means the list is unknown.
639
+ if (exportInfo.provided === false) continue;
640
+ if (exportInfo.provided !== true) return null;
641
+ // A namespace never exposes `then`, so it is not one of the spec's keys.
642
+ if (exportInfo.name === "then") continue;
643
+ names.push(exportInfo.name);
644
+ }
645
+ return names.sort();
646
+ };
647
+
558
648
  module.exports.MakeDeferredNamespaceObjectRuntimeModule =
559
649
  MakeDeferredNamespaceObjectRuntimeModule;
560
650
  module.exports.MakeOptimizedDeferredNamespaceObjectRuntimeModule =
561
651
  MakeOptimizedDeferredNamespaceObjectRuntimeModule;
562
652
  module.exports.getDeferredCycleModuleIds = getDeferredCycleModuleIds;
563
653
  module.exports.getDeferredCycleModules = getDeferredCycleModules;
654
+ module.exports.getKnownExportNames = getKnownExportNames;
564
655
  module.exports.getMakeDeferredNamespaceModeFromExportsType =
565
656
  getMakeDeferredNamespaceModeFromExportsType;
566
657
  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