webpack 5.112.0 → 5.112.2

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 +198 -61
  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 -47
  28. package/lib/css/CssModule.js +10 -0
  29. package/lib/css/CssModulesPlugin.js +13 -6
  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 +1312 -312
  34. package/lib/css/syntax-printer.js +1142 -1025
  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 +4 -8
  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 +146 -29
  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 +18 -19
  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
@@ -34,23 +34,7 @@ const { fileUrlToPath } = require("../util/identifier");
34
34
  * @property {AbsolutePath=} outputPath Path to the output file e.g. `path.resolve(__dirname, 'profiling/events.json')`. Defaults to `events.json`.
35
35
  */
36
36
 
37
- /**
38
- * Defines the hook type used by this module.
39
- * @template T, R
40
- * @typedef {import("tapable").Hook<T, R>} Hook
41
- */
42
-
43
- /**
44
- * Defines the fake hook type used by this module.
45
- * @template T
46
- * @typedef {import("../util/deprecation").FakeHook<T>} FakeHook
47
- */
48
-
49
- /**
50
- * Defines the hook map type used by this module.
51
- * @template T
52
- * @typedef {import("tapable").HookMap<T>} HookMap
53
- */
37
+ /** @import { FakeHookMarker } from "../util/deprecation" */
54
38
 
55
39
  /**
56
40
  * Defines the hook interceptor type used by this module.
@@ -96,8 +80,7 @@ class Profiler {
96
80
 
97
81
  try {
98
82
  this.session = new /** @type {Inspector} */ (inspector).Session();
99
- /** @type {Session} */
100
- (this.session).connect();
83
+ this.session.connect();
101
84
  } catch (_) {
102
85
  this.session = undefined;
103
86
  return Promise.resolve();
@@ -119,7 +102,7 @@ class Profiler {
119
102
  * Returns promise for the result.
120
103
  * @param {string} method method name
121
104
  * @param {import("inspector").Profiler.SetSamplingIntervalParameterType=} params params
122
- * @returns {Promise<EXPECTED_ANY | void>} Promise for the result
105
+ * @returns {Promise<Partial<import("inspector").Profiler.StopReturnType> | void>} Promise for the result, `{}` for commands without one
123
106
  */
124
107
  sendCommand(method, params) {
125
108
  if (this.hasSession()) {
@@ -151,7 +134,9 @@ class Profiler {
151
134
  * @returns {Promise<{ profile: { startTime: number, endTime: number } }>} profile result
152
135
  */
153
136
  stopProfiling() {
154
- return this.sendCommand("Profiler.stop").then(({ profile }) => {
137
+ return /** @type {Promise<import("inspector").Profiler.StopReturnType>} */ (
138
+ this.sendCommand("Profiler.stop")
139
+ ).then(({ profile }) => {
155
140
  const hrtime = process.hrtime();
156
141
  const endTime = hrtime[0] * 1000000 + Math.round(hrtime[1] / 1000);
157
142
  // Avoid coverage problems due indirect changes
@@ -406,18 +391,34 @@ class ProfilingPlugin {
406
391
  }
407
392
  }
408
393
 
409
- /** @typedef {Record<string, Hook<EXPECTED_ANY, EXPECTED_ANY> | FakeHook<EXPECTED_ANY> | HookMap<EXPECTED_ANY>>} Hooks */
394
+ /**
395
+ * The part of a tapable `HookInterceptor` this plugin sets: it rewraps each tap.
396
+ * @typedef {{ register?(tap: FullTap): FullTap }} TapInterceptor
397
+ */
398
+
399
+ /**
400
+ * What intercepting a tapable `Hook` needs of it. Methods, so every hook fits
401
+ * whatever its arguments, result and additional tap options.
402
+ * @typedef {{ intercept(interceptor: TapInterceptor): void, _fakeHook?: undefined }} HookWithInterceptor
403
+ */
404
+
405
+ /**
406
+ * What intercepting a tapable `HookMap` needs of it, whatever hook it holds.
407
+ * @typedef {{ for(key: string): HookWithInterceptor, intercept(interceptor: { factory?(key: string, hook: HookWithInterceptor): HookWithInterceptor }): void, _fakeHook?: undefined }} HookMapWithInterceptor
408
+ */
409
+
410
+ /** @typedef {Record<string, HookWithInterceptor | HookMapWithInterceptor | FakeHookMarker>} Hooks */
410
411
 
411
412
  /**
412
413
  * Intercepts the taps of a hook or every cached and future hook in a hook map.
413
- * @param {Hooks[string]} hook the hook or hook map
414
- * @param {HookInterceptor<EXPECTED_ANY, EXPECTED_ANY>} interceptor what intercepts each tap
414
+ * @param {HookWithInterceptor | HookMapWithInterceptor} hook the hook or hook map
415
+ * @param {TapInterceptor} interceptor what intercepts each tap
415
416
  * @returns {void}
416
417
  */
417
418
  const interceptTaps = (hook, interceptor) => {
418
419
  if ("for" in hook) {
419
420
  const { _map } =
420
- /** @type {HookMap<Hook<EXPECTED_ANY, EXPECTED_ANY>> & { _map: Map<unknown, Hook<EXPECTED_ANY, EXPECTED_ANY>> }} */
421
+ /** @type {HookMapWithInterceptor & { _map: Map<string, HookWithInterceptor> }} */
421
422
  (hook);
422
423
  for (const cached of _map.values()) {
423
424
  cached.intercept(interceptor);
@@ -425,8 +426,8 @@ const interceptTaps = (hook, interceptor) => {
425
426
  hook.intercept({
426
427
  /**
427
428
  * @param {string} key the key the hook is created for
428
- * @param {Hook<EXPECTED_ANY, EXPECTED_ANY>} created the hook created
429
- * @returns {Hook<EXPECTED_ANY, EXPECTED_ANY>} the same hook, intercepted
429
+ * @param {HookWithInterceptor} created the hook created
430
+ * @returns {HookWithInterceptor} the same hook, intercepted
430
431
  */
431
432
  factory: (key, created) => {
432
433
  created.intercept(interceptor);
@@ -533,7 +534,25 @@ const interceptAllCssModulesPluginHooks = (compilation, tracer) => {
533
534
  );
534
535
  };
535
536
 
536
- /** @typedef {(...args: EXPECTED_ANY[]) => EXPECTED_ANY | Promise<(...args: EXPECTED_ANY[]) => EXPECTED_ANY>} PluginFunction */
537
+ /**
538
+ * A `sync` tap's function, or a `promise` tap's when `R` is a promise.
539
+ * @template {unknown[]} A the hook's arguments
540
+ * @template R what the tap returns
541
+ * @typedef {(...args: A) => R} PluginFunction
542
+ */
543
+
544
+ /**
545
+ * The callback an `async` tap reports its error or result through.
546
+ * @template R the hook's result
547
+ * @typedef {(error?: Error | null, result?: R) => void} TapCallback
548
+ */
549
+
550
+ /**
551
+ * An `async` tap's function, the hook's callback after its arguments.
552
+ * @template {unknown[]} A the hook's arguments
553
+ * @template R the hook's result
554
+ * @typedef {(...args: [...A, TapCallback<R>]) => void} AsyncPluginFunction
555
+ */
537
556
 
538
557
  /**
539
558
  * Creates interceptor for.
@@ -556,7 +575,7 @@ const makeInterceptorFor = (instance, tracer) => (hookName) => ({
556
575
  : makeNewProfiledTapFn(hookName, tracer, {
557
576
  name,
558
577
  type,
559
- fn: /** @type {PluginFunction} */ (internalFn)
578
+ fn: internalFn
560
579
  });
561
580
  return { ...tapInfo, fn: newFn };
562
581
  }
@@ -564,20 +583,22 @@ const makeInterceptorFor = (instance, tracer) => (hookName) => ({
564
583
 
565
584
  /**
566
585
  * Creates new profiled tap fn.
586
+ * @template {unknown[]} A the hook's arguments
587
+ * @template R the hook's result
567
588
  * @param {string} hookName Name of the hook to profile.
568
589
  * @param {Trace} tracer The trace object.
569
590
  * @param {object} options Options for the profiled fn.
570
591
  * @param {string} options.name Plugin name
571
592
  * @param {"sync" | "async" | "promise"} options.type Plugin type (sync | async | promise)
572
- * @param {PluginFunction} options.fn Plugin function
573
- * @returns {PluginFunction} Chainable hooked function.
593
+ * @param {FullTap["fn"]} options.fn Plugin function, its shape set by `options.type`
594
+ * @returns {FullTap["fn"]} Chainable hooked function.
574
595
  */
575
596
  const makeNewProfiledTapFn = (hookName, tracer, { name, type, fn }) => {
576
597
  const defaultCategory = ["blink.user_timing"];
577
598
 
578
599
  switch (type) {
579
600
  case "promise":
580
- return (...args) => {
601
+ return /** @type {PluginFunction<A, Promise<R>>} */ (...args) => {
581
602
  const id = ++tracer.counter;
582
603
  tracer.trace.begin({
583
604
  name,
@@ -585,8 +606,8 @@ const makeNewProfiledTapFn = (hookName, tracer, { name, type, fn }) => {
585
606
  cat: defaultCategory
586
607
  });
587
608
  const promise =
588
- /** @type {Promise<(...args: EXPECTED_ANY[]) => EXPECTED_ANY>} */
589
- (fn(...args));
609
+ /** @type {PluginFunction<A, Promise<R>>} */
610
+ (fn)(...args);
590
611
  return promise.then((r) => {
591
612
  tracer.trace.end({
592
613
  name,
@@ -597,19 +618,20 @@ const makeNewProfiledTapFn = (hookName, tracer, { name, type, fn }) => {
597
618
  });
598
619
  };
599
620
  case "async":
600
- return (...args) => {
621
+ return /** @type {AsyncPluginFunction<A, R>} */ (...args) => {
601
622
  const id = ++tracer.counter;
602
623
  tracer.trace.begin({
603
624
  name,
604
625
  id,
605
626
  cat: defaultCategory
606
627
  });
607
- const callback = args.pop();
608
- fn(
609
- ...args,
628
+ const callback = /** @type {TapCallback<R>} */ (args.pop());
629
+ /** @type {AsyncPluginFunction<A, R>} */ (fn)(
630
+ // `pop()` took the callback off, which the tuple type cannot follow.
631
+ .../** @type {A} */ (/** @type {unknown[]} */ (args)),
610
632
  /**
611
633
  * Handles the cat callback for this hook.
612
- * @param {...EXPECTED_ANY[]} r result
634
+ * @param {Parameters<TapCallback<R>>} r result
613
635
  */
614
636
  (...r) => {
615
637
  tracer.trace.end({
@@ -622,12 +644,12 @@ const makeNewProfiledTapFn = (hookName, tracer, { name, type, fn }) => {
622
644
  );
623
645
  };
624
646
  case "sync":
625
- return (...args) => {
647
+ return /** @type {PluginFunction<A, R>} */ (...args) => {
626
648
  const id = ++tracer.counter;
627
649
  // Do not instrument ourself due to the CPU
628
650
  // profile needing to be the last event in the trace.
629
651
  if (name === PLUGIN_NAME) {
630
- return fn(...args);
652
+ return /** @type {PluginFunction<A, R>} */ (fn)(...args);
631
653
  }
632
654
 
633
655
  tracer.trace.begin({
@@ -635,10 +657,10 @@ const makeNewProfiledTapFn = (hookName, tracer, { name, type, fn }) => {
635
657
  id,
636
658
  cat: defaultCategory
637
659
  });
638
- /** @type {PluginFunction} */
660
+ /** @type {R} */
639
661
  let r;
640
662
  try {
641
- r = fn(...args);
663
+ r = /** @type {PluginFunction<A, R>} */ (fn)(...args);
642
664
  } catch (err) {
643
665
  tracer.trace.end({
644
666
  name,
@@ -255,7 +255,7 @@ const dropTrailingMembers = (node, count) => {
255
255
 
256
256
  /**
257
257
  * Returns code converted to string that evaluates.
258
- * @param {EXPECTED_ANY[] | { [k: string]: EXPECTED_ANY }} obj obj
258
+ * @param {CodeValue[] | Record<string, CodeValue>} obj obj
259
259
  * @param {JavascriptParser} parser Parser
260
260
  * @param {ValueCacheVersions} valueCacheVersions valueCacheVersions
261
261
  * @param {string} key the defined key
@@ -376,7 +376,7 @@ const toCode = (
376
376
  }
377
377
  if (typeof code === "object") {
378
378
  return stringifyObj(
379
- code,
379
+ /** @type {CodeValue[] | Record<string, CodeValue>} */ (code),
380
380
  parser,
381
381
  valueCacheVersions,
382
382
  key,
@@ -675,7 +675,7 @@ const stringifyMergedNode = (merged, node, parser, key, objKeys) => {
675
675
  }
676
676
  const code = `{${keys
677
677
  .map((k) => {
678
- const value = /** @type {MergedDefinitionNode} */ (node.get(k));
678
+ const value = node.get(k);
679
679
  return `${toPropertyKey(k)}:${
680
680
  value instanceof Map
681
681
  ? stringifyMergedNode(merged, value, parser, k)
@@ -1115,7 +1115,9 @@ class DefinePlugin {
1115
1115
  // so scanning that text cannot find every reference.
1116
1116
  const hasPreparsedAst =
1117
1117
  /** @type {{ _ast: PreparsedAst | null }} */ (
1118
- /** @type {unknown} */ (module)
1118
+ /** @type {NormalModule | { _ast: PreparsedAst | null }} */ (
1119
+ module
1120
+ )
1119
1121
  )._ast !== null;
1120
1122
  await resolveAsyncRuntimeValues(
1121
1123
  compilation,
@@ -1139,9 +1141,7 @@ class DefinePlugin {
1139
1141
  /** @type {ValueCacheVersion} */
1140
1142
  (compilation.valueCacheVersions.get(VALUE_DEP_MAIN));
1141
1143
  parser.hooks.program.tap(PLUGIN_NAME, () => {
1142
- const buildInfo = /** @type {NormalModuleBuildInfo} */ (
1143
- parser.state.module.buildInfo
1144
- );
1144
+ const buildInfo = parser.state.module.buildInfo;
1145
1145
  if (!buildInfo.valueDependencies) {
1146
1146
  buildInfo.valueDependencies = new Map();
1147
1147
  }
@@ -1153,9 +1153,7 @@ class DefinePlugin {
1153
1153
  * @param {string} key key
1154
1154
  */
1155
1155
  const addValueDependency = (key) => {
1156
- const buildInfo =
1157
- /** @type {NormalModuleBuildInfo} */
1158
- (parser.state.module.buildInfo);
1156
+ const buildInfo = parser.state.module.buildInfo;
1159
1157
  /** @type {NonNullable<NormalModuleBuildInfo["valueDependencies"]>} */
1160
1158
  (buildInfo.valueDependencies).set(
1161
1159
  VALUE_DEP_PREFIX + key,
@@ -1229,7 +1227,7 @@ class DefinePlugin {
1229
1227
  // several DefinePlugins can still be destructured together
1230
1228
  const nestedSet = mergedDefinitions.nestedByFinalKey.get(final);
1231
1229
  if (!nestedSet || nestedSet.size <= 0) return;
1232
- for (const nested of /** @type {Set<string>} */ (nestedSet)) {
1230
+ for (const nested of nestedSet) {
1233
1231
  if (nested && !hooked.has(nested)) {
1234
1232
  // only detect the same nested key once
1235
1233
  hooked.add(nested);
@@ -1475,10 +1473,7 @@ class DefinePlugin {
1475
1473
  parser.hooks.expression.for(key).tap(PLUGIN_NAME, (expr) => {
1476
1474
  const valueDependencies =
1477
1475
  /** @type {NonNullable<NormalModuleBuildInfo["valueDependencies"]>} */
1478
- (
1479
- /** @type {NormalModuleBuildInfo} */
1480
- (parser.state.module.buildInfo).valueDependencies
1481
- );
1476
+ (parser.state.module.buildInfo.valueDependencies);
1482
1477
  for (const [name, version] of objectValueDependencies) {
1483
1478
  valueDependencies.set(name, version);
1484
1479
  }
@@ -281,7 +281,11 @@ class DotenvPlugin {
281
281
  {
282
282
  name: "Dotenv Plugin",
283
283
  baseDataPath: "options"
284
- }
284
+ },
285
+ (options) =>
286
+ require("../../schemas/plugins/define/DotenvPluginOptions.check")(
287
+ options
288
+ )
285
289
  );
286
290
  });
287
291
  const definePlugin = new compiler.webpack.DefinePlugin({});
@@ -491,6 +495,8 @@ class DotenvPlugin {
491
495
  * @returns {Env} env variables
492
496
  */
493
497
  _getEnv(prefixes, parsed) {
498
+ // Expansion mutates its input, but the cache must retain the raw file values.
499
+ parsed = Object.assign(/** @type {Env} */ (Object.create(null)), parsed);
494
500
  // Always expand environment variables (like Vite does)
495
501
  // Make a copy of process.env so that dotenv-expand doesn't modify global process.env
496
502
  const processEnv = { ...process.env };
@@ -503,11 +509,9 @@ class DotenvPlugin {
503
509
  // Prioritize actual env variables from `process.env`, fallback to parsed
504
510
  for (const key of keys) {
505
511
  if (prefixes.some((prefix) => key.startsWith(prefix))) {
506
- env[key] =
507
- Object.prototype.hasOwnProperty.call(process.env, key) &&
508
- process.env[key]
509
- ? process.env[key]
510
- : parsed[key];
512
+ env[key] = Object.prototype.hasOwnProperty.call(process.env, key)
513
+ ? /** @type {string} */ (process.env[key])
514
+ : parsed[key];
511
515
  }
512
516
  }
513
517
 
@@ -10,23 +10,25 @@ const DefinePlugin = require("./DefinePlugin");
10
10
 
11
11
  /** @import Compiler from "../Compiler" */
12
12
  /** @import { CodeValue } from "./DefinePlugin" */
13
+ /** @import { JsonObject } from "../fs/fs" */
13
14
 
14
15
  const PLUGIN_NAME = "EnvironmentPlugin";
15
16
 
16
17
  class EnvironmentPlugin {
17
18
  /**
18
19
  * Creates an instance of EnvironmentPlugin.
19
- * @param {(string | string[] | Record<string, EXPECTED_ANY>)[]} keys keys
20
+ * @param {(string | string[] | JsonObject)[]} keys keys
20
21
  */
21
22
  constructor(...keys) {
22
23
  if (keys.length === 1 && Array.isArray(keys[0])) {
23
24
  /** @type {string[]} */
24
25
  this.keys = keys[0];
26
+ /** @type {JsonObject} */
25
27
  this.defaultValues = {};
26
28
  } else if (keys.length === 1 && keys[0] && typeof keys[0] === "object") {
27
29
  this.keys = Object.keys(keys[0]);
28
30
  this.defaultValues =
29
- /** @type {Record<string, EXPECTED_ANY>} */
31
+ /** @type {JsonObject} */
30
32
  (keys[0]);
31
33
  } else {
32
34
  this.keys = /** @type {string[]} */ (keys);
@@ -36,7 +36,6 @@ const { addLocalModule, getLocalModule } = require("./LocalModulesHelpers");
36
36
  * } from "../../../declarations/WebpackOptions"
37
37
  */
38
38
  /** @import Dependency from "../../graph/Dependency" */
39
- /** @import { BuildInfo } from "../../module/Module" */
40
39
  /** @import BasicEvaluatedExpression from "../../javascript/BasicEvaluatedExpression" */
41
40
  /**
42
41
  * @import JavascriptParser, {
@@ -356,7 +355,7 @@ class AMDDefineDependencyParserPlugin {
356
355
  }
357
356
  DynamicExports.bailout(parser.state);
358
357
  recordOptimizationBailout(
359
- /** @type {BuildInfo} */ (parser.state.module.buildInfo),
358
+ parser.state.module.buildInfo,
360
359
  "AMD bailout: define() prevents static exports analysis"
361
360
  );
362
361
  /** @type {Identifier[] | null} */
@@ -39,6 +39,7 @@ const getUnsupportedFeatureWarning = memoize(() =>
39
39
  * } from "../../../declarations/WebpackOptions"
40
40
  */
41
41
  /** @import Dependency, { DependencyLocation } from "../../graph/Dependency" */
42
+ /** @import DependenciesBlock from "../../graph/DependenciesBlock" */
42
43
  /** @import BasicEvaluatedExpression from "../../javascript/BasicEvaluatedExpression" */
43
44
  /** @import JavascriptParser, { Range } from "../../javascript/JavascriptParser" */
44
45
  /** @import LocalModule from "./LocalModule" */
@@ -323,7 +324,9 @@ class AMDRequireDependenciesBlockParserPlugin {
323
324
  dep.loc = parser.getLocation(expr);
324
325
  depBlock.addDependency(dep);
325
326
 
326
- parser.state.current = /** @type {EXPECTED_ANY} */ (depBlock);
327
+ parser.state.current = /** @type {typeof parser.state.current} */ (
328
+ /** @type {DependenciesBlock} */ (depBlock)
329
+ );
327
330
  }
328
331
 
329
332
  if (expr.arguments.length === 1) {
@@ -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, [], () => {