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
@@ -389,7 +389,7 @@ class ScopeAnalyzer {
389
389
  */
390
390
  constructor(recordEveryReference) {
391
391
  /** @type {Scope} the scope the walker is currently inside */
392
- this.scope = /** @type {Scope} */ (/** @type {unknown} */ (null));
392
+ this.scope = /** @type {Scope} */ (/** @type {Scope | null} */ (null));
393
393
  /** @type {Identifier[]} identifiers awaiting resolution */
394
394
  this.pendingIdentifiers = [];
395
395
  /** @type {Scope[]} the scope each pending identifier was seen in */
@@ -455,9 +455,9 @@ class ScopeAnalyzer {
455
455
  addBinding(scope, variable);
456
456
  }
457
457
  if (variable.identifiers === NO_IDENTIFIERS) {
458
- variable.identifiers = [/** @type {Identifier} */ (node)];
458
+ variable.identifiers = [node];
459
459
  } else {
460
- variable.identifiers.push(/** @type {Identifier} */ (node));
460
+ variable.identifiers.push(node);
461
461
  }
462
462
  }
463
463
 
@@ -722,8 +722,8 @@ class ScopeAnalyzer {
722
722
  if (key === "key" && "computed" in node && node.computed === false) {
723
723
  continue;
724
724
  }
725
- const child = /** @type {Record<string, unknown>} */ (
726
- /** @type {unknown} */ (node)
725
+ const child = /** @type {NodeChildren} */ (
726
+ /** @type {Node | NodeChildren} */ (node)
727
727
  )[key];
728
728
  if (child === null || typeof child !== "object") continue;
729
729
  if (Array.isArray(child)) {
@@ -732,8 +732,8 @@ class ScopeAnalyzer {
732
732
  this._visit(item);
733
733
  }
734
734
  }
735
- } else if (/** @type {Node} */ (child).type) {
736
- this._visit(/** @type {Node} */ (child));
735
+ } else if (child.type) {
736
+ this._visit(child);
737
737
  }
738
738
  }
739
739
  }
@@ -1019,7 +1019,7 @@ class ScopeAnalyzer {
1019
1019
  }
1020
1020
  for (let i = 0; i < keys.length; i++) {
1021
1021
  const child = /** @type {NodeChildren} */ (
1022
- /** @type {unknown} */ (node)
1022
+ /** @type {Node | NodeChildren} */ (node)
1023
1023
  )[keys[i]];
1024
1024
  if (child === null || child === undefined) continue;
1025
1025
  if (Array.isArray(child)) {
@@ -1139,7 +1139,7 @@ const analyzeScope = (ast, recordEveryReference = false) => {
1139
1139
  * @typedef {import("./syntax-printer").PrintVariableDeclaration} PrintVariableDeclaration
1140
1140
  * @typedef {import("./syntax-printer").PrintVariableDeclarator} PrintVariableDeclarator
1141
1141
  * @typedef {import("./syntax-printer").PrintExport} PrintExport
1142
- * @typedef {import("./syntax-printer").Token} Token
1142
+ * @typedef {import("./syntax-printer").NodeToken} Token
1143
1143
  * @typedef {NonNullable<PrintProgram["tokenTables"]>} TokenTables
1144
1144
  * @typedef {import("./syntax-printer").Node} CompressorNode
1145
1145
  * @typedef {import("./syntax-printer").Scope} CompressorScopeShape
@@ -1367,7 +1367,7 @@ class MinifierVariable extends Variable {
1367
1367
 
1368
1368
  /**
1369
1369
  * Whether a definition is a variable rather than a label or a compressor's own definition.
1370
- * @param {unknown} value a definition
1370
+ * @param {MinifierVariable | MinifierLabel | CompressorDefinition | import("./syntax-printer").NamedDefinition | null | undefined} value a definition
1371
1371
  * @returns {value is MinifierVariable} true when the value is a variable
1372
1372
  */
1373
1373
  const isMinifierVariable = (value) => value instanceof MinifierVariable;
@@ -1408,11 +1408,15 @@ class CompressorScope extends MinifierScope {
1408
1408
  // reads `childScopes`, and its tree moves, copies and drops scopes.
1409
1409
  super(
1410
1410
  type,
1411
- /** @type {PrintNode} */ (/** @type {unknown} */ (node)),
1411
+ /** @type {PrintNode} */ (
1412
+ /** @type {PrintNode | CompressorNode} */ (node)
1413
+ ),
1412
1414
  null,
1413
1415
  true
1414
1416
  );
1415
- this.upper = /** @type {Scope | null} */ (/** @type {unknown} */ (upper));
1417
+ this.upper = /** @type {Scope | null} */ (
1418
+ /** @type {Scope | CompressorScopeShape | null} */ (upper)
1419
+ );
1416
1420
  if (!isVarScope) {
1417
1421
  this.variableScope = /** @type {Scope} */ (this.upper).variableScope;
1418
1422
  }
@@ -1437,7 +1441,7 @@ class CompressorScope extends MinifierScope {
1437
1441
  this.type,
1438
1442
  node,
1439
1443
  /** @type {CompressorScopeShape | null} */ (
1440
- /** @type {unknown} */ (this.upper)
1444
+ /** @type {CompressorScopeShape | Scope | null} */ (this.upper)
1441
1445
  ),
1442
1446
  this.variableScope === this
1443
1447
  );
@@ -1448,7 +1452,7 @@ class CompressorScope extends MinifierScope {
1448
1452
  shared.usesWith = this.usesWith;
1449
1453
  shared.usesArguments = this.usesArguments;
1450
1454
  return /** @type {CompressorScopeShape} */ (
1451
- /** @type {unknown} */ (shared)
1455
+ /** @type {CompressorScopeShape | CompressorScope} */ (shared)
1452
1456
  );
1453
1457
  }
1454
1458
 
@@ -1484,7 +1488,9 @@ class CompressorScope extends MinifierScope {
1484
1488
  bind(variable) {
1485
1489
  addBinding(
1486
1490
  this,
1487
- /** @type {Variable} */ (/** @type {unknown} */ (variable))
1491
+ /** @type {Variable} */ (
1492
+ /** @type {Variable | CompressorDefinition} */ (variable)
1493
+ )
1488
1494
  );
1489
1495
  }
1490
1496
 
@@ -1496,23 +1502,26 @@ class CompressorScope extends MinifierScope {
1496
1502
  * @returns {CompressorDefinition} its definition, made or joined
1497
1503
  */
1498
1504
  defineVariable(symbol, init, isFunction) {
1499
- const name = /** @type {string} */ (symbol.name);
1505
+ const name = symbol.name;
1500
1506
  let variable = /** @type {CompressorDefinition | undefined} */ (
1501
- /** @type {unknown} */ (this.getBinding(name))
1507
+ /** @type {CompressorDefinition | Variable | undefined} */ (
1508
+ this.getBinding(name)
1509
+ )
1502
1510
  );
1503
1511
  if (variable !== undefined) {
1504
1512
  variable.identifiers.push(symbol);
1505
1513
  if (
1506
1514
  variable.init &&
1507
- (variable.scope !== /** @type {unknown} */ (symbol.scope) ||
1508
- isFunction(variable.init))
1515
+ (variable.scope !== symbol.scope || isFunction(variable.init))
1509
1516
  ) {
1510
1517
  variable.init = init;
1511
1518
  }
1512
1519
  } else {
1513
1520
  variable = createCompressorDefinition(
1514
1521
  name,
1515
- /** @type {CompressorScopeShape} */ (/** @type {unknown} */ (this)),
1522
+ /** @type {CompressorScopeShape} */ (
1523
+ /** @type {CompressorScopeShape | CompressorScope} */ (this)
1524
+ ),
1516
1525
  0,
1517
1526
  symbol,
1518
1527
  init
@@ -1533,7 +1542,7 @@ class CompressorScope extends MinifierScope {
1533
1542
  */
1534
1543
  adopt(child, readsArguments) {
1535
1544
  const self = /** @type {CompressorScopeShape} */ (
1536
- /** @type {unknown} */ (this)
1545
+ /** @type {CompressorScopeShape | CompressorScope} */ (this)
1537
1546
  );
1538
1547
  if (child.upper === self) return;
1539
1548
  child.upper = self;
@@ -1561,12 +1570,14 @@ class CompressorScope extends MinifierScope {
1561
1570
  const toEnclose = [];
1562
1571
  for (const ancestor of ancestry) {
1563
1572
  const scope = /** @type {MinifierScope} */ (
1564
- /** @type {unknown} */ (ancestor)
1573
+ /** @type {MinifierScope | CompressorScopeShape} */ (ancestor)
1565
1574
  );
1566
1575
  for (const definition of toEnclose) {
1567
1576
  encloseUnique(
1568
1577
  scope,
1569
- /** @type {MinifierVariable} */ (/** @type {unknown} */ (definition))
1578
+ /** @type {MinifierVariable} */ (
1579
+ /** @type {MinifierVariable | CompressorDefinition} */ (definition)
1580
+ )
1570
1581
  );
1571
1582
  }
1572
1583
  const { variables } = ancestor;
@@ -1589,7 +1600,9 @@ class CompressorScope extends MinifierScope {
1589
1600
  if (!toEnclose.includes(only)) toEnclose.push(only);
1590
1601
  encloseUnique(
1591
1602
  scope,
1592
- /** @type {MinifierVariable} */ (/** @type {unknown} */ (only))
1603
+ /** @type {MinifierVariable} */ (
1604
+ /** @type {MinifierVariable | CompressorDefinition} */ (only)
1605
+ )
1593
1606
  );
1594
1607
  continue;
1595
1608
  }
@@ -1601,7 +1614,9 @@ class CompressorScope extends MinifierScope {
1601
1614
  encloseUnique(
1602
1615
  scope,
1603
1616
  /** @type {MinifierVariable} */ (
1604
- /** @type {unknown} */ (definition)
1617
+ /** @type {MinifierVariable | CompressorDefinition} */ (
1618
+ definition
1619
+ )
1605
1620
  )
1606
1621
  );
1607
1622
  if (--left === 0) break;
@@ -1620,7 +1635,9 @@ class CompressorScope extends MinifierScope {
1620
1635
  variable.references.push(symbol);
1621
1636
  encloseVariable(
1622
1637
  this,
1623
- /** @type {MinifierVariable} */ (/** @type {unknown} */ (variable))
1638
+ /** @type {MinifierVariable} */ (
1639
+ /** @type {MinifierVariable | CompressorDefinition} */ (variable)
1640
+ )
1624
1641
  );
1625
1642
  }
1626
1643
  }
@@ -1642,11 +1659,15 @@ class CompressorVariable extends MinifierVariable {
1642
1659
  constructor(name, scope, kind, orig, init) {
1643
1660
  super(
1644
1661
  name,
1645
- /** @type {MinifierScope} */ (/** @type {unknown} */ (scope)),
1662
+ /** @type {MinifierScope} */ (
1663
+ /** @type {MinifierScope | CompressorScopeShape | null} */ (scope)
1664
+ ),
1646
1665
  kind
1647
1666
  );
1648
1667
  this.identifiers = [
1649
- /** @type {Identifier} */ (/** @type {unknown} */ (orig))
1668
+ /** @type {Identifier} */ (
1669
+ /** @type {Identifier | CompressorNode | { name: string }} */ (orig)
1670
+ )
1650
1671
  ];
1651
1672
  /** @type {CompressorNode | null | undefined} what it is initialized to */
1652
1673
  this.init = init;
@@ -1682,6 +1703,10 @@ class CompressorVariable extends MinifierVariable {
1682
1703
  this.inUseRun = 0;
1683
1704
  /** @type {CompressorNode | undefined} the name a copy of it was set from, kept where a write through the copy dropped `fixed` */
1684
1705
  this.copyOf = undefined;
1706
+ /** @type {boolean} whether `reduce_vars` met a read of it before any value was set */
1707
+ this.readUnset = false;
1708
+ /** @type {boolean} whether `reduce_vars` met a declaration of it giving a value */
1709
+ this.declaredWithValue = false;
1685
1710
  }
1686
1711
  }
1687
1712
 
@@ -1696,7 +1721,7 @@ class CompressorVariable extends MinifierVariable {
1696
1721
  */
1697
1722
  const createCompressorDefinition = (name, scope, kind, orig, init) =>
1698
1723
  /** @type {CompressorDefinition} */ (
1699
- /** @type {unknown} */ (
1724
+ /** @type {CompressorDefinition | CompressorVariable} */ (
1700
1725
  new CompressorVariable(name, scope, kind, orig, init)
1701
1726
  )
1702
1727
  );
@@ -1711,7 +1736,9 @@ const createCompressorDefinition = (name, scope, kind, orig, init) =>
1711
1736
  */
1712
1737
  const createCompressorScope = (type, node, upper, isVarScope) =>
1713
1738
  /** @type {CompressorScopeShape} */ (
1714
- /** @type {unknown} */ (new CompressorScope(type, node, upper, isVarScope))
1739
+ /** @type {CompressorScopeShape | CompressorScope} */ (
1740
+ new CompressorScope(type, node, upper, isVarScope)
1741
+ )
1715
1742
  );
1716
1743
 
1717
1744
  /**
@@ -1787,12 +1814,13 @@ const bindsName = (node, name) => {
1787
1814
  };
1788
1815
 
1789
1816
  /**
1790
- * @param {PrintNode | null} node a statement, or a loop's head
1817
+ * @param {PrintNode | null | undefined} node a statement, or a loop's head, which a compressed `for` may lack
1791
1818
  * @param {string} name a name
1792
1819
  * @returns {boolean} whether it declares the name with `let`, `const`, `using` or a class
1793
1820
  */
1794
1821
  const declaresLexically = (node, name) =>
1795
1822
  node !== null &&
1823
+ node !== undefined &&
1796
1824
  (node.type === "VariableDeclaration"
1797
1825
  ? node.kind !== "var" &&
1798
1826
  node.declarations.some((declarator) =>
@@ -1993,7 +2021,7 @@ class MinifierScopeAnalyzer extends ScopeAnalyzer {
1993
2021
  ) {
1994
2022
  return;
1995
2023
  }
1996
- names.identifiers.push(/** @type {PrintIdentifier} */ (identifier));
2024
+ names.identifiers.push(identifier);
1997
2025
  names.spellings.push(spelling);
1998
2026
  names.savings.push(saving);
1999
2027
  }
@@ -2030,12 +2058,7 @@ class MinifierScopeAnalyzer extends ScopeAnalyzer {
2030
2058
  * @returns {MinifierScope} the scope, now current
2031
2059
  */
2032
2060
  _open(type, node, isVarScope) {
2033
- const scope = new MinifierScope(
2034
- type,
2035
- node,
2036
- /** @type {MinifierScope} */ (this.scope),
2037
- isVarScope
2038
- );
2061
+ const scope = new MinifierScope(type, node, this.scope, isVarScope);
2039
2062
  this.scope = scope;
2040
2063
  return scope;
2041
2064
  }
@@ -2047,7 +2070,7 @@ class MinifierScopeAnalyzer extends ScopeAnalyzer {
2047
2070
  * @returns {MinifierScope} the scope it leaves, now the new scope's parent
2048
2071
  */
2049
2072
  _enterBlock(type, node) {
2050
- const outer = /** @type {MinifierScope} */ (this.scope);
2073
+ const outer = this.scope;
2051
2074
  this._open(type, node, false).usesWith = outer.usesWith;
2052
2075
  return outer;
2053
2076
  }
@@ -2169,7 +2192,7 @@ class MinifierScopeAnalyzer extends ScopeAnalyzer {
2169
2192
  _addReference(node, flags) {
2170
2193
  if (this.release !== undefined) this.release(node);
2171
2194
  this.referenceNodes.push(node);
2172
- this.referenceScopes.push(/** @type {MinifierScope} */ (this.scope));
2195
+ this.referenceScopes.push(this.scope);
2173
2196
  this.referenceFlags.push(flags);
2174
2197
  }
2175
2198
 
@@ -2244,7 +2267,7 @@ class MinifierScopeAnalyzer extends ScopeAnalyzer {
2244
2267
  */
2245
2268
  _declare(identifier, kind) {
2246
2269
  const { name } = identifier;
2247
- const scope = /** @type {MinifierScope} */ (this.scope);
2270
+ const scope = this.scope;
2248
2271
  if (kind === DECLARES_IMPORT) {
2249
2272
  this._defineVariable(scope, identifier, name, kind);
2250
2273
  return;
@@ -2381,7 +2404,7 @@ class MinifierScopeAnalyzer extends ScopeAnalyzer {
2381
2404
  */
2382
2405
  _visitMinifierFunction(node) {
2383
2406
  const outerStrict = this.strict;
2384
- const outer = /** @type {MinifierScope} */ (this.scope);
2407
+ const outer = this.scope;
2385
2408
  const outerLabels = this.labelsInScope;
2386
2409
  const stack = this.stack;
2387
2410
  const inBlock =
@@ -2448,7 +2471,7 @@ class MinifierScopeAnalyzer extends ScopeAnalyzer {
2448
2471
  */
2449
2472
  _visitMinifierClass(node) {
2450
2473
  const outerStrict = this.strict;
2451
- const outer = /** @type {MinifierScope} */ (this.scope);
2474
+ const outer = this.scope;
2452
2475
  const outerLabels = this.labelsInScope;
2453
2476
  this.stack.push(node);
2454
2477
  this.strict = true;
@@ -2572,7 +2595,9 @@ class MinifierScopeAnalyzer extends ScopeAnalyzer {
2572
2595
  */
2573
2596
  _visit(node) {
2574
2597
  // the shared walk's way back in, for the children of what it reads
2575
- this._visitPrint(/** @type {PrintNode} */ (/** @type {unknown} */ (node)));
2598
+ this._visitPrint(
2599
+ /** @type {PrintNode} */ (/** @type {PrintNode | Node} */ (node))
2600
+ );
2576
2601
  }
2577
2602
 
2578
2603
  /**
@@ -2683,7 +2708,7 @@ class MinifierScopeAnalyzer extends ScopeAnalyzer {
2683
2708
  current
2684
2709
  );
2685
2710
  if (this.safari10 && current.type.startsWith("For")) {
2686
- this.forScopes.push(/** @type {MinifierScope} */ (this.scope));
2711
+ this.forScopes.push(this.scope);
2687
2712
  }
2688
2713
  this._visitLoop(current);
2689
2714
  this.scope = outer;
@@ -2706,7 +2731,7 @@ class MinifierScopeAnalyzer extends ScopeAnalyzer {
2706
2731
  case "CatchClause": {
2707
2732
  stack.push(current);
2708
2733
  const outer = this._enterBlock("catch", current);
2709
- const catchScope = /** @type {MinifierScope} */ (this.scope);
2734
+ const catchScope = this.scope;
2710
2735
  const ranged = this.parameterScopes && Boolean(current.param);
2711
2736
  if (ranged) {
2712
2737
  catchScope.parameterStart = this.referenceNodes.length;
@@ -2824,7 +2849,9 @@ class MinifierScopeAnalyzer extends ScopeAnalyzer {
2824
2849
  case "TryStatement":
2825
2850
  // scoped alike, so read by the shared walk, pushed as terser's walk does
2826
2851
  stack.push(current);
2827
- super._visit(/** @type {Node} */ (/** @type {unknown} */ (current)));
2852
+ super._visit(
2853
+ /** @type {Node} */ (/** @type {Node | PrintNode} */ (current))
2854
+ );
2828
2855
  stack.pop();
2829
2856
  return;
2830
2857
  case "PrivateIdentifier":
@@ -2997,7 +3024,7 @@ class MinifierScopeAnalyzer extends ScopeAnalyzer {
2997
3024
  const { length } = references;
2998
3025
  for (let j = 0; j < length; j++) {
2999
3026
  const read = /** @type {PrintIdentifier} */ (
3000
- /** @type {unknown} */ (references[j].identifier)
3027
+ /** @type {PrintIdentifier | Identifier} */ (references[j].identifier)
3001
3028
  );
3002
3029
  read.definition = variable;
3003
3030
  this._referenceVariable(
@@ -3098,7 +3125,7 @@ class MinifierTreeScopeAnalyzer {
3098
3125
  /** @type {MinifierScope} */
3099
3126
  this.toplevel = new MinifierScope(
3100
3127
  "global",
3101
- /** @type {PrintNode} */ (/** @type {unknown} */ (program)),
3128
+ /** @type {PrintNode} */ (/** @type {PrintNode | number} */ (program)),
3102
3129
  null,
3103
3130
  true
3104
3131
  );
@@ -3167,7 +3194,7 @@ class MinifierTreeScopeAnalyzer {
3167
3194
  ) {
3168
3195
  return;
3169
3196
  }
3170
- /** @type {unknown} */
3197
+ /** @type {ReturnType<SyntaxTree["value"]>} */
3171
3198
  let spelling;
3172
3199
  if (types[spelled] === NodeType.Identifier) {
3173
3200
  spelling = tree.name(spelled);
@@ -3282,7 +3309,7 @@ class MinifierTreeScopeAnalyzer {
3282
3309
  _open(type, node, isVarScope) {
3283
3310
  const scope = new MinifierScope(
3284
3311
  type,
3285
- /** @type {PrintNode} */ (/** @type {unknown} */ (node)),
3312
+ /** @type {PrintNode} */ (/** @type {PrintNode | number} */ (node)),
3286
3313
  this.scope,
3287
3314
  isVarScope
3288
3315
  );
@@ -3603,7 +3630,9 @@ class MinifierTreeScopeAnalyzer {
3603
3630
  _keepsInBlock(scope, name) {
3604
3631
  const { tree } = this;
3605
3632
  while (scope !== scope.variableScope) {
3606
- const node = /** @type {number} */ (/** @type {unknown} */ (scope.node));
3633
+ const node = /** @type {number} */ (
3634
+ /** @type {number | PrintNode} */ (scope.node)
3635
+ );
3607
3636
  switch (this.types[node]) {
3608
3637
  case NodeType.BlockStatement:
3609
3638
  if (this._listDeclaresLexically(node, Field.body, name)) return true;
@@ -3648,7 +3677,9 @@ class MinifierTreeScopeAnalyzer {
3648
3677
  }
3649
3678
  scope = /** @type {MinifierScope} */ (scope.upper);
3650
3679
  }
3651
- const node = /** @type {number} */ (/** @type {unknown} */ (scope.node));
3680
+ const node = /** @type {number} */ (
3681
+ /** @type {number | PrintNode} */ (scope.node)
3682
+ );
3652
3683
  if (this.types[node] === NodeType.Program) {
3653
3684
  return this._listDeclaresLexically(node, Field.body, name);
3654
3685
  }
@@ -4285,7 +4316,7 @@ class MinifierTreeScopeAnalyzer {
4285
4316
  return identifiers.map(
4286
4317
  (identifier) =>
4287
4318
  /** @type {PrintIdentifier} */ (
4288
- /** @type {unknown} */ ({
4319
+ /** @type {PrintIdentifier | { name: string, definition: TreeDefinition }} */ ({
4289
4320
  name: this.tree.name(identifier),
4290
4321
  definition: this.definitions[identifier]
4291
4322
  })
@@ -4383,7 +4414,9 @@ class CompressorScopeAnalyzer extends MinifierScopeAnalyzer {
4383
4414
  */
4384
4415
  constructor(root, options, raise, dialect, parentScope, toplevel) {
4385
4416
  super(
4386
- /** @type {PrintProgram} */ (/** @type {unknown} */ (root)),
4417
+ /** @type {PrintProgram} */ (
4418
+ /** @type {PrintProgram | CompressorNode} */ (root)
4419
+ ),
4387
4420
  {
4388
4421
  ie8: options.ie8,
4389
4422
  safari10: options.safari10,
@@ -4396,18 +4429,20 @@ class CompressorScopeAnalyzer extends MinifierScopeAnalyzer {
4396
4429
  /** @type {CompressorDialect} */
4397
4430
  this.dialect = dialect;
4398
4431
  this.toplevel = /** @type {MinifierScope} */ (
4399
- /** @type {unknown} */ (toplevel)
4432
+ /** @type {MinifierScope | CompressorScopeShape} */ (toplevel)
4400
4433
  );
4401
4434
  this.tokenTables =
4402
- /** @type {PrintProgram} */ (/** @type {unknown} */ (toplevel.node))
4403
- .tokenTables || undefined;
4435
+ /** @type {PrintProgram} */ (
4436
+ /** @type {PrintProgram | CompressorNode} */ (toplevel.node)
4437
+ ).tokenTables || undefined;
4404
4438
  this.scope = /** @type {MinifierScope} */ (
4405
- /** @type {unknown} */ (parentScope)
4439
+ /** @type {MinifierScope | CompressorScopeShape} */ (parentScope)
4406
4440
  );
4407
4441
  // The program's node holds its globals, as terser's did.
4408
4442
  this.globals = /** @type {Map<string, MinifierVariable>} */ (
4409
- /** @type {CompressorNode} */ (/** @type {unknown} */ (toplevel.node))
4410
- .globals
4443
+ /** @type {Map<string, MinifierVariable> | Map<string, CompressorDefinition>} */ (
4444
+ toplevel.node.globals
4445
+ )
4411
4446
  );
4412
4447
  }
4413
4448
 
@@ -4419,19 +4454,21 @@ class CompressorScopeAnalyzer extends MinifierScopeAnalyzer {
4419
4454
  */
4420
4455
  _open(type, node, isVarScope) {
4421
4456
  const opener = /** @type {CompressorNode} */ (
4422
- /** @type {unknown} */ (node)
4457
+ /** @type {CompressorNode | PrintNode} */ (node)
4423
4458
  );
4424
4459
  const scope = createCompressorScope(
4425
4460
  type,
4426
4461
  opener,
4427
4462
  /** @type {CompressorScopeShape | null} */ (
4428
- /** @type {unknown} */ (this.scope)
4463
+ /** @type {CompressorScopeShape | MinifierScope | null} */ (this.scope)
4429
4464
  ),
4430
4465
  isVarScope
4431
4466
  );
4432
4467
  // eslint-disable-next-line camelcase -- terser's name, which the compressor reads
4433
4468
  opener.block_scope = scope;
4434
- this.scope = /** @type {MinifierScope} */ (/** @type {unknown} */ (scope));
4469
+ this.scope = /** @type {MinifierScope} */ (
4470
+ /** @type {MinifierScope | CompressorScopeShape} */ (scope)
4471
+ );
4435
4472
  return this.scope;
4436
4473
  }
4437
4474
 
@@ -4446,10 +4483,10 @@ class CompressorScopeAnalyzer extends MinifierScopeAnalyzer {
4446
4483
  */
4447
4484
  _addDeclaration(target, variable, identifier, name, kind) {
4448
4485
  const scope = /** @type {CompressorScopeShape} */ (
4449
- /** @type {unknown} */ (target)
4486
+ /** @type {CompressorScopeShape | MinifierScope} */ (target)
4450
4487
  );
4451
4488
  const opener = /** @type {CompressorNode} */ (
4452
- /** @type {unknown} */ (/** @type {MinifierScope} */ (this.scope).node)
4489
+ /** @type {CompressorNode | PrintNode} */ (this.scope.node)
4453
4490
  );
4454
4491
  /** @type {CompressorNode | null | undefined} */
4455
4492
  let init;
@@ -4458,13 +4495,11 @@ class CompressorScopeAnalyzer extends MinifierScopeAnalyzer {
4458
4495
  symbol = this.dialect.argumentsSymbol(opener);
4459
4496
  } else {
4460
4497
  symbol = /** @type {CompressorNode} */ (
4461
- /** @type {unknown} */ (identifier)
4498
+ /** @type {CompressorNode | PrintIdentifier} */ (identifier)
4462
4499
  );
4463
4500
  if ((1 << kind) & (FUNCTION_DECLARATIONS | (1 << DECLARES_CLASS))) {
4464
4501
  // A function's or class's name, its scope where it is declared.
4465
- symbol.scope = /** @type {CompressorNode} */ (
4466
- /** @type {unknown} */ (scope)
4467
- );
4502
+ symbol.scope = scope;
4468
4503
  // A function expression named `arguments` is not its own value.
4469
4504
  init =
4470
4505
  kind === DECLARES_LAMBDA && name === "arguments" ? undefined : opener;
@@ -4473,14 +4508,16 @@ class CompressorScopeAnalyzer extends MinifierScopeAnalyzer {
4473
4508
  }
4474
4509
  }
4475
4510
  let definition = /** @type {CompressorDefinition | undefined} */ (
4476
- /** @type {unknown} */ (variable)
4511
+ /** @type {CompressorDefinition | MinifierVariable | undefined} */ (
4512
+ variable
4513
+ )
4477
4514
  );
4478
4515
  if (definition !== undefined) {
4479
4516
  definition.declarations |= 1 << kind;
4480
4517
  definition.identifiers.push(symbol);
4481
4518
  if (
4482
4519
  definition.init &&
4483
- (definition.scope !== /** @type {unknown} */ (symbol.scope) ||
4520
+ (definition.scope !== symbol.scope ||
4484
4521
  this.dialect.isFunction(definition.init))
4485
4522
  ) {
4486
4523
  definition.init = init;
@@ -4498,7 +4535,7 @@ class CompressorScopeAnalyzer extends MinifierScopeAnalyzer {
4498
4535
  }
4499
4536
  symbol.definition = definition;
4500
4537
  return /** @type {MinifierVariable} */ (
4501
- /** @type {unknown} */ (definition)
4538
+ /** @type {MinifierVariable | CompressorDefinition} */ (definition)
4502
4539
  );
4503
4540
  }
4504
4541
 
@@ -4511,9 +4548,11 @@ class CompressorScopeAnalyzer extends MinifierScopeAnalyzer {
4511
4548
  */
4512
4549
  _referenceVariable(identifier, from, variable) {
4513
4550
  /** @type {CompressorDefinition} */ (
4514
- /** @type {unknown} */ (variable)
4551
+ /** @type {CompressorDefinition | MinifierVariable} */ (variable)
4515
4552
  ).references.push(
4516
- /** @type {CompressorNode} */ (/** @type {unknown} */ (identifier))
4553
+ /** @type {CompressorNode} */ (
4554
+ /** @type {CompressorNode | PrintIdentifier} */ (identifier)
4555
+ )
4517
4556
  );
4518
4557
  encloseVariable(from, variable);
4519
4558
  }
@@ -4525,8 +4564,11 @@ class CompressorScopeAnalyzer extends MinifierScopeAnalyzer {
4525
4564
  * @returns {void}
4526
4565
  */
4527
4566
  _declare(identifier, kind) {
4528
- /** @type {CompressorNode} */ (/** @type {unknown} */ (identifier)).scope =
4529
- /** @type {CompressorNode} */ (/** @type {unknown} */ (this.scope));
4567
+ /** @type {CompressorNode} */ (
4568
+ /** @type {CompressorNode | PrintIdentifier} */ (identifier)
4569
+ ).scope = /** @type {CompressorScopeShape} */ (
4570
+ /** @type {CompressorScopeShape | MinifierScope} */ (this.scope)
4571
+ );
4530
4572
  super._declare(identifier, kind);
4531
4573
  }
4532
4574
 
@@ -4549,12 +4591,10 @@ class CompressorScopeAnalyzer extends MinifierScopeAnalyzer {
4549
4591
  */
4550
4592
  _recordScope(node) {
4551
4593
  if (node === null || node === undefined) return;
4552
- const symbol = /** @type {CompressorNode} */ (
4553
- /** @type {unknown} */ (node)
4554
- );
4594
+ const symbol = /** @type {CompressorNode} */ (node);
4555
4595
  if (this.dialect.isSymbol(symbol)) {
4556
- symbol.scope = /** @type {CompressorNode} */ (
4557
- /** @type {unknown} */ (this.scope)
4596
+ symbol.scope = /** @type {CompressorScopeShape} */ (
4597
+ /** @type {CompressorScopeShape | MinifierScope} */ (this.scope)
4558
4598
  );
4559
4599
  }
4560
4600
  }
@@ -4567,7 +4607,7 @@ class CompressorScopeAnalyzer extends MinifierScopeAnalyzer {
4567
4607
  */
4568
4608
  _visitPrint(current) {
4569
4609
  const node = /** @type {CompressorNode} */ (
4570
- /** @type {unknown} */ (current)
4610
+ /** @type {CompressorNode | PrintNode} */ (current)
4571
4611
  );
4572
4612
  switch (current.type) {
4573
4613
  case "Identifier":
@@ -4584,7 +4624,9 @@ class CompressorScopeAnalyzer extends MinifierScopeAnalyzer {
4584
4624
  if (
4585
4625
  !current.computed &&
4586
4626
  !this.dialect.isObjectKeyValue(
4587
- /** @type {CompressorNode} */ (/** @type {unknown} */ (current))
4627
+ /** @type {CompressorNode} */ (
4628
+ /** @type {CompressorNode | PrintNode} */ (current)
4629
+ )
4588
4630
  )
4589
4631
  ) {
4590
4632
  this._recordScope(current.key);
@@ -4594,7 +4636,9 @@ class CompressorScopeAnalyzer extends MinifierScopeAnalyzer {
4594
4636
  if (
4595
4637
  !current.computed &&
4596
4638
  !this.dialect.isPrivateField(
4597
- /** @type {CompressorNode} */ (/** @type {unknown} */ (current))
4639
+ /** @type {CompressorNode} */ (
4640
+ /** @type {CompressorNode | PrintNode} */ (current)
4641
+ )
4598
4642
  )
4599
4643
  ) {
4600
4644
  this._recordScope(current.key);
@@ -4640,7 +4684,9 @@ class CompressorScopeAnalyzer extends MinifierScopeAnalyzer {
4640
4684
  * @returns {void}
4641
4685
  */
4642
4686
  _visitExportAll(node) {
4643
- const exported = /** @type {PrintNode} */ (/** @type {unknown} */ (node));
4687
+ const exported = /** @type {PrintNode} */ (
4688
+ /** @type {PrintNode | CompressorNode} */ (node)
4689
+ );
4644
4690
  this._checkModuleStatement(exported, "Export");
4645
4691
  /** @type {CompressorNode[]} */
4646
4692
  const names = node.exported_names;
@@ -4649,7 +4695,11 @@ class CompressorScopeAnalyzer extends MinifierScopeAnalyzer {
4649
4695
  stack.push(exported);
4650
4696
  for (let i = 0; i < names.length; i++) {
4651
4697
  const mapping = names[i];
4652
- stack.push(/** @type {PrintNode} */ (/** @type {unknown} */ (mapping)));
4698
+ stack.push(
4699
+ /** @type {PrintNode} */ (
4700
+ /** @type {PrintNode | CompressorNode} */ (mapping)
4701
+ )
4702
+ );
4653
4703
  this._addReference(
4654
4704
  /** @type {PrintIdentifier} */ (mapping.local),
4655
4705
  REFERENCE_EXPORTED | REFERENCE_FROM_MODULE
@@ -4668,18 +4718,28 @@ class CompressorScopeAnalyzer extends MinifierScopeAnalyzer {
4668
4718
  const { label } = node;
4669
4719
  const { name } = label;
4670
4720
  const labels = /** @type {Map<string, CompressorNode>} */ (
4671
- /** @type {unknown} */ (this.labelsInScope)
4721
+ /** @type {Map<string, CompressorNode> | Map<string, MinifierLabel>} */ (
4722
+ this.labelsInScope
4723
+ )
4672
4724
  );
4673
4725
  if (labels.has(name)) throw new Error(`Label ${name} defined twice`);
4674
4726
  this._recordScope(label);
4675
4727
  // A label's definition is the label itself.
4676
4728
  label.definition = /** @type {CompressorDefinition} */ (
4677
- /** @type {unknown} */ (label)
4729
+ /** @type {CompressorDefinition | CompressorNode} */ (label)
4678
4730
  );
4679
4731
  label.references = [];
4680
4732
  labels.set(name, label);
4681
- this.stack.push(/** @type {PrintNode} */ (/** @type {unknown} */ (node)));
4682
- this._visitPrint(node.body);
4733
+ this.stack.push(
4734
+ /** @type {PrintNode} */ (
4735
+ /** @type {PrintNode | CompressorNode} */ (node)
4736
+ )
4737
+ );
4738
+ this._visitPrint(
4739
+ /** @type {PrintNode} */ (
4740
+ /** @type {PrintNode | CompressorNode | CompressorNode[]} */ (node.body)
4741
+ )
4742
+ );
4683
4743
  this.stack.pop();
4684
4744
  labels.delete(name);
4685
4745
  }
@@ -4694,7 +4754,9 @@ class CompressorScopeAnalyzer extends MinifierScopeAnalyzer {
4694
4754
  if (!name) return;
4695
4755
  this._recordScope(name);
4696
4756
  const label = /** @type {Map<string, CompressorNode>} */ (
4697
- /** @type {unknown} */ (this.labelsInScope)
4757
+ /** @type {Map<string, CompressorNode> | Map<string, MinifierLabel>} */ (
4758
+ this.labelsInScope
4759
+ )
4698
4760
  ).get(name.name);
4699
4761
  if (label === undefined) {
4700
4762
  const start = /** @type {Token} */ (this.tokenOf(name.startToken));
@@ -4703,7 +4765,7 @@ class CompressorScopeAnalyzer extends MinifierScopeAnalyzer {
4703
4765
  );
4704
4766
  }
4705
4767
  name.definition = /** @type {CompressorDefinition} */ (
4706
- /** @type {unknown} */ (label)
4768
+ /** @type {CompressorDefinition | CompressorNode} */ (label)
4707
4769
  );
4708
4770
  label.references.push(node);
4709
4771
  }
@@ -4717,17 +4779,21 @@ class CompressorScopeAnalyzer extends MinifierScopeAnalyzer {
4717
4779
  _resolveCompressor() {
4718
4780
  const { referenceNodes, referenceFlags } = this;
4719
4781
  const globals = /** @type {Map<string, CompressorDefinition>} */ (
4720
- /** @type {unknown} */ (this.globals)
4782
+ /** @type {Map<string, CompressorDefinition> | Map<string, MinifierVariable>} */ (
4783
+ this.globals
4784
+ )
4721
4785
  );
4722
4786
  const toplevel = /** @type {CompressorScopeShape} */ (
4723
- /** @type {unknown} */ (this.toplevel)
4787
+ /** @type {CompressorScopeShape | MinifierScope} */ (this.toplevel)
4724
4788
  );
4725
4789
  for (let i = 0; i < referenceNodes.length; i++) {
4726
4790
  const node = /** @type {CompressorNode} */ (
4727
- /** @type {unknown} */ (referenceNodes[i])
4791
+ /** @type {CompressorNode | PrintIdentifier | PrintLiteral} */ (
4792
+ referenceNodes[i]
4793
+ )
4728
4794
  );
4729
4795
  const from = /** @type {MinifierScope} */ (
4730
- /** @type {unknown} */ (node.scope)
4796
+ /** @type {MinifierScope | CompressorScopeShape} */ (node.scope)
4731
4797
  );
4732
4798
  const flags = referenceFlags[i];
4733
4799
  const { name } = node;
@@ -4748,7 +4814,7 @@ class CompressorScopeAnalyzer extends MinifierScopeAnalyzer {
4748
4814
  }
4749
4815
  }
4750
4816
  let definition = /** @type {CompressorDefinition | undefined} */ (
4751
- /** @type {unknown} */ (
4817
+ /** @type {CompressorDefinition | MinifierVariable | undefined} */ (
4752
4818
  flags & REFERENCE_FROM_MODULE
4753
4819
  ? undefined
4754
4820
  : findMinifierVariable(from, name, i)
@@ -4776,14 +4842,16 @@ class CompressorScopeAnalyzer extends MinifierScopeAnalyzer {
4776
4842
  definition.references.push(node);
4777
4843
  encloseVariable(
4778
4844
  from,
4779
- /** @type {MinifierVariable} */ (/** @type {unknown} */ (definition))
4845
+ /** @type {MinifierVariable} */ (
4846
+ /** @type {MinifierVariable | CompressorDefinition} */ (definition)
4847
+ )
4780
4848
  );
4781
4849
  if (
4782
4850
  from.variableScope !== from &&
4783
4851
  ((1 << definition.kind) & BLOCK_DECLARATIONS) === 0
4784
4852
  ) {
4785
- node.scope = /** @type {CompressorNode} */ (
4786
- /** @type {unknown} */ (from.variableScope)
4853
+ node.scope = /** @type {CompressorScopeShape} */ (
4854
+ /** @type {CompressorScopeShape | Scope} */ (from.variableScope)
4787
4855
  );
4788
4856
  }
4789
4857
  }
@@ -4794,12 +4862,14 @@ class CompressorScopeAnalyzer extends MinifierScopeAnalyzer {
4794
4862
  const { catchNames, catchScopes } = this;
4795
4863
  for (let i = 0; i < catchNames.length; i++) {
4796
4864
  const symbol = /** @type {CompressorNode} */ (
4797
- /** @type {unknown} */ (catchNames[i])
4865
+ /** @type {CompressorNode | PrintIdentifier} */ (catchNames[i])
4798
4866
  );
4799
4867
  const { name } = symbol;
4800
4868
  const { references } = symbol.definition;
4801
4869
  const defunScope = /** @type {CompressorScopeShape} */ (
4802
- /** @type {unknown} */ (catchScopes[i].variableScope)
4870
+ /** @type {CompressorScopeShape | Scope} */ (
4871
+ catchScopes[i].variableScope
4872
+ )
4803
4873
  );
4804
4874
  let definition = defunScope.findVariable(name) || globals.get(name);
4805
4875
  if (definition === undefined) {
@@ -4874,22 +4944,28 @@ const analyzeCompressorScope = (
4874
4944
  );
4875
4945
  if (isProgram) {
4876
4946
  analyzer.stack.push(
4877
- /** @type {PrintNode} */ (/** @type {unknown} */ (root))
4947
+ /** @type {PrintNode} */ (
4948
+ /** @type {PrintNode | CompressorNode} */ (root)
4949
+ )
4878
4950
  );
4879
4951
  analyzer._visitList(
4880
- /** @type {PrintProgram} */ (/** @type {unknown} */ (root)).body
4952
+ /** @type {PrintProgram} */ (
4953
+ /** @type {PrintProgram | CompressorNode} */ (root)
4954
+ ).body
4881
4955
  );
4882
4956
  } else {
4883
4957
  // What a declaration's `export` is read off is not there.
4884
4958
  analyzer.stack.push(
4885
4959
  /** @type {PrintNode} */ (
4886
- /** @type {unknown} */ (
4960
+ /** @type {PrintNode | CompressorNode} */ (
4887
4961
  /** @type {CompressorScopeShape} */ (parentScope).node
4888
4962
  )
4889
4963
  )
4890
4964
  );
4891
4965
  analyzer._visitPrint(
4892
- /** @type {PrintNode} */ (/** @type {unknown} */ (root))
4966
+ /** @type {PrintNode} */ (
4967
+ /** @type {PrintNode | CompressorNode} */ (root)
4968
+ )
4893
4969
  );
4894
4970
  }
4895
4971
  analyzer.stack.pop();