@depup/webpack 5.110.3-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 (283) 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/CircularModulesPlugin.js +157 -55
  8. package/lib/CleanPlugin.js +2 -2
  9. package/lib/CompatibilityPlugin.js +3 -4
  10. package/lib/Compilation.js +336 -337
  11. package/lib/Compiler.js +213 -51
  12. package/lib/ConstPlugin.js +16 -132
  13. package/lib/CopyPlugin.js +1054 -0
  14. package/lib/DefinePlugin.js +24 -8
  15. package/lib/DependencyTemplate.js +2 -1
  16. package/lib/DotenvPlugin.js +24 -28
  17. package/lib/ErrorHelpers.js +113 -0
  18. package/lib/ExportsInfo.js +20 -16
  19. package/lib/ExternalModule.js +47 -22
  20. package/lib/FileSystemInfo.js +17 -14
  21. package/lib/FlagDependencyExportsPlugin.js +53 -34
  22. package/lib/FlagDependencyUsagePlugin.js +9 -13
  23. package/lib/Generator.js +24 -2
  24. package/lib/HotModuleReplacementPlugin.js +55 -7
  25. package/lib/IgnorePlugin.js +1 -1
  26. package/lib/JavascriptMetaInfoPlugin.js +5 -3
  27. package/lib/LoaderOptionsPlugin.js +1 -1
  28. package/lib/MainTemplate.js +5 -1
  29. package/lib/Module.js +19 -10
  30. package/lib/ModuleGraph.js +6 -9
  31. package/lib/MultiCompiler.js +7 -17
  32. package/lib/MultiWatching.js +1 -1
  33. package/lib/NormalModule.js +135 -50
  34. package/lib/NormalModuleFactory.js +1 -1
  35. package/lib/RuntimeGlobals.js +21 -7
  36. package/lib/RuntimeModule.js +28 -12
  37. package/lib/RuntimePlugin.js +30 -3
  38. package/lib/RuntimeTemplate.js +813 -518
  39. package/lib/SourceMapDevToolPlugin.js +54 -104
  40. package/lib/TemplatedPathPlugin.js +16 -59
  41. package/lib/Watching.js +9 -0
  42. package/lib/WebpackOptionsApply.js +84 -91
  43. package/lib/asset/AssetBytesGenerator.js +7 -1
  44. package/lib/asset/AssetGenerator.js +50 -24
  45. package/lib/asset/AssetModule.js +3 -0
  46. package/lib/asset/AssetSourceGenerator.js +7 -1
  47. package/lib/asset/WebManifestParser.js +7 -5
  48. package/lib/buildChunkGraph.js +11 -15
  49. package/lib/cache/AddBuildDependenciesPlugin.js +33 -4
  50. package/lib/cache/IdleFileCachePlugin.js +2 -2
  51. package/lib/cache/MemoryCachePlugin.js +4 -4
  52. package/lib/cache/MemoryWithGcCachePlugin.js +7 -8
  53. package/lib/cache/PackFileCacheStrategy.js +17 -19
  54. package/lib/cache/getLazyHashedEtag.js +3 -5
  55. package/lib/config/browserslistTargetHandler.js +17 -4
  56. package/lib/config/defaults.js +138 -128
  57. package/lib/config/getClaimedAssetTypes.js +10 -11
  58. package/lib/config/normalization.js +82 -12
  59. package/lib/config/target.js +13 -4
  60. package/lib/container/ContainerReferencePlugin.js +6 -0
  61. package/lib/container/RemoteRuntimeModule.js +9 -0
  62. package/lib/container/declaredRemotes.js +39 -0
  63. package/lib/{ContextExclusionPlugin.js → context/ContextExclusionPlugin.js} +1 -1
  64. package/lib/{ContextModule.js → context/ContextModule.js} +54 -115
  65. package/lib/{ContextModuleFactory.js → context/ContextModuleFactory.js} +19 -21
  66. package/lib/{ContextReplacementPlugin.js → context/ContextReplacementPlugin.js} +4 -4
  67. package/lib/css/CssGenerator.js +27 -11
  68. package/lib/css/CssInjectStyleRuntimeModule.js +9 -0
  69. package/lib/css/CssLoadingRuntimeModule.js +94 -36
  70. package/lib/css/CssModule.js +1 -1
  71. package/lib/css/CssModulesPlugin.js +7 -6
  72. package/lib/css/CssParser.js +162 -31
  73. package/lib/css/CssServerStylesRuntimeModule.js +9 -0
  74. package/lib/css/cssMinify.js +43 -32
  75. package/lib/css/data.js +3514 -869
  76. package/lib/css/syntax.js +6370 -1220
  77. package/lib/debug/ProfilingPlugin.js +7 -4
  78. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +6 -3
  79. package/lib/dependencies/AMDRuntimeModules.js +18 -0
  80. package/lib/dependencies/CommonJsExportRequireDependency.js +13 -12
  81. package/lib/dependencies/CommonJsExportsParserPlugin.js +12 -13
  82. package/lib/dependencies/CommonJsImportsParserPlugin.js +5 -5
  83. package/lib/dependencies/CommonJsPlugin.js +19 -3
  84. package/lib/dependencies/CommonJsRequireDependency.js +14 -5
  85. package/lib/dependencies/CommonJsSelfReferenceDependency.js +2 -4
  86. package/lib/dependencies/ContextDependency.js +1 -1
  87. package/lib/dependencies/ContextDependencyHelpers.js +3 -9
  88. package/lib/dependencies/ContextElementDependency.js +1 -1
  89. package/lib/dependencies/CssIcssExportDependency.js +13 -9
  90. package/lib/dependencies/CssIcssImportDependency.js +3 -6
  91. package/lib/dependencies/CssUrlDependency.js +3 -5
  92. package/lib/dependencies/HarmonyCompatibilityDependency.js +67 -22
  93. package/lib/dependencies/HarmonyDetectionParserPlugin.js +3 -4
  94. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +10 -7
  95. package/lib/dependencies/HarmonyExportExpressionDependency.js +47 -33
  96. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +74 -17
  97. package/lib/dependencies/HarmonyExportInitFragment.js +110 -23
  98. package/lib/dependencies/HarmonyExportSpecifierDependency.js +25 -58
  99. package/lib/dependencies/HarmonyImportBareSideEffectDependency.js +59 -0
  100. package/lib/dependencies/HarmonyImportDependency.js +6 -1
  101. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +111 -17
  102. package/lib/dependencies/HarmonyImportSideEffectDependency.js +3 -4
  103. package/lib/dependencies/HarmonyImportSpecifierDependency.js +40 -3
  104. package/lib/dependencies/HarmonyModulesPlugin.js +20 -0
  105. package/lib/dependencies/HtmlEntryDependency.js +124 -102
  106. package/lib/dependencies/HtmlInlineScriptDependency.js +3 -4
  107. package/lib/dependencies/HtmlInlineStyleDependency.js +3 -4
  108. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -1
  109. package/lib/dependencies/ImportMetaGlobHelpers.js +1 -1
  110. package/lib/dependencies/ImportMetaMainDependency.js +104 -0
  111. package/lib/dependencies/ImportMetaPlugin.js +67 -25
  112. package/lib/dependencies/ImportParserPlugin.js +1 -1
  113. package/lib/dependencies/LoaderPlugin.js +26 -1
  114. package/lib/dependencies/RequireContextDependencyParserPlugin.js +1 -1
  115. package/lib/dependencies/SystemRuntimeModule.js +9 -0
  116. package/lib/dependencies/URLContextDependency.js +1 -1
  117. package/lib/dependencies/URLDependency.js +6 -5
  118. package/lib/dependencies/WorkerAndWorkletPlugin.js +15 -21
  119. package/lib/dependencies/WorkerDependency.js +7 -7
  120. package/lib/dependencies/WorkletDependency.js +7 -11
  121. package/lib/dll/DelegatedModule.js +18 -1
  122. package/lib/dll/DllReferencePlugin.js +11 -8
  123. package/lib/dll/LibManifestPlugin.js +1 -1
  124. package/lib/errors/AnalyzableBailoutsWarning.js +41 -0
  125. package/lib/errors/DuplicateModulesWarning.js +12 -7
  126. package/lib/errors/EmptyCopyPatternWarning.js +26 -0
  127. package/lib/errors/ExternalStarReexportError.js +44 -0
  128. package/lib/errors/HookWebpackError.js +3 -2
  129. package/lib/errors/MissingSourceMapsWarning.js +36 -0
  130. package/lib/errors/ModuleParseError.js +2 -1
  131. package/lib/errors/UnusedAssetsWarning.js +36 -0
  132. package/lib/errors/UnusedFederationWarning.js +35 -0
  133. package/lib/errors/UnusedModulesWarning.js +38 -0
  134. package/lib/esm/ExportWebpackRequireRuntimeModule.js +9 -0
  135. package/lib/esm/ModuleChunkFormatPlugin.js +28 -3
  136. package/lib/esm/ModuleChunkLoadingPlugin.js +30 -11
  137. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +92 -60
  138. package/lib/hmr/HotModuleReplacement.runtime.js +8 -2
  139. package/lib/hmr/HotModuleReplacementRuntimeModule.js +9 -0
  140. package/lib/hmr/LazyCompilationPlugin.js +3 -5
  141. package/lib/html/HtmlGenerator.js +72 -87
  142. package/lib/html/HtmlModulesPlugin.js +418 -200
  143. package/lib/html/HtmlParser.js +110 -147
  144. package/lib/html/builtinEmbeddedRenderer.js +107 -0
  145. package/lib/html/data.js +142 -7
  146. package/lib/html/htmlMinify.js +92 -122
  147. package/lib/html/syntax.js +1618 -1391
  148. package/lib/ids/HashedModuleIdsPlugin.js +2 -1
  149. package/lib/index.js +49 -3
  150. package/lib/javascript/ChunkFormatHelpers.js +4 -3
  151. package/lib/javascript/JavascriptGenerator.js +8 -1
  152. package/lib/javascript/JavascriptModule.js +1 -0
  153. package/lib/javascript/JavascriptModulesPlugin.js +73 -72
  154. package/lib/javascript/JavascriptParser.js +1970 -900
  155. package/lib/javascript/StartupHelpers.js +27 -3
  156. package/lib/javascript/data.js +172 -0
  157. package/lib/javascript/grammar.js +5546 -0
  158. package/lib/javascript/parser.js +1500 -0
  159. package/lib/javascript/regexp.js +1762 -0
  160. package/lib/javascript/regexpData.js +51 -0
  161. package/lib/javascript/syntax.js +9061 -5262
  162. package/lib/json/JsonGenerator.js +7 -1
  163. package/lib/library/ModuleLibraryPlugin.js +171 -132
  164. package/lib/loaders/LoaderRunner.js +137 -9
  165. package/lib/node/NodeWatchFileSystem.js +3 -9
  166. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +22 -0
  167. package/lib/node/RequireChunkLoadingRuntimeModule.js +22 -0
  168. package/lib/optimize/AggressiveMergingPlugin.js +3 -5
  169. package/lib/optimize/ConcatenatedModule.js +178 -120
  170. package/lib/optimize/ConstExportsPlugin.js +50 -39
  171. package/lib/optimize/FlagIncludedChunksPlugin.js +3 -11
  172. package/lib/optimize/InlineExports.js +20 -123
  173. package/lib/optimize/InnerGraphPlugin.js +7 -13
  174. package/lib/optimize/LimitChunkCountPlugin.js +5 -8
  175. package/lib/optimize/MangleExportsPlugin.js +13 -4
  176. package/lib/optimize/ModuleConcatenationPlugin.js +27 -5
  177. package/lib/optimize/RealContentHashPlugin.js +68 -9
  178. package/lib/optimize/SideEffectsFlagPlugin.js +24 -28
  179. package/lib/optimize/SplitChunksPlugin.js +2 -4
  180. package/lib/performance/AnalyzableBailoutsPlugin.js +115 -0
  181. package/lib/performance/BroadContextsPlugin.js +1 -1
  182. package/lib/performance/CacheEffectivenessPlugin.js +7 -7
  183. package/lib/performance/DuplicateModulesPlugin.js +57 -13
  184. package/lib/performance/EvalUsagePlugin.js +5 -2
  185. package/lib/performance/MissingSourceMapsPlugin.js +115 -0
  186. package/lib/performance/PureAnnotationsPlugin.js +6 -3
  187. package/lib/performance/SizeLimitsPlugin.js +2 -4
  188. package/lib/performance/TopLevelThisPlugin.js +5 -4
  189. package/lib/performance/UnusedAssetsPlugin.js +109 -0
  190. package/lib/performance/UnusedFederationPlugin.js +147 -0
  191. package/lib/performance/UnusedModulesPlugin.js +141 -0
  192. package/lib/performance/UnusedReexportsPlugin.js +1 -55
  193. package/lib/performance/isOnlyReexported.js +65 -0
  194. package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +25 -5
  195. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +8 -8
  196. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +9 -0
  197. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +9 -0
  198. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +9 -0
  199. package/lib/prefetch/ResourceHintPlugin.js +18 -23
  200. package/lib/prefetch/ResourceHintRuntimeModule.js +9 -0
  201. package/lib/prefetch/StartupAssetHintRuntimeModule.js +16 -10
  202. package/lib/rules/RuleSetCompiler.js +211 -4
  203. package/lib/runtime/AsyncModuleRuntimeModule.js +98 -66
  204. package/lib/runtime/AutoPublicPathRuntimeModule.js +9 -0
  205. package/lib/runtime/BaseUriRuntimeModule.js +9 -0
  206. package/lib/runtime/ChunkNameRuntimeModule.js +9 -0
  207. package/lib/runtime/EnsureChunkRuntimeModule.js +35 -16
  208. package/lib/runtime/GetChunkFilenameRuntimeModule.js +12 -4
  209. package/lib/runtime/GetFullHashRuntimeModule.js +9 -0
  210. package/lib/runtime/GetMainFilenameRuntimeModule.js +9 -0
  211. package/lib/runtime/GetWorkletBootstrapRuntimeModule.js +9 -0
  212. package/lib/runtime/GlobalRuntimeModule.js +11 -4
  213. package/lib/runtime/HasOwnPropertyRuntimeModule.js +9 -0
  214. package/lib/runtime/HelperRuntimeModule.js +10 -0
  215. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +305 -224
  216. package/lib/runtime/NonceRuntimeModule.js +9 -0
  217. package/lib/runtime/OnChunksLoadedRuntimeModule.js +67 -20
  218. package/lib/runtime/PublicPathRuntimeModule.js +9 -0
  219. package/lib/runtime/RuntimeIdRuntimeModule.js +9 -0
  220. package/lib/runtime/SpecNamespaceObjectRuntimeModule.js +90 -0
  221. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +9 -0
  222. package/lib/runtime/StartupEntrypointRuntimeModule.js +9 -0
  223. package/lib/runtime/SystemContextRuntimeModule.js +9 -0
  224. package/lib/runtime/ToBinaryRuntimeModule.js +9 -0
  225. package/lib/schemes/DataUriPlugin.js +3 -6
  226. package/lib/schemes/VirtualUrlPlugin.js +1 -1
  227. package/lib/serialization/BinaryMiddleware.js +9 -9
  228. package/lib/serialization/FileMiddleware.js +16 -16
  229. package/lib/serialization/ObjectMiddleware.js +168 -139
  230. package/lib/sharing/ConsumeSharedPlugin.js +12 -0
  231. package/lib/sharing/ConsumeSharedRuntimeModule.js +11 -0
  232. package/lib/sharing/ShareRuntimeModule.js +9 -0
  233. package/lib/sharing/declaredShared.js +47 -0
  234. package/lib/stats/DefaultStatsFactoryPlugin.js +6 -5
  235. package/lib/stats/DefaultStatsPrinterPlugin.js +3 -0
  236. package/lib/typescript/TypeScriptPlugin.js +2 -3
  237. package/lib/url/URLParserPlugin.js +6 -8
  238. package/lib/util/LocConverter.js +4 -7
  239. package/lib/util/SourceProcessor.js +91 -91
  240. package/lib/util/async.js +292 -0
  241. package/lib/util/buildDiagnostics.js +69 -0
  242. package/lib/util/chainedImports.js +3 -4
  243. package/lib/util/concatenate.js +4 -4
  244. package/lib/util/createHooksRegistry.js +1 -2
  245. package/lib/util/dataURL.js +2 -3
  246. package/lib/util/deterministicGrouping.js +8 -13
  247. package/lib/util/findGraphRoots.js +6 -13
  248. package/lib/util/fs.js +27 -1
  249. package/lib/util/globUtils.js +1 -1
  250. package/lib/util/handlerKeys.js +40 -0
  251. package/lib/util/hash/wasm-hash.js +3 -4
  252. package/lib/util/identifier.js +20 -0
  253. package/lib/util/internalSerializables.js +5 -1
  254. package/lib/util/registerExternalSerializer.js +6 -45
  255. package/lib/util/semver.js +5 -3
  256. package/lib/wasm-async/AsyncWasmCompileRuntimeModule.js +9 -0
  257. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +9 -0
  258. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +6 -1
  259. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +5 -1
  260. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +12 -4
  261. package/lib/wasm-sync/WebAssemblyGenerator.js +6 -1
  262. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +5 -1
  263. package/lib/wasm-sync/WebAssemblyUtils.js +2 -4
  264. package/lib/web/JsonpChunkLoadingRuntimeModule.js +36 -0
  265. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +19 -0
  266. package/package.json +55 -46
  267. package/schemas/WebpackOptions.check.js +1 -1
  268. package/schemas/WebpackOptions.json +379 -66
  269. package/schemas/plugins/LoaderOptionsPlugin.check.js +1 -1
  270. package/schemas/plugins/ManifestPlugin.check.js +1 -1
  271. package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
  272. package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
  273. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
  274. package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
  275. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  276. package/schemas/plugins/debug/ProfilingPlugin.check.js +1 -1
  277. package/schemas/plugins/dll/DllReferencePlugin.check.js +1 -1
  278. package/schemas/plugins/ids/HashedModuleIdsPlugin.check.js +1 -1
  279. package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
  280. package/types.d.ts +1723 -604
  281. package/lib/dependencies/ExportBindingInitFragment.js +0 -191
  282. package/lib/errors/EntrypointOverlapWarning.js +0 -45
  283. package/lib/performance/EntrypointOverlapPlugin.js +0 -122
@@ -32,6 +32,28 @@ class ReadFileChunkLoadingRuntimeModule extends RuntimeModule {
32
32
  this.runtimeRequirements = runtimeRequirements;
33
33
  }
34
34
 
35
+ /**
36
+ * The `[handlerMap, key]` pairs this module installs onto a chunk handler map
37
+ * such as `__webpack_require__.f`, or `null` where it cannot name them.
38
+ * @returns {[string, string][] | null} installed chunk handlers (do not mutate)
39
+ */
40
+ getInstalledChunkHandlers() {
41
+ const runtimeRequirements = this.runtimeRequirements;
42
+ /** @type {[string, string][]} */
43
+ const handlers = [];
44
+ if (runtimeRequirements.has(RuntimeGlobals.ensureChunkHandlers)) {
45
+ handlers.push([RuntimeGlobals.ensureChunkHandlers, "readFileVm"]);
46
+ }
47
+ // The hot update flow installs this one onto the same map while it runs.
48
+ if (runtimeRequirements.has(RuntimeGlobals.hmrDownloadUpdateHandlers)) {
49
+ handlers.push([RuntimeGlobals.ensureChunkHandlers, "readFileVmHmr"]);
50
+ }
51
+ if (runtimeRequirements.has(RuntimeGlobals.onChunksLoaded)) {
52
+ handlers.push([RuntimeGlobals.onChunksLoaded, "readFileVm"]);
53
+ }
54
+ return handlers;
55
+ }
56
+
35
57
  /**
36
58
  * Returns generated code.
37
59
  * @private
@@ -32,6 +32,28 @@ class RequireChunkLoadingRuntimeModule extends RuntimeModule {
32
32
  this.runtimeRequirements = runtimeRequirements;
33
33
  }
34
34
 
35
+ /**
36
+ * The `[handlerMap, key]` pairs this module installs onto a chunk handler map
37
+ * such as `__webpack_require__.f`, or `null` where it cannot name them.
38
+ * @returns {[string, string][] | null} installed chunk handlers (do not mutate)
39
+ */
40
+ getInstalledChunkHandlers() {
41
+ const runtimeRequirements = this.runtimeRequirements;
42
+ /** @type {[string, string][]} */
43
+ const handlers = [];
44
+ if (runtimeRequirements.has(RuntimeGlobals.ensureChunkHandlers)) {
45
+ handlers.push([RuntimeGlobals.ensureChunkHandlers, "require"]);
46
+ }
47
+ // The hot update flow installs this one onto the same map while it runs.
48
+ if (runtimeRequirements.has(RuntimeGlobals.hmrDownloadUpdateHandlers)) {
49
+ handlers.push([RuntimeGlobals.ensureChunkHandlers, "requireHmr"]);
50
+ }
51
+ if (runtimeRequirements.has(RuntimeGlobals.onChunksLoaded)) {
52
+ handlers.push([RuntimeGlobals.onChunksLoaded, "require"]);
53
+ }
54
+ return handlers;
55
+ }
56
+
35
57
  /**
36
58
  * Returns generated code.
37
59
  * @private
@@ -53,11 +53,9 @@ class AggressiveMergingPlugin {
53
53
  },
54
54
  (chunks) => {
55
55
  const chunkGraph = compilation.chunkGraph;
56
- // Only the single best pair is merged per pass (the hook re-runs
57
- // after each merge), so track the max directly instead of building
58
- // and sorting the full O(chunks²) list of pairs every pass. A strict
59
- // `>` keeps the first-encountered best, matching the previous stable
60
- // descending sort's `[0]`.
56
+ // One pair is merged per pass and the hook re-runs, so the maximum is
57
+ // tracked directly rather than sorting every pair each time. A strict
58
+ // `>` keeps the first best found, as a stable descending sort would.
61
59
  /** @type {Chunk | undefined} */
62
60
  let bestA;
63
61
  /** @type {Chunk | undefined} */
@@ -34,11 +34,13 @@ const analyzeScope = require("../javascript/ScopeAnalyzer");
34
34
  const {
35
35
  getDeferredCycleModuleIds,
36
36
  getDeferredCycleModules,
37
+ getKnownExportNames,
37
38
  getMakeDeferredNamespaceModeFromExportsType,
38
39
  getOptimizedDeferredModule
39
40
  } = require("../runtime/MakeDeferredNamespaceObjectRuntime");
40
41
  const { equals } = require("../util/ArrayHelpers");
41
42
  const LazySet = require("../util/LazySet");
43
+ const { getBuildDiagnostics } = require("../util/buildDiagnostics");
42
44
  const {
43
45
  compareModulesByFullName,
44
46
  concatComparators
@@ -116,8 +118,7 @@ const { InlinedUsedName } = require("./InlineExports");
116
118
  * @import {
117
119
  * ChunkRenderContext,
118
120
  * Scope,
119
- * Reference,
120
- * Variable
121
+ * Reference
121
122
  * } from "../javascript/JavascriptModulesPlugin"
122
123
  */
123
124
  /** @import { Range } from "../javascript/JavascriptParser" */
@@ -247,6 +248,7 @@ const findIdentifiers = (source) => {
247
248
  * @property {boolean} deferred the module is deferred at least once
248
249
  * @property {boolean} deferredNamespaceObjectUsed deferred namespace object that being used in a not-analyzable way so it must be materialized
249
250
  * @property {string | undefined} deferredNamespaceObjectName deferred namespace object that being used in a not-analyzable way so it must be materialized
251
+ * @property {boolean} specNamespaceObjectUsed an import reads the spec namespace object the module hands out
250
252
  * @property {boolean} interopNamespaceObjectUsed "default-with-named" namespace
251
253
  * @property {string | undefined} interopNamespaceObjectName "default-with-named" namespace
252
254
  * @property {boolean} interopNamespaceObject2Used "default-only" namespace
@@ -423,13 +425,26 @@ const getInteropExpr = (info, interopName) =>
423
425
  * slot, but a wrapped one only runs when its accessor is called, so dropping
424
426
  * the reference would drop the module's side effects with it.
425
427
  * @param {ConcatenatedModuleInfo} info module info
428
+ * @param {boolean | undefined} asiSafe asiSafe
426
429
  * @returns {string} expression evaluating to undefined
427
430
  */
428
- const getUnusedExportExpr = (info) =>
431
+ const getUnusedExportExpr = (info, asiSafe) =>
429
432
  info.wrapped
430
- ? `/* unused export */ (${info.namespaceObjectName}, undefined)`
433
+ ? `${asiSafe === false ? ";" : ""}/* unused export */ (${info.namespaceObjectName}, undefined)`
431
434
  : "/* unused export */ undefined";
432
435
 
436
+ /**
437
+ * Parenthesizes a reference that may already carry an ASI guard of its own,
438
+ * keeping that guard outside the new parentheses — nested it would not parse.
439
+ * @param {string} reference the reference
440
+ * @param {boolean | undefined} asiSafe asiSafe
441
+ * @returns {string} the parenthesized reference
442
+ */
443
+ const parenthesizeReference = (reference, asiSafe) =>
444
+ asiSafe === false
445
+ ? `;(${reference.startsWith(";") ? reference.slice(1) : reference})`
446
+ : `(${reference})`;
447
+
433
448
  /**
434
449
  * @param {ModuleGraph} moduleGraph the module graph
435
450
  * @param {ModuleInfo} info module info
@@ -484,7 +499,7 @@ const getFinalBinding = (
484
499
  if (!usedName) {
485
500
  return {
486
501
  info,
487
- rawName: getUnusedExportExpr(info),
502
+ rawName: getUnusedExportExpr(info, asiSafe),
488
503
  ids: [],
489
504
  exportName
490
505
  };
@@ -543,12 +558,13 @@ const getFinalBinding = (
543
558
  case "default":
544
559
  exportName = exportName.slice(1);
545
560
  if (deferred) {
546
- // `ns.default` for a deferred default-with-named external
547
- // module must read through the optimized `.a` getter
548
- // (which lazily evaluates the module and returns its
549
- // exports), not the proxy namespace itself — otherwise
550
- // `typeof ns.default` / `ns.default instanceof X`
551
- // observe the proxy instead of the actual default.
561
+ // WHY: `ns.default` for a deferred default-with-named external
562
+ // module must read through the optimized `.a` getter, which
563
+ // evaluates the
564
+ // module lazily and returns its exports, rather than through the
565
+ // proxy namespace — otherwise `typeof ns.default` and
566
+ // `ns.default instanceof X` observe the proxy, not the actual
567
+ // default.
552
568
  return {
553
569
  info,
554
570
  rawName: `${info.deferredName}.a`,
@@ -587,10 +603,9 @@ const getFinalBinding = (
587
603
  };
588
604
  }
589
605
  if (deferred) {
590
- // As with default-with-named above, `ns.default` for a
591
- // deferred default-only external must read through the
592
- // optimized `.a` getter so that `typeof` / `instanceof`
593
- // observe the actual default value rather than the proxy.
606
+ // As with default-with-named above, a deferred default-only
607
+ // external reads through the `.a` getter, so `typeof` and
608
+ // `instanceof` see the value rather than the proxy.
594
609
  return {
595
610
  info,
596
611
  rawName: `${info.deferredName}.a`,
@@ -667,7 +682,7 @@ const getFinalBinding = (
667
682
  exportName,
668
683
  accessorCall: info.wrapped
669
684
  };
670
- case "external":
685
+ case "external": {
671
686
  if (deferred) {
672
687
  info.deferredNamespaceObjectUsed = true;
673
688
  return {
@@ -677,13 +692,30 @@ const getFinalBinding = (
677
692
  exportName
678
693
  };
679
694
  }
695
+
696
+ // `require()` reads the exports object rather than a namespace, so
697
+ // only an import gets the spec object and interop keeps working.
698
+ const spec =
699
+ !moduleExportsAccess &&
700
+ exportsType === "namespace" &&
701
+ Boolean(
702
+ /** @type {BuildInfo} */
703
+ (info.module.buildInfo).specNamespaceObject
704
+ );
705
+ const rawName = getExternalModuleExpr(info);
706
+
707
+ if (spec) info.specNamespaceObjectUsed = true;
708
+
680
709
  return {
681
710
  info,
682
- rawName: getExternalModuleExpr(info),
711
+ rawName: spec
712
+ ? `${RuntimeGlobals.specNamespaceObject}(${rawName})`
713
+ : rawName,
683
714
  ids: exportName,
684
715
  exportName,
685
- accessorCall: info.wrapped
716
+ accessorCall: spec || info.wrapped
686
717
  };
718
+ }
687
719
  }
688
720
  }
689
721
  const exportsInfo = moduleGraph.getExportsInfo(info.module);
@@ -727,10 +759,9 @@ const getFinalBinding = (
727
759
  if (usedName instanceof InlinedUsedName) {
728
760
  return {
729
761
  info,
730
- // Render the inlined literal only (e.g. `"str"`), not its property
731
- // suffix: that suffix is returned in `ids` and appended once by
732
- // getFinalName. Using `usedName.render()` would emit it here too,
733
- // duplicating the access (e.g. `"str".a.a`).
762
+ // Render the inlined literal only, not its property suffix: that
763
+ // comes back in `ids` and getFinalName appends it once, so emitting
764
+ // it here too would duplicate the access.
734
765
  rawName: usedName.render(
735
766
  Template.toNormalComment(
736
767
  `inlined export ${propertyAccess(exportName)}`
@@ -981,12 +1012,12 @@ const getFinalName = (
981
1012
  ? `;(0,${reference})`
982
1013
  : `/*#__PURE__*/Object(${reference})`;
983
1014
  } else if (binding.info.wrapped) {
984
- return asiSafe === false ? `;(${reference})` : `(${reference})`;
1015
+ return parenthesizeReference(reference, asiSafe);
985
1016
  }
986
1017
  } else if (accessorCall && !asCall) {
987
1018
  // without parentheses `new X()` would construct the accessor rather
988
1019
  // than what it returns
989
- return asiSafe === false ? `;(${reference})` : `(${reference})`;
1020
+ return parenthesizeReference(reference, asiSafe);
990
1021
  }
991
1022
 
992
1023
  return reference;
@@ -995,7 +1026,6 @@ const getFinalName = (
995
1026
 
996
1027
  /**
997
1028
  * @typedef {object} ConcatenateModuleHooks
998
- * @property {SyncBailHook<[ConcatenatedModule, RuntimeSpec[], string, Record<string, string>], boolean>} onDemandExportsGeneration
999
1029
  * @property {SyncBailHook<[Partial<ConcatenatedModuleInfo>, ConcatenatedModuleInfo], boolean | void>} concatenatedModuleInfo
1000
1030
  */
1001
1031
 
@@ -1183,15 +1213,17 @@ class ConcatenatedModule extends Module {
1183
1213
 
1184
1214
  for (const m of this._modules) {
1185
1215
  // populate cacheable
1186
- const { cacheable, notCacheableReasons } = /** @type {BuildInfo} */ (
1187
- m.buildInfo
1188
- );
1216
+ const { cacheable, diagnostics } = /** @type {BuildInfo} */ (m.buildInfo);
1189
1217
  if (!cacheable) {
1190
1218
  this.buildInfo.cacheable = false;
1219
+ const notCacheableReasons =
1220
+ diagnostics === undefined
1221
+ ? undefined
1222
+ : diagnostics.notCacheableReasons;
1191
1223
  if (notCacheableReasons) {
1224
+ const own = getBuildDiagnostics(this.buildInfo);
1192
1225
  const reasons =
1193
- this.buildInfo.notCacheableReasons ||
1194
- (this.buildInfo.notCacheableReasons = []);
1226
+ own.notCacheableReasons || (own.notCacheableReasons = []);
1195
1227
  for (const reason of notCacheableReasons) {
1196
1228
  if (!reasons.includes(reason)) reasons.push(reason);
1197
1229
  }
@@ -1210,10 +1242,9 @@ class ConcatenatedModule extends Module {
1210
1242
  this.dependencies.push(d);
1211
1243
  }
1212
1244
  }
1213
- // populate codeGenerationDependencies — the inner modules'
1214
- // templates are applied during ConcatenatedModule.codeGeneration,
1215
- // so the referenced modules must have been code-generated by then.
1216
- // Skip references that point back into the concat set itself.
1245
+ // populate codeGenerationDependencies: the inner templates are applied
1246
+ // during this module's own codeGeneration, so what they reference must be
1247
+ // generated by then. References back into the concat set are skipped.
1217
1248
  if (m.codeGenerationDependencies !== undefined) {
1218
1249
  for (const d of m.codeGenerationDependencies) {
1219
1250
  const referenced =
@@ -1369,10 +1400,9 @@ class ConcatenatedModule extends Module {
1369
1400
  (connection.dependency);
1370
1401
  return {
1371
1402
  connection,
1372
- // A require() edge carries no sourceOrder; Infinity sorts it last,
1373
- // matching the low-priority sentinel. NaN must not be used here:
1374
- // compareNumbers returns 0 against every number, which makes the
1375
- // comparator non-transitive and the order depend on insertion order.
1403
+ // A require() edge carries no sourceOrder, and Infinity sorts it
1404
+ // last. Not NaN: `compareNumbers` returns 0 against every number,
1405
+ // which makes the comparator non-transitive.
1376
1406
  sourceOrder:
1377
1407
  typeof dep.sourceOrder === "number" ? dep.sourceOrder : Infinity,
1378
1408
  rangeStart: dep.range && dep.range[0],
@@ -1670,40 +1700,38 @@ class ConcatenatedModule extends Module {
1670
1700
  }
1671
1701
  }
1672
1702
 
1673
- /*
1674
- * How the inner modules become one flat source. Stages [1]-[5] only mutate the
1675
- * per-module info records (names, ReplaceSource patches); stages [6]-[9] append
1676
- * to the single output ConcatSource, in exactly the order shown.
1677
- *
1678
- * _getModulesWithInfo() — ordered concatenation list + one info per module
1679
- * | (concatenated [+wrapped] | external | reference)
1680
- * v
1681
- * [1] ANALYSE — inner codeGeneration() per module, into a ConcatenationScope
1682
- * | plain -> ReplaceSource + ast + scope analysis
1683
- * | wrapped -> ReplaceSource only, body kept verbatim
1684
- * | external -> nothing yet, rendered as a require() below
1685
- * [2] RESERVE — free globals of the analysed bodies enter allUsedNames, so
1686
- * | renaming in [3] can't shadow them (a wrapped body is not analysed;
1687
- * | the reserved `__webpack_` prefix protects it)
1688
- * [3] RENAME — module-scope variables renamed inside the ReplaceSource, then
1689
- * | the generated names allocated: wrapper accessor, namespace object,
1690
- * | interop helpers, external import variable
1691
- * [4] LINK — __WEBPACK_MODULE_REFERENCE__ tokens replaced by their final
1692
- * | binding; through the ast for analysed bodies, textually for wrapped
1693
- * [5] COLLECT EXPORTS — root exports split into used / unused / inlined
1694
- * v
1695
- * ---- from here on everything is appended to the result ConcatSource ----
1696
- * |
1697
- * [6] EMIT EXPORTS — __esModule flag + exports getters, UNUSED/INLINED lists
1698
- * [7] BUILD NS — namespace object sources built as strings (not emitted yet)
1699
- * [8] DEFINE — everything that must exist before any body runs: namespace
1700
- * | objects, wrapper accessors (wrapped modules and wrapped externals),
1701
- * | deferred external loaders
1702
- * [9] EVALUATE — bodies in concatenation order: plain bodies inline, externals
1703
- * | as require(); a wrapped body stays behind its accessor
1704
- * v
1705
- * [10] RESULT — CodeGenerationResult { sources, data, runtimeRequirements }
1706
- */
1703
+ // WHY: how the inner modules become one flat source. Stages [1]-[5] only mutate
1704
+ // the per-module info records (names, ReplaceSource patches); stages [6]-[9]
1705
+ // append to the single output ConcatSource, in exactly the order shown.
1706
+ //
1707
+ // _getModulesWithInfo() — ordered concatenation list + one info per module
1708
+ // | (concatenated [+wrapped] | external | reference)
1709
+ // v
1710
+ // [1] ANALYSE — inner codeGeneration() per module, into a ConcatenationScope
1711
+ // | plain -> ReplaceSource + ast + scope analysis
1712
+ // | wrapped -> ReplaceSource only, body kept verbatim
1713
+ // | external -> nothing yet, rendered as a require() below
1714
+ // [2] RESERVE — free globals of the analysed bodies enter allUsedNames, so
1715
+ // | renaming in [3] can't shadow them (a wrapped body is not analysed;
1716
+ // | the reserved `__webpack_` prefix protects it)
1717
+ // [3] RENAME — module-scope variables renamed inside the ReplaceSource, then
1718
+ // | the generated names allocated: wrapper accessor, namespace object,
1719
+ // | interop helpers, external import variable
1720
+ // [4] LINK — __WEBPACK_MODULE_REFERENCE__ tokens replaced by their final
1721
+ // | binding; through the ast for analysed bodies, textually for wrapped
1722
+ // [5] COLLECT EXPORTS — root exports split into used / unused / inlined
1723
+ // v
1724
+ // ---- from here on everything is appended to the result ConcatSource ----
1725
+ // |
1726
+ // [6] EMIT EXPORTS — __esModule flag + exports getters, UNUSED/INLINED lists
1727
+ // [7] BUILD NS — namespace object sources built as strings (not emitted yet)
1728
+ // [8] DEFINE — everything that must exist before any body runs: namespace
1729
+ // | objects, wrapper accessors (wrapped modules and wrapped externals),
1730
+ // | deferred external loaders
1731
+ // [9] EVALUATE — bodies in concatenation order: plain bodies inline, externals
1732
+ // | as require(); a wrapped body stays behind its accessor
1733
+ // v
1734
+ // [10] RESULT — CodeGenerationResult { sources, data, runtimeRequirements }
1707
1735
  /**
1708
1736
  * Generates code and runtime requirements for this module.
1709
1737
  * @param {CodeGenerationContext} context context for code generation
@@ -1821,6 +1849,15 @@ class ConcatenatedModule extends Module {
1821
1849
  return info.escapeNamespaceObjectName;
1822
1850
  }
1823
1851
  const exportsInfo = moduleGraph.getExportsInfo(info.module);
1852
+ // Its names are not mangled, and the wrapped binding is already the
1853
+ // namespace, so a decoupled object would only shadow it.
1854
+ if (
1855
+ /** @type {BuildInfo} */
1856
+ (info.module.buildInfo).specNamespaceObject
1857
+ ) {
1858
+ return undefined;
1859
+ }
1860
+
1824
1861
  let mangled = false;
1825
1862
  for (const exportInfo of exportsInfo.orderedExports) {
1826
1863
  if (exportInfo.provided === false) continue;
@@ -2065,10 +2102,9 @@ class ConcatenatedModule extends Module {
2065
2102
  switch (info.type) {
2066
2103
  case "concatenated": {
2067
2104
  if (info.wrapped) {
2068
- // A wrapped module declares exactly one shared-scope name: the
2069
- // lazy wrapper accessor holding its body. [2] claimed every
2070
- // identifier of that body, so findNewName avoids the ones that
2071
- // would shadow the accessor from inside it.
2105
+ // A wrapped module declares one shared-scope name, the lazy accessor
2106
+ // holding its body. Stage 2 claimed that body's identifiers, so
2107
+ // findNewName avoids the ones that would shadow it from inside.
2072
2108
  const namespaceFnName = findNewName(
2073
2109
  "namespaceFn",
2074
2110
  allUsedNames,
@@ -2376,10 +2412,9 @@ class ConcatenatedModule extends Module {
2376
2412
  }
2377
2413
  // #endregion
2378
2414
 
2379
- // #region [5] COLLECT EXPORTS: split the root module's exports into used /
2380
- // unused / inlined. Used ones stay thunks — resolving one can still
2381
- // register a namespace object, which [7] must see
2382
- // Map with all root exposed used exports
2415
+ // #region [5] COLLECT EXPORTS: split the root module's exports into used,
2416
+ // unused and inlined. Used ones stay thunks, since resolving one can still
2417
+ // register a namespace object that stage 7 must see.
2383
2418
  /** @type {Map<string, (requestShortener: RequestShortener) => string>} */
2384
2419
  const exportsMap = new Map();
2385
2420
 
@@ -2457,6 +2492,8 @@ class ConcatenatedModule extends Module {
2457
2492
  shouldAddHarmonyFlag = true;
2458
2493
  }
2459
2494
 
2495
+ /** @type {string | undefined} */
2496
+ let onDemandExportsSource;
2460
2497
  // define exports
2461
2498
  if (exportsMap.size > 0) {
2462
2499
  /** @type {string[]} */
@@ -2487,17 +2524,10 @@ class ConcatenatedModule extends Module {
2487
2524
  this.exportsArgument
2488
2525
  }, {${definitions.join(",")}\n});\n`;
2489
2526
 
2490
- const { onDemandExportsGeneration } =
2491
- ConcatenatedModule.getCompilationHooks(this.compilation);
2492
-
2493
- if (
2494
- !onDemandExportsGeneration.call(
2495
- this,
2496
- runtimes,
2497
- `${harmonyFlagSource}${exportsSource}`,
2498
- exportsFinalName
2499
- )
2500
- ) {
2527
+ const meta = moduleGraph.getMetaIfExisting(this);
2528
+ if (meta !== undefined && meta.onDemandExports === true) {
2529
+ onDemandExportsSource = `${harmonyFlagSource}${exportsSource}`;
2530
+ } else {
2501
2531
  result.add(harmonyFlagSource);
2502
2532
  result.add(exportsSource);
2503
2533
  }
@@ -2519,13 +2549,12 @@ class ConcatenatedModule extends Module {
2519
2549
  // #endregion
2520
2550
 
2521
2551
  // #region [7] BUILD NS: namespace object sources are built as strings here
2522
- // and emitted by [8]; an external's is emitted next to its import variable
2523
- // or accessor instead, which is defined later.
2524
- //
2525
- // generate decoupled namespace objects for escaping mangled namespaces:
2526
- // same getters as the regular namespace object, but keyed by the original
2527
- // export names so untracked access by name keeps working. Done before the
2528
- // regular namespace objects so any nested namespace they pull in is built.
2552
+ // and emitted by stage 8; an external's goes next to its import variable or
2553
+ // accessor instead, defined later.
2554
+
2555
+ // Decoupled namespace objects for escaping mangled namespaces carry the same
2556
+ // getters keyed by the original export names, so untracked access by name
2557
+ // keeps working. Built first, so any nested namespace they pull in exists.
2529
2558
  /** @type {Map<ConcatenatedModuleInfo | ExternalModuleInfo, string>} */
2530
2559
  const escapeNamespaceObjectSources = new Map();
2531
2560
  for (const info of neededEscapeNamespaceObjects) {
@@ -2697,10 +2726,9 @@ ${defineGetters}`
2697
2726
  }) {\n`
2698
2727
  );
2699
2728
  result.add(/** @type {ReplaceSource} */ (info.source));
2700
- // A generated body (json, asset, html) binds its value to a local
2701
- // instead of writing exports; hand that local to the accessor. The
2702
- // name is verbatim: a wrapped body is not scope-analysed, so it keeps
2703
- // the reserved symbol the generator registered.
2729
+ // A generated body binds its value to a local rather than writing
2730
+ // exports, so hand that local to the accessor. The name is verbatim: a
2731
+ // wrapped body is not scope-analysed and keeps the reserved symbol.
2704
2732
  result.add(
2705
2733
  info.namespaceExportSymbol
2706
2734
  ? `\n${info.module.moduleArgument}.exports = ${info.namespaceExportSymbol};\n});\n`
@@ -2719,10 +2747,18 @@ ${defineGetters}`
2719
2747
  runtimeRequirements
2720
2748
  });
2721
2749
  const moduleId = JSON.stringify(chunkGraph.getModuleId(info.module));
2750
+ const required = `${RuntimeGlobals.require}(${moduleId})`;
2751
+
2752
+ // The wrapping happens per reference, so only the helper has to be
2753
+ // declared here.
2754
+ if (info.specNamespaceObjectUsed) {
2755
+ runtimeRequirements.add(RuntimeGlobals.specNamespaceObject);
2756
+ }
2757
+
2722
2758
  const body =
2723
2759
  condition === "true"
2724
- ? `return ${RuntimeGlobals.require}(${moduleId});`
2725
- : `if (${condition}) return ${RuntimeGlobals.require}(${moduleId});`;
2760
+ ? `return ${required};`
2761
+ : `if (${condition}) return ${required};`;
2726
2762
  result.add(
2727
2763
  `\n// EXTERNAL MODULE: ${info.module.readableIdentifier(
2728
2764
  requestShortener
@@ -2778,14 +2814,31 @@ ${defineGetters}`
2778
2814
  );
2779
2815
  if (info.deferredNamespaceObjectUsed) {
2780
2816
  runtimeRequirements.add(RuntimeGlobals.makeDeferredNamespaceObject);
2817
+ // Every call site for a module must agree on the shape, since the
2818
+ // runtime caches one namespace object per module and mode.
2819
+ const deferredExportsType = getExportsType(
2820
+ moduleGraph,
2821
+ info,
2822
+ strictHarmonyModule
2823
+ );
2824
+ const names = getKnownExportNames(
2825
+ moduleGraph,
2826
+ info.module,
2827
+ deferredExportsType
2828
+ );
2829
+ runtimeRequirements.add(
2830
+ names
2831
+ ? RuntimeGlobals.hasSealedDeferredNamespace
2832
+ : RuntimeGlobals.hasSynthesizedDeferredNamespace
2833
+ );
2781
2834
  result.add(
2782
2835
  `\nvar ${info.deferredNamespaceObjectName} = /*#__PURE__*/${
2783
2836
  RuntimeGlobals.makeDeferredNamespaceObject
2784
2837
  }(${JSON.stringify(
2785
2838
  chunkGraph.getModuleId(info.module)
2786
2839
  )}, ${getMakeDeferredNamespaceModeFromExportsType(
2787
- getExportsType(moduleGraph, info, strictHarmonyModule)
2788
- )});`
2840
+ deferredExportsType
2841
+ )}${names ? `, ${JSON.stringify(names)}` : ""});`
2789
2842
  );
2790
2843
  }
2791
2844
  }
@@ -2871,7 +2924,15 @@ ${defineGetters}`
2871
2924
  // External module bindings may be wrapped in
2872
2925
  // runtime-condition `if` blocks but referenced outside,
2873
2926
  // so they must remain function-scoped (`var`).
2874
- result.add(`var ${info.name} = __webpack_require__(${moduleId});`);
2927
+ const required = `__webpack_require__(${moduleId})`;
2928
+
2929
+ // The wrapping happens per reference, so only the helper has
2930
+ // to be declared here.
2931
+ if (info.specNamespaceObjectUsed) {
2932
+ runtimeRequirements.add(RuntimeGlobals.specNamespaceObject);
2933
+ }
2934
+
2935
+ result.add(`var ${info.name} = ${required};`);
2875
2936
 
2876
2937
  // Decoupled namespace object for an escaping mangled external
2877
2938
  // module must come after its import variable is defined.
@@ -2904,9 +2965,8 @@ ${defineGetters}`
2904
2965
  throw new Error(`Unsupported concatenation entry type ${info.type}`);
2905
2966
  }
2906
2967
  // Building a wrapped module's interop object here would evaluate its body
2907
- // at the top level and break require() cycles, so defer it behind a
2908
- // hoisted function. The memo lives on the function object: it keeps the
2909
- // identity stable without claiming a second top-level name.
2968
+ // at the top level and break require() cycles, so it is deferred behind a
2969
+ // hoisted function, memoized on the function object itself.
2910
2970
  /**
2911
2971
  * @param {string} interopName interop variable name
2912
2972
  * @param {string} expr interop object expression
@@ -2958,6 +3018,10 @@ ${defineGetters}`
2958
3018
  }
2959
3019
  data.set("topLevelDeclarations", topLevelDeclarations);
2960
3020
  data.set("freeNames", freeNames);
3021
+ if (onDemandExportsSource !== undefined) {
3022
+ data.set("exportsSource", onDemandExportsSource);
3023
+ data.set("exportsFinalName", exportsFinalName);
3024
+ }
2961
3025
 
2962
3026
  /** @type {CodeGenerationResult} */
2963
3027
  const resultEntry = {
@@ -2997,10 +3061,9 @@ ${defineGetters}`
2997
3061
  if (info.type === "concatenated") {
2998
3062
  const m = info.module;
2999
3063
  if (info.wrapped) {
3000
- // the wrapper isolates the body's top-level declarations, so no
3001
- // renaming is needed -- only a concatenation scope, to rewrite in-scope
3002
- // `require()` targets to accessor references. [2] claims its identifiers
3003
- // textually in place of the scope analysis skipped here.
3064
+ // the wrapper isolates the body's top-level declarations, so only a
3065
+ // concatenation scope is needed, rewriting in-scope `require()` targets.
3066
+ // Stage 2 claims its identifiers textually, in place of that analysis.
3004
3067
  const concatenationScope = new ConcatenationScope(
3005
3068
  modulesMap,
3006
3069
  info,
@@ -3179,6 +3242,7 @@ ${defineGetters}`
3179
3242
  namespaceFnName: undefined,
3180
3243
  escapeNamespaceObjectName: undefined,
3181
3244
  deferredName: undefined,
3245
+ specNamespaceObjectUsed: false,
3182
3246
  interopNamespaceObjectUsed: false,
3183
3247
  interopNamespaceObjectName: undefined,
3184
3248
  interopNamespaceObject2Used: false,
@@ -3272,12 +3336,6 @@ ${defineGetters}`
3272
3336
  ConcatenatedModule.getCompilationHooks = createHooksRegistry(
3273
3337
  () =>
3274
3338
  /** @type {ConcatenateModuleHooks} */ ({
3275
- onDemandExportsGeneration: new SyncBailHook([
3276
- "module",
3277
- "runtimes",
3278
- "exportsFinalName",
3279
- "exportsSource"
3280
- ]),
3281
3339
  concatenatedModuleInfo: new SyncBailHook([
3282
3340
  "updatedInfo",
3283
3341
  "concatenatedModuleInfo"