tsc-ts 0.0.4 → 0.0.6

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 +34 -2
  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 +2351 -0
  5. package/dist/api/compiler/ast.js +11212 -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 +1241 -0
  10. package/dist/api/compiler/binder.d.ts +33 -0
  11. package/dist/api/compiler/binder.js +2359 -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 +1641 -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 +357 -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 +788 -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 +314 -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 +291 -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 +580 -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 +2587 -0
  54. package/dist/api/compiler/checker-heritage.d.ts +28 -0
  55. package/dist/api/compiler/checker-heritage.js +901 -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 +442 -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 +200 -0
  69. package/dist/api/compiler/checker-members.js +2148 -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 +483 -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 +271 -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 +789 -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 +51 -0
  93. package/dist/api/compiler/checker-symbol-types.js +955 -0
  94. package/dist/api/compiler/checker-symbols.d.ts +181 -0
  95. package/dist/api/compiler/checker-symbols.js +1784 -0
  96. package/dist/api/compiler/checker-type-factory.d.ts +142 -0
  97. package/dist/api/compiler/checker-type-factory.js +2542 -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 +1093 -0
  103. package/dist/api/compiler/checker-types.js +1874 -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 +512 -0
  109. package/dist/api/compiler/checker.js +932 -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 +161 -0
  119. package/dist/api/compiler/diagnostics.js +784 -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 +144 -0
  123. package/dist/api/compiler/file-include.js +599 -0
  124. package/dist/api/compiler/file-loader.d.ts +290 -0
  125. package/dist/api/compiler/file-loader.js +1323 -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 +835 -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 +105 -0
  135. package/dist/api/compiler/link-tables.js +319 -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 +745 -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 +221 -0
  191. package/dist/api/compiler/parallel-parse.js +541 -0
  192. package/dist/api/compiler/parser.d.ts +604 -0
  193. package/dist/api/compiler/parser.js +6426 -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 +157 -0
  203. package/dist/api/compiler/printer/emit-context.js +582 -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 +529 -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 +1019 -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 +991 -0
  244. package/dist/api/compiler/symbol.d.ts +282 -0
  245. package/dist/api/compiler/symbol.js +339 -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 +677 -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 +539 -0
  268. package/dist/api/compiler/transformers/declarations-pseudo.d.ts +160 -0
  269. package/dist/api/compiler/transformers/declarations-pseudo.js +799 -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 +198 -0
  276. package/dist/api/compiler/transformers/declarations.d.ts +175 -0
  277. package/dist/api/compiler/transformers/declarations.js +2381 -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 +129 -0
  321. package/dist/api/compiler/transformers/reference-resolver.js +1157 -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 +10 -0
  325. package/dist/api/compiler/transformers/subtree-facts.js +205 -0
  326. package/dist/api/compiler/transformers/syntax-facts.d.ts +52 -0
  327. package/dist/api/compiler/transformers/syntax-facts.js +258 -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 +12870 -0
  382. package/src/compiler/astnav.ts +799 -0
  383. package/src/compiler/binder-utilities.ts +1392 -0
  384. package/src/compiler/binder.ts +2707 -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 +1201 -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 +355 -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 +3596 -0
  407. package/src/compiler/checker-heritage.ts +1240 -0
  408. package/src/compiler/checker-inference.ts +2584 -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 +1928 -0
  413. package/src/compiler/checker-literals.ts +61 -0
  414. package/src/compiler/checker-members.ts +2480 -0
  415. package/src/compiler/checker-modules.ts +2896 -0
  416. package/src/compiler/checker-narrowing.ts +3230 -0
  417. package/src/compiler/checker-object-literals.ts +591 -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 +1187 -0
  427. package/src/compiler/checker-symbols.ts +2157 -0
  428. package/src/compiler/checker-type-factory.ts +2616 -0
  429. package/src/compiler/checker-type-nodes.ts +1033 -0
  430. package/src/compiler/checker-type-operators.ts +2510 -0
  431. package/src/compiler/checker-types.ts +2520 -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 +1138 -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 +858 -0
  441. package/src/compiler/emitter.ts +434 -0
  442. package/src/compiler/encoder.ts +1945 -0
  443. package/src/compiler/file-include.ts +741 -0
  444. package/src/compiler/file-loader.ts +1597 -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 +2818 -0
  449. package/src/compiler/init.ts +141 -0
  450. package/src/compiler/instantiation.ts +938 -0
  451. package/src/compiler/jsdoc.ts +1386 -0
  452. package/src/compiler/link-tables.ts +343 -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 +1071 -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 +3433 -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 +1954 -0
  481. package/src/compiler/parallel-parse.ts +595 -0
  482. package/src/compiler/parse-thread.ts +136 -0
  483. package/src/compiler/parser.ts +7766 -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 +684 -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 +594 -0
  498. package/src/compiler/program-utilities.ts +435 -0
  499. package/src/compiler/program.ts +1426 -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 +1166 -0
  510. package/src/compiler/symbol.ts +557 -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 +833 -0
  523. package/src/compiler/transformers/declarations-pseudo.ts +969 -0
  524. package/src/compiler/transformers/declarations-resolver.ts +249 -0
  525. package/src/compiler/transformers/declarations-syntactic.ts +1867 -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 +1213 -0
  550. package/src/compiler/transformers/runtime-syntax.ts +942 -0
  551. package/src/compiler/transformers/subtree-facts.ts +253 -0
  552. package/src/compiler/transformers/syntax-facts.ts +358 -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 +1422 -0
  562. package/src/compiler/tsc-cli.ts +669 -0
  563. package/src/compiler/tsc-compile.ts +446 -0
  564. package/src/compiler/tsc-watch.ts +922 -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,2157 @@
1
+ // Symbols: merging globals and augmentations, merged and late-bound symbols, aliases, exports,
2
+ // entity names and the checker's name resolver.
3
+ import { sideOf, signatureSideOf } from './side-state.js';
4
+ import { isTypeAssignableToKindEx } from './checker-type-operators.js';
5
+ import {
6
+ BinaryExpression,
7
+ type ElementAccessExpression,
8
+ type Identifier,
9
+ ModuleDeclaration,
10
+ type Node,
11
+ NodeFlags,
12
+ type PatternAmbientModule,
13
+ type QualifiedName,
14
+ type SourceFile,
15
+ Tristate,
16
+ getExpression,
17
+ getInitializer,
18
+ getMembers as getMemberNodes,
19
+ getName,
20
+ getSymbol,
21
+ getText,
22
+ getIsTypeOnly,
23
+ HeritageClause,
24
+ getProperties,
25
+ getType,
26
+ getLocals,
27
+ } from './ast.js';
28
+ import { isAmbientModule, isGlobalScopeAugmentation, nodeIsMissing } from './ast-utilities.js';
29
+ import { CodePoints, distanceToCandidate, utf8Length } from './spelling.js';
30
+ import { setValueDeclaration } from './binder.js';
31
+ import { checkResolvedBlockScopedVariable, getEmitStandardClassFields } from './checker-declaration-order.js';
32
+ import {
33
+ declarationNameToString,
34
+ getNameOfDeclaration,
35
+ getRootDeclaration,
36
+ getSourceFileOfNode,
37
+ getSourceTextOfNode,
38
+ getDeclarationOfKind,
39
+ getThisContainer,
40
+ hasStaticModifier,
41
+ isClassLike,
42
+ isEntityNameExpression,
43
+ isExternalOrCommonJSModule,
44
+ isPartOfTypeQuery,
45
+ isStatic,
46
+ } from './binder-utilities.js';
47
+ import { type Diagnostic, type DiagnosticMessage, Diagnostics, compareDiagnostics } from './diagnostics.js';
48
+ import { NameResolver } from './name-resolver.js';
49
+ import { SyntaxKind } from './syntax-kind.js';
50
+ import { type Checker, createDiagnosticForNode } from './checker.js';
51
+ import {
52
+ InterfaceType,
53
+ type Type,
54
+ TypeFlags,
55
+ type Signature,
56
+ TypeReference,
57
+ UnionOrIntersectionType,
58
+ } from './checker-types.js';
59
+ import { compareSymbols } from './checker-type-factory.js';
60
+ import { getDeclaredTypeOfSymbol } from './checker-declared-types.js';
61
+ import { symbolToString } from './type-printer.js';
62
+ import { getTypeOfSymbol } from './checker-symbol-types.js';
63
+ import { getPropertyOfType } from './checker-members.js';
64
+ import { checkComputedPropertyName, checkExpressionCached, entityNameToString } from './checker-expressions.js';
65
+ import {
66
+ getLateBindableNameOfDeclaration,
67
+ getPropertyNameFromType,
68
+ isTypeUsableAsPropertyName,
69
+ hasLateBindableName,
70
+ hasLateBindableIndexSignature,
71
+ } from './checker-utilities.js';
72
+ import {
73
+ checkTypeOnlyAliasUse,
74
+ markAliasDeclarationOfNameIfTypeOnly,
75
+ getExportsOfModuleWorker,
76
+ getTargetOfAliasDeclaration,
77
+ getTypeOnlyAliasDeclaration,
78
+ isTypeOnlyImportOrExportDeclaration,
79
+ resolveExternalModuleNameWorker,
80
+ resolveExternalModuleSymbol,
81
+ resolveIndirectionAlias,
82
+ } from './checker-modules.js';
83
+ import { isJSAliasDeclaration } from './checker-javascript.js';
84
+ import { getFeatureMap } from './checker-features.js';
85
+ import { NodeBuilderInternalFlags } from './transformers/declarations-resolver.js';
86
+ import {
87
+ addDeclaration,
88
+ CheckFlags,
89
+ declarationAt,
90
+ declarationCount,
91
+ getDeclarations,
92
+ getSymbolId,
93
+ InternalSymbolName,
94
+ setDeclarations,
95
+ Symbol,
96
+ SymbolFlags,
97
+ type SymbolTable,
98
+ } from './symbol.js';
99
+
100
+ // ---- Name resolution
101
+
102
+ /** The binder's name resolver with the checker's merging, alias handling and errors. */
103
+ export class CheckerNameResolver extends NameResolver {
104
+ readonly checker: Checker;
105
+
106
+ constructor(checker: Checker) {
107
+ super(checker.compilerOptions);
108
+ this.checker = checker;
109
+ this.globals = checker.globals;
110
+ this.argumentsSymbol = checker.argumentsSymbol;
111
+ this.requireSymbol = checker.requireSymbol;
112
+ }
113
+
114
+ lookup(symbols: SymbolTable, name: string, meaning: SymbolFlags): Symbol | undefined {
115
+ return getSymbolOfMeaning(this.checker, symbols, name, meaning);
116
+ }
117
+
118
+ getSymbolOfDeclaration(node: Node): Symbol | undefined {
119
+ return getSymbolOfDeclaration(this.checker, node);
120
+ }
121
+
122
+ error(location: Node, message: DiagnosticMessage, args: readonly string[]): void {
123
+ this.checker.error(location, message, ...args);
124
+ }
125
+
126
+ symbolReferenced(symbol: Symbol, meaning: SymbolFlags): void {
127
+ const kinds = this.checker.symbolReferenceKinds;
128
+ const id = getSymbolId(symbol);
129
+ kinds.set(id, kinds.get(id) | meaning);
130
+ }
131
+
132
+ getRequiresScopeChangeCache(node: Node): Tristate {
133
+ return (this.checker.existingNodeLinks(node)?.declarationRequiresScopeChange ?? 0) as Tristate;
134
+ }
135
+
136
+ setRequiresScopeChangeCache(node: Node, value: Tristate): void {
137
+ this.checker.nodeLinks(node).declarationRequiresScopeChange = value;
138
+ }
139
+
140
+ /**
141
+ * A property initializer that references a local of the constructor, where the initializer is emitted
142
+ * when class fields aren't standard: reports a missing `this.` when the name resolves to nothing, else
143
+ * that the initializer (or the property's type) can't reference it.
144
+ */
145
+ onPropertyWithInvalidInitializer(
146
+ location: Node,
147
+ name: string,
148
+ declaration: Node,
149
+ result: Symbol | undefined,
150
+ ): boolean {
151
+ const c = this.checker;
152
+ if (getEmitStandardClassFields(c)) return false;
153
+ if (result === undefined && checkAndReportErrorForMissingPrefix(c, location, name)) return true;
154
+ const typeNode = getType(declaration);
155
+ const inType = typeNode !== undefined && typeNode.pos <= location.pos && location.pos <= typeNode.end;
156
+ c.error(
157
+ location,
158
+ inType
159
+ ? Diagnostics.Type_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor
160
+ : Diagnostics.Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor,
161
+ declarationNameToString(getSourceFileOfNode(declaration), getName(declaration)!),
162
+ name,
163
+ );
164
+ return true;
165
+ }
166
+
167
+ onFailedToResolveSymbol(
168
+ location: Node | undefined,
169
+ name: string,
170
+ meaning: SymbolFlags,
171
+ message: DiagnosticMessage,
172
+ ): void {
173
+ onFailedToResolveSymbol(this.checker, location, name, meaning, message);
174
+ }
175
+
176
+ onSuccessfullyResolvedSymbol(
177
+ location: Node | undefined,
178
+ result: Symbol,
179
+ meaning: SymbolFlags,
180
+ lastLocation: Node | undefined,
181
+ associatedDeclarationForContainingInitializerOrBindingName: Node | undefined,
182
+ withinDeferredContext: boolean,
183
+ ): void {
184
+ const c = this.checker;
185
+ const isInExternalModule =
186
+ lastLocation !== undefined &&
187
+ lastLocation.kind === SyntaxKind.SourceFile &&
188
+ isExternalOrCommonJSModule(lastLocation as SourceFile);
189
+ // Only names in value positions check block-scoped declaration order: a symbol may be both a
190
+ // block-scoped variable and a namespace, as in `const foo: foo.bar`.
191
+ if (
192
+ location !== undefined &&
193
+ ((meaning & SymbolFlags.BlockScopedVariable) !== 0 ||
194
+ ((meaning & (SymbolFlags.Class | SymbolFlags.Enum)) !== 0 &&
195
+ (meaning & SymbolFlags.Value) === SymbolFlags.Value))
196
+ )
197
+ checkResolvedBlockScopedVariable(this.checker, result, location);
198
+ // A module can't reference the value of a UMD global (`export as namespace`).
199
+ if (
200
+ isInExternalModule &&
201
+ location !== undefined &&
202
+ (meaning & SymbolFlags.Value) === SymbolFlags.Value &&
203
+ (location.flags & NodeFlags.JSDoc) === 0
204
+ ) {
205
+ const merged = getMergedSymbol(c, result);
206
+ if (
207
+ declarationCount(merged) !== 0 &&
208
+ getDeclarations(merged).every(
209
+ (d) =>
210
+ d.kind === SyntaxKind.NamespaceExportDeclaration ||
211
+ (d.kind === SyntaxKind.SourceFile && (d as SourceFile).globalExports !== undefined),
212
+ )
213
+ )
214
+ c.addErrorOrSuggestion(
215
+ c.compilerOptions.allowUmdGlobalAccess !== true,
216
+ createDiagnosticForNode(
217
+ location,
218
+ Diagnostics.X_0_refers_to_a_UMD_global_but_the_current_file_is_a_module_Consider_adding_an_import_instead,
219
+ [result.name],
220
+ ),
221
+ );
222
+ }
223
+ // A parameter initializer or binding name can't reference its own parameter or the ones after it.
224
+ const associated = associatedDeclarationForContainingInitializerOrBindingName;
225
+ if (
226
+ location !== undefined &&
227
+ associated !== undefined &&
228
+ !withinDeferredContext &&
229
+ (meaning & SymbolFlags.Value) === SymbolFlags.Value
230
+ ) {
231
+ const candidate = getMergedSymbol(c, getLateBoundSymbol(c, result));
232
+ const root = getRootDeclaration(associated);
233
+ const file = getSourceFileOfNode(associated);
234
+ if (candidate === getSymbolOfDeclaration(c, associated))
235
+ c.error(
236
+ location,
237
+ Diagnostics.Parameter_0_cannot_reference_itself,
238
+ declarationNameToString(file, getName(associated)),
239
+ );
240
+ else if (
241
+ candidate.valueDeclaration !== undefined &&
242
+ candidate.valueDeclaration.pos > associated.pos &&
243
+ getLocals(root.parent!) !== undefined &&
244
+ getSymbolOfMeaning(c, getLocals(root.parent!)!, candidate.name, meaning) === candidate
245
+ )
246
+ c.error(
247
+ location,
248
+ Diagnostics.Parameter_0_cannot_reference_identifier_1_declared_after_it,
249
+ declarationNameToString(file, getName(associated)),
250
+ declarationNameToString(file, location),
251
+ );
252
+ }
253
+ if (location !== undefined && (meaning & SymbolFlags.Value) !== 0)
254
+ checkTypeOnlyAliasUse(this.checker, location, result, result.name);
255
+ // Under isolatedModules, a value import named like a global value that the file uses must be type-only.
256
+ if (
257
+ c.compilerOptions.isolatedModules === true &&
258
+ isInExternalModule &&
259
+ (meaning & SymbolFlags.Value) === SymbolFlags.Value
260
+ ) {
261
+ const name = result.name;
262
+ const isGlobal = getSymbolOfMeaning(c, c.globals, name, meaning) === result;
263
+ const locals = isGlobal ? getLocals(lastLocation!) : undefined;
264
+ const nonValueSymbol = locals !== undefined ? getSymbolOfMeaning(c, locals, name, ~SymbolFlags.Value) : undefined;
265
+ if (nonValueSymbol !== undefined) {
266
+ const importDeclaration = getDeclarations(nonValueSymbol).find(
267
+ (d) =>
268
+ d.kind === SyntaxKind.ImportSpecifier ||
269
+ d.kind === SyntaxKind.ImportClause ||
270
+ d.kind === SyntaxKind.NamespaceImport ||
271
+ d.kind === SyntaxKind.ImportEqualsDeclaration,
272
+ );
273
+ if (importDeclaration !== undefined && !isTypeOnlyImportOrExportDeclaration(importDeclaration))
274
+ c.error(
275
+ importDeclaration,
276
+ Diagnostics.Import_0_conflicts_with_global_value_used_in_this_file_so_must_be_declared_with_a_type_only_import_when_isolatedModules_is_enabled,
277
+ name,
278
+ );
279
+ }
280
+ }
281
+ }
282
+ }
283
+
284
+ export function resolveName(
285
+ c: Checker,
286
+ location: Node | undefined,
287
+ name: string,
288
+ meaning: SymbolFlags,
289
+ nameNotFoundMessage: DiagnosticMessage | undefined,
290
+ isUse: boolean,
291
+ excludeGlobals: boolean,
292
+ ): Symbol | undefined {
293
+ return c.resolver.resolve(location, name, meaning, nameNotFoundMessage, isUse, excludeGlobals);
294
+ }
295
+
296
+ /** `symbols[name]` (merged) if it has `meaning`, directly or through an alias. */
297
+ export function getSymbolOfMeaning(
298
+ c: Checker,
299
+ symbols: SymbolTable,
300
+ name: string,
301
+ meaning: SymbolFlags,
302
+ ): Symbol | undefined {
303
+ if ((meaning & SymbolFlags.All) === 0) return undefined;
304
+ const found = symbols.get(name);
305
+ if (found === undefined) return undefined;
306
+ const symbol = getMergedSymbol(c, found);
307
+ if ((symbol.flags & meaning) !== 0) return symbol;
308
+ // getSymbolFlags is All when alias resolution failed, which avoids cascading errors.
309
+ if ((symbol.flags & SymbolFlags.Alias) !== 0 && (getSymbolFlags(c, symbol) & meaning) !== 0) return symbol;
310
+ return undefined;
311
+ }
312
+
313
+ function isPrimitiveTypeName(name: string): boolean {
314
+ return (
315
+ name === 'any' ||
316
+ name === 'string' ||
317
+ name === 'number' ||
318
+ name === 'boolean' ||
319
+ name === 'never' ||
320
+ name === 'unknown'
321
+ );
322
+ }
323
+
324
+ function isES2015OrLaterConstructorName(name: string): boolean {
325
+ return (
326
+ name === 'Promise' ||
327
+ name === 'Symbol' ||
328
+ name === 'Map' ||
329
+ name === 'WeakMap' ||
330
+ name === 'Set' ||
331
+ name === 'WeakSet'
332
+ );
333
+ }
334
+
335
+ function onFailedToResolveSymbol(
336
+ c: Checker,
337
+ location: Node | undefined,
338
+ name: string,
339
+ meaning: SymbolFlags,
340
+ message: DiagnosticMessage,
341
+ ): void {
342
+ let declarationName = name;
343
+ if (location !== undefined) {
344
+ if (location.parent !== undefined && location.parent.kind === SyntaxKind.JSDocLink) return;
345
+ if (
346
+ checkAndReportErrorForMissingPrefix(c, location, name) ||
347
+ checkAndReportErrorForExtendingInterface(c, location) ||
348
+ checkAndReportErrorForUsingTypeAsNamespace(c, location, name, meaning) ||
349
+ checkAndReportErrorForExportingPrimitiveType(c, location, name) ||
350
+ checkAndReportErrorForUsingNamespaceAsTypeOrValue(c, location, name, meaning) ||
351
+ checkAndReportErrorForUsingTypeAsValue(c, location, name, meaning) ||
352
+ checkAndReportErrorForUsingValueAsType(c, location, name, meaning)
353
+ )
354
+ return;
355
+ if (location.kind === SyntaxKind.Identifier && getText(location) === name)
356
+ declarationName = declarationNameToString(getSourceFileOfNode(location), location);
357
+ }
358
+ // A missing library comes before spelling suggestions.
359
+ const features = getFeatureMap().get(name);
360
+ if (features !== undefined) {
361
+ c.error(location, message, declarationName, features[0]!.lib);
362
+ return;
363
+ }
364
+ const suggestion = c.suggestionResolver.resolve(location, name, meaning, undefined, false, false);
365
+ if (
366
+ suggestion !== undefined &&
367
+ !(
368
+ suggestion.valueDeclaration !== undefined &&
369
+ isAmbientModule(suggestion.valueDeclaration) &&
370
+ isGlobalScopeAugmentation(suggestion.valueDeclaration)
371
+ )
372
+ ) {
373
+ const suggestionName = symbolToString(c, suggestion);
374
+ const diagnostic = createDiagnosticForNode(
375
+ location,
376
+ meaning === SymbolFlags.Namespace
377
+ ? Diagnostics.Cannot_find_namespace_0_Did_you_mean_1
378
+ : Diagnostics.Cannot_find_name_0_Did_you_mean_1,
379
+ [declarationName, suggestionName],
380
+ );
381
+ if (suggestion.valueDeclaration !== undefined)
382
+ diagnostic.addRelatedInfo(
383
+ createDiagnosticForNode(suggestion.valueDeclaration, Diagnostics.X_0_is_declared_here, [suggestionName]),
384
+ );
385
+ c.addDiagnostic(diagnostic);
386
+ return;
387
+ }
388
+ c.error(location, message, declarationName);
389
+ }
390
+
391
+ function checkAndReportErrorForMissingPrefix(c: Checker, location: Node, name: string): boolean {
392
+ if (
393
+ location.kind !== SyntaxKind.Identifier ||
394
+ getText(location) !== name ||
395
+ isTypeReferenceIdentifier(location) ||
396
+ isPartOfTypeQuery(location)
397
+ )
398
+ return false;
399
+ const container = getThisContainer(location, false, false);
400
+ for (let current = container; current.parent !== undefined; current = current.parent) {
401
+ if (!isClassLike(current.parent)) continue;
402
+ const classSymbol = getSymbolOfDeclaration(c, current.parent);
403
+ if (classSymbol === undefined) break;
404
+ if (getPropertyOfType(c, getTypeOfSymbol(c, classSymbol), name) !== undefined) {
405
+ c.error(
406
+ location,
407
+ Diagnostics.Cannot_find_name_0_Did_you_mean_the_static_member_1_0,
408
+ name,
409
+ symbolToString(c, classSymbol),
410
+ );
411
+ return true;
412
+ }
413
+ if (current === container && !isStatic(current)) {
414
+ const thisType = (getDeclaredTypeOfSymbol(c, classSymbol) as InterfaceType).thisType;
415
+ if (thisType !== undefined && getPropertyOfType(c, thisType, name) !== undefined) {
416
+ c.error(location, Diagnostics.Cannot_find_name_0_Did_you_mean_the_instance_member_this_0, name);
417
+ return true;
418
+ }
419
+ }
420
+ }
421
+ return false;
422
+ }
423
+
424
+ function isTypeReferenceIdentifier(node: Node): boolean {
425
+ let current = node;
426
+ while (current.parent !== undefined && current.parent.kind === SyntaxKind.QualifiedName) current = current.parent;
427
+ return current.parent !== undefined && current.parent.kind === SyntaxKind.TypeReference;
428
+ }
429
+
430
+ function checkAndReportErrorForExtendingInterface(c: Checker, location: Node): boolean {
431
+ const expression = getEntityNameForExtendingInterface(location);
432
+ if (
433
+ expression !== undefined &&
434
+ resolveEntityName(c, expression, SymbolFlags.Interface, true, false, undefined) !== undefined
435
+ ) {
436
+ c.error(
437
+ location,
438
+ Diagnostics.Cannot_extend_an_interface_0_Did_you_mean_implements,
439
+ getSourceTextOfNode(getSourceFileOfNode(expression), expression),
440
+ );
441
+ return true;
442
+ }
443
+ return false;
444
+ }
445
+
446
+ function getEntityNameForExtendingInterface(node: Node): Node | undefined {
447
+ switch (node.kind) {
448
+ case SyntaxKind.Identifier:
449
+ case SyntaxKind.PropertyAccessExpression:
450
+ return node.parent !== undefined ? getEntityNameForExtendingInterface(node.parent) : undefined;
451
+ case SyntaxKind.ExpressionWithTypeArguments: {
452
+ const expression = getExpression(node)!;
453
+ return isEntityNameExpression(expression, false) ? expression : undefined;
454
+ }
455
+ }
456
+ return undefined;
457
+ }
458
+
459
+ /** Resolves names to their closest misspelling in scope, for "Did you mean" suggestions. */
460
+ export class SuggestionNameResolver extends CheckerNameResolver {
461
+ lookup(symbols: SymbolTable, name: string, meaning: SymbolFlags): Symbol | undefined {
462
+ const symbol = getSymbolOfMeaning(this.checker, symbols, name, meaning);
463
+ if (symbol !== undefined) return symbol;
464
+ const candidates: Symbol[] = [];
465
+ for (const s of symbols.values()) candidates.push(s);
466
+ if ((meaning & SymbolFlags.GlobalLookup) !== 0) {
467
+ for (const builtin of primitiveBuiltins.split(' '))
468
+ if (symbols.has(builtin))
469
+ candidates.push(getPrimitiveTypeAliasSuggestion(this.checker, primitiveTypeAliasFor(builtin)));
470
+ }
471
+ return getSpellingSuggestionForName(this.checker, name, candidates, meaning);
472
+ }
473
+
474
+ error(_location: Node, _message: DiagnosticMessage, _args: readonly string[]): void {}
475
+
476
+ symbolReferenced(_symbol: Symbol, _meaning: SymbolFlags): void {}
477
+
478
+ onFailedToResolveSymbol(
479
+ _location: Node | undefined,
480
+ _name: string,
481
+ _meaning: SymbolFlags,
482
+ _message: DiagnosticMessage,
483
+ ): void {}
484
+ }
485
+
486
+ /** The primitive type alias suggested for a misspelled builtin wrapper name, or ''. */
487
+ function primitiveTypeAliasFor(builtin: string): string {
488
+ switch (builtin) {
489
+ case 'String':
490
+ return 'string';
491
+ case 'Number':
492
+ return 'number';
493
+ case 'Boolean':
494
+ return 'boolean';
495
+ case 'Object':
496
+ return 'object';
497
+ case 'BigInt':
498
+ return 'bigint';
499
+ case 'Symbol':
500
+ return 'symbol';
501
+ }
502
+ return '';
503
+ }
504
+
505
+ const primitiveBuiltins = 'String Number Boolean Object BigInt Symbol';
506
+
507
+ function getPrimitiveTypeAliasSuggestion(c: Checker, name: string): Symbol {
508
+ let symbol = c.primitiveTypeAliasSuggestions.get(name);
509
+ if (symbol === undefined) {
510
+ symbol = c.newSymbol(SymbolFlags.TypeAlias, name);
511
+ c.primitiveTypeAliasSuggestions.set(name, symbol);
512
+ }
513
+ return symbol;
514
+ }
515
+
516
+ /** The symbol whose name is closest to `name` and that has `meaning`, if close enough. */
517
+ export function getSpellingSuggestionForName(
518
+ c: Checker,
519
+ name: string,
520
+ symbols: readonly Symbol[],
521
+ meaning: SymbolFlags,
522
+ ): Symbol | undefined {
523
+ const nameCodePoints = new CodePoints();
524
+ nameCodePoints.set(name);
525
+ const maximumLengthDifference = Math.max(2, Math.floor(nameCodePoints.length * 0.34));
526
+ let bestDistance = Math.floor(nameCodePoints.length * 0.4) + 0.9;
527
+ let best: Symbol | undefined = undefined;
528
+ const lowerName = name.toLowerCase();
529
+ for (const candidate of symbols) {
530
+ const candidateName = getCandidateName(c, candidate, meaning);
531
+ if (candidateName === '') continue;
532
+ // tsgo measures candidates in bytes and the name in code points. A candidate has at least as
533
+ // many bytes as UTF-16 units, so most long candidates are out without measuring them.
534
+ if (candidateName.length - nameCodePoints.length > maximumLengthDifference) continue;
535
+ const candidateLength = utf8Length(candidateName);
536
+ if (
537
+ Math.max(candidateLength, nameCodePoints.length) - Math.min(candidateLength, nameCodePoints.length) >
538
+ maximumLengthDifference
539
+ )
540
+ continue;
541
+ if (candidateName === name) continue;
542
+ if (candidateLength < 3 && candidateName.toLowerCase() !== lowerName) continue;
543
+ const distance = distanceToCandidate(nameCodePoints, candidateName, bestDistance);
544
+ if (distance < 0) continue;
545
+ if (distance < bestDistance) {
546
+ bestDistance = distance;
547
+ best = candidate;
548
+ } else if (best === undefined || compareSymbols(c, candidate, best) < 0) best = candidate;
549
+ }
550
+ return best;
551
+ }
552
+
553
+ function getCandidateName(c: Checker, candidate: Symbol, meaning: SymbolFlags): string {
554
+ const name = candidate.name;
555
+ if (name.length === 0 || name.charCodeAt(0) === 0x22 || name.charCodeAt(0) === 0xfffe) return '';
556
+ if ((candidate.flags & meaning) !== 0) return name;
557
+ if ((candidate.flags & SymbolFlags.Alias) !== 0) {
558
+ const target = tryResolveAlias(c, candidate);
559
+ if (target !== undefined && (target.flags & meaning) !== 0) return name;
560
+ }
561
+ return '';
562
+ }
563
+
564
+ function checkAndReportErrorForUsingTypeAsNamespace(
565
+ c: Checker,
566
+ location: Node,
567
+ name: string,
568
+ meaning: SymbolFlags,
569
+ ): boolean {
570
+ if (meaning !== SymbolFlags.Namespace) return false;
571
+ const symbol = resolveSymbol(
572
+ c,
573
+ resolveName(c, location, name, SymbolFlags.Type & ~SymbolFlags.Namespace, undefined, false, false),
574
+ );
575
+ if (symbol === undefined) return false;
576
+ const parent = location.parent;
577
+ if (parent !== undefined && parent.kind === SyntaxKind.QualifiedName) {
578
+ const propName = (parent as QualifiedName).right.text;
579
+ if (getPropertyOfType(c, getDeclaredTypeOfSymbol(c, symbol), propName) !== undefined) {
580
+ c.error(
581
+ parent,
582
+ Diagnostics.Cannot_access_0_1_because_0_is_a_type_but_not_a_namespace_Did_you_mean_to_retrieve_the_type_of_the_property_1_in_0_with_0_1,
583
+ name,
584
+ propName,
585
+ );
586
+ return true;
587
+ }
588
+ }
589
+ c.error(location, Diagnostics.X_0_only_refers_to_a_type_but_is_being_used_as_a_namespace_here, name);
590
+ return true;
591
+ }
592
+
593
+ function checkAndReportErrorForExportingPrimitiveType(c: Checker, location: Node, name: string): boolean {
594
+ if (
595
+ isPrimitiveTypeName(name) &&
596
+ location.parent !== undefined &&
597
+ location.parent.kind === SyntaxKind.ExportSpecifier
598
+ ) {
599
+ c.error(location, Diagnostics.Cannot_export_0_Only_local_declarations_can_be_exported_from_a_module, name);
600
+ return true;
601
+ }
602
+ return false;
603
+ }
604
+
605
+ function checkAndReportErrorForUsingNamespaceAsTypeOrValue(
606
+ c: Checker,
607
+ location: Node,
608
+ name: string,
609
+ meaning: SymbolFlags,
610
+ ): boolean {
611
+ if ((meaning & (SymbolFlags.Value & ~SymbolFlags.Type)) !== 0) {
612
+ const symbol = resolveSymbol(
613
+ c,
614
+ resolveName(c, location, name, SymbolFlags.NamespaceModule, undefined, false, false),
615
+ );
616
+ if (symbol !== undefined) {
617
+ c.error(location, Diagnostics.Cannot_use_namespace_0_as_a_value, name);
618
+ return true;
619
+ }
620
+ } else if ((meaning & (SymbolFlags.Type & ~SymbolFlags.Value)) !== 0) {
621
+ const symbol = resolveSymbol(c, resolveName(c, location, name, SymbolFlags.Module, undefined, false, false));
622
+ if (symbol !== undefined) {
623
+ c.error(location, Diagnostics.Cannot_use_namespace_0_as_a_type, name);
624
+ return true;
625
+ }
626
+ }
627
+ return false;
628
+ }
629
+
630
+ function checkAndReportErrorForUsingTypeAsValue(
631
+ c: Checker,
632
+ location: Node,
633
+ name: string,
634
+ meaning: SymbolFlags,
635
+ ): boolean {
636
+ if ((meaning & SymbolFlags.Value) === 0) return false;
637
+ if (isPrimitiveTypeName(name)) {
638
+ const grandparent = location.parent?.parent;
639
+ if (
640
+ grandparent !== undefined &&
641
+ grandparent.parent !== undefined &&
642
+ grandparent.kind === SyntaxKind.HeritageClause
643
+ ) {
644
+ const heritageKind = (grandparent as HeritageClause).token;
645
+ const containerKind = grandparent.parent.kind;
646
+ const isClass = containerKind === SyntaxKind.ClassDeclaration || containerKind === SyntaxKind.ClassExpression;
647
+ if (containerKind === SyntaxKind.InterfaceDeclaration && heritageKind === SyntaxKind.ExtendsKeyword)
648
+ c.error(
649
+ location,
650
+ Diagnostics.An_interface_cannot_extend_a_primitive_type_like_0_It_can_only_extend_other_named_object_types,
651
+ name,
652
+ );
653
+ else if (isClass && heritageKind === SyntaxKind.ExtendsKeyword)
654
+ c.error(
655
+ location,
656
+ Diagnostics.A_class_cannot_extend_a_primitive_type_like_0_Classes_can_only_extend_constructable_values,
657
+ name,
658
+ );
659
+ else if (isClass && heritageKind === SyntaxKind.ImplementsKeyword)
660
+ c.error(
661
+ location,
662
+ Diagnostics.A_class_cannot_implement_a_primitive_type_like_0_It_can_only_implement_other_named_object_types,
663
+ name,
664
+ );
665
+ } else c.error(location, Diagnostics.X_0_only_refers_to_a_type_but_is_being_used_as_a_value_here, name);
666
+ return true;
667
+ }
668
+ const symbol = resolveSymbol(
669
+ c,
670
+ resolveName(c, location, name, SymbolFlags.Type & ~SymbolFlags.Value, undefined, false, false),
671
+ );
672
+ if (symbol !== undefined && (getSymbolFlags(c, symbol) & SymbolFlags.Value) === 0) {
673
+ if (isES2015OrLaterConstructorName(name))
674
+ c.error(
675
+ location,
676
+ Diagnostics.X_0_only_refers_to_a_type_but_is_being_used_as_a_value_here_Do_you_need_to_change_your_target_library_Try_changing_the_lib_compiler_option_to_es2015_or_later,
677
+ name,
678
+ );
679
+ else if (maybeMappedType(c, location, symbol))
680
+ c.error(
681
+ location,
682
+ Diagnostics.X_0_only_refers_to_a_type_but_is_being_used_as_a_value_here_Did_you_mean_to_use_1_in_0,
683
+ name,
684
+ name === 'K' ? 'P' : 'K',
685
+ );
686
+ else c.error(location, Diagnostics.X_0_only_refers_to_a_type_but_is_being_used_as_a_value_here, name);
687
+ return true;
688
+ }
689
+ return false;
690
+ }
691
+
692
+ function maybeMappedType(c: Checker, node: Node, symbol: Symbol): boolean {
693
+ let container = node.parent;
694
+ while (
695
+ container !== undefined &&
696
+ (container.kind === SyntaxKind.ComputedPropertyName || container.kind === SyntaxKind.PropertySignature)
697
+ )
698
+ container = container.parent;
699
+ if (container === undefined || container.kind !== SyntaxKind.TypeLiteral) return false;
700
+ const members = getMemberNodes(container);
701
+ if (members === undefined || members.nodes.length !== 1) return false;
702
+ const type = getDeclaredTypeOfSymbol(c, symbol);
703
+ if ((type.flags & TypeFlags.Union) === 0) return false;
704
+ for (const t of (type as UnionOrIntersectionType).types)
705
+ if (!isTypeAssignableToKindEx(c, t, TypeFlags.StringOrNumberLiteral, true)) return false;
706
+ return true;
707
+ }
708
+
709
+ function checkAndReportErrorForUsingValueAsType(
710
+ c: Checker,
711
+ location: Node,
712
+ name: string,
713
+ meaning: SymbolFlags,
714
+ ): boolean {
715
+ if ((meaning & (SymbolFlags.Type & ~SymbolFlags.Namespace)) === 0) return false;
716
+ const symbol = resolveSymbol(
717
+ c,
718
+ resolveName(c, location, name, ~SymbolFlags.Type & SymbolFlags.Value, undefined, false, false),
719
+ );
720
+ if (symbol !== undefined && (symbol.flags & SymbolFlags.Namespace) === 0) {
721
+ c.error(location, Diagnostics.X_0_refers_to_a_value_but_is_being_used_as_a_type_here_Did_you_mean_typeof_0, name);
722
+ return true;
723
+ }
724
+ return false;
725
+ }
726
+
727
+ // ---- Merging
728
+
729
+ function mergeFileGlobals(c: Checker, file: SourceFile): void {
730
+ if (!isExternalOrCommonJSModule(file)) {
731
+ const locals = file.locals;
732
+ if (locals !== undefined) {
733
+ const fileGlobalThis = locals.get('globalThis');
734
+ if (fileGlobalThis !== undefined)
735
+ for (const d of getDeclarations(fileGlobalThis))
736
+ c.addDiagnostic(
737
+ createDiagnosticForNode(d, Diagnostics.Declaration_name_conflicts_with_built_in_global_identifier_0, [
738
+ 'globalThis',
739
+ ]),
740
+ );
741
+ for (const symbol of locals.values()) {
742
+ if ((symbol.flags & SymbolFlags.Module) !== 0 && isAmbientModuleSymbolName(symbol.name))
743
+ c.ambientModuleSymbols.push(symbol);
744
+ else mergeGlobalSymbol(c, symbol);
745
+ }
746
+ }
747
+ }
748
+ for (const pattern of file.patternAmbientModules) c.patternAmbientModules.push(pattern);
749
+ if (file.symbol !== undefined && file.globalExports !== undefined)
750
+ // UMD exports, first in wins.
751
+ for (const [name, symbol] of file.globalExports) if (!c.globals.has(name)) setGlobal(c, name, symbol);
752
+ }
753
+
754
+ /** Changes to a map, recorded so that they can be undone. */
755
+ export class TableChanges<K, V> {
756
+ private readonly added = new Set<K>();
757
+ private readonly replaced = new Map<K, V>();
758
+
759
+ set(table: Map<K, V>, key: K, value: V): void {
760
+ const previous = table.get(key);
761
+ if (previous === undefined) this.added.add(key);
762
+ else if (!this.added.has(key) && !this.replaced.has(key)) this.replaced.set(key, previous);
763
+ table.set(key, value);
764
+ }
765
+
766
+ /** Restores `table`, or a copy of it, to its state before the changes. */
767
+ undo(table: Map<K, V>): void {
768
+ for (const key of this.added) table.delete(key);
769
+ for (const [key, value] of this.replaced) table.set(key, value);
770
+ }
771
+ }
772
+
773
+ /**
774
+ * Globals merged from the locals of a program's leading default libraries. Checkers of programs
775
+ * with the same libraries start from them; a later merge into a shared symbol merges into a copy.
776
+ * One checker at a time borrows the tables and changes them in place; the others copy them.
777
+ */
778
+ export class LibGlobals {
779
+ readonly files: SourceFile[];
780
+ readonly globals: SymbolTable;
781
+ readonly mergedSymbols: Map<number, Symbol>;
782
+ readonly ambientModuleSymbols: Symbol[];
783
+ readonly patternAmbientModules: PatternAmbientModule[];
784
+ /** Ids of the symbols merged into each shared symbol. */
785
+ readonly sources = new Map<Symbol, number[]>();
786
+ /** The checker using `globals` and `mergedSymbols` in place. */
787
+ borrower: Checker | undefined = undefined;
788
+
789
+ constructor(c: Checker, files: SourceFile[]) {
790
+ this.files = files;
791
+ this.globals = new Map(c.globals);
792
+ // Each checker sets its own `globalThis`, keeping it first.
793
+ this.globals.set(c.globalThisSymbol.name, new Symbol(SymbolFlags.None, 'globalThis'));
794
+ this.mergedSymbols = new Map(c.mergedSymbols);
795
+ this.ambientModuleSymbols = c.ambientModuleSymbols.slice();
796
+ this.patternAmbientModules = c.patternAmbientModules.slice();
797
+ for (const [id, target] of this.mergedSymbols) {
798
+ let ids = this.sources.get(target);
799
+ if (ids === undefined) {
800
+ ids = [];
801
+ this.sources.set(target, ids);
802
+ }
803
+ ids.push(id);
804
+ }
805
+ }
806
+
807
+ copyGlobals(): SymbolTable {
808
+ const globals = new Map(this.globals);
809
+ if (this.borrower !== undefined) this.borrower.globalChanges!.undo(globals);
810
+ return globals;
811
+ }
812
+
813
+ copyMergedSymbols(): Map<number, Symbol> {
814
+ const mergedSymbols = new Map(this.mergedSymbols);
815
+ if (this.borrower !== undefined) this.borrower.mergedSymbolChanges!.undo(mergedSymbols);
816
+ return mergedSymbols;
817
+ }
818
+
819
+ /** Whether `files` starts with exactly these `count` libraries. */
820
+ matches(files: readonly SourceFile[], count: number): boolean {
821
+ if (count !== this.files.length) return false;
822
+ for (let i = 0; i < count; i++) if (files[i]! !== this.files[i]!) return false;
823
+ return true;
824
+ }
825
+ }
826
+
827
+ /**
828
+ * The globals, merged symbols and module augmentations of a whole program, as one checker merged
829
+ * them before checker threads share the program (parallel-check.ts). Other checkers of the program
830
+ * start from copies of the tables and add the diagnostics the merges reported; the merged symbols
831
+ * are shared, and a later merge into one merges into a copy.
832
+ */
833
+ export class MergedGlobals {
834
+ readonly globals: SymbolTable;
835
+ readonly mergedSymbols: Map<number, Symbol>;
836
+ readonly ambientModuleSymbols: Symbol[];
837
+ readonly patternAmbientModules: PatternAmbientModule[];
838
+ readonly patternAmbientModuleAugmentations: Map<string, Symbol>;
839
+ /** Whether the global `undefined` is the checker's own (no declaration of `undefined` merged). */
840
+ readonly ownUndefined: boolean;
841
+ /** Ids of the symbols merged into each shared symbol. */
842
+ readonly sources = new Map<Symbol, number[]>();
843
+ /** Copies of the checker's `mergeDiagnostics`. */
844
+ readonly diagnostics: Diagnostic[][] = [];
845
+
846
+ constructor(c: Checker) {
847
+ this.globals = new Map(c.globals);
848
+ // Each checker sets its own `globalThis` and `undefined`, in the same places in the table.
849
+ this.globals.set(c.globalThisSymbol.name, new Symbol(SymbolFlags.None, 'globalThis'));
850
+ this.ownUndefined = c.globals.get('undefined') === c.undefinedSymbol;
851
+ if (this.ownUndefined) this.globals.set('undefined', new Symbol(SymbolFlags.None, 'undefined'));
852
+ for (const symbol of this.globals.values()) getSymbolId(symbol);
853
+ this.mergedSymbols = new Map(c.mergedSymbols);
854
+ this.ambientModuleSymbols = c.ambientModuleSymbols.slice();
855
+ this.patternAmbientModules = c.patternAmbientModules.slice();
856
+ this.patternAmbientModuleAugmentations = new Map(c.patternAmbientModuleAugmentations);
857
+ for (const [id, target] of this.mergedSymbols) {
858
+ let ids = this.sources.get(target);
859
+ if (ids === undefined) {
860
+ // Shared symbols are never written, so they need their ids now.
861
+ getSymbolId(target);
862
+ ids = [];
863
+ this.sources.set(target, ids);
864
+ }
865
+ ids.push(id);
866
+ }
867
+ // The checker can add related information to its diagnostics later.
868
+ for (const list of c.mergeDiagnostics) this.diagnostics.push(copyDiagnostics(list));
869
+ }
870
+ }
871
+
872
+ function copyDiagnostics(list: readonly Diagnostic[]): Diagnostic[] {
873
+ const result: Diagnostic[] = [];
874
+ for (const diagnostic of list) {
875
+ const copy = diagnostic.clone();
876
+ copy.relatedInformation = diagnostic.relatedInformation.slice();
877
+ result.push(copy);
878
+ }
879
+ return result;
880
+ }
881
+
882
+ /** Adds the diagnostics and suggestions of `merged`'s merge `step` (0: globals, 1: augmentations). */
883
+ function addMergeDiagnostics(c: Checker, merged: MergedGlobals, step: number): void {
884
+ for (const diagnostic of copyDiagnostics(merged.diagnostics[2 * step]!)) c.diagnostics.add(diagnostic);
885
+ for (const diagnostic of copyDiagnostics(merged.diagnostics[2 * step + 1]!)) c.suggestionDiagnostics.add(diagnostic);
886
+ }
887
+
888
+ /**
889
+ * Shares the globals and module augmentations `c` merged with the other checkers of its program;
890
+ * `c` treats its merged symbols as shared from now on.
891
+ */
892
+ export function shareMergedGlobals(c: Checker): MergedGlobals {
893
+ const merged = new MergedGlobals(c);
894
+ c.mergedGlobals = merged;
895
+ return merged;
896
+ }
897
+
898
+ /** The ids of the symbols merged into `symbol`, if it is shared with other checkers. */
899
+ function sharedSources(c: Checker, symbol: Symbol): number[] | undefined {
900
+ const merged = c.mergedGlobals;
901
+ const ids = merged !== undefined ? merged.sources.get(symbol) : undefined;
902
+ if (ids !== undefined) return ids;
903
+ const libs = c.libGlobals;
904
+ return libs !== undefined ? libs.sources.get(symbol) : undefined;
905
+ }
906
+
907
+ const libGlobalsCache: LibGlobals[] = [];
908
+
909
+ /** Drops the shared library globals (a rebuild reparses the library files). */
910
+ export function clearLibGlobalsCache(): void {
911
+ libGlobalsCache.length = 0;
912
+ }
913
+
914
+ /** Drops the shared library globals merged from any of `files`, for a program that is no longer used. */
915
+ export function dropLibGlobals(files: readonly SourceFile[]): void {
916
+ const dropped = new Set(files);
917
+ for (let i = libGlobalsCache.length - 1; i >= 0; i--)
918
+ if (dropped.has(libGlobalsCache[i]!.files[0]!)) libGlobalsCache.splice(i, 1);
919
+ }
920
+
921
+ /** Number of leading default library files, whose merged locals can be shared. */
922
+ function getLibraryCount(c: Checker): number {
923
+ const files = c.files;
924
+ let count = 0;
925
+ while (count < files.length && c.host.isSourceFileDefaultLibrary(files[count]!)) count++;
926
+ return count;
927
+ }
928
+
929
+ /** The shared globals of the checker's default libraries, if another checker merged them. */
930
+ export function findLibGlobals(c: Checker): LibGlobals | undefined {
931
+ const count = getLibraryCount(c);
932
+ if (count > 0) for (const libs of libGlobalsCache) if (libs.matches(c.files, count)) return libs;
933
+ return undefined;
934
+ }
935
+
936
+ export function borrowLibGlobals(c: Checker, libs: LibGlobals): void {
937
+ libs.borrower = c;
938
+ c.globalChanges = new TableChanges<string, Symbol>();
939
+ c.mergedSymbolChanges = new TableChanges<number, Symbol>();
940
+ }
941
+
942
+ /** Undoes a disposed checker's changes to the tables it borrowed. */
943
+ export function returnLibGlobals(c: Checker): void {
944
+ const libs = c.libGlobals!;
945
+ c.globalChanges!.undo(libs.globals);
946
+ c.mergedSymbolChanges!.undo(libs.mergedSymbols);
947
+ c.globalChanges = undefined;
948
+ c.mergedSymbolChanges = undefined;
949
+ libs.borrower = undefined;
950
+ }
951
+
952
+ export function setGlobal(c: Checker, name: string, symbol: Symbol): void {
953
+ if (c.globalChanges !== undefined) c.globalChanges.set(c.globals, name, symbol);
954
+ else c.globals.set(name, symbol);
955
+ }
956
+
957
+ function setMergedSymbol(c: Checker, id: number, target: Symbol): void {
958
+ if (c.mergedSymbolChanges !== undefined) c.mergedSymbolChanges.set(c.mergedSymbols, id, target);
959
+ else c.mergedSymbols.set(id, target);
960
+ }
961
+
962
+ /** Merges script locals into globals; ambient modules and augmentations wait for global types. */
963
+ export function initializeGlobals(c: Checker): void {
964
+ const globals = c.globals;
965
+ const merged = c.mergedGlobals;
966
+ if (merged !== undefined) {
967
+ // The constructor copied the globals and merged symbols.
968
+ for (const symbol of merged.ambientModuleSymbols) c.ambientModuleSymbols.push(symbol);
969
+ for (const pattern of merged.patternAmbientModules) c.patternAmbientModules.push(pattern);
970
+ for (const [name, symbol] of merged.patternAmbientModuleAugmentations)
971
+ c.patternAmbientModuleAugmentations.set(name, symbol);
972
+ addMergeDiagnostics(c, merged, 0);
973
+ if (merged.ownUndefined) setGlobal(c, 'undefined', c.undefinedSymbol);
974
+ return;
975
+ }
976
+ const libraryCount = getLibraryCount(c);
977
+ const libs = c.libGlobals;
978
+ if (libs !== undefined) {
979
+ // The constructor copied the globals and merged symbols.
980
+ for (const symbol of libs.ambientModuleSymbols) c.ambientModuleSymbols.push(symbol);
981
+ for (const pattern of libs.patternAmbientModules) c.patternAmbientModules.push(pattern);
982
+ } else if (libraryCount > 0) {
983
+ const diagnosticCount = c.diagnostics.count();
984
+ for (let i = 0; i < libraryCount; i++) mergeFileGlobals(c, c.files[i]!);
985
+ // Diagnostics belong to one checker, so libraries that report any aren't shared.
986
+ if (c.diagnostics.count() === diagnosticCount) {
987
+ c.libGlobals = new LibGlobals(c, c.files.slice(0, libraryCount));
988
+ libGlobalsCache.push(c.libGlobals);
989
+ }
990
+ }
991
+ for (let i = libraryCount; i < c.files.length; i++) mergeFileGlobals(c, c.files[i]!);
992
+ for (const file of c.files)
993
+ for (const augmentation of file.moduleAugmentations)
994
+ if (augmentation.parent !== undefined && isGlobalScopeAugmentation(augmentation.parent))
995
+ mergeModuleAugmentation(c, augmentation);
996
+ // addUndefinedToGlobalsOrErrorOnRedeclaration
997
+ const target = globals.get('undefined');
998
+ if (target !== undefined) {
999
+ for (const declaration of getDeclarations(target))
1000
+ if (!isTypeDeclaration(declaration))
1001
+ c.addDiagnostic(
1002
+ createDiagnosticForNode(
1003
+ declaration,
1004
+ Diagnostics.Declaration_name_conflicts_with_built_in_global_identifier_0,
1005
+ ['undefined'],
1006
+ ),
1007
+ );
1008
+ } else setGlobal(c, 'undefined', c.undefinedSymbol);
1009
+ }
1010
+
1011
+ export function mergeAmbientModulesAndAugmentations(c: Checker): void {
1012
+ const merged = c.mergedGlobals;
1013
+ if (merged !== undefined) {
1014
+ addMergeDiagnostics(c, merged, 1);
1015
+ return;
1016
+ }
1017
+ for (const symbol of c.ambientModuleSymbols) mergeGlobalSymbol(c, symbol);
1018
+ for (const file of c.files)
1019
+ for (const augmentation of file.moduleAugmentations)
1020
+ if (augmentation.parent !== undefined && !isGlobalScopeAugmentation(augmentation.parent))
1021
+ mergeModuleAugmentation(c, augmentation);
1022
+ }
1023
+
1024
+ export function isAmbientModuleSymbolName(name: string): boolean {
1025
+ return name.length >= 2 && name.charCodeAt(0) === 0x22 && name.charCodeAt(name.length - 1) === 0x22;
1026
+ }
1027
+
1028
+ function isTypeDeclaration(node: Node): boolean {
1029
+ switch (node.kind) {
1030
+ case SyntaxKind.TypeParameter:
1031
+ case SyntaxKind.ClassDeclaration:
1032
+ case SyntaxKind.InterfaceDeclaration:
1033
+ case SyntaxKind.TypeAliasDeclaration:
1034
+ case SyntaxKind.JSTypeAliasDeclaration:
1035
+ case SyntaxKind.EnumDeclaration:
1036
+ return true;
1037
+ case SyntaxKind.ImportClause:
1038
+ return getIsTypeOnly(node);
1039
+ case SyntaxKind.ImportSpecifier:
1040
+ case SyntaxKind.ExportSpecifier:
1041
+ return getIsTypeOnly(node);
1042
+ }
1043
+ return false;
1044
+ }
1045
+
1046
+ function mergeGlobalSymbol(c: Checker, symbol: Symbol): void {
1047
+ const globalSymbol = c.globals.get(symbol.name);
1048
+ setGlobal(
1049
+ c,
1050
+ symbol.name,
1051
+ globalSymbol !== undefined ? mergeSymbol(c, globalSymbol, symbol, false) : getMergedSymbol(c, symbol),
1052
+ );
1053
+ }
1054
+
1055
+ function mergeModuleAugmentation(c: Checker, moduleName: Node): void {
1056
+ const moduleNode = moduleName.parent as ModuleDeclaration;
1057
+ const augmentationSymbol = moduleNode.symbol!;
1058
+ // Several augmentations in one file share a symbol; merge it once.
1059
+ if (augmentationSymbol.declaration! !== moduleNode) return;
1060
+ if (isGlobalScopeAugmentation(moduleNode)) {
1061
+ if (augmentationSymbol.exports !== undefined)
1062
+ mergeSymbolTable(c, c.globals, augmentationSymbol.exports, false, undefined);
1063
+ return;
1064
+ }
1065
+ const moduleNotFoundError =
1066
+ (moduleNode.parent!.flags & NodeFlags.Ambient) === 0
1067
+ ? Diagnostics.Invalid_module_name_in_augmentation_module_0_cannot_be_found
1068
+ : undefined;
1069
+ let mainModule = resolveExternalModuleNameWorker(c, moduleName, moduleName, moduleNotFoundError, false, true);
1070
+ if (mainModule === undefined) return;
1071
+ mainModule = resolveExternalModuleSymbol(c, mainModule, false)!;
1072
+ if ((mainModule.flags & SymbolFlags.Namespace) !== 0) {
1073
+ for (const pattern of c.patternAmbientModules)
1074
+ if (pattern.symbol === mainModule) {
1075
+ const merged = mergeSymbol(c, augmentationSymbol, mainModule, true);
1076
+ c.patternAmbientModuleAugmentations.set(getText(moduleName), merged);
1077
+ return;
1078
+ }
1079
+ // Exports the module gets through `export *` live on the re-exported symbols; merge into those.
1080
+ const mainExports = mainModule.exports;
1081
+ const exports = augmentationSymbol.exports;
1082
+ if (
1083
+ mainExports !== undefined &&
1084
+ mainExports.has(InternalSymbolName.ExportStar) &&
1085
+ exports !== undefined &&
1086
+ exports.size > 0
1087
+ ) {
1088
+ const resolvedExports = getExportsOfModuleWorker(c, mainModule);
1089
+ for (const [id, symbol] of exports) {
1090
+ const resolved = resolvedExports.get(id);
1091
+ if (resolved !== undefined && !mainExports.has(id)) mergeSymbol(c, resolved, symbol, false);
1092
+ }
1093
+ }
1094
+ mergeSymbol(c, mainModule, augmentationSymbol, false);
1095
+ } else
1096
+ c.error(
1097
+ moduleName,
1098
+ Diagnostics.Cannot_augment_module_0_because_it_resolves_to_a_non_module_entity,
1099
+ getText(moduleName),
1100
+ );
1101
+ }
1102
+
1103
+ export function mergeSymbolTable(
1104
+ c: Checker,
1105
+ target: SymbolTable,
1106
+ source: SymbolTable,
1107
+ unidirectional: boolean,
1108
+ mergedParent: Symbol | undefined,
1109
+ ): void {
1110
+ for (const [id, sourceSymbol] of source) {
1111
+ const targetSymbol = target.get(id);
1112
+ const merged =
1113
+ targetSymbol !== undefined
1114
+ ? mergeSymbol(c, targetSymbol, sourceSymbol, unidirectional)
1115
+ : getMergedSymbol(c, sourceSymbol);
1116
+ // A merged symbol takes the parent that initiated the merge of its exports.
1117
+ if (mergedParent !== undefined && targetSymbol !== undefined && (merged.flags & SymbolFlags.Transient) !== 0)
1118
+ merged.parent = mergedParent;
1119
+ if (target === c.globals) setGlobal(c, id, merged);
1120
+ else target.set(id, merged);
1121
+ }
1122
+ }
1123
+
1124
+ /** Merges `source` into `target`, cloning a non-transient target first. */
1125
+ export function mergeSymbol(c: Checker, target: Symbol, source: Symbol, unidirectional: boolean): Symbol {
1126
+ if (
1127
+ (target.flags & getExcludedSymbolFlags(source.flags)) === 0 ||
1128
+ ((source.flags | target.flags) & SymbolFlags.Assignment) !== 0
1129
+ ) {
1130
+ if (source === target) return target;
1131
+ if ((target.flags & SymbolFlags.Transient) === 0) {
1132
+ const resolvedTarget = resolveSymbol(c, target)!;
1133
+ if (resolvedTarget === c.unknownSymbol) return source;
1134
+ if (
1135
+ (resolvedTarget.flags & getExcludedSymbolFlags(source.flags)) === 0 ||
1136
+ ((source.flags | resolvedTarget.flags) & SymbolFlags.Assignment) !== 0
1137
+ )
1138
+ target = cloneSymbol(c, resolvedTarget);
1139
+ else {
1140
+ reportMergeSymbolError(c, target, source);
1141
+ return source;
1142
+ }
1143
+ } else if (sharedSources(c, target) !== undefined) target = copySharedSymbol(c, target);
1144
+ if (
1145
+ (source.flags & SymbolFlags.ValueModule) !== 0 &&
1146
+ (target.flags & SymbolFlags.ValueModule) !== 0 &&
1147
+ (target.flags & SymbolFlags.ConstEnumOnlyModule) !== 0 &&
1148
+ (source.flags & SymbolFlags.ConstEnumOnlyModule) === 0
1149
+ )
1150
+ target.flags &= ~SymbolFlags.ConstEnumOnlyModule;
1151
+ let sourceFlags = source.flags;
1152
+ if ((target.flags & SymbolFlags.ConstEnumOnlyModule) === 0) sourceFlags &= ~SymbolFlags.ConstEnumOnlyModule;
1153
+ target.flags |= sourceFlags;
1154
+ if (source.valueDeclaration !== undefined) setValueDeclaration(target, source.valueDeclaration);
1155
+ for (const d of getDeclarations(source)) addDeclaration(target, d);
1156
+ if (source.members !== undefined) {
1157
+ if (target.members === undefined) target.members = new Map<string, Symbol>();
1158
+ mergeSymbolTable(c, target.members, source.members, unidirectional, undefined);
1159
+ }
1160
+ if (source.exports !== undefined) {
1161
+ if (target.exports === undefined) target.exports = new Map<string, Symbol>();
1162
+ mergeSymbolTable(c, target.exports, source.exports, unidirectional, target);
1163
+ }
1164
+ if (!unidirectional) recordMergedSymbol(c, target, source);
1165
+ } else if ((target.flags & SymbolFlags.NamespaceModule) !== 0) {
1166
+ // `var globalThis` already reports a conflict with the built-in.
1167
+ if (target !== c.globalThisSymbol)
1168
+ c.error(
1169
+ getNameOfDeclaration(source.declaration!),
1170
+ Diagnostics.Cannot_augment_module_0_with_value_exports_because_it_resolves_to_a_non_module_entity,
1171
+ symbolToString(c, target),
1172
+ );
1173
+ } else reportMergeSymbolError(c, target, source);
1174
+ return target;
1175
+ }
1176
+
1177
+ function reportMergeSymbolError(c: Checker, target: Symbol, source: Symbol): void {
1178
+ const isEitherEnum = ((target.flags | source.flags) & SymbolFlags.Enum) !== 0;
1179
+ const isEitherBlockScoped = ((target.flags | source.flags) & SymbolFlags.BlockScopedVariable) !== 0;
1180
+ const message = isEitherEnum
1181
+ ? Diagnostics.Enum_declarations_can_only_merge_with_namespace_or_other_enum_declarations
1182
+ : isEitherBlockScoped
1183
+ ? Diagnostics.Cannot_redeclare_block_scoped_variable_0
1184
+ : Diagnostics.Duplicate_identifier_0;
1185
+ const name = symbolToString(c, source);
1186
+ if (!isPlainJSFile(source)) addDuplicateDeclarationErrors(c, source, message, name, target);
1187
+ if (!isPlainJSFile(target)) addDuplicateDeclarationErrors(c, target, message, name, source);
1188
+ }
1189
+
1190
+ function isPlainJSFile(symbol: Symbol): boolean {
1191
+ if (declarationCount(symbol) === 0) return false;
1192
+ const file = getSourceFileOfNode(symbol.declaration!);
1193
+ return file.isJS() && file.checkJsDirective === undefined;
1194
+ }
1195
+
1196
+ function addDuplicateDeclarationErrors(
1197
+ c: Checker,
1198
+ target: Symbol,
1199
+ message: DiagnosticMessage,
1200
+ name: string,
1201
+ source: Symbol,
1202
+ ): void {
1203
+ for (const node of getDeclarations(target))
1204
+ addDuplicateDeclarationError(c, node, message, name, getDeclarations(source));
1205
+ }
1206
+
1207
+ export function addDuplicateDeclarationError(
1208
+ c: Checker,
1209
+ node: Node,
1210
+ message: DiagnosticMessage,
1211
+ name: string,
1212
+ relatedNodes: readonly Node[],
1213
+ ): void {
1214
+ const errorNode = getNameOfDeclaration(node) ?? node;
1215
+ const error = lookupOrIssueError(c, errorNode, message, [name]);
1216
+ for (const relatedNode of relatedNodes) {
1217
+ const adjusted = getNameOfDeclaration(relatedNode) ?? relatedNode;
1218
+ if (adjusted === errorNode) continue;
1219
+ const leading = createDiagnosticForNode(adjusted, Diagnostics.X_0_was_also_declared_here, [name]);
1220
+ const followOn = createDiagnosticForNode(adjusted, Diagnostics.X_and_here, []);
1221
+ const related = error.relatedInformation;
1222
+ if (related.length >= 5 || hasMatchingDiagnostic(related, leading, followOn)) continue;
1223
+ error.addRelatedInfo(related.length === 0 ? leading : followOn);
1224
+ }
1225
+ }
1226
+
1227
+ function hasMatchingDiagnostic(diagnostics: readonly Diagnostic[], a: Diagnostic, b: Diagnostic): boolean {
1228
+ for (const d of diagnostics) if (compareDiagnostics(d, b) === 0 || compareDiagnostics(d, a) === 0) return true;
1229
+ return false;
1230
+ }
1231
+
1232
+ function lookupOrIssueError(c: Checker, location: Node, message: DiagnosticMessage, args: string[]) {
1233
+ const diagnostic = createDiagnosticForNode(location, message, args);
1234
+ const existing = c.diagnostics.lookup(diagnostic);
1235
+ if (existing !== undefined) return existing;
1236
+ c.addDiagnostic(diagnostic);
1237
+ return diagnostic;
1238
+ }
1239
+
1240
+ export function getExcludedSymbolFlags(flags: SymbolFlags): SymbolFlags {
1241
+ let result = 0;
1242
+ if ((flags & SymbolFlags.BlockScopedVariable) !== 0) result |= SymbolFlags.BlockScopedVariableExcludes;
1243
+ if ((flags & SymbolFlags.FunctionScopedVariable) !== 0) result |= SymbolFlags.FunctionScopedVariableExcludes;
1244
+ if ((flags & SymbolFlags.Property) !== 0) result |= SymbolFlags.PropertyExcludes;
1245
+ if ((flags & SymbolFlags.EnumMember) !== 0) result |= SymbolFlags.EnumMemberExcludes;
1246
+ if ((flags & SymbolFlags.Function) !== 0) result |= SymbolFlags.FunctionExcludes;
1247
+ if ((flags & SymbolFlags.Class) !== 0) result |= SymbolFlags.ClassExcludes;
1248
+ if ((flags & SymbolFlags.Interface) !== 0) result |= SymbolFlags.InterfaceExcludes;
1249
+ if ((flags & SymbolFlags.RegularEnum) !== 0) result |= SymbolFlags.RegularEnumExcludes;
1250
+ if ((flags & SymbolFlags.ConstEnum) !== 0) result |= SymbolFlags.ConstEnumExcludes;
1251
+ if ((flags & SymbolFlags.ValueModule) !== 0) result |= SymbolFlags.ValueModuleExcludes;
1252
+ if ((flags & SymbolFlags.Method) !== 0) result |= SymbolFlags.MethodExcludes;
1253
+ if ((flags & SymbolFlags.GetAccessor) !== 0) result |= SymbolFlags.GetAccessorExcludes;
1254
+ if ((flags & SymbolFlags.SetAccessor) !== 0) result |= SymbolFlags.SetAccessorExcludes;
1255
+ if ((flags & SymbolFlags.TypeParameter) !== 0) result |= SymbolFlags.TypeParameterExcludes;
1256
+ if ((flags & SymbolFlags.TypeAlias) !== 0) result |= SymbolFlags.TypeAliasExcludes;
1257
+ if ((flags & SymbolFlags.Alias) !== 0) result |= SymbolFlags.AliasExcludes;
1258
+ if ((flags & SymbolFlags.ReplaceableByMethod) !== 0) result &= ~SymbolFlags.Method;
1259
+ return result;
1260
+ }
1261
+
1262
+ export function cloneSymbol(c: Checker, symbol: Symbol): Symbol {
1263
+ const result = c.newSymbol(symbol.flags, symbol.name);
1264
+ setDeclarations(result, getDeclarations(symbol).slice());
1265
+ result.parent = symbol.parent;
1266
+ result.valueDeclaration = symbol.valueDeclaration;
1267
+ if (symbol.members !== undefined) result.members = new Map(symbol.members);
1268
+ if (symbol.exports !== undefined) result.exports = new Map(symbol.exports);
1269
+ recordMergedSymbol(c, result, symbol);
1270
+ return result;
1271
+ }
1272
+
1273
+ /**
1274
+ * A checker's own copy of a symbol shared through `LibGlobals`, which stands for it: the symbols
1275
+ * merged into the shared one, and the shared one itself, now merge into the copy.
1276
+ */
1277
+ function copySharedSymbol(c: Checker, shared: Symbol): Symbol {
1278
+ const result = c.newSymbol(shared.flags, shared.name);
1279
+ setDeclarations(result, getDeclarations(shared).slice());
1280
+ result.parent = shared.parent;
1281
+ result.valueDeclaration = shared.valueDeclaration;
1282
+ if (shared.members !== undefined) result.members = new Map(shared.members);
1283
+ if (shared.exports !== undefined) result.exports = new Map(shared.exports);
1284
+ c.sharedSymbolCopies.set(result, shared);
1285
+ recordMergedSymbol(c, result, result);
1286
+ return result;
1287
+ }
1288
+
1289
+ function recordMergedSymbol(c: Checker, target: Symbol, source: Symbol): void {
1290
+ setMergedSymbol(c, getSymbolId(source), target);
1291
+ // Merging a copy merges what it stands for.
1292
+ const shared = c.sharedSymbolCopies.get(source);
1293
+ if (shared !== undefined) {
1294
+ setMergedSymbol(c, getSymbolId(shared), target);
1295
+ for (const id of sharedSources(c, shared)!) setMergedSymbol(c, id, target);
1296
+ }
1297
+ }
1298
+
1299
+ export function getMergedSymbol(c: Checker, symbol: Symbol): Symbol {
1300
+ const id = symbol.id;
1301
+ if (id !== 0) {
1302
+ const merged = c.mergedSymbols.get(id);
1303
+ if (merged !== undefined) return merged;
1304
+ }
1305
+ return symbol;
1306
+ }
1307
+
1308
+ export function getParentOfSymbol(c: Checker, symbol: Symbol): Symbol | undefined {
1309
+ return symbol.parent !== undefined ? getMergedSymbol(c, getLateBoundSymbol(c, symbol.parent)) : undefined;
1310
+ }
1311
+
1312
+ export function getExportSymbolOfValueSymbolIfExported(c: Checker, symbol: Symbol): Symbol {
1313
+ if ((symbol.flags & SymbolFlags.ExportValue) !== 0 && symbol.exportSymbol !== undefined) symbol = symbol.exportSymbol;
1314
+ return getMergedSymbol(c, symbol);
1315
+ }
1316
+
1317
+ export function getSymbolOfDeclaration(c: Checker, node: Node): Symbol | undefined {
1318
+ const symbol = getSymbol(node);
1319
+ return symbol !== undefined ? getMergedSymbol(c, getLateBoundSymbol(c, symbol)) : undefined;
1320
+ }
1321
+
1322
+ function hasStaticDeclaration(symbol: Symbol): boolean {
1323
+ for (const d of getDeclarations(symbol)) if (hasStaticModifier(d)) return true;
1324
+ return false;
1325
+ }
1326
+
1327
+ export function getLateBoundSymbol(c: Checker, symbol: Symbol): Symbol {
1328
+ if ((symbol.flags & SymbolFlags.ClassMember) === 0 || symbol.name !== InternalSymbolName.Computed) return symbol;
1329
+ const links = c.symbolLinks(symbol);
1330
+ if (links.lateSymbol === undefined && hasLateBindableDeclaration(c, symbol)) {
1331
+ // Force late binding of the parent's members or exports, which sets lateSymbol.
1332
+ if (symbol.parent !== undefined) {
1333
+ const parent = getMergedSymbol(c, symbol.parent);
1334
+ if (hasStaticDeclaration(symbol)) getExportsOfSymbol(c, parent);
1335
+ else getMembersOfSymbol(c, parent);
1336
+ } else {
1337
+ // An `F[name] = …` assignment in a script has no parent. Checking its target late-binds it
1338
+ // with the members of the function it's assigned to.
1339
+ for (const declaration of getDeclarations(symbol))
1340
+ if (declaration instanceof BinaryExpression) checkExpressionCached(c, declaration.left);
1341
+ }
1342
+ }
1343
+ if (links.lateSymbol === undefined) links.lateSymbol = symbol;
1344
+ return links.lateSymbol;
1345
+ }
1346
+
1347
+ function hasLateBindableDeclaration(c: Checker, symbol: Symbol): boolean {
1348
+ for (const declaration of getDeclarations(symbol)) if (hasLateBindableName(c, declaration)) return true;
1349
+ return false;
1350
+ }
1351
+
1352
+ // ---- Global types
1353
+
1354
+ export function getGlobalSymbol(
1355
+ c: Checker,
1356
+ name: string,
1357
+ meaning: SymbolFlags,
1358
+ diagnostic: DiagnosticMessage | undefined,
1359
+ ): Symbol | undefined {
1360
+ // Without a location, missing globals are global diagnostics.
1361
+ return resolveName(c, undefined, name, meaning, diagnostic, false, false);
1362
+ }
1363
+
1364
+ function getGlobalTypeDeclaration(symbol: Symbol): Node | undefined {
1365
+ for (const d of getDeclarations(symbol)) {
1366
+ switch (d.kind) {
1367
+ case SyntaxKind.ClassDeclaration:
1368
+ case SyntaxKind.InterfaceDeclaration:
1369
+ case SyntaxKind.EnumDeclaration:
1370
+ case SyntaxKind.TypeAliasDeclaration:
1371
+ return d;
1372
+ }
1373
+ }
1374
+ return undefined;
1375
+ }
1376
+
1377
+ /** The global class or interface `name` with `arity` type parameters, or the empty (generic) object type. */
1378
+ export function getGlobalType(c: Checker, name: string, arity: number, reportErrors: boolean): Type {
1379
+ const symbol = getGlobalSymbol(
1380
+ c,
1381
+ name,
1382
+ SymbolFlags.Type,
1383
+ reportErrors ? Diagnostics.Cannot_find_global_type_0 : undefined,
1384
+ );
1385
+ if (symbol !== undefined) {
1386
+ if ((symbol.flags & (SymbolFlags.Class | SymbolFlags.Interface)) !== 0) {
1387
+ const type = getDeclaredTypeOfSymbol(c, symbol);
1388
+ if ((type as InterfaceType).typeParameterCount() === arity) return type;
1389
+ if (reportErrors)
1390
+ c.error(
1391
+ getGlobalTypeDeclaration(symbol),
1392
+ Diagnostics.Global_type_0_must_have_1_type_parameter_s,
1393
+ symbol.name,
1394
+ String(arity),
1395
+ );
1396
+ } else if (reportErrors)
1397
+ c.error(
1398
+ getGlobalTypeDeclaration(symbol),
1399
+ Diagnostics.Global_type_0_must_be_a_class_or_interface_type,
1400
+ symbol.name,
1401
+ );
1402
+ }
1403
+ return arity !== 0 ? c.emptyGenericType : c.emptyObjectType;
1404
+ }
1405
+
1406
+ /** Memoized `getGlobalType`, keyed by name, arity and whether errors were reported. */
1407
+ export function getCachedGlobalType(c: Checker, name: string, arity: number, reportErrors: boolean): Type {
1408
+ // By name, then by arity and whether errors are reported: callers pass literal names.
1409
+ let byArity = c.globalTypeCache.get(name);
1410
+ if (byArity === undefined) {
1411
+ byArity = new Map<number, Type>();
1412
+ c.globalTypeCache.set(name, byArity);
1413
+ }
1414
+ const slot = arity * 2 + (reportErrors ? 1 : 0);
1415
+ let type = byArity.get(slot);
1416
+ if (type === undefined) {
1417
+ type = getGlobalType(c, name, arity, reportErrors);
1418
+ byArity.set(slot, type);
1419
+ }
1420
+ return type;
1421
+ }
1422
+
1423
+ export function getGlobalTypeAliasSymbol(
1424
+ c: Checker,
1425
+ name: string,
1426
+ arity: number,
1427
+ reportErrors: boolean,
1428
+ ): Symbol | undefined {
1429
+ const key = 'alias:' + name + '/' + arity + (reportErrors ? '!' : '');
1430
+ const cached = c.globalSymbolCache.get(key);
1431
+ if (cached !== undefined) return cached === null ? undefined : cached;
1432
+ let symbol = getGlobalSymbol(
1433
+ c,
1434
+ name,
1435
+ SymbolFlags.TypeAlias,
1436
+ reportErrors ? Diagnostics.Cannot_find_global_type_0 : undefined,
1437
+ );
1438
+ if (symbol !== undefined) {
1439
+ getDeclaredTypeOfSymbol(c, symbol);
1440
+ const typeParameters = c.symbolLinks(symbol).typeParameters;
1441
+ if ((typeParameters === undefined ? 0 : typeParameters.length) !== arity) {
1442
+ if (reportErrors) {
1443
+ c.error(
1444
+ getDeclarationOfKind(symbol, SyntaxKind.TypeAliasDeclaration),
1445
+ Diagnostics.Global_type_0_must_have_1_type_parameter_s,
1446
+ symbol.name,
1447
+ String(arity),
1448
+ );
1449
+ }
1450
+ symbol = undefined;
1451
+ }
1452
+ }
1453
+ c.globalSymbolCache.set(key, symbol === undefined ? null : symbol);
1454
+ return symbol;
1455
+ }
1456
+
1457
+ export function getGlobalValueSymbol(c: Checker, name: string, reportErrors: boolean): Symbol | undefined {
1458
+ const key = 'value:' + name + (reportErrors ? '!' : '');
1459
+ const cached = c.globalSymbolCache.get(key);
1460
+ if (cached !== undefined) return cached === null ? undefined : cached;
1461
+ const symbol = getGlobalSymbol(
1462
+ c,
1463
+ name,
1464
+ SymbolFlags.Value,
1465
+ reportErrors ? Diagnostics.Cannot_find_global_value_0 : undefined,
1466
+ );
1467
+ c.globalSymbolCache.set(key, symbol === undefined ? null : symbol);
1468
+ return symbol;
1469
+ }
1470
+
1471
+ export function getGlobalStrictFunctionType(c: Checker, name: string): Type {
1472
+ return c.strictBindCallApply ? getGlobalType(c, name, 0, true) : c.globalFunctionType;
1473
+ }
1474
+
1475
+ // ---- Aliases
1476
+
1477
+ export function isNonLocalAlias(symbol: Symbol | undefined, excludes: SymbolFlags): boolean {
1478
+ if (symbol === undefined) return false;
1479
+ return (
1480
+ (symbol.flags & (SymbolFlags.Alias | excludes)) === SymbolFlags.Alias ||
1481
+ ((symbol.flags & SymbolFlags.Alias) !== 0 && (symbol.flags & SymbolFlags.Assignment) !== 0)
1482
+ );
1483
+ }
1484
+
1485
+ export function resolveSymbol(c: Checker, symbol: Symbol | undefined): Symbol | undefined {
1486
+ if (symbol !== undefined && isNonLocalAlias(symbol, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace))
1487
+ return resolveAlias(c, symbol);
1488
+ return symbol;
1489
+ }
1490
+
1491
+ export function resolveSymbolEx(c: Checker, symbol: Symbol, dontResolveAlias: boolean): Symbol {
1492
+ if (!dontResolveAlias && isNonLocalAlias(symbol, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace))
1493
+ return resolveAlias(c, symbol);
1494
+ return symbol;
1495
+ }
1496
+
1497
+ export function getDeclarationOfAliasSymbol(symbol: Symbol): Node | undefined {
1498
+ for (let i = declarationCount(symbol) - 1; i >= 0; i--) {
1499
+ const d = declarationAt(symbol, i);
1500
+ if (isAliasSymbolDeclaration(d)) return d;
1501
+ }
1502
+ return undefined;
1503
+ }
1504
+
1505
+ export function isAliasSymbolDeclaration(node: Node): boolean {
1506
+ switch (node.kind) {
1507
+ case SyntaxKind.ImportEqualsDeclaration:
1508
+ case SyntaxKind.NamespaceExportDeclaration:
1509
+ case SyntaxKind.NamespaceImport:
1510
+ case SyntaxKind.NamespaceExport:
1511
+ case SyntaxKind.ImportSpecifier:
1512
+ case SyntaxKind.ExportSpecifier:
1513
+ return true;
1514
+ case SyntaxKind.ImportClause:
1515
+ return getName(node) !== undefined;
1516
+ case SyntaxKind.ExportAssignment: {
1517
+ const e = getExpression(node);
1518
+ return e !== undefined && isEntityNameExpressionNode(e);
1519
+ }
1520
+ case SyntaxKind.VariableDeclaration:
1521
+ case SyntaxKind.BindingElement:
1522
+ case SyntaxKind.BinaryExpression:
1523
+ return isJSAliasDeclaration(node);
1524
+ }
1525
+ return false;
1526
+ }
1527
+
1528
+ function isEntityNameExpressionNode(node: Node): boolean {
1529
+ if (node.kind === SyntaxKind.Identifier) return true;
1530
+ if (node.kind === SyntaxKind.PropertyAccessExpression) {
1531
+ const e = getExpression(node)!;
1532
+ const name = getName(node);
1533
+ return name !== undefined && name.kind === SyntaxKind.Identifier && isEntityNameExpressionNode(e);
1534
+ }
1535
+ return false;
1536
+ }
1537
+
1538
+ /** The alias target, unless resolving it now would be circular. */
1539
+ export function tryResolveAlias(c: Checker, symbol: Symbol): Symbol | undefined {
1540
+ if (
1541
+ c.symbolLinks(symbol).aliasTarget !== undefined ||
1542
+ findResolutionCycleStartIndex(c, symbol, TypeSystemPropertyName.AliasTarget) < 0
1543
+ )
1544
+ return resolveAlias(c, symbol);
1545
+ return undefined;
1546
+ }
1547
+
1548
+ export function resolveAlias(c: Checker, symbol: Symbol): Symbol {
1549
+ const links = c.symbolLinks(symbol);
1550
+ let target = links.aliasTarget;
1551
+ if (target !== undefined) return target;
1552
+ if (!pushTypeResolution(c, symbol, TypeSystemPropertyName.AliasTarget)) return c.unknownSymbol;
1553
+ const node = getDeclarationOfAliasSymbol(symbol);
1554
+ let resolved = getTargetOfAliasDeclaration(c, node);
1555
+ // A pure alias target is resolved transitively, carrying over its type-only declaration.
1556
+ if (resolved !== undefined && isNonLocalAlias(resolved, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace))
1557
+ resolved = resolveIndirectionAlias(c, symbol, resolved);
1558
+ target = resolved ?? c.unknownSymbol;
1559
+ links.aliasTarget = target;
1560
+ if (!popTypeResolution(c)) {
1561
+ c.error(node, Diagnostics.Circular_definition_of_import_alias_0, symbolToString(c, symbol));
1562
+ links.aliasTarget = c.unknownSymbol;
1563
+ }
1564
+ return links.aliasTarget;
1565
+ }
1566
+
1567
+ /**
1568
+ * The combined flags of `symbol` and every alias target; All when an alias resolves to unknown. With
1569
+ * `excludeTypeOnlyMeanings`, the chain stops at the first alias with a type-only declaration.
1570
+ */
1571
+ export function getSymbolFlags(c: Checker, symbol: Symbol, excludeTypeOnlyMeanings = false): SymbolFlags {
1572
+ let flags = symbol.flags;
1573
+ // Created for the first alias of an alias, as tsgo's zero-value set.
1574
+ let seen: Set<Symbol> | undefined = undefined;
1575
+ while ((symbol.flags & SymbolFlags.Alias) !== 0) {
1576
+ if (excludeTypeOnlyMeanings && getTypeOnlyAliasDeclaration(c, symbol) !== undefined) break;
1577
+ const target = getExportSymbolOfValueSymbolIfExported(c, resolveAlias(c, symbol));
1578
+ if (target === c.unknownSymbol) return SymbolFlags.All;
1579
+ if ((target.flags & SymbolFlags.Alias) !== 0) {
1580
+ if (target === symbol || (seen !== undefined && seen.has(target))) break;
1581
+ if (seen === undefined) seen = new Set<Symbol>();
1582
+ seen.add(symbol);
1583
+ seen.add(target);
1584
+ }
1585
+ flags |= target.flags;
1586
+ symbol = target;
1587
+ }
1588
+ return flags;
1589
+ }
1590
+
1591
+ // ---- Members and exports
1592
+
1593
+ export function getExportsOfSymbol(c: Checker, symbol: Symbol): SymbolTable {
1594
+ if ((symbol.flags & SymbolFlags.LateBindingContainer) !== 0) return getResolvedMembersOrExports(c, symbol, true);
1595
+ if ((symbol.flags & SymbolFlags.Module) !== 0) return getExportsOfModule(c, symbol);
1596
+ return symbol.exports ?? emptySymbolTable;
1597
+ }
1598
+
1599
+ export const emptySymbolTable: SymbolTable = new Map<string, Symbol>();
1600
+
1601
+ export function getExportsOfModule(c: Checker, moduleSymbol: Symbol): SymbolTable {
1602
+ // Late-bound members share the cache.
1603
+ if ((moduleSymbol.flags & SymbolFlags.LateBindingContainer) !== 0)
1604
+ return getResolvedMembersOrExports(c, moduleSymbol, true);
1605
+ const links = c.symbolLinks(moduleSymbol);
1606
+ let exports = links.resolvedExports;
1607
+ if (exports === undefined) {
1608
+ exports = getExportsOfModuleWorker(c, moduleSymbol);
1609
+ links.resolvedExports = exports;
1610
+ }
1611
+ return exports;
1612
+ }
1613
+
1614
+ export function getMembersOfSymbol(c: Checker, symbol: Symbol): SymbolTable {
1615
+ if ((symbol.flags & SymbolFlags.LateBindingContainer) !== 0) return getResolvedMembersOrExports(c, symbol, false);
1616
+ return symbol.members ?? emptySymbolTable;
1617
+ }
1618
+
1619
+ function getResolvedMembersOrExports(c: Checker, symbol: Symbol, isStatic: boolean): SymbolTable {
1620
+ const links = c.symbolLinks(symbol);
1621
+ const cached = isStatic ? links.resolvedExports : links.resolvedMembers;
1622
+ if (cached !== undefined) return cached;
1623
+ let early: SymbolTable;
1624
+ if (!isStatic) early = symbol.members ?? emptySymbolTable;
1625
+ else if ((symbol.flags & SymbolFlags.Module) !== 0) early = getExportsOfModuleWorker(c, symbol);
1626
+ else early = symbol.exports ?? emptySymbolTable;
1627
+ if (isStatic) links.resolvedExports = early;
1628
+ else links.resolvedMembers = early;
1629
+ let late: SymbolTable | undefined;
1630
+ for (const decl of getDeclarations(symbol)) {
1631
+ const members = getMembersOfDeclaration(decl);
1632
+ if (members === undefined) continue;
1633
+ for (const member of members) {
1634
+ if (isStatic !== hasStaticModifier(member)) continue;
1635
+ if (hasLateBindableName(c, member)) {
1636
+ if (late === undefined) late = new Map<string, Symbol>();
1637
+ lateBindMember(c, symbol, early, late, member);
1638
+ } else if (hasLateBindableIndexSignature(c, member)) {
1639
+ if (late === undefined) late = new Map<string, Symbol>();
1640
+ lateBindIndexSignature(c, early, late, member);
1641
+ }
1642
+ }
1643
+ }
1644
+ // JavaScript `F[name] = …` assignments with late-bindable names.
1645
+ const assignments = isStatic ? symbol.exports?.get(InternalSymbolName.AssignmentDeclaration) : undefined;
1646
+ if (assignments !== undefined)
1647
+ for (const member of getDeclarations(assignments))
1648
+ if (hasLateBindableName(c, member)) {
1649
+ if (late === undefined) late = new Map<string, Symbol>();
1650
+ lateBindMember(c, symbol, early, late, member);
1651
+ }
1652
+ const result = late === undefined ? early : combineSymbolTables(c, early, late);
1653
+ if (isStatic) links.resolvedExports = result;
1654
+ else links.resolvedMembers = result;
1655
+ return result;
1656
+ }
1657
+
1658
+ function getMembersOfDeclaration(decl: Node): Node[] | undefined {
1659
+ switch (decl.kind) {
1660
+ case SyntaxKind.ClassDeclaration:
1661
+ case SyntaxKind.ClassExpression:
1662
+ case SyntaxKind.InterfaceDeclaration:
1663
+ case SyntaxKind.TypeLiteral:
1664
+ return getMemberNodes(decl)?.nodes;
1665
+ case SyntaxKind.ObjectLiteralExpression:
1666
+ return getProperties(decl)!.nodes;
1667
+ }
1668
+ return undefined;
1669
+ }
1670
+
1671
+ export function combineSymbolTables(c: Checker, first: SymbolTable, second: SymbolTable): SymbolTable {
1672
+ if (first.size === 0) return second;
1673
+ if (second.size === 0) return first;
1674
+ const combined = new Map<string, Symbol>();
1675
+ mergeSymbolTable(c, combined, first, false, undefined);
1676
+ mergeSymbolTable(c, combined, second, false, undefined);
1677
+ return combined;
1678
+ }
1679
+
1680
+ /** Binds a member with a computed name whose type is a literal or unique symbol under that name. */
1681
+ function lateBindMember(c: Checker, parent: Symbol, early: SymbolTable, late: SymbolTable, decl: Node): Symbol {
1682
+ const cached = c.resolvedSymbols.get(decl.id);
1683
+ if (cached !== undefined) return cached;
1684
+ // A recursive request falls back to the early-bound symbol.
1685
+ c.resolvedSymbols.set(decl.id, getSymbol(decl));
1686
+ const declName = getLateBindableNameOfDeclaration(decl)!;
1687
+ const type =
1688
+ declName.kind === SyntaxKind.ElementAccessExpression
1689
+ ? checkExpressionCached(c, (declName as ElementAccessExpression).argumentExpression)
1690
+ : checkComputedPropertyName(c, declName);
1691
+ if (isTypeUsableAsPropertyName(type)) {
1692
+ const memberName = getPropertyNameFromType(type);
1693
+ const symbolFlags = getSymbol(decl)!.flags;
1694
+ let lateSymbol = late.get(memberName);
1695
+ if (lateSymbol === undefined) {
1696
+ lateSymbol = c.newSymbolWithCheckFlags(SymbolFlags.None, memberName, CheckFlags.Late);
1697
+ late.set(memberName, lateSymbol);
1698
+ }
1699
+ const earlySymbol = early.get(memberName);
1700
+ if ((lateSymbol.flags & getExcludedSymbolFlags(symbolFlags)) !== 0) {
1701
+ const declarations =
1702
+ earlySymbol !== undefined
1703
+ ? getDeclarations(earlySymbol).concat(getDeclarations(lateSymbol))
1704
+ : getDeclarations(lateSymbol);
1705
+ const name =
1706
+ (type.flags & 16384) !== 0 ? declarationNameToString(getSourceFileOfNode(declName), declName) : memberName;
1707
+ for (const d of declarations) c.error(getNameOfDeclaration(d) ?? d, Diagnostics.Duplicate_identifier_0, name);
1708
+ c.error(declName, Diagnostics.Duplicate_identifier_0, name);
1709
+ lateSymbol = c.newSymbolWithCheckFlags(SymbolFlags.None, memberName, CheckFlags.Late);
1710
+ }
1711
+ c.symbolNameTypes.set(getSymbolId(lateSymbol), type);
1712
+ addDeclarationToLateBoundSymbol(c, lateSymbol, decl, symbolFlags);
1713
+ if (lateSymbol.parent === undefined) lateSymbol.parent = parent;
1714
+ c.resolvedSymbols.set(decl.id, lateSymbol);
1715
+ }
1716
+ return c.resolvedSymbols.get(decl.id)!;
1717
+ }
1718
+
1719
+ /** Adds a member whose computed name has a non-literal key type to the index symbol. */
1720
+ function lateBindIndexSignature(c: Checker, early: SymbolTable, late: SymbolTable, decl: Node): void {
1721
+ let indexSymbol = late.get(InternalSymbolName.Index);
1722
+ if (indexSymbol === undefined) {
1723
+ const earlyIndex = early.get(InternalSymbolName.Index);
1724
+ if (earlyIndex === undefined)
1725
+ indexSymbol = c.newSymbolWithCheckFlags(SymbolFlags.None, InternalSymbolName.Index, CheckFlags.Late);
1726
+ else {
1727
+ indexSymbol = cloneSymbol(c, earlyIndex);
1728
+ indexSymbol.checkFlags |= CheckFlags.Late;
1729
+ }
1730
+ late.set(InternalSymbolName.Index, indexSymbol);
1731
+ }
1732
+ // Unlike late-bound members, `decl` gets no late symbol: the index symbol isn't one property.
1733
+ if (declarationCount(indexSymbol) === 0 || (getSymbol(decl)!.flags & SymbolFlags.ReplaceableByMethod) === 0)
1734
+ addDeclaration(indexSymbol, decl);
1735
+ }
1736
+
1737
+ function addDeclarationToLateBoundSymbol(c: Checker, symbol: Symbol, member: Node, symbolFlags: SymbolFlags): void {
1738
+ const memberSymbol = getSymbol(member)!;
1739
+ c.symbolLinks(memberSymbol).lateSymbol = symbol;
1740
+ if (declarationCount(symbol) === 0 || (memberSymbol.flags & SymbolFlags.ReplaceableByMethod) === 0) {
1741
+ symbol.flags |= symbolFlags;
1742
+ addDeclaration(symbol, member);
1743
+ }
1744
+ if ((symbolFlags & SymbolFlags.Value) !== 0) setValueDeclaration(symbol, member);
1745
+ }
1746
+
1747
+ export function isReservedMemberName(name: string): boolean {
1748
+ if (name.length < 2 || name.charCodeAt(0) !== 0xfffe) return false;
1749
+ const second = name.charCodeAt(1);
1750
+ return second !== 0x40 && second !== 0x23;
1751
+ }
1752
+
1753
+ /** Whether `symbol` has a value meaning; one reached through a type-only alias doesn't count. */
1754
+ export function symbolIsValue(c: Checker, symbol: Symbol): boolean {
1755
+ return (
1756
+ (symbol.flags & SymbolFlags.Value) !== 0 ||
1757
+ ((symbol.flags & SymbolFlags.Alias) !== 0 && (getSymbolFlags(c, symbol, true) & SymbolFlags.Value) !== 0)
1758
+ );
1759
+ }
1760
+
1761
+ function isDeclarationContainedBy(symbol: Symbol, container: Symbol): boolean {
1762
+ const declaration = symbol.valueDeclaration;
1763
+ if (declaration !== undefined)
1764
+ for (const d of getDeclarations(container)) if (declaration.pos >= d.pos && declaration.end <= d.end) return true;
1765
+ return false;
1766
+ }
1767
+
1768
+ /** Value members other than signatures and index signatures, declared ones first, each part ordered by declaration. */
1769
+ export function getNamedMembers(c: Checker, members: SymbolTable | undefined, container: Symbol | undefined): Symbol[] {
1770
+ if (members === undefined || members.size === 0) return [];
1771
+ const isClassOrInterface =
1772
+ container !== undefined && (container.flags & (SymbolFlags.Class | SymbolFlags.Interface)) !== 0;
1773
+ const contained: Symbol[] = [];
1774
+ const rest: Symbol[] = [];
1775
+ for (const [id, symbol] of members) {
1776
+ if (isReservedMemberName(id) || !symbolIsValue(c, symbol)) continue;
1777
+ if (isClassOrInterface && isDeclarationContainedBy(symbol, container!)) contained.push(symbol);
1778
+ else rest.push(symbol);
1779
+ }
1780
+ sortSymbols(c, contained);
1781
+ sortSymbols(c, rest);
1782
+ return contained.length === 0 ? rest : contained.concat(rest);
1783
+ }
1784
+
1785
+ /** Sorts symbols by declaration order; members are usually in that order already. */
1786
+ function sortSymbols(c: Checker, symbols: Symbol[]): void {
1787
+ for (let i = 1; i < symbols.length; i++)
1788
+ if (compareSymbols(c, symbols[i - 1]!, symbols[i]!) > 0) {
1789
+ symbols.sort((a, b) => compareSymbols(c, a, b));
1790
+ return;
1791
+ }
1792
+ }
1793
+
1794
+ // ---- Entity names
1795
+
1796
+ export function getFirstIdentifier(node: Node): Identifier {
1797
+ let current = node;
1798
+ for (;;) {
1799
+ if (current.kind === SyntaxKind.QualifiedName) current = (current as QualifiedName).left;
1800
+ else if (current.kind === SyntaxKind.PropertyAccessExpression) current = getExpression(current)!;
1801
+ else return current as Identifier;
1802
+ }
1803
+ }
1804
+
1805
+ export function resolveEntityName(
1806
+ c: Checker,
1807
+ name: Node,
1808
+ meaning: SymbolFlags,
1809
+ ignoreErrors: boolean,
1810
+ dontResolveAlias: boolean,
1811
+ location: Node | undefined,
1812
+ ): Symbol | undefined {
1813
+ if (nodeIsMissing(name)) return undefined;
1814
+ let symbol: Symbol | undefined;
1815
+ if (name.kind === SyntaxKind.Identifier) {
1816
+ const message = ignoreErrors
1817
+ ? undefined
1818
+ : meaning === SymbolFlags.Namespace || (name.flags & NodeFlags.Synthesized) !== 0
1819
+ ? Diagnostics.Cannot_find_namespace_0
1820
+ : getCannotFindNameDiagnosticForName(c, getFirstIdentifier(name));
1821
+ const resolveLocation = location ?? name;
1822
+ const text = getText(name);
1823
+ if (meaning === SymbolFlags.Namespace) {
1824
+ const found = resolveName(c, resolveLocation, text, meaning, undefined, true, false);
1825
+ symbol = found !== undefined ? getMergedSymbol(c, found) : undefined;
1826
+ if (symbol === undefined) {
1827
+ // Typedefs exported from CommonJS are stored on the module symbol, the parent of its `export=`. The
1828
+ // lookup also marks an alias of the name as referenced.
1829
+ const alias = resolveName(c, resolveLocation, text, SymbolFlags.Alias, undefined, true, false);
1830
+ if (alias !== undefined && getMergedSymbol(c, alias).name === InternalSymbolName.ExportEquals)
1831
+ symbol = getMergedSymbol(c, alias).parent;
1832
+ }
1833
+ if (symbol === undefined && message !== undefined)
1834
+ resolveName(c, resolveLocation, text, meaning, message, true, false);
1835
+ } else {
1836
+ const found = resolveName(c, resolveLocation, text, meaning, message, true, false);
1837
+ symbol = found !== undefined ? getMergedSymbol(c, found) : undefined;
1838
+ }
1839
+ } else if (name.kind === SyntaxKind.QualifiedName) {
1840
+ const qualified = name as QualifiedName;
1841
+ symbol = resolveQualifiedName(c, name, qualified.left, qualified.right, meaning, ignoreErrors, location);
1842
+ } else if (name.kind === SyntaxKind.PropertyAccessExpression) {
1843
+ symbol = resolveQualifiedName(c, name, getExpression(name)!, getName(name)!, meaning, ignoreErrors, location);
1844
+ } else return undefined;
1845
+ if (symbol !== undefined && symbol !== c.unknownSymbol) {
1846
+ if (
1847
+ (name.flags & NodeFlags.Synthesized) === 0 &&
1848
+ name.kind !== SyntaxKind.PropertyAccessExpression &&
1849
+ ((symbol.flags & SymbolFlags.Alias) !== 0 ||
1850
+ (name.parent !== undefined && name.parent.kind === SyntaxKind.ExportAssignment))
1851
+ )
1852
+ markAliasDeclarationOfNameIfTypeOnly(c, name);
1853
+ // Resolve along the alias chain to the symbol with the meaning.
1854
+ while ((symbol.flags & meaning) === 0 && !dontResolveAlias && (symbol.flags & SymbolFlags.Alias) !== 0)
1855
+ symbol = resolveAlias(c, symbol);
1856
+ }
1857
+ return symbol;
1858
+ }
1859
+
1860
+ function resolveQualifiedName(
1861
+ c: Checker,
1862
+ name: Node,
1863
+ left: Node,
1864
+ right: Node,
1865
+ meaning: SymbolFlags,
1866
+ ignoreErrors: boolean,
1867
+ location: Node | undefined,
1868
+ ): Symbol | undefined {
1869
+ const namespace = resolveEntityName(c, left, SymbolFlags.Namespace, ignoreErrors, false, location);
1870
+ if (namespace === undefined || nodeIsMissing(right)) return undefined;
1871
+ if (namespace === c.unknownSymbol) return namespace;
1872
+ const text = getText(right);
1873
+ let found = getSymbolOfMeaning(c, getExportsOfSymbol(c, namespace), text, meaning);
1874
+ // A namespace merged with a re-export resolves further.
1875
+ if (found === undefined && (namespace.flags & SymbolFlags.Alias) !== 0)
1876
+ found = getSymbolOfMeaning(c, getExportsOfSymbol(c, resolveAlias(c, namespace)), text, meaning);
1877
+ if (found !== undefined) return getMergedSymbol(c, found);
1878
+ if (ignoreErrors) return undefined;
1879
+ const namespaceName = getFullyQualifiedName(c, namespace);
1880
+ const declarationName = declarationNameToString(getSourceFileOfNode(right), right);
1881
+ const suggestion = getSpellingSuggestionForName(
1882
+ c,
1883
+ text,
1884
+ Array.from(getExportsOfModule(c, namespace).values()),
1885
+ SymbolFlags.ModuleMember,
1886
+ );
1887
+ if (suggestion !== undefined) {
1888
+ c.error(
1889
+ right,
1890
+ Diagnostics.X_0_has_no_exported_member_named_1_Did_you_mean_2,
1891
+ namespaceName,
1892
+ declarationName,
1893
+ symbolToString(c, suggestion),
1894
+ );
1895
+ return undefined;
1896
+ }
1897
+ let containingQualifiedName: Node | undefined;
1898
+ if (name.kind === SyntaxKind.QualifiedName) {
1899
+ containingQualifiedName = name;
1900
+ while (containingQualifiedName.parent!.kind === SyntaxKind.QualifiedName)
1901
+ containingQualifiedName = containingQualifiedName.parent!;
1902
+ }
1903
+ if (
1904
+ // Not while the checker is being created, before global types are known.
1905
+ c.hasGlobalObjectType &&
1906
+ (meaning & SymbolFlags.Type) !== 0 &&
1907
+ containingQualifiedName !== undefined &&
1908
+ containingQualifiedName.parent!.kind !== SyntaxKind.TypeOfExpression &&
1909
+ tryGetQualifiedNameAsValue(c, containingQualifiedName) !== undefined
1910
+ ) {
1911
+ c.error(
1912
+ containingQualifiedName,
1913
+ Diagnostics.X_0_refers_to_a_value_but_is_being_used_as_a_type_here_Did_you_mean_typeof_0,
1914
+ entityNameToString(containingQualifiedName),
1915
+ );
1916
+ return undefined;
1917
+ }
1918
+ if (
1919
+ (meaning & SymbolFlags.Namespace) !== 0 &&
1920
+ name.parent !== undefined &&
1921
+ name.parent.kind === SyntaxKind.QualifiedName
1922
+ ) {
1923
+ const exportedType = getSymbolOfMeaning(c, getExportsOfSymbol(c, namespace), text, SymbolFlags.Type);
1924
+ if (exportedType !== undefined) {
1925
+ const qualified = name.parent as QualifiedName;
1926
+ c.error(
1927
+ qualified.right,
1928
+ Diagnostics.Cannot_access_0_1_because_0_is_a_type_but_not_a_namespace_Did_you_mean_to_retrieve_the_type_of_the_property_1_in_0_with_0_1,
1929
+ symbolToString(c, getMergedSymbol(c, exportedType)),
1930
+ qualified.right.text,
1931
+ );
1932
+ return undefined;
1933
+ }
1934
+ }
1935
+ c.error(right, Diagnostics.Namespace_0_has_no_exported_member_1, namespaceName, declarationName);
1936
+ return undefined;
1937
+ }
1938
+
1939
+ /** The value a qualified name denotes as a property access, if any. */
1940
+ function tryGetQualifiedNameAsValue(c: Checker, node: Node): Symbol | undefined {
1941
+ const id = getFirstIdentifier(node);
1942
+ let symbol = resolveName(c, id, getText(id), SymbolFlags.Value, undefined, true, false);
1943
+ if (symbol === undefined) return undefined;
1944
+ let current: Node = id;
1945
+ while (current.parent!.kind === SyntaxKind.QualifiedName) {
1946
+ symbol = getPropertyOfType(c, getTypeOfSymbol(c, symbol), (current.parent as QualifiedName).right.text);
1947
+ if (symbol === undefined) return undefined;
1948
+ current = current.parent!;
1949
+ }
1950
+ return symbol;
1951
+ }
1952
+
1953
+ /**
1954
+ * `symbol` qualified by its parents. The outermost one is written as seen from `containingLocation`
1955
+ * if given, so that a module is named by a specifier the containing file could import it with.
1956
+ */
1957
+ export function getFullyQualifiedName(c: Checker, symbol: Symbol, containingLocation?: Node): string {
1958
+ return symbol.parent !== undefined
1959
+ ? getFullyQualifiedName(c, symbol.parent, containingLocation) + '.' + symbolToString(c, symbol)
1960
+ : symbolToString(c, symbol, containingLocation, NodeBuilderInternalFlags.DoNotIncludeSymbolChain);
1961
+ }
1962
+
1963
+ export function getCannotFindNameDiagnosticForName(c: Checker, node: Node): DiagnosticMessage {
1964
+ const wildcard = c.compilerOptions.types !== undefined && c.compilerOptions.types.includes('*');
1965
+ switch (getText(node)) {
1966
+ case 'document':
1967
+ case 'console':
1968
+ return Diagnostics.Cannot_find_name_0_Do_you_need_to_change_your_target_library_Try_changing_the_lib_compiler_option_to_include_dom;
1969
+ case '$':
1970
+ return wildcard
1971
+ ? Diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_jQuery_Try_npm_i_save_dev_types_Slashjquery
1972
+ : Diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_jQuery_Try_npm_i_save_dev_types_Slashjquery_and_then_add_jquery_to_the_types_field_in_your_tsconfig;
1973
+ case 'beforeEach':
1974
+ case 'describe':
1975
+ case 'suite':
1976
+ case 'it':
1977
+ case 'test':
1978
+ return wildcard
1979
+ ? Diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_a_test_runner_Try_npm_i_save_dev_types_Slashjest_or_npm_i_save_dev_types_Slashmocha
1980
+ : Diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_a_test_runner_Try_npm_i_save_dev_types_Slashjest_or_npm_i_save_dev_types_Slashmocha_and_then_add_jest_or_mocha_to_the_types_field_in_your_tsconfig;
1981
+ case 'process':
1982
+ case 'require':
1983
+ case 'Buffer':
1984
+ case 'module':
1985
+ case 'NodeJS':
1986
+ return wildcard
1987
+ ? Diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_node_Try_npm_i_save_dev_types_Slashnode
1988
+ : Diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_node_Try_npm_i_save_dev_types_Slashnode_and_then_add_node_to_the_types_field_in_your_tsconfig;
1989
+ case 'Bun':
1990
+ return wildcard
1991
+ ? Diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_Bun_Try_npm_i_save_dev_types_Slashbun
1992
+ : Diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_Bun_Try_npm_i_save_dev_types_Slashbun_and_then_add_bun_to_the_types_field_in_your_tsconfig;
1993
+ // tsgo lists `ast.Symbol` here rather than `Symbol`.
1994
+ case 'Map':
1995
+ case 'Set':
1996
+ case 'Promise':
1997
+ case 'WeakMap':
1998
+ case 'WeakSet':
1999
+ case 'Iterator':
2000
+ case 'AsyncIterator':
2001
+ case 'SharedArrayBuffer':
2002
+ case 'Atomics':
2003
+ case 'AsyncIterable':
2004
+ case 'AsyncIterableIterator':
2005
+ case 'AsyncGenerator':
2006
+ case 'AsyncGeneratorFunction':
2007
+ case 'BigInt':
2008
+ case 'Reflect':
2009
+ case 'BigInt64Array':
2010
+ case 'BigUint64Array':
2011
+ return Diagnostics.Cannot_find_name_0_Do_you_need_to_change_your_target_library_Try_changing_the_lib_compiler_option_to_1_or_later;
2012
+ case 'await':
2013
+ if (node.parent !== undefined && node.parent.kind === SyntaxKind.CallExpression)
2014
+ return Diagnostics.Cannot_find_name_0_Did_you_mean_to_write_this_in_an_async_function;
2015
+ break;
2016
+ }
2017
+ if (node.parent !== undefined && node.parent.kind === SyntaxKind.ShorthandPropertyAssignment)
2018
+ return Diagnostics.No_value_exists_in_scope_for_the_shorthand_property_0_Either_declare_one_or_provide_an_initializer;
2019
+ return Diagnostics.Cannot_find_name_0;
2020
+ }
2021
+
2022
+ // ---- Resolution stack
2023
+
2024
+ export const enum TypeSystemPropertyName {
2025
+ Type = 0,
2026
+ ResolvedBaseConstructorType = 1,
2027
+ DeclaredType = 2,
2028
+ ResolvedReturnType = 3,
2029
+ ResolvedBaseConstraint = 4,
2030
+ ResolvedTypeArguments = 5,
2031
+ ResolvedBaseTypes = 6,
2032
+ WriteType = 7,
2033
+ InitializerIsUndefined = 8,
2034
+ AliasTarget = 9,
2035
+ }
2036
+
2037
+ type ResolutionTarget = Symbol | Type | Signature | Node;
2038
+
2039
+ /**
2040
+ * Pushes a resolution of `propertyName` on `target`. When the same resolution is already on the
2041
+ * stack with no resolved entries above it, marks the cycle and returns false.
2042
+ */
2043
+ export function pushTypeResolution(
2044
+ c: Checker,
2045
+ target: ResolutionTarget,
2046
+ propertyName: TypeSystemPropertyName,
2047
+ ): boolean {
2048
+ const start = findResolutionCycleStartIndex(c, target, propertyName);
2049
+ if (start >= 0) {
2050
+ c.resolutionCycleCount++;
2051
+ for (let i = start; i < c.resolutionDepth; i++) c.resolutionResults[i] = false;
2052
+ return false;
2053
+ }
2054
+ const depth = c.resolutionDepth;
2055
+ if (depth < c.resolutionTargets.length) {
2056
+ c.resolutionTargets[depth] = target;
2057
+ c.resolutionPropertyNames[depth] = propertyName;
2058
+ c.resolutionResults[depth] = true;
2059
+ } else {
2060
+ c.resolutionTargets.push(target);
2061
+ c.resolutionPropertyNames.push(propertyName);
2062
+ c.resolutionResults.push(true);
2063
+ }
2064
+ c.resolutionDepth = depth + 1;
2065
+ return true;
2066
+ }
2067
+
2068
+ /** Pops the last resolution; false if it was part of a cycle. */
2069
+ export function popTypeResolution(c: Checker): boolean {
2070
+ const depth = c.resolutionDepth - 1;
2071
+ c.resolutionDepth = depth;
2072
+ return c.resolutionResults[depth]!;
2073
+ }
2074
+
2075
+ export function findResolutionCycleStartIndex(
2076
+ c: Checker,
2077
+ target: ResolutionTarget,
2078
+ propertyName: TypeSystemPropertyName,
2079
+ ): number {
2080
+ for (let i = c.resolutionDepth - 1; i >= c.resolutionStart; i--) {
2081
+ if (resolutionHasProperty(c, c.resolutionTargets[i]!, c.resolutionPropertyNames[i]!)) return -1;
2082
+ if (c.resolutionTargets[i]! === target && c.resolutionPropertyNames[i]! === propertyName) return i;
2083
+ }
2084
+ return -1;
2085
+ }
2086
+
2087
+ function resolutionHasProperty(c: Checker, target: ResolutionTarget, propertyName: number): boolean {
2088
+ switch (propertyName) {
2089
+ case TypeSystemPropertyName.Type:
2090
+ return c.symbolTypes.get(getSymbolId(target as Symbol)) !== undefined;
2091
+ case TypeSystemPropertyName.DeclaredType:
2092
+ return c.symbolLinks(target as Symbol).declaredType !== undefined;
2093
+ case TypeSystemPropertyName.ResolvedTypeArguments:
2094
+ return (
2095
+ typeReferenceOf(target as Type).resolvedTypeArguments !== undefined ||
2096
+ sideOf(c, typeReferenceOf(target as Type)).resolvedTypeArguments !== undefined
2097
+ );
2098
+ case TypeSystemPropertyName.ResolvedBaseTypes:
2099
+ return sideOf(c, interfaceTypeOf(target as Type)).baseTypesResolved;
2100
+ case TypeSystemPropertyName.ResolvedBaseConstructorType:
2101
+ return sideOf(c, interfaceTypeOf(target as Type)).resolvedBaseConstructorType !== undefined;
2102
+ case TypeSystemPropertyName.ResolvedReturnType:
2103
+ return (
2104
+ (target as Signature).resolvedReturnType !== undefined ||
2105
+ signatureSideOf(c, target as Signature).resolvedReturnType !== undefined
2106
+ );
2107
+ case TypeSystemPropertyName.ResolvedBaseConstraint:
2108
+ return (
2109
+ (target as Type).resolvedBaseConstraint !== undefined ||
2110
+ sideOf(c, target as Type).resolvedBaseConstraint !== undefined
2111
+ );
2112
+ case TypeSystemPropertyName.InitializerIsUndefined:
2113
+ return ((c.existingNodeLinks(target as Node)?.flags ?? 0) & (1 << 25)) !== 0;
2114
+ case TypeSystemPropertyName.WriteType:
2115
+ return c.symbolLinks(target as Symbol).writeType !== undefined;
2116
+ case TypeSystemPropertyName.AliasTarget:
2117
+ return c.symbolLinks(target as Symbol).aliasTarget !== undefined;
2118
+ }
2119
+ return false;
2120
+ }
2121
+
2122
+ function typeReferenceOf(t: Type): TypeReference {
2123
+ return t as TypeReference;
2124
+ }
2125
+
2126
+ function interfaceTypeOf(t: Type): InterfaceType {
2127
+ return t as InterfaceType;
2128
+ }
2129
+
2130
+ export function reportCircularityError(c: Checker, symbol: Symbol): Type {
2131
+ const declaration = symbol.valueDeclaration;
2132
+ if (declaration !== undefined) {
2133
+ if (getType(declaration) !== undefined) {
2134
+ c.error(
2135
+ declaration,
2136
+ Diagnostics.X_0_is_referenced_directly_or_indirectly_in_its_own_type_annotation,
2137
+ symbolToString(c, symbol),
2138
+ );
2139
+ return c.errorType;
2140
+ }
2141
+ if (c.noImplicitAny && (declaration.kind !== SyntaxKind.Parameter || getInitializer(declaration) !== undefined))
2142
+ c.error(
2143
+ declaration,
2144
+ Diagnostics.X_0_implicitly_has_type_any_because_it_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer,
2145
+ symbolToString(c, symbol),
2146
+ );
2147
+ } else if ((symbol.flags & SymbolFlags.Alias) !== 0) {
2148
+ const node = getDeclarationOfAliasSymbol(symbol);
2149
+ if (node !== undefined) c.error(node, Diagnostics.Circular_definition_of_import_alias_0, symbolToString(c, symbol));
2150
+ }
2151
+ // Circularities could also result from parameters in function expressions that end up having themselves as
2152
+ // contextual types. Those are reported elsewhere.
2153
+ return c.anyType;
2154
+ }
2155
+
2156
+ export { getTypeOfSymbol, getSourceFileOfNode };
2157
+ export type { SourceFile };