tsc-ts 0.0.4 → 0.0.5

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 (584) hide show
  1. package/README.md +33 -1
  2. package/dist/api/compiler/ast-utilities.d.ts +82 -0
  3. package/dist/api/compiler/ast-utilities.js +462 -0
  4. package/dist/api/compiler/ast.d.ts +2350 -0
  5. package/dist/api/compiler/ast.js +11206 -0
  6. package/dist/api/compiler/astnav.d.ts +37 -0
  7. package/dist/api/compiler/astnav.js +767 -0
  8. package/dist/api/compiler/binder-utilities.d.ts +182 -0
  9. package/dist/api/compiler/binder-utilities.js +1240 -0
  10. package/dist/api/compiler/binder.d.ts +33 -0
  11. package/dist/api/compiler/binder.js +2358 -0
  12. package/dist/api/compiler/character-codes.d.ts +161 -0
  13. package/dist/api/compiler/character-codes.js +160 -0
  14. package/dist/api/compiler/checker-calls.d.ts +46 -0
  15. package/dist/api/compiler/checker-calls.js +1640 -0
  16. package/dist/api/compiler/checker-classes.d.ts +30 -0
  17. package/dist/api/compiler/checker-classes.js +582 -0
  18. package/dist/api/compiler/checker-contextual.d.ts +77 -0
  19. package/dist/api/compiler/checker-contextual.js +1136 -0
  20. package/dist/api/compiler/checker-declaration-order.d.ts +12 -0
  21. package/dist/api/compiler/checker-declaration-order.js +356 -0
  22. package/dist/api/compiler/checker-declarations.d.ts +33 -0
  23. package/dist/api/compiler/checker-declarations.js +888 -0
  24. package/dist/api/compiler/checker-declared-types.d.ts +48 -0
  25. package/dist/api/compiler/checker-declared-types.js +787 -0
  26. package/dist/api/compiler/checker-decorators.d.ts +26 -0
  27. package/dist/api/compiler/checker-decorators.js +562 -0
  28. package/dist/api/compiler/checker-deprecation.d.ts +33 -0
  29. package/dist/api/compiler/checker-deprecation.js +315 -0
  30. package/dist/api/compiler/checker-destructuring.d.ts +34 -0
  31. package/dist/api/compiler/checker-destructuring.js +584 -0
  32. package/dist/api/compiler/checker-elaboration.d.ts +15 -0
  33. package/dist/api/compiler/checker-elaboration.js +290 -0
  34. package/dist/api/compiler/checker-emit-helpers.d.ts +58 -0
  35. package/dist/api/compiler/checker-emit-helpers.js +154 -0
  36. package/dist/api/compiler/checker-emit-resolver.d.ts +75 -0
  37. package/dist/api/compiler/checker-emit-resolver.js +579 -0
  38. package/dist/api/compiler/checker-evaluator.d.ts +27 -0
  39. package/dist/api/compiler/checker-evaluator.js +188 -0
  40. package/dist/api/compiler/checker-expressions.d.ts +67 -0
  41. package/dist/api/compiler/checker-expressions.js +1351 -0
  42. package/dist/api/compiler/checker-features.d.ts +6 -0
  43. package/dist/api/compiler/checker-features.js +354 -0
  44. package/dist/api/compiler/checker-flow.d.ts +86 -0
  45. package/dist/api/compiler/checker-flow.js +169 -0
  46. package/dist/api/compiler/checker-functions.d.ts +43 -0
  47. package/dist/api/compiler/checker-functions.js +1002 -0
  48. package/dist/api/compiler/checker-generated-code.d.ts +25 -0
  49. package/dist/api/compiler/checker-generated-code.js +168 -0
  50. package/dist/api/compiler/checker-globals.d.ts +14 -0
  51. package/dist/api/compiler/checker-globals.js +37 -0
  52. package/dist/api/compiler/checker-grammar.d.ts +35 -0
  53. package/dist/api/compiler/checker-grammar.js +2573 -0
  54. package/dist/api/compiler/checker-heritage.d.ts +28 -0
  55. package/dist/api/compiler/checker-heritage.js +900 -0
  56. package/dist/api/compiler/checker-inference.d.ts +179 -0
  57. package/dist/api/compiler/checker-inference.js +2105 -0
  58. package/dist/api/compiler/checker-iteration.d.ts +115 -0
  59. package/dist/api/compiler/checker-iteration.js +857 -0
  60. package/dist/api/compiler/checker-javascript.d.ts +42 -0
  61. package/dist/api/compiler/checker-javascript.js +441 -0
  62. package/dist/api/compiler/checker-jsdoc.d.ts +30 -0
  63. package/dist/api/compiler/checker-jsdoc.js +320 -0
  64. package/dist/api/compiler/checker-jsx.d.ts +94 -0
  65. package/dist/api/compiler/checker-jsx.js +1433 -0
  66. package/dist/api/compiler/checker-literals.d.ts +6 -0
  67. package/dist/api/compiler/checker-literals.js +43 -0
  68. package/dist/api/compiler/checker-members.d.ts +198 -0
  69. package/dist/api/compiler/checker-members.js +2126 -0
  70. package/dist/api/compiler/checker-modules.d.ts +85 -0
  71. package/dist/api/compiler/checker-modules.js +2141 -0
  72. package/dist/api/compiler/checker-narrowing.d.ts +120 -0
  73. package/dist/api/compiler/checker-narrowing.js +2797 -0
  74. package/dist/api/compiler/checker-object-literals.d.ts +14 -0
  75. package/dist/api/compiler/checker-object-literals.js +479 -0
  76. package/dist/api/compiler/checker-operators.d.ts +33 -0
  77. package/dist/api/compiler/checker-operators.js +1040 -0
  78. package/dist/api/compiler/checker-overloads.d.ts +7 -0
  79. package/dist/api/compiler/checker-overloads.js +270 -0
  80. package/dist/api/compiler/checker-property-access.d.ts +34 -0
  81. package/dist/api/compiler/checker-property-access.js +672 -0
  82. package/dist/api/compiler/checker-services.d.ts +49 -0
  83. package/dist/api/compiler/checker-services.js +995 -0
  84. package/dist/api/compiler/checker-signatures.d.ts +55 -0
  85. package/dist/api/compiler/checker-signatures.js +788 -0
  86. package/dist/api/compiler/checker-source-file.d.ts +27 -0
  87. package/dist/api/compiler/checker-source-file.js +619 -0
  88. package/dist/api/compiler/checker-statements.d.ts +18 -0
  89. package/dist/api/compiler/checker-statements.js +226 -0
  90. package/dist/api/compiler/checker-super.d.ts +13 -0
  91. package/dist/api/compiler/checker-super.js +241 -0
  92. package/dist/api/compiler/checker-symbol-types.d.ts +67 -0
  93. package/dist/api/compiler/checker-symbol-types.js +1885 -0
  94. package/dist/api/compiler/checker-symbols.d.ts +181 -0
  95. package/dist/api/compiler/checker-symbols.js +1782 -0
  96. package/dist/api/compiler/checker-type-factory.d.ts +142 -0
  97. package/dist/api/compiler/checker-type-factory.js +2501 -0
  98. package/dist/api/compiler/checker-type-nodes.d.ts +26 -0
  99. package/dist/api/compiler/checker-type-nodes.js +828 -0
  100. package/dist/api/compiler/checker-type-operators.d.ts +109 -0
  101. package/dist/api/compiler/checker-type-operators.js +1842 -0
  102. package/dist/api/compiler/checker-types.d.ts +1027 -0
  103. package/dist/api/compiler/checker-types.js +1697 -0
  104. package/dist/api/compiler/checker-unused.d.ts +19 -0
  105. package/dist/api/compiler/checker-unused.js +524 -0
  106. package/dist/api/compiler/checker-utilities.d.ts +33 -0
  107. package/dist/api/compiler/checker-utilities.js +141 -0
  108. package/dist/api/compiler/checker.d.ts +491 -0
  109. package/dist/api/compiler/checker.js +912 -0
  110. package/dist/api/compiler/command-line.d.ts +32 -0
  111. package/dist/api/compiler/command-line.js +383 -0
  112. package/dist/api/compiler/compile-program.d.ts +118 -0
  113. package/dist/api/compiler/compile-program.js +384 -0
  114. package/dist/api/compiler/diagnostic-locales.d.ts +22 -0
  115. package/dist/api/compiler/diagnostic-locales.js +64 -0
  116. package/dist/api/compiler/diagnostic-messages.d.ts +2166 -0
  117. package/dist/api/compiler/diagnostic-messages.js +184 -0
  118. package/dist/api/compiler/diagnostics.d.ts +167 -0
  119. package/dist/api/compiler/diagnostics.js +820 -0
  120. package/dist/api/compiler/emitter.d.ts +71 -0
  121. package/dist/api/compiler/emitter.js +327 -0
  122. package/dist/api/compiler/file-include.d.ts +117 -0
  123. package/dist/api/compiler/file-include.js +536 -0
  124. package/dist/api/compiler/file-loader.d.ts +261 -0
  125. package/dist/api/compiler/file-loader.js +1257 -0
  126. package/dist/api/compiler/file-system.d.ts +51 -0
  127. package/dist/api/compiler/file-system.js +132 -0
  128. package/dist/api/compiler/flow.d.ts +60 -0
  129. package/dist/api/compiler/flow.js +45 -0
  130. package/dist/api/compiler/instantiation.d.ts +74 -0
  131. package/dist/api/compiler/instantiation.js +799 -0
  132. package/dist/api/compiler/jsdoc.d.ts +75 -0
  133. package/dist/api/compiler/jsdoc.js +1229 -0
  134. package/dist/api/compiler/link-tables.d.ts +36 -0
  135. package/dist/api/compiler/link-tables.js +83 -0
  136. package/dist/api/compiler/locale-data.d.ts +24 -0
  137. package/dist/api/compiler/locale-data.js +183 -0
  138. package/dist/api/compiler/locale.d.ts +4 -0
  139. package/dist/api/compiler/locale.js +317 -0
  140. package/dist/api/compiler/locales/cs-CZ.d.ts +2 -0
  141. package/dist/api/compiler/locales/cs-CZ.js +3 -0
  142. package/dist/api/compiler/locales/de-DE.d.ts +2 -0
  143. package/dist/api/compiler/locales/de-DE.js +3 -0
  144. package/dist/api/compiler/locales/es-ES.d.ts +2 -0
  145. package/dist/api/compiler/locales/es-ES.js +3 -0
  146. package/dist/api/compiler/locales/fr-FR.d.ts +2 -0
  147. package/dist/api/compiler/locales/fr-FR.js +3 -0
  148. package/dist/api/compiler/locales/it-IT.d.ts +2 -0
  149. package/dist/api/compiler/locales/it-IT.js +3 -0
  150. package/dist/api/compiler/locales/ja-JP.d.ts +2 -0
  151. package/dist/api/compiler/locales/ja-JP.js +3 -0
  152. package/dist/api/compiler/locales/ko-KR.d.ts +2 -0
  153. package/dist/api/compiler/locales/ko-KR.js +3 -0
  154. package/dist/api/compiler/locales/pl-PL.d.ts +2 -0
  155. package/dist/api/compiler/locales/pl-PL.js +3 -0
  156. package/dist/api/compiler/locales/pt-BR.d.ts +2 -0
  157. package/dist/api/compiler/locales/pt-BR.js +3 -0
  158. package/dist/api/compiler/locales/ru-RU.d.ts +2 -0
  159. package/dist/api/compiler/locales/ru-RU.js +3 -0
  160. package/dist/api/compiler/locales/tr-TR.d.ts +2 -0
  161. package/dist/api/compiler/locales/tr-TR.js +3 -0
  162. package/dist/api/compiler/locales/zh-CN.d.ts +2 -0
  163. package/dist/api/compiler/locales/zh-CN.js +3 -0
  164. package/dist/api/compiler/locales/zh-TW.d.ts +2 -0
  165. package/dist/api/compiler/locales/zh-TW.js +3 -0
  166. package/dist/api/compiler/module-resolution-types.d.ts +83 -0
  167. package/dist/api/compiler/module-resolution-types.js +176 -0
  168. package/dist/api/compiler/module-resolution.d.ts +71 -0
  169. package/dist/api/compiler/module-resolution.js +1598 -0
  170. package/dist/api/compiler/module-specifiers.d.ts +64 -0
  171. package/dist/api/compiler/module-specifiers.js +1101 -0
  172. package/dist/api/compiler/name-resolver.d.ts +43 -0
  173. package/dist/api/compiler/name-resolver.js +509 -0
  174. package/dist/api/compiler/node-builder-names.d.ts +32 -0
  175. package/dist/api/compiler/node-builder-names.js +854 -0
  176. package/dist/api/compiler/node-builder-pseudo.d.ts +36 -0
  177. package/dist/api/compiler/node-builder-pseudo.js +744 -0
  178. package/dist/api/compiler/node-builder-reuse.d.ts +4 -0
  179. package/dist/api/compiler/node-builder-reuse.js +647 -0
  180. package/dist/api/compiler/node-builder.d.ts +270 -0
  181. package/dist/api/compiler/node-builder.js +2645 -0
  182. package/dist/api/compiler/option-declarations.d.ts +90 -0
  183. package/dist/api/compiler/option-declarations.js +1460 -0
  184. package/dist/api/compiler/options.d.ts +289 -0
  185. package/dist/api/compiler/options.js +1197 -0
  186. package/dist/api/compiler/output-paths.d.ts +42 -0
  187. package/dist/api/compiler/output-paths.js +195 -0
  188. package/dist/api/compiler/package-json.d.ts +175 -0
  189. package/dist/api/compiler/package-json.js +1015 -0
  190. package/dist/api/compiler/parallel-parse.d.ts +219 -0
  191. package/dist/api/compiler/parallel-parse.js +537 -0
  192. package/dist/api/compiler/parser.d.ts +587 -0
  193. package/dist/api/compiler/parser.js +6407 -0
  194. package/dist/api/compiler/path.d.ts +91 -0
  195. package/dist/api/compiler/path.js +705 -0
  196. package/dist/api/compiler/printer/async-helpers.d.ts +22 -0
  197. package/dist/api/compiler/printer/async-helpers.js +91 -0
  198. package/dist/api/compiler/printer/auto-generate.d.ts +13 -0
  199. package/dist/api/compiler/printer/auto-generate.js +20 -0
  200. package/dist/api/compiler/printer/decorator-helpers.d.ts +24 -0
  201. package/dist/api/compiler/printer/decorator-helpers.js +118 -0
  202. package/dist/api/compiler/printer/emit-context.d.ts +154 -0
  203. package/dist/api/compiler/printer/emit-context.js +576 -0
  204. package/dist/api/compiler/printer/emit-flags.d.ts +60 -0
  205. package/dist/api/compiler/printer/emit-flags.js +2 -0
  206. package/dist/api/compiler/printer/factory-base.d.ts +171 -0
  207. package/dist/api/compiler/printer/factory-base.js +1505 -0
  208. package/dist/api/compiler/printer/factory.d.ts +147 -0
  209. package/dist/api/compiler/printer/factory.js +542 -0
  210. package/dist/api/compiler/printer/helpers.d.ts +27 -0
  211. package/dist/api/compiler/printer/helpers.js +164 -0
  212. package/dist/api/compiler/printer/name-generator.d.ts +41 -0
  213. package/dist/api/compiler/printer/name-generator.js +283 -0
  214. package/dist/api/compiler/printer/printer.d.ts +411 -0
  215. package/dist/api/compiler/printer/printer.js +4517 -0
  216. package/dist/api/compiler/printer/text-writer.d.ts +46 -0
  217. package/dist/api/compiler/printer/text-writer.js +172 -0
  218. package/dist/api/compiler/printer/utilities.d.ts +82 -0
  219. package/dist/api/compiler/printer/utilities.js +817 -0
  220. package/dist/api/compiler/program-checker.d.ts +156 -0
  221. package/dist/api/compiler/program-checker.js +526 -0
  222. package/dist/api/compiler/program-utilities.d.ts +52 -0
  223. package/dist/api/compiler/program-utilities.js +365 -0
  224. package/dist/api/compiler/program.d.ts +180 -0
  225. package/dist/api/compiler/program.js +1011 -0
  226. package/dist/api/compiler/pseudo-bigint.d.ts +5 -0
  227. package/dist/api/compiler/pseudo-bigint.js +61 -0
  228. package/dist/api/compiler/regexp-checker.d.ts +38 -0
  229. package/dist/api/compiler/regexp-checker.js +942 -0
  230. package/dist/api/compiler/relations.d.ts +263 -0
  231. package/dist/api/compiler/relations.js +4002 -0
  232. package/dist/api/compiler/reparser.d.ts +48 -0
  233. package/dist/api/compiler/reparser.js +1323 -0
  234. package/dist/api/compiler/scanner.d.ts +256 -0
  235. package/dist/api/compiler/scanner.js +2853 -0
  236. package/dist/api/compiler/side-state.d.ts +16 -0
  237. package/dist/api/compiler/side-state.js +89 -0
  238. package/dist/api/compiler/sourcemap.d.ts +55 -0
  239. package/dist/api/compiler/sourcemap.js +340 -0
  240. package/dist/api/compiler/spelling.d.ts +14 -0
  241. package/dist/api/compiler/spelling.js +128 -0
  242. package/dist/api/compiler/symbol-accessibility.d.ts +57 -0
  243. package/dist/api/compiler/symbol-accessibility.js +894 -0
  244. package/dist/api/compiler/symbol.d.ts +240 -0
  245. package/dist/api/compiler/symbol.js +228 -0
  246. package/dist/api/compiler/symlinks.d.ts +32 -0
  247. package/dist/api/compiler/symlinks.js +114 -0
  248. package/dist/api/compiler/syntax-kind.d.ts +389 -0
  249. package/dist/api/compiler/syntax-kind.js +2 -0
  250. package/dist/api/compiler/timeline.d.ts +9 -0
  251. package/dist/api/compiler/timeline.js +54 -0
  252. package/dist/api/compiler/transformers/alias-references.d.ts +39 -0
  253. package/dist/api/compiler/transformers/alias-references.js +676 -0
  254. package/dist/api/compiler/transformers/async-utilities.d.ts +51 -0
  255. package/dist/api/compiler/transformers/async-utilities.js +260 -0
  256. package/dist/api/compiler/transformers/async.d.ts +53 -0
  257. package/dist/api/compiler/transformers/async.js +645 -0
  258. package/dist/api/compiler/transformers/class-fields.d.ts +206 -0
  259. package/dist/api/compiler/transformers/class-fields.js +2418 -0
  260. package/dist/api/compiler/transformers/class-utilities.d.ts +46 -0
  261. package/dist/api/compiler/transformers/class-utilities.js +261 -0
  262. package/dist/api/compiler/transformers/commonjs-module.d.ts +103 -0
  263. package/dist/api/compiler/transformers/commonjs-module.js +1180 -0
  264. package/dist/api/compiler/transformers/const-enum-inliner.d.ts +11 -0
  265. package/dist/api/compiler/transformers/const-enum-inliner.js +36 -0
  266. package/dist/api/compiler/transformers/declarations-diagnostics.d.ts +52 -0
  267. package/dist/api/compiler/transformers/declarations-diagnostics.js +538 -0
  268. package/dist/api/compiler/transformers/declarations-pseudo.d.ts +160 -0
  269. package/dist/api/compiler/transformers/declarations-pseudo.js +797 -0
  270. package/dist/api/compiler/transformers/declarations-resolver.d.ts +152 -0
  271. package/dist/api/compiler/transformers/declarations-resolver.js +35 -0
  272. package/dist/api/compiler/transformers/declarations-syntactic.d.ts +119 -0
  273. package/dist/api/compiler/transformers/declarations-syntactic.js +1582 -0
  274. package/dist/api/compiler/transformers/declarations-tracker.d.ts +46 -0
  275. package/dist/api/compiler/transformers/declarations-tracker.js +197 -0
  276. package/dist/api/compiler/transformers/declarations.d.ts +175 -0
  277. package/dist/api/compiler/transformers/declarations.js +2380 -0
  278. package/dist/api/compiler/transformers/decorator-metadata.d.ts +54 -0
  279. package/dist/api/compiler/transformers/decorator-metadata.js +554 -0
  280. package/dist/api/compiler/transformers/decorator-utilities.d.ts +38 -0
  281. package/dist/api/compiler/transformers/decorator-utilities.js +238 -0
  282. package/dist/api/compiler/transformers/destructuring.d.ts +25 -0
  283. package/dist/api/compiler/transformers/destructuring.js +626 -0
  284. package/dist/api/compiler/transformers/downlevel.d.ts +6 -0
  285. package/dist/api/compiler/transformers/downlevel.js +45 -0
  286. package/dist/api/compiler/transformers/emit-resolver.d.ts +61 -0
  287. package/dist/api/compiler/transformers/emit-resolver.js +197 -0
  288. package/dist/api/compiler/transformers/es-decorators.d.ts +118 -0
  289. package/dist/api/compiler/transformers/es-decorators.js +1901 -0
  290. package/dist/api/compiler/transformers/exponentiation.d.ts +11 -0
  291. package/dist/api/compiler/transformers/exponentiation.js +76 -0
  292. package/dist/api/compiler/transformers/external-module-info.d.ts +35 -0
  293. package/dist/api/compiler/transformers/external-module-info.js +351 -0
  294. package/dist/api/compiler/transformers/for-await.d.ts +43 -0
  295. package/dist/api/compiler/transformers/for-await.js +469 -0
  296. package/dist/api/compiler/transformers/import-elision.d.ts +16 -0
  297. package/dist/api/compiler/transformers/import-elision.js +124 -0
  298. package/dist/api/compiler/transformers/jsx-entities.d.ts +1 -0
  299. package/dist/api/compiler/transformers/jsx-entities.js +256 -0
  300. package/dist/api/compiler/transformers/jsx.d.ts +71 -0
  301. package/dist/api/compiler/transformers/jsx.js +700 -0
  302. package/dist/api/compiler/transformers/legacy-decorators.d.ts +56 -0
  303. package/dist/api/compiler/transformers/legacy-decorators.js +564 -0
  304. package/dist/api/compiler/transformers/logical-assignment.d.ts +14 -0
  305. package/dist/api/compiler/transformers/logical-assignment.js +62 -0
  306. package/dist/api/compiler/transformers/module-utilities.d.ts +9 -0
  307. package/dist/api/compiler/transformers/module-utilities.js +36 -0
  308. package/dist/api/compiler/transformers/module.d.ts +49 -0
  309. package/dist/api/compiler/transformers/module.js +296 -0
  310. package/dist/api/compiler/transformers/named-evaluation.d.ts +26 -0
  311. package/dist/api/compiler/transformers/named-evaluation.js +266 -0
  312. package/dist/api/compiler/transformers/nullish-coalescing.d.ts +9 -0
  313. package/dist/api/compiler/transformers/nullish-coalescing.js +26 -0
  314. package/dist/api/compiler/transformers/object-rest-spread.d.ts +34 -0
  315. package/dist/api/compiler/transformers/object-rest-spread.js +411 -0
  316. package/dist/api/compiler/transformers/optional-catch.d.ts +9 -0
  317. package/dist/api/compiler/transformers/optional-catch.js +20 -0
  318. package/dist/api/compiler/transformers/optional-chain.d.ts +14 -0
  319. package/dist/api/compiler/transformers/optional-chain.js +188 -0
  320. package/dist/api/compiler/transformers/reference-resolver.d.ts +128 -0
  321. package/dist/api/compiler/transformers/reference-resolver.js +1155 -0
  322. package/dist/api/compiler/transformers/runtime-syntax.d.ts +71 -0
  323. package/dist/api/compiler/transformers/runtime-syntax.js +753 -0
  324. package/dist/api/compiler/transformers/subtree-facts.d.ts +9 -0
  325. package/dist/api/compiler/transformers/subtree-facts.js +203 -0
  326. package/dist/api/compiler/transformers/syntax-facts.d.ts +51 -0
  327. package/dist/api/compiler/transformers/syntax-facts.js +254 -0
  328. package/dist/api/compiler/transformers/tagged-template.d.ts +17 -0
  329. package/dist/api/compiler/transformers/tagged-template.js +148 -0
  330. package/dist/api/compiler/transformers/transformer.d.ts +17 -0
  331. package/dist/api/compiler/transformers/transformer.js +54 -0
  332. package/dist/api/compiler/transformers/type-eraser.d.ts +21 -0
  333. package/dist/api/compiler/transformers/type-eraser.js +346 -0
  334. package/dist/api/compiler/transformers/type-serialization.d.ts +20 -0
  335. package/dist/api/compiler/transformers/type-serialization.js +347 -0
  336. package/dist/api/compiler/transformers/using.d.ts +56 -0
  337. package/dist/api/compiler/transformers/using.js +453 -0
  338. package/dist/api/compiler/transformers/utilities.d.ts +50 -0
  339. package/dist/api/compiler/transformers/utilities.js +347 -0
  340. package/dist/api/compiler/transformers/visitor-base.d.ts +6 -0
  341. package/dist/api/compiler/transformers/visitor-base.js +817 -0
  342. package/dist/api/compiler/transformers/visitor-hooks.d.ts +29 -0
  343. package/dist/api/compiler/transformers/visitor-hooks.js +189 -0
  344. package/dist/api/compiler/tsconfig.d.ts +177 -0
  345. package/dist/api/compiler/tsconfig.js +1311 -0
  346. package/dist/api/compiler/type-printer.d.ts +15 -0
  347. package/dist/api/compiler/type-printer.js +74 -0
  348. package/dist/api/compiler/types.d.ts +87 -0
  349. package/dist/api/compiler/types.js +23 -0
  350. package/dist/api/compiler/unicode-identifiers.d.ts +2 -0
  351. package/dist/api/compiler/unicode-identifiers.js +209 -0
  352. package/dist/api/compiler/unicode-properties.d.ts +8 -0
  353. package/dist/api/compiler/unicode-properties.js +531 -0
  354. package/dist/api/compiler/vfs-match.d.ts +24 -0
  355. package/dist/api/compiler/vfs-match.js +587 -0
  356. package/dist/api/library/ast.d.ts +3 -2
  357. package/dist/api/library/ast.generated.d.ts +127 -139
  358. package/dist/api/library/checker.d.ts +51 -0
  359. package/dist/api/library/checker.js +318 -0
  360. package/dist/api/library/diagnostics.d.ts +13 -0
  361. package/dist/api/library/diagnostics.js +50 -0
  362. package/dist/api/library/disk.d.ts +13 -0
  363. package/dist/api/library/disk.js +66 -0
  364. package/dist/api/library/errors.d.ts +13 -0
  365. package/dist/api/library/errors.js +24 -0
  366. package/dist/api/library/host.d.ts +24 -0
  367. package/dist/api/library/host.js +52 -0
  368. package/dist/api/library/index.d.ts +5 -1
  369. package/dist/api/library/index.js +4 -0
  370. package/dist/api/library/nodes.d.ts +51 -0
  371. package/dist/api/library/nodes.js +196 -0
  372. package/dist/api/library/options.d.ts +144 -0
  373. package/dist/api/library/options.js +308 -0
  374. package/dist/api/library/parse.d.ts +19 -0
  375. package/dist/api/library/parse.js +41 -0
  376. package/dist/api/library/program.d.ts +21 -0
  377. package/dist/api/library/program.js +234 -0
  378. package/dist/api/library/types.d.ts +14 -1
  379. package/package.json +12 -8
  380. package/src/compiler/ast-utilities.ts +548 -0
  381. package/src/compiler/ast.ts +12862 -0
  382. package/src/compiler/astnav.ts +799 -0
  383. package/src/compiler/binder-utilities.ts +1392 -0
  384. package/src/compiler/binder.ts +2703 -0
  385. package/src/compiler/build-info.ts +1197 -0
  386. package/src/compiler/character-codes.ts +323 -0
  387. package/src/compiler/checker-calls.ts +2155 -0
  388. package/src/compiler/checker-classes.ts +706 -0
  389. package/src/compiler/checker-contextual.ts +1457 -0
  390. package/src/compiler/checker-declaration-order.ts +438 -0
  391. package/src/compiler/checker-declarations.ts +1194 -0
  392. package/src/compiler/checker-declared-types.ts +919 -0
  393. package/src/compiler/checker-decorators.ts +694 -0
  394. package/src/compiler/checker-deprecation.ts +359 -0
  395. package/src/compiler/checker-destructuring.ts +805 -0
  396. package/src/compiler/checker-elaboration.ts +477 -0
  397. package/src/compiler/checker-emit-helpers.ts +224 -0
  398. package/src/compiler/checker-emit-resolver.ts +769 -0
  399. package/src/compiler/checker-evaluator.ts +243 -0
  400. package/src/compiler/checker-expressions.ts +1831 -0
  401. package/src/compiler/checker-features.ts +361 -0
  402. package/src/compiler/checker-flow.ts +394 -0
  403. package/src/compiler/checker-functions.ts +1296 -0
  404. package/src/compiler/checker-generated-code.ts +227 -0
  405. package/src/compiler/checker-globals.ts +52 -0
  406. package/src/compiler/checker-grammar.ts +3584 -0
  407. package/src/compiler/checker-heritage.ts +1233 -0
  408. package/src/compiler/checker-inference.ts +2576 -0
  409. package/src/compiler/checker-iteration.ts +1206 -0
  410. package/src/compiler/checker-javascript.ts +502 -0
  411. package/src/compiler/checker-jsdoc.ts +360 -0
  412. package/src/compiler/checker-jsx.ts +1924 -0
  413. package/src/compiler/checker-literals.ts +61 -0
  414. package/src/compiler/checker-members.ts +2436 -0
  415. package/src/compiler/checker-modules.ts +2886 -0
  416. package/src/compiler/checker-narrowing.ts +3230 -0
  417. package/src/compiler/checker-object-literals.ts +575 -0
  418. package/src/compiler/checker-operators.ts +1422 -0
  419. package/src/compiler/checker-overloads.ts +328 -0
  420. package/src/compiler/checker-property-access.ts +906 -0
  421. package/src/compiler/checker-services.ts +1149 -0
  422. package/src/compiler/checker-signatures.ts +1032 -0
  423. package/src/compiler/checker-source-file.ts +732 -0
  424. package/src/compiler/checker-statements.ts +292 -0
  425. package/src/compiler/checker-super.ts +261 -0
  426. package/src/compiler/checker-symbol-types.ts +2107 -0
  427. package/src/compiler/checker-symbols.ts +2150 -0
  428. package/src/compiler/checker-type-factory.ts +2579 -0
  429. package/src/compiler/checker-type-nodes.ts +1033 -0
  430. package/src/compiler/checker-type-operators.ts +2502 -0
  431. package/src/compiler/checker-types.ts +2340 -0
  432. package/src/compiler/checker-unused.ts +642 -0
  433. package/src/compiler/checker-utilities.ts +161 -0
  434. package/src/compiler/checker.ts +1116 -0
  435. package/src/compiler/command-line.ts +436 -0
  436. package/src/compiler/compile-program.ts +439 -0
  437. package/src/compiler/decoder.ts +1209 -0
  438. package/src/compiler/diagnostic-locales.ts +86 -0
  439. package/src/compiler/diagnostic-messages.ts +2349 -0
  440. package/src/compiler/diagnostics.ts +897 -0
  441. package/src/compiler/emitter.ts +434 -0
  442. package/src/compiler/encoder.ts +1945 -0
  443. package/src/compiler/file-include.ts +673 -0
  444. package/src/compiler/file-loader.ts +1528 -0
  445. package/src/compiler/file-system.ts +143 -0
  446. package/src/compiler/flow.ts +89 -0
  447. package/src/compiler/help.ts +473 -0
  448. package/src/compiler/incremental.ts +2784 -0
  449. package/src/compiler/init.ts +141 -0
  450. package/src/compiler/instantiation.ts +894 -0
  451. package/src/compiler/jsdoc.ts +1386 -0
  452. package/src/compiler/link-tables.ts +98 -0
  453. package/src/compiler/locale-data.ts +203 -0
  454. package/src/compiler/locale.ts +307 -0
  455. package/src/compiler/locales/cs-CZ.ts +5 -0
  456. package/src/compiler/locales/de-DE.ts +5 -0
  457. package/src/compiler/locales/es-ES.ts +5 -0
  458. package/src/compiler/locales/fr-FR.ts +5 -0
  459. package/src/compiler/locales/it-IT.ts +5 -0
  460. package/src/compiler/locales/ja-JP.ts +5 -0
  461. package/src/compiler/locales/ko-KR.ts +5 -0
  462. package/src/compiler/locales/pl-PL.ts +5 -0
  463. package/src/compiler/locales/pt-BR.ts +5 -0
  464. package/src/compiler/locales/ru-RU.ts +5 -0
  465. package/src/compiler/locales/tr-TR.ts +5 -0
  466. package/src/compiler/locales/zh-CN.ts +5 -0
  467. package/src/compiler/locales/zh-TW.ts +5 -0
  468. package/src/compiler/module-resolution-types.ts +243 -0
  469. package/src/compiler/module-resolution.ts +2072 -0
  470. package/src/compiler/module-specifiers.ts +1491 -0
  471. package/src/compiler/name-resolver.ts +646 -0
  472. package/src/compiler/node-builder-names.ts +1069 -0
  473. package/src/compiler/node-builder-pseudo.ts +892 -0
  474. package/src/compiler/node-builder-reuse.ts +764 -0
  475. package/src/compiler/node-builder.ts +3425 -0
  476. package/src/compiler/option-declarations.ts +1560 -0
  477. package/src/compiler/options.ts +1576 -0
  478. package/src/compiler/output-paths.ts +334 -0
  479. package/src/compiler/package-json.ts +1083 -0
  480. package/src/compiler/parallel-check.ts +1951 -0
  481. package/src/compiler/parallel-parse.ts +590 -0
  482. package/src/compiler/parse-thread.ts +140 -0
  483. package/src/compiler/parser.ts +7716 -0
  484. package/src/compiler/path.ts +717 -0
  485. package/src/compiler/printer/async-helpers.ts +183 -0
  486. package/src/compiler/printer/auto-generate.ts +27 -0
  487. package/src/compiler/printer/decorator-helpers.ts +218 -0
  488. package/src/compiler/printer/emit-context.ts +679 -0
  489. package/src/compiler/printer/emit-flags.ts +64 -0
  490. package/src/compiler/printer/factory-base.ts +2577 -0
  491. package/src/compiler/printer/factory.ts +764 -0
  492. package/src/compiler/printer/helpers.ts +291 -0
  493. package/src/compiler/printer/name-generator.ts +372 -0
  494. package/src/compiler/printer/printer.ts +5072 -0
  495. package/src/compiler/printer/text-writer.ts +183 -0
  496. package/src/compiler/printer/utilities.ts +884 -0
  497. package/src/compiler/program-checker.ts +592 -0
  498. package/src/compiler/program-utilities.ts +435 -0
  499. package/src/compiler/program.ts +1419 -0
  500. package/src/compiler/pseudo-bigint.ts +62 -0
  501. package/src/compiler/regexp-checker.ts +1142 -0
  502. package/src/compiler/relations.ts +5149 -0
  503. package/src/compiler/reparser.ts +1566 -0
  504. package/src/compiler/scanner.ts +2951 -0
  505. package/src/compiler/show-config.ts +239 -0
  506. package/src/compiler/side-state.ts +125 -0
  507. package/src/compiler/sourcemap.ts +366 -0
  508. package/src/compiler/spelling.ts +122 -0
  509. package/src/compiler/symbol-accessibility.ts +1071 -0
  510. package/src/compiler/symbol.ts +439 -0
  511. package/src/compiler/symlinks.ts +137 -0
  512. package/src/compiler/syntax-kind.ts +391 -0
  513. package/src/compiler/thread-entry.ts +191 -0
  514. package/src/compiler/timeline.ts +53 -0
  515. package/src/compiler/transformers/alias-references.ts +757 -0
  516. package/src/compiler/transformers/async-utilities.ts +335 -0
  517. package/src/compiler/transformers/async.ts +838 -0
  518. package/src/compiler/transformers/class-fields.ts +2967 -0
  519. package/src/compiler/transformers/class-utilities.ts +324 -0
  520. package/src/compiler/transformers/commonjs-module.ts +1621 -0
  521. package/src/compiler/transformers/const-enum-inliner.ts +50 -0
  522. package/src/compiler/transformers/declarations-diagnostics.ts +832 -0
  523. package/src/compiler/transformers/declarations-pseudo.ts +966 -0
  524. package/src/compiler/transformers/declarations-resolver.ts +249 -0
  525. package/src/compiler/transformers/declarations-syntactic.ts +1859 -0
  526. package/src/compiler/transformers/declarations-tracker.ts +269 -0
  527. package/src/compiler/transformers/declarations.ts +3120 -0
  528. package/src/compiler/transformers/decorator-metadata.ts +697 -0
  529. package/src/compiler/transformers/decorator-utilities.ts +283 -0
  530. package/src/compiler/transformers/destructuring.ts +708 -0
  531. package/src/compiler/transformers/downlevel.ts +50 -0
  532. package/src/compiler/transformers/emit-resolver.ts +258 -0
  533. package/src/compiler/transformers/es-decorators.ts +2682 -0
  534. package/src/compiler/transformers/exponentiation.ts +80 -0
  535. package/src/compiler/transformers/external-module-info.ts +412 -0
  536. package/src/compiler/transformers/for-await.ts +687 -0
  537. package/src/compiler/transformers/import-elision.ts +152 -0
  538. package/src/compiler/transformers/jsx-entities.ts +256 -0
  539. package/src/compiler/transformers/jsx.ts +824 -0
  540. package/src/compiler/transformers/legacy-decorators.ts +726 -0
  541. package/src/compiler/transformers/logical-assignment.ts +75 -0
  542. package/src/compiler/transformers/module-utilities.ts +42 -0
  543. package/src/compiler/transformers/module.ts +474 -0
  544. package/src/compiler/transformers/named-evaluation.ts +389 -0
  545. package/src/compiler/transformers/nullish-coalescing.ts +35 -0
  546. package/src/compiler/transformers/object-rest-spread.ts +577 -0
  547. package/src/compiler/transformers/optional-catch.ts +29 -0
  548. package/src/compiler/transformers/optional-chain.ts +246 -0
  549. package/src/compiler/transformers/reference-resolver.ts +1201 -0
  550. package/src/compiler/transformers/runtime-syntax.ts +942 -0
  551. package/src/compiler/transformers/subtree-facts.ts +245 -0
  552. package/src/compiler/transformers/syntax-facts.ts +353 -0
  553. package/src/compiler/transformers/tagged-template.ts +167 -0
  554. package/src/compiler/transformers/transformer.ts +56 -0
  555. package/src/compiler/transformers/type-eraser.ts +520 -0
  556. package/src/compiler/transformers/type-serialization.ts +374 -0
  557. package/src/compiler/transformers/using.ts +613 -0
  558. package/src/compiler/transformers/utilities.ts +419 -0
  559. package/src/compiler/transformers/visitor-base.ts +1601 -0
  560. package/src/compiler/transformers/visitor-hooks.ts +252 -0
  561. package/src/compiler/tsc-build.ts +1418 -0
  562. package/src/compiler/tsc-cli.ts +666 -0
  563. package/src/compiler/tsc-compile.ts +437 -0
  564. package/src/compiler/tsc-watch.ts +854 -0
  565. package/src/compiler/tsconfig.ts +1574 -0
  566. package/src/compiler/type-printer.ts +110 -0
  567. package/src/compiler/types.ts +115 -0
  568. package/src/compiler/unicode-identifiers.ts +212 -0
  569. package/src/compiler/unicode-properties.ts +537 -0
  570. package/src/compiler/vfs-match.ts +597 -0
  571. package/src/compiler/xxh3.ts +650 -0
  572. package/src/library/ast.generated.ts +141 -167
  573. package/src/library/ast.ts +4 -1
  574. package/src/library/checker.ts +384 -0
  575. package/src/library/diagnostics.ts +72 -0
  576. package/src/library/disk.ts +73 -0
  577. package/src/library/errors.ts +26 -0
  578. package/src/library/host.ts +63 -0
  579. package/src/library/index.ts +21 -0
  580. package/src/library/nodes.ts +232 -0
  581. package/src/library/options.ts +449 -0
  582. package/src/library/parse.ts +63 -0
  583. package/src/library/program.ts +293 -0
  584. package/src/library/types.ts +14 -1
@@ -0,0 +1,1351 @@
1
+ // Expression checking: types of expressions and the errors they produce.
2
+ import { checkMetaProperty, getIsolatedModulesLikeFlagName, isValidTypeOnlyAliasUseSite, markIdentifierAliasReferencedInExpression, } from './checker-modules.js';
3
+ import { checkDeprecatedIdentifier } from './checker-deprecation.js';
4
+ import { isWriteOnlyAccess } from './checker-unused.js';
5
+ import { BinaryExpression, getExpression, getInitializer, getName, getText, getTagName, getType, } from './ast.js';
6
+ import { getThisContainer, isEntityNameExpression, isStatic, skipParentheses, isClassLike, getNameOfDeclaration, getRootDeclaration, hasSyntacticModifier, isFunctionExpressionOrArrowFunction, isObjectLiteralOrClassExpressionMethodOrAccessor, isPartOfTypeQuery, isOptionalChain, isAssignmentTarget, getSourceFileOfNode, } from './binder-utilities.js';
7
+ import { shouldCheckErasableSyntax } from './checker-declarations.js';
8
+ import { skipTrivia } from './scanner.js';
9
+ import { Diagnostic } from './diagnostics.js';
10
+ import { checkSuperExpression, checkThisBeforeSuper, checkThisInStaticClassFieldInitializerInDecoratedClass, } from './checker-super.js';
11
+ import { cachedTypeKey, } from './checker-types.js';
12
+ import { createTupleTypeEx, getBigIntLiteralType, getFreshTypeOfLiteralType, getNumberLiteralType, getRegularTypeOfLiteralType, getStringLiteralType, getUnionTypeEx, getWidenedLiteralType, getWidenedUniqueESSymbolType, isErrorType, isTupleType, someType, typesOf, getBaseTypeOfLiteralType, cloneTypeReference, createArrayTypeEx, everyType, getTemplateLiteralType, isMutableArrayOrTuple, } from './checker-type-factory.js';
13
+ import { TupleElementInfo } from './checker-types.js';
14
+ import { getBaseConstraintOfType, getPropertyOfType, getIndexInfoOfType, getIndexInfosOfType, getIndexTypeOfType, getTypeOfPropertyOfType, isArrayLikeType, getBaseConstraintOrType, isApplicableIndexType, getDeclarationModifierFlagsFromSymbol, getApparentType, mapToBaseConstraintOrType, } from './checker-members.js';
15
+ import { getExportSymbolOfValueSymbolIfExported, getMergedSymbol, getSymbolOfDeclaration, resolveEntityName, resolveName, getFirstIdentifier, getCannotFindNameDiagnosticForName, getDeclarationOfAliasSymbol, popTypeResolution, pushTypeResolution, reportCircularityError, } from './checker-symbols.js';
16
+ import { getTypeOfSymbol, getWidenedType, isReadonlySymbol, getOptionalType, removeMissingType, addOptionality, } from './checker-symbol-types.js';
17
+ import { getDeclaredTypeOfClassOrInterface } from './checker-declared-types.js';
18
+ import { getTypeFromTypeNode } from './checker-type-nodes.js';
19
+ import { isGenericObjectType, getIndexedAccessTypeOrUndefinedEx, getHomomorphicTypeVariable, isGenericIndexType, isGenericMappedType, isGenericType, getMappedTypeNameTypeKind, getIndexForMappedType, getIndexTypeEx, getMappedTypeModifiers, getPropertyNameFromIndex, isNoInferType, } from './checker-type-operators.js';
20
+ import { getTypeFacts, getNonNullableType, getTypeWithFacts, hasTypeFacts } from './checker-flow.js';
21
+ import { checkTypeComparableTo, isTypeAssignableTo, isTypeComparableTo } from './relations.js';
22
+ import { isTypeAssignableToKindEx as isTypeAssignableToKind } from './checker-type-operators.js';
23
+ import { typeToString, symbolToString } from './type-printer.js';
24
+ import { isTypeUsableAsPropertyName, getPropertyNameFromType, maybeTypeOfKind } from './checker-utilities.js';
25
+ import { getApparentTypeOfContextualType, getContextualType, getContextualTypeEx, getContextualSignatureForFunctionLikeDeclaration, } from './checker-contextual.js';
26
+ import { checkCallExpression, checkExpressionWithTypeArguments, checkNewExpression, checkTaggedTemplateExpression, getOptionalExpressionType, instantiateTypeWithSingleGenericCallSignature, isSymbolOrSymbolForCall, propagateOptionalTypeMarker, } from './checker-calls.js';
27
+ import { checkAwaitExpression, checkFunctionExpressionOrObjectLiteralMethod, checkYieldExpression, } from './checker-functions.js';
28
+ import { checkIteratedTypeOrElementType, getAwaitedType, getIteratedTypeOrElementType, } from './checker-iteration.js';
29
+ import { checkClassExpression } from './checker-classes.js';
30
+ import { padParameterInitializerType } from './checker-destructuring.js';
31
+ import { checkNodeDeferred, checkTypeNodeIfPresent } from './checker-source-file.js';
32
+ import { isInPropertyInitializerOrClassStaticBlock } from './checker-declaration-order.js';
33
+ import { checkObjectLiteral } from './checker-object-literals.js';
34
+ import { evaluate } from './checker-evaluator.js';
35
+ import { checkPrivateIdentifierExpression, checkPropertyAccessExpressionOrQualifiedName, isMethodAccessForCall, } from './checker-property-access.js';
36
+ import { checkBinaryExpression, checkConditionalExpression, checkDeleteExpression, checkPostfixUnaryExpression, checkPrefixUnaryExpression, isTypeAssertion, } from './checker-operators.js';
37
+ import { checkJsx } from './checker-jsx.js';
38
+ import { getRegularTypeOfObjectLiteral } from './checker-literals.js';
39
+ import { getReturnTypeOfSignature, getSignatureFromDeclaration, getSingleSignature, getThisTypeOfSignature, } from './checker-signatures.js';
40
+ import { isFunctionLike, isImportCall, isInJSFile, isRequireCall } from './ast-utilities.js';
41
+ import { isLiteralKind } from './printer/utilities.js';
42
+ import { convertAutoToAny, isEvolvingArrayOperationTarget, getAssignmentTargetKind, getControlFlowContainer, isConstantVariable, isInCompoundLikeAssignment, isMutableLocalVariableDeclaration, isParameterOrMutableLocalVariable, isPastLastAssignment, isSymbolAssignedDefinitely, getFlowTypeOfReference, getNarrowedTypeOfSymbol, } from './checker-narrowing.js';
43
+ import { getFlowTypeOfAutoTypedProperty, getThisTypeOfAssignedFunction } from './checker-javascript.js';
44
+ import { checkExpressionWithContextualType, getThisTypeOfObjectLiteralMember } from './checker-contextual.js';
45
+ import { getInferenceContext, instantiateContextualType, popContextualType, pushCachedContextualType, } from './checker-contextual.js';
46
+ import { addIntraExpressionInferenceSite, isConstTypeVariable } from './checker-inference.js';
47
+ import { isContextSensitiveFunctionOrObjectLiteralMethod } from './checker-contextual.js';
48
+ import { checkTypeRelatedToAndOptionallyElaborate } from './checker-elaboration.js';
49
+ import { isContextSensitive } from './checker-functions.js';
50
+ import { getSignatureOfFullSignatureType } from './checker-jsdoc.js';
51
+ export { getContextuallyTypedParameterType, isContextSensitiveFunctionOrObjectLiteralMethod, } from './checker-contextual.js';
52
+ // ---- Entry points
53
+ export function checkExpression(c, node) {
54
+ return checkExpressionEx(c, node, 0 /* CheckMode.Normal */);
55
+ }
56
+ export function checkExpressionEx(c, node, checkMode) {
57
+ const saveCurrentNode = c.currentNode;
58
+ c.currentNode = node;
59
+ c.instantiationCount = 0;
60
+ const t = instantiateTypeWithSingleGenericCallSignature(c, node, checkExpressionWorker(c, node, checkMode), checkMode);
61
+ if (isConstEnumObjectTypeLocal(t))
62
+ checkConstEnumAccess(c, node, t);
63
+ c.currentNode = saveCurrentNode;
64
+ return t;
65
+ }
66
+ /**
67
+ * A const enum object can only be accessed, imported, exported or queried. Under isolatedModules, an
68
+ * ambient one can't be used at all outside types.
69
+ */
70
+ function checkConstEnumAccess(c, node, t) {
71
+ const parent = node.parent;
72
+ const ok = ((parent.kind === 212 /* SyntaxKind.PropertyAccessExpression */ || parent.kind === 213 /* SyntaxKind.ElementAccessExpression */) &&
73
+ getExpression(parent) === node) ||
74
+ ((node.kind === 79 /* SyntaxKind.Identifier */ || node.kind === 167 /* SyntaxKind.QualifiedName */) &&
75
+ isInRightSideOfImportOrExportAssignment(node)) ||
76
+ (parent.kind === 187 /* SyntaxKind.TypeQuery */ && parent.exprName === node) ||
77
+ parent.kind === 282 /* SyntaxKind.ExportSpecifier */;
78
+ if (!ok)
79
+ c.error(node, 639 /* Diagnostics.X_const_enums_can_only_be_used_in_property_or_index_access_expressions_or_the_right_hand_side_of_an_import_declaration_or_export_assignment_or_type_query */);
80
+ // Under verbatimModuleSyntax, only uses that don't resolve to an import are checked here; imports of
81
+ // ambient const enums are checked with the alias.
82
+ if (c.compilerOptions.isolatedModules === true ||
83
+ (c.compilerOptions.verbatimModuleSyntax === true &&
84
+ ok &&
85
+ resolveName(c, node, getText(getFirstIdentifier(node)), 2097152 /* SymbolFlags.Alias */, undefined, false, true) === undefined)) {
86
+ const constEnumDeclaration = t.symbol.valueDeclaration;
87
+ if ((constEnumDeclaration.flags & 8388608 /* NodeFlags.Ambient */) !== 0 && !isValidTypeOnlyAliasUseSite(node))
88
+ c.error(node, 880 /* Diagnostics.Cannot_access_ambient_const_enums_when_0_is_enabled */, getIsolatedModulesLikeFlagName(c));
89
+ }
90
+ }
91
+ function isInRightSideOfImportOrExportAssignment(name) {
92
+ let node = name;
93
+ while (node.parent.kind === 167 /* SyntaxKind.QualifiedName */)
94
+ node = node.parent;
95
+ const parent = node.parent;
96
+ return ((parent.kind === 272 /* SyntaxKind.ImportEqualsDeclaration */ &&
97
+ parent.moduleReference === node) ||
98
+ (parent.kind === 278 /* SyntaxKind.ExportAssignment */ && getExpression(parent) === node));
99
+ }
100
+ /** The type of `node`, computed once. */
101
+ export function checkExpressionCached(c, node) {
102
+ let type = c.resolvedTypes.get(node.id);
103
+ if (type === undefined) {
104
+ // A type that is cached is computed without the control flow analysis in progress, whose variables may
105
+ // have transient types: loops being analyzed start over.
106
+ const saveFlowLoopStack = c.flowLoopStack;
107
+ const saveFlowTypeCache = c.flowTypeCache;
108
+ if (saveFlowLoopStack.length !== 0)
109
+ c.flowLoopStack = [];
110
+ c.flowTypeCache = undefined;
111
+ type = checkExpression(c, node);
112
+ c.resolvedTypes.set(node.id, type);
113
+ c.flowTypeCache = saveFlowTypeCache;
114
+ c.flowLoopStack = saveFlowLoopStack;
115
+ }
116
+ return type;
117
+ }
118
+ /** The type of an expression, cached when computing it needed flow analysis; may skip some diagnostics. */
119
+ export function getTypeOfExpression(c, node) {
120
+ const quickType = getQuickTypeOfExpression(c, node);
121
+ if (quickType !== undefined)
122
+ return quickType;
123
+ const cachedType = c.flowTypeCache?.get(node);
124
+ if (cachedType !== undefined)
125
+ return cachedType;
126
+ const startInvocationCount = c.flowInvocationCount;
127
+ const t = checkExpressionEx(c, node, 64 /* CheckMode.TypeOnly */);
128
+ if (c.flowInvocationCount !== startInvocationCount) {
129
+ if (c.flowTypeCache === undefined)
130
+ c.flowTypeCache = new Map();
131
+ c.flowTypeCache.set(node, t);
132
+ }
133
+ return t;
134
+ }
135
+ /** The type of an initializer in a position where literals widen unless the context wants them. */
136
+ export function checkExpressionForMutableLocation(c, node) {
137
+ return checkExpressionForMutableLocationEx(c, node, 0 /* CheckMode.Normal */);
138
+ }
139
+ export function checkExpressionForMutableLocationEx(c, node, checkMode) {
140
+ const t = checkExpressionEx(c, node, checkMode);
141
+ if (isConstContext(c, node))
142
+ return getRegularTypeOfLiteralType(c, t);
143
+ // An asserted type is kept as written.
144
+ if (isTypeAssertion(node))
145
+ return t;
146
+ return getWidenedLiteralLikeTypeForContextualType(c, t, instantiateContextualType(c, getContextualType(c, node), node, 0 /* ContextFlags.None */));
147
+ }
148
+ export function checkDeclarationInitializer(c, declaration, checkMode = 0 /* CheckMode.Normal */, contextualType) {
149
+ const initializer = getInitializer(declaration);
150
+ const t = getQuickTypeOfExpression(c, initializer) ??
151
+ (contextualType !== undefined
152
+ ? checkExpressionWithContextualType(c, initializer, contextualType, undefined, checkMode)
153
+ : checkMode === 0 /* CheckMode.Normal */
154
+ ? checkExpressionCached(c, initializer)
155
+ : checkExpressionEx(c, initializer, checkMode));
156
+ return padParameterInitializerType(c, declaration, t);
157
+ }
158
+ /**
159
+ * The type of an expression whose type doesn't need its arguments checked: a call or `new` of a single
160
+ * non-generic signature, an assertion, or a literal.
161
+ */
162
+ function getQuickTypeOfExpression(c, node) {
163
+ const expr = skipParentheses(node);
164
+ switch (expr.kind) {
165
+ case 224 /* SyntaxKind.AwaitExpression */: {
166
+ const t = getQuickTypeOfExpression(c, getExpression(expr));
167
+ return t !== undefined ? getAwaitedType(c, t) : undefined;
168
+ }
169
+ case 214 /* SyntaxKind.CallExpression */: {
170
+ const call = expr;
171
+ if (call.expression.kind === 107 /* SyntaxKind.SuperKeyword */ ||
172
+ isRequireCall(call, true) ||
173
+ isSymbolOrSymbolForCall(c, call) ||
174
+ isImportCall(call))
175
+ return undefined;
176
+ if (isOptionalChain(call)) {
177
+ const funcType = checkExpression(c, call.expression);
178
+ const nonOptionalType = getOptionalExpressionType(c, funcType, call.expression);
179
+ const returnType = getReturnTypeOfSingleNonGenericSignature(c, funcType, 0 /* SignatureKind.Call */);
180
+ return returnType !== undefined
181
+ ? propagateOptionalTypeMarker(c, returnType, call, nonOptionalType !== funcType)
182
+ : undefined;
183
+ }
184
+ return getReturnTypeOfSingleNonGenericSignature(c, checkNonNullExpression(c, call.expression), 0 /* SignatureKind.Call */);
185
+ }
186
+ case 215 /* SyntaxKind.NewExpression */:
187
+ return getReturnTypeOfSingleNonGenericSignature(c, checkNonNullExpression(c, getExpression(expr)), 1 /* SignatureKind.Construct */);
188
+ case 235 /* SyntaxKind.AsExpression */:
189
+ case 217 /* SyntaxKind.TypeAssertionExpression */: {
190
+ const typeNode = getType(expr);
191
+ return isConstTypeReference(typeNode) ? undefined : getTypeFromTypeNode(c, typeNode);
192
+ }
193
+ }
194
+ if (isLiteralKind(node.kind) || node.kind === 111 /* SyntaxKind.TrueKeyword */ || node.kind === 96 /* SyntaxKind.FalseKeyword */)
195
+ return checkExpression(c, node);
196
+ return undefined;
197
+ }
198
+ function getReturnTypeOfSingleNonGenericSignature(c, funcType, kind) {
199
+ const signature = getSingleSignature(c, funcType, kind, true);
200
+ return signature !== undefined && signature.typeParameters.length === 0
201
+ ? getReturnTypeOfSignature(c, signature)
202
+ : undefined;
203
+ }
204
+ export function checkComputedPropertyName(c, node) {
205
+ const nodeId = node.expression.id;
206
+ if (c.resolvedTypes.get(nodeId) === undefined) {
207
+ const expression = node.expression;
208
+ const container = node.parent.parent;
209
+ // `[x in y]` in a type member is a mapped type written in the wrong place, reported by the parser.
210
+ if ((container.kind === 188 /* SyntaxKind.TypeLiteral */ ||
211
+ isClassLike(container) ||
212
+ container.kind === 265 /* SyntaxKind.InterfaceDeclaration */) &&
213
+ expression.kind === 227 /* SyntaxKind.BinaryExpression */ &&
214
+ expression.operatorToken.kind === 102 /* SyntaxKind.InKeyword */ &&
215
+ node.parent.kind !== 178 /* SyntaxKind.GetAccessor */ &&
216
+ node.parent.kind !== 179 /* SyntaxKind.SetAccessor */) {
217
+ c.resolvedTypes.set(nodeId, c.errorType);
218
+ return c.resolvedTypes.get(nodeId);
219
+ }
220
+ const t = checkExpression(c, expression);
221
+ c.resolvedTypes.set(nodeId, t);
222
+ // Allows string, number, symbol and any, as well as enums, unknown and unions of them.
223
+ if ((t.flags & 12 /* TypeFlags.Nullable */) !== 0 ||
224
+ (!isTypeAssignableToKind(c, t, 12583968 /* TypeFlags.StringLike */ | 67648 /* TypeFlags.NumberLike */ | 16896 /* TypeFlags.ESSymbolLike */, false) &&
225
+ !isTypeAssignableTo(c, t, c.stringNumberSymbolType)))
226
+ c.error(node, 630 /* Diagnostics.A_computed_property_name_must_be_of_type_string_number_symbol_or_any */);
227
+ }
228
+ return c.resolvedTypes.get(nodeId);
229
+ }
230
+ /** A parameter's declared type without `undefined` when its initializer can't be `undefined`. */
231
+ function removeOptionalityFromDeclaredType(c, declaredType, declaration) {
232
+ const removeUndefined = c.strictNullChecks &&
233
+ declaration.kind === 170 /* SyntaxKind.Parameter */ &&
234
+ getInitializer(declaration) !== undefined &&
235
+ hasTypeFacts(c, declaredType, 16777216 /* TypeFacts.IsUndefined */) &&
236
+ !parameterInitializerContainsUndefined(c, declaration);
237
+ return removeUndefined ? getTypeWithFacts(c, declaredType, 524288 /* TypeFacts.NEUndefined */) : declaredType;
238
+ }
239
+ function parameterInitializerContainsUndefined(c, declaration) {
240
+ const links = c.nodeLinks(declaration);
241
+ if ((links.flags & 33554432 /* NodeCheckFlags.InitializerIsUndefinedComputed */) === 0) {
242
+ if (!pushTypeResolution(c, declaration, 8 /* TypeSystemPropertyName.InitializerIsUndefined */)) {
243
+ reportCircularityError(c, getSymbolOfDeclaration(c, declaration));
244
+ return true;
245
+ }
246
+ const containsUndefined = hasTypeFacts(c, checkDeclarationInitializer(c, declaration), 16777216 /* TypeFacts.IsUndefined */);
247
+ if (!popTypeResolution(c)) {
248
+ reportCircularityError(c, getSymbolOfDeclaration(c, declaration));
249
+ return true;
250
+ }
251
+ if ((links.flags & 33554432 /* NodeCheckFlags.InitializerIsUndefinedComputed */) === 0)
252
+ links.flags |=
253
+ 33554432 /* NodeCheckFlags.InitializerIsUndefinedComputed */ | (containsUndefined ? 16777216 /* NodeCheckFlags.InitializerIsUndefined */ : 0);
254
+ }
255
+ return (links.flags & 16777216 /* NodeCheckFlags.InitializerIsUndefined */) !== 0;
256
+ }
257
+ /** Whether `node` is the operand of a spread in an object destructuring assignment, as in `({ ...x } = obj)`. */
258
+ function isSpreadDestructuringAssignmentTarget(node) {
259
+ const parent = node.parent;
260
+ if (parent.kind !== 305 /* SyntaxKind.SpreadAssignment */ || parent.parent === undefined)
261
+ return false;
262
+ const pattern = parent.parent;
263
+ const grandparent = pattern.parent;
264
+ return ((grandparent.kind === 227 /* SyntaxKind.BinaryExpression */ && grandparent.left === pattern) ||
265
+ (grandparent.kind === 251 /* SyntaxKind.ForOfStatement */ && grandparent.initializer === pattern));
266
+ }
267
+ /** Whether `node` is in a binding element of the same declaration as the binding element `declaration`. */
268
+ function isSameScopedBindingElement(node, declaration) {
269
+ if (declaration.kind !== 209 /* SyntaxKind.BindingElement */)
270
+ return false;
271
+ let bindingElement = node.parent;
272
+ while (bindingElement !== undefined && bindingElement.kind !== 209 /* SyntaxKind.BindingElement */)
273
+ bindingElement = bindingElement.parent;
274
+ return bindingElement !== undefined && getRootDeclaration(bindingElement) === getRootDeclaration(declaration);
275
+ }
276
+ /** Whether `node` is the `this` of `typeof this` or `typeof this.x`, which parses as an identifier. */
277
+ export function isThisInTypeQuery(node) {
278
+ if (node.kind !== 79 /* SyntaxKind.Identifier */ || getText(node) !== 'this')
279
+ return false;
280
+ let current = node;
281
+ while (current.parent.kind === 167 /* SyntaxKind.QualifiedName */ && current.parent.left === current)
282
+ current = current.parent;
283
+ return current.parent.kind === 187 /* SyntaxKind.TypeQuery */;
284
+ }
285
+ /** The type of the expression in a `typeof` type query. */
286
+ export function checkTypeQueryExpression(c, node) {
287
+ const exprName = node.exprName;
288
+ if (exprName.kind === 79 /* SyntaxKind.Identifier */)
289
+ return checkIdentifier(c, exprName);
290
+ if (exprName.kind === 167 /* SyntaxKind.QualifiedName */)
291
+ return checkQualifiedName(c, exprName);
292
+ if (exprName.kind === 109 /* SyntaxKind.ThisKeyword */)
293
+ return checkThisExpression(c, exprName);
294
+ return c.errorType;
295
+ }
296
+ /** The symbol an identifier refers to as a value; reports unresolved names. */
297
+ export function getResolvedSymbol(c, node) {
298
+ const cached = c.resolvedSymbols.get(node.id);
299
+ if (cached !== undefined)
300
+ return cached;
301
+ let symbol = c.unknownSymbol;
302
+ if (getText(node) !== '') {
303
+ const text = getText(node);
304
+ const found = resolveName(c, node, text, 111551 /* SymbolFlags.Value */ | 1048576 /* SymbolFlags.ExportValue */, getCannotFindNameDiagnosticForName(c, node), !isWriteOnlyAccess(node), false);
305
+ if (found !== undefined)
306
+ symbol = found;
307
+ }
308
+ c.resolvedSymbols.set(node.id, symbol);
309
+ return symbol;
310
+ }
311
+ // ---- Dispatch
312
+ function checkExpressionWorker(c, node, checkMode) {
313
+ switch (node.kind) {
314
+ case 79 /* SyntaxKind.Identifier */:
315
+ return checkIdentifier(c, node, checkMode);
316
+ case 80 /* SyntaxKind.PrivateIdentifier */:
317
+ return checkPrivateIdentifierExpression(c, node);
318
+ case 109 /* SyntaxKind.ThisKeyword */:
319
+ return checkThisExpression(c, node);
320
+ case 107 /* SyntaxKind.SuperKeyword */:
321
+ return checkSuperExpression(c, node);
322
+ case 105 /* SyntaxKind.NullKeyword */:
323
+ return c.nullWideningType;
324
+ case 111 /* SyntaxKind.TrueKeyword */:
325
+ return c.trueType;
326
+ case 96 /* SyntaxKind.FalseKeyword */:
327
+ return c.falseType;
328
+ case 10 /* SyntaxKind.StringLiteral */:
329
+ case 14 /* SyntaxKind.NoSubstitutionTemplateLiteral */:
330
+ return getFreshTypeOfLiteralType(c, getStringLiteralType(c, getText(node)));
331
+ case 8 /* SyntaxKind.NumericLiteral */:
332
+ return getFreshTypeOfLiteralType(c, getNumberLiteralType(c, Number(getText(node))));
333
+ case 9 /* SyntaxKind.BigIntLiteral */:
334
+ return getFreshTypeOfLiteralType(c, getBigIntLiteralType(c, parseBigIntText(getText(node))));
335
+ case 229 /* SyntaxKind.TemplateExpression */:
336
+ return checkTemplateExpression(c, node);
337
+ case 13 /* SyntaxKind.RegularExpressionLiteral */:
338
+ return c.globalRegExpType;
339
+ case 210 /* SyntaxKind.ArrayLiteralExpression */:
340
+ return checkArrayLiteral(c, node, checkMode);
341
+ case 211 /* SyntaxKind.ObjectLiteralExpression */:
342
+ return checkObjectLiteral(c, node, checkMode);
343
+ case 212 /* SyntaxKind.PropertyAccessExpression */:
344
+ return checkPropertyAccessExpression(c, node, false, checkMode);
345
+ case 167 /* SyntaxKind.QualifiedName */:
346
+ return checkQualifiedName(c, node);
347
+ case 213 /* SyntaxKind.ElementAccessExpression */:
348
+ return checkElementAccessExpression(c, node, checkMode);
349
+ case 214 /* SyntaxKind.CallExpression */:
350
+ return checkCallExpression(c, node, checkMode);
351
+ case 215 /* SyntaxKind.NewExpression */:
352
+ return checkNewExpression(c, node, checkMode);
353
+ case 216 /* SyntaxKind.TaggedTemplateExpression */:
354
+ return checkTaggedTemplateExpression(c, node, checkMode);
355
+ case 218 /* SyntaxKind.ParenthesizedExpression */:
356
+ return checkExpressionEx(c, getExpression(node), checkMode);
357
+ case 232 /* SyntaxKind.ClassExpression */:
358
+ return checkClassExpression(c, node);
359
+ case 219 /* SyntaxKind.FunctionExpression */:
360
+ case 220 /* SyntaxKind.ArrowFunction */:
361
+ return checkFunctionExpressionOrObjectLiteralMethod(c, node, checkMode);
362
+ case 222 /* SyntaxKind.TypeOfExpression */:
363
+ checkExpression(c, getExpression(node));
364
+ return c.typeofType;
365
+ case 217 /* SyntaxKind.TypeAssertionExpression */:
366
+ case 235 /* SyntaxKind.AsExpression */:
367
+ return checkAssertion(c, node, checkMode);
368
+ case 236 /* SyntaxKind.NonNullExpression */: {
369
+ const leftType = checkExpressionEx(c, getExpression(node), checkMode);
370
+ if ((node.flags & 32 /* NodeFlags.OptionalChain */) === 0)
371
+ return getNonNullableType(c, leftType);
372
+ // In an optional chain, the chain's undefined stays.
373
+ const nonOptionalType = getOptionalExpressionType(c, leftType, getExpression(node));
374
+ return propagateOptionalTypeMarker(c, getNonNullableType(c, nonOptionalType), node, nonOptionalType !== leftType);
375
+ }
376
+ case 234 /* SyntaxKind.ExpressionWithTypeArguments */:
377
+ return checkExpressionWithTypeArguments(c, node);
378
+ case 239 /* SyntaxKind.SatisfiesExpression */:
379
+ return checkSatisfiesExpression(c, node, checkMode);
380
+ case 237 /* SyntaxKind.MetaProperty */:
381
+ return checkMetaProperty(c, node);
382
+ case 221 /* SyntaxKind.DeleteExpression */:
383
+ return checkDeleteExpression(c, node);
384
+ case 223 /* SyntaxKind.VoidExpression */:
385
+ // The operand is checked deferred.
386
+ checkNodeDeferred(c, node);
387
+ return c.undefinedWideningType;
388
+ case 224 /* SyntaxKind.AwaitExpression */:
389
+ return checkAwaitExpression(c, node);
390
+ case 225 /* SyntaxKind.PrefixUnaryExpression */:
391
+ return checkPrefixUnaryExpression(c, node);
392
+ case 226 /* SyntaxKind.PostfixUnaryExpression */:
393
+ return checkPostfixUnaryExpression(c, node);
394
+ case 227 /* SyntaxKind.BinaryExpression */:
395
+ return checkBinaryExpression(c, node, checkMode);
396
+ case 228 /* SyntaxKind.ConditionalExpression */:
397
+ return checkConditionalExpression(c, node, checkMode);
398
+ case 231 /* SyntaxKind.SpreadElement */:
399
+ return checkSpreadExpression(c, node, checkMode);
400
+ case 233 /* SyntaxKind.OmittedExpression */:
401
+ return c.undefinedWideningType;
402
+ case 230 /* SyntaxKind.YieldExpression */:
403
+ return checkYieldExpression(c, node);
404
+ case 238 /* SyntaxKind.SyntheticExpression */:
405
+ return c.anyType;
406
+ case 295 /* SyntaxKind.JsxExpression */:
407
+ case 285 /* SyntaxKind.JsxElement */:
408
+ case 286 /* SyntaxKind.JsxSelfClosingElement */:
409
+ case 289 /* SyntaxKind.JsxFragment */:
410
+ case 293 /* SyntaxKind.JsxAttributes */:
411
+ return checkJsx(c, node, checkMode);
412
+ }
413
+ return c.errorType;
414
+ }
415
+ export function parseBigIntText(text) {
416
+ let digits = text.endsWith('n') ? text.substring(0, text.length - 1) : text;
417
+ digits = digits.split('_').join('');
418
+ if (digits.length > 2 && digits.charCodeAt(0) === 0x30) {
419
+ const radix = digits.charCodeAt(1) | 0x20;
420
+ if (radix === 0x78 || radix === 0x6f || radix === 0x62)
421
+ return BigInt(digits).toString();
422
+ }
423
+ let i = 0;
424
+ while (i < digits.length - 1 && digits.charCodeAt(i) === 0x30)
425
+ i++;
426
+ return digits.substring(i);
427
+ }
428
+ // ---- Identifiers and `this`
429
+ export function checkIdentifier(c, node, checkMode = 0 /* CheckMode.Normal */) {
430
+ if (isThisInTypeQuery(node))
431
+ return checkThisExpression(c, node);
432
+ const symbol = getResolvedSymbol(c, node);
433
+ if (symbol === c.unknownSymbol)
434
+ return c.errorType;
435
+ if (symbol === c.argumentsSymbol) {
436
+ if (isInPropertyInitializerOrClassStaticBlock(node, true)) {
437
+ c.error(node, 946 /* Diagnostics.X_arguments_cannot_be_referenced_in_property_initializers_or_class_static_initialization_blocks */);
438
+ return c.errorType;
439
+ }
440
+ return getTypeOfSymbol(c, symbol);
441
+ }
442
+ markIdentifierAliasReferencedInExpression(c, node);
443
+ const localOrExportSymbol = getExportSymbolOfValueSymbolIfExported(c, symbol);
444
+ checkDeprecatedIdentifier(c, node, localOrExportSymbol);
445
+ let declaration = localOrExportSymbol.valueDeclaration;
446
+ const immediateDeclaration = declaration;
447
+ // In `const [a, b = a + 1] = [2]`, `a` is `any` while computing the contextual type of `[2]`.
448
+ if (declaration !== undefined &&
449
+ declaration.kind === 209 /* SyntaxKind.BindingElement */ &&
450
+ c.contextualBindingPatterns.includes(declaration.parent) &&
451
+ isDescendantOf(node, declaration.parent))
452
+ return c.nonInferrableAnyType;
453
+ let t = getNarrowableTypeForReference(c, getNarrowedTypeOfSymbol(c, localOrExportSymbol, node), node, checkMode);
454
+ const assignmentKind = getAssignmentTargetKind(node);
455
+ if (assignmentKind !== 0 /* AssignmentKind.None */) {
456
+ if ((localOrExportSymbol.flags & 3 /* SymbolFlags.Variable */) === 0) {
457
+ let message = 696 /* Diagnostics.Cannot_assign_to_0_because_it_is_not_a_variable */;
458
+ if ((localOrExportSymbol.flags & 384 /* SymbolFlags.Enum */) !== 0)
459
+ message = 771 /* Diagnostics.Cannot_assign_to_0_because_it_is_an_enum */;
460
+ else if ((localOrExportSymbol.flags & 32 /* SymbolFlags.Class */) !== 0)
461
+ message = 772 /* Diagnostics.Cannot_assign_to_0_because_it_is_a_class */;
462
+ else if ((localOrExportSymbol.flags & 1536 /* SymbolFlags.Module */) !== 0)
463
+ message = 774 /* Diagnostics.Cannot_assign_to_0_because_it_is_a_namespace */;
464
+ else if ((localOrExportSymbol.flags & 16 /* SymbolFlags.Function */) !== 0)
465
+ message = 773 /* Diagnostics.Cannot_assign_to_0_because_it_is_a_function */;
466
+ else if ((localOrExportSymbol.flags & 2097152 /* SymbolFlags.Alias */) !== 0)
467
+ message = 775 /* Diagnostics.Cannot_assign_to_0_because_it_is_an_import */;
468
+ c.error(node, message, symbolToString(c, symbol));
469
+ return c.errorType;
470
+ }
471
+ if (isReadonlySymbol(c, localOrExportSymbol)) {
472
+ c.error(node, 736 /* Diagnostics.Cannot_assign_to_0_because_it_is_a_constant */, symbolToString(c, symbol));
473
+ return c.errorType;
474
+ }
475
+ }
476
+ const isAlias = (localOrExportSymbol.flags & 2097152 /* SymbolFlags.Alias */) !== 0;
477
+ // Only variables and parameters outside assignment targets are narrowed.
478
+ if ((localOrExportSymbol.flags & 3 /* SymbolFlags.Variable */) !== 0) {
479
+ if (assignmentKind === 1 /* AssignmentKind.Definite */)
480
+ return isInCompoundLikeAssignment(node) ? getBaseTypeOfLiteralType(c, t) : t;
481
+ }
482
+ else if (isAlias)
483
+ declaration = getDeclarationOfAliasSymbol(symbol);
484
+ else
485
+ return t;
486
+ if (declaration === undefined)
487
+ return t;
488
+ const isParameter = getRootDeclaration(declaration).kind === 170 /* SyntaxKind.Parameter */;
489
+ // The CommonJS `module` symbol is declared by its source file.
490
+ const declarationContainer = declaration.parent !== undefined ? getControlFlowContainer(declaration) : undefined;
491
+ let flowContainer = getControlFlowContainer(node);
492
+ const isOuterVariable = flowContainer !== declarationContainer;
493
+ const isModuleExports = (symbol.flags & 134217728 /* SymbolFlags.ModuleExports */) !== 0;
494
+ const typeIsAutomatic = t === c.autoType || t === c.autoArrayType;
495
+ const isAutomaticTypeInNonNull = typeIsAutomatic && node.parent.kind === 236 /* SyntaxKind.NonNullExpression */;
496
+ // Closures see narrowings of constants, and of variables past their last assignment.
497
+ while (flowContainer !== declarationContainer &&
498
+ (isFunctionExpressionOrArrowFunction(flowContainer) ||
499
+ isObjectLiteralOrClassExpressionMethodOrAccessor(flowContainer)) &&
500
+ ((isConstantVariable(c, localOrExportSymbol) && t !== c.autoArrayType) ||
501
+ (isParameterOrMutableLocalVariable(c, localOrExportSymbol) && isPastLastAssignment(c, localOrExportSymbol, node))))
502
+ flowContainer = getControlFlowContainer(flowContainer);
503
+ const isNeverInitialized = immediateDeclaration !== undefined &&
504
+ immediateDeclaration.kind === 261 /* SyntaxKind.VariableDeclaration */ &&
505
+ immediateDeclaration.parent.parent.kind !== 250 /* SyntaxKind.ForInStatement */ &&
506
+ immediateDeclaration.parent.parent.kind !== 251 /* SyntaxKind.ForOfStatement */ &&
507
+ getInitializer(immediateDeclaration) === undefined &&
508
+ immediateDeclaration.exclamationToken === undefined &&
509
+ isMutableLocalVariableDeclaration(immediateDeclaration) &&
510
+ !isSymbolAssignedDefinitely(c, localOrExportSymbol);
511
+ const assumeInitialized = isParameter ||
512
+ isAlias ||
513
+ (isOuterVariable && !isNeverInitialized) ||
514
+ isSpreadDestructuringAssignmentTarget(node) ||
515
+ isModuleExports ||
516
+ isSameScopedBindingElement(node, declaration) ||
517
+ (t !== c.autoType &&
518
+ t !== c.autoArrayType &&
519
+ (!c.strictNullChecks ||
520
+ (t.flags & (3 /* TypeFlags.AnyOrUnknown */ | 16 /* TypeFlags.Void */)) !== 0 ||
521
+ isPartOfTypeQuery(node) ||
522
+ isInAmbientOrTypeNode(node) ||
523
+ node.parent.kind === 282 /* SyntaxKind.ExportSpecifier */)) ||
524
+ node.parent.kind === 236 /* SyntaxKind.NonNullExpression */ ||
525
+ (declaration.kind === 261 /* SyntaxKind.VariableDeclaration */ &&
526
+ declaration.exclamationToken !== undefined) ||
527
+ (declaration.flags & 8388608 /* NodeFlags.Ambient */) !== 0;
528
+ let initialType;
529
+ if (isAutomaticTypeInNonNull)
530
+ initialType = c.undefinedType;
531
+ else if (assumeInitialized && isParameter)
532
+ initialType = removeOptionalityFromDeclaredType(c, t, declaration);
533
+ else if (assumeInitialized)
534
+ initialType = t;
535
+ else if (typeIsAutomatic)
536
+ initialType = c.undefinedType;
537
+ else
538
+ initialType = getOptionalType(c, t, false);
539
+ let flowType = getFlowTypeOfReference(c, node, t, initialType, flowContainer);
540
+ if (isAutomaticTypeInNonNull)
541
+ flowType = getNonNullableType(c, flowType);
542
+ if (!isEvolvingArrayOperationTarget(c, node) && typeIsAutomatic) {
543
+ if (flowType === c.autoType || flowType === c.autoArrayType) {
544
+ if (c.noImplicitAny) {
545
+ c.error(getNameOfDeclaration(declaration), 1705 /* Diagnostics.Variable_0_implicitly_has_type_1_in_some_locations_where_its_type_cannot_be_determined */, symbolToString(c, symbol), typeToString(c, flowType));
546
+ c.error(node, 1678 /* Diagnostics.Variable_0_implicitly_has_an_1_type */, symbolToString(c, symbol), typeToString(c, flowType));
547
+ }
548
+ return convertAutoToAny(c, flowType);
549
+ }
550
+ }
551
+ else if (!assumeInitialized && !containsUndefinedType(t) && containsUndefinedType(flowType)) {
552
+ c.error(node, 621 /* Diagnostics.Variable_0_is_used_before_being_assigned */, symbolToString(c, symbol));
553
+ return t;
554
+ }
555
+ return assignmentKind !== 0 /* AssignmentKind.None */ ? getBaseTypeOfLiteralType(c, flowType) : flowType;
556
+ }
557
+ /**
558
+ * A reference's type with union constraints substituted for generic types where only the
559
+ * constraint matters, so narrowing can apply: in constraint positions like `x.p`, or with a
560
+ * non-generic contextual type.
561
+ */
562
+ export function getNarrowableTypeForReference(c, t, reference, checkMode = 0 /* CheckMode.Normal */) {
563
+ if (isNoInferType(c, t))
564
+ t = t.baseType;
565
+ const substituteConstraints = (checkMode & 2 /* CheckMode.Inferential */) === 0 &&
566
+ someTypeIsGenericWithUnionConstraint(c, t) &&
567
+ (isConstraintPosition(c, t, reference) || hasContextualTypeWithNoGenericTypes(c, reference, checkMode));
568
+ return substituteConstraints ? mapToBaseConstraintOrType(c, t) : t;
569
+ }
570
+ export function someTypeIsGenericWithUnionConstraint(c, t) {
571
+ if ((t.flags & 134217728 /* TypeFlags.Union */) === 0)
572
+ return isGenericTypeWithUnionConstraint(c, t);
573
+ for (const u of typesOf(t))
574
+ if (isGenericTypeWithUnionConstraint(c, u))
575
+ return true;
576
+ return false;
577
+ }
578
+ function isConstraintPosition(c, t, node) {
579
+ const parent = node.parent;
580
+ // `obj[x]` keeps `T[K]` when both are generic and obj's constraint isn't nullable.
581
+ return (parent.kind === 212 /* SyntaxKind.PropertyAccessExpression */ ||
582
+ parent.kind === 167 /* SyntaxKind.QualifiedName */ ||
583
+ ((parent.kind === 214 /* SyntaxKind.CallExpression */ || parent.kind === 215 /* SyntaxKind.NewExpression */) &&
584
+ getExpression(parent) === node) ||
585
+ (parent.kind === 213 /* SyntaxKind.ElementAccessExpression */ &&
586
+ getExpression(parent) === node &&
587
+ !(someType(t, (u) => isGenericTypeWithoutNullableConstraint(c, u)) &&
588
+ isGenericIndexType(c, getTypeOfExpression(c, parent.argumentExpression)))));
589
+ }
590
+ function isGenericTypeWithUnionConstraint(c, t) {
591
+ if ((t.flags & 268435456 /* TypeFlags.Intersection */) !== 0) {
592
+ for (const u of typesOf(t))
593
+ if (isGenericTypeWithUnionConstraint(c, u))
594
+ return true;
595
+ return false;
596
+ }
597
+ return ((t.flags & 132644864 /* TypeFlags.Instantiable */) !== 0 &&
598
+ (getBaseConstraintOrType(c, t).flags & (12 /* TypeFlags.Nullable */ | 134217728 /* TypeFlags.Union */)) !== 0);
599
+ }
600
+ function isGenericTypeWithoutNullableConstraint(c, t) {
601
+ if ((t.flags & 268435456 /* TypeFlags.Intersection */) !== 0) {
602
+ for (const u of typesOf(t))
603
+ if (isGenericTypeWithoutNullableConstraint(c, u))
604
+ return true;
605
+ return false;
606
+ }
607
+ return ((t.flags & 132644864 /* TypeFlags.Instantiable */) !== 0 && !maybeTypeOfKind(getBaseConstraintOrType(c, t), 12 /* TypeFlags.Nullable */));
608
+ }
609
+ function hasContextualTypeWithNoGenericTypes(c, node, checkMode) {
610
+ // JSX tag names are excluded: their contextual type resolves the tag itself.
611
+ if (node.kind !== 79 /* SyntaxKind.Identifier */ &&
612
+ node.kind !== 212 /* SyntaxKind.PropertyAccessExpression */ &&
613
+ node.kind !== 213 /* SyntaxKind.ElementAccessExpression */)
614
+ return false;
615
+ const parent = node.parent;
616
+ if ((parent.kind === 287 /* SyntaxKind.JsxOpeningElement */ || parent.kind === 286 /* SyntaxKind.JsxSelfClosingElement */) &&
617
+ getTagName(parent) === node)
618
+ return false;
619
+ // Rest elements skip binding pattern contextual types, so their type stays generic when possible.
620
+ const contextualType = getContextualTypeEx(c, node, (checkMode & 32 /* CheckMode.RestBindingElement */) !== 0 ? 8 /* ContextFlags.SkipBindingPatterns */ : 0 /* ContextFlags.None */);
621
+ return contextualType !== undefined && !isGenericType(c, contextualType);
622
+ }
623
+ /** Whether `t` is or includes undefined, which includes the missing type of an optional property or element. */
624
+ function containsUndefinedType(t) {
625
+ const u = (t.flags & 134217728 /* TypeFlags.Union */) !== 0 ? t.types[0] : t;
626
+ return (u.flags & 4 /* TypeFlags.Undefined */) !== 0;
627
+ }
628
+ function isDescendantOf(node, ancestor) {
629
+ for (let current = node; current !== undefined; current = current.parent)
630
+ if (current === ancestor)
631
+ return true;
632
+ return false;
633
+ }
634
+ export function isInAmbientOrTypeNode(node) {
635
+ if ((node.flags & 8388608 /* NodeFlags.Ambient */) !== 0)
636
+ return true;
637
+ for (let current = node; current !== undefined; current = current.parent) {
638
+ if (current.kind === 265 /* SyntaxKind.InterfaceDeclaration */ ||
639
+ current.kind === 266 /* SyntaxKind.TypeAliasDeclaration */ ||
640
+ current.kind === 188 /* SyntaxKind.TypeLiteral */)
641
+ return true;
642
+ }
643
+ return false;
644
+ }
645
+ export function checkThisExpression(c, node) {
646
+ // Stop at the first arrow function to tell whether `this` is captured.
647
+ let container = getThisContainer(node, true, true);
648
+ let capturedByArrowFunction = false;
649
+ let thisInComputedPropertyName = false;
650
+ if (container.kind === 177 /* SyntaxKind.Constructor */)
651
+ checkThisBeforeSuper(c, node, container, 1812 /* Diagnostics.X_super_must_be_called_before_accessing_this_in_the_constructor_of_a_derived_class */);
652
+ for (;;) {
653
+ // Skip arrow functions to the real owner of `this`.
654
+ if (container.kind === 220 /* SyntaxKind.ArrowFunction */) {
655
+ container = getThisContainer(container, false, !thisInComputedPropertyName);
656
+ capturedByArrowFunction = true;
657
+ }
658
+ if (container.kind === 168 /* SyntaxKind.ComputedPropertyName */) {
659
+ container = getThisContainer(container, !capturedByArrowFunction, false);
660
+ thisInComputedPropertyName = true;
661
+ continue;
662
+ }
663
+ break;
664
+ }
665
+ checkThisInStaticClassFieldInitializerInDecoratedClass(c, node, container);
666
+ if (thisInComputedPropertyName)
667
+ c.error(node, 631 /* Diagnostics.X_this_cannot_be_referenced_in_a_computed_property_name */);
668
+ else if (container.kind === 268 /* SyntaxKind.ModuleDeclaration */)
669
+ c.error(node, 509 /* Diagnostics.X_this_cannot_be_referenced_in_a_module_or_namespace_body */);
670
+ else if (container.kind === 267 /* SyntaxKind.EnumDeclaration */)
671
+ c.error(node, 510 /* Diagnostics.X_this_cannot_be_referenced_in_current_location */);
672
+ const t = tryGetThisTypeAt(c, node, container);
673
+ if (c.noImplicitThis) {
674
+ const globalThisType = getTypeOfSymbol(c, c.globalThisSymbol);
675
+ if (t === globalThisType && capturedByArrowFunction)
676
+ c.error(node, 1712 /* Diagnostics.The_containing_arrow_function_captures_the_global_value_of_this */);
677
+ else if (t === undefined)
678
+ c.error(node, 816 /* Diagnostics.X_this_implicitly_has_type_any_because_it_does_not_have_a_type_annotation */);
679
+ }
680
+ return t ?? c.anyType;
681
+ }
682
+ function tryGetThisTypeAt(c, node, container) {
683
+ if (isFunctionLike(container) && container.kind !== 177 /* SyntaxKind.Constructor */) {
684
+ const thisType = getThisTypeOfSignature(c, getSignatureOfFullSignatureType(c, container) ?? getSignatureFromDeclaration(c, container)) ?? getContextualThisParameterType(c, container);
685
+ if (thisType !== undefined)
686
+ return getFlowTypeOfReference(c, node, thisType, thisType, undefined);
687
+ }
688
+ const parent = container.parent;
689
+ if (parent !== undefined && isClassLike(parent)) {
690
+ const classSymbol = getSymbolOfDeclaration(c, parent);
691
+ if (classSymbol === undefined)
692
+ return c.anyType;
693
+ const t = isStatic(container) || container.kind === 176 /* SyntaxKind.ClassStaticBlockDeclaration */
694
+ ? getTypeOfSymbol(c, classSymbol)
695
+ : getDeclaredTypeOfClassOrInterface(c, getMergedSymbol(c, classSymbol)).thisType;
696
+ return t !== undefined ? getFlowTypeOfReference(c, node, t, t, undefined) : c.anyType;
697
+ }
698
+ if (container.kind === 307 /* SyntaxKind.SourceFile */) {
699
+ if (container.externalModuleIndicator !== undefined)
700
+ return c.undefinedType;
701
+ return getTypeOfSymbol(c, c.globalThisSymbol);
702
+ }
703
+ return undefined;
704
+ }
705
+ /** The `this` type of a function expression or method from its context, such as its object literal. */
706
+ export function getContextualThisParameterType(c, func) {
707
+ if (func.kind === 220 /* SyntaxKind.ArrowFunction */)
708
+ return undefined;
709
+ if (isContextSensitiveFunctionOrObjectLiteralMethod(c, func)) {
710
+ const signature = getContextualSignatureForFunctionLikeDeclaration(c, func);
711
+ if (signature !== undefined && signature.thisParameter !== undefined)
712
+ return getTypeOfSymbol(c, signature.thisParameter);
713
+ }
714
+ if (!c.noImplicitThis && !isInJSFile(func))
715
+ return undefined;
716
+ const literal = getContainingObjectLiteral(func);
717
+ if (literal !== undefined)
718
+ return getThisTypeOfObjectLiteralMember(c, literal);
719
+ return getThisTypeOfAssignedFunction(c, func);
720
+ }
721
+ function getContainingObjectLiteral(func) {
722
+ const parent = func.parent;
723
+ if ((func.kind === 175 /* SyntaxKind.MethodDeclaration */ ||
724
+ func.kind === 178 /* SyntaxKind.GetAccessor */ ||
725
+ func.kind === 179 /* SyntaxKind.SetAccessor */) &&
726
+ parent.kind === 211 /* SyntaxKind.ObjectLiteralExpression */)
727
+ return parent;
728
+ if (func.kind === 219 /* SyntaxKind.FunctionExpression */ && parent.kind === 303 /* SyntaxKind.PropertyAssignment */)
729
+ return parent.parent;
730
+ return undefined;
731
+ }
732
+ // ---- Literals
733
+ function checkTemplateExpression(c, node) {
734
+ const texts = [getText(node.head)];
735
+ const types = [];
736
+ for (const span of node.templateSpans.nodes) {
737
+ const expression = getExpression(span);
738
+ const t = checkExpression(c, expression);
739
+ if (maybeTypeOfKind(t, 16896 /* TypeFlags.ESSymbolLike */) ||
740
+ maybeTypeOfKind(getBaseConstraintOrType(c, t), 16896 /* TypeFlags.ESSymbolLike */))
741
+ c.error(expression, 863 /* Diagnostics.Implicit_conversion_of_a_symbol_to_a_string_will_fail_at_runtime_Consider_wrapping_this_expression_in_String */);
742
+ texts.push(getText(span.literal));
743
+ types.push(isTypeAssignableTo(c, t, c.templateConstraintType) ? t : c.stringType);
744
+ }
745
+ if (node.parent.kind !== 216 /* SyntaxKind.TaggedTemplateExpression */) {
746
+ const evaluated = evaluate(c, node, node);
747
+ if (evaluated.kind === 2 /* EvaluatedKind.String */)
748
+ return getFreshTypeOfLiteralType(c, getStringLiteralType(c, evaluated.stringValue));
749
+ }
750
+ if (isConstContext(c, node) ||
751
+ isTemplateLiteralContext(node) ||
752
+ someType(getContextualType(c, node) ?? c.unknownType, (t) => isTemplateLiteralContextualType(c, t)))
753
+ return getTemplateLiteralType(c, texts, types);
754
+ return c.stringType;
755
+ }
756
+ function isTemplateLiteralContext(node) {
757
+ const parent = node.parent;
758
+ return ((parent.kind === 218 /* SyntaxKind.ParenthesizedExpression */ && isTemplateLiteralContext(parent)) ||
759
+ (parent.kind === 213 /* SyntaxKind.ElementAccessExpression */ &&
760
+ parent.argumentExpression === node));
761
+ }
762
+ function isTemplateLiteralContextualType(c, t) {
763
+ return ((t.flags & (1024 /* TypeFlags.StringLiteral */ | 4194304 /* TypeFlags.TemplateLiteral */)) !== 0 ||
764
+ ((t.flags & 117964800 /* TypeFlags.InstantiableNonPrimitive */) !== 0 &&
765
+ maybeTypeOfKind(getBaseConstraintOfType(c, t) ?? c.unknownType, 12583968 /* TypeFlags.StringLike */)));
766
+ }
767
+ function checkSpreadExpression(c, node, checkMode) {
768
+ const arrayOrIterableType = checkExpressionEx(c, node.expression, checkMode);
769
+ return checkIteratedTypeOrElementType(c, 33 /* IterationUse.Spread */, arrayOrIterableType, c.undefinedType, node.expression);
770
+ }
771
+ function checkArrayLiteral(c, node, checkMode) {
772
+ const elements = node.elements.nodes;
773
+ const elementTypes = [];
774
+ const elementInfos = [];
775
+ // The elements' contextual types come from the literal's, computed once.
776
+ pushCachedContextualType(c, node);
777
+ const inDestructuringPattern = isAssignmentTarget(node);
778
+ const inConstContext = isConstContext(c, node);
779
+ const contextualType = getApparentTypeOfContextualType(c, node);
780
+ const inTupleContext = isSpreadIntoCallOrNew(node) ||
781
+ (contextualType !== undefined && someType(contextualType, (t) => isTupleLikeContext(c, t)));
782
+ let hasOmittedExpression = false;
783
+ for (const e of elements) {
784
+ if (e.kind === 231 /* SyntaxKind.SpreadElement */) {
785
+ const spreadType = checkExpressionEx(c, e.expression, checkMode);
786
+ if (isArrayLikeType(c, spreadType)) {
787
+ elementTypes.push(spreadType);
788
+ elementInfos.push(new TupleElementInfo(8 /* ElementFlags.Variadic */, undefined));
789
+ }
790
+ else if (inDestructuringPattern) {
791
+ // `[...c] = ...` makes `c` a rest target that only provides a contextual type, so it's not
792
+ // checked as iterable.
793
+ const restElementType = getIndexTypeOfType(c, spreadType, c.numberType) ??
794
+ getIteratedTypeOrElementType(c, 65 /* IterationUse.Destructuring */, spreadType, c.undefinedType, undefined, false) ??
795
+ c.unknownType;
796
+ elementTypes.push(restElementType);
797
+ elementInfos.push(new TupleElementInfo(4 /* ElementFlags.Rest */, undefined));
798
+ }
799
+ else {
800
+ elementTypes.push(checkIteratedTypeOrElementType(c, 33 /* IterationUse.Spread */, spreadType, c.undefinedType, e.expression));
801
+ elementInfos.push(new TupleElementInfo(4 /* ElementFlags.Rest */, undefined));
802
+ }
803
+ }
804
+ else if (c.exactOptionalPropertyTypes && e.kind === 233 /* SyntaxKind.OmittedExpression */) {
805
+ hasOmittedExpression = true;
806
+ elementTypes.push(c.undefinedOrMissingType);
807
+ elementInfos.push(new TupleElementInfo(2 /* ElementFlags.Optional */, undefined));
808
+ }
809
+ else {
810
+ const t = e.kind === 233 /* SyntaxKind.OmittedExpression */
811
+ ? c.undefinedWideningType
812
+ : checkExpressionForMutableLocationEx(c, e, checkMode);
813
+ if (inTupleContext &&
814
+ (checkMode & 2 /* CheckMode.Inferential */) !== 0 &&
815
+ (checkMode & 4 /* CheckMode.SkipContextSensitive */) === 0 &&
816
+ isContextSensitive(c, e)) {
817
+ // Inferences flowing between context-sensitive tuple elements are made before fixing.
818
+ const inferenceContext = getInferenceContext(c, node);
819
+ if (inferenceContext !== undefined)
820
+ addIntraExpressionInferenceSite(inferenceContext, e, t);
821
+ }
822
+ elementTypes.push(addOptionality(c, t, true, hasOmittedExpression));
823
+ elementInfos.push(new TupleElementInfo(hasOmittedExpression ? 2 /* ElementFlags.Optional */ : 1 /* ElementFlags.Required */, undefined));
824
+ }
825
+ }
826
+ popContextualType(c);
827
+ if (inDestructuringPattern)
828
+ return createTupleTypeEx(c, elementTypes, elementInfos, false);
829
+ if (inConstContext || inTupleContext || (checkMode & 128 /* CheckMode.ForceTuple */) !== 0)
830
+ return createArrayLiteralType(c, createTupleTypeEx(c, elementTypes, elementInfos, inConstContext &&
831
+ !(contextualType !== undefined && someType(contextualType, (t) => isMutableArrayLikeType(c, t)))));
832
+ let elementType;
833
+ if (elementTypes.length > 0) {
834
+ for (let i = 0; i < elementTypes.length; i++)
835
+ if ((elementInfos[i].flags & 8 /* ElementFlags.Variadic */) !== 0)
836
+ elementTypes[i] =
837
+ getIndexedAccessTypeOrUndefinedEx(c, elementTypes[i], c.numberType, 0 /* AccessFlags.None */, undefined, undefined) ?? c.anyType;
838
+ elementType = getUnionTypeEx(c, elementTypes, 2 /* UnionReduction.Subtype */, undefined, undefined);
839
+ }
840
+ else
841
+ elementType = c.strictNullChecks ? c.implicitNeverType : c.undefinedWideningType;
842
+ return createArrayLiteralType(c, createArrayTypeEx(c, elementType, inConstContext));
843
+ }
844
+ function isSpreadIntoCallOrNew(node) {
845
+ let parent = node.parent;
846
+ while (parent.kind === 218 /* SyntaxKind.ParenthesizedExpression */)
847
+ parent = parent.parent;
848
+ return (parent.kind === 231 /* SyntaxKind.SpreadElement */ &&
849
+ (parent.parent.kind === 214 /* SyntaxKind.CallExpression */ || parent.parent.kind === 215 /* SyntaxKind.NewExpression */));
850
+ }
851
+ function isTupleLikeContext(c, t) {
852
+ if (isTupleLikeType(c, t))
853
+ return true;
854
+ if (!isGenericMappedType(c, t))
855
+ return false;
856
+ const mapped = t;
857
+ if (mapped.nameType !== undefined)
858
+ return false;
859
+ const target = mapped.target;
860
+ return getHomomorphicTypeVariable(c, target !== undefined ? target : mapped) !== undefined;
861
+ }
862
+ export function isTupleLikeType(c, t) {
863
+ if (isTupleType(t) || getPropertyOfType(c, t, '0') !== undefined)
864
+ return true;
865
+ if (!isArrayLikeType(c, t))
866
+ return false;
867
+ const lengthType = getTypeOfPropertyOfType(c, t, 'length');
868
+ return lengthType !== undefined && everyType(lengthType, (u) => (u.flags & 2048 /* TypeFlags.NumberLiteral */) !== 0);
869
+ }
870
+ /** Whether `t` is a mutable array, a mutable tuple, or assignable to `any[]`. */
871
+ export function isMutableArrayLikeType(c, t) {
872
+ return (isMutableArrayOrTuple(c, t) ||
873
+ ((t.flags & (1 /* TypeFlags.Any */ | 12 /* TypeFlags.Nullable */)) === 0 && isTypeAssignableTo(c, t, c.anyArrayType)));
874
+ }
875
+ function createArrayLiteralType(c, t) {
876
+ if ((t.objectFlags & 4 /* ObjectFlags.Reference */) === 0)
877
+ return t;
878
+ const key = cachedTypeKey(7 /* CachedTypeKind.ArrayLiteral */, t.id);
879
+ let literal = c.cachedTypesById.get(key);
880
+ if (literal === undefined) {
881
+ literal = cloneTypeReference(c, t);
882
+ literal.objectFlags |= 16384 /* ObjectFlags.ArrayLiteral */ | 131072 /* ObjectFlags.ContainsObjectOrArrayLiteral */;
883
+ c.cachedTypesById.set(key, literal);
884
+ }
885
+ return literal;
886
+ }
887
+ /** The name of an object literal element, or undefined when it's computed and not a literal. */
888
+ export function getPropertyNameOfObjectLiteralElement(c, element) {
889
+ const name = getName(element);
890
+ if (name === undefined)
891
+ return undefined;
892
+ switch (name.kind) {
893
+ case 79 /* SyntaxKind.Identifier */:
894
+ case 80 /* SyntaxKind.PrivateIdentifier */:
895
+ case 10 /* SyntaxKind.StringLiteral */:
896
+ case 14 /* SyntaxKind.NoSubstitutionTemplateLiteral */:
897
+ return getText(name);
898
+ case 8 /* SyntaxKind.NumericLiteral */:
899
+ return String(Number(getText(name)));
900
+ case 9 /* SyntaxKind.BigIntLiteral */:
901
+ return parseBigIntText(getText(name));
902
+ case 168 /* SyntaxKind.ComputedPropertyName */: {
903
+ const t = checkComputedPropertyName(c, name);
904
+ return isTypeUsableAsPropertyName(t) ? getPropertyNameFromType(t) : undefined;
905
+ }
906
+ }
907
+ return undefined;
908
+ }
909
+ /** Whether `node` is in an `as const` context, where literals keep their types. */
910
+ export function isConstContext(c, node) {
911
+ const parent = node.parent;
912
+ if (parent === undefined)
913
+ return false;
914
+ // Literals contextually typed by a `const` type parameter are in a const context.
915
+ if (isValidConstAssertionArgument(c, node) && isConstTypeVariable(c, getContextualType(c, node), 0))
916
+ return true;
917
+ switch (parent.kind) {
918
+ case 235 /* SyntaxKind.AsExpression */:
919
+ case 217 /* SyntaxKind.TypeAssertionExpression */:
920
+ return isConstTypeReference(getType(parent));
921
+ // As in tsgo, a const context does not reach through `satisfies` or into the branches of a
922
+ // conditional expression: those are in one only when their own contextual type is a `const`
923
+ // type parameter (above).
924
+ case 218 /* SyntaxKind.ParenthesizedExpression */:
925
+ case 210 /* SyntaxKind.ArrayLiteralExpression */:
926
+ case 231 /* SyntaxKind.SpreadElement */:
927
+ return isConstContext(c, parent);
928
+ case 303 /* SyntaxKind.PropertyAssignment */:
929
+ case 304 /* SyntaxKind.ShorthandPropertyAssignment */:
930
+ return isConstContext(c, parent.parent);
931
+ case 240 /* SyntaxKind.TemplateSpan */:
932
+ return isConstContext(c, parent.parent);
933
+ }
934
+ return false;
935
+ }
936
+ /** Whether `as const` applies to the expression: a literal, or a reference to an enum member. */
937
+ function isValidConstAssertionArgument(c, node) {
938
+ switch (node.kind) {
939
+ case 10 /* SyntaxKind.StringLiteral */:
940
+ case 14 /* SyntaxKind.NoSubstitutionTemplateLiteral */:
941
+ case 8 /* SyntaxKind.NumericLiteral */:
942
+ case 9 /* SyntaxKind.BigIntLiteral */:
943
+ case 111 /* SyntaxKind.TrueKeyword */:
944
+ case 96 /* SyntaxKind.FalseKeyword */:
945
+ case 210 /* SyntaxKind.ArrayLiteralExpression */:
946
+ case 211 /* SyntaxKind.ObjectLiteralExpression */:
947
+ case 229 /* SyntaxKind.TemplateExpression */:
948
+ return true;
949
+ case 218 /* SyntaxKind.ParenthesizedExpression */:
950
+ return isValidConstAssertionArgument(c, getExpression(node));
951
+ case 225 /* SyntaxKind.PrefixUnaryExpression */: {
952
+ const unary = node;
953
+ const kind = unary.operand.kind;
954
+ return ((unary.operator === 40 /* SyntaxKind.MinusToken */ &&
955
+ (kind === 8 /* SyntaxKind.NumericLiteral */ || kind === 9 /* SyntaxKind.BigIntLiteral */)) ||
956
+ (unary.operator === 39 /* SyntaxKind.PlusToken */ && kind === 8 /* SyntaxKind.NumericLiteral */));
957
+ }
958
+ case 212 /* SyntaxKind.PropertyAccessExpression */:
959
+ case 213 /* SyntaxKind.ElementAccessExpression */: {
960
+ const expr = skipParentheses(getExpression(node));
961
+ const symbol = isEntityNameExpression(expr, false)
962
+ ? resolveEntityName(c, expr, 111551 /* SymbolFlags.Value */, true, false, undefined)
963
+ : undefined;
964
+ return symbol !== undefined && (symbol.flags & 384 /* SymbolFlags.Enum */) !== 0;
965
+ }
966
+ }
967
+ return false;
968
+ }
969
+ export function isConstTypeReference(node) {
970
+ if (node.kind !== 184 /* SyntaxKind.TypeReference */)
971
+ return false;
972
+ const ref = node;
973
+ return (ref.typeName.kind === 79 /* SyntaxKind.Identifier */ && getText(ref.typeName) === 'const' && ref.typeArguments === undefined);
974
+ }
975
+ /** Widens a literal type unless the contextual type calls for literals of its kind. */
976
+ export function getWidenedLiteralLikeTypeForContextualType(c, t, contextualType) {
977
+ if (!isLiteralOfContextualType(c, t, contextualType))
978
+ return getWidenedUniqueESSymbolType(c, getWidenedLiteralType(c, t));
979
+ return getRegularTypeOfLiteralType(c, t);
980
+ }
981
+ export function isLiteralOfContextualType(c, candidate, contextualType) {
982
+ if (contextualType === undefined)
983
+ return false;
984
+ if ((contextualType.flags & 402653184 /* TypeFlags.UnionOrIntersection */) !== 0) {
985
+ for (const t of typesOf(contextualType))
986
+ if (isLiteralOfContextualType(c, candidate, t))
987
+ return true;
988
+ return false;
989
+ }
990
+ if ((contextualType.flags & 117964800 /* TypeFlags.InstantiableNonPrimitive */) !== 0) {
991
+ const constraint = getBaseConstraintOfType(c, contextualType) ?? c.unknownType;
992
+ return ((maybeTypeOfKind(constraint, 32 /* TypeFlags.String */) && maybeTypeOfKind(candidate, 1024 /* TypeFlags.StringLiteral */)) ||
993
+ (maybeTypeOfKind(constraint, 64 /* TypeFlags.Number */) && maybeTypeOfKind(candidate, 2048 /* TypeFlags.NumberLiteral */)) ||
994
+ (maybeTypeOfKind(constraint, 128 /* TypeFlags.BigInt */) && maybeTypeOfKind(candidate, 4096 /* TypeFlags.BigIntLiteral */)) ||
995
+ (maybeTypeOfKind(constraint, 512 /* TypeFlags.ESSymbol */) && maybeTypeOfKind(candidate, 16384 /* TypeFlags.UniqueESSymbol */)) ||
996
+ isLiteralOfContextualType(c, candidate, constraint));
997
+ }
998
+ return (((contextualType.flags &
999
+ (1024 /* TypeFlags.StringLiteral */ | 2097152 /* TypeFlags.Index */ | 4194304 /* TypeFlags.TemplateLiteral */ | 8388608 /* TypeFlags.StringMapping */)) !==
1000
+ 0 &&
1001
+ maybeTypeOfKind(candidate, 1024 /* TypeFlags.StringLiteral */)) ||
1002
+ ((contextualType.flags & 2048 /* TypeFlags.NumberLiteral */) !== 0 && maybeTypeOfKind(candidate, 2048 /* TypeFlags.NumberLiteral */)) ||
1003
+ ((contextualType.flags & 4096 /* TypeFlags.BigIntLiteral */) !== 0 && maybeTypeOfKind(candidate, 4096 /* TypeFlags.BigIntLiteral */)) ||
1004
+ ((contextualType.flags & 8192 /* TypeFlags.BooleanLiteral */) !== 0 && maybeTypeOfKind(candidate, 8192 /* TypeFlags.BooleanLiteral */)) ||
1005
+ ((contextualType.flags & 16384 /* TypeFlags.UniqueESSymbol */) !== 0 && maybeTypeOfKind(candidate, 16384 /* TypeFlags.UniqueESSymbol */)));
1006
+ }
1007
+ // ---- Property and element access
1008
+ /**
1009
+ * The type of an expression used as an object, with `null` and `undefined` removed. Without
1010
+ * narrowing, nullability errors are only reported where no narrowing could apply.
1011
+ */
1012
+ export function checkNonNullExpression(c, node) {
1013
+ return checkNonNullType(c, checkExpression(c, node), node);
1014
+ }
1015
+ export function checkNonNullType(c, t, node) {
1016
+ return checkNonNullTypeEx(c, t, node, false);
1017
+ }
1018
+ /** `checkNonNullType`, reporting a possibly nullish callee of a call when `isCallee`. */
1019
+ export function checkNonNullTypeEx(c, t, node, isCallee) {
1020
+ if (c.strictNullChecks && (t.flags & 2 /* TypeFlags.Unknown */) !== 0) {
1021
+ if (isEntityNameExpression(node, false)) {
1022
+ const nodeText = entityNameToString(node);
1023
+ if (nodeText.length < 100) {
1024
+ c.error(node, 1862 /* Diagnostics.X_0_is_of_type_unknown */, nodeText);
1025
+ return c.errorType;
1026
+ }
1027
+ }
1028
+ c.error(node, 724 /* Diagnostics.Object_is_of_type_unknown */);
1029
+ return c.errorType;
1030
+ }
1031
+ const facts = getTypeFacts(c, t, 50331648 /* TypeFacts.IsUndefinedOrNull */);
1032
+ if ((facts & 50331648 /* TypeFacts.IsUndefinedOrNull */) !== 0) {
1033
+ if (isCallee)
1034
+ reportCannotInvokePossiblyNullOrUndefinedError(c, node, facts);
1035
+ else
1036
+ reportObjectPossiblyNullOrUndefinedError(c, node, facts);
1037
+ const nonNullable = getNonNullableType(c, t);
1038
+ return (nonNullable.flags & (12 /* TypeFlags.Nullable */ | 262144 /* TypeFlags.Never */)) !== 0 ? c.errorType : nonNullable;
1039
+ }
1040
+ return t;
1041
+ }
1042
+ function reportCannotInvokePossiblyNullOrUndefinedError(c, node, facts) {
1043
+ c.error(node, (facts & 16777216 /* TypeFacts.IsUndefined */) !== 0
1044
+ ? (facts & 33554432 /* TypeFacts.IsNull */) !== 0
1045
+ ? 855 /* Diagnostics.Cannot_invoke_an_object_which_is_possibly_null_or_undefined */
1046
+ : 854 /* Diagnostics.Cannot_invoke_an_object_which_is_possibly_undefined */
1047
+ : 853 /* Diagnostics.Cannot_invoke_an_object_which_is_possibly_null */);
1048
+ }
1049
+ function reportObjectPossiblyNullOrUndefinedError(c, node, facts) {
1050
+ if (node.kind === 105 /* SyntaxKind.NullKeyword */) {
1051
+ c.error(node, 1866 /* Diagnostics.The_value_0_cannot_be_used_here */, 'null');
1052
+ return;
1053
+ }
1054
+ const nodeText = isEntityNameExpression(node, false) ? entityNameToString(node) : '';
1055
+ if (nodeText !== '' && nodeText.length < 100) {
1056
+ if (node.kind === 79 /* SyntaxKind.Identifier */ && nodeText === 'undefined') {
1057
+ c.error(node, 1866 /* Diagnostics.The_value_0_cannot_be_used_here */, 'undefined');
1058
+ return;
1059
+ }
1060
+ c.error(node, (facts & 16777216 /* TypeFacts.IsUndefined */) !== 0
1061
+ ? (facts & 33554432 /* TypeFacts.IsNull */) !== 0
1062
+ ? 1865 /* Diagnostics.X_0_is_possibly_null_or_undefined */
1063
+ : 1864 /* Diagnostics.X_0_is_possibly_undefined */
1064
+ : 1863 /* Diagnostics.X_0_is_possibly_null */, nodeText);
1065
+ }
1066
+ else {
1067
+ c.error(node, (facts & 16777216 /* TypeFacts.IsUndefined */) !== 0
1068
+ ? (facts & 33554432 /* TypeFacts.IsNull */) !== 0
1069
+ ? 691 /* Diagnostics.Object_is_possibly_null_or_undefined */
1070
+ : 690 /* Diagnostics.Object_is_possibly_undefined */
1071
+ : 689 /* Diagnostics.Object_is_possibly_null */);
1072
+ }
1073
+ }
1074
+ /** `checkNonNullType`, also reporting a `void` type as possibly undefined. */
1075
+ export function checkNonNullNonVoidType(c, t, node) {
1076
+ const nonNullType = checkNonNullType(c, t, node);
1077
+ if ((nonNullType.flags & 16 /* TypeFlags.Void */) === 0)
1078
+ return nonNullType;
1079
+ if (isEntityNameExpression(node, false)) {
1080
+ const nodeText = entityNameToString(node);
1081
+ if (node.kind === 79 /* SyntaxKind.Identifier */ && nodeText === 'undefined') {
1082
+ c.error(node, 1866 /* Diagnostics.The_value_0_cannot_be_used_here */, nodeText);
1083
+ return nonNullType;
1084
+ }
1085
+ if (nodeText.length < 100) {
1086
+ c.error(node, 1864 /* Diagnostics.X_0_is_possibly_undefined */, nodeText);
1087
+ return nonNullType;
1088
+ }
1089
+ }
1090
+ c.error(node, 690 /* Diagnostics.Object_is_possibly_undefined */);
1091
+ return nonNullType;
1092
+ }
1093
+ export function entityNameToString(node) {
1094
+ switch (node.kind) {
1095
+ case 79 /* SyntaxKind.Identifier */:
1096
+ return getText(node);
1097
+ case 109 /* SyntaxKind.ThisKeyword */:
1098
+ return 'this';
1099
+ case 212 /* SyntaxKind.PropertyAccessExpression */: {
1100
+ const access = node;
1101
+ return entityNameToString(access.expression) + '.' + entityNameToString(access.name);
1102
+ }
1103
+ case 167 /* SyntaxKind.QualifiedName */: {
1104
+ const q = node;
1105
+ return entityNameToString(q.left) + '.' + q.right.text;
1106
+ }
1107
+ }
1108
+ return getText(node);
1109
+ }
1110
+ /** The type of `obj.name`; `writeOnly` gives the type it can be assigned, as for compound assignments. */
1111
+ export function checkPropertyAccessExpression(c, node, writeOnly, checkMode = 0 /* CheckMode.Normal */) {
1112
+ if (!isOptionalChain(node))
1113
+ return checkPropertyAccessExpressionOrQualifiedName(c, node, node.expression, checkNonNullExpression(c, node.expression), node.name, writeOnly, checkMode);
1114
+ const leftType = checkExpression(c, node.expression);
1115
+ const nonOptional = getOptionalExpressionType(c, leftType, node.expression);
1116
+ const t = checkPropertyAccessExpressionOrQualifiedName(c, node, node.expression, checkNonNullType(c, nonOptional, node.expression), node.name, writeOnly, checkMode);
1117
+ return propagateOptionalTypeMarker(c, t, node, nonOptional !== leftType);
1118
+ }
1119
+ export function checkQualifiedName(c, node) {
1120
+ const leftType = checkNonNullExpressionOfEntity(c, node.left);
1121
+ return checkPropertyAccessExpressionOrQualifiedName(c, node, node.left, leftType, node.right, false);
1122
+ }
1123
+ function checkNonNullExpressionOfEntity(c, node) {
1124
+ if (node.kind === 79 /* SyntaxKind.Identifier */)
1125
+ return checkNonNullType(c, checkIdentifier(c, node), node);
1126
+ return checkNonNullType(c, checkQualifiedName(c, node), node);
1127
+ }
1128
+ export function getFlowTypeOfAccessExpression(c, node, prop, propTypeIn, errorNode, checkMode = 0 /* CheckMode.Normal */) {
1129
+ let propType = propTypeIn;
1130
+ const assignmentKind = getAssignmentTargetKind(node);
1131
+ if (assignmentKind === 1 /* AssignmentKind.Definite */)
1132
+ return removeMissingType(c, propType, prop !== undefined && (prop.flags & 16777216 /* SymbolFlags.Optional */) !== 0);
1133
+ if (prop !== undefined &&
1134
+ (prop.flags & (3 /* SymbolFlags.Variable */ | 4 /* SymbolFlags.Property */ | 98304 /* SymbolFlags.Accessor */)) === 0 &&
1135
+ !((prop.flags & 8192 /* SymbolFlags.Method */) !== 0 && (propType.flags & 134217728 /* TypeFlags.Union */) !== 0))
1136
+ return propType;
1137
+ if (propType === c.autoType)
1138
+ return getFlowTypeOfAutoTypedProperty(c, node, prop);
1139
+ propType = getNarrowableTypeForReference(c, propType, node, checkMode);
1140
+ // `this.x` in the constructor of x's class starts out uninitialized under strictPropertyInitialization.
1141
+ let assumeUninitialized = false;
1142
+ const expression = getExpression(node);
1143
+ if (c.strictNullChecks &&
1144
+ c.strictPropertyInitialization &&
1145
+ expression !== undefined &&
1146
+ expression.kind === 109 /* SyntaxKind.ThisKeyword */ &&
1147
+ prop !== undefined) {
1148
+ const declaration = prop.valueDeclaration;
1149
+ if (declaration !== undefined && isPropertyWithoutInitializer(declaration) && !isStatic(declaration)) {
1150
+ const flowContainer = getControlFlowContainer(node);
1151
+ assumeUninitialized =
1152
+ flowContainer.kind === 177 /* SyntaxKind.Constructor */ &&
1153
+ flowContainer.parent === declaration.parent &&
1154
+ (declaration.flags & 8388608 /* NodeFlags.Ambient */) === 0;
1155
+ }
1156
+ }
1157
+ // A JavaScript `this.x = …` declaration is unassigned before it in its own function.
1158
+ if (c.strictNullChecks && prop !== undefined && !assumeUninitialized) {
1159
+ const declaration = prop.valueDeclaration;
1160
+ assumeUninitialized =
1161
+ declaration instanceof BinaryExpression &&
1162
+ declaration.left.kind === 212 /* SyntaxKind.PropertyAccessExpression */ &&
1163
+ getControlFlowContainer(node) === getControlFlowContainer(declaration);
1164
+ }
1165
+ const initialType = assumeUninitialized ? getOptionalType(c, propType, false) : propType;
1166
+ const flowType = getFlowTypeOfReference(c, node, propType, initialType, undefined);
1167
+ if (assumeUninitialized && !containsUndefinedType(propType) && containsUndefinedType(flowType)) {
1168
+ c.error(errorNode, 719 /* Diagnostics.Property_0_is_used_before_being_assigned */, symbolToString(c, prop));
1169
+ return propType;
1170
+ }
1171
+ return assignmentKind !== 0 /* AssignmentKind.None */ ? getBaseTypeOfLiteralType(c, flowType) : flowType;
1172
+ }
1173
+ function isPropertyWithoutInitializer(node) {
1174
+ return (node.kind === 173 /* SyntaxKind.PropertyDeclaration */ &&
1175
+ !hasSyntacticModifier(node, 64 /* ModifierFlags.Abstract */) &&
1176
+ node.postfixToken === undefined &&
1177
+ getInitializer(node) === undefined);
1178
+ }
1179
+ function checkElementAccessExpression(c, node, _checkMode) {
1180
+ let exprType = checkExpression(c, node.expression);
1181
+ let wasOptional = false;
1182
+ if (isOptionalChain(node)) {
1183
+ const nonOptional = getOptionalExpressionType(c, exprType, node.expression);
1184
+ wasOptional = nonOptional !== exprType;
1185
+ exprType = checkNonNullType(c, nonOptional, node.expression);
1186
+ }
1187
+ else
1188
+ exprType = checkNonNullType(c, exprType, node.expression);
1189
+ const indexExpression = node.argumentExpression;
1190
+ const indexType = checkExpression(c, indexExpression);
1191
+ if (isErrorType(c, exprType) || exprType === c.silentNeverType)
1192
+ return exprType;
1193
+ const assignmentKind = getAssignmentTargetKind(node);
1194
+ const isAssignment = assignmentKind !== 0 /* AssignmentKind.None */;
1195
+ const objectType = isAssignment || isMethodAccessForCall(node) ? getWidenedType(c, exprType) : exprType;
1196
+ if (isConstEnumObjectTypeLocal(objectType) && !isStringLiteralLike(indexExpression)) {
1197
+ c.error(indexExpression, 640 /* Diagnostics.A_const_enum_member_can_only_be_accessed_using_a_string_literal */);
1198
+ return c.errorType;
1199
+ }
1200
+ const effectiveIndexType = isForInVariableForNumericPropertyNames(c, indexExpression) ? c.numberType : indexType;
1201
+ // A compound assignment (`a[i] += 1`, `a[i]++`) also reads the element.
1202
+ const accessFlags = isAssignment
1203
+ ? 4 /* AccessFlags.Writing */ |
1204
+ (assignmentKind === 2 /* AssignmentKind.Compound */ ? 32 /* AccessFlags.ExpressionPosition */ : 0) |
1205
+ (isGenericObjectType(c, objectType) && !isThisTypeParameter(objectType) ? 2 /* AccessFlags.NoIndexSignatures */ : 0)
1206
+ : 32 /* AccessFlags.ExpressionPosition */;
1207
+ const indexedAccessType = getIndexedAccessTypeOrUndefinedEx(c, objectType, effectiveIndexType, accessFlags, node, undefined) ?? c.errorType;
1208
+ const t = checkIndexedAccessIndexType(c, getFlowTypeOfAccessExpression(c, node, c.resolvedSymbols.get(node.id), indexedAccessType, indexExpression), node);
1209
+ return propagateOptionalTypeMarker(c, t, node, wasOptional);
1210
+ }
1211
+ /** Checks that the index of a generic indexed access is assignable to `keyof` its object type. */
1212
+ export function checkIndexedAccessIndexType(c, t, accessNode) {
1213
+ if ((t.flags & 33554432 /* TypeFlags.IndexedAccess */) === 0)
1214
+ return t;
1215
+ const objectType = t.objectType;
1216
+ const indexType = t.indexType;
1217
+ // Remapping mapped types don't defer their index types.
1218
+ const objectIndexType = isGenericMappedType(c, objectType) &&
1219
+ getMappedTypeNameTypeKind(c, objectType) === 2 /* MappedTypeNameTypeKind.Remapping */
1220
+ ? getIndexForMappedType(c, objectType, 0 /* IndexFlags.None */)
1221
+ : getIndexTypeEx(c, objectType, 0 /* IndexFlags.None */);
1222
+ const hasNumberIndexInfo = getIndexInfoOfType(c, objectType, c.numberType) !== undefined;
1223
+ if (everyType(indexType, (u) => isTypeAssignableTo(c, u, objectIndexType) || (hasNumberIndexInfo && isApplicableIndexType(c, u, c.numberType)))) {
1224
+ if (accessNode.kind === 213 /* SyntaxKind.ElementAccessExpression */ &&
1225
+ isAssignmentTarget(accessNode) &&
1226
+ (objectType.objectFlags & 32 /* ObjectFlags.Mapped */) !== 0 &&
1227
+ (getMappedTypeModifiers(objectType) & 1 /* MappedTypeModifiers.IncludeReadonly */) !== 0)
1228
+ c.error(accessNode, 698 /* Diagnostics.Index_signature_in_type_0_only_permits_reading */, typeToString(c, objectType));
1229
+ return t;
1230
+ }
1231
+ if (isGenericObjectType(c, objectType)) {
1232
+ const propertyName = getPropertyNameFromIndex(indexType);
1233
+ if (propertyName !== undefined) {
1234
+ const propertySymbol = getConstituentProperty(c, objectType, propertyName);
1235
+ if (propertySymbol !== undefined &&
1236
+ (getDeclarationModifierFlagsFromSymbol(c, propertySymbol, false) &
1237
+ 6 /* ModifierFlags.NonPublicAccessibilityModifier */) !==
1238
+ 0) {
1239
+ c.error(accessNode, 1091 /* Diagnostics.Private_or_protected_member_0_cannot_be_accessed_on_a_type_parameter */, propertyName);
1240
+ return c.errorType;
1241
+ }
1242
+ }
1243
+ }
1244
+ c.error(accessNode, 693 /* Diagnostics.Type_0_cannot_be_used_to_index_type_1 */, typeToString(c, indexType), typeToString(c, objectType));
1245
+ return c.errorType;
1246
+ }
1247
+ function getConstituentProperty(c, objectType, propertyName) {
1248
+ const apparentType = getApparentType(c, objectType);
1249
+ const constituents = (apparentType.flags & 402653184 /* TypeFlags.UnionOrIntersection */) !== 0 ? typesOf(apparentType) : [apparentType];
1250
+ for (const t of constituents) {
1251
+ const prop = getPropertyOfType(c, t, propertyName);
1252
+ if (prop !== undefined)
1253
+ return prop;
1254
+ }
1255
+ return undefined;
1256
+ }
1257
+ function isStringLiteralLike(node) {
1258
+ return node.kind === 10 /* SyntaxKind.StringLiteral */ || node.kind === 14 /* SyntaxKind.NoSubstitutionTemplateLiteral */;
1259
+ }
1260
+ function isConstEnumObjectTypeLocal(t) {
1261
+ return ((t.objectFlags & 16 /* ObjectFlags.Anonymous */) !== 0 &&
1262
+ t.symbol !== undefined &&
1263
+ (t.symbol.flags & 128 /* SymbolFlags.ConstEnum */) !== 0);
1264
+ }
1265
+ function isThisTypeParameter(t) {
1266
+ return (t.flags & 524288 /* TypeFlags.TypeParameter */) !== 0 && t.isThisType;
1267
+ }
1268
+ function isForInVariableForNumericPropertyNames(c, expr) {
1269
+ const e = skipParentheses(expr);
1270
+ if (e.kind !== 79 /* SyntaxKind.Identifier */)
1271
+ return false;
1272
+ const symbol = getResolvedSymbol(c, e);
1273
+ if ((symbol.flags & 3 /* SymbolFlags.Variable */) === 0)
1274
+ return false;
1275
+ let child = expr;
1276
+ let node = expr.parent;
1277
+ while (node !== undefined) {
1278
+ if (node.kind === 250 /* SyntaxKind.ForInStatement */) {
1279
+ const statement = node;
1280
+ if (child === statement.statement &&
1281
+ getForInVariableSymbol(c, statement) === symbol &&
1282
+ hasNumericPropertyNames(c, getTypeOfExpression(c, statement.expression)))
1283
+ return true;
1284
+ }
1285
+ child = node;
1286
+ node = node.parent;
1287
+ }
1288
+ return false;
1289
+ }
1290
+ function getForInVariableSymbol(c, node) {
1291
+ const initializer = node.initializer;
1292
+ if (initializer.kind === 262 /* SyntaxKind.VariableDeclarationList */) {
1293
+ const declarations = initializer.declarations.nodes;
1294
+ return declarations.length > 0 ? getSymbolOfDeclaration(c, declarations[0]) : undefined;
1295
+ }
1296
+ return initializer.kind === 79 /* SyntaxKind.Identifier */ ? getResolvedSymbol(c, initializer) : undefined;
1297
+ }
1298
+ function hasNumericPropertyNames(c, t) {
1299
+ return getIndexInfosOfType(c, t).length === 1 && getIndexInfoOfType(c, t, c.numberType) !== undefined;
1300
+ }
1301
+ // ---- Assertions
1302
+ function checkAssertion(c, node, checkMode) {
1303
+ // `<T>expr`, over `<T>`.
1304
+ if (node.kind === 217 /* SyntaxKind.TypeAssertionExpression */ && shouldCheckErasableSyntax(c, node)) {
1305
+ const file = getSourceFileOfNode(node);
1306
+ c.addDiagnostic(new Diagnostic(file.diagnosticFile(), skipTrivia(file.text, node.pos), getExpression(node).pos, 243 /* Diagnostics.This_syntax_is_not_allowed_when_erasableSyntaxOnly_is_enabled */, []));
1307
+ }
1308
+ if (isConstTypeReference(getType(node))) {
1309
+ const exprType = checkExpressionEx(c, getExpression(node), checkMode);
1310
+ if (!isValidConstAssertionArgument(c, getExpression(node)))
1311
+ c.error(getExpression(node), 289 /* Diagnostics.A_const_assertion_can_only_be_applied_to_references_to_enum_members_or_string_number_boolean_array_or_object_literals */);
1312
+ return getRegularTypeOfLiteralType(c, exprType);
1313
+ }
1314
+ const exprType = checkExpressionEx(c, getExpression(node), checkMode);
1315
+ // The operand is compared with the asserted type once, after the last check of the operand.
1316
+ c.nodeLinks(node).assertionExpressionType = exprType;
1317
+ checkTypeNodeIfPresent(c, getType(node));
1318
+ checkNodeDeferred(c, node);
1319
+ return getTypeFromTypeNode(c, getType(node));
1320
+ }
1321
+ /** Checks that an assertion's operand type and asserted type are comparable. */
1322
+ export function checkAssertionDeferred(c, node) {
1323
+ const typeNode = getType(node);
1324
+ const targetType = getTypeFromTypeNode(c, typeNode);
1325
+ // A JSDoc cast reports on its type.
1326
+ const errorNode = (typeNode.flags & 8 /* NodeFlags.Reparsed */) !== 0 ? typeNode : node;
1327
+ if (!isErrorType(c, targetType))
1328
+ checkAssertionCompatibility(c, errorNode, c.nodeLinks(node).assertionExpressionType, targetType);
1329
+ }
1330
+ function checkAssertionCompatibility(c, node, rawExprType, targetType) {
1331
+ const exprType = getRegularTypeOfObjectLiteral(c, getBaseTypeOfLiteralType(c, rawExprType));
1332
+ if (isErrorType(c, targetType))
1333
+ return;
1334
+ if (!isTypeComparableTo(c, targetType, getWidenedType(c, exprType)))
1335
+ checkTypeComparableTo(c, exprType, targetType, node, 528 /* Diagnostics.Conversion_of_type_0_to_type_1_may_be_a_mistake_because_neither_type_sufficiently_overlaps_with_the_other_If_this_was_intentional_convert_the_expression_to_unknown_first */);
1336
+ }
1337
+ function checkSatisfiesExpression(c, node, checkMode) {
1338
+ const expr = getExpression(node);
1339
+ const typeNode = getType(node);
1340
+ checkTypeNodeIfPresent(c, typeNode);
1341
+ const exprType = checkExpressionEx(c, expr, checkMode);
1342
+ const targetType = getTypeFromTypeNode(c, typeNode);
1343
+ if (isErrorType(c, targetType))
1344
+ return targetType;
1345
+ checkTypeRelatedToAndOptionallyElaborate(c, exprType, targetType, c.assignableRelation, node, expr, 294 /* Diagnostics.Type_0_does_not_satisfy_the_expected_type_1 */, undefined);
1346
+ return exprType;
1347
+ }
1348
+ /** Reports `source` not assignable to `target` at `errorNode`. */
1349
+ export function checkTypeAssignableToAndOptionallyElaborate(c, source, target, errorNode, expr) {
1350
+ return checkTypeRelatedToAndOptionallyElaborate(c, source, target, c.assignableRelation, errorNode, expr, undefined, undefined);
1351
+ }