tsc-ts 0.0.9 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (373) hide show
  1. package/README.md +2 -2
  2. package/bin/tsc-ts.js +70 -1
  3. package/dist/api/compiler/ast-utilities.d.ts +19 -1
  4. package/dist/api/compiler/ast-utilities.js +180 -95
  5. package/dist/api/compiler/ast.d.ts +22 -15
  6. package/dist/api/compiler/ast.js +1026 -995
  7. package/dist/api/compiler/astnav.js +15 -15
  8. package/dist/api/compiler/binder-utilities.js +186 -186
  9. package/dist/api/compiler/binder.js +290 -263
  10. package/dist/api/compiler/character-codes.js +2 -2
  11. package/dist/api/compiler/checker-calls.js +178 -124
  12. package/dist/api/compiler/checker-classes.d.ts +14 -3
  13. package/dist/api/compiler/checker-classes.js +134 -90
  14. package/dist/api/compiler/checker-contextual.js +64 -61
  15. package/dist/api/compiler/checker-declaration-order.js +79 -79
  16. package/dist/api/compiler/checker-declarations.d.ts +1 -0
  17. package/dist/api/compiler/checker-declarations.js +160 -136
  18. package/dist/api/compiler/checker-declared-types.js +67 -65
  19. package/dist/api/compiler/checker-decorators.js +77 -77
  20. package/dist/api/compiler/checker-deprecation.d.ts +8 -3
  21. package/dist/api/compiler/checker-deprecation.js +76 -55
  22. package/dist/api/compiler/checker-destructuring.js +47 -45
  23. package/dist/api/compiler/checker-elaboration.js +24 -24
  24. package/dist/api/compiler/checker-emit-helpers.js +4 -4
  25. package/dist/api/compiler/checker-emit-resolver.d.ts +4 -2
  26. package/dist/api/compiler/checker-emit-resolver.js +25 -13
  27. package/dist/api/compiler/checker-evaluator.js +9 -9
  28. package/dist/api/compiler/checker-expressions.js +244 -211
  29. package/dist/api/compiler/checker-functions.js +113 -107
  30. package/dist/api/compiler/checker-generated-code.d.ts +0 -11
  31. package/dist/api/compiler/checker-generated-code.js +28 -52
  32. package/dist/api/compiler/checker-grammar.d.ts +1 -0
  33. package/dist/api/compiler/checker-grammar.js +472 -440
  34. package/dist/api/compiler/checker-heritage.js +91 -93
  35. package/dist/api/compiler/checker-inference.d.ts +77 -5
  36. package/dist/api/compiler/checker-inference.js +487 -107
  37. package/dist/api/compiler/checker-iteration.d.ts +0 -10
  38. package/dist/api/compiler/checker-iteration.js +35 -52
  39. package/dist/api/compiler/checker-javascript.js +14 -14
  40. package/dist/api/compiler/checker-jsdoc.d.ts +8 -10
  41. package/dist/api/compiler/checker-jsdoc.js +67 -58
  42. package/dist/api/compiler/checker-jsx.js +105 -88
  43. package/dist/api/compiler/checker-members.d.ts +9 -2
  44. package/dist/api/compiler/checker-members.js +212 -75
  45. package/dist/api/compiler/checker-modules.d.ts +15 -6
  46. package/dist/api/compiler/checker-modules.js +469 -309
  47. package/dist/api/compiler/checker-narrowing.js +273 -189
  48. package/dist/api/compiler/checker-object-literals.js +25 -22
  49. package/dist/api/compiler/checker-operators.js +126 -118
  50. package/dist/api/compiler/checker-overloads.js +27 -27
  51. package/dist/api/compiler/checker-property-access.js +59 -55
  52. package/dist/api/compiler/checker-services.d.ts +1 -0
  53. package/dist/api/compiler/checker-services.js +222 -210
  54. package/dist/api/compiler/checker-signatures.js +65 -49
  55. package/dist/api/compiler/checker-source-file.d.ts +5 -0
  56. package/dist/api/compiler/checker-source-file.js +154 -130
  57. package/dist/api/compiler/checker-statements.js +33 -32
  58. package/dist/api/compiler/checker-super.js +50 -50
  59. package/dist/api/compiler/checker-symbol-types.js +109 -93
  60. package/dist/api/compiler/checker-symbols.d.ts +13 -1
  61. package/dist/api/compiler/checker-symbols.js +264 -149
  62. package/dist/api/compiler/checker-type-factory.d.ts +5 -0
  63. package/dist/api/compiler/checker-type-factory.js +145 -36
  64. package/dist/api/compiler/checker-type-nodes.d.ts +1 -0
  65. package/dist/api/compiler/checker-type-nodes.js +179 -141
  66. package/dist/api/compiler/checker-type-operators.d.ts +2 -0
  67. package/dist/api/compiler/checker-type-operators.js +110 -63
  68. package/dist/api/compiler/checker-types.d.ts +80 -3
  69. package/dist/api/compiler/checker-types.js +121 -2
  70. package/dist/api/compiler/checker-unused.js +114 -118
  71. package/dist/api/compiler/checker-utilities.js +11 -11
  72. package/dist/api/compiler/checker.d.ts +104 -31
  73. package/dist/api/compiler/checker.js +181 -33
  74. package/dist/api/compiler/command-line.d.ts +1 -3
  75. package/dist/api/compiler/command-line.js +47 -44
  76. package/dist/api/compiler/compile-program.d.ts +42 -3
  77. package/dist/api/compiler/compile-program.js +139 -27
  78. package/dist/api/compiler/diagnostic-messages.d.ts +1849 -1774
  79. package/dist/api/compiler/diagnostic-messages.js +128 -122
  80. package/dist/api/compiler/diagnostics.d.ts +22 -0
  81. package/dist/api/compiler/diagnostics.js +93 -11
  82. package/dist/api/compiler/emitter.d.ts +7 -1
  83. package/dist/api/compiler/emitter.js +53 -11
  84. package/dist/api/compiler/file-include.d.ts +2 -1
  85. package/dist/api/compiler/file-include.js +11 -7
  86. package/dist/api/compiler/file-loader.d.ts +21 -1
  87. package/dist/api/compiler/file-loader.js +201 -48
  88. package/dist/api/compiler/instantiation.d.ts +7 -0
  89. package/dist/api/compiler/instantiation.js +101 -49
  90. package/dist/api/compiler/jsdoc.js +23 -23
  91. package/dist/api/compiler/link-tables.d.ts +48 -18
  92. package/dist/api/compiler/link-tables.js +80 -37
  93. package/dist/api/compiler/locales/cs-CZ.d.ts +1 -1
  94. package/dist/api/compiler/locales/cs-CZ.js +1 -1
  95. package/dist/api/compiler/locales/de-DE.d.ts +1 -1
  96. package/dist/api/compiler/locales/de-DE.js +1 -1
  97. package/dist/api/compiler/locales/es-ES.d.ts +1 -1
  98. package/dist/api/compiler/locales/es-ES.js +1 -1
  99. package/dist/api/compiler/locales/fr-FR.d.ts +1 -1
  100. package/dist/api/compiler/locales/fr-FR.js +1 -1
  101. package/dist/api/compiler/locales/it-IT.d.ts +1 -1
  102. package/dist/api/compiler/locales/it-IT.js +1 -1
  103. package/dist/api/compiler/locales/ja-JP.d.ts +1 -1
  104. package/dist/api/compiler/locales/ja-JP.js +1 -1
  105. package/dist/api/compiler/locales/ko-KR.d.ts +1 -1
  106. package/dist/api/compiler/locales/ko-KR.js +1 -1
  107. package/dist/api/compiler/locales/pl-PL.d.ts +1 -1
  108. package/dist/api/compiler/locales/pl-PL.js +1 -1
  109. package/dist/api/compiler/locales/pt-BR.d.ts +1 -1
  110. package/dist/api/compiler/locales/pt-BR.js +1 -1
  111. package/dist/api/compiler/locales/ru-RU.d.ts +1 -1
  112. package/dist/api/compiler/locales/ru-RU.js +1 -1
  113. package/dist/api/compiler/locales/tr-TR.d.ts +1 -1
  114. package/dist/api/compiler/locales/tr-TR.js +1 -1
  115. package/dist/api/compiler/locales/zh-CN.d.ts +1 -1
  116. package/dist/api/compiler/locales/zh-CN.js +1 -1
  117. package/dist/api/compiler/locales/zh-TW.d.ts +1 -1
  118. package/dist/api/compiler/locales/zh-TW.js +1 -1
  119. package/dist/api/compiler/module-resolution-types.js +6 -6
  120. package/dist/api/compiler/module-resolution.d.ts +10 -1
  121. package/dist/api/compiler/module-resolution.js +115 -84
  122. package/dist/api/compiler/module-specifiers.d.ts +15 -0
  123. package/dist/api/compiler/module-specifiers.js +24 -18
  124. package/dist/api/compiler/name-resolver.js +74 -65
  125. package/dist/api/compiler/node-builder-names.d.ts +11 -3
  126. package/dist/api/compiler/node-builder-names.js +210 -90
  127. package/dist/api/compiler/node-builder-pseudo.js +29 -31
  128. package/dist/api/compiler/node-builder-reuse.js +23 -22
  129. package/dist/api/compiler/node-builder.d.ts +18 -1
  130. package/dist/api/compiler/node-builder.js +191 -102
  131. package/dist/api/compiler/option-declarations.d.ts +2 -6
  132. package/dist/api/compiler/option-declarations.js +315 -375
  133. package/dist/api/compiler/options.d.ts +15 -33
  134. package/dist/api/compiler/options.js +21 -54
  135. package/dist/api/compiler/output-paths.d.ts +4 -1
  136. package/dist/api/compiler/output-paths.js +6 -11
  137. package/dist/api/compiler/package-json.d.ts +3 -3
  138. package/dist/api/compiler/package-json.js +11 -10
  139. package/dist/api/compiler/parallel-parse.d.ts +3 -2
  140. package/dist/api/compiler/parallel-parse.js +17 -5
  141. package/dist/api/compiler/parser.d.ts +40 -19
  142. package/dist/api/compiler/parser.js +308 -216
  143. package/dist/api/compiler/path.d.ts +9 -0
  144. package/dist/api/compiler/path.js +20 -3
  145. package/dist/api/compiler/printer/emit-context.d.ts +5 -1
  146. package/dist/api/compiler/printer/emit-context.js +20 -1
  147. package/dist/api/compiler/printer/factory-base.d.ts +2 -2
  148. package/dist/api/compiler/printer/factory-base.js +7 -3
  149. package/dist/api/compiler/printer/factory.js +3 -1
  150. package/dist/api/compiler/printer/helpers.js +10 -1
  151. package/dist/api/compiler/printer/name-generator.d.ts +1 -1
  152. package/dist/api/compiler/printer/name-generator.js +35 -16
  153. package/dist/api/compiler/printer/printer.d.ts +49 -2
  154. package/dist/api/compiler/printer/printer.js +539 -293
  155. package/dist/api/compiler/printer/utilities.js +149 -147
  156. package/dist/api/compiler/program-checker.d.ts +12 -2
  157. package/dist/api/compiler/program-checker.js +88 -34
  158. package/dist/api/compiler/program-utilities.d.ts +3 -1
  159. package/dist/api/compiler/program-utilities.js +28 -15
  160. package/dist/api/compiler/program.d.ts +4 -6
  161. package/dist/api/compiler/program.js +74 -87
  162. package/dist/api/compiler/pseudo-bigint.d.ts +2 -0
  163. package/dist/api/compiler/pseudo-bigint.js +18 -0
  164. package/dist/api/compiler/regexp-checker.d.ts +1 -1
  165. package/dist/api/compiler/regexp-checker.js +93 -76
  166. package/dist/api/compiler/relations.d.ts +27 -4
  167. package/dist/api/compiler/relations.js +347 -180
  168. package/dist/api/compiler/reparser.js +60 -56
  169. package/dist/api/compiler/scanner.d.ts +19 -2
  170. package/dist/api/compiler/scanner.js +123 -108
  171. package/dist/api/compiler/shared-results.d.ts +463 -0
  172. package/dist/api/compiler/shared-results.js +2128 -0
  173. package/dist/api/compiler/sourcemap.js +2 -2
  174. package/dist/api/compiler/symbol-accessibility.js +87 -74
  175. package/dist/api/compiler/symbol.d.ts +23 -14
  176. package/dist/api/compiler/symbol.js +23 -11
  177. package/dist/api/compiler/syntax-kind.d.ts +198 -197
  178. package/dist/api/compiler/transformers/alias-references.js +247 -139
  179. package/dist/api/compiler/transformers/async-utilities.js +25 -25
  180. package/dist/api/compiler/transformers/async.d.ts +0 -1
  181. package/dist/api/compiler/transformers/async.js +64 -77
  182. package/dist/api/compiler/transformers/class-fields.d.ts +1 -0
  183. package/dist/api/compiler/transformers/class-fields.js +81 -78
  184. package/dist/api/compiler/transformers/commonjs-module.js +18 -15
  185. package/dist/api/compiler/transformers/const-enum-inliner.js +1 -1
  186. package/dist/api/compiler/transformers/declarations-diagnostics.js +247 -244
  187. package/dist/api/compiler/transformers/declarations-pseudo.js +100 -100
  188. package/dist/api/compiler/transformers/declarations-resolver.d.ts +0 -3
  189. package/dist/api/compiler/transformers/declarations-syntactic.d.ts +1 -2
  190. package/dist/api/compiler/transformers/declarations-syntactic.js +134 -156
  191. package/dist/api/compiler/transformers/declarations-tracker.js +18 -18
  192. package/dist/api/compiler/transformers/declarations.d.ts +4 -1
  193. package/dist/api/compiler/transformers/declarations.js +305 -238
  194. package/dist/api/compiler/transformers/decorator-metadata.d.ts +1 -1
  195. package/dist/api/compiler/transformers/decorator-metadata.js +53 -45
  196. package/dist/api/compiler/transformers/decorator-utilities.js +24 -24
  197. package/dist/api/compiler/transformers/destructuring.js +19 -18
  198. package/dist/api/compiler/transformers/emit-resolver.js +1 -1
  199. package/dist/api/compiler/transformers/es-decorators.js +55 -55
  200. package/dist/api/compiler/transformers/external-module-info.js +3 -3
  201. package/dist/api/compiler/transformers/for-await.js +25 -25
  202. package/dist/api/compiler/transformers/import-elision.js +14 -14
  203. package/dist/api/compiler/transformers/jsx.js +12 -12
  204. package/dist/api/compiler/transformers/legacy-decorators.js +17 -17
  205. package/dist/api/compiler/transformers/module.js +8 -8
  206. package/dist/api/compiler/transformers/named-evaluation.js +4 -4
  207. package/dist/api/compiler/transformers/object-rest-spread.js +20 -20
  208. package/dist/api/compiler/transformers/optional-chain.js +10 -10
  209. package/dist/api/compiler/transformers/reference-resolver.d.ts +12 -1
  210. package/dist/api/compiler/transformers/reference-resolver.js +131 -69
  211. package/dist/api/compiler/transformers/runtime-syntax.js +35 -31
  212. package/dist/api/compiler/transformers/subtree-facts.js +47 -47
  213. package/dist/api/compiler/transformers/syntax-facts.js +56 -58
  214. package/dist/api/compiler/transformers/type-eraser.js +73 -66
  215. package/dist/api/compiler/transformers/type-serialization.js +24 -24
  216. package/dist/api/compiler/transformers/using.js +12 -12
  217. package/dist/api/compiler/transformers/utilities.js +77 -77
  218. package/dist/api/compiler/transformers/visitor-base.js +172 -172
  219. package/dist/api/compiler/transformers/visitor-hooks.js +6 -2
  220. package/dist/api/compiler/tsconfig.d.ts +10 -2
  221. package/dist/api/compiler/tsconfig.js +136 -48
  222. package/dist/api/compiler/type-printer.js +40 -3
  223. package/dist/api/compiler/types.d.ts +2 -1
  224. package/dist/api/library/ast.generated.d.ts +42 -39
  225. package/dist/api/library/ast.generated.js +1 -1
  226. package/dist/api/library/compiler-options.generated.d.ts +111 -100
  227. package/dist/api/library/compiler-options.generated.js +1 -1
  228. package/dist/api/library/disk.js +12 -1
  229. package/dist/api/library/enums.generated.d.ts +206 -206
  230. package/dist/api/library/enums.generated.js +206 -206
  231. package/dist/api/library/nodes.js +26 -26
  232. package/package.json +9 -9
  233. package/src/compiler/ast-utilities.ts +99 -7
  234. package/src/compiler/ast.ts +58 -26
  235. package/src/compiler/binder.ts +39 -4
  236. package/src/compiler/character-codes.ts +2 -2
  237. package/src/compiler/checker-calls.ts +79 -9
  238. package/src/compiler/checker-classes.ts +78 -24
  239. package/src/compiler/checker-contextual.ts +6 -1
  240. package/src/compiler/checker-declarations.ts +31 -4
  241. package/src/compiler/checker-declared-types.ts +8 -5
  242. package/src/compiler/checker-decorators.ts +1 -1
  243. package/src/compiler/checker-deprecation.ts +29 -8
  244. package/src/compiler/checker-destructuring.ts +10 -3
  245. package/src/compiler/checker-emit-helpers.ts +1 -0
  246. package/src/compiler/checker-emit-resolver.ts +16 -6
  247. package/src/compiler/checker-expressions.ts +79 -46
  248. package/src/compiler/checker-functions.ts +21 -6
  249. package/src/compiler/checker-generated-code.ts +2 -22
  250. package/src/compiler/checker-grammar.ts +136 -62
  251. package/src/compiler/checker-heritage.ts +22 -21
  252. package/src/compiler/checker-inference.ts +514 -82
  253. package/src/compiler/checker-iteration.ts +18 -31
  254. package/src/compiler/checker-javascript.ts +1 -1
  255. package/src/compiler/checker-jsdoc.ts +50 -27
  256. package/src/compiler/checker-jsx.ts +26 -4
  257. package/src/compiler/checker-members.ts +200 -56
  258. package/src/compiler/checker-modules.ts +332 -65
  259. package/src/compiler/checker-narrowing.ts +98 -19
  260. package/src/compiler/checker-object-literals.ts +3 -0
  261. package/src/compiler/checker-operators.ts +11 -4
  262. package/src/compiler/checker-property-access.ts +7 -2
  263. package/src/compiler/checker-services.ts +39 -12
  264. package/src/compiler/checker-signatures.ts +15 -1
  265. package/src/compiler/checker-source-file.ts +39 -13
  266. package/src/compiler/checker-statements.ts +3 -2
  267. package/src/compiler/checker-symbol-types.ts +29 -6
  268. package/src/compiler/checker-symbols.ts +158 -15
  269. package/src/compiler/checker-type-factory.ts +124 -23
  270. package/src/compiler/checker-type-nodes.ts +46 -3
  271. package/src/compiler/checker-type-operators.ts +83 -26
  272. package/src/compiler/checker-types.ts +147 -4
  273. package/src/compiler/checker-unused.ts +9 -14
  274. package/src/compiler/checker.ts +203 -39
  275. package/src/compiler/command-line.ts +28 -28
  276. package/src/compiler/compile-program.ts +167 -27
  277. package/src/compiler/decoder.ts +13 -4
  278. package/src/compiler/diagnostic-messages.ts +1973 -1892
  279. package/src/compiler/diagnostics.ts +84 -3
  280. package/src/compiler/emitter.ts +57 -8
  281. package/src/compiler/encoder.ts +23 -8
  282. package/src/compiler/file-include.ts +9 -3
  283. package/src/compiler/file-loader.ts +197 -38
  284. package/src/compiler/help.ts +10 -14
  285. package/src/compiler/incremental.ts +165 -30
  286. package/src/compiler/init.ts +2 -7
  287. package/src/compiler/instantiation.ts +77 -22
  288. package/src/compiler/jsdoc.ts +3 -1
  289. package/src/compiler/link-tables.ts +82 -37
  290. package/src/compiler/locales/cs-CZ.ts +1 -1
  291. package/src/compiler/locales/de-DE.ts +1 -1
  292. package/src/compiler/locales/es-ES.ts +1 -1
  293. package/src/compiler/locales/fr-FR.ts +1 -1
  294. package/src/compiler/locales/it-IT.ts +1 -1
  295. package/src/compiler/locales/ja-JP.ts +1 -1
  296. package/src/compiler/locales/ko-KR.ts +1 -1
  297. package/src/compiler/locales/pl-PL.ts +1 -1
  298. package/src/compiler/locales/pt-BR.ts +1 -1
  299. package/src/compiler/locales/ru-RU.ts +1 -1
  300. package/src/compiler/locales/tr-TR.ts +1 -1
  301. package/src/compiler/locales/zh-CN.ts +1 -1
  302. package/src/compiler/locales/zh-TW.ts +1 -1
  303. package/src/compiler/module-resolution.ts +44 -8
  304. package/src/compiler/module-specifiers.ts +62 -20
  305. package/src/compiler/name-resolver.ts +9 -1
  306. package/src/compiler/node-builder-names.ts +236 -54
  307. package/src/compiler/node-builder-pseudo.ts +4 -7
  308. package/src/compiler/node-builder-reuse.ts +5 -4
  309. package/src/compiler/node-builder.ts +130 -31
  310. package/src/compiler/option-declarations.ts +33 -103
  311. package/src/compiler/options.ts +23 -62
  312. package/src/compiler/output-paths.ts +5 -18
  313. package/src/compiler/package-entrypoints.ts +345 -0
  314. package/src/compiler/package-json.ts +4 -4
  315. package/src/compiler/parallel-check.ts +326 -52
  316. package/src/compiler/parallel-emit.ts +320 -0
  317. package/src/compiler/parallel-parse.ts +16 -5
  318. package/src/compiler/parse-thread.ts +3 -0
  319. package/src/compiler/parser.ts +156 -39
  320. package/src/compiler/path.ts +22 -2
  321. package/src/compiler/printer/emit-context.ts +21 -0
  322. package/src/compiler/printer/factory-base.ts +10 -3
  323. package/src/compiler/printer/factory.ts +4 -1
  324. package/src/compiler/printer/helpers.ts +10 -1
  325. package/src/compiler/printer/name-generator.ts +24 -2
  326. package/src/compiler/printer/printer.ts +266 -30
  327. package/src/compiler/printer/utilities.ts +8 -2
  328. package/src/compiler/program-checker.ts +57 -5
  329. package/src/compiler/program-utilities.ts +23 -10
  330. package/src/compiler/program.ts +18 -26
  331. package/src/compiler/pseudo-bigint.ts +17 -0
  332. package/src/compiler/regexp-checker.ts +63 -30
  333. package/src/compiler/relations.ts +240 -77
  334. package/src/compiler/reparser.ts +7 -2
  335. package/src/compiler/scanner.ts +109 -79
  336. package/src/compiler/shared-results.ts +2414 -0
  337. package/src/compiler/show-config.ts +18 -1
  338. package/src/compiler/sourcemap.ts +2 -2
  339. package/src/compiler/symbol-accessibility.ts +26 -3
  340. package/src/compiler/symbol.ts +46 -24
  341. package/src/compiler/syntax-kind.ts +188 -187
  342. package/src/compiler/thread-entry.ts +64 -4
  343. package/src/compiler/transformers/alias-references.ts +123 -4
  344. package/src/compiler/transformers/async.ts +2 -17
  345. package/src/compiler/transformers/class-fields.ts +13 -12
  346. package/src/compiler/transformers/commonjs-module.ts +11 -7
  347. package/src/compiler/transformers/declarations-diagnostics.ts +5 -3
  348. package/src/compiler/transformers/declarations-pseudo.ts +2 -4
  349. package/src/compiler/transformers/declarations-resolver.ts +0 -3
  350. package/src/compiler/transformers/declarations-syntactic.ts +1 -21
  351. package/src/compiler/transformers/declarations.ts +134 -48
  352. package/src/compiler/transformers/decorator-metadata.ts +9 -1
  353. package/src/compiler/transformers/destructuring.ts +4 -3
  354. package/src/compiler/transformers/external-module-info.ts +1 -1
  355. package/src/compiler/transformers/jsx.ts +2 -1
  356. package/src/compiler/transformers/reference-resolver.ts +83 -19
  357. package/src/compiler/transformers/runtime-syntax.ts +6 -1
  358. package/src/compiler/transformers/syntax-facts.ts +2 -7
  359. package/src/compiler/transformers/type-eraser.ts +10 -1
  360. package/src/compiler/transformers/type-serialization.ts +3 -2
  361. package/src/compiler/transformers/visitor-base.ts +2 -1
  362. package/src/compiler/transformers/visitor-hooks.ts +9 -4
  363. package/src/compiler/tsc-build.ts +66 -9
  364. package/src/compiler/tsc-cli.ts +7 -0
  365. package/src/compiler/tsc-compile.ts +284 -4
  366. package/src/compiler/tsc-watch.ts +74 -45
  367. package/src/compiler/tsconfig.ts +176 -19
  368. package/src/compiler/type-printer.ts +36 -2
  369. package/src/compiler/types.ts +2 -1
  370. package/src/library/ast.generated.ts +57 -41
  371. package/src/library/compiler-options.generated.ts +117 -103
  372. package/src/library/disk.ts +10 -1
  373. package/src/library/enums.generated.ts +196 -196
@@ -6,12 +6,12 @@ import { cachedTypeKey, cachedTypePairKey, } from './checker-types.js';
6
6
  import { getSymbolId } from './symbol.js';
7
7
  import { getNodeId } from './ast.js';
8
8
  import { getAdjustedTypeWithFacts, getNonNullableType, getTypeFacts, getTypeWithFacts, hasTypeFacts, } from './checker-flow.js';
9
- import { everyType, filterType, getBaseTypeOfLiteralType, getFreshTypeOfLiteralType, getIntersectionType, getRegularTypeOfLiteralType, getUnionType, getUnionTypeEx, getWidenedLiteralType, isEmptyAnonymousObjectType, isFreshLiteralType, isLiteralType, isPatternLiteralType, isUnitType, mapType, removeType, someType, typesOf, containsMissingType, getNumberLiteralType, createArrayType, isTupleType, newObjectType, } from './checker-type-factory.js';
9
+ import { everyType, filterType, getBaseTypeOfLiteralType, getFreshTypeOfLiteralType, getIntersectionType, getRegularTypeOfLiteralType, getUnionType, getUnionTypeEx, getWidenedLiteralType, isEmptyAnonymousObjectType, isFreshLiteralType, isLiteralType, isPatternLiteralType, isUnitType, mapType, removeType, someType, typesOf, containsMissingType, getNumberLiteralType, createArrayType, isTupleType, newObjectType, unionContainsTypeOrPrimitive, } from './checker-type-factory.js';
10
10
  import { areTypesComparable, isDiscriminantProperty, isTypeAssignableTo, isTypeDerivedFrom, isTypeRelatedTo, isTypeStrictSubtypeOf, isTypeSubsetOf, isTypeSubtypeOf, } from './relations.js';
11
11
  import { checkExpression, checkExpressionCached, checkExpressionEx, checkNonNullExpression, checkNonNullType, getNarrowableTypeForReference, someTypeIsGenericWithUnionConstraint, getResolvedSymbol, getTypeOfExpression, isThisInTypeQuery, isTupleLikeType, } from './checker-expressions.js';
12
12
  import { isBlockScopedNameDeclaredBeforeUse } from './checker-declaration-order.js';
13
13
  import { getContextualSignature, getInferenceContext, isContextSensitiveFunctionOrObjectLiteralMethod, } from './checker-contextual.js';
14
- import { instantiateType } from './instantiation.js';
14
+ import { instantiateType, isNodeDescendantOf } from './instantiation.js';
15
15
  import { checkIteratedTypeOrElementType } from './checker-iteration.js';
16
16
  import { checkSuperExpression } from './checker-super.js';
17
17
  import { getSymbolNameForPrivateIdentifier } from './binder.js';
@@ -20,7 +20,7 @@ import { getRegularTypeOfObjectLiteral } from './checker-literals.js';
20
20
  import { checkRightHandSideOfForOf } from './checker-statements.js';
21
21
  import { getApparentType, getApplicableIndexInfoForName, getBaseConstraintOfType, getPropertiesOfType, getPropertyOfType, getReducedApparentType, getSignaturesOfType, getTypeOfPropertyOfType, mapToBaseConstraintOrType, } from './checker-members.js';
22
22
  import { getAssignmentTarget, isAssignmentTarget, isPushOrUnshiftIdentifier, getCombinedModifierFlags, hasStaticModifier, getCombinedNodeFlags, getImmediatelyInvokedFunctionExpression, getRootDeclaration, getThisContainer, isAssignmentExpression, isClassLike, isEntityNameExpression, isObjectLiteralMethod, isExpressionOfOptionalChainRoot, isGlobalSourceFile, isLogicalOrCoalescingAssignmentOperator, isOptionalChain, isStatic, skipParentheses, getRangeOfTokenAtPosition, getSourceFileOfNode, } from './binder-utilities.js';
23
- import { getDeclaredTypeOfSymbol, isConstructorType } from './checker-declared-types.js';
23
+ import { getDeclaredTypeOfSymbol, getParentOfSymbol, isConstructorType } from './checker-declared-types.js';
24
24
  import { getErasedSignature, getReturnTypeFromAnnotation, getReturnTypeOfSignature, getSignatureFromDeclaration, getTypePredicateOfSignature, } from './checker-signatures.js';
25
25
  import { getExportSymbolOfValueSymbolIfExported, getSymbolOfDeclaration, resolveEntityName, resolveSymbol, getGlobalTypeAliasSymbol, } from './checker-symbols.js';
26
26
  import { getOptionalType, getTypeOfSymbol, isReadonlySymbol } from './checker-symbol-types.js';
@@ -139,8 +139,8 @@ function isDottedReference(node) {
139
139
  return !isThisInTypeQuery(n);
140
140
  case 109 /* SyntaxKind.ThisKeyword */:
141
141
  return true;
142
- case 212 /* SyntaxKind.PropertyAccessExpression */:
143
- case 213 /* SyntaxKind.ElementAccessExpression */:
142
+ case 213 /* SyntaxKind.PropertyAccessExpression */:
143
+ case 214 /* SyntaxKind.ElementAccessExpression */:
144
144
  n = getExpression(n);
145
145
  break;
146
146
  default:
@@ -155,8 +155,8 @@ function isDottedReference(node) {
155
155
  */
156
156
  function hasKeyCharacterInName(c, node) {
157
157
  let n = node;
158
- while (n.kind === 212 /* SyntaxKind.PropertyAccessExpression */ || n.kind === 213 /* SyntaxKind.ElementAccessExpression */) {
159
- if (n.kind === 213 /* SyntaxKind.ElementAccessExpression */) {
158
+ while (n.kind === 213 /* SyntaxKind.PropertyAccessExpression */ || n.kind === 214 /* SyntaxKind.ElementAccessExpression */) {
159
+ if (n.kind === 214 /* SyntaxKind.ElementAccessExpression */) {
160
160
  const name = getAccessedPropertyName(c, n);
161
161
  if (name !== undefined && /[.@#]/.test(name))
162
162
  return true;
@@ -231,7 +231,7 @@ export function getFlowTypeOfReferenceAt(c, reference, declaredType, initialType
231
231
  : finalizeEvolvingArrayType(c, evolvedType);
232
232
  if (resultType === c.unreachableNeverType ||
233
233
  (reference.parent !== undefined &&
234
- reference.parent.kind === 236 /* SyntaxKind.NonNullExpression */ &&
234
+ reference.parent.kind === 237 /* SyntaxKind.NonNullExpression */ &&
235
235
  (resultType.flags & 262144 /* TypeFlags.Never */) === 0 &&
236
236
  (getTypeWithFacts(c, resultType, 2097152 /* TypeFacts.NEUndefinedOrNull */).flags & 262144 /* TypeFlags.Never */) !== 0))
237
237
  return declaredType;
@@ -357,9 +357,9 @@ export function getTypeAtFlowNode(c, f, start) {
357
357
  const container = flow.node;
358
358
  if (container !== undefined &&
359
359
  container !== f.flowContainer &&
360
- f.reference.kind !== 212 /* SyntaxKind.PropertyAccessExpression */ &&
361
- f.reference.kind !== 213 /* SyntaxKind.ElementAccessExpression */ &&
362
- !(f.reference.kind === 109 /* SyntaxKind.ThisKeyword */ && container.kind !== 220 /* SyntaxKind.ArrowFunction */)) {
360
+ f.reference.kind !== 213 /* SyntaxKind.PropertyAccessExpression */ &&
361
+ f.reference.kind !== 214 /* SyntaxKind.ElementAccessExpression */ &&
362
+ !(f.reference.kind === 109 /* SyntaxKind.ThisKeyword */ && container.kind !== 221 /* SyntaxKind.ArrowFunction */)) {
363
363
  const outer = getFlowNode(container);
364
364
  if (outer !== undefined) {
365
365
  flow = outer;
@@ -442,7 +442,7 @@ function getTypeAtFlowAssignment(c, f, flow) {
442
442
  return complete(f, c.unreachableNeverType);
443
443
  // The dotted name may be an expando property of a function expression; its flow continues
444
444
  // back past the function's declaration.
445
- if (node.kind === 261 /* SyntaxKind.VariableDeclaration */) {
445
+ if (node.kind === 262 /* SyntaxKind.VariableDeclaration */) {
446
446
  const blockScope = getCombinedNodeFlags(node) & 7 /* NodeFlags.BlockScoped */;
447
447
  const initializer = getInitializer(node);
448
448
  if ((isInJSFile(node) ||
@@ -450,13 +450,13 @@ function getTypeAtFlowAssignment(c, f, flow) {
450
450
  blockScope === 4 /* NodeFlags.Using */ ||
451
451
  blockScope === 6 /* NodeFlags.AwaitUsing */) &&
452
452
  initializer !== undefined &&
453
- (initializer.kind === 219 /* SyntaxKind.FunctionExpression */ || initializer.kind === 220 /* SyntaxKind.ArrowFunction */))
453
+ (initializer.kind === 220 /* SyntaxKind.FunctionExpression */ || initializer.kind === 221 /* SyntaxKind.ArrowFunction */))
454
454
  return getTypeAtFlowNode(c, f, flow.antecedent);
455
455
  }
456
456
  return complete(f, f.declaredType);
457
457
  }
458
458
  // `for (const _ in ref)` acts as a non-null check of `ref`.
459
- if (node.kind === 261 /* SyntaxKind.VariableDeclaration */ && node.parent.parent.kind === 250 /* SyntaxKind.ForInStatement */) {
459
+ if (node.kind === 262 /* SyntaxKind.VariableDeclaration */ && node.parent.parent.kind === 251 /* SyntaxKind.ForInStatement */) {
460
460
  const statementExpression = getExpression(node.parent.parent);
461
461
  if (isMatchingReference(c, f.reference, statementExpression) ||
462
462
  optionalChainContainsReference(c, statementExpression, f.reference)) {
@@ -468,21 +468,21 @@ function getTypeAtFlowAssignment(c, f, flow) {
468
468
  return undefined;
469
469
  }
470
470
  function isEmptyArrayAssignment(node) {
471
- if (node.kind === 261 /* SyntaxKind.VariableDeclaration */) {
471
+ if (node.kind === 262 /* SyntaxKind.VariableDeclaration */) {
472
472
  const initializer = getInitializer(node);
473
473
  return initializer !== undefined && isEmptyArrayLiteral(initializer);
474
474
  }
475
475
  const parent = node.parent;
476
- return (node.kind !== 209 /* SyntaxKind.BindingElement */ &&
477
- parent.kind === 227 /* SyntaxKind.BinaryExpression */ &&
476
+ return (node.kind !== 210 /* SyntaxKind.BindingElement */ &&
477
+ parent.kind === 228 /* SyntaxKind.BinaryExpression */ &&
478
478
  isEmptyArrayLiteral(parent.right));
479
479
  }
480
480
  function isEmptyArrayLiteral(node) {
481
- return node.kind === 210 /* SyntaxKind.ArrayLiteralExpression */ && getElements(node).nodes.length === 0;
481
+ return node.kind === 211 /* SyntaxKind.ArrayLiteralExpression */ && getElements(node).nodes.length === 0;
482
482
  }
483
483
  function getInitialOrAssignedType(c, f, flow) {
484
484
  const node = flow.node;
485
- const t = node.kind === 261 /* SyntaxKind.VariableDeclaration */ || node.kind === 209 /* SyntaxKind.BindingElement */
485
+ const t = node.kind === 262 /* SyntaxKind.VariableDeclaration */ || node.kind === 210 /* SyntaxKind.BindingElement */
486
486
  ? getInitialType(c, node)
487
487
  : getAssignedType(c, node);
488
488
  // getNarrowableTypeForReference looks at the reference's position for these.
@@ -491,14 +491,14 @@ function getInitialOrAssignedType(c, f, flow) {
491
491
  return getNarrowableTypeForReference(c, t, f.reference);
492
492
  }
493
493
  function getInitialType(c, node) {
494
- if (node.kind === 261 /* SyntaxKind.VariableDeclaration */) {
494
+ if (node.kind === 262 /* SyntaxKind.VariableDeclaration */) {
495
495
  const initializer = getInitializer(node);
496
496
  if (initializer !== undefined)
497
497
  return getTypeOfInitializer(c, initializer);
498
498
  const statement = node.parent.parent;
499
- if (statement.kind === 250 /* SyntaxKind.ForInStatement */)
499
+ if (statement.kind === 251 /* SyntaxKind.ForInStatement */)
500
500
  return c.stringType;
501
- if (statement.kind === 251 /* SyntaxKind.ForOfStatement */)
501
+ if (statement.kind === 252 /* SyntaxKind.ForOfStatement */)
502
502
  return checkRightHandSideOfForOf(c, statement);
503
503
  return c.errorType;
504
504
  }
@@ -512,7 +512,7 @@ function getInitialTypeOfBindingElement(c, node) {
512
512
  const pattern = node.parent;
513
513
  const parentType = getInitialType(c, pattern.parent);
514
514
  let t;
515
- if (pattern.kind === 207 /* SyntaxKind.ObjectBindingPattern */)
515
+ if (pattern.kind === 208 /* SyntaxKind.ObjectBindingPattern */)
516
516
  t = getTypeOfDestructuredProperty(c, parentType, (node.propertyName ?? node.name));
517
517
  else if (node.dotDotDotToken === undefined)
518
518
  t = getTypeOfDestructuredArrayElement(c, parentType, getElements(pattern).nodes.indexOf(node));
@@ -523,37 +523,37 @@ function getInitialTypeOfBindingElement(c, node) {
523
523
  function getAssignedType(c, node) {
524
524
  const parent = node.parent;
525
525
  switch (parent.kind) {
526
- case 250 /* SyntaxKind.ForInStatement */:
526
+ case 251 /* SyntaxKind.ForInStatement */:
527
527
  return c.stringType;
528
- case 251 /* SyntaxKind.ForOfStatement */:
528
+ case 252 /* SyntaxKind.ForOfStatement */:
529
529
  return checkRightHandSideOfForOf(c, parent);
530
- case 227 /* SyntaxKind.BinaryExpression */:
530
+ case 228 /* SyntaxKind.BinaryExpression */:
531
531
  return getAssignedTypeOfBinaryExpression(c, parent);
532
- case 221 /* SyntaxKind.DeleteExpression */:
532
+ case 222 /* SyntaxKind.DeleteExpression */:
533
533
  return c.undefinedType;
534
- case 210 /* SyntaxKind.ArrayLiteralExpression */:
534
+ case 211 /* SyntaxKind.ArrayLiteralExpression */:
535
535
  return getTypeOfDestructuredArrayElement(c, getAssignedType(c, parent), getElements(parent).nodes.indexOf(node));
536
- case 231 /* SyntaxKind.SpreadElement */:
536
+ case 232 /* SyntaxKind.SpreadElement */:
537
537
  return getTypeOfDestructuredSpreadExpression(c, getAssignedType(c, parent.parent));
538
- case 303 /* SyntaxKind.PropertyAssignment */:
538
+ case 304 /* SyntaxKind.PropertyAssignment */:
539
539
  return getAssignedTypeOfPropertyAssignment(c, parent);
540
- case 304 /* SyntaxKind.ShorthandPropertyAssignment */:
540
+ case 305 /* SyntaxKind.ShorthandPropertyAssignment */:
541
541
  return getTypeWithDefault(c, getAssignedTypeOfPropertyAssignment(c, parent), parent.objectAssignmentInitializer);
542
542
  }
543
543
  return c.errorType;
544
544
  }
545
545
  function getAssignedTypeOfBinaryExpression(c, node) {
546
546
  const parent = node.parent;
547
- const isDestructuringDefaultAssignment = (parent.kind === 210 /* SyntaxKind.ArrayLiteralExpression */ && isDestructuringAssignmentTarget(parent)) ||
548
- (parent.kind === 303 /* SyntaxKind.PropertyAssignment */ && isDestructuringAssignmentTarget(parent.parent));
547
+ const isDestructuringDefaultAssignment = (parent.kind === 211 /* SyntaxKind.ArrayLiteralExpression */ && isDestructuringAssignmentTarget(parent)) ||
548
+ (parent.kind === 304 /* SyntaxKind.PropertyAssignment */ && isDestructuringAssignmentTarget(parent.parent));
549
549
  if (isDestructuringDefaultAssignment)
550
550
  return getTypeWithDefault(c, getAssignedType(c, node), node.right);
551
551
  return getTypeOfExpression(c, node.right);
552
552
  }
553
553
  function isDestructuringAssignmentTarget(parent) {
554
554
  const grandparent = parent.parent;
555
- return ((grandparent.kind === 227 /* SyntaxKind.BinaryExpression */ && grandparent.left === parent) ||
556
- (grandparent.kind === 251 /* SyntaxKind.ForOfStatement */ && grandparent.initializer === parent));
555
+ return ((grandparent.kind === 228 /* SyntaxKind.BinaryExpression */ && grandparent.left === parent) ||
556
+ (grandparent.kind === 252 /* SyntaxKind.ForOfStatement */ && grandparent.initializer === parent));
557
557
  }
558
558
  function getAssignedTypeOfPropertyAssignment(c, node) {
559
559
  return getTypeOfDestructuredProperty(c, getAssignedType(c, node.parent), getName(node));
@@ -659,7 +659,7 @@ function narrowTypeByAssertion(c, f, t, expr) {
659
659
  const node = skipParentheses(expr);
660
660
  if (node.kind === 96 /* SyntaxKind.FalseKeyword */)
661
661
  return c.unreachableNeverType;
662
- if (node.kind === 227 /* SyntaxKind.BinaryExpression */) {
662
+ if (node.kind === 228 /* SyntaxKind.BinaryExpression */) {
663
663
  const binary = node;
664
664
  if (binary.operatorToken.kind === 55 /* SyntaxKind.AmpersandAmpersandToken */)
665
665
  return narrowTypeByAssertion(c, f, narrowTypeByAssertion(c, f, t, binary.left), binary.right);
@@ -678,12 +678,12 @@ export function getEffectsSignature(c, node) {
678
678
  if (signature === undefined) {
679
679
  // Assertion calls resolve their target with getTypeOfDottedName to avoid circularities.
680
680
  let funcType = undefined;
681
- if (node.kind === 227 /* SyntaxKind.BinaryExpression */)
681
+ if (node.kind === 228 /* SyntaxKind.BinaryExpression */)
682
682
  funcType = getSymbolHasInstanceMethodOfObjectType(c, checkNonNullExpression(c, node.right));
683
683
  else {
684
684
  const callee = getExpression(node);
685
685
  // Assertions resolve their target without inference, to avoid circularities in flow analysis.
686
- if (node.parent.kind === 245 /* SyntaxKind.ExpressionStatement */)
686
+ if (node.parent.kind === 246 /* SyntaxKind.ExpressionStatement */)
687
687
  funcType = getTypeOfDottedName(c, callee);
688
688
  else if (callee.kind !== 107 /* SyntaxKind.SuperKeyword */)
689
689
  funcType = isOptionalChain(node)
@@ -728,7 +728,7 @@ function getTypeOfDottedName(c, node) {
728
728
  return getExplicitThisType(c, node);
729
729
  case 107 /* SyntaxKind.SuperKeyword */:
730
730
  return checkSuperExpression(c, node);
731
- case 212 /* SyntaxKind.PropertyAccessExpression */: {
731
+ case 213 /* SyntaxKind.PropertyAccessExpression */: {
732
732
  const t = getTypeOfDottedName(c, getExpression(node));
733
733
  if (t === undefined)
734
734
  return undefined;
@@ -743,17 +743,27 @@ function getTypeOfDottedName(c, node) {
743
743
  prop = getPropertyOfType(c, t, getText(name));
744
744
  return prop !== undefined ? getExplicitTypeOfSymbol(c, prop) : undefined;
745
745
  }
746
- case 218 /* SyntaxKind.ParenthesizedExpression */:
746
+ case 219 /* SyntaxKind.ParenthesizedExpression */:
747
747
  return getTypeOfDottedName(c, getExpression(node));
748
748
  }
749
749
  return undefined;
750
750
  }
751
751
  function getExplicitTypeOfSymbol(c, original) {
752
752
  const symbol = resolveSymbol(c, original) ?? original;
753
+ // `for (const x of x.y)` asks for the explicit type of `x` while finding it.
754
+ const resolving = c.resolvingExplicitTypeOfSymbol;
755
+ if (resolving.has(symbol))
756
+ return undefined;
757
+ resolving.add(symbol);
758
+ const result = getExplicitTypeOfResolvedSymbol(c, symbol);
759
+ resolving.delete(symbol);
760
+ return result;
761
+ }
762
+ function getExplicitTypeOfResolvedSymbol(c, symbol) {
753
763
  if ((symbol.flags & (16 /* SymbolFlags.Function */ | 8192 /* SymbolFlags.Method */ | 32 /* SymbolFlags.Class */ | 512 /* SymbolFlags.ValueModule */)) !== 0)
754
764
  return getTypeOfSymbol(c, symbol);
755
765
  if ((symbol.flags & (3 /* SymbolFlags.Variable */ | 4 /* SymbolFlags.Property */)) !== 0) {
756
- if ((symbol.checkFlags & 262144 /* CheckFlags.Mapped */) !== 0) {
766
+ if ((symbol.checkFlags & 2097152 /* CheckFlags.Mapped */) !== 0) {
757
767
  const origin = c.symbolSyntheticOrigins.get(getSymbolId(symbol));
758
768
  if (origin !== undefined && getExplicitTypeOfSymbol(c, origin) !== undefined)
759
769
  return getTypeOfSymbol(c, symbol);
@@ -763,8 +773,8 @@ function getExplicitTypeOfSymbol(c, original) {
763
773
  if (isDeclarationWithExplicitTypeAnnotation(declaration))
764
774
  return getTypeOfSymbol(c, symbol);
765
775
  // `for (const x of xs)` where `xs` has an explicit type.
766
- if (declaration.kind === 261 /* SyntaxKind.VariableDeclaration */ &&
767
- declaration.parent.parent.kind === 251 /* SyntaxKind.ForOfStatement */) {
776
+ if (declaration.kind === 262 /* SyntaxKind.VariableDeclaration */ &&
777
+ declaration.parent.parent.kind === 252 /* SyntaxKind.ForOfStatement */) {
768
778
  const statement = declaration.parent.parent;
769
779
  const expressionType = getTypeOfDottedName(c, statement.expression);
770
780
  if (expressionType !== undefined)
@@ -776,12 +786,12 @@ function getExplicitTypeOfSymbol(c, original) {
776
786
  }
777
787
  function isDeclarationWithExplicitTypeAnnotation(node) {
778
788
  switch (node.kind) {
779
- case 261 /* SyntaxKind.VariableDeclaration */:
780
- case 173 /* SyntaxKind.PropertyDeclaration */:
781
- case 172 /* SyntaxKind.PropertySignature */:
782
- case 170 /* SyntaxKind.Parameter */:
789
+ case 262 /* SyntaxKind.VariableDeclaration */:
790
+ case 174 /* SyntaxKind.PropertyDeclaration */:
791
+ case 173 /* SyntaxKind.PropertySignature */:
792
+ case 171 /* SyntaxKind.Parameter */:
783
793
  return getType(node) !== undefined;
784
- case 227 /* SyntaxKind.BinaryExpression */: {
794
+ case 228 /* SyntaxKind.BinaryExpression */: {
785
795
  // An expando property assigned a function with a return type annotation.
786
796
  const right = node.right;
787
797
  return isFunctionLike(right) && getType(right) !== undefined;
@@ -982,22 +992,22 @@ function writeFlowCacheKey(c, node, declaredType, initialType, flowContainer) {
982
992
  key += '@' + getNodeId(flowContainer);
983
993
  return key;
984
994
  }
985
- case 236 /* SyntaxKind.NonNullExpression */:
986
- case 218 /* SyntaxKind.ParenthesizedExpression */:
995
+ case 237 /* SyntaxKind.NonNullExpression */:
996
+ case 219 /* SyntaxKind.ParenthesizedExpression */:
987
997
  return writeFlowCacheKey(c, getExpression(node), declaredType, initialType, flowContainer);
988
- case 167 /* SyntaxKind.QualifiedName */: {
998
+ case 168 /* SyntaxKind.QualifiedName */: {
989
999
  const left = writeFlowCacheKey(c, node.left, declaredType, initialType, flowContainer);
990
- return left === undefined ? undefined : left + '.' + node.right.text;
1000
+ return left === undefined ? undefined : left + '.' + getText(node.right);
991
1001
  }
992
- case 212 /* SyntaxKind.PropertyAccessExpression */:
993
- case 213 /* SyntaxKind.ElementAccessExpression */: {
1002
+ case 213 /* SyntaxKind.PropertyAccessExpression */:
1003
+ case 214 /* SyntaxKind.ElementAccessExpression */: {
994
1004
  const name = getAccessedPropertyName(c, node);
995
1005
  if (name !== undefined) {
996
1006
  const left = writeFlowCacheKey(c, getExpression(node), declaredType, initialType, flowContainer);
997
1007
  return left === undefined ? undefined : left + '.' + name;
998
1008
  }
999
1009
  // `obj[key]` for a key that isn't reassigned.
1000
- if (node.kind !== 213 /* SyntaxKind.ElementAccessExpression */)
1010
+ if (node.kind !== 214 /* SyntaxKind.ElementAccessExpression */)
1001
1011
  return undefined;
1002
1012
  const argument = node.argumentExpression;
1003
1013
  if (argument.kind !== 79 /* SyntaxKind.Identifier */)
@@ -1009,12 +1019,12 @@ function writeFlowCacheKey(c, node, declaredType, initialType, flowContainer) {
1009
1019
  return left === undefined ? undefined : left + '.@' + getSymbolId(symbol);
1010
1020
  }
1011
1021
  // Pseudo-references of getNarrowedTypeOfSymbol.
1012
- case 207 /* SyntaxKind.ObjectBindingPattern */:
1013
- case 208 /* SyntaxKind.ArrayBindingPattern */:
1014
- case 263 /* SyntaxKind.FunctionDeclaration */:
1015
- case 219 /* SyntaxKind.FunctionExpression */:
1016
- case 220 /* SyntaxKind.ArrowFunction */:
1017
- case 175 /* SyntaxKind.MethodDeclaration */:
1022
+ case 208 /* SyntaxKind.ObjectBindingPattern */:
1023
+ case 209 /* SyntaxKind.ArrayBindingPattern */:
1024
+ case 264 /* SyntaxKind.FunctionDeclaration */:
1025
+ case 220 /* SyntaxKind.FunctionExpression */:
1026
+ case 221 /* SyntaxKind.ArrowFunction */:
1027
+ case 176 /* SyntaxKind.MethodDeclaration */:
1018
1028
  return '#' + getNodeId(node) + '#' + declaredType.id;
1019
1029
  }
1020
1030
  return undefined;
@@ -1025,7 +1035,7 @@ function narrowType(c, f, t, expr, assumeTrue) {
1025
1035
  const parent = expr.parent;
1026
1036
  if (isExpressionOfOptionalChainRoot(expr) ||
1027
1037
  (parent !== undefined &&
1028
- parent.kind === 227 /* SyntaxKind.BinaryExpression */ &&
1038
+ parent.kind === 228 /* SyntaxKind.BinaryExpression */ &&
1029
1039
  (parent.operatorToken.kind === 60 /* SyntaxKind.QuestionQuestionToken */ ||
1030
1040
  parent.operatorToken.kind === 77 /* SyntaxKind.QuestionQuestionEqualsToken */) &&
1031
1041
  parent.left === expr))
@@ -1038,7 +1048,7 @@ function narrowType(c, f, t, expr, assumeTrue) {
1038
1048
  if (isConstantVariable(c, symbol)) {
1039
1049
  const declaration = symbol.valueDeclaration;
1040
1050
  if (declaration !== undefined &&
1041
- declaration.kind === 261 /* SyntaxKind.VariableDeclaration */ &&
1051
+ declaration.kind === 262 /* SyntaxKind.VariableDeclaration */ &&
1042
1052
  getType(declaration) === undefined) {
1043
1053
  const initializer = getInitializer(declaration);
1044
1054
  // For an access, isConstantReference reads the property symbol resolved where the
@@ -1057,18 +1067,18 @@ function narrowType(c, f, t, expr, assumeTrue) {
1057
1067
  return narrowTypeByTruthiness(c, f, t, expr, assumeTrue);
1058
1068
  case 109 /* SyntaxKind.ThisKeyword */:
1059
1069
  case 107 /* SyntaxKind.SuperKeyword */:
1060
- case 212 /* SyntaxKind.PropertyAccessExpression */:
1061
- case 213 /* SyntaxKind.ElementAccessExpression */:
1070
+ case 213 /* SyntaxKind.PropertyAccessExpression */:
1071
+ case 214 /* SyntaxKind.ElementAccessExpression */:
1062
1072
  return narrowTypeByTruthiness(c, f, t, expr, assumeTrue);
1063
- case 214 /* SyntaxKind.CallExpression */:
1073
+ case 215 /* SyntaxKind.CallExpression */:
1064
1074
  return narrowTypeByCallExpression(c, f, t, expr, assumeTrue);
1065
- case 218 /* SyntaxKind.ParenthesizedExpression */:
1066
- case 236 /* SyntaxKind.NonNullExpression */:
1067
- case 239 /* SyntaxKind.SatisfiesExpression */:
1075
+ case 219 /* SyntaxKind.ParenthesizedExpression */:
1076
+ case 237 /* SyntaxKind.NonNullExpression */:
1077
+ case 240 /* SyntaxKind.SatisfiesExpression */:
1068
1078
  return narrowType(c, f, t, getExpression(expr), assumeTrue);
1069
- case 227 /* SyntaxKind.BinaryExpression */:
1079
+ case 228 /* SyntaxKind.BinaryExpression */:
1070
1080
  return narrowTypeByBinaryExpression(c, f, t, expr, assumeTrue);
1071
- case 225 /* SyntaxKind.PrefixUnaryExpression */:
1081
+ case 226 /* SyntaxKind.PrefixUnaryExpression */:
1072
1082
  if (expr.operator === 53 /* SyntaxKind.ExclamationToken */)
1073
1083
  return narrowType(c, f, t, expr.operand, !assumeTrue);
1074
1084
  break;
@@ -1106,7 +1116,7 @@ function narrowTypeByCallExpression(c, f, t, call, assumeTrue) {
1106
1116
  // `obj.hasOwnProperty("p")` narrows an optional `obj.p` under exactOptionalPropertyTypes.
1107
1117
  if (containsMissingType(c, t) && isAccessExpression(f.reference)) {
1108
1118
  const callee = getExpression(call);
1109
- if (callee.kind === 212 /* SyntaxKind.PropertyAccessExpression */) {
1119
+ if (callee.kind === 213 /* SyntaxKind.PropertyAccessExpression */) {
1110
1120
  const name = callee.name;
1111
1121
  const args = getArguments(call).nodes;
1112
1122
  if (isMatchingReference(c, getExpression(f.reference), getReferenceCandidate(getExpression(callee))) &&
@@ -1153,7 +1163,7 @@ function getTypePredicateArgument(predicate, call) {
1153
1163
  : undefined;
1154
1164
  }
1155
1165
  const invoked = skipParentheses(getExpression(call));
1156
- return invoked.kind === 212 /* SyntaxKind.PropertyAccessExpression */ || invoked.kind === 213 /* SyntaxKind.ElementAccessExpression */
1166
+ return invoked.kind === 213 /* SyntaxKind.PropertyAccessExpression */ || invoked.kind === 214 /* SyntaxKind.ElementAccessExpression */
1157
1167
  ? skipParentheses(getExpression(invoked))
1158
1168
  : undefined;
1159
1169
  }
@@ -1171,9 +1181,9 @@ function narrowTypeByBinaryExpression(c, f, t, expr, assumeTrue) {
1171
1181
  case 37 /* SyntaxKind.ExclamationEqualsEqualsToken */: {
1172
1182
  const left = getReferenceCandidate(expr.left);
1173
1183
  const right = getReferenceCandidate(expr.right);
1174
- if (left.kind === 222 /* SyntaxKind.TypeOfExpression */ && isStringLiteralLike(right))
1184
+ if (left.kind === 223 /* SyntaxKind.TypeOfExpression */ && isStringLiteralLike(right))
1175
1185
  return narrowTypeByTypeof(c, f, t, left, operator, right, assumeTrue);
1176
- if (right.kind === 222 /* SyntaxKind.TypeOfExpression */ && isStringLiteralLike(left))
1186
+ if (right.kind === 223 /* SyntaxKind.TypeOfExpression */ && isStringLiteralLike(left))
1177
1187
  return narrowTypeByTypeof(c, f, t, right, operator, left, assumeTrue);
1178
1188
  if (isMatchingReference(c, f.reference, left))
1179
1189
  return narrowTypeByEquality(c, t, operator, right, assumeTrue);
@@ -1251,7 +1261,7 @@ function isBooleanLiteral(node) {
1251
1261
  return node.kind === 111 /* SyntaxKind.TrueKeyword */ || node.kind === 96 /* SyntaxKind.FalseKeyword */;
1252
1262
  }
1253
1263
  function isAccessExpression(node) {
1254
- return node.kind === 212 /* SyntaxKind.PropertyAccessExpression */ || node.kind === 213 /* SyntaxKind.ElementAccessExpression */;
1264
+ return node.kind === 213 /* SyntaxKind.PropertyAccessExpression */ || node.kind === 214 /* SyntaxKind.ElementAccessExpression */;
1255
1265
  }
1256
1266
  function isStringLiteralLike(node) {
1257
1267
  return node.kind === 10 /* SyntaxKind.StringLiteral */ || node.kind === 14 /* SyntaxKind.NoSubstitutionTemplateLiteral */;
@@ -1307,13 +1317,59 @@ function narrowTypeByEqualityWorker(c, t, valueType, doubleEquals, assumeTrue) {
1307
1317
  if ((valueType.flags & 1048576 /* TypeFlags.Object */) !== 0)
1308
1318
  return c.nonPrimitiveType;
1309
1319
  }
1320
+ if (!doubleEquals && (valueType.flags & 12713980 /* TypeFlags.Primitive */) !== 0 && isUniformUnionType(c, t)) {
1321
+ const regularType = getRegularTypeOfLiteralType(c, valueType);
1322
+ if (unionContainsTypeOrPrimitive(c, t, regularType, false))
1323
+ return regularType;
1324
+ }
1310
1325
  const filtered = filterType(c, t, (u) => areTypesComparable(c, u, valueType) || (doubleEquals && isCoercibleUnderDoubleEquals(u, valueType)));
1311
1326
  return replacePrimitivesWithLiterals(c, filtered, valueType);
1312
1327
  }
1313
- if (isUnitType(valueType))
1328
+ if (isUnitType(valueType)) {
1329
+ if (isUniformUnionType(c, t)) {
1330
+ const filtered = removeType(c, t, getRegularTypeOfLiteralType(c, valueType));
1331
+ if (filtered !== t)
1332
+ return filtered;
1333
+ }
1314
1334
  return filterType(c, t, (u) => !(isUnitLikeType(u) && areTypesComparable(c, u, valueType)));
1335
+ }
1315
1336
  return t;
1316
1337
  }
1338
+ /**
1339
+ * Whether `t` is a primitive union in which no two literal constituents are comparable: it has no
1340
+ * literals of two enums, and not both enum literals and string or number literals. Comparing such a
1341
+ * union with one of its literals matches only that literal.
1342
+ */
1343
+ function isUniformUnionType(c, t) {
1344
+ if ((t.objectFlags & 32768 /* ObjectFlags.PrimitiveUnion */) === 0)
1345
+ return false;
1346
+ const side = sideOf(c, t);
1347
+ if ((side.objectFlags & 268435456 /* ObjectFlags.IsUniformEnumComputed */) === 0)
1348
+ side.objectFlags |=
1349
+ 268435456 /* ObjectFlags.IsUniformEnumComputed */ | (computeIsUniformUnionType(c, typesOf(t)) ? 536870912 /* ObjectFlags.IsUniformEnum */ : 0);
1350
+ return (side.objectFlags & 536870912 /* ObjectFlags.IsUniformEnum */) !== 0;
1351
+ }
1352
+ function computeIsUniformUnionType(c, types) {
1353
+ let enumSymbol;
1354
+ let hasStringOrNumberLiteral = false;
1355
+ for (const t of types) {
1356
+ if ((t.flags & 98304 /* TypeFlags.EnumLike */) !== 0) {
1357
+ if (hasStringOrNumberLiteral)
1358
+ return false;
1359
+ const parent = getParentOfSymbol(c, t.symbol);
1360
+ if (enumSymbol === undefined)
1361
+ enumSymbol = parent;
1362
+ else if (enumSymbol !== parent)
1363
+ return false;
1364
+ }
1365
+ else if ((t.flags & 3072 /* TypeFlags.StringOrNumberLiteral */) !== 0) {
1366
+ if (enumSymbol !== undefined)
1367
+ return false;
1368
+ hasStringOrNumberLiteral = true;
1369
+ }
1370
+ }
1371
+ return true;
1372
+ }
1317
1373
  function isCoercibleUnderDoubleEquals(source, target) {
1318
1374
  return ((source.flags & (64 /* TypeFlags.Number */ | 32 /* TypeFlags.String */ | 8192 /* TypeFlags.BooleanLiteral */)) !== 0 &&
1319
1375
  (target.flags & (64 /* TypeFlags.Number */ | 32 /* TypeFlags.String */ | 256 /* TypeFlags.Boolean */)) !== 0);
@@ -1601,20 +1657,20 @@ function getDiscriminantPropertyAccess(c, f, expr, computedType) {
1601
1657
  }
1602
1658
  function getCandidateDiscriminantPropertyAccess(c, f, expr) {
1603
1659
  const reference = f.reference;
1604
- if (reference.kind === 207 /* SyntaxKind.ObjectBindingPattern */ ||
1605
- reference.kind === 208 /* SyntaxKind.ArrayBindingPattern */ ||
1606
- reference.kind === 219 /* SyntaxKind.FunctionExpression */ ||
1607
- reference.kind === 220 /* SyntaxKind.ArrowFunction */ ||
1660
+ if (reference.kind === 208 /* SyntaxKind.ObjectBindingPattern */ ||
1661
+ reference.kind === 209 /* SyntaxKind.ArrayBindingPattern */ ||
1662
+ reference.kind === 220 /* SyntaxKind.FunctionExpression */ ||
1663
+ reference.kind === 221 /* SyntaxKind.ArrowFunction */ ||
1608
1664
  isObjectLiteralMethod(reference)) {
1609
1665
  // A pseudo-reference from getNarrowedTypeOfSymbol: a sibling destructured variable or parameter is a candidate.
1610
1666
  if (expr.kind !== 79 /* SyntaxKind.Identifier */)
1611
1667
  return undefined;
1612
1668
  const declaration = getExportSymbolOfValueSymbolIfExported(c, getResolvedSymbol(c, expr)).valueDeclaration;
1613
1669
  if (declaration !== undefined &&
1614
- (declaration.kind === 209 /* SyntaxKind.BindingElement */ || declaration.kind === 170 /* SyntaxKind.Parameter */) &&
1670
+ (declaration.kind === 210 /* SyntaxKind.BindingElement */ || declaration.kind === 171 /* SyntaxKind.Parameter */) &&
1615
1671
  declaration.parent === reference &&
1616
1672
  getInitializer(declaration) === undefined &&
1617
- (declaration.kind === 209 /* SyntaxKind.BindingElement */
1673
+ (declaration.kind === 210 /* SyntaxKind.BindingElement */
1618
1674
  ? declaration.dotDotDotToken
1619
1675
  : getDotDotDotToken(declaration)) === undefined)
1620
1676
  return declaration;
@@ -1634,7 +1690,7 @@ function getCandidateDiscriminantPropertyAccess(c, f, expr) {
1634
1690
  return initializer;
1635
1691
  // `const { kind: x } = obj` makes `x` an alias of `obj.kind`.
1636
1692
  if (declaration !== undefined &&
1637
- declaration.kind === 209 /* SyntaxKind.BindingElement */ &&
1693
+ declaration.kind === 210 /* SyntaxKind.BindingElement */ &&
1638
1694
  getInitializer(declaration) === undefined) {
1639
1695
  const parentInitializer = getCandidateVariableDeclarationInitializer(declaration.parent.parent);
1640
1696
  if (parentInitializer !== undefined &&
@@ -1647,7 +1703,7 @@ function getCandidateDiscriminantPropertyAccess(c, f, expr) {
1647
1703
  return undefined;
1648
1704
  }
1649
1705
  function getCandidateVariableDeclarationInitializer(node) {
1650
- if (node === undefined || node.kind !== 261 /* SyntaxKind.VariableDeclaration */ || getType(node) !== undefined)
1706
+ if (node === undefined || node.kind !== 262 /* SyntaxKind.VariableDeclaration */ || getType(node) !== undefined)
1651
1707
  return undefined;
1652
1708
  const initializer = getInitializer(node);
1653
1709
  return initializer !== undefined ? skipParentheses(initializer) : undefined;
@@ -1673,7 +1729,7 @@ function narrowTypeByDiscriminant(c, t, access, narrow) {
1673
1729
  });
1674
1730
  }
1675
1731
  function isNonNullAccess(node) {
1676
- return isAccessExpression(node) && getExpression(node).kind === 236 /* SyntaxKind.NonNullExpression */;
1732
+ return isAccessExpression(node) && getExpression(node).kind === 237 /* SyntaxKind.NonNullExpression */;
1677
1733
  }
1678
1734
  function getTypeOfPropertyOrIndexSignatureOfType(c, t, name) {
1679
1735
  const propType = getTypeOfPropertyOfType(c, t, name);
@@ -1771,7 +1827,7 @@ function getTypeAtSwitchClause(c, f, flow) {
1771
1827
  let t = flowType;
1772
1828
  if (isMatchingReference(c, f.reference, expr))
1773
1829
  t = narrowTypeBySwitchOnDiscriminant(c, t, flow);
1774
- else if (expr.kind === 222 /* SyntaxKind.TypeOfExpression */ && isMatchingReference(c, f.reference, getExpression(expr)))
1830
+ else if (expr.kind === 223 /* SyntaxKind.TypeOfExpression */ && isMatchingReference(c, f.reference, getExpression(expr)))
1775
1831
  t = narrowTypeBySwitchOnTypeOf(c, t, flow);
1776
1832
  else if (expr.kind === 111 /* SyntaxKind.TrueKeyword */)
1777
1833
  t = narrowTypeBySwitchOnTrue(c, f, t, flow);
@@ -1779,7 +1835,7 @@ function getTypeAtSwitchClause(c, f, flow) {
1779
1835
  if (c.strictNullChecks) {
1780
1836
  if (optionalChainContainsReference(c, expr, f.reference))
1781
1837
  t = narrowTypeBySwitchOptionalChainContainment(c, t, flow, (u) => (u.flags & (4 /* TypeFlags.Undefined */ | 262144 /* TypeFlags.Never */)) === 0);
1782
- else if (expr.kind === 222 /* SyntaxKind.TypeOfExpression */ &&
1838
+ else if (expr.kind === 223 /* SyntaxKind.TypeOfExpression */ &&
1783
1839
  optionalChainContainsReference(c, getExpression(expr), f.reference))
1784
1840
  t = narrowTypeBySwitchOptionalChainContainment(c, t, flow, (u) => !((u.flags & 262144 /* TypeFlags.Never */) !== 0 ||
1785
1841
  ((u.flags & 1024 /* TypeFlags.StringLiteral */) !== 0 && u.stringValue === 'undefined')));
@@ -1860,9 +1916,18 @@ function narrowTypeBySwitchOnDiscriminantWorker(c, t, flow) {
1860
1916
  return getUnionType(c, ground);
1861
1917
  }
1862
1918
  const discriminantType = getUnionType(c, clauseTypes);
1863
- const caseType = (discriminantType.flags & 262144 /* TypeFlags.Never */) !== 0
1864
- ? c.neverType
1865
- : replacePrimitivesWithLiterals(c, filterType(c, t, (u) => areTypesComparable(c, discriminantType, u)), discriminantType);
1919
+ let caseType;
1920
+ if ((discriminantType.flags & 262144 /* TypeFlags.Never */) !== 0)
1921
+ caseType = c.neverType;
1922
+ else {
1923
+ if ((discriminantType.flags & 12713980 /* TypeFlags.Primitive */) !== 0 && isUniformUnionType(c, t)) {
1924
+ const regularType = getRegularTypeOfLiteralType(c, discriminantType);
1925
+ if (unionContainsTypeOrPrimitive(c, t, regularType, false))
1926
+ caseType = regularType;
1927
+ }
1928
+ if (caseType === undefined)
1929
+ caseType = replacePrimitivesWithLiterals(c, filterType(c, t, (u) => areTypesComparable(c, discriminantType, u)), discriminantType);
1930
+ }
1866
1931
  if (!hasDefaultClause)
1867
1932
  return caseType;
1868
1933
  const defaultType = filterType(c, t, (u) => {
@@ -1912,7 +1977,7 @@ function getNotEqualFactsFromTypeofSwitch(start, end, witnesses) {
1912
1977
  function getDefaultClauseIndex(statement) {
1913
1978
  const clauses = getClauses(statement);
1914
1979
  for (let i = 0; i < clauses.length; i++)
1915
- if (clauses[i].kind === 298 /* SyntaxKind.DefaultClause */)
1980
+ if (clauses[i].kind === 299 /* SyntaxKind.DefaultClause */)
1916
1981
  return i;
1917
1982
  return -1;
1918
1983
  }
@@ -1971,7 +2036,7 @@ export function isExhaustiveSwitchStatement(c, statement) {
1971
2036
  }
1972
2037
  function computeExhaustiveSwitchStatement(c, statement) {
1973
2038
  const expression = statement.expression;
1974
- if (expression.kind === 222 /* SyntaxKind.TypeOfExpression */) {
2039
+ if (expression.kind === 223 /* SyntaxKind.TypeOfExpression */) {
1975
2040
  const witnesses = getSwitchClauseTypeOfWitnesses(c, statement);
1976
2041
  if (witnesses === undefined)
1977
2042
  return false;
@@ -2003,9 +2068,9 @@ export function isMatchingReference(c, source, target) {
2003
2068
  // A declaration's symbol has the declaration's name, and an identifier's text is its name: an
2004
2069
  // identifier never refers to the variable or binding element of a declaration of another name.
2005
2070
  if (source.kind === 79 /* SyntaxKind.Identifier */ &&
2006
- (target.kind === 261 /* SyntaxKind.VariableDeclaration */ || target.kind === 209 /* SyntaxKind.BindingElement */)) {
2071
+ (target.kind === 262 /* SyntaxKind.VariableDeclaration */ || target.kind === 210 /* SyntaxKind.BindingElement */)) {
2007
2072
  // A cast to one class: a union of the two would be boxed in native builds.
2008
- const name = target.kind === 261 /* SyntaxKind.VariableDeclaration */
2073
+ const name = target.kind === 262 /* SyntaxKind.VariableDeclaration */
2009
2074
  ? target.name
2010
2075
  : target.name;
2011
2076
  if (name !== undefined &&
@@ -2014,10 +2079,10 @@ export function isMatchingReference(c, source, target) {
2014
2079
  return false;
2015
2080
  }
2016
2081
  switch (target.kind) {
2017
- case 218 /* SyntaxKind.ParenthesizedExpression */:
2018
- case 236 /* SyntaxKind.NonNullExpression */:
2082
+ case 219 /* SyntaxKind.ParenthesizedExpression */:
2083
+ case 237 /* SyntaxKind.NonNullExpression */:
2019
2084
  return isMatchingReference(c, source, getExpression(target));
2020
- case 227 /* SyntaxKind.BinaryExpression */: {
2085
+ case 228 /* SyntaxKind.BinaryExpression */: {
2021
2086
  const binary = target;
2022
2087
  return ((isAssignmentExpression(target, false) && isMatchingReference(c, source, binary.left)) ||
2023
2088
  (binary.operatorToken.kind === 27 /* SyntaxKind.CommaToken */ && isMatchingReference(c, source, binary.right)));
@@ -2030,23 +2095,23 @@ export function isMatchingReference(c, source, target) {
2030
2095
  return target.kind === 109 /* SyntaxKind.ThisKeyword */;
2031
2096
  if (target.kind === 79 /* SyntaxKind.Identifier */)
2032
2097
  return getResolvedSymbol(c, source) === getResolvedSymbol(c, target);
2033
- if (target.kind === 261 /* SyntaxKind.VariableDeclaration */ || target.kind === 209 /* SyntaxKind.BindingElement */)
2098
+ if (target.kind === 262 /* SyntaxKind.VariableDeclaration */ || target.kind === 210 /* SyntaxKind.BindingElement */)
2034
2099
  return (getExportSymbolOfValueSymbolIfExported(c, getResolvedSymbol(c, source)) === getSymbolOfDeclaration(c, target));
2035
2100
  return false;
2036
2101
  case 109 /* SyntaxKind.ThisKeyword */:
2037
2102
  return target.kind === 109 /* SyntaxKind.ThisKeyword */;
2038
2103
  case 107 /* SyntaxKind.SuperKeyword */:
2039
2104
  return target.kind === 107 /* SyntaxKind.SuperKeyword */;
2040
- case 237 /* SyntaxKind.MetaProperty */:
2041
- return (target.kind === 237 /* SyntaxKind.MetaProperty */ &&
2105
+ case 238 /* SyntaxKind.MetaProperty */:
2106
+ return (target.kind === 238 /* SyntaxKind.MetaProperty */ &&
2042
2107
  source.keywordToken === target.keywordToken &&
2043
2108
  source.name.text === target.name.text);
2044
- case 236 /* SyntaxKind.NonNullExpression */:
2045
- case 218 /* SyntaxKind.ParenthesizedExpression */:
2046
- case 239 /* SyntaxKind.SatisfiesExpression */:
2109
+ case 237 /* SyntaxKind.NonNullExpression */:
2110
+ case 219 /* SyntaxKind.ParenthesizedExpression */:
2111
+ case 240 /* SyntaxKind.SatisfiesExpression */:
2047
2112
  return isMatchingReference(c, getExpression(source), target);
2048
- case 212 /* SyntaxKind.PropertyAccessExpression */:
2049
- case 213 /* SyntaxKind.ElementAccessExpression */: {
2113
+ case 213 /* SyntaxKind.PropertyAccessExpression */:
2114
+ case 214 /* SyntaxKind.ElementAccessExpression */: {
2050
2115
  const sourceName = getAccessedPropertyName(c, source);
2051
2116
  if (sourceName !== undefined && isAccessExpression(target)) {
2052
2117
  const targetName = getAccessedPropertyName(c, target);
@@ -2054,7 +2119,7 @@ export function isMatchingReference(c, source, target) {
2054
2119
  return targetName === sourceName && isMatchingReference(c, getExpression(source), getExpression(target));
2055
2120
  }
2056
2121
  // `obj[key]` matches `obj[key]` for a key that isn't reassigned.
2057
- if (source.kind === 213 /* SyntaxKind.ElementAccessExpression */ && target.kind === 213 /* SyntaxKind.ElementAccessExpression */) {
2122
+ if (source.kind === 214 /* SyntaxKind.ElementAccessExpression */ && target.kind === 214 /* SyntaxKind.ElementAccessExpression */) {
2058
2123
  const sourceArg = source.argumentExpression;
2059
2124
  const targetArg = target.argumentExpression;
2060
2125
  if (sourceArg.kind === 79 /* SyntaxKind.Identifier */ && targetArg.kind === 79 /* SyntaxKind.Identifier */) {
@@ -2065,15 +2130,15 @@ export function isMatchingReference(c, source, target) {
2065
2130
  }
2066
2131
  return false;
2067
2132
  }
2068
- case 167 /* SyntaxKind.QualifiedName */:
2133
+ case 168 /* SyntaxKind.QualifiedName */:
2069
2134
  if (isAccessExpression(target)) {
2070
2135
  const targetName = getAccessedPropertyName(c, target);
2071
2136
  if (targetName !== undefined)
2072
- return (source.right.text === targetName &&
2137
+ return (getText(source.right) === targetName &&
2073
2138
  isMatchingReference(c, source.left, getExpression(target)));
2074
2139
  }
2075
2140
  return false;
2076
- case 227 /* SyntaxKind.BinaryExpression */:
2141
+ case 228 /* SyntaxKind.BinaryExpression */:
2077
2142
  return (source.operatorToken.kind === 27 /* SyntaxKind.CommaToken */ &&
2078
2143
  isMatchingReference(c, source.right, target));
2079
2144
  }
@@ -2081,9 +2146,14 @@ export function isMatchingReference(c, source, target) {
2081
2146
  }
2082
2147
  /** Whether `expr` is `reference.constructor`. */
2083
2148
  function isMatchingConstructorReference(c, f, expr) {
2084
- return (isAccessExpression(expr) &&
2085
- getAccessedPropertyName(c, expr) === 'constructor' &&
2086
- isMatchingReference(c, f.reference, getExpression(expr)));
2149
+ // Only a literal name is read here; resolving an entity name argument could start a circularity.
2150
+ let name = undefined;
2151
+ if (expr.kind === 213 /* SyntaxKind.PropertyAccessExpression */)
2152
+ name = expr.name;
2153
+ else if (expr.kind === 214 /* SyntaxKind.ElementAccessExpression */ &&
2154
+ isStringLiteralLike(expr.argumentExpression))
2155
+ name = expr.argumentExpression;
2156
+ return (name !== undefined && getText(name) === 'constructor' && isMatchingReference(c, f.reference, getExpression(expr)));
2087
2157
  }
2088
2158
  /** Narrows by `x.constructor === C` to the constituents constructed by `C`. */
2089
2159
  function narrowTypeByConstructor(c, t, operator, identifier, assumeTrue) {
@@ -2117,11 +2187,11 @@ function isConstructedBy(c, source, target) {
2117
2187
  return isTypeSubtypeOf(c, source, target);
2118
2188
  }
2119
2189
  export function getAccessedPropertyName(c, access) {
2120
- if (access.kind === 212 /* SyntaxKind.PropertyAccessExpression */)
2190
+ if (access.kind === 213 /* SyntaxKind.PropertyAccessExpression */)
2121
2191
  return getText(access.name);
2122
- if (access.kind === 209 /* SyntaxKind.BindingElement */)
2192
+ if (access.kind === 210 /* SyntaxKind.BindingElement */)
2123
2193
  return getDestructuringPropertyName(c, access);
2124
- if (access.kind === 213 /* SyntaxKind.ElementAccessExpression */) {
2194
+ if (access.kind === 214 /* SyntaxKind.ElementAccessExpression */) {
2125
2195
  const argument = access.argumentExpression;
2126
2196
  if (isStringLiteralLike(argument))
2127
2197
  return getText(argument);
@@ -2130,7 +2200,7 @@ export function getAccessedPropertyName(c, access) {
2130
2200
  if (isEntityNameExpression(argument, false))
2131
2201
  return tryGetNameFromEntityNameExpression(c, argument);
2132
2202
  }
2133
- if (access.kind === 170 /* SyntaxKind.Parameter */)
2203
+ if (access.kind === 171 /* SyntaxKind.Parameter */)
2134
2204
  return String(getParameters(access.parent).nodes.indexOf(access));
2135
2205
  return undefined;
2136
2206
  }
@@ -2150,16 +2220,16 @@ export function tryGetNameFromEntityNameExpression(c, node) {
2150
2220
  }
2151
2221
  // Binding elements are excluded: their initializers don't alone determine their types, and resolving
2152
2222
  // their full types can be circular.
2153
- if ((declaration.kind === 261 /* SyntaxKind.VariableDeclaration */ ||
2154
- declaration.kind === 173 /* SyntaxKind.PropertyDeclaration */ ||
2155
- declaration.kind === 303 /* SyntaxKind.PropertyAssignment */ ||
2156
- declaration.kind === 170 /* SyntaxKind.Parameter */ ||
2157
- declaration.kind === 306 /* SyntaxKind.EnumMember */) &&
2223
+ if ((declaration.kind === 262 /* SyntaxKind.VariableDeclaration */ ||
2224
+ declaration.kind === 174 /* SyntaxKind.PropertyDeclaration */ ||
2225
+ declaration.kind === 304 /* SyntaxKind.PropertyAssignment */ ||
2226
+ declaration.kind === 171 /* SyntaxKind.Parameter */ ||
2227
+ declaration.kind === 307 /* SyntaxKind.EnumMember */) &&
2158
2228
  isBlockScopedNameDeclaredBeforeUse(c, declaration, node)) {
2159
2229
  const initializer = getInitializer(declaration);
2160
2230
  if (initializer !== undefined)
2161
2231
  return tryGetNameFromType(getTypeOfExpression(c, initializer));
2162
- if (declaration.kind === 306 /* SyntaxKind.EnumMember */) {
2232
+ if (declaration.kind === 307 /* SyntaxKind.EnumMember */) {
2163
2233
  const name = getName(declaration);
2164
2234
  if (isStringLiteralLike(name) || name.kind === 8 /* SyntaxKind.NumericLiteral */ || name.kind === 79 /* SyntaxKind.Identifier */)
2165
2235
  return getText(name);
@@ -2176,11 +2246,11 @@ export function tryGetNameFromType(t) {
2176
2246
  export function getDestructuringPropertyName(c, node) {
2177
2247
  const parent = node.parent;
2178
2248
  let name;
2179
- if (node.kind === 209 /* SyntaxKind.BindingElement */ && parent.kind === 207 /* SyntaxKind.ObjectBindingPattern */)
2249
+ if (node.kind === 210 /* SyntaxKind.BindingElement */ && parent.kind === 208 /* SyntaxKind.ObjectBindingPattern */)
2180
2250
  name = node.propertyName ?? node.name;
2181
- else if (node.kind === 303 /* SyntaxKind.PropertyAssignment */ || node.kind === 304 /* SyntaxKind.ShorthandPropertyAssignment */)
2251
+ else if (node.kind === 304 /* SyntaxKind.PropertyAssignment */ || node.kind === 305 /* SyntaxKind.ShorthandPropertyAssignment */)
2182
2252
  name = getName(node);
2183
- else if (parent.kind === 210 /* SyntaxKind.ArrayLiteralExpression */ || parent.kind === 208 /* SyntaxKind.ArrayBindingPattern */)
2253
+ else if (parent.kind === 211 /* SyntaxKind.ArrayLiteralExpression */ || parent.kind === 209 /* SyntaxKind.ArrayBindingPattern */)
2184
2254
  return String(getElements(parent).nodes.indexOf(node));
2185
2255
  if (name === undefined)
2186
2256
  return undefined;
@@ -2199,24 +2269,24 @@ export function isConstantReference(c, node) {
2199
2269
  const symbol = getResolvedSymbol(c, node);
2200
2270
  return (isConstantVariable(c, symbol) ||
2201
2271
  (isParameterOrMutableLocalVariable(c, symbol) && !isSymbolAssigned(c, symbol)) ||
2202
- (symbol.valueDeclaration !== undefined && symbol.valueDeclaration.kind === 219 /* SyntaxKind.FunctionExpression */));
2272
+ (symbol.valueDeclaration !== undefined && symbol.valueDeclaration.kind === 220 /* SyntaxKind.FunctionExpression */));
2203
2273
  }
2204
- case 212 /* SyntaxKind.PropertyAccessExpression */:
2205
- case 213 /* SyntaxKind.ElementAccessExpression */: {
2274
+ case 213 /* SyntaxKind.PropertyAccessExpression */:
2275
+ case 214 /* SyntaxKind.ElementAccessExpression */: {
2206
2276
  if (!isConstantReference(c, getExpression(node)))
2207
2277
  return false;
2208
2278
  const symbol = c.resolvedSymbols.get(node.id);
2209
2279
  return symbol !== undefined && isReadonlySymbol(c, symbol);
2210
2280
  }
2211
- case 207 /* SyntaxKind.ObjectBindingPattern */:
2212
- case 208 /* SyntaxKind.ArrayBindingPattern */: {
2281
+ case 208 /* SyntaxKind.ObjectBindingPattern */:
2282
+ case 209 /* SyntaxKind.ArrayBindingPattern */: {
2213
2283
  // A destructuring pseudo-reference is constant when none of its variables are reassigned.
2214
2284
  const rootDeclaration = getRootDeclaration(node.parent);
2215
- if (rootDeclaration.kind === 170 /* SyntaxKind.Parameter */ ||
2216
- (rootDeclaration.kind === 261 /* SyntaxKind.VariableDeclaration */ &&
2217
- rootDeclaration.parent.kind === 300 /* SyntaxKind.CatchClause */))
2285
+ if (rootDeclaration.kind === 171 /* SyntaxKind.Parameter */ ||
2286
+ (rootDeclaration.kind === 262 /* SyntaxKind.VariableDeclaration */ &&
2287
+ rootDeclaration.parent.kind === 301 /* SyntaxKind.CatchClause */))
2218
2288
  return !isSomeSymbolAssigned(c, getName(rootDeclaration));
2219
- if (rootDeclaration.kind !== 261 /* SyntaxKind.VariableDeclaration */)
2289
+ if (rootDeclaration.kind !== 262 /* SyntaxKind.VariableDeclaration */)
2220
2290
  return false;
2221
2291
  const blockScopeKind = getCombinedNodeFlags(rootDeclaration) & 7 /* NodeFlags.BlockScoped */;
2222
2292
  return (blockScopeKind === 2 /* NodeFlags.Const */ ||
@@ -2246,9 +2316,9 @@ function optionalChainContainsReference(c, sourceIn, target) {
2246
2316
  }
2247
2317
  function getReferenceCandidate(node) {
2248
2318
  switch (node.kind) {
2249
- case 218 /* SyntaxKind.ParenthesizedExpression */:
2319
+ case 219 /* SyntaxKind.ParenthesizedExpression */:
2250
2320
  return getReferenceCandidate(getExpression(node));
2251
- case 227 /* SyntaxKind.BinaryExpression */: {
2321
+ case 228 /* SyntaxKind.BinaryExpression */: {
2252
2322
  const binary = node;
2253
2323
  switch (binary.operatorToken.kind) {
2254
2324
  case 63 /* SyntaxKind.EqualsToken */:
@@ -2272,18 +2342,23 @@ export function hasMatchingArgument(c, call, reference) {
2272
2342
  return true;
2273
2343
  }
2274
2344
  const callee = getExpression(call);
2275
- return (callee.kind === 212 /* SyntaxKind.PropertyAccessExpression */ &&
2345
+ return (callee.kind === 213 /* SyntaxKind.PropertyAccessExpression */ &&
2276
2346
  isOrContainsMatchingReference(c, reference, getExpression(callee)));
2277
2347
  }
2278
2348
  function isOrContainsMatchingReference(c, source, target) {
2279
2349
  return isMatchingReference(c, source, target) || containsMatchingReference(c, source, target);
2280
2350
  }
2281
2351
  function isCallChain(node) {
2282
- return node.kind === 214 /* SyntaxKind.CallExpression */ && isOptionalChain(node);
2352
+ return node.kind === 215 /* SyntaxKind.CallExpression */ && isOptionalChain(node);
2283
2353
  }
2284
2354
  // ---- Reachability
2285
2355
  export function isReachableFlowNode(c, flow) {
2356
+ // The reduce labels of an enclosing flow analysis don't apply.
2357
+ const outerReduceLabels = c.flowReduceLabels;
2358
+ if (outerReduceLabels.length !== 0)
2359
+ c.flowReduceLabels = [];
2286
2360
  const result = isReachableFlowNodeWorker(c, flow, false);
2361
+ c.flowReduceLabels = outerReduceLabels;
2287
2362
  c.lastFlowNode = flow;
2288
2363
  c.lastFlowNodeReachable = result;
2289
2364
  return result;
@@ -2296,7 +2371,8 @@ function isReachableFlowNodeWorker(c, start, noCacheCheckIn) {
2296
2371
  return c.lastFlowNodeReachable;
2297
2372
  const flags = flow.flags;
2298
2373
  if ((flags & 4096 /* FlowFlags.Shared */) !== 0) {
2299
- if (!noCacheCheck) {
2374
+ // A result found through a reduce label holds only for that label's antecedents.
2375
+ if (!noCacheCheck && c.flowReduceLabels.length === 0) {
2300
2376
  const cached = c.flowNodeReachable.get(flow);
2301
2377
  if (cached !== undefined)
2302
2378
  return cached;
@@ -2359,7 +2435,7 @@ function isFalseExpression(expr) {
2359
2435
  const node = skipParentheses(expr);
2360
2436
  if (node.kind === 96 /* SyntaxKind.FalseKeyword */)
2361
2437
  return true;
2362
- if (node.kind === 227 /* SyntaxKind.BinaryExpression */) {
2438
+ if (node.kind === 228 /* SyntaxKind.BinaryExpression */) {
2363
2439
  const binary = node;
2364
2440
  if (binary.operatorToken.kind === 55 /* SyntaxKind.AmpersandAmpersandToken */)
2365
2441
  return isFalseExpression(binary.left) || isFalseExpression(binary.right);
@@ -2372,13 +2448,13 @@ export function getAssignmentTargetKind(node) {
2372
2448
  const target = getAssignmentTarget(node);
2373
2449
  if (target === undefined)
2374
2450
  return 0 /* AssignmentKind.None */;
2375
- if (target.kind === 227 /* SyntaxKind.BinaryExpression */) {
2451
+ if (target.kind === 228 /* SyntaxKind.BinaryExpression */) {
2376
2452
  const op = target.operatorToken.kind;
2377
2453
  return op === 63 /* SyntaxKind.EqualsToken */ || isLogicalOrCoalescingAssignmentOperator(op)
2378
2454
  ? 1 /* AssignmentKind.Definite */
2379
2455
  : 2 /* AssignmentKind.Compound */;
2380
2456
  }
2381
- if (target.kind === 225 /* SyntaxKind.PrefixUnaryExpression */ || target.kind === 226 /* SyntaxKind.PostfixUnaryExpression */)
2457
+ if (target.kind === 226 /* SyntaxKind.PrefixUnaryExpression */ || target.kind === 227 /* SyntaxKind.PostfixUnaryExpression */)
2382
2458
  return 2 /* AssignmentKind.Compound */;
2383
2459
  return 1 /* AssignmentKind.Definite */;
2384
2460
  }
@@ -2387,7 +2463,7 @@ export function isInCompoundLikeAssignment(node) {
2387
2463
  if (target === undefined || !isAssignmentExpression(target, true))
2388
2464
  return false;
2389
2465
  const right = skipParentheses(target.right);
2390
- return (right.kind === 227 /* SyntaxKind.BinaryExpression */ &&
2466
+ return (right.kind === 228 /* SyntaxKind.BinaryExpression */ &&
2391
2467
  isShiftOperatorOrHigher(right.operatorToken.kind));
2392
2468
  }
2393
2469
  function isShiftOperatorOrHigher(kind) {
@@ -2417,9 +2493,9 @@ export function isParameterOrMutableLocalVariable(_c, symbol) {
2417
2493
  if (symbol.valueDeclaration === undefined)
2418
2494
  return false;
2419
2495
  const declaration = getRootDeclaration(symbol.valueDeclaration);
2420
- return (declaration.kind === 170 /* SyntaxKind.Parameter */ ||
2421
- (declaration.kind === 261 /* SyntaxKind.VariableDeclaration */ &&
2422
- (declaration.parent.kind === 300 /* SyntaxKind.CatchClause */ || isMutableLocalVariableDeclaration(declaration))));
2496
+ return (declaration.kind === 171 /* SyntaxKind.Parameter */ ||
2497
+ (declaration.kind === 262 /* SyntaxKind.VariableDeclaration */ &&
2498
+ (declaration.parent.kind === 301 /* SyntaxKind.CatchClause */ || isMutableLocalVariableDeclaration(declaration))));
2423
2499
  }
2424
2500
  export function isMutableLocalVariableDeclaration(declaration) {
2425
2501
  const list = declaration.parent;
@@ -2428,7 +2504,7 @@ export function isMutableLocalVariableDeclaration(declaration) {
2428
2504
  if ((getCombinedModifierFlags(declaration) & 32 /* ModifierFlags.Export */) !== 0)
2429
2505
  return false;
2430
2506
  const statement = list.parent;
2431
- return !(statement.kind === 244 /* SyntaxKind.VariableStatement */ && isGlobalSourceFile(statement.parent));
2507
+ return !(statement.kind === 245 /* SyntaxKind.VariableStatement */ && isGlobalSourceFile(statement.parent));
2432
2508
  }
2433
2509
  export function isSymbolAssigned(c, symbol) {
2434
2510
  ensureAssignmentsMarked(c, symbol);
@@ -2445,7 +2521,7 @@ export function isPastLastAssignment(c, symbol, location) {
2445
2521
  return pos === 0 || (location !== undefined && pos < location.pos);
2446
2522
  }
2447
2523
  function isFunctionOrSourceFile(node) {
2448
- return node.kind === 307 /* SyntaxKind.SourceFile */ || isFunctionLike(node);
2524
+ return node.kind === 308 /* SyntaxKind.SourceFile */ || isFunctionLike(node);
2449
2525
  }
2450
2526
  function findFunctionOrSourceFile(node) {
2451
2527
  let current = node;
@@ -2454,8 +2530,6 @@ function findFunctionOrSourceFile(node) {
2454
2530
  return current;
2455
2531
  }
2456
2532
  function ensureAssignmentsMarked(c, symbol) {
2457
- if (c.symbolLinks(symbol).lastAssignmentPos !== 0)
2458
- return;
2459
2533
  const parent = findFunctionOrSourceFile(symbol.valueDeclaration);
2460
2534
  if (parent === undefined)
2461
2535
  return;
@@ -2502,7 +2576,7 @@ export class AssignmentMarker extends NodeVisitor {
2502
2576
  links.hasDefiniteAssignment = true;
2503
2577
  return false;
2504
2578
  }
2505
- case 282 /* SyntaxKind.ExportSpecifier */: {
2579
+ case 283 /* SyntaxKind.ExportSpecifier */: {
2506
2580
  const specifier = node;
2507
2581
  const declaration = specifier.parent.parent;
2508
2582
  const name = specifier.propertyName ?? specifier.name;
@@ -2516,13 +2590,13 @@ export class AssignmentMarker extends NodeVisitor {
2516
2590
  }
2517
2591
  return false;
2518
2592
  }
2519
- case 265 /* SyntaxKind.InterfaceDeclaration */:
2520
- case 266 /* SyntaxKind.TypeAliasDeclaration */:
2521
- case 345 /* SyntaxKind.JSTypeAliasDeclaration */:
2522
- case 267 /* SyntaxKind.EnumDeclaration */:
2593
+ case 266 /* SyntaxKind.InterfaceDeclaration */:
2594
+ case 267 /* SyntaxKind.TypeAliasDeclaration */:
2595
+ case 346 /* SyntaxKind.JSTypeAliasDeclaration */:
2596
+ case 268 /* SyntaxKind.EnumDeclaration */:
2523
2597
  return false;
2524
2598
  }
2525
- if (node.kind >= 183 /* SyntaxKind.FirstTypeNode */ && node.kind <= 206 /* SyntaxKind.LastTypeNode */)
2599
+ if (node.kind >= 184 /* SyntaxKind.FirstTypeNode */ && node.kind <= 207 /* SyntaxKind.LastTypeNode */)
2526
2600
  return false;
2527
2601
  return node.forEachChild(this);
2528
2602
  }
@@ -2532,18 +2606,18 @@ function extendAssignmentPosition(nodeIn, declaration) {
2532
2606
  let pos = nodeIn.pos;
2533
2607
  while (node !== undefined && node.pos > declaration.pos) {
2534
2608
  switch (node.kind) {
2535
- case 244 /* SyntaxKind.VariableStatement */:
2536
- case 245 /* SyntaxKind.ExpressionStatement */:
2537
- case 246 /* SyntaxKind.IfStatement */:
2538
- case 247 /* SyntaxKind.DoStatement */:
2539
- case 248 /* SyntaxKind.WhileStatement */:
2540
- case 249 /* SyntaxKind.ForStatement */:
2541
- case 250 /* SyntaxKind.ForInStatement */:
2542
- case 251 /* SyntaxKind.ForOfStatement */:
2543
- case 255 /* SyntaxKind.WithStatement */:
2544
- case 256 /* SyntaxKind.SwitchStatement */:
2545
- case 259 /* SyntaxKind.TryStatement */:
2546
- case 264 /* SyntaxKind.ClassDeclaration */:
2609
+ case 245 /* SyntaxKind.VariableStatement */:
2610
+ case 246 /* SyntaxKind.ExpressionStatement */:
2611
+ case 247 /* SyntaxKind.IfStatement */:
2612
+ case 248 /* SyntaxKind.DoStatement */:
2613
+ case 249 /* SyntaxKind.WhileStatement */:
2614
+ case 250 /* SyntaxKind.ForStatement */:
2615
+ case 251 /* SyntaxKind.ForInStatement */:
2616
+ case 252 /* SyntaxKind.ForOfStatement */:
2617
+ case 256 /* SyntaxKind.WithStatement */:
2618
+ case 257 /* SyntaxKind.SwitchStatement */:
2619
+ case 260 /* SyntaxKind.TryStatement */:
2620
+ case 265 /* SyntaxKind.ClassDeclaration */:
2547
2621
  pos = node.end;
2548
2622
  }
2549
2623
  node = node.parent;
@@ -2555,9 +2629,9 @@ export function getControlFlowContainer(node) {
2555
2629
  let current = node.parent;
2556
2630
  for (;;) {
2557
2631
  if ((isFunctionLike(current) && getImmediatelyInvokedFunctionExpression(current) === undefined) ||
2558
- current.kind === 269 /* SyntaxKind.ModuleBlock */ ||
2559
- current.kind === 307 /* SyntaxKind.SourceFile */ ||
2560
- current.kind === 173 /* SyntaxKind.PropertyDeclaration */)
2632
+ current.kind === 270 /* SyntaxKind.ModuleBlock */ ||
2633
+ current.kind === 308 /* SyntaxKind.SourceFile */ ||
2634
+ current.kind === 174 /* SyntaxKind.PropertyDeclaration */)
2561
2635
  return current;
2562
2636
  current = current.parent;
2563
2637
  }
@@ -2567,7 +2641,7 @@ function getTypeAtFlowArrayMutation(c, f, flow) {
2567
2641
  if (f.declaredType !== c.autoType && f.declaredType !== c.autoArrayType)
2568
2642
  return undefined;
2569
2643
  const node = flow.node;
2570
- const expr = node.kind === 214 /* SyntaxKind.CallExpression */
2644
+ const expr = node.kind === 215 /* SyntaxKind.CallExpression */
2571
2645
  ? getExpression(getExpression(node))
2572
2646
  : getExpression(node.left);
2573
2647
  if (!isMatchingReference(c, f.reference, getReferenceCandidate(expr)))
@@ -2577,7 +2651,7 @@ function getTypeAtFlowArrayMutation(c, f, flow) {
2577
2651
  return flowType;
2578
2652
  const incomplete = f.incomplete;
2579
2653
  let evolvedType = flowType;
2580
- if (node.kind === 214 /* SyntaxKind.CallExpression */) {
2654
+ if (node.kind === 215 /* SyntaxKind.CallExpression */) {
2581
2655
  for (const arg of getArguments(node).nodes)
2582
2656
  evolvedType = addEvolvingArrayElementType(c, evolvedType, arg);
2583
2657
  }
@@ -2623,17 +2697,17 @@ function isEvolvingArrayTypeList(types) {
2623
2697
  export function isEvolvingArrayOperationTarget(c, node) {
2624
2698
  const root = getReferenceRoot(node);
2625
2699
  const parent = root.parent;
2626
- if (parent.kind === 212 /* SyntaxKind.PropertyAccessExpression */) {
2700
+ if (parent.kind === 213 /* SyntaxKind.PropertyAccessExpression */) {
2627
2701
  const name = parent.name;
2628
2702
  return (getText(name) === 'length' ||
2629
- (parent.parent.kind === 214 /* SyntaxKind.CallExpression */ &&
2703
+ (parent.parent.kind === 215 /* SyntaxKind.CallExpression */ &&
2630
2704
  name.kind === 79 /* SyntaxKind.Identifier */ &&
2631
2705
  isPushOrUnshiftIdentifier(name)));
2632
2706
  }
2633
- if (parent.kind !== 213 /* SyntaxKind.ElementAccessExpression */ || getExpression(parent) !== root)
2707
+ if (parent.kind !== 214 /* SyntaxKind.ElementAccessExpression */ || getExpression(parent) !== root)
2634
2708
  return false;
2635
2709
  const grandparent = parent.parent;
2636
- return (grandparent.kind === 227 /* SyntaxKind.BinaryExpression */ &&
2710
+ return (grandparent.kind === 228 /* SyntaxKind.BinaryExpression */ &&
2637
2711
  grandparent.operatorToken.kind === 63 /* SyntaxKind.EqualsToken */ &&
2638
2712
  grandparent.left === parent &&
2639
2713
  !isAssignmentTarget(grandparent) &&
@@ -2641,9 +2715,9 @@ export function isEvolvingArrayOperationTarget(c, node) {
2641
2715
  }
2642
2716
  function getReferenceRoot(node) {
2643
2717
  const parent = node.parent;
2644
- if (parent.kind === 218 /* SyntaxKind.ParenthesizedExpression */)
2718
+ if (parent.kind === 219 /* SyntaxKind.ParenthesizedExpression */)
2645
2719
  return getReferenceRoot(parent);
2646
- if (parent.kind === 227 /* SyntaxKind.BinaryExpression */) {
2720
+ if (parent.kind === 228 /* SyntaxKind.BinaryExpression */) {
2647
2721
  const binary = parent;
2648
2722
  if ((binary.operatorToken.kind === 63 /* SyntaxKind.EqualsToken */ && binary.left === node) ||
2649
2723
  (binary.operatorToken.kind === 27 /* SyntaxKind.CommaToken */ && binary.right === node))
@@ -2693,12 +2767,12 @@ function reportFlowControlError(c, node) {
2693
2767
  return;
2694
2768
  const file = getSourceFileOfNode(node);
2695
2769
  const span = getRangeOfTokenAtPosition(file, getStatements(block).pos);
2696
- c.addDiagnostic(new Diagnostic(file.diagnosticFile(), span.pos, span.end, 717 /* Diagnostics.The_containing_function_or_module_body_is_too_large_for_control_flow_analysis */, []));
2770
+ c.addDiagnostic(new Diagnostic(file.diagnosticFile(), span.pos, span.end, 724 /* Diagnostics.The_containing_function_or_module_body_is_too_large_for_control_flow_analysis */, []));
2697
2771
  }
2698
2772
  function isFunctionOrModuleBlock(node) {
2699
- return (node.kind === 307 /* SyntaxKind.SourceFile */ ||
2700
- node.kind === 269 /* SyntaxKind.ModuleBlock */ ||
2701
- (node.kind === 242 /* SyntaxKind.Block */ && node.parent !== undefined && isFunctionLike(node.parent)));
2773
+ return (node.kind === 308 /* SyntaxKind.SourceFile */ ||
2774
+ node.kind === 270 /* SyntaxKind.ModuleBlock */ ||
2775
+ (node.kind === 243 /* SyntaxKind.Block */ && node.parent !== undefined && isFunctionLike(node.parent)));
2702
2776
  }
2703
2777
  /**
2704
2778
  * The type of `symbol` at `location`. A destructured variable of a const declaration or unassigned
@@ -2709,13 +2783,13 @@ export function getNarrowedTypeOfSymbol(c, symbol, location) {
2709
2783
  const t = getTypeOfSymbol(c, symbol);
2710
2784
  const declaration = symbol.valueDeclaration;
2711
2785
  if (declaration !== undefined &&
2712
- declaration.kind === 170 /* SyntaxKind.Parameter */ &&
2786
+ declaration.kind === 171 /* SyntaxKind.Parameter */ &&
2713
2787
  getType(declaration) === undefined &&
2714
2788
  getInitializer(declaration) === undefined &&
2715
2789
  getDotDotDotToken(declaration) === undefined)
2716
2790
  return getNarrowedTypeOfDependentParameter(c, t, declaration, location);
2717
2791
  if (declaration === undefined ||
2718
- declaration.kind !== 209 /* SyntaxKind.BindingElement */ ||
2792
+ declaration.kind !== 210 /* SyntaxKind.BindingElement */ ||
2719
2793
  getInitializer(declaration) !== undefined ||
2720
2794
  declaration.dotDotDotToken !== undefined ||
2721
2795
  getElements(declaration.parent).nodes.length < 2)
@@ -2723,11 +2797,20 @@ export function getNarrowedTypeOfSymbol(c, symbol, location) {
2723
2797
  const pattern = declaration.parent;
2724
2798
  const parent = pattern.parent;
2725
2799
  const rootDeclaration = getRootDeclaration(parent);
2726
- const isParameter = rootDeclaration.kind === 170 /* SyntaxKind.Parameter */;
2800
+ const isParameter = rootDeclaration.kind === 171 /* SyntaxKind.Parameter */;
2727
2801
  if (!isParameter &&
2728
- !(rootDeclaration.kind === 261 /* SyntaxKind.VariableDeclaration */ &&
2802
+ !(rootDeclaration.kind === 262 /* SyntaxKind.VariableDeclaration */ &&
2729
2803
  (getCombinedNodeFlags(rootDeclaration) & 6 /* NodeFlags.Constant */) !== 0))
2730
2804
  return t;
2805
+ // A reference in the declaration's own initializer would need the declaration's type; defaults of
2806
+ // the binding elements and nested functions are narrowed.
2807
+ const rootInitializer = getInitializer(rootDeclaration);
2808
+ if (rootInitializer !== undefined &&
2809
+ location.pos >= rootInitializer.pos &&
2810
+ location.end <= rootInitializer.end &&
2811
+ isNodeDescendantOf(location, rootInitializer) &&
2812
+ getControlFlowContainer(declaration) === getControlFlowContainer(location))
2813
+ return t;
2731
2814
  const links = c.nodeLinks(parent);
2732
2815
  if ((links.flags & 4194304 /* NodeCheckFlags.InCheckIdentifier */) !== 0)
2733
2816
  return t;
@@ -2735,6 +2818,8 @@ export function getNarrowedTypeOfSymbol(c, symbol, location) {
2735
2818
  let result = t;
2736
2819
  const parentType = getTypeForBindingElementParent(c, parent, 0 /* CheckMode.Normal */);
2737
2820
  const parentTypeConstraint = parentType !== undefined ? mapToBaseConstraintOrType(c, parentType) : undefined;
2821
+ // Only the parent's type is guarded; flow analysis may narrow the binding elements again.
2822
+ links.flags &= ~4194304 /* NodeCheckFlags.InCheckIdentifier */;
2738
2823
  if (parentTypeConstraint !== undefined &&
2739
2824
  (parentTypeConstraint.flags & 134217728 /* TypeFlags.Union */) !== 0 &&
2740
2825
  !(isParameter && isSomeSymbolAssigned(c, getName(rootDeclaration)))) {
@@ -2745,7 +2830,6 @@ export function getNarrowedTypeOfSymbol(c, symbol, location) {
2745
2830
  ? c.neverType
2746
2831
  : getBindingElementTypeFromParentType(c, declaration, narrowedType, true);
2747
2832
  }
2748
- links.flags &= ~4194304 /* NodeCheckFlags.InCheckIdentifier */;
2749
2833
  return result;
2750
2834
  }
2751
2835
  /**