webpack 5.112.0 → 5.112.1

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 (263) hide show
  1. package/bin/webpack.js +13 -7
  2. package/lib/Compilation.js +152 -60
  3. package/lib/Compiler.js +12 -25
  4. package/lib/asset/AssetBytesGenerator.js +14 -6
  5. package/lib/asset/AssetBytesParser.js +10 -8
  6. package/lib/asset/AssetGenerator.js +36 -48
  7. package/lib/asset/AssetModule.js +11 -0
  8. package/lib/asset/AssetModulesPlugin.js +5 -4
  9. package/lib/asset/AssetParser.js +8 -8
  10. package/lib/asset/AssetSourceGenerator.js +16 -8
  11. package/lib/asset/AssetSourceParser.js +10 -8
  12. package/lib/asset/WebManifestGenerator.js +11 -6
  13. package/lib/asset/WebManifestParser.js +3 -3
  14. package/lib/async-modules/AsyncModuleHelpers.js +8 -2
  15. package/lib/async-modules/InferAsyncModulesPlugin.js +7 -2
  16. package/lib/cache/CacheFacade.js +1 -1
  17. package/lib/cache/PackFileCacheStrategy.js +6 -10
  18. package/lib/cache/ResolverCachePlugin.js +58 -8
  19. package/lib/config/WebpackOptionsApply.js +8 -28
  20. package/lib/config/cli.js +9 -6
  21. package/lib/config/defaults.js +24 -13
  22. package/lib/config/getClaimedAssetTypes.js +2 -2
  23. package/lib/config/target.js +1 -1
  24. package/lib/context/ContextModule.js +1 -1
  25. package/lib/context/ContextModuleFactory.js +1 -1
  26. package/lib/context/ContextReplacementPlugin.js +3 -9
  27. package/lib/css/CssGenerator.js +40 -37
  28. package/lib/css/CssModule.js +10 -0
  29. package/lib/css/CssModulesPlugin.js +2 -2
  30. package/lib/css/CssParser.js +33 -32
  31. package/lib/css/conventions.js +1 -1
  32. package/lib/css/data.js +224 -219
  33. package/lib/css/syntax-parser.js +1159 -298
  34. package/lib/css/syntax-printer.js +90 -35
  35. package/lib/debug/ProfilingPlugin.js +65 -43
  36. package/lib/define/DefinePlugin.js +10 -15
  37. package/lib/define/DotenvPlugin.js +10 -6
  38. package/lib/define/EnvironmentPlugin.js +4 -2
  39. package/lib/dependencies/amd/AMDDefineDependencyParserPlugin.js +1 -2
  40. package/lib/dependencies/amd/AMDRequireDependenciesBlockParserPlugin.js +4 -1
  41. package/lib/dependencies/commonjs/CommonJsExportRequireDependency.js +1 -4
  42. package/lib/dependencies/commonjs/CommonJsExportsParserPlugin.js +18 -33
  43. package/lib/dependencies/commonjs/CommonJsImportsParserPlugin.js +1 -3
  44. package/lib/dependencies/commonjs/CommonJsObjectExportDependency.js +4 -4
  45. package/lib/dependencies/commonjs/CommonJsPlugin.js +2 -5
  46. package/lib/dependencies/commonjs/RequireEnsureDependenciesBlockParserPlugin.js +4 -1
  47. package/lib/dependencies/context/ImportMetaContextDependencyParserPlugin.js +1 -2
  48. package/lib/dependencies/context/ImportMetaGlobDependencyParserPlugin.js +4 -7
  49. package/lib/dependencies/context/ImportMetaGlobHelpers.js +8 -10
  50. package/lib/dependencies/core/CachedConstDependency.js +9 -6
  51. package/lib/dependencies/css/CssIcssExportDependency.js +6 -7
  52. package/lib/dependencies/css/CssIcssImportDependency.js +1 -3
  53. package/lib/dependencies/css/CssUrlDependency.js +2 -6
  54. package/lib/dependencies/esm/ESMDetectionParserPlugin.js +2 -4
  55. package/lib/dependencies/esm/ESMExportExpressionDependency.js +2 -2
  56. package/lib/dependencies/esm/ESMExportImportedSpecifierDependency.js +16 -18
  57. package/lib/dependencies/esm/ESMExportSpecifierDependency.js +20 -3
  58. package/lib/dependencies/esm/ESMExports.js +2 -10
  59. package/lib/dependencies/esm/ESMImportDependency.js +17 -2
  60. package/lib/dependencies/esm/ESMImportDependencyParserPlugin.js +6 -17
  61. package/lib/dependencies/esm/ESMImportGuard.js +11 -23
  62. package/lib/dependencies/esm/ESMImportSideEffectDependency.js +1 -1
  63. package/lib/dependencies/esm/ESMImportSpecifierDependency.js +4 -1
  64. package/lib/dependencies/esm/ESMLiveExportDependency.js +311 -0
  65. package/lib/dependencies/esm/ESMLiveExportParserPlugin.js +862 -0
  66. package/lib/dependencies/esm/ESMModulesPlugin.js +1 -3
  67. package/lib/dependencies/esm/TopLevelAwaitDependency.js +1 -8
  68. package/lib/dependencies/helpers/DynamicExports.js +4 -6
  69. package/lib/dependencies/html/HtmlEntryDependency.js +5 -14
  70. package/lib/dependencies/html/HtmlInlineHtmlDependency.js +1 -4
  71. package/lib/dependencies/html/HtmlInlineScriptDependency.js +2 -6
  72. package/lib/dependencies/html/HtmlInlineStyleDependency.js +1 -4
  73. package/lib/dependencies/import/ImportParserPlugin.js +3 -6
  74. package/lib/dependencies/import-meta/ImportMetaPlugin.js +4 -6
  75. package/lib/dependencies/url/URLParserPlugin.js +1 -1
  76. package/lib/dependencies/worker/WorkerAndWorkletPlugin.js +51 -20
  77. package/lib/devtool/ModuleFilenameHelpers.js +1 -1
  78. package/lib/devtool/SourceMapDevToolPlugin.js +1 -1
  79. package/lib/dll/DelegatedModule.js +3 -3
  80. package/lib/dll/DllModule.js +3 -1
  81. package/lib/dll/DllReferencePlugin.js +1 -4
  82. package/lib/errors/AbstractMethodError.js +1 -1
  83. package/lib/errors/ErrorHelpers.js +2 -1
  84. package/lib/errors/HookWebpackError.js +2 -1
  85. package/lib/errors/JSONParseError.js +4 -4
  86. package/lib/errors/WebpackError.js +3 -2
  87. package/lib/esm/ModuleChunkFormatPlugin.js +36 -1
  88. package/lib/externals/ExternalModule.js +12 -9
  89. package/lib/externals/ExternalModuleFactoryPlugin.js +1 -2
  90. package/lib/externals/ExternalsPlugin.js +1 -1
  91. package/lib/fs/FileSystemInfo.js +4 -4
  92. package/lib/graph/AsyncDependenciesBlock.js +1 -1
  93. package/lib/graph/ChunkGraph.js +5 -0
  94. package/lib/graph/Dependency.js +8 -2
  95. package/lib/graph/ExportsInfo.js +1 -1
  96. package/lib/graph/ModuleGraph.js +14 -3
  97. package/lib/graph/buildChunkGraph.js +17 -19
  98. package/lib/graph/findGraphRoots.js +1 -1
  99. package/lib/hmr/HotModuleReplacement.runtime.js +10 -9
  100. package/lib/hmr/HotModuleReplacementPlugin.js +5 -11
  101. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +16 -19
  102. package/lib/hmr/LazyCompilationPlugin.js +1 -7
  103. package/lib/html/HtmlGenerator.js +25 -17
  104. package/lib/html/HtmlModule.js +11 -1
  105. package/lib/html/HtmlModulesPlugin.js +12 -11
  106. package/lib/html/HtmlParser.js +10 -9
  107. package/lib/html/builtinEmbeddedRenderer.js +31 -33
  108. package/lib/html/data.js +42 -21
  109. package/lib/html/htmlMinify.js +4 -1
  110. package/lib/html/syntax-parser.js +34 -35
  111. package/lib/html/syntax-printer.js +2 -3
  112. package/lib/html/xmlMinify.js +4 -1
  113. package/lib/ids/HashedModuleIdsPlugin.js +1 -1
  114. package/lib/index.js +13 -12
  115. package/lib/javascript/APIPlugin.js +7 -13
  116. package/lib/javascript/BasicEvaluatedExpression.js +5 -5
  117. package/lib/javascript/CommonJsChunkFormatPlugin.js +2 -7
  118. package/lib/javascript/ConstPlugin.js +1 -1
  119. package/lib/javascript/JavascriptGenerator.js +16 -11
  120. package/lib/javascript/JavascriptMetaInfoPlugin.js +3 -15
  121. package/lib/javascript/JavascriptModule.js +10 -0
  122. package/lib/javascript/JavascriptModulesPlugin.js +2 -4
  123. package/lib/javascript/JavascriptParser.js +99 -11
  124. package/lib/javascript/ScopeAnalyzer.js +183 -107
  125. package/lib/javascript/UseStrictPlugin.js +2 -5
  126. package/lib/javascript/jsMinify.js +1 -1
  127. package/lib/javascript/regexp.js +2 -2
  128. package/lib/javascript/syntax-parser.js +2114 -1506
  129. package/lib/javascript/syntax-printer-data.js +167 -1
  130. package/lib/javascript/syntax-printer.js +9554 -2782
  131. package/lib/json/JsonGenerator.js +15 -7
  132. package/lib/json/JsonModule.js +11 -0
  133. package/lib/json/JsonParser.js +7 -6
  134. package/lib/library/AssignLibraryPlugin.js +1 -1
  135. package/lib/library/JsonpLibraryPlugin.js +1 -1
  136. package/lib/library/ModuleLibraryPlugin.js +399 -23
  137. package/lib/loaders/LoaderRunner.js +76 -38
  138. package/lib/loaders/loadLoader.js +16 -10
  139. package/lib/module/Generator.js +17 -9
  140. package/lib/module/Module.js +2 -2
  141. package/lib/module/NormalModule.js +7 -5
  142. package/lib/module/NormalModuleFactory.js +11 -17
  143. package/lib/module/Parser.js +9 -2
  144. package/lib/module/extractSourceMap.js +69 -18
  145. package/lib/module/findCaseMismatch.js +2 -2
  146. package/lib/node/ExternalModuleInitFragment.js +2 -2
  147. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +4 -12
  148. package/lib/node/ReadFileCompileWasmPlugin.js +2 -6
  149. package/lib/node/nodeConsole.js +4 -3
  150. package/lib/optimize/CircularModulesPlugin.js +1 -1
  151. package/lib/optimize/ConcatenatedModule.js +2 -6
  152. package/lib/optimize/FlagDependencyExportsPlugin.js +6 -11
  153. package/lib/optimize/FlagDependencyUsagePlugin.js +28 -3
  154. package/lib/optimize/InlineExports.js +4 -7
  155. package/lib/optimize/LazyBarrels.js +41 -5
  156. package/lib/optimize/ModuleConcatenationPlugin.js +8 -10
  157. package/lib/optimize/RealContentHashPlugin.js +2 -6
  158. package/lib/optimize/SideEffectsFlagPlugin.js +7 -21
  159. package/lib/optimize/SplitChunksPlugin.js +11 -24
  160. package/lib/optimize/TupleQueue.js +1 -1
  161. package/lib/output/CleanPlugin.js +3 -1
  162. package/lib/output/CopyPlugin.js +3 -4
  163. package/lib/performance/EvalUsagePlugin.js +1 -3
  164. package/lib/performance/HotspotsPlugin.js +33 -9
  165. package/lib/performance/PureAnnotationsPlugin.js +16 -10
  166. package/lib/performance/TopLevelThisPlugin.js +17 -9
  167. package/lib/prefetch/ResourceHintPlugin.js +1 -1
  168. package/lib/provide/ProvidedDependency.js +36 -4
  169. package/lib/rules/BasicEffectRulePlugin.js +1 -1
  170. package/lib/rules/RuleSetCompiler.js +15 -5
  171. package/lib/rules/UseEffectRulePlugin.js +1 -3
  172. package/lib/runtime/AsyncModuleRuntimeModule.js +7 -1
  173. package/lib/runtime/GetChunkFilenameRuntimeModule.js +1 -5
  174. package/lib/runtime/RuntimeGlobals.js +6 -0
  175. package/lib/runtime/RuntimePlugin.js +2 -0
  176. package/lib/schemes/HttpUriPlugin.js +1 -2
  177. package/lib/schemes/VirtualUrlPlugin.js +3 -1
  178. package/lib/serialization/AggregateErrorSerializer.js +3 -3
  179. package/lib/serialization/BinaryMiddleware.js +4 -1
  180. package/lib/serialization/ErrorObjectSerializer.js +2 -5
  181. package/lib/serialization/ObjectMiddleware.js +17 -15
  182. package/lib/serialization/PlainObjectSerializer.js +3 -7
  183. package/lib/serialization/Serializer.js +21 -11
  184. package/lib/serialization/SerializerMiddleware.js +8 -6
  185. package/lib/stats/DefaultStatsFactoryPlugin.js +35 -35
  186. package/lib/stats/DefaultStatsPresetPlugin.js +2 -6
  187. package/lib/stats/DefaultStatsPrinterPlugin.js +12 -11
  188. package/lib/stats/StatsFactory.js +194 -24
  189. package/lib/stats/StatsPrinter.js +126 -13
  190. package/lib/template/DependencyTemplate.js +1 -1
  191. package/lib/template/RuntimeTemplate.js +13 -32
  192. package/lib/template/Template.js +1 -1
  193. package/lib/util/SourceProcessor.js +98 -15
  194. package/lib/util/WeakTupleMap.js +10 -4
  195. package/lib/util/cleverMerge.js +61 -33
  196. package/lib/util/comparators.js +9 -5
  197. package/lib/util/dataURL.js +2 -0
  198. package/lib/util/deprecation.js +4 -3
  199. package/lib/util/globUtils.js +1 -4
  200. package/lib/util/internalSerializables.js +2 -0
  201. package/lib/util/makeSerializable.js +6 -4
  202. package/lib/util/memoize.js +1 -1
  203. package/lib/util/parseJson.js +2 -2
  204. package/lib/util/serialization.js +31 -27
  205. package/lib/wasm/AsyncWasmModule.js +12 -2
  206. package/lib/wasm/AsyncWebAssemblyGenerator.js +12 -4
  207. package/lib/wasm/AsyncWebAssemblyJavascriptGenerator.js +13 -5
  208. package/lib/wasm/AsyncWebAssemblyParser.js +7 -5
  209. package/lib/wasm/UniversalCompileAsyncWasmPlugin.js +2 -6
  210. package/lib/wasm-sync/SyncWasmModule.js +16 -1
  211. package/lib/wasm-sync/WebAssemblyGenerator.js +15 -10
  212. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +13 -5
  213. package/lib/wasm-sync/WebAssemblyParser.js +10 -12
  214. package/lib/web/FetchCompileAsyncWasmPlugin.js +4 -12
  215. package/lib/web/FetchCompileWasmPlugin.js +2 -6
  216. package/package.json +16 -18
  217. package/schemas/WebpackOptions.check.js +3 -3
  218. package/schemas/WebpackOptions.json +2 -2
  219. package/schemas/plugins/BannerPlugin.check.js +3 -3
  220. package/schemas/plugins/HtmlGeneratorOptions.check.js +3 -3
  221. package/schemas/plugins/HtmlParserOptions.check.js +3 -3
  222. package/schemas/plugins/IgnorePlugin.check.js +3 -3
  223. package/schemas/plugins/LoaderOptionsPlugin.check.js +3 -3
  224. package/schemas/plugins/ManifestPlugin.check.js +3 -3
  225. package/schemas/plugins/ProgressPlugin.check.js +3 -3
  226. package/schemas/plugins/SSRManifestPlugin.check.js +3 -3
  227. package/schemas/plugins/SourceMapDevToolPlugin.check.js +3 -3
  228. package/schemas/plugins/WatchIgnorePlugin.check.js +3 -3
  229. package/schemas/plugins/asset/AssetGeneratorOptions.check.js +3 -3
  230. package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.js +3 -3
  231. package/schemas/plugins/asset/AssetParserOptions.check.js +3 -3
  232. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +3 -3
  233. package/schemas/plugins/container/ContainerPlugin.check.js +3 -3
  234. package/schemas/plugins/container/ContainerReferencePlugin.check.js +3 -3
  235. package/schemas/plugins/container/ExternalsType.check.js +3 -3
  236. package/schemas/plugins/container/ModuleFederationPlugin.check.js +3 -3
  237. package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.js +3 -3
  238. package/schemas/plugins/css/CssGeneratorOptions.check.js +3 -3
  239. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +3 -3
  240. package/schemas/plugins/css/CssModuleParserOptions.check.js +3 -3
  241. package/schemas/plugins/css/CssParserOptions.check.js +3 -3
  242. package/schemas/plugins/debug/ProfilingPlugin.check.js +3 -3
  243. package/schemas/plugins/define/DotenvPluginOptions.check.js +7 -0
  244. package/schemas/plugins/define/DotenvPluginOptions.json +3 -0
  245. package/schemas/plugins/dll/DllPlugin.check.js +3 -3
  246. package/schemas/plugins/dll/DllReferencePlugin.check.js +3 -3
  247. package/schemas/plugins/ids/HashedModuleIdsPlugin.check.js +3 -3
  248. package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.check.js +3 -3
  249. package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.check.js +3 -3
  250. package/schemas/plugins/json/JsonModulesPluginGenerator.check.js +3 -3
  251. package/schemas/plugins/json/JsonModulesPluginParser.check.js +3 -3
  252. package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +3 -3
  253. package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +3 -3
  254. package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.js +3 -3
  255. package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +3 -3
  256. package/schemas/plugins/output/CleanOptions.check.js +7 -0
  257. package/schemas/plugins/output/CleanOptions.json +3 -0
  258. package/schemas/plugins/schemes/HttpUriPlugin.check.js +3 -3
  259. package/schemas/plugins/schemes/VirtualUrlPlugin.check.js +3 -3
  260. package/schemas/plugins/sharing/ConsumeSharedPlugin.check.js +3 -3
  261. package/schemas/plugins/sharing/ProvideSharedPlugin.check.js +3 -3
  262. package/schemas/plugins/sharing/SharePlugin.check.js +3 -3
  263. package/types.d.ts +1482 -358
@@ -36,7 +36,6 @@ const {
36
36
  /** @import ExportsInfo, { ExportInfo } from "../../graph/ExportsInfo" */
37
37
  /** @import Module from "../../module/Module" */
38
38
  /** @import ModuleGraph from "../../graph/ModuleGraph" */
39
- /** @import ModuleGraphConnection from "../../graph/ModuleGraphConnection" */
40
39
  /** @import { Range } from "../../javascript/JavascriptParser" */
41
40
  /** @import { RuntimeSpec } from "../../util/runtime" */
42
41
  /** @import CommonJsRequireDependency from "./CommonJsRequireDependency" */
@@ -576,9 +575,7 @@ CommonJsExportRequireDependency.Template = class CommonJsExportRequireDependency
576
575
  moduleGraph.getExportsInfo(module).getUsedName(dep.names, runtime)
577
576
  );
578
577
 
579
- const connection = /** @type {ModuleGraphConnection | undefined} */ (
580
- moduleGraph.getConnection(dep)
581
- );
578
+ const connection = moduleGraph.getConnection(dep);
582
579
  // Inactive unused reexport: no module id; drop to a no-op.
583
580
  // Missing connection (e.g. IgnorePlugin) must keep the require so it throws.
584
581
  if (!used && connection && !connection.isTargetActive(runtime)) {
@@ -52,7 +52,6 @@ const FUNCTION_PROPERTY_DROP_HEAD =
52
52
  */
53
53
  /** @import CommonJsRequireDependency from "./CommonJsRequireDependency" */
54
54
  /** @import { ExportInfoName } from "../../graph/Dependency" */
55
- /** @import { BuildInfo } from "../../module/Module" */
56
55
 
57
56
  /**
58
57
  * @import JavascriptParser, {
@@ -72,11 +71,6 @@ const FUNCTION_PROPERTY_DROP_HEAD =
72
71
  * } from "./CommonJsObjectExportDependency"
73
72
  */
74
73
  /** @import { RequireBindingData } from "./CommonJsImportsParserPlugin" */
75
- /**
76
- * @import {
77
- * JavascriptModuleBuildMeta
78
- * } from "../../javascript/JavascriptModule"
79
- */
80
74
 
81
75
  /**
82
76
  * This function takes a generic expression and detects whether it is an ObjectExpression.
@@ -165,7 +159,7 @@ const getReexportOfPropertyDescriptor = (expr) => {
165
159
  if (getFn.async || getFn.generator) return;
166
160
  // Arrow with expression body: `() => require("./x")`.
167
161
  if (getFn.body.type !== "BlockStatement") {
168
- return { expr: /** @type {Expression} */ (getFn.body), getter: true };
162
+ return { expr: getFn.body, getter: true };
169
163
  }
170
164
  // Function body must be exactly `return <expr>;`.
171
165
  if (
@@ -264,15 +258,18 @@ const parseRequireCall = (parser, expr) => {
264
258
  };
265
259
  };
266
260
 
261
+ /** @typedef {Node extends infer N ? (N extends Node ? N[keyof N] : never) : never} NodeFieldValue */
262
+
267
263
  /**
268
264
  * Checks if a value is an AST node.
269
- * @param {unknown} value candidate
270
- * @returns {value is Node} true when the value is an AST node
265
+ * @template V
266
+ * @param {V} value candidate
267
+ * @returns {value is Extract<V, Node>} true when the value is an AST node
271
268
  */
272
269
  const isNode = (value) =>
273
270
  typeof value === "object" &&
274
271
  value !== null &&
275
- typeof (/** @type {{ type?: unknown }} */ (value).type) === "string";
272
+ typeof (/** @type {Partial<Node>} */ (value).type) === "string";
276
273
 
277
274
  /** Positional/metadata keys that never hold child AST nodes. */
278
275
  const NON_CHILD_KEYS = new Set([
@@ -337,8 +334,8 @@ const findOwnThisExpression = (body, params) => {
337
334
  break;
338
335
  default: {
339
336
  const children =
340
- /** @type {Record<string, unknown>} */
341
- (/** @type {unknown} */ (node));
337
+ /** @type {Node & Record<string, NodeFieldValue>} */
338
+ (node);
342
339
  const keys = getChildKeys(node);
343
340
  for (let i = 0; i < keys.length; i++) {
344
341
  const value = children[keys[i]];
@@ -462,11 +459,11 @@ class CommonJsExportsParserPlugin {
462
459
  */
463
460
  const bailoutHint = (reason) => {
464
461
  recordOptimizationBailout(
465
- /** @type {BuildInfo} */ (parser.state.module.buildInfo),
462
+ parser.state.module.buildInfo,
466
463
  `CommonJS bailout: ${reason}`
467
464
  );
468
465
  };
469
- /** @type {unknown} */
466
+ /** @type {JavascriptParser["state"] | undefined} */
470
467
  let keptAllExportsForState;
471
468
  /**
472
469
  * An exported function accessing its own `this` may reach any export
@@ -547,9 +544,7 @@ class CommonJsExportsParserPlugin {
547
544
  dep.loc = parser.getLocation(expr);
548
545
  dep.optional = Boolean(parser.scope.inTry);
549
546
  parser.state.module.addDependency(dep);
550
- /** @type {JavascriptModuleBuildMeta} */ (
551
- parser.state.module.buildMeta
552
- ).treatAsCommonJs = true;
547
+ parser.state.module.buildMeta.treatAsCommonJs = true;
553
548
 
554
549
  return true;
555
550
  }
@@ -574,9 +569,7 @@ class CommonJsExportsParserPlugin {
574
569
  );
575
570
  dep.loc = parser.getLocation(expr);
576
571
  parser.state.module.addDependency(dep);
577
- /** @type {JavascriptModuleBuildMeta} */ (
578
- parser.state.module.buildMeta
579
- ).treatAsCommonJs = true;
572
+ parser.state.module.buildMeta.treatAsCommonJs = true;
580
573
  keepAllExportsOnThisAccess(expr.right, base);
581
574
  parser.walkExpression(expr.right);
582
575
  return true;
@@ -600,9 +593,7 @@ class CommonJsExportsParserPlugin {
600
593
  if (object.type !== "ObjectExpression") return;
601
594
 
602
595
  const module = parser.state.module;
603
- /** @type {JavascriptModuleBuildMeta} */ (
604
- module.buildMeta
605
- ).treatAsCommonJs = true;
596
+ module.buildMeta.treatAsCommonJs = true;
606
597
  // LHS stays as the text `module.exports` (moduleArgument is "module"
607
598
  // unless a top-level `module` binding shadows it, which prevents this hook).
608
599
  module.addPresentationalDependency(
@@ -697,7 +688,7 @@ class CommonJsExportsParserPlugin {
697
688
  parser.hooks.call
698
689
  .for("Object.defineProperty")
699
690
  .tap(PLUGIN_NAME, (expression) => {
700
- const expr = /** @type {CallExpression} */ (expression);
691
+ const expr = expression;
701
692
  if (!parser.isStatementLevelExpression(expr)) return;
702
693
  if (expr.arguments.length !== 3) return;
703
694
  if (expr.arguments[0].type === "SpreadElement") return;
@@ -747,9 +738,7 @@ class CommonJsExportsParserPlugin {
747
738
  dep.loc = parser.getLocation(expr);
748
739
  dep.optional = Boolean(parser.scope.inTry);
749
740
  parser.state.module.addDependency(dep);
750
- /** @type {JavascriptModuleBuildMeta} */ (
751
- parser.state.module.buildMeta
752
- ).treatAsCommonJs = true;
741
+ parser.state.module.buildMeta.treatAsCommonJs = true;
753
742
 
754
743
  return true;
755
744
  }
@@ -768,9 +757,7 @@ class CommonJsExportsParserPlugin {
768
757
  );
769
758
  dep.loc = parser.getLocation(expr);
770
759
  parser.state.module.addDependency(dep);
771
- /** @type {JavascriptModuleBuildMeta} */ (
772
- parser.state.module.buildMeta
773
- ).treatAsCommonJs = true;
760
+ parser.state.module.buildMeta.treatAsCommonJs = true;
774
761
 
775
762
  if (descArg.type === "ObjectExpression") {
776
763
  // `value`, `get` and `set` descriptor functions are all called
@@ -824,9 +811,7 @@ class CommonJsExportsParserPlugin {
824
811
  );
825
812
  dep.loc = parser.getLocation(expr);
826
813
  parser.state.module.addDependency(dep);
827
- /** @type {JavascriptModuleBuildMeta} */ (
828
- parser.state.module.buildMeta
829
- ).treatAsCommonJs = true;
814
+ parser.state.module.buildMeta.treatAsCommonJs = true;
830
815
 
831
816
  if (call) {
832
817
  parser.walkExpressions(call.arguments);
@@ -189,9 +189,7 @@ const createRequireCallHandler = (
189
189
  parser,
190
190
  expr
191
191
  );
192
- const binding =
193
- requireBindingData &&
194
- requireBindingData.get(/** @type {CallExpression} */ (expr));
192
+ const binding = requireBindingData && requireBindingData.get(expr);
195
193
  if (binding && !referencedExports) {
196
194
  // `const NAME = require(LITERAL)` — let later member-access walks
197
195
  // on `NAME` populate the dependency's referenced exports.
@@ -136,10 +136,10 @@ CommonJsObjectExportDependency.Template = class CommonJsObjectExportDependencyTe
136
136
  if (!used) {
137
137
  // Object spread rewrite needs environment.spread.
138
138
  if (!runtimeTemplate.supportsSpread()) return;
139
- const range = /** @type {Range} */ (dep.range);
139
+ const range = dep.range;
140
140
  if (FUNCTION_PROPERTY_DROP_HEAD.has(dep.kind)) {
141
141
  // Keep the function body so nested dependency replaces stay valid.
142
- const valueRange = /** @type {Range} */ (dep.valueRange);
142
+ const valueRange = dep.valueRange;
143
143
  source.replace(
144
144
  range[0],
145
145
  valueRange[0] - 1,
@@ -153,7 +153,7 @@ CommonJsObjectExportDependency.Template = class CommonJsObjectExportDependencyTe
153
153
  return;
154
154
  }
155
155
  // keyValue: keep the value's side effects in place.
156
- const valueRange = /** @type {Range} */ (dep.valueRange);
156
+ const valueRange = dep.valueRange;
157
157
  if (dep.pure) {
158
158
  // spreading null adds nothing; the text stays so nested replaces hold
159
159
  source.replace(
@@ -170,7 +170,7 @@ CommonJsObjectExportDependency.Template = class CommonJsObjectExportDependencyTe
170
170
  }
171
171
  if (used === dep.name) return;
172
172
  // Rename the key to the mangled export name.
173
- const keyRange = /** @type {Range} */ (dep.keyRange);
173
+ const keyRange = dep.keyRange;
174
174
  if (dep.kind === "shorthand") {
175
175
  source.replace(
176
176
  keyRange[0],
@@ -42,7 +42,6 @@ const TopLevelThisParserPlugin = require("./TopLevelThisParserPlugin");
42
42
  */
43
43
  /** @import Compilation from "../../Compilation" */
44
44
  /** @import Compiler from "../../Compiler" */
45
- /** @import { BuildInfo } from "../../module/Module" */
46
45
  /** @import Parser from "../../javascript/JavascriptParser" */
47
46
 
48
47
  const PLUGIN_NAME = "CommonJsPlugin";
@@ -232,8 +231,7 @@ class CommonJsPlugin {
232
231
  parser.hooks.expression
233
232
  .for(RuntimeGlobals.moduleLoaded)
234
233
  .tap(PLUGIN_NAME, (expr) => {
235
- /** @type {BuildInfo} */
236
- (parser.state.module.buildInfo).moduleConcatenationBailout =
234
+ parser.state.module.buildInfo.moduleConcatenationBailout =
237
235
  RuntimeGlobals.moduleLoaded;
238
236
  const dep = new RuntimeRequirementsDependency([
239
237
  RuntimeGlobals.moduleLoaded
@@ -246,8 +244,7 @@ class CommonJsPlugin {
246
244
  parser.hooks.expression
247
245
  .for(RuntimeGlobals.moduleId)
248
246
  .tap(PLUGIN_NAME, (expr) => {
249
- /** @type {BuildInfo} */
250
- (parser.state.module.buildInfo).moduleConcatenationBailout =
247
+ parser.state.module.buildInfo.moduleConcatenationBailout =
251
248
  RuntimeGlobals.moduleId;
252
249
  const dep = new RuntimeRequirementsDependency([
253
250
  RuntimeGlobals.moduleId
@@ -12,6 +12,7 @@ const RequireEnsureItemDependency = require("./RequireEnsureItemDependency");
12
12
 
13
13
  /** @import { Expression, SpreadElement } from "estree" */
14
14
  /** @import { GroupOptions } from "../../graph/AsyncDependenciesBlock" */
15
+ /** @import DependenciesBlock from "../../graph/DependenciesBlock" */
15
16
  /** @import BasicEvaluatedExpression from "../../javascript/BasicEvaluatedExpression" */
16
17
  /** @import JavascriptParser, { Range } from "../../javascript/JavascriptParser" */
17
18
  /** @import { FunctionExpressionResult } from "../helpers/getFunctionExpression" */
@@ -87,7 +88,9 @@ module.exports = class RequireEnsureDependenciesBlockParserPlugin {
87
88
  dep.loc = parser.getLocation(expr);
88
89
  depBlock.addDependency(dep);
89
90
  const old = parser.state.current;
90
- parser.state.current = /** @type {EXPECTED_ANY} */ (depBlock);
91
+ parser.state.current = /** @type {typeof parser.state.current} */ (
92
+ /** @type {DependenciesBlock} */ (depBlock)
93
+ );
91
94
  try {
92
95
  let failed = false;
93
96
  parser.inFunctionScope(true, [], () => {
@@ -105,8 +105,7 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
105
105
  /** @type {RawReferencedExports | undefined} */
106
106
  let exports;
107
107
  if (optionsNode) {
108
- for (const prop of /** @type {ObjectExpression} */ (optionsNode)
109
- .properties) {
108
+ for (const prop of optionsNode.properties) {
110
109
  if (prop.type !== "Property" || prop.key.type !== "Identifier") {
111
110
  errors.push(
112
111
  createError(
@@ -11,7 +11,6 @@ const {
11
11
  const ImportMetaGlobDependency = require("./ImportMetaGlobDependency");
12
12
  const { parseImportMetaGlobCall } = require("./ImportMetaGlobHelpers");
13
13
 
14
- /** @import { CallExpression } from "estree" */
15
14
  /** @import JavascriptParser from "../../javascript/JavascriptParser" */
16
15
 
17
16
  const PLUGIN_NAME = "ImportMetaGlobDependencyParserPlugin";
@@ -38,7 +37,7 @@ module.exports = class ImportMetaGlobDependencyParserPlugin {
38
37
  options: globOptions,
39
38
  errors,
40
39
  warnings
41
- } = parseImportMetaGlobCall(/** @type {CallExpression} */ (expr), parser);
40
+ } = parseImportMetaGlobCall(expr, parser);
42
41
  for (const warning of warnings) {
43
42
  parser.state.module.addWarning(warning);
44
43
  }
@@ -58,11 +57,9 @@ module.exports = class ImportMetaGlobDependencyParserPlugin {
58
57
  exhaustive: globOptions.exhaustive,
59
58
  caseSensitive: globOptions.caseSensitive,
60
59
  referencedExports: globOptions.referencedExports,
61
- namespaceObject:
62
- /** @type {import("../../module/Module").BuildMeta} */
63
- (parser.state.module.buildMeta).strictHarmonyModule
64
- ? "strict"
65
- : true,
60
+ namespaceObject: parser.state.module.buildMeta.strictHarmonyModule
61
+ ? "strict"
62
+ : true,
66
63
  mode: globOptions.mode,
67
64
  category: "esm"
68
65
  },
@@ -87,9 +87,7 @@ const staticStringFromExpr = (expr, parser) => {
87
87
  return /** @type {string} */ (evaluated.string);
88
88
  }
89
89
  if (expr.type === "TemplateLiteral" && expr.expressions.length === 0) {
90
- const cooked = /** @type {import("estree").TemplateElement} */ (
91
- expr.quasis[0]
92
- ).value.cooked;
90
+ const cooked = expr.quasis[0].value.cooked;
93
91
  if (cooked !== null && cooked !== undefined) return cooked;
94
92
  }
95
93
  };
@@ -189,7 +187,10 @@ const staticImportMetaGlobQueryKeyFromPropName = (propName, parser) => {
189
187
  if (typeof propName.value === "number") return String(propName.value);
190
188
  if (typeof propName.value === "boolean") return String(propName.value);
191
189
  }
192
- const keyNode = /** @type {unknown} */ (propName);
190
+ const keyNode =
191
+ /** @type {typeof propName | { type: "Computed", expression: Expression }} */ (
192
+ propName
193
+ );
193
194
  if (
194
195
  typeof keyNode === "object" &&
195
196
  keyNode !== null &&
@@ -197,10 +198,7 @@ const staticImportMetaGlobQueryKeyFromPropName = (propName, parser) => {
197
198
  keyNode.type === "Computed" &&
198
199
  "expression" in keyNode
199
200
  ) {
200
- return staticImportMetaGlobQueryKeyFromExpr(
201
- /** @type {Expression} */ (keyNode.expression),
202
- parser
203
- );
201
+ return staticImportMetaGlobQueryKeyFromExpr(keyNode.expression, parser);
204
202
  }
205
203
  };
206
204
 
@@ -551,7 +549,7 @@ const parseImportMetaGlobCall = (expr, parser) => {
551
549
  }
552
550
 
553
551
  const rawGlobPatterns = parseStaticGlobPatternsFromExpr(
554
- /** @type {Expression} */ (directoryNode),
552
+ directoryNode,
555
553
  parser,
556
554
  warnings
557
555
  );
@@ -605,7 +603,7 @@ const parseImportMetaGlobCall = (expr, parser) => {
605
603
  const compilerContext = parser.state.compilation.compiler.context;
606
604
  const globOptions =
607
605
  optionsNode && optionsNode.type === "ObjectExpression"
608
- ? /** @type {ObjectExpression} */ (optionsNode)
606
+ ? optionsNode
609
607
  : undefined;
610
608
  const { eager, importName, query, base, exhaustive, caseSensitive } =
611
609
  parseImportMetaGlobOptionsObject(globOptions, parser, warnings);
@@ -127,12 +127,15 @@ CachedConstDependency.Template = class CachedConstDependencyTemplate extends (
127
127
  ? initFragments
128
128
  : chunkInitFragments
129
129
  ).push(
130
- new InitFragment(
131
- `var ${dep.identifier} = ${dep.expression};\n`,
132
- InitFragment.STAGE_CONSTANTS,
133
- // For a chunk we inject expression after imports
134
- dep.place === CachedConstDependency.PLACE_MODULE ? 0 : 10,
135
- `const ${dep.identifier}`
130
+ // Its content is fixed, so it fits either list's render context.
131
+ /** @type {DependencyTemplateContext["initFragments"][number] & DependencyTemplateContext["chunkInitFragments"][number]} */ (
132
+ new InitFragment(
133
+ `var ${dep.identifier} = ${dep.expression};\n`,
134
+ InitFragment.STAGE_CONSTANTS,
135
+ // For a chunk we inject expression after imports
136
+ dep.place === CachedConstDependency.PLACE_MODULE ? 0 : 10,
137
+ `const ${dep.identifier}`
138
+ )
136
139
  )
137
140
  );
138
141
 
@@ -141,8 +141,7 @@ const getLocalIdent = (local, module, chunkGraph, runtimeTemplate) => {
141
141
  /** @type {CssGeneratorLocalIdentName} */
142
142
  (generator.options.localIdentName);
143
143
  const relativeResourcePath = makePathsRelative(
144
- /** @type {string} */
145
- (runtimeTemplate.compilation.compiler.context),
144
+ runtimeTemplate.compilation.compiler.context,
146
145
  /** @type {string} */
147
146
  (module.getResource()),
148
147
  runtimeTemplate.compilation.compiler.root
@@ -197,8 +196,8 @@ const getLocalIdent = (local, module, chunkGraph, runtimeTemplate) => {
197
196
 
198
197
  contentHash = digestNonNumericOnly(
199
198
  hash,
200
- /** @type {string} */ (runtimeTemplate.outputOptions.hashDigest),
201
- /** @type {number} */ (runtimeTemplate.outputOptions.hashDigestLength)
199
+ runtimeTemplate.outputOptions.hashDigest,
200
+ runtimeTemplate.outputOptions.hashDigestLength
202
201
  );
203
202
  }
204
203
 
@@ -651,7 +650,7 @@ const EMPTY_INDEX = new Map();
651
650
  * type (CSS and JS), so this survives both passes — the index is built once per
652
651
  * build instead of once per `apply`. Weakly held, so it never keeps a module
653
652
  * alive.
654
- * @type {WeakMap<CssModule, { buildInfo: unknown, index: Map<string, CssIcssImportDependency[]> }>}
653
+ * @type {WeakMap<CssModule, { buildInfo: CssModule["buildInfo"], index: Map<string, CssIcssImportDependency[]> }>}
655
654
  */
656
655
  const moduleImportIndexes = new WeakMap();
657
656
 
@@ -1022,7 +1021,7 @@ CssIcssExportDependency.Template = class CssIcssExportDependencyTemplate extends
1022
1021
  } else {
1023
1022
  references.push(
1024
1023
  CssIcssExportDependencyTemplate.getIdentifier(
1025
- /** @type {string} */ (entry.value),
1024
+ entry.value,
1026
1025
  entry,
1027
1026
  templateContext
1028
1027
  )
@@ -1031,7 +1030,7 @@ CssIcssExportDependency.Template = class CssIcssExportDependencyTemplate extends
1031
1030
  const matches = getExportIndex(
1032
1031
  cache,
1033
1032
  /** @type {CssModule} */ (templateContext.module)
1034
- ).get(/** @type {string} */ (entry.value));
1033
+ ).get(entry.value);
1035
1034
  if (matches) {
1036
1035
  for (const d of matches) {
1037
1036
  if (d.exportMode === EXPORT_MODE.NONE) continue;
@@ -107,9 +107,7 @@ class CssIcssImportDependency extends CssImportDependency {
107
107
  /** @type {CssGenerator | undefined} */
108
108
  (module.generator);
109
109
  const convention =
110
- generator &&
111
- /** @type {CssGeneratorExportsConvention | undefined} */
112
- (generator.options && generator.options.exportsConvention);
110
+ generator && generator.options && generator.options.exportsConvention;
113
111
  const exportsInfo = moduleGraph.getExportsInfo(module);
114
112
  const names = convention
115
113
  ? this.getImportNameConventionNames(convention)
@@ -94,7 +94,7 @@ class CssUrlDependency extends ModuleDependency {
94
94
  module.buildInfo
95
95
  );
96
96
  if (buildInfo && buildInfo.hash) {
97
- hash.update(/** @type {string} */ (buildInfo.hash));
97
+ hash.update(buildInfo.hash);
98
98
  }
99
99
  }
100
100
 
@@ -231,11 +231,7 @@ CssUrlDependency.Template = class CssUrlDependencyTemplate extends (
231
231
  break;
232
232
  }
233
233
 
234
- source.replace(
235
- dep.range[0],
236
- dep.range[1] - 1,
237
- /** @type {string} */ (newValue)
238
- );
234
+ source.replace(dep.range[0], dep.range[1] - 1, newValue);
239
235
  }
240
236
 
241
237
  /**
@@ -23,7 +23,6 @@ const getEnvironmentNotSupportAsyncWarning = memoize(() =>
23
23
  require("../../errors/EnvironmentNotSupportAsyncWarning")
24
24
  );
25
25
 
26
- /** @import { BuildInfo, BuildMeta } from "../../module/Module" */
27
26
  /** @import JavascriptParser, { Range } from "../../javascript/JavascriptParser" */
28
27
 
29
28
  const PLUGIN_NAME = "ESMDetectionParserPlugin";
@@ -82,9 +81,8 @@ module.exports = class ESMDetectionParserPlugin {
82
81
  parser.hooks.topLevelAwait.tap(PLUGIN_NAME, (node) => {
83
82
  const module = parser.state.module;
84
83
  enableHarmony(false);
85
- /** @type {BuildMeta} */
86
- (module.buildMeta).async = true;
87
- const buildInfo = /** @type {BuildInfo} */ (module.buildInfo);
84
+ module.buildMeta.async = true;
85
+ const buildInfo = module.buildInfo;
88
86
  if (node.type === "AwaitExpression") {
89
87
  // Record for a possible `await` -> `(yield …)` rewrite when the module
90
88
  // is lowered to a generator (target without `async`/`await`).
@@ -30,8 +30,8 @@ const DEFAULT_EXPORT_NAME = "default";
30
30
  /** @import { InlinedValue } from "../../optimize/InlineExports" */
31
31
  /** @import { Range } from "../../javascript/JavascriptParser" */
32
32
  /** @typedef {string | { id?: string | undefined, range: Range, prefix: string, suffix: string }} DeclarationId */
33
- /** @typedef {import("../../serialization/ObjectMiddleware").ObjectDeserializerContext<[Range, Range, string, DeclarationId | undefined, boolean, boolean]>} ObjectDeserializerContext */
34
- /** @typedef {import("../../serialization/ObjectMiddleware").ObjectSerializerContext<[Range, Range, string, DeclarationId | undefined, boolean, boolean]>} ObjectSerializerContext */
33
+ /** @typedef {import("../../serialization/ObjectMiddleware").ObjectDeserializerContext<[Range, Range, string, DeclarationId | undefined, boolean, boolean, InlinedValue | undefined]>} ObjectDeserializerContext */
34
+ /** @typedef {import("../../serialization/ObjectMiddleware").ObjectSerializerContext<[Range, Range, string, DeclarationId | undefined, boolean, boolean, InlinedValue | undefined]>} ObjectSerializerContext */
35
35
  /** @import { ExportMap } from "./ESMExportInitFragment" */
36
36
  /**
37
37
  * @import {
@@ -14,6 +14,7 @@ const {
14
14
  isInlineExportsEnabled,
15
15
  isInlinedUsedName
16
16
  } = require("../../optimize/InlineExports");
17
+ const LazyBarrels = require("../../optimize/LazyBarrels");
17
18
  const {
18
19
  getKnownExportNames,
19
20
  getMakeDeferredNamespaceModeFromExportsType
@@ -899,9 +900,7 @@ class ESMExportImportedSpecifierDependency extends ESMImportDependency {
899
900
  runtime,
900
901
  referencedExports,
901
902
  [],
902
- /** @type {InstanceType<ExportInfo>} */ (
903
- mode.partialNamespaceExportInfo
904
- )
903
+ mode.partialNamespaceExportInfo
905
904
  );
906
905
  return referencedExports;
907
906
  }
@@ -917,9 +916,7 @@ class ESMExportImportedSpecifierDependency extends ESMImportDependency {
917
916
  runtime,
918
917
  referencedExports,
919
918
  [],
920
- /** @type {InstanceType<ExportInfo>} */ (
921
- mode.partialNamespaceExportInfo
922
- ),
919
+ mode.partialNamespaceExportInfo,
923
920
  mode.type === "reexport-fake-namespace-object"
924
921
  );
925
922
  return referencedExports;
@@ -1387,6 +1384,11 @@ ESMExportImportedSpecifierDependency.Template = class ESMExportImportedSpecifier
1387
1384
 
1388
1385
  const mode = dep.getMode(moduleGraph, runtime);
1389
1386
 
1387
+ // deferred by lazy barrel: never resolved, renders nothing
1388
+ if (mode.type === "missing" && LazyBarrels.isLazy(moduleGraph, dep)) {
1389
+ return;
1390
+ }
1391
+
1390
1392
  // a wrapped module has no shared-scope symbols to redirect reexports to
1391
1393
  if (concatenationScope && !concatenationScope.isWrapped()) {
1392
1394
  switch (mode.type) {
@@ -1457,15 +1459,13 @@ ESMExportImportedSpecifierDependency.Template = class ESMExportImportedSpecifier
1457
1459
  concatenationScope !== undefined &&
1458
1460
  concatenationScope.isModuleInScope(importedModule);
1459
1461
  const importVar = inScope
1460
- ? /** @type {ConcatenationScope} */ (
1461
- concatenationScope
1462
- ).createModuleReference(importedModule, { asiSafe: true })
1462
+ ? concatenationScope.createModuleReference(importedModule, {
1463
+ asiSafe: true
1464
+ })
1463
1465
  : dep.getImportVar(moduleGraph);
1464
1466
 
1465
1467
  const defaultImportVar = inScope
1466
- ? /** @type {ConcatenationScope} */ (
1467
- concatenationScope
1468
- ).createModuleReference(importedModule, {
1468
+ ? concatenationScope.createModuleReference(importedModule, {
1469
1469
  ids: ["default"],
1470
1470
  asiSafe: true
1471
1471
  })
@@ -1473,9 +1473,7 @@ ESMExportImportedSpecifierDependency.Template = class ESMExportImportedSpecifier
1473
1473
 
1474
1474
  // whole-namespace modes need the original export names, not mangled ones
1475
1475
  const namespaceImportVar = inScope
1476
- ? /** @type {ConcatenationScope} */ (
1477
- concatenationScope
1478
- ).createModuleReference(importedModule, {
1476
+ ? concatenationScope.createModuleReference(importedModule, {
1479
1477
  asiSafe: true,
1480
1478
  mangleableNamespace: true
1481
1479
  })
@@ -1560,9 +1558,9 @@ ESMExportImportedSpecifierDependency.Template = class ESMExportImportedSpecifier
1560
1558
  moduleGraph
1561
1559
  .getExportsInfo(module)
1562
1560
  .getUsedName(/** @type {string} */ (mode.name), runtime),
1563
- /** @type {ConcatenationScope} */ (
1564
- concatenationScope
1565
- ).createModuleReference(importedModule, { asiSafe: true }),
1561
+ concatenationScope.createModuleReference(importedModule, {
1562
+ asiSafe: true
1563
+ }),
1566
1564
  "",
1567
1565
  runtimeRequirements
1568
1566
  )
@@ -8,13 +8,14 @@
8
8
  const Dependency = require("../../graph/Dependency");
9
9
  const { isInlinedUsedName } = require("../../optimize/InlineExports");
10
10
  const makeSerializable = require("../../util/makeSerializable");
11
+ const { getRuntimeKey } = require("../../util/runtime");
11
12
  const NullDependency = require("../core/NullDependency");
12
13
  const ESMExportInitFragment = require("./ESMExportInitFragment");
13
14
 
14
15
  const { ExportBindingType } = ESMExportInitFragment;
15
16
 
16
17
  /** @import { ReplaceSource } from "webpack-sources" */
17
- /** @import { ExportsSpec, LazyRole, UpdateHashContext } from "../../graph/Dependency" */
18
+ /** @import { DependencyKinds, ExportsSpec, LazyRole, UpdateHashContext } from "../../graph/Dependency" */
18
19
  /** @import Module, { BuildInfo } from "../../module/Module" */
19
20
  /** @import Hash from "../../util/Hash" */
20
21
  /** @import { DependencyTemplateContext } from "../../template/DependencyTemplate" */
@@ -204,12 +205,22 @@ ESMExportSpecifierDependency.Template = class ESMExportSpecifierDependencyTempla
204
205
  meta !== undefined &&
205
206
  meta.onDemandExports === true;
206
207
 
208
+ // a module library may have moved the binding to the chunk's scope
209
+ const live =
210
+ meta !== undefined && meta.liveBindings !== undefined
211
+ ? meta.liveBindings.get(dep.id)
212
+ : undefined;
213
+ const local =
214
+ live !== undefined && live.runtimes.has(getRuntimeKey(runtime))
215
+ ? live.name
216
+ : dep.id;
217
+
207
218
  /** @type {ExportMap} */
208
219
  const map = new Map();
209
220
  map.set(used, {
210
- value: `/* binding */ ${dep.id}`,
221
+ value: `/* binding */ ${local}`,
211
222
  type: valueFormat ? ExportBindingType.Value : ExportBindingType.Getter,
212
- finalName: dep.id
223
+ finalName: local
213
224
  });
214
225
  initFragments.push(
215
226
  new ESMExportInitFragment(
@@ -222,4 +233,10 @@ ESMExportSpecifierDependency.Template = class ESMExportSpecifierDependencyTempla
222
233
  }
223
234
  };
224
235
 
236
+ /** @type {Set<keyof DependencyKinds>} */
237
+ ESMExportSpecifierDependency.KINDS = new Set([
238
+ ...NullDependency.KINDS,
239
+ "esm-export-specifier"
240
+ ]);
241
+
225
242
  module.exports = ESMExportSpecifierDependency;
@@ -7,12 +7,6 @@
7
7
 
8
8
  const RuntimeGlobals = require("../../runtime/RuntimeGlobals");
9
9
 
10
- /** @import { BuildInfo } from "../../module/Module" */
11
- /**
12
- * @import {
13
- * JavascriptModuleBuildMeta
14
- * } from "../../javascript/JavascriptModule"
15
- */
16
10
  /** @import { JavascriptParserState } from "../../javascript/JavascriptParser" */
17
11
 
18
12
  /** @type {WeakMap<JavascriptParserState, boolean>} */
@@ -29,11 +23,9 @@ module.exports.enable = (parserState, isStrictHarmony) => {
29
23
  if (value === false) return;
30
24
  parserStateExportsState.set(parserState, true);
31
25
  if (value !== true) {
32
- const buildMeta =
33
- /** @type {JavascriptModuleBuildMeta} */
34
- (parserState.module.buildMeta);
26
+ const buildMeta = parserState.module.buildMeta;
35
27
  buildMeta.exportsType = "namespace";
36
- const buildInfo = /** @type {BuildInfo} */ (parserState.module.buildInfo);
28
+ const buildInfo = parserState.module.buildInfo;
37
29
  buildInfo.strict = true;
38
30
  buildInfo.exportsArgument = RuntimeGlobals.exports;
39
31
  if (isStrictHarmony) {