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,1201 @@
1
+ // Declarations: variables, parameters, functions, type aliases, enums, namespaces, imports, exports.
2
+ import { checkCollisionsForDeclarationName } from './checker-generated-code.js';
3
+ import { ExternalEmitHelpers, checkExternalEmitHelpers } from './checker-emit-helpers.js';
4
+ import { convertAutoToAny } from './checker-narrowing.js';
5
+ import { markPropertyAsReferenced } from './checker-unused.js';
6
+ import {
7
+ type BindingElement,
8
+ type EnumDeclaration,
9
+ type ImportEqualsDeclaration,
10
+ type ModuleDeclaration,
11
+ type SourceFile,
12
+ type Node,
13
+ type NodeList,
14
+ NodeVisitor,
15
+ type TypeAliasDeclaration,
16
+ type TypeParameterDeclaration,
17
+ type VariableDeclarationList,
18
+ type VariableStatement,
19
+ getExpression,
20
+ getInitializer,
21
+ getName,
22
+ getType,
23
+ getElements,
24
+ getSymbol,
25
+ ModifierFlags,
26
+ NodeFlags,
27
+ getLocalSymbol,
28
+ getBody,
29
+ getDotDotDotToken,
30
+ getParameters,
31
+ getStatements,
32
+ getText,
33
+ getTypeArguments,
34
+ getModifiers,
35
+ } from './ast.js';
36
+ import { ModuleKind, ScriptTarget } from './options.js';
37
+ import { isExternalModuleNameRelative } from './path.js';
38
+ import { checkTypeNameIsReserved } from './checker-classes.js';
39
+ import { getPropertyNameFromType, isBindingPattern, isTypeUsableAsPropertyName } from './checker-utilities.js';
40
+ import { checkPropertyAccessibility } from './checker-property-access.js';
41
+ import {
42
+ declarationNameToString,
43
+ getNameOfDeclaration,
44
+ getSourceFileOfNode,
45
+ ModuleInstanceState,
46
+ JSDeclarationKind,
47
+ getAssignmentDeclarationKind,
48
+ getCombinedModifierFlags,
49
+ getCombinedNodeFlags,
50
+ isPartOfParameterDeclaration,
51
+ getRootDeclaration,
52
+ getDeclarationOfKind,
53
+ getModifierFlags,
54
+ getModuleInstanceState,
55
+ getRangeOfTokenAtPosition,
56
+ hasSyntacticModifier,
57
+ isEntityNameExpression,
58
+ isEnumConst,
59
+ isExternalModule,
60
+ isModuleAugmentationExternal,
61
+ isVariableDeclarationInitializedToRequire,
62
+ isClassLike,
63
+ } from './binder-utilities.js';
64
+ import { Diagnostic, type DiagnosticMessage, Diagnostics } from './diagnostics.js';
65
+ import { SyntaxKind } from './syntax-kind.js';
66
+ import { type Checker, createDiagnosticForNode } from './checker.js';
67
+ import { IntrinsicTypeKind, getLiteralTypeFromPropertyName, intrinsicTypeKind } from './checker-type-operators.js';
68
+ import {
69
+ CheckMode,
70
+ type InterfaceType,
71
+ ObjectFlags,
72
+ SimpleTypeMapper,
73
+ type Type,
74
+ TypeFlags,
75
+ type TypeParameter,
76
+ type TypeReference,
77
+ } from './checker-types.js';
78
+ import { checkTypeArgumentConstraints } from './checker-heritage.js';
79
+ import { getUnionType, isErrorType } from './checker-type-factory.js';
80
+ import { getTypeFromTypeNode } from './checker-type-nodes.js';
81
+ import {
82
+ computeEnumMemberValues,
83
+ getConstraintOfTypeParameter,
84
+ getDeclaredTypeOfSymbol,
85
+ getDeclaredTypeOfTypeParameter,
86
+ getDefaultFromTypeParameter,
87
+ getResolvedTypeParameterDefault,
88
+ } from './checker-declared-types.js';
89
+ import {
90
+ getDeclarationOfAliasSymbol,
91
+ getExportsOfModule,
92
+ getSymbolFlags,
93
+ getSymbolOfDeclaration,
94
+ resolveAlias,
95
+ resolveName,
96
+ getCachedGlobalType,
97
+ } from './checker-symbols.js';
98
+ import {
99
+ getTypeOfSymbol,
100
+ getWidenedTypeForVariableLikeDeclaration,
101
+ widenTypeForVariableLikeDeclaration,
102
+ isOptionalDeclaration,
103
+ } from './checker-symbol-types.js';
104
+ import {
105
+ checkComputedPropertyName,
106
+ checkExpression,
107
+ checkExpressionCached,
108
+ checkNonNullNonVoidType,
109
+ checkTypeAssignableToAndOptionallyElaborate,
110
+ isInAmbientOrTypeNode,
111
+ } from './checker-expressions.js';
112
+ import { IterationUse, checkIteratedTypeOrElementType } from './checker-iteration.js';
113
+ import {
114
+ isTypeAssignableTo,
115
+ isTypeIdenticalTo,
116
+ checkTypeAssignableTo,
117
+ createMarkerType,
118
+ getTypeParameterModifiers,
119
+ } from './relations.js';
120
+ import {
121
+ getBaseConstraintOfType,
122
+ getPropertyOfType,
123
+ getReducedType,
124
+ getTypeWithThisArgument,
125
+ } from './checker-members.js';
126
+ import { instantiateType } from './instantiation.js';
127
+ import { symbolToString, typeToString } from './type-printer.js';
128
+ import { checkNodeDeferred, checkSourceElement, checkTypeNodeIfPresent } from './checker-source-file.js';
129
+ import { checkFunctionLikeBody } from './checker-functions.js';
130
+ import { ContainerFlags, getContainerFlags } from './binder.js';
131
+ import {
132
+ isAmbientModule,
133
+ isFunctionLike,
134
+ isGlobalScopeAugmentation,
135
+ isInJSFile,
136
+ nodeIsMissing,
137
+ nodeIsPresent,
138
+ } from './ast-utilities.js';
139
+ import { getTypeForBindingElementParent } from './checker-destructuring.js';
140
+ import { checkFunctionOrMethodSymbols } from './checker-overloads.js';
141
+ import { checkJSDocFullSignature } from './checker-jsdoc.js';
142
+ import { checkAliasSymbol } from './checker-modules.js';
143
+ import { checkDecorators } from './checker-decorators.js';
144
+ import {
145
+ declarationCount,
146
+ getDeclarations,
147
+ getSymbolId,
148
+ InternalSymbolName,
149
+ type Symbol,
150
+ SymbolFlags,
151
+ } from './symbol.js';
152
+
153
+ // ---- Variables and parameters
154
+
155
+ export function checkVariableStatement(c: Checker, node: Node): void {
156
+ checkVariableDeclarationList(c, (node as VariableStatement).declarationList);
157
+ }
158
+
159
+ export function checkVariableDeclarationList(c: Checker, node: Node): void {
160
+ // `using` and `await using` before ESNext use __addDisposableResource and __disposeResources.
161
+ const blockScopeKind = getCombinedNodeFlags(node) & NodeFlags.BlockScoped;
162
+ if (
163
+ (blockScopeKind === NodeFlags.Using || blockScopeKind === NodeFlags.AwaitUsing) &&
164
+ c.languageVersion < ScriptTarget.ESNext
165
+ )
166
+ checkExternalEmitHelpers(c, node, ExternalEmitHelpers.AddDisposableResourceAndDisposeResources);
167
+ for (const d of (node as VariableDeclarationList).declarations.nodes) checkVariableLikeDeclaration(c, d);
168
+ }
169
+
170
+ /** The initializer of a `using` or `await using` declaration must be disposable, `null` or `undefined`. */
171
+ function checkUsingDeclarationInitializer(c: Checker, node: Node, initializer: Node, initType: Type): void {
172
+ const blockScopeKind = getCombinedNodeFlags(node) & NodeFlags.BlockScoped;
173
+ if (blockScopeKind === NodeFlags.AwaitUsing) {
174
+ const globalAsyncDisposableType = getCachedGlobalType(c, 'AsyncDisposable', 0, true);
175
+ const globalDisposableType = getCachedGlobalType(c, 'Disposable', 0, true);
176
+ if (globalAsyncDisposableType !== c.emptyObjectType && globalDisposableType !== c.emptyObjectType)
177
+ checkTypeAssignableTo(
178
+ c,
179
+ widenTypeForVariableLikeDeclaration(c, initType, node, false),
180
+ getUnionType(c, [globalAsyncDisposableType, globalDisposableType, c.nullType, c.undefinedType]),
181
+ initializer,
182
+ Diagnostics.The_initializer_of_an_await_using_declaration_must_be_either_an_object_with_a_Symbol_asyncDispose_or_Symbol_dispose_method_or_be_null_or_undefined,
183
+ );
184
+ } else if (blockScopeKind === NodeFlags.Using) {
185
+ const globalDisposableType = getCachedGlobalType(c, 'Disposable', 0, true);
186
+ if (globalDisposableType !== c.emptyObjectType)
187
+ checkTypeAssignableTo(
188
+ c,
189
+ widenTypeForVariableLikeDeclaration(c, initType, node, false),
190
+ getUnionType(c, [globalDisposableType, c.nullType, c.undefinedType]),
191
+ initializer,
192
+ Diagnostics.The_initializer_of_a_using_declaration_must_be_either_an_object_with_a_Symbol_dispose_method_or_be_null_or_undefined,
193
+ );
194
+ }
195
+ }
196
+
197
+ /** Checks a variable, parameter, property or binding element declaration. */
198
+ export function checkVariableLikeDeclaration(c: Checker, node: Node): void {
199
+ checkDecorators(c, node);
200
+ if (node.kind === SyntaxKind.Parameter) checkParameter(c, node);
201
+ const typeNode = getType(node);
202
+ checkTypeNodeIfPresent(c, typeNode);
203
+ const name = getName(node);
204
+ if (node.kind === SyntaxKind.PropertySignature && name !== undefined && name.kind === SyntaxKind.PrivateIdentifier)
205
+ c.error(node, Diagnostics.Private_identifiers_are_not_allowed_outside_class_bodies);
206
+ if (name !== undefined && name.kind === SyntaxKind.ComputedPropertyName) checkComputedPropertyName(c, name);
207
+ const initializer = getInitializer(node);
208
+ // Parameter initializers need an implementation.
209
+ const initializerNotAllowed =
210
+ initializer !== undefined && node.kind === SyntaxKind.Parameter && nodeIsMissing(getBody(node.parent!));
211
+ if (
212
+ name !== undefined &&
213
+ (name.kind === SyntaxKind.ObjectBindingPattern || name.kind === SyntaxKind.ArrayBindingPattern)
214
+ ) {
215
+ if (initializerNotAllowed)
216
+ c.error(node, Diagnostics.A_parameter_initializer_is_only_allowed_in_a_function_or_constructor_implementation);
217
+ for (const element of getElements(name)!.nodes) checkBindingElement(c, element as BindingElement);
218
+ if (!initializerNotAllowed) checkBindingPatternInitializer(c, node, name, initializer);
219
+ return;
220
+ }
221
+ if (initializerNotAllowed) {
222
+ c.error(node, Diagnostics.A_parameter_initializer_is_only_allowed_in_a_function_or_constructor_implementation);
223
+ return;
224
+ }
225
+ if (name !== undefined && name.kind === SyntaxKind.BigIntLiteral)
226
+ c.error(name, Diagnostics.A_bigint_literal_cannot_be_used_as_a_property_name);
227
+ const symbol = getSymbolOfDeclaration(c, node);
228
+ if (symbol === undefined) {
229
+ if (initializer !== undefined) checkExpressionCached(c, initializer);
230
+ return;
231
+ }
232
+ // `const x = require("m")` declares an alias.
233
+ if ((symbol.flags & SymbolFlags.Alias) !== 0 && isVariableDeclarationInitializedToRequire(node)) {
234
+ checkAliasSymbol(c, node);
235
+ return;
236
+ }
237
+ if (
238
+ name !== undefined &&
239
+ name.kind === SyntaxKind.Identifier &&
240
+ node.kind !== SyntaxKind.PropertyDeclaration &&
241
+ node.kind !== SyntaxKind.PropertySignature
242
+ )
243
+ checkCollisionsForDeclarationName(c, node, name);
244
+ const t = convertAutoToAny(c, getTypeOfSymbol(c, symbol));
245
+ if (
246
+ node.kind !== SyntaxKind.PropertyDeclaration &&
247
+ node.kind !== SyntaxKind.PropertySignature &&
248
+ node.kind !== SyntaxKind.Parameter
249
+ ) {
250
+ checkExportsOnMergedDeclarations(c, node);
251
+ if (node.kind === SyntaxKind.VariableDeclaration) checkVarDeclaredNamesNotShadowed(c, node, symbol);
252
+ }
253
+ if (node === symbol.valueDeclaration) {
254
+ // A for-in initializer is already an error.
255
+ if (initializer !== undefined && node.parent!.parent!.kind !== SyntaxKind.ForInStatement) {
256
+ const initType = checkExpressionCached(c, initializer);
257
+ checkTypeAssignableToAndOptionallyElaborate(c, initType, t, node, initializer);
258
+ checkUsingDeclarationInitializer(c, node, initializer, initType);
259
+ }
260
+ if (name !== undefined && declarationCount(symbol) > 1) {
261
+ for (const d of getDeclarations(symbol)) {
262
+ if (d !== node && isVariableLike(d) && !areDeclarationFlagsIdentical(d, node)) {
263
+ reportNonIdenticalModifiers(c, name);
264
+ break;
265
+ }
266
+ }
267
+ }
268
+ return;
269
+ }
270
+ if (
271
+ name !== undefined &&
272
+ symbol.valueDeclaration !== undefined &&
273
+ !areDeclarationFlagsIdentical(node, symbol.valueDeclaration)
274
+ )
275
+ reportNonIdenticalModifiers(c, name);
276
+ // A redeclaration: types must be identical.
277
+ const declarationType = convertAutoToAny(c, getWidenedTypeForVariableLikeDeclaration(c, node, false));
278
+ if (
279
+ !isErrorType(c, t) &&
280
+ !isErrorType(c, declarationType) &&
281
+ !isTypeIdenticalTo(c, t, declarationType) &&
282
+ (symbol.flags & SymbolFlags.Assignment) === 0
283
+ )
284
+ errorNextVariableOrPropertyDeclarationMustHaveSameType(c, symbol.valueDeclaration, t, node, declarationType);
285
+ if (initializer !== undefined) {
286
+ const initType = checkExpressionCached(c, initializer);
287
+ if (!isErrorType(c, declarationType))
288
+ checkTypeAssignableToAndOptionallyElaborate(c, initType, declarationType, node, initializer);
289
+ }
290
+ }
291
+
292
+ /** Checks the initializer of a binding pattern, and that a pattern without names destructures a valid type. */
293
+ function checkBindingPatternInitializer(c: Checker, node: Node, name: Node, initializer: Node | undefined): void {
294
+ if (isInAmbientOrTypeNode(node)) return;
295
+ // A for-in initializer is already an error.
296
+ const needCheckInitializer = initializer !== undefined && node.parent!.parent!.kind !== SyntaxKind.ForInStatement;
297
+ let needCheckWidenedType = true;
298
+ for (const e of getElements(name)!.nodes) {
299
+ if (getName(e) !== undefined) {
300
+ needCheckWidenedType = false;
301
+ break;
302
+ }
303
+ }
304
+ if (!needCheckInitializer && !needCheckWidenedType) return;
305
+ const widenedType = getWidenedTypeForVariableLikeDeclaration(c, node, false);
306
+ if (needCheckInitializer) {
307
+ const initializerType = checkExpressionCached(c, initializer!);
308
+ if (c.strictNullChecks && needCheckWidenedType) checkNonNullNonVoidType(c, initializerType, node);
309
+ else
310
+ checkTypeAssignableToAndOptionallyElaborate(
311
+ c,
312
+ initializerType,
313
+ getWidenedTypeForVariableLikeDeclaration(c, node, false),
314
+ node,
315
+ initializer,
316
+ );
317
+ }
318
+ if (needCheckWidenedType) {
319
+ if (name.kind === SyntaxKind.ArrayBindingPattern)
320
+ checkIteratedTypeOrElementType(c, IterationUse.Destructuring, widenedType, c.undefinedType, node);
321
+ else if (c.strictNullChecks) checkNonNullNonVoidType(c, widenedType, node);
322
+ }
323
+ }
324
+
325
+ /**
326
+ * Reports a `var` that would hoist past a `let` or `const` of the same name declared in an inner
327
+ * scope: the initializer would write to the block-scoped variable.
328
+ */
329
+ function checkVarDeclaredNamesNotShadowed(c: Checker, node: Node, symbol: Symbol): void {
330
+ if ((getCombinedNodeFlags(node) & NodeFlags.BlockScoped) !== 0 || isPartOfParameterDeclaration(node)) return;
331
+ const name = getName(node);
332
+ if ((symbol.flags & SymbolFlags.FunctionScopedVariable) === 0 || name === undefined) return;
333
+ if (name.kind !== SyntaxKind.Identifier) return;
334
+ const local = resolveName(c, node, getText(name), SymbolFlags.Variable, undefined, false, false);
335
+ if (local === undefined || local === symbol || (local.flags & SymbolFlags.BlockScopedVariable) === 0) return;
336
+ const declaration = local.valueDeclaration;
337
+ if (declaration === undefined || (getCombinedNodeFlags(declaration) & NodeFlags.BlockScoped) === 0) return;
338
+ let list: Node | undefined = declaration;
339
+ while (list !== undefined && list.kind !== SyntaxKind.VariableDeclarationList) list = list.parent;
340
+ const statement = list?.parent;
341
+ const container =
342
+ statement !== undefined && statement.kind === SyntaxKind.VariableStatement ? statement.parent : undefined;
343
+ // Block-scoped variables of the function, module or file scope share it with hoisted `var`s.
344
+ const namesShareScope =
345
+ container !== undefined &&
346
+ ((container.kind === SyntaxKind.Block && isFunctionLike(container.parent)) ||
347
+ container.kind === SyntaxKind.ModuleBlock ||
348
+ container.kind === SyntaxKind.ModuleDeclaration ||
349
+ container.kind === SyntaxKind.SourceFile);
350
+ if (namesShareScope) return;
351
+ const localName = symbolToString(c, local);
352
+ c.error(
353
+ node,
354
+ Diagnostics.Cannot_initialize_outer_scoped_variable_0_in_the_same_scope_as_block_scoped_declaration_1,
355
+ localName,
356
+ localName,
357
+ );
358
+ }
359
+
360
+ /** Parameter properties, `this` parameters and rest parameter types. */
361
+ function checkParameter(c: Checker, node: Node): void {
362
+ const fn = node.parent!;
363
+ const name = getName(node);
364
+ const paramName = name !== undefined && name.kind === SyntaxKind.Identifier ? getText(name) : '';
365
+ if (hasSyntacticModifier(node, ModifierFlags.ParameterPropertyModifier)) {
366
+ if (shouldCheckErasableSyntax(c, node))
367
+ c.error(node, Diagnostics.This_syntax_is_not_allowed_when_erasableSyntaxOnly_is_enabled);
368
+ if (fn.kind !== SyntaxKind.Constructor || !nodeIsPresent(getBody(fn)))
369
+ c.error(node, Diagnostics.A_parameter_property_is_only_allowed_in_a_constructor_implementation);
370
+ if (fn.kind === SyntaxKind.Constructor && paramName === 'constructor')
371
+ c.error(name, Diagnostics.X_constructor_cannot_be_used_as_a_parameter_property_name);
372
+ }
373
+ if (
374
+ getInitializer(node) === undefined &&
375
+ isOptionalDeclaration(node) &&
376
+ isBindingPattern(name) &&
377
+ getBody(fn) !== undefined
378
+ )
379
+ c.error(node, Diagnostics.A_binding_pattern_parameter_cannot_be_optional_in_an_implementation_signature);
380
+ if (paramName === 'this' || paramName === 'new') {
381
+ if (getParameters(fn)!.nodes.indexOf(node) !== 0)
382
+ c.error(node, Diagnostics.A_0_parameter_must_be_the_first_parameter, paramName);
383
+ if (
384
+ fn.kind === SyntaxKind.Constructor ||
385
+ fn.kind === SyntaxKind.ConstructSignature ||
386
+ fn.kind === SyntaxKind.ConstructorType
387
+ )
388
+ c.error(node, Diagnostics.A_constructor_cannot_have_a_this_parameter);
389
+ if (fn.kind === SyntaxKind.ArrowFunction) c.error(node, Diagnostics.An_arrow_function_cannot_have_a_this_parameter);
390
+ if (fn.kind === SyntaxKind.GetAccessor || fn.kind === SyntaxKind.SetAccessor)
391
+ c.error(node, Diagnostics.X_get_and_set_accessors_cannot_declare_this_parameters);
392
+ }
393
+ // Binding patterns in rest parameters are a grammar error. Generic rest types are skipped: the
394
+ // implied `any[]` constraints of `infer` positions aren't computed yet.
395
+ if (getDotDotDotToken(node) !== undefined && !isBindingPattern(name)) {
396
+ const symbol = getSymbolOfDeclaration(c, node);
397
+ const t = symbol !== undefined ? getReducedType(c, getTypeOfSymbol(c, symbol)) : undefined;
398
+ if (t !== undefined && !isTypeAssignableTo(c, t, c.anyReadonlyArrayType))
399
+ c.error(node, Diagnostics.A_rest_parameter_must_be_of_an_array_type);
400
+ }
401
+ }
402
+
403
+ function isVariableLike(node: Node): boolean {
404
+ switch (node.kind) {
405
+ case SyntaxKind.BindingElement:
406
+ case SyntaxKind.EnumMember:
407
+ case SyntaxKind.Parameter:
408
+ case SyntaxKind.PropertyAssignment:
409
+ case SyntaxKind.PropertyDeclaration:
410
+ case SyntaxKind.PropertySignature:
411
+ case SyntaxKind.ShorthandPropertyAssignment:
412
+ case SyntaxKind.VariableDeclaration:
413
+ return true;
414
+ }
415
+ return false;
416
+ }
417
+
418
+ function areDeclarationFlagsIdentical(left: Node, right: Node): boolean {
419
+ // Parameters and variables may differ in optionality.
420
+ if (
421
+ (left.kind === SyntaxKind.Parameter && right.kind === SyntaxKind.VariableDeclaration) ||
422
+ (left.kind === SyntaxKind.VariableDeclaration && right.kind === SyntaxKind.Parameter)
423
+ )
424
+ return true;
425
+ if (isOptionalDeclaration(left) !== isOptionalDeclaration(right)) return false;
426
+ const interestingFlags =
427
+ ModifierFlags.Private |
428
+ ModifierFlags.Protected |
429
+ ModifierFlags.Async |
430
+ ModifierFlags.Abstract |
431
+ ModifierFlags.Readonly |
432
+ ModifierFlags.Static;
433
+ return (getModifierFlags(left) & interestingFlags) === (getModifierFlags(right) & interestingFlags);
434
+ }
435
+
436
+ function reportNonIdenticalModifiers(c: Checker, name: Node): void {
437
+ c.error(
438
+ name,
439
+ Diagnostics.All_declarations_of_0_must_have_identical_modifiers,
440
+ declarationNameToString(getSourceFileOfNode(name), name),
441
+ );
442
+ }
443
+
444
+ function checkBindingElement(c: Checker, element: BindingElement): void {
445
+ // Missing array binding elements have no name.
446
+ if (element.name === undefined) return;
447
+ if (
448
+ element.propertyName !== undefined &&
449
+ element.name.kind === SyntaxKind.Identifier &&
450
+ isPartOfParameterDeclaration(element) &&
451
+ nodeIsMissing(getBody(getRootDeclaration(element).parent!))
452
+ ) {
453
+ // Renaming in `type F = ({ a: string }) => void` is confusing, so it's an error once the file is
454
+ // checked if the name is unused, even without noUnusedLocals.
455
+ c.renamedBindingElementsInTypes.push(element);
456
+ return;
457
+ }
458
+ if (element.name.kind === SyntaxKind.Identifier) checkCollisionsForDeclarationName(c, element, element.name);
459
+ // An object rest binding before ES2018 uses __rest.
460
+ if (
461
+ element.parent!.kind === SyntaxKind.ObjectBindingPattern &&
462
+ element.dotDotDotToken !== undefined &&
463
+ c.languageVersion < ScriptTarget.ES2018
464
+ )
465
+ checkExternalEmitHelpers(c, element, ExternalEmitHelpers.Rest);
466
+ if (element.propertyName !== undefined && element.propertyName.kind === SyntaxKind.ComputedPropertyName)
467
+ checkComputedPropertyName(c, element.propertyName);
468
+ // Private and protected properties can't be destructured outside their classes.
469
+ const parent = element.parent!.parent!;
470
+ const parentType = getTypeForBindingElementParent(
471
+ c,
472
+ parent,
473
+ element.dotDotDotToken !== undefined ? CheckMode.RestBindingElement : CheckMode.Normal,
474
+ );
475
+ const propertyName = element.propertyName ?? element.name;
476
+ if (parentType !== undefined && !isBindingPattern(propertyName)) {
477
+ const exprType = getLiteralTypeFromPropertyName(c, propertyName);
478
+ if (exprType !== undefined && isTypeUsableAsPropertyName(exprType)) {
479
+ const property = getPropertyOfType(c, parentType, getPropertyNameFromType(exprType));
480
+ if (property !== undefined) {
481
+ markPropertyAsReferenced(c, property, undefined, false);
482
+ const initializer = getInitializer(parent);
483
+ checkPropertyAccessibility(
484
+ c,
485
+ element,
486
+ initializer !== undefined && initializer.kind === SyntaxKind.SuperKeyword,
487
+ false,
488
+ parentType,
489
+ property,
490
+ );
491
+ }
492
+ }
493
+ }
494
+ const name = element.name;
495
+ if (
496
+ name !== undefined &&
497
+ (name.kind === SyntaxKind.ObjectBindingPattern || name.kind === SyntaxKind.ArrayBindingPattern)
498
+ ) {
499
+ for (const e of getElements(name)!.nodes) checkBindingElement(c, e as BindingElement);
500
+ }
501
+ // Initializers in parameters need an implementation.
502
+ if (
503
+ element.initializer !== undefined &&
504
+ isPartOfParameterDeclaration(element) &&
505
+ nodeIsMissing(getBody(getRootDeclaration(element).parent!))
506
+ ) {
507
+ c.error(element, Diagnostics.A_parameter_initializer_is_only_allowed_in_a_function_or_constructor_implementation);
508
+ return;
509
+ }
510
+ if (name.kind === SyntaxKind.ObjectBindingPattern || name.kind === SyntaxKind.ArrayBindingPattern) {
511
+ checkBindingPatternInitializer(c, element, name, element.initializer);
512
+ return;
513
+ }
514
+ {
515
+ const symbol = getSymbolOfDeclaration(c, element);
516
+ if (
517
+ symbol !== undefined &&
518
+ (symbol.flags & SymbolFlags.Alias) !== 0 &&
519
+ isVariableDeclarationInitializedToRequire(element)
520
+ ) {
521
+ checkAliasSymbol(c, element);
522
+ return;
523
+ }
524
+ if (symbol !== undefined) {
525
+ const t = convertAutoToAny(c, getTypeOfSymbol(c, symbol));
526
+ const initializer = element.initializer;
527
+ if (element === symbol.valueDeclaration) {
528
+ // A for-in initializer is already an error.
529
+ if (initializer !== undefined && getRootDeclaration(element).parent!.parent!.kind !== SyntaxKind.ForInStatement)
530
+ checkTypeAssignableToAndOptionallyElaborate(
531
+ c,
532
+ checkExpressionCached(c, initializer),
533
+ t,
534
+ element,
535
+ initializer,
536
+ );
537
+ } else if (symbol.valueDeclaration !== undefined) {
538
+ // A redeclaration must have the type of the first declaration.
539
+ const declarationType = convertAutoToAny(c, getWidenedTypeForVariableLikeDeclaration(c, element, false));
540
+ if (
541
+ !isErrorType(c, t) &&
542
+ !isErrorType(c, declarationType) &&
543
+ !isTypeIdenticalTo(c, t, declarationType) &&
544
+ (symbol.flags & SymbolFlags.Assignment) === 0
545
+ )
546
+ errorNextVariableOrPropertyDeclarationMustHaveSameType(
547
+ c,
548
+ symbol.valueDeclaration,
549
+ t,
550
+ element,
551
+ declarationType,
552
+ );
553
+ if (initializer !== undefined)
554
+ checkTypeAssignableToAndOptionallyElaborate(
555
+ c,
556
+ checkExpressionCached(c, initializer),
557
+ declarationType,
558
+ element,
559
+ initializer,
560
+ );
561
+ if (!areDeclarationFlagsIdentical(element, symbol.valueDeclaration)) reportNonIdenticalModifiers(c, name);
562
+ }
563
+ checkExportsOnMergedDeclarations(c, element);
564
+ checkVarDeclaredNamesNotShadowed(c, element, symbol);
565
+ return;
566
+ }
567
+ }
568
+ if (element.initializer !== undefined) checkExpressionCached(c, element.initializer);
569
+ }
570
+
571
+ function errorNextVariableOrPropertyDeclarationMustHaveSameType(
572
+ c: Checker,
573
+ firstDeclaration: Node | undefined,
574
+ firstType: Type,
575
+ nextDeclaration: Node,
576
+ nextType: Type,
577
+ ): void {
578
+ const nextDeclarationName = getNameOfDeclaration(nextDeclaration);
579
+ const message =
580
+ nextDeclaration.kind === SyntaxKind.PropertyDeclaration || nextDeclaration.kind === SyntaxKind.PropertySignature
581
+ ? Diagnostics.Subsequent_property_declarations_must_have_the_same_type_Property_0_must_be_of_type_1_but_here_has_type_2
582
+ : Diagnostics.Subsequent_variable_declarations_must_have_the_same_type_Variable_0_must_be_of_type_1_but_here_has_type_2;
583
+ const declName = declarationNameToString(getSourceFileOfNode(nextDeclaration), nextDeclarationName);
584
+ const err = c.error(nextDeclarationName, message, declName, typeToString(c, firstType), typeToString(c, nextType));
585
+ if (firstDeclaration !== undefined)
586
+ err.addRelatedInfo(
587
+ createDiagnosticForNode(
588
+ getNameOfDeclaration(firstDeclaration) ?? firstDeclaration,
589
+ Diagnostics.X_0_was_also_declared_here,
590
+ [declName],
591
+ ),
592
+ );
593
+ }
594
+
595
+ // ---- Functions
596
+
597
+ export function checkFunctionDeclaration(c: Checker, node: Node): void {
598
+ const symbol = getSymbolOfDeclaration(c, node);
599
+ if (symbol !== undefined) getTypeOfSymbol(c, symbol);
600
+ checkFunctionLikeBody(c, node);
601
+ checkJSDocFullSignature(c, node);
602
+ checkFunctionOrMethodSymbols(c, node);
603
+ checkCollisionsForDeclarationName(c, node, getName(node));
604
+ }
605
+
606
+ // ---- Types
607
+
608
+ export function checkTypeParameter(c: Checker, node: Node): void {
609
+ const tp = node as TypeParameterDeclaration;
610
+ checkTypeNodeIfPresent(c, tp.constraint);
611
+ checkTypeNodeIfPresent(c, tp.defaultType);
612
+ const symbol = getSymbol(node);
613
+ if (symbol === undefined) return;
614
+ const typeParameter = getDeclaredTypeOfTypeParameter(c, symbol);
615
+ // Resolving the base constraint reveals circularities.
616
+ getBaseConstraintOfType(c, typeParameter);
617
+ if (getResolvedTypeParameterDefault(c, typeParameter as TypeParameter) === c.circularConstraintType)
618
+ c.error(tp.defaultType, Diagnostics.Type_parameter_0_has_a_circular_default, typeToString(c, typeParameter));
619
+ const constraintType = getConstraintOfTypeParameter(c, typeParameter);
620
+ const defaultType = getDefaultFromTypeParameter(c, typeParameter);
621
+ if (constraintType !== undefined && defaultType !== undefined)
622
+ checkTypeAssignableTo(
623
+ c,
624
+ defaultType,
625
+ getTypeWithThisArgument(
626
+ c,
627
+ instantiateType(c, constraintType, new SimpleTypeMapper(typeParameter, defaultType)),
628
+ defaultType,
629
+ false,
630
+ ),
631
+ tp.defaultType,
632
+ Diagnostics.Type_0_does_not_satisfy_the_constraint_1,
633
+ );
634
+ checkTypeNameIsReserved(c, tp.name, Diagnostics.Type_parameter_name_cannot_be_0);
635
+ checkNodeDeferred(c, node);
636
+ }
637
+
638
+ /** Variance annotations are only allowed on type aliases of object, function, constructor and mapped types. */
639
+ export function checkTypeParameterDeferred(c: Checker, node: Node): void {
640
+ const parent = node.parent!;
641
+ const isTypeAlias =
642
+ parent.kind === SyntaxKind.TypeAliasDeclaration || parent.kind === SyntaxKind.JSTypeAliasDeclaration;
643
+ if (!isTypeAlias && parent.kind !== SyntaxKind.InterfaceDeclaration && !isClassLike(parent)) return;
644
+ const typeParameterSymbol = getSymbolOfDeclaration(c, node);
645
+ if (typeParameterSymbol === undefined) return;
646
+ const typeParameter = getDeclaredTypeOfTypeParameter(c, typeParameterSymbol);
647
+ const modifiers = getTypeParameterModifiers(typeParameter) & (ModifierFlags.In | ModifierFlags.Out);
648
+ if (modifiers === 0) return;
649
+ const symbol = getSymbolOfDeclaration(c, parent);
650
+ if (symbol === undefined) return;
651
+ if (
652
+ isTypeAlias &&
653
+ (getDeclaredTypeOfSymbol(c, symbol).objectFlags & (ObjectFlags.Anonymous | ObjectFlags.Mapped)) === 0
654
+ )
655
+ c.error(
656
+ node,
657
+ Diagnostics.Variance_annotations_are_only_supported_in_type_aliases_for_object_function_constructor_and_mapped_types,
658
+ );
659
+ else if (modifiers === ModifierFlags.In || modifiers === ModifierFlags.Out) {
660
+ // The declared variance must hold between instantiations with marker sub- and supertypes.
661
+ const isOut = modifiers === ModifierFlags.Out;
662
+ const source = createMarkerType(
663
+ c,
664
+ symbol,
665
+ typeParameter,
666
+ isOut ? c.markerSubTypeForCheck : c.markerSuperTypeForCheck,
667
+ );
668
+ const target = createMarkerType(
669
+ c,
670
+ symbol,
671
+ typeParameter,
672
+ isOut ? c.markerSuperTypeForCheck : c.markerSubTypeForCheck,
673
+ );
674
+ const saveVarianceTypeParameter = c.varianceTypeParameter;
675
+ c.varianceTypeParameter = typeParameter;
676
+ checkTypeAssignableTo(
677
+ c,
678
+ source,
679
+ target,
680
+ node,
681
+ Diagnostics.Type_0_is_not_assignable_to_type_1_as_implied_by_variance_annotation,
682
+ );
683
+ c.varianceTypeParameter = saveVarianceTypeParameter;
684
+ }
685
+ }
686
+
687
+ /** Checks a type parameter list: each parameter, default ordering and duplicate names. */
688
+ export function checkTypeParameters(c: Checker, list: NodeList | undefined): void {
689
+ if (list === undefined) return;
690
+ const typeParameters = list.nodes;
691
+ let seenDefault = false;
692
+ for (let i = 0; i < typeParameters.length; i++) {
693
+ const node = typeParameters[i]! as TypeParameterDeclaration;
694
+ checkTypeParameter(c, node);
695
+ if (node.defaultType !== undefined) {
696
+ seenDefault = true;
697
+ const finder = new LaterTypeParameterReferenceFinder(c, typeParameters, i);
698
+ finder.visitNode(node.defaultType);
699
+ } else if (seenDefault) c.error(node, Diagnostics.Required_type_parameters_may_not_follow_optional_type_parameters);
700
+ for (let j = 0; j < i; j++)
701
+ if (getSymbol(typeParameters[j]!) === getSymbol(node))
702
+ c.error(
703
+ node.name,
704
+ Diagnostics.Duplicate_identifier_0,
705
+ declarationNameToString(getSourceFileOfNode(node), node.name),
706
+ );
707
+ }
708
+ }
709
+
710
+ /** Reports references in a type parameter default to the parameter itself or later ones. */
711
+ class LaterTypeParameterReferenceFinder extends NodeVisitor {
712
+ readonly c: Checker;
713
+ readonly typeParameters: Node[];
714
+ readonly index: number;
715
+
716
+ constructor(c: Checker, typeParameters: Node[], index: number) {
717
+ super();
718
+ this.c = c;
719
+ this.typeParameters = typeParameters;
720
+ this.index = index;
721
+ }
722
+
723
+ visitNode(node: Node): boolean {
724
+ if (node.kind === SyntaxKind.TypeReference) {
725
+ const t = getTypeFromTypeNode(this.c, node);
726
+ if ((t.flags & TypeFlags.TypeParameter) !== 0)
727
+ for (let i = this.index; i < this.typeParameters.length; i++)
728
+ if (t.symbol === getSymbolOfDeclaration(this.c, this.typeParameters[i]!))
729
+ this.c.error(
730
+ node,
731
+ Diagnostics.Type_parameter_defaults_can_only_reference_previously_declared_type_parameters,
732
+ );
733
+ }
734
+ return node.forEachChild(this);
735
+ }
736
+ }
737
+
738
+ export function checkTypeAliasDeclaration(c: Checker, node: Node): void {
739
+ const alias = node as TypeAliasDeclaration;
740
+ const typeParameters = alias.typeParameters;
741
+ checkTypeNameIsReserved(c, alias.name, Diagnostics.Type_alias_name_cannot_be_0);
742
+ checkExportsOnMergedDeclarations(c, node);
743
+ checkTypeParameters(c, typeParameters);
744
+ if (alias.type.kind === SyntaxKind.IntrinsicKeyword) {
745
+ const name = getText(alias.name);
746
+ const count = typeParameters !== undefined ? typeParameters.nodes.length : 0;
747
+ if (
748
+ !(count === 0 && name === 'BuiltinIteratorReturn') &&
749
+ !(count === 1 && intrinsicTypeKind(name) !== IntrinsicTypeKind.Unknown)
750
+ )
751
+ c.error(
752
+ alias.type,
753
+ Diagnostics.The_intrinsic_keyword_can_only_be_used_to_declare_compiler_provided_intrinsic_types,
754
+ );
755
+ } else checkSourceElement(c, alias.type);
756
+ }
757
+
758
+ /**
759
+ * Checks the type arguments of a type reference, an import type or a heritage type reference against the
760
+ * constraints of the type parameters of what it references, as tsgo's checkTypeReferenceOrImport does;
761
+ * not when `type`, the type of the reference, is the error type.
762
+ */
763
+ export function checkTypeArgumentConstraintsOfReference(c: Checker, node: Node, type: Type): void {
764
+ if (isErrorType(c, type) || (getTypeArguments(node)?.nodes.length ?? 0) === 0) return;
765
+ const symbol = c.resolvedSymbols.get(node.id);
766
+ if (symbol === undefined) return;
767
+ let typeParameters: readonly Type[] | undefined = undefined;
768
+ if ((symbol.flags & SymbolFlags.TypeAlias) !== 0) typeParameters = c.symbolLinks(symbol).typeParameters;
769
+ if ((typeParameters === undefined || typeParameters.length === 0) && (type.objectFlags & ObjectFlags.Reference) !== 0)
770
+ typeParameters = ((type as TypeReference).target as InterfaceType).localTypeParameters();
771
+ if (typeParameters !== undefined && typeParameters.length > 0) checkTypeArgumentConstraints(c, node, typeParameters);
772
+ }
773
+
774
+ export function checkEnumMember(c: Checker, node: Node): void {
775
+ const name = getName(node);
776
+ if (name !== undefined && name.kind === SyntaxKind.PrivateIdentifier)
777
+ c.error(node, Diagnostics.An_enum_member_cannot_be_named_with_a_private_identifier);
778
+ const initializer = getInitializer(node);
779
+ if (initializer !== undefined) checkExpression(c, initializer);
780
+ }
781
+
782
+ export function checkEnumDeclaration(c: Checker, node: Node): void {
783
+ const name = getName(node)!;
784
+ checkCollisionsForDeclarationName(c, node, name);
785
+ checkTypeNameIsReserved(c, name, Diagnostics.Enum_name_cannot_be_0);
786
+ checkExportsOnMergedDeclarations(c, node);
787
+ for (const member of (node as EnumDeclaration).members.nodes) checkSourceElement(c, member);
788
+ if (shouldCheckErasableSyntax(c, node) && (node.flags & NodeFlags.Ambient) === 0)
789
+ c.error(node, Diagnostics.This_syntax_is_not_allowed_when_erasableSyntaxOnly_is_enabled);
790
+ computeEnumMemberValues(c, node);
791
+ const symbol = getSymbolOfDeclaration(c, node);
792
+ if (symbol === undefined) return;
793
+ const links = c.symbolLinks(symbol);
794
+ if (links.enumChecked) return;
795
+ links.enumChecked = true;
796
+ if (declarationCount(symbol) > 1) {
797
+ const enumIsConst = isEnumConst(node);
798
+ for (const d of getDeclarations(symbol))
799
+ if (d.kind === SyntaxKind.EnumDeclaration && isEnumConst(d) !== enumIsConst)
800
+ c.error(getNameOfDeclaration(d), Diagnostics.Enum_declarations_must_all_be_const_or_non_const);
801
+ }
802
+ // Only one declaration of a merged enum may continue automatic numbering from zero.
803
+ let seenEnumMissingInitialInitializer = false;
804
+ for (const d of getDeclarations(symbol)) {
805
+ if (d.kind !== SyntaxKind.EnumDeclaration) continue;
806
+ const members = (d as EnumDeclaration).members.nodes;
807
+ if (members.length === 0 || getInitializer(members[0]!) !== undefined) continue;
808
+ if (seenEnumMissingInitialInitializer)
809
+ c.error(
810
+ getName(members[0]!),
811
+ Diagnostics.In_an_enum_with_multiple_declarations_only_one_declaration_can_omit_an_initializer_for_its_first_enum_element,
812
+ );
813
+ else seenEnumMissingInitialInitializer = true;
814
+ }
815
+ }
816
+
817
+ /** Whether erasableSyntaxOnly applies at `node`: it is set, and `node` is in a TypeScript file. */
818
+ export function shouldCheckErasableSyntax(c: Checker, node: Node): boolean {
819
+ return c.compilerOptions.erasableSyntaxOnly === true && !isInJSFile(node);
820
+ }
821
+
822
+ export function checkModuleDeclaration(c: Checker, node: Node): void {
823
+ const module = node as ModuleDeclaration;
824
+ const body = module.body;
825
+ if (body !== undefined) checkSourceElement(c, body);
826
+ const isGlobalAugmentation = isGlobalScopeAugmentation(node);
827
+ const inAmbientContext = (node.flags & NodeFlags.Ambient) !== 0;
828
+ if (isGlobalAugmentation && !inAmbientContext)
829
+ c.error(
830
+ module.name,
831
+ Diagnostics.Augmentations_for_the_global_scope_should_have_declare_modifier_unless_they_appear_in_already_ambient_context,
832
+ );
833
+ const contextMessage = isAmbientModule(node)
834
+ ? Diagnostics.An_ambient_module_declaration_is_only_allowed_at_the_top_level_in_a_file
835
+ : Diagnostics.A_namespace_declaration_is_only_allowed_at_the_top_level_of_a_namespace_or_module;
836
+ if (checkModuleElementContext(c, node, contextMessage)) return;
837
+ if (module.name.kind === SyntaxKind.Identifier) checkCollisionsForDeclarationName(c, node, module.name);
838
+ if (module.name.kind === SyntaxKind.Identifier && module.keyword === SyntaxKind.ModuleKeyword)
839
+ c.error(
840
+ module.name,
841
+ Diagnostics.A_namespace_declaration_should_not_be_declared_using_the_module_keyword_Please_use_the_namespace_keyword_instead,
842
+ );
843
+ checkExportsOnMergedDeclarations(c, node);
844
+ const symbol = getSymbolOfDeclaration(c, node);
845
+ // Only non-ambient instantiated namespaces.
846
+ if (
847
+ symbol !== undefined &&
848
+ (symbol.flags & SymbolFlags.ValueModule) !== 0 &&
849
+ !inAmbientContext &&
850
+ isInstantiatedModule(node, c.preserveConstEnums)
851
+ ) {
852
+ if (shouldCheckErasableSyntax(c, node))
853
+ c.error(node, Diagnostics.This_syntax_is_not_allowed_when_erasableSyntaxOnly_is_enabled);
854
+ // Namespaces of global scripts can merge across files, which a transpiler of one file cannot see.
855
+ if (c.isolatedModules && getSourceFileOfNode(node).externalModuleIndicator === undefined)
856
+ c.error(
857
+ module.name,
858
+ Diagnostics.Namespaces_are_not_allowed_in_global_script_files_when_0_is_enabled_If_this_file_is_not_intended_to_be_a_global_script_set_moduleDetection_to_force_or_add_an_empty_export_statement,
859
+ c.compilerOptions.verbatimModuleSyntax === true ? 'verbatimModuleSyntax' : 'isolatedModules',
860
+ );
861
+ if (declarationCount(symbol) > 1) {
862
+ const classOrFunction = getFirstNonAmbientClassOrFunctionDeclaration(symbol);
863
+ if (classOrFunction !== undefined) {
864
+ if (getSourceFileOfNode(node) !== getSourceFileOfNode(classOrFunction))
865
+ c.error(
866
+ module.name,
867
+ Diagnostics.A_namespace_declaration_cannot_be_in_a_different_file_from_a_class_or_function_with_which_it_is_merged,
868
+ );
869
+ else if (node.pos < classOrFunction.pos)
870
+ c.error(
871
+ module.name,
872
+ Diagnostics.A_namespace_declaration_cannot_be_located_prior_to_a_class_or_function_with_which_it_is_merged,
873
+ );
874
+ }
875
+ }
876
+ if (
877
+ c.compilerOptions.verbatimModuleSyntax === true &&
878
+ node.parent!.kind === SyntaxKind.SourceFile &&
879
+ hasSyntacticModifier(node, ModifierFlags.Export) &&
880
+ c.host.getEmitModuleFormatOfFile(node.parent as SourceFile) === ModuleKind.CommonJS
881
+ ) {
882
+ const exportModifier = getModifiers(node)!.nodes.find((m) => m.kind === SyntaxKind.ExportKeyword)!;
883
+ c.error(
884
+ exportModifier,
885
+ Diagnostics.A_top_level_export_modifier_cannot_be_used_on_value_declarations_in_a_CommonJS_module_when_verbatimModuleSyntax_is_enabled,
886
+ );
887
+ }
888
+ }
889
+ if (!isAmbientModule(node)) return;
890
+ if (isModuleAugmentationExternal(node)) {
891
+ // Check an augmentation's body only when it merged with its target.
892
+ const checkBody = isGlobalAugmentation || (symbol !== undefined && (symbol.flags & SymbolFlags.Transient) !== 0);
893
+ if (checkBody && body !== undefined && body.kind === SyntaxKind.ModuleBlock)
894
+ for (const statement of getStatements(body)!.nodes) checkModuleAugmentationElement(c, statement);
895
+ return;
896
+ }
897
+ const parent = node.parent!;
898
+ if (isGlobalAugmentation)
899
+ c.error(
900
+ module.name,
901
+ Diagnostics.Augmentations_for_the_global_scope_can_only_be_directly_nested_in_external_modules_or_ambient_module_declarations,
902
+ );
903
+ else if (parent.kind === SyntaxKind.SourceFile && !isExternalModule(parent as SourceFile)) {
904
+ if (isExternalModuleNameRelative(getText(module.name)))
905
+ c.error(module.name, Diagnostics.Ambient_module_declaration_cannot_specify_relative_module_name);
906
+ } else c.error(module.name, Diagnostics.Ambient_modules_cannot_be_nested_in_other_modules_or_namespaces);
907
+ }
908
+
909
+ export function isInstantiatedModule(node: Node, preserveConstEnums: boolean): boolean {
910
+ const state = getModuleInstanceState(node);
911
+ return (
912
+ state === ModuleInstanceState.Instantiated || (preserveConstEnums && state === ModuleInstanceState.ConstEnumOnly)
913
+ );
914
+ }
915
+
916
+ function getFirstNonAmbientClassOrFunctionDeclaration(symbol: Symbol): Node | undefined {
917
+ for (const d of getDeclarations(symbol))
918
+ if (
919
+ (d.kind === SyntaxKind.ClassDeclaration ||
920
+ (d.kind === SyntaxKind.FunctionDeclaration && nodeIsPresent(getBody(d)))) &&
921
+ (d.flags & NodeFlags.Ambient) === 0
922
+ )
923
+ return d;
924
+ return undefined;
925
+ }
926
+
927
+ function checkModuleAugmentationElement(c: Checker, node: Node): void {
928
+ switch (node.kind) {
929
+ case SyntaxKind.VariableStatement:
930
+ // Each name, rather than the whole statement.
931
+ for (const d of (node as VariableStatement).declarationList.declarations.nodes)
932
+ checkModuleAugmentationElement(c, d);
933
+ return;
934
+ case SyntaxKind.ExportAssignment:
935
+ case SyntaxKind.ExportDeclaration:
936
+ grammarErrorOnFirstToken(
937
+ c,
938
+ node,
939
+ Diagnostics.Exports_and_export_assignments_are_not_permitted_in_module_augmentations,
940
+ );
941
+ return;
942
+ case SyntaxKind.ImportEqualsDeclaration:
943
+ // `import a = e.x` is allowed; `import a = require("m")` isn't.
944
+ if ((node as ImportEqualsDeclaration).moduleReference.kind !== SyntaxKind.ExternalModuleReference) return;
945
+ grammarErrorOnFirstToken(
946
+ c,
947
+ node,
948
+ Diagnostics.Imports_are_not_permitted_in_module_augmentations_Consider_moving_them_to_the_enclosing_external_module,
949
+ );
950
+ return;
951
+ case SyntaxKind.ImportDeclaration:
952
+ grammarErrorOnFirstToken(
953
+ c,
954
+ node,
955
+ Diagnostics.Imports_are_not_permitted_in_module_augmentations_Consider_moving_them_to_the_enclosing_external_module,
956
+ );
957
+ return;
958
+ }
959
+ }
960
+
961
+ /** Reports at the first token of `node` unless the file has syntax errors. */
962
+ function grammarErrorOnFirstToken(c: Checker, node: Node, message: DiagnosticMessage): void {
963
+ const file = getSourceFileOfNode(node);
964
+ if (file.diagnostics.length > 0) return;
965
+ const span = getRangeOfTokenAtPosition(file, node.pos);
966
+ c.addDiagnostic(new Diagnostic(file.diagnosticFile(), span.pos, span.end, message, []));
967
+ }
968
+
969
+ // ---- Imports and exports
970
+
971
+ /**
972
+ * Reports a module element (import, export, namespace) outside a file, namespace or module body.
973
+ * Callers stop checking the element when this returns true.
974
+ */
975
+ function checkModuleElementContext(c: Checker, node: Node, message: DiagnosticMessage): boolean {
976
+ const parent = node.parent!.kind;
977
+ if (parent === SyntaxKind.SourceFile || parent === SyntaxKind.ModuleBlock || parent === SyntaxKind.ModuleDeclaration)
978
+ return false;
979
+ grammarErrorOnFirstToken(c, node, message);
980
+ return true;
981
+ }
982
+
983
+ /** Reports `export =` mixed with other exports, and names exported by more than one declaration. */
984
+ export function checkExternalModuleExports(c: Checker, node: Node): void {
985
+ const moduleSymbol = getSymbolOfDeclaration(c, node);
986
+ if (moduleSymbol === undefined) return;
987
+ const links = c.symbolLinks(moduleSymbol);
988
+ if (links.exportsChecked) return;
989
+ links.exportsChecked = true;
990
+ const exportEquals = moduleSymbol.exports?.get(InternalSymbolName.ExportEquals);
991
+ // `export =` conflicts with exported values, and with exported types or namespaces the target also exports.
992
+ if (
993
+ exportEquals !== undefined &&
994
+ (hasExportedMembersOfKind(c, moduleSymbol, SymbolFlags.Value) || hasShadowedNamespace(c, exportEquals))
995
+ ) {
996
+ const declaration = getDeclarationOfAliasSymbol(exportEquals) ?? exportEquals.valueDeclaration;
997
+ if (declaration !== undefined && !isTopLevelInExternalModuleAugmentation(declaration))
998
+ c.error(declaration, Diagnostics.An_export_assignment_cannot_be_used_in_a_module_with_other_exported_elements);
999
+ }
1000
+ for (const [id, symbol] of getExportsOfModule(c, moduleSymbol)) {
1001
+ // Namespaces, enums, interfaces and overloads may have several declarations.
1002
+ if (id === InternalSymbolName.ExportStar || (symbol.flags & (SymbolFlags.Namespace | SymbolFlags.Enum)) !== 0)
1003
+ continue;
1004
+ let count = 0;
1005
+ for (const d of getDeclarations(symbol))
1006
+ if (isNotOverload(d) && !isAccessorDeclaration(d) && d.kind !== SyntaxKind.InterfaceDeclaration) count++;
1007
+ // A type alias may merge with one value.
1008
+ if ((symbol.flags & SymbolFlags.TypeAlias) !== 0 && count <= 2) continue;
1009
+ if (count <= 1) continue;
1010
+ let allExportsProperties = true;
1011
+ for (const d of getDeclarations(symbol))
1012
+ if (getAssignmentDeclarationKind(d) !== JSDeclarationKind.ExportsProperty) allExportsProperties = false;
1013
+ if (allExportsProperties) continue;
1014
+ for (const d of getDeclarations(symbol))
1015
+ if (isNotOverload(d)) c.error(d, Diagnostics.Cannot_redeclare_exported_variable_0, id);
1016
+ }
1017
+ }
1018
+
1019
+ function hasExportedMembersOfKind(c: Checker, moduleSymbol: Symbol, kind: SymbolFlags): boolean {
1020
+ if (moduleSymbol.exports === undefined) return false;
1021
+ for (const [name, symbol] of moduleSymbol.exports)
1022
+ if (name !== InternalSymbolName.ExportEquals && (getSymbolFlags(c, symbol) & kind) !== 0) return true;
1023
+ return false;
1024
+ }
1025
+
1026
+ function hasShadowedNamespace(c: Checker, symbol: Symbol): boolean {
1027
+ if ((symbol.flags & SymbolFlags.NamespaceModule) === 0 || (symbol.flags & SymbolFlags.Alias) === 0) return false;
1028
+ const target = resolveAlias(c, symbol);
1029
+ return (
1030
+ (target.flags & SymbolFlags.Namespace) !== 0 &&
1031
+ hasExportedMembersOfKind(c, target, SymbolFlags.Type | SymbolFlags.Namespace)
1032
+ );
1033
+ }
1034
+
1035
+ function isNotOverload(node: Node): boolean {
1036
+ return (
1037
+ (node.kind !== SyntaxKind.FunctionDeclaration && node.kind !== SyntaxKind.MethodDeclaration) ||
1038
+ getBody(node) !== undefined
1039
+ );
1040
+ }
1041
+
1042
+ function isAccessorDeclaration(node: Node): boolean {
1043
+ return node.kind === SyntaxKind.GetAccessor || node.kind === SyntaxKind.SetAccessor;
1044
+ }
1045
+
1046
+ function isTopLevelInExternalModuleAugmentation(node: Node): boolean {
1047
+ const parent = node.parent;
1048
+ if (parent === undefined || parent.kind !== SyntaxKind.ModuleBlock) return false;
1049
+ const module = parent.parent!;
1050
+ return isAmbientModule(module) && isModuleAugmentationExternal(module);
1051
+ }
1052
+
1053
+ // ---- Merged declarations
1054
+
1055
+ const enum DeclarationSpaces {
1056
+ None = 0,
1057
+ ExportValue = 1 << 0,
1058
+ ExportType = 1 << 1,
1059
+ ExportNamespace = 1 << 2,
1060
+ }
1061
+
1062
+ /** Reports merged declarations that mix exported and local (or default-exported) declarations. */
1063
+ export function checkExportsOnMergedDeclarations(c: Checker, node: Node): void {
1064
+ let symbol = getLocalSymbol(node);
1065
+ if (symbol === undefined) {
1066
+ symbol = getSymbolOfDeclaration(c, node);
1067
+ if (symbol === undefined || symbol.exportSymbol === undefined) return;
1068
+ }
1069
+ if (getDeclarationOfKind(symbol, node.kind) !== node) return;
1070
+ let exported = DeclarationSpaces.None;
1071
+ let nonExported = DeclarationSpaces.None;
1072
+ let defaultExported = DeclarationSpaces.None;
1073
+ for (const d of getDeclarations(symbol)) {
1074
+ const spaces = getDeclarationSpaces(c, d);
1075
+ const flags = getEffectiveDeclarationFlags(d, ModifierFlags.Export | ModifierFlags.Default);
1076
+ if ((flags & ModifierFlags.Export) !== 0) {
1077
+ if ((flags & ModifierFlags.Default) !== 0) defaultExported |= spaces;
1078
+ else exported |= spaces;
1079
+ } else nonExported |= spaces;
1080
+ }
1081
+ const nonDefaultExported = exported | nonExported;
1082
+ const commonForExportsAndLocals = exported & nonExported;
1083
+ const commonForDefaultAndNonDefault = defaultExported & nonDefaultExported;
1084
+ if (commonForExportsAndLocals === 0 && commonForDefaultAndNonDefault === 0) return;
1085
+ for (const d of getDeclarations(symbol)) {
1086
+ const spaces = getDeclarationSpaces(c, d);
1087
+ const name = getNameOfDeclaration(d);
1088
+ const text = declarationNameToString(getSourceFileOfNode(d), name);
1089
+ if ((spaces & commonForDefaultAndNonDefault) !== 0)
1090
+ c.error(
1091
+ name,
1092
+ Diagnostics.Merged_declaration_0_cannot_include_a_default_export_declaration_Consider_adding_a_separate_export_default_0_declaration_instead,
1093
+ text,
1094
+ );
1095
+ else if ((spaces & commonForExportsAndLocals) !== 0)
1096
+ c.error(
1097
+ name,
1098
+ Diagnostics.Individual_declarations_in_merged_declaration_0_must_be_all_exported_or_all_local,
1099
+ text,
1100
+ );
1101
+ }
1102
+ }
1103
+
1104
+ function getDeclarationSpaces(c: Checker, node: Node): DeclarationSpaces {
1105
+ switch (node.kind) {
1106
+ case SyntaxKind.InterfaceDeclaration:
1107
+ case SyntaxKind.TypeAliasDeclaration:
1108
+ case SyntaxKind.JSTypeAliasDeclaration:
1109
+ return DeclarationSpaces.ExportType;
1110
+ case SyntaxKind.ModuleDeclaration:
1111
+ return isAmbientModule(node) || getModuleInstanceState(node) !== ModuleInstanceState.NonInstantiated
1112
+ ? DeclarationSpaces.ExportNamespace | DeclarationSpaces.ExportValue
1113
+ : DeclarationSpaces.ExportNamespace;
1114
+ case SyntaxKind.ClassDeclaration:
1115
+ case SyntaxKind.EnumDeclaration:
1116
+ case SyntaxKind.EnumMember:
1117
+ return DeclarationSpaces.ExportType | DeclarationSpaces.ExportValue;
1118
+ case SyntaxKind.SourceFile:
1119
+ return DeclarationSpaces.ExportType | DeclarationSpaces.ExportValue | DeclarationSpaces.ExportNamespace;
1120
+ case SyntaxKind.ExportAssignment: {
1121
+ const expression = getExpression(node)!;
1122
+ const symbol = getSymbolOfDeclaration(c, node);
1123
+ if (
1124
+ !isEntityNameExpression(expression, false) ||
1125
+ symbol === undefined ||
1126
+ (symbol.flags & SymbolFlags.Alias) === 0
1127
+ )
1128
+ return DeclarationSpaces.ExportValue;
1129
+ return getAliasDeclarationSpaces(c, node);
1130
+ }
1131
+ case SyntaxKind.ImportEqualsDeclaration:
1132
+ case SyntaxKind.NamespaceImport:
1133
+ case SyntaxKind.ImportClause:
1134
+ return getAliasDeclarationSpaces(c, node);
1135
+ case SyntaxKind.MethodSignature:
1136
+ case SyntaxKind.PropertySignature:
1137
+ return DeclarationSpaces.ExportType;
1138
+ }
1139
+ return DeclarationSpaces.ExportValue;
1140
+ }
1141
+
1142
+ function getAliasDeclarationSpaces(c: Checker, node: Node): DeclarationSpaces {
1143
+ const symbol = getSymbolOfDeclaration(c, node);
1144
+ if (symbol === undefined) return DeclarationSpaces.None;
1145
+ let result = DeclarationSpaces.None;
1146
+ for (const d of getDeclarations(resolveAlias(c, symbol))) result |= getDeclarationSpaces(c, d);
1147
+ return result;
1148
+ }
1149
+
1150
+ export function getEffectiveDeclarationFlags(node: Node, flagsToCheck: ModifierFlags): ModifierFlags {
1151
+ let flags = getCombinedModifierFlags(node);
1152
+ const parent = node.parent!;
1153
+ if (
1154
+ parent.kind !== SyntaxKind.InterfaceDeclaration &&
1155
+ parent.kind !== SyntaxKind.ClassDeclaration &&
1156
+ parent.kind !== SyntaxKind.ClassExpression &&
1157
+ (node.flags & NodeFlags.Ambient) !== 0
1158
+ ) {
1159
+ let container = node.parent;
1160
+ while (container !== undefined && (getContainerFlags(container) & ContainerFlags.IsContainer) === 0)
1161
+ container = container.parent;
1162
+ if (
1163
+ container !== undefined &&
1164
+ (container.flags & NodeFlags.ExportContext) !== 0 &&
1165
+ (flags & ModifierFlags.Ambient) === 0 &&
1166
+ !(parent.kind === SyntaxKind.ModuleBlock && isGlobalScopeAugmentation(parent.parent!))
1167
+ )
1168
+ flags |= ModifierFlags.Export;
1169
+ flags |= ModifierFlags.Ambient;
1170
+ }
1171
+ return flags & flagsToCheck;
1172
+ }
1173
+
1174
+ /** Reports renamings in parameters of bodiless signatures whose new names are unused. */
1175
+ export function checkUnusedRenamedBindingElements(c: Checker): void {
1176
+ for (const element of c.renamedBindingElementsInTypes) {
1177
+ const symbol = getSymbolOfDeclaration(c, element);
1178
+ if (symbol !== undefined && c.symbolReferenceKinds.get(getSymbolId(symbol)) !== 0) continue;
1179
+ const file = getSourceFileOfNode(element);
1180
+ const name = (element as BindingElement).name!;
1181
+ const propertyName = declarationNameToString(file, (element as BindingElement).propertyName);
1182
+ const diagnostic = c.error(
1183
+ name,
1184
+ Diagnostics.X_0_is_an_unused_renaming_of_1_Did_you_intend_to_use_it_as_a_type_annotation,
1185
+ declarationNameToString(file, name),
1186
+ propertyName,
1187
+ );
1188
+ const parameter = getRootDeclaration(element);
1189
+ if (getType(parameter) === undefined)
1190
+ diagnostic.addRelatedInfo(
1191
+ new Diagnostic(
1192
+ file.diagnosticFile(),
1193
+ parameter.end,
1194
+ parameter.end,
1195
+ Diagnostics.We_can_only_write_a_type_for_0_by_adding_a_type_for_the_entire_parameter_here,
1196
+ [propertyName],
1197
+ ),
1198
+ );
1199
+ }
1200
+ c.renamedBindingElementsInTypes.length = 0;
1201
+ }