tsc-ts 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (584) hide show
  1. package/README.md +33 -1
  2. package/dist/api/compiler/ast-utilities.d.ts +82 -0
  3. package/dist/api/compiler/ast-utilities.js +462 -0
  4. package/dist/api/compiler/ast.d.ts +2350 -0
  5. package/dist/api/compiler/ast.js +11206 -0
  6. package/dist/api/compiler/astnav.d.ts +37 -0
  7. package/dist/api/compiler/astnav.js +767 -0
  8. package/dist/api/compiler/binder-utilities.d.ts +182 -0
  9. package/dist/api/compiler/binder-utilities.js +1240 -0
  10. package/dist/api/compiler/binder.d.ts +33 -0
  11. package/dist/api/compiler/binder.js +2358 -0
  12. package/dist/api/compiler/character-codes.d.ts +161 -0
  13. package/dist/api/compiler/character-codes.js +160 -0
  14. package/dist/api/compiler/checker-calls.d.ts +46 -0
  15. package/dist/api/compiler/checker-calls.js +1640 -0
  16. package/dist/api/compiler/checker-classes.d.ts +30 -0
  17. package/dist/api/compiler/checker-classes.js +582 -0
  18. package/dist/api/compiler/checker-contextual.d.ts +77 -0
  19. package/dist/api/compiler/checker-contextual.js +1136 -0
  20. package/dist/api/compiler/checker-declaration-order.d.ts +12 -0
  21. package/dist/api/compiler/checker-declaration-order.js +356 -0
  22. package/dist/api/compiler/checker-declarations.d.ts +33 -0
  23. package/dist/api/compiler/checker-declarations.js +888 -0
  24. package/dist/api/compiler/checker-declared-types.d.ts +48 -0
  25. package/dist/api/compiler/checker-declared-types.js +787 -0
  26. package/dist/api/compiler/checker-decorators.d.ts +26 -0
  27. package/dist/api/compiler/checker-decorators.js +562 -0
  28. package/dist/api/compiler/checker-deprecation.d.ts +33 -0
  29. package/dist/api/compiler/checker-deprecation.js +315 -0
  30. package/dist/api/compiler/checker-destructuring.d.ts +34 -0
  31. package/dist/api/compiler/checker-destructuring.js +584 -0
  32. package/dist/api/compiler/checker-elaboration.d.ts +15 -0
  33. package/dist/api/compiler/checker-elaboration.js +290 -0
  34. package/dist/api/compiler/checker-emit-helpers.d.ts +58 -0
  35. package/dist/api/compiler/checker-emit-helpers.js +154 -0
  36. package/dist/api/compiler/checker-emit-resolver.d.ts +75 -0
  37. package/dist/api/compiler/checker-emit-resolver.js +579 -0
  38. package/dist/api/compiler/checker-evaluator.d.ts +27 -0
  39. package/dist/api/compiler/checker-evaluator.js +188 -0
  40. package/dist/api/compiler/checker-expressions.d.ts +67 -0
  41. package/dist/api/compiler/checker-expressions.js +1351 -0
  42. package/dist/api/compiler/checker-features.d.ts +6 -0
  43. package/dist/api/compiler/checker-features.js +354 -0
  44. package/dist/api/compiler/checker-flow.d.ts +86 -0
  45. package/dist/api/compiler/checker-flow.js +169 -0
  46. package/dist/api/compiler/checker-functions.d.ts +43 -0
  47. package/dist/api/compiler/checker-functions.js +1002 -0
  48. package/dist/api/compiler/checker-generated-code.d.ts +25 -0
  49. package/dist/api/compiler/checker-generated-code.js +168 -0
  50. package/dist/api/compiler/checker-globals.d.ts +14 -0
  51. package/dist/api/compiler/checker-globals.js +37 -0
  52. package/dist/api/compiler/checker-grammar.d.ts +35 -0
  53. package/dist/api/compiler/checker-grammar.js +2573 -0
  54. package/dist/api/compiler/checker-heritage.d.ts +28 -0
  55. package/dist/api/compiler/checker-heritage.js +900 -0
  56. package/dist/api/compiler/checker-inference.d.ts +179 -0
  57. package/dist/api/compiler/checker-inference.js +2105 -0
  58. package/dist/api/compiler/checker-iteration.d.ts +115 -0
  59. package/dist/api/compiler/checker-iteration.js +857 -0
  60. package/dist/api/compiler/checker-javascript.d.ts +42 -0
  61. package/dist/api/compiler/checker-javascript.js +441 -0
  62. package/dist/api/compiler/checker-jsdoc.d.ts +30 -0
  63. package/dist/api/compiler/checker-jsdoc.js +320 -0
  64. package/dist/api/compiler/checker-jsx.d.ts +94 -0
  65. package/dist/api/compiler/checker-jsx.js +1433 -0
  66. package/dist/api/compiler/checker-literals.d.ts +6 -0
  67. package/dist/api/compiler/checker-literals.js +43 -0
  68. package/dist/api/compiler/checker-members.d.ts +198 -0
  69. package/dist/api/compiler/checker-members.js +2126 -0
  70. package/dist/api/compiler/checker-modules.d.ts +85 -0
  71. package/dist/api/compiler/checker-modules.js +2141 -0
  72. package/dist/api/compiler/checker-narrowing.d.ts +120 -0
  73. package/dist/api/compiler/checker-narrowing.js +2797 -0
  74. package/dist/api/compiler/checker-object-literals.d.ts +14 -0
  75. package/dist/api/compiler/checker-object-literals.js +479 -0
  76. package/dist/api/compiler/checker-operators.d.ts +33 -0
  77. package/dist/api/compiler/checker-operators.js +1040 -0
  78. package/dist/api/compiler/checker-overloads.d.ts +7 -0
  79. package/dist/api/compiler/checker-overloads.js +270 -0
  80. package/dist/api/compiler/checker-property-access.d.ts +34 -0
  81. package/dist/api/compiler/checker-property-access.js +672 -0
  82. package/dist/api/compiler/checker-services.d.ts +49 -0
  83. package/dist/api/compiler/checker-services.js +995 -0
  84. package/dist/api/compiler/checker-signatures.d.ts +55 -0
  85. package/dist/api/compiler/checker-signatures.js +788 -0
  86. package/dist/api/compiler/checker-source-file.d.ts +27 -0
  87. package/dist/api/compiler/checker-source-file.js +619 -0
  88. package/dist/api/compiler/checker-statements.d.ts +18 -0
  89. package/dist/api/compiler/checker-statements.js +226 -0
  90. package/dist/api/compiler/checker-super.d.ts +13 -0
  91. package/dist/api/compiler/checker-super.js +241 -0
  92. package/dist/api/compiler/checker-symbol-types.d.ts +67 -0
  93. package/dist/api/compiler/checker-symbol-types.js +1885 -0
  94. package/dist/api/compiler/checker-symbols.d.ts +181 -0
  95. package/dist/api/compiler/checker-symbols.js +1782 -0
  96. package/dist/api/compiler/checker-type-factory.d.ts +142 -0
  97. package/dist/api/compiler/checker-type-factory.js +2501 -0
  98. package/dist/api/compiler/checker-type-nodes.d.ts +26 -0
  99. package/dist/api/compiler/checker-type-nodes.js +828 -0
  100. package/dist/api/compiler/checker-type-operators.d.ts +109 -0
  101. package/dist/api/compiler/checker-type-operators.js +1842 -0
  102. package/dist/api/compiler/checker-types.d.ts +1027 -0
  103. package/dist/api/compiler/checker-types.js +1697 -0
  104. package/dist/api/compiler/checker-unused.d.ts +19 -0
  105. package/dist/api/compiler/checker-unused.js +524 -0
  106. package/dist/api/compiler/checker-utilities.d.ts +33 -0
  107. package/dist/api/compiler/checker-utilities.js +141 -0
  108. package/dist/api/compiler/checker.d.ts +491 -0
  109. package/dist/api/compiler/checker.js +912 -0
  110. package/dist/api/compiler/command-line.d.ts +32 -0
  111. package/dist/api/compiler/command-line.js +383 -0
  112. package/dist/api/compiler/compile-program.d.ts +118 -0
  113. package/dist/api/compiler/compile-program.js +384 -0
  114. package/dist/api/compiler/diagnostic-locales.d.ts +22 -0
  115. package/dist/api/compiler/diagnostic-locales.js +64 -0
  116. package/dist/api/compiler/diagnostic-messages.d.ts +2166 -0
  117. package/dist/api/compiler/diagnostic-messages.js +184 -0
  118. package/dist/api/compiler/diagnostics.d.ts +167 -0
  119. package/dist/api/compiler/diagnostics.js +820 -0
  120. package/dist/api/compiler/emitter.d.ts +71 -0
  121. package/dist/api/compiler/emitter.js +327 -0
  122. package/dist/api/compiler/file-include.d.ts +117 -0
  123. package/dist/api/compiler/file-include.js +536 -0
  124. package/dist/api/compiler/file-loader.d.ts +261 -0
  125. package/dist/api/compiler/file-loader.js +1257 -0
  126. package/dist/api/compiler/file-system.d.ts +51 -0
  127. package/dist/api/compiler/file-system.js +132 -0
  128. package/dist/api/compiler/flow.d.ts +60 -0
  129. package/dist/api/compiler/flow.js +45 -0
  130. package/dist/api/compiler/instantiation.d.ts +74 -0
  131. package/dist/api/compiler/instantiation.js +799 -0
  132. package/dist/api/compiler/jsdoc.d.ts +75 -0
  133. package/dist/api/compiler/jsdoc.js +1229 -0
  134. package/dist/api/compiler/link-tables.d.ts +36 -0
  135. package/dist/api/compiler/link-tables.js +83 -0
  136. package/dist/api/compiler/locale-data.d.ts +24 -0
  137. package/dist/api/compiler/locale-data.js +183 -0
  138. package/dist/api/compiler/locale.d.ts +4 -0
  139. package/dist/api/compiler/locale.js +317 -0
  140. package/dist/api/compiler/locales/cs-CZ.d.ts +2 -0
  141. package/dist/api/compiler/locales/cs-CZ.js +3 -0
  142. package/dist/api/compiler/locales/de-DE.d.ts +2 -0
  143. package/dist/api/compiler/locales/de-DE.js +3 -0
  144. package/dist/api/compiler/locales/es-ES.d.ts +2 -0
  145. package/dist/api/compiler/locales/es-ES.js +3 -0
  146. package/dist/api/compiler/locales/fr-FR.d.ts +2 -0
  147. package/dist/api/compiler/locales/fr-FR.js +3 -0
  148. package/dist/api/compiler/locales/it-IT.d.ts +2 -0
  149. package/dist/api/compiler/locales/it-IT.js +3 -0
  150. package/dist/api/compiler/locales/ja-JP.d.ts +2 -0
  151. package/dist/api/compiler/locales/ja-JP.js +3 -0
  152. package/dist/api/compiler/locales/ko-KR.d.ts +2 -0
  153. package/dist/api/compiler/locales/ko-KR.js +3 -0
  154. package/dist/api/compiler/locales/pl-PL.d.ts +2 -0
  155. package/dist/api/compiler/locales/pl-PL.js +3 -0
  156. package/dist/api/compiler/locales/pt-BR.d.ts +2 -0
  157. package/dist/api/compiler/locales/pt-BR.js +3 -0
  158. package/dist/api/compiler/locales/ru-RU.d.ts +2 -0
  159. package/dist/api/compiler/locales/ru-RU.js +3 -0
  160. package/dist/api/compiler/locales/tr-TR.d.ts +2 -0
  161. package/dist/api/compiler/locales/tr-TR.js +3 -0
  162. package/dist/api/compiler/locales/zh-CN.d.ts +2 -0
  163. package/dist/api/compiler/locales/zh-CN.js +3 -0
  164. package/dist/api/compiler/locales/zh-TW.d.ts +2 -0
  165. package/dist/api/compiler/locales/zh-TW.js +3 -0
  166. package/dist/api/compiler/module-resolution-types.d.ts +83 -0
  167. package/dist/api/compiler/module-resolution-types.js +176 -0
  168. package/dist/api/compiler/module-resolution.d.ts +71 -0
  169. package/dist/api/compiler/module-resolution.js +1598 -0
  170. package/dist/api/compiler/module-specifiers.d.ts +64 -0
  171. package/dist/api/compiler/module-specifiers.js +1101 -0
  172. package/dist/api/compiler/name-resolver.d.ts +43 -0
  173. package/dist/api/compiler/name-resolver.js +509 -0
  174. package/dist/api/compiler/node-builder-names.d.ts +32 -0
  175. package/dist/api/compiler/node-builder-names.js +854 -0
  176. package/dist/api/compiler/node-builder-pseudo.d.ts +36 -0
  177. package/dist/api/compiler/node-builder-pseudo.js +744 -0
  178. package/dist/api/compiler/node-builder-reuse.d.ts +4 -0
  179. package/dist/api/compiler/node-builder-reuse.js +647 -0
  180. package/dist/api/compiler/node-builder.d.ts +270 -0
  181. package/dist/api/compiler/node-builder.js +2645 -0
  182. package/dist/api/compiler/option-declarations.d.ts +90 -0
  183. package/dist/api/compiler/option-declarations.js +1460 -0
  184. package/dist/api/compiler/options.d.ts +289 -0
  185. package/dist/api/compiler/options.js +1197 -0
  186. package/dist/api/compiler/output-paths.d.ts +42 -0
  187. package/dist/api/compiler/output-paths.js +195 -0
  188. package/dist/api/compiler/package-json.d.ts +175 -0
  189. package/dist/api/compiler/package-json.js +1015 -0
  190. package/dist/api/compiler/parallel-parse.d.ts +219 -0
  191. package/dist/api/compiler/parallel-parse.js +537 -0
  192. package/dist/api/compiler/parser.d.ts +587 -0
  193. package/dist/api/compiler/parser.js +6407 -0
  194. package/dist/api/compiler/path.d.ts +91 -0
  195. package/dist/api/compiler/path.js +705 -0
  196. package/dist/api/compiler/printer/async-helpers.d.ts +22 -0
  197. package/dist/api/compiler/printer/async-helpers.js +91 -0
  198. package/dist/api/compiler/printer/auto-generate.d.ts +13 -0
  199. package/dist/api/compiler/printer/auto-generate.js +20 -0
  200. package/dist/api/compiler/printer/decorator-helpers.d.ts +24 -0
  201. package/dist/api/compiler/printer/decorator-helpers.js +118 -0
  202. package/dist/api/compiler/printer/emit-context.d.ts +154 -0
  203. package/dist/api/compiler/printer/emit-context.js +576 -0
  204. package/dist/api/compiler/printer/emit-flags.d.ts +60 -0
  205. package/dist/api/compiler/printer/emit-flags.js +2 -0
  206. package/dist/api/compiler/printer/factory-base.d.ts +171 -0
  207. package/dist/api/compiler/printer/factory-base.js +1505 -0
  208. package/dist/api/compiler/printer/factory.d.ts +147 -0
  209. package/dist/api/compiler/printer/factory.js +542 -0
  210. package/dist/api/compiler/printer/helpers.d.ts +27 -0
  211. package/dist/api/compiler/printer/helpers.js +164 -0
  212. package/dist/api/compiler/printer/name-generator.d.ts +41 -0
  213. package/dist/api/compiler/printer/name-generator.js +283 -0
  214. package/dist/api/compiler/printer/printer.d.ts +411 -0
  215. package/dist/api/compiler/printer/printer.js +4517 -0
  216. package/dist/api/compiler/printer/text-writer.d.ts +46 -0
  217. package/dist/api/compiler/printer/text-writer.js +172 -0
  218. package/dist/api/compiler/printer/utilities.d.ts +82 -0
  219. package/dist/api/compiler/printer/utilities.js +817 -0
  220. package/dist/api/compiler/program-checker.d.ts +156 -0
  221. package/dist/api/compiler/program-checker.js +526 -0
  222. package/dist/api/compiler/program-utilities.d.ts +52 -0
  223. package/dist/api/compiler/program-utilities.js +365 -0
  224. package/dist/api/compiler/program.d.ts +180 -0
  225. package/dist/api/compiler/program.js +1011 -0
  226. package/dist/api/compiler/pseudo-bigint.d.ts +5 -0
  227. package/dist/api/compiler/pseudo-bigint.js +61 -0
  228. package/dist/api/compiler/regexp-checker.d.ts +38 -0
  229. package/dist/api/compiler/regexp-checker.js +942 -0
  230. package/dist/api/compiler/relations.d.ts +263 -0
  231. package/dist/api/compiler/relations.js +4002 -0
  232. package/dist/api/compiler/reparser.d.ts +48 -0
  233. package/dist/api/compiler/reparser.js +1323 -0
  234. package/dist/api/compiler/scanner.d.ts +256 -0
  235. package/dist/api/compiler/scanner.js +2853 -0
  236. package/dist/api/compiler/side-state.d.ts +16 -0
  237. package/dist/api/compiler/side-state.js +89 -0
  238. package/dist/api/compiler/sourcemap.d.ts +55 -0
  239. package/dist/api/compiler/sourcemap.js +340 -0
  240. package/dist/api/compiler/spelling.d.ts +14 -0
  241. package/dist/api/compiler/spelling.js +128 -0
  242. package/dist/api/compiler/symbol-accessibility.d.ts +57 -0
  243. package/dist/api/compiler/symbol-accessibility.js +894 -0
  244. package/dist/api/compiler/symbol.d.ts +240 -0
  245. package/dist/api/compiler/symbol.js +228 -0
  246. package/dist/api/compiler/symlinks.d.ts +32 -0
  247. package/dist/api/compiler/symlinks.js +114 -0
  248. package/dist/api/compiler/syntax-kind.d.ts +389 -0
  249. package/dist/api/compiler/syntax-kind.js +2 -0
  250. package/dist/api/compiler/timeline.d.ts +9 -0
  251. package/dist/api/compiler/timeline.js +54 -0
  252. package/dist/api/compiler/transformers/alias-references.d.ts +39 -0
  253. package/dist/api/compiler/transformers/alias-references.js +676 -0
  254. package/dist/api/compiler/transformers/async-utilities.d.ts +51 -0
  255. package/dist/api/compiler/transformers/async-utilities.js +260 -0
  256. package/dist/api/compiler/transformers/async.d.ts +53 -0
  257. package/dist/api/compiler/transformers/async.js +645 -0
  258. package/dist/api/compiler/transformers/class-fields.d.ts +206 -0
  259. package/dist/api/compiler/transformers/class-fields.js +2418 -0
  260. package/dist/api/compiler/transformers/class-utilities.d.ts +46 -0
  261. package/dist/api/compiler/transformers/class-utilities.js +261 -0
  262. package/dist/api/compiler/transformers/commonjs-module.d.ts +103 -0
  263. package/dist/api/compiler/transformers/commonjs-module.js +1180 -0
  264. package/dist/api/compiler/transformers/const-enum-inliner.d.ts +11 -0
  265. package/dist/api/compiler/transformers/const-enum-inliner.js +36 -0
  266. package/dist/api/compiler/transformers/declarations-diagnostics.d.ts +52 -0
  267. package/dist/api/compiler/transformers/declarations-diagnostics.js +538 -0
  268. package/dist/api/compiler/transformers/declarations-pseudo.d.ts +160 -0
  269. package/dist/api/compiler/transformers/declarations-pseudo.js +797 -0
  270. package/dist/api/compiler/transformers/declarations-resolver.d.ts +152 -0
  271. package/dist/api/compiler/transformers/declarations-resolver.js +35 -0
  272. package/dist/api/compiler/transformers/declarations-syntactic.d.ts +119 -0
  273. package/dist/api/compiler/transformers/declarations-syntactic.js +1582 -0
  274. package/dist/api/compiler/transformers/declarations-tracker.d.ts +46 -0
  275. package/dist/api/compiler/transformers/declarations-tracker.js +197 -0
  276. package/dist/api/compiler/transformers/declarations.d.ts +175 -0
  277. package/dist/api/compiler/transformers/declarations.js +2380 -0
  278. package/dist/api/compiler/transformers/decorator-metadata.d.ts +54 -0
  279. package/dist/api/compiler/transformers/decorator-metadata.js +554 -0
  280. package/dist/api/compiler/transformers/decorator-utilities.d.ts +38 -0
  281. package/dist/api/compiler/transformers/decorator-utilities.js +238 -0
  282. package/dist/api/compiler/transformers/destructuring.d.ts +25 -0
  283. package/dist/api/compiler/transformers/destructuring.js +626 -0
  284. package/dist/api/compiler/transformers/downlevel.d.ts +6 -0
  285. package/dist/api/compiler/transformers/downlevel.js +45 -0
  286. package/dist/api/compiler/transformers/emit-resolver.d.ts +61 -0
  287. package/dist/api/compiler/transformers/emit-resolver.js +197 -0
  288. package/dist/api/compiler/transformers/es-decorators.d.ts +118 -0
  289. package/dist/api/compiler/transformers/es-decorators.js +1901 -0
  290. package/dist/api/compiler/transformers/exponentiation.d.ts +11 -0
  291. package/dist/api/compiler/transformers/exponentiation.js +76 -0
  292. package/dist/api/compiler/transformers/external-module-info.d.ts +35 -0
  293. package/dist/api/compiler/transformers/external-module-info.js +351 -0
  294. package/dist/api/compiler/transformers/for-await.d.ts +43 -0
  295. package/dist/api/compiler/transformers/for-await.js +469 -0
  296. package/dist/api/compiler/transformers/import-elision.d.ts +16 -0
  297. package/dist/api/compiler/transformers/import-elision.js +124 -0
  298. package/dist/api/compiler/transformers/jsx-entities.d.ts +1 -0
  299. package/dist/api/compiler/transformers/jsx-entities.js +256 -0
  300. package/dist/api/compiler/transformers/jsx.d.ts +71 -0
  301. package/dist/api/compiler/transformers/jsx.js +700 -0
  302. package/dist/api/compiler/transformers/legacy-decorators.d.ts +56 -0
  303. package/dist/api/compiler/transformers/legacy-decorators.js +564 -0
  304. package/dist/api/compiler/transformers/logical-assignment.d.ts +14 -0
  305. package/dist/api/compiler/transformers/logical-assignment.js +62 -0
  306. package/dist/api/compiler/transformers/module-utilities.d.ts +9 -0
  307. package/dist/api/compiler/transformers/module-utilities.js +36 -0
  308. package/dist/api/compiler/transformers/module.d.ts +49 -0
  309. package/dist/api/compiler/transformers/module.js +296 -0
  310. package/dist/api/compiler/transformers/named-evaluation.d.ts +26 -0
  311. package/dist/api/compiler/transformers/named-evaluation.js +266 -0
  312. package/dist/api/compiler/transformers/nullish-coalescing.d.ts +9 -0
  313. package/dist/api/compiler/transformers/nullish-coalescing.js +26 -0
  314. package/dist/api/compiler/transformers/object-rest-spread.d.ts +34 -0
  315. package/dist/api/compiler/transformers/object-rest-spread.js +411 -0
  316. package/dist/api/compiler/transformers/optional-catch.d.ts +9 -0
  317. package/dist/api/compiler/transformers/optional-catch.js +20 -0
  318. package/dist/api/compiler/transformers/optional-chain.d.ts +14 -0
  319. package/dist/api/compiler/transformers/optional-chain.js +188 -0
  320. package/dist/api/compiler/transformers/reference-resolver.d.ts +128 -0
  321. package/dist/api/compiler/transformers/reference-resolver.js +1155 -0
  322. package/dist/api/compiler/transformers/runtime-syntax.d.ts +71 -0
  323. package/dist/api/compiler/transformers/runtime-syntax.js +753 -0
  324. package/dist/api/compiler/transformers/subtree-facts.d.ts +9 -0
  325. package/dist/api/compiler/transformers/subtree-facts.js +203 -0
  326. package/dist/api/compiler/transformers/syntax-facts.d.ts +51 -0
  327. package/dist/api/compiler/transformers/syntax-facts.js +254 -0
  328. package/dist/api/compiler/transformers/tagged-template.d.ts +17 -0
  329. package/dist/api/compiler/transformers/tagged-template.js +148 -0
  330. package/dist/api/compiler/transformers/transformer.d.ts +17 -0
  331. package/dist/api/compiler/transformers/transformer.js +54 -0
  332. package/dist/api/compiler/transformers/type-eraser.d.ts +21 -0
  333. package/dist/api/compiler/transformers/type-eraser.js +346 -0
  334. package/dist/api/compiler/transformers/type-serialization.d.ts +20 -0
  335. package/dist/api/compiler/transformers/type-serialization.js +347 -0
  336. package/dist/api/compiler/transformers/using.d.ts +56 -0
  337. package/dist/api/compiler/transformers/using.js +453 -0
  338. package/dist/api/compiler/transformers/utilities.d.ts +50 -0
  339. package/dist/api/compiler/transformers/utilities.js +347 -0
  340. package/dist/api/compiler/transformers/visitor-base.d.ts +6 -0
  341. package/dist/api/compiler/transformers/visitor-base.js +817 -0
  342. package/dist/api/compiler/transformers/visitor-hooks.d.ts +29 -0
  343. package/dist/api/compiler/transformers/visitor-hooks.js +189 -0
  344. package/dist/api/compiler/tsconfig.d.ts +177 -0
  345. package/dist/api/compiler/tsconfig.js +1311 -0
  346. package/dist/api/compiler/type-printer.d.ts +15 -0
  347. package/dist/api/compiler/type-printer.js +74 -0
  348. package/dist/api/compiler/types.d.ts +87 -0
  349. package/dist/api/compiler/types.js +23 -0
  350. package/dist/api/compiler/unicode-identifiers.d.ts +2 -0
  351. package/dist/api/compiler/unicode-identifiers.js +209 -0
  352. package/dist/api/compiler/unicode-properties.d.ts +8 -0
  353. package/dist/api/compiler/unicode-properties.js +531 -0
  354. package/dist/api/compiler/vfs-match.d.ts +24 -0
  355. package/dist/api/compiler/vfs-match.js +587 -0
  356. package/dist/api/library/ast.d.ts +3 -2
  357. package/dist/api/library/ast.generated.d.ts +127 -139
  358. package/dist/api/library/checker.d.ts +51 -0
  359. package/dist/api/library/checker.js +318 -0
  360. package/dist/api/library/diagnostics.d.ts +13 -0
  361. package/dist/api/library/diagnostics.js +50 -0
  362. package/dist/api/library/disk.d.ts +13 -0
  363. package/dist/api/library/disk.js +66 -0
  364. package/dist/api/library/errors.d.ts +13 -0
  365. package/dist/api/library/errors.js +24 -0
  366. package/dist/api/library/host.d.ts +24 -0
  367. package/dist/api/library/host.js +52 -0
  368. package/dist/api/library/index.d.ts +5 -1
  369. package/dist/api/library/index.js +4 -0
  370. package/dist/api/library/nodes.d.ts +51 -0
  371. package/dist/api/library/nodes.js +196 -0
  372. package/dist/api/library/options.d.ts +144 -0
  373. package/dist/api/library/options.js +308 -0
  374. package/dist/api/library/parse.d.ts +19 -0
  375. package/dist/api/library/parse.js +41 -0
  376. package/dist/api/library/program.d.ts +21 -0
  377. package/dist/api/library/program.js +234 -0
  378. package/dist/api/library/types.d.ts +14 -1
  379. package/package.json +12 -8
  380. package/src/compiler/ast-utilities.ts +548 -0
  381. package/src/compiler/ast.ts +12862 -0
  382. package/src/compiler/astnav.ts +799 -0
  383. package/src/compiler/binder-utilities.ts +1392 -0
  384. package/src/compiler/binder.ts +2703 -0
  385. package/src/compiler/build-info.ts +1197 -0
  386. package/src/compiler/character-codes.ts +323 -0
  387. package/src/compiler/checker-calls.ts +2155 -0
  388. package/src/compiler/checker-classes.ts +706 -0
  389. package/src/compiler/checker-contextual.ts +1457 -0
  390. package/src/compiler/checker-declaration-order.ts +438 -0
  391. package/src/compiler/checker-declarations.ts +1194 -0
  392. package/src/compiler/checker-declared-types.ts +919 -0
  393. package/src/compiler/checker-decorators.ts +694 -0
  394. package/src/compiler/checker-deprecation.ts +359 -0
  395. package/src/compiler/checker-destructuring.ts +805 -0
  396. package/src/compiler/checker-elaboration.ts +477 -0
  397. package/src/compiler/checker-emit-helpers.ts +224 -0
  398. package/src/compiler/checker-emit-resolver.ts +769 -0
  399. package/src/compiler/checker-evaluator.ts +243 -0
  400. package/src/compiler/checker-expressions.ts +1831 -0
  401. package/src/compiler/checker-features.ts +361 -0
  402. package/src/compiler/checker-flow.ts +394 -0
  403. package/src/compiler/checker-functions.ts +1296 -0
  404. package/src/compiler/checker-generated-code.ts +227 -0
  405. package/src/compiler/checker-globals.ts +52 -0
  406. package/src/compiler/checker-grammar.ts +3584 -0
  407. package/src/compiler/checker-heritage.ts +1233 -0
  408. package/src/compiler/checker-inference.ts +2576 -0
  409. package/src/compiler/checker-iteration.ts +1206 -0
  410. package/src/compiler/checker-javascript.ts +502 -0
  411. package/src/compiler/checker-jsdoc.ts +360 -0
  412. package/src/compiler/checker-jsx.ts +1924 -0
  413. package/src/compiler/checker-literals.ts +61 -0
  414. package/src/compiler/checker-members.ts +2436 -0
  415. package/src/compiler/checker-modules.ts +2886 -0
  416. package/src/compiler/checker-narrowing.ts +3230 -0
  417. package/src/compiler/checker-object-literals.ts +575 -0
  418. package/src/compiler/checker-operators.ts +1422 -0
  419. package/src/compiler/checker-overloads.ts +328 -0
  420. package/src/compiler/checker-property-access.ts +906 -0
  421. package/src/compiler/checker-services.ts +1149 -0
  422. package/src/compiler/checker-signatures.ts +1032 -0
  423. package/src/compiler/checker-source-file.ts +732 -0
  424. package/src/compiler/checker-statements.ts +292 -0
  425. package/src/compiler/checker-super.ts +261 -0
  426. package/src/compiler/checker-symbol-types.ts +2107 -0
  427. package/src/compiler/checker-symbols.ts +2150 -0
  428. package/src/compiler/checker-type-factory.ts +2579 -0
  429. package/src/compiler/checker-type-nodes.ts +1033 -0
  430. package/src/compiler/checker-type-operators.ts +2502 -0
  431. package/src/compiler/checker-types.ts +2340 -0
  432. package/src/compiler/checker-unused.ts +642 -0
  433. package/src/compiler/checker-utilities.ts +161 -0
  434. package/src/compiler/checker.ts +1116 -0
  435. package/src/compiler/command-line.ts +436 -0
  436. package/src/compiler/compile-program.ts +439 -0
  437. package/src/compiler/decoder.ts +1209 -0
  438. package/src/compiler/diagnostic-locales.ts +86 -0
  439. package/src/compiler/diagnostic-messages.ts +2349 -0
  440. package/src/compiler/diagnostics.ts +897 -0
  441. package/src/compiler/emitter.ts +434 -0
  442. package/src/compiler/encoder.ts +1945 -0
  443. package/src/compiler/file-include.ts +673 -0
  444. package/src/compiler/file-loader.ts +1528 -0
  445. package/src/compiler/file-system.ts +143 -0
  446. package/src/compiler/flow.ts +89 -0
  447. package/src/compiler/help.ts +473 -0
  448. package/src/compiler/incremental.ts +2784 -0
  449. package/src/compiler/init.ts +141 -0
  450. package/src/compiler/instantiation.ts +894 -0
  451. package/src/compiler/jsdoc.ts +1386 -0
  452. package/src/compiler/link-tables.ts +98 -0
  453. package/src/compiler/locale-data.ts +203 -0
  454. package/src/compiler/locale.ts +307 -0
  455. package/src/compiler/locales/cs-CZ.ts +5 -0
  456. package/src/compiler/locales/de-DE.ts +5 -0
  457. package/src/compiler/locales/es-ES.ts +5 -0
  458. package/src/compiler/locales/fr-FR.ts +5 -0
  459. package/src/compiler/locales/it-IT.ts +5 -0
  460. package/src/compiler/locales/ja-JP.ts +5 -0
  461. package/src/compiler/locales/ko-KR.ts +5 -0
  462. package/src/compiler/locales/pl-PL.ts +5 -0
  463. package/src/compiler/locales/pt-BR.ts +5 -0
  464. package/src/compiler/locales/ru-RU.ts +5 -0
  465. package/src/compiler/locales/tr-TR.ts +5 -0
  466. package/src/compiler/locales/zh-CN.ts +5 -0
  467. package/src/compiler/locales/zh-TW.ts +5 -0
  468. package/src/compiler/module-resolution-types.ts +243 -0
  469. package/src/compiler/module-resolution.ts +2072 -0
  470. package/src/compiler/module-specifiers.ts +1491 -0
  471. package/src/compiler/name-resolver.ts +646 -0
  472. package/src/compiler/node-builder-names.ts +1069 -0
  473. package/src/compiler/node-builder-pseudo.ts +892 -0
  474. package/src/compiler/node-builder-reuse.ts +764 -0
  475. package/src/compiler/node-builder.ts +3425 -0
  476. package/src/compiler/option-declarations.ts +1560 -0
  477. package/src/compiler/options.ts +1576 -0
  478. package/src/compiler/output-paths.ts +334 -0
  479. package/src/compiler/package-json.ts +1083 -0
  480. package/src/compiler/parallel-check.ts +1951 -0
  481. package/src/compiler/parallel-parse.ts +590 -0
  482. package/src/compiler/parse-thread.ts +140 -0
  483. package/src/compiler/parser.ts +7716 -0
  484. package/src/compiler/path.ts +717 -0
  485. package/src/compiler/printer/async-helpers.ts +183 -0
  486. package/src/compiler/printer/auto-generate.ts +27 -0
  487. package/src/compiler/printer/decorator-helpers.ts +218 -0
  488. package/src/compiler/printer/emit-context.ts +679 -0
  489. package/src/compiler/printer/emit-flags.ts +64 -0
  490. package/src/compiler/printer/factory-base.ts +2577 -0
  491. package/src/compiler/printer/factory.ts +764 -0
  492. package/src/compiler/printer/helpers.ts +291 -0
  493. package/src/compiler/printer/name-generator.ts +372 -0
  494. package/src/compiler/printer/printer.ts +5072 -0
  495. package/src/compiler/printer/text-writer.ts +183 -0
  496. package/src/compiler/printer/utilities.ts +884 -0
  497. package/src/compiler/program-checker.ts +592 -0
  498. package/src/compiler/program-utilities.ts +435 -0
  499. package/src/compiler/program.ts +1419 -0
  500. package/src/compiler/pseudo-bigint.ts +62 -0
  501. package/src/compiler/regexp-checker.ts +1142 -0
  502. package/src/compiler/relations.ts +5149 -0
  503. package/src/compiler/reparser.ts +1566 -0
  504. package/src/compiler/scanner.ts +2951 -0
  505. package/src/compiler/show-config.ts +239 -0
  506. package/src/compiler/side-state.ts +125 -0
  507. package/src/compiler/sourcemap.ts +366 -0
  508. package/src/compiler/spelling.ts +122 -0
  509. package/src/compiler/symbol-accessibility.ts +1071 -0
  510. package/src/compiler/symbol.ts +439 -0
  511. package/src/compiler/symlinks.ts +137 -0
  512. package/src/compiler/syntax-kind.ts +391 -0
  513. package/src/compiler/thread-entry.ts +191 -0
  514. package/src/compiler/timeline.ts +53 -0
  515. package/src/compiler/transformers/alias-references.ts +757 -0
  516. package/src/compiler/transformers/async-utilities.ts +335 -0
  517. package/src/compiler/transformers/async.ts +838 -0
  518. package/src/compiler/transformers/class-fields.ts +2967 -0
  519. package/src/compiler/transformers/class-utilities.ts +324 -0
  520. package/src/compiler/transformers/commonjs-module.ts +1621 -0
  521. package/src/compiler/transformers/const-enum-inliner.ts +50 -0
  522. package/src/compiler/transformers/declarations-diagnostics.ts +832 -0
  523. package/src/compiler/transformers/declarations-pseudo.ts +966 -0
  524. package/src/compiler/transformers/declarations-resolver.ts +249 -0
  525. package/src/compiler/transformers/declarations-syntactic.ts +1859 -0
  526. package/src/compiler/transformers/declarations-tracker.ts +269 -0
  527. package/src/compiler/transformers/declarations.ts +3120 -0
  528. package/src/compiler/transformers/decorator-metadata.ts +697 -0
  529. package/src/compiler/transformers/decorator-utilities.ts +283 -0
  530. package/src/compiler/transformers/destructuring.ts +708 -0
  531. package/src/compiler/transformers/downlevel.ts +50 -0
  532. package/src/compiler/transformers/emit-resolver.ts +258 -0
  533. package/src/compiler/transformers/es-decorators.ts +2682 -0
  534. package/src/compiler/transformers/exponentiation.ts +80 -0
  535. package/src/compiler/transformers/external-module-info.ts +412 -0
  536. package/src/compiler/transformers/for-await.ts +687 -0
  537. package/src/compiler/transformers/import-elision.ts +152 -0
  538. package/src/compiler/transformers/jsx-entities.ts +256 -0
  539. package/src/compiler/transformers/jsx.ts +824 -0
  540. package/src/compiler/transformers/legacy-decorators.ts +726 -0
  541. package/src/compiler/transformers/logical-assignment.ts +75 -0
  542. package/src/compiler/transformers/module-utilities.ts +42 -0
  543. package/src/compiler/transformers/module.ts +474 -0
  544. package/src/compiler/transformers/named-evaluation.ts +389 -0
  545. package/src/compiler/transformers/nullish-coalescing.ts +35 -0
  546. package/src/compiler/transformers/object-rest-spread.ts +577 -0
  547. package/src/compiler/transformers/optional-catch.ts +29 -0
  548. package/src/compiler/transformers/optional-chain.ts +246 -0
  549. package/src/compiler/transformers/reference-resolver.ts +1201 -0
  550. package/src/compiler/transformers/runtime-syntax.ts +942 -0
  551. package/src/compiler/transformers/subtree-facts.ts +245 -0
  552. package/src/compiler/transformers/syntax-facts.ts +353 -0
  553. package/src/compiler/transformers/tagged-template.ts +167 -0
  554. package/src/compiler/transformers/transformer.ts +56 -0
  555. package/src/compiler/transformers/type-eraser.ts +520 -0
  556. package/src/compiler/transformers/type-serialization.ts +374 -0
  557. package/src/compiler/transformers/using.ts +613 -0
  558. package/src/compiler/transformers/utilities.ts +419 -0
  559. package/src/compiler/transformers/visitor-base.ts +1601 -0
  560. package/src/compiler/transformers/visitor-hooks.ts +252 -0
  561. package/src/compiler/tsc-build.ts +1418 -0
  562. package/src/compiler/tsc-cli.ts +666 -0
  563. package/src/compiler/tsc-compile.ts +437 -0
  564. package/src/compiler/tsc-watch.ts +854 -0
  565. package/src/compiler/tsconfig.ts +1574 -0
  566. package/src/compiler/type-printer.ts +110 -0
  567. package/src/compiler/types.ts +115 -0
  568. package/src/compiler/unicode-identifiers.ts +212 -0
  569. package/src/compiler/unicode-properties.ts +537 -0
  570. package/src/compiler/vfs-match.ts +597 -0
  571. package/src/compiler/xxh3.ts +650 -0
  572. package/src/library/ast.generated.ts +141 -167
  573. package/src/library/ast.ts +4 -1
  574. package/src/library/checker.ts +384 -0
  575. package/src/library/diagnostics.ts +72 -0
  576. package/src/library/disk.ts +73 -0
  577. package/src/library/errors.ts +26 -0
  578. package/src/library/host.ts +63 -0
  579. package/src/library/index.ts +21 -0
  580. package/src/library/nodes.ts +232 -0
  581. package/src/library/options.ts +449 -0
  582. package/src/library/parse.ts +63 -0
  583. package/src/library/program.ts +293 -0
  584. package/src/library/types.ts +14 -1
@@ -0,0 +1,2645 @@
1
+ // Building type nodes from types, like tsgo's node builder: `typeToTypeNode` and
2
+ // `signatureToSignatureDeclaration` for the API, and the serializers declaration emit uses.
3
+ //
4
+ // A `NodeBuilder` is one serialization: its fields are tsgo's node builder context. Naming
5
+ // symbols is in node-builder-names.ts and reusing existing type nodes in node-builder-reuse.ts.
6
+ import { sideOf } from './side-state.js';
7
+ import { utf8Length } from './character-codes.js';
8
+ import { ArrayTypeNode, ArrowFunction, BinaryExpression, ElementAccessExpression, ImportTypeNode, NodeVisitor, getExpression, getParameters, getPostfixToken, getQuestionToken, getSymbol, BigIntLiteral, BindingElement, BindingPattern, Block, CallSignatureDeclaration, ConditionalTypeNode, ConstructSignatureDeclaration, ConstructorDeclaration, ConstructorTypeNode, FunctionDeclaration, FunctionExpression, FunctionTypeNode, GetAccessorDeclaration, Identifier, IndexSignatureDeclaration, IndexedAccessTypeNode, InferTypeNode, IntersectionTypeNode, KeywordTypeNode, LiteralTypeNode, MappedTypeNode, MethodDeclaration, MethodSignatureDeclaration, NamedTupleMember, NotEmittedTypeElement, OptionalTypeNode, ParameterDeclaration, PrefixUnaryExpression, PropertySignatureDeclaration, RestTypeNode, SetAccessorDeclaration, TemplateHead, TemplateLiteralTypeNode, TemplateLiteralTypeSpan, TemplateMiddle, TemplateTail, ThisTypeNode, TupleTypeNode, TypeLiteralNode, TypeOperatorNode, TypeParameterDeclaration, TypePredicateNode, TypeQueryNode, TypeReferenceNode, UnionTypeNode, getModifiers, getName, getNodeId, getText, getType, } from './ast.js';
9
+ import { isModifierKind, modifierToFlag } from './ast-utilities.js';
10
+ import { declarationNameToString, getCombinedModifierFlags, getDeclarationOfKind, getImmediatelyInvokedFunctionExpression, getNameOfDeclaration, getSourceFileOfNode, getThisContainer, hasSyntacticModifier, isClassLike, isEntityNameExpression, isStatic, symbolName, } from './binder-utilities.js';
11
+ import { getEffectiveCallArguments } from './checker-calls.js';
12
+ import { getIntendedTypeFromJSDocTypeReference } from './checker-jsdoc.js';
13
+ import { maxSerializationLevel } from './checker.js';
14
+ import { getConstraintDeclaration, getConstraintOfTypeParameter, getDeclaredTypeOfClassOrInterface, getDeclaredTypeOfSymbol, getDefaultFromTypeParameter, getLocalTypeParametersOfClassOrInterfaceOrTypeAlias, getMinTypeArgumentCount, } from './checker-declared-types.js';
15
+ import { getTypeWithFacts } from './checker-flow.js';
16
+ import { getInferredTypeParameterConstraint } from './checker-inference.js';
17
+ import { getGlobalIterableIteratorType, getGlobalIterableType, isReferenceToType } from './checker-iteration.js';
18
+ import { getDeclarationModifierFlagsFromSymbol, getPropertiesOfObjectType, getReducedType, getSignaturesOfType, getTargetSymbol, membersHolder, resolveStructuredTypeMembers, } from './checker-members.js';
19
+ import { getOrCreateTypeFromSignature, getReturnTypeOfSignature, getSignatureFromDeclaration, getTypeParametersFromDeclaration, getTypePredicateOfSignature, instantiateTypePredicate, } from './checker-signatures.js';
20
+ import { getBaseTypeVariableOfClass, getNonMissingTypeOfSymbol, getOptionalType, getTypeOfSymbol, getWriteTypeOfSymbol, isReadonlySymbol, removeMissingType, } from './checker-symbol-types.js';
21
+ import { getFirstIdentifier, getGlobalTypeAliasSymbol, getMergedSymbol, getParentOfSymbol, getSymbolOfDeclaration, resolveName, } from './checker-symbols.js';
22
+ import { createArrayType, filterType, getIntersectionType, getTypeArguments, getTypeReferenceArity, getWidenedLiteralType, isErrorType, isTupleType, inDeclarationOrder, newAnonymousType, } from './checker-type-factory.js';
23
+ import { getTypeFromTypeNode } from './checker-type-nodes.js';
24
+ import { getConstraintTypeFromMappedType, getFalseTypeFromConditionalType, getHomomorphicTypeVariable, getMappedTypeModifiers, getModifiersTypeFromMappedType, getNameTypeFromMappedType, getTemplateTypeFromMappedType, getTrueTypeFromConditionalType, getTypeParameterFromMappedType, isGenericMappedType, isMappedTypeWithKeyofConstraintDeclaration, isNoInferType, } from './checker-type-operators.js';
25
+ import { newTypeMapper, prependTypeMapping, } from './checker-types.js';
26
+ import { hasLateBindableIndexSignature, hasLateBindableName, isLateBindableName, isLateBoundName, } from './checker-utilities.js';
27
+ import { instantiateSignature, instantiateType } from './instantiation.js';
28
+ import { EmitContext } from './printer/emit-context.js';
29
+ import { Printer, PrinterOptions } from './printer/printer.js';
30
+ import { TextWriter } from './printer/text-writer.js';
31
+ import { isTypeIdenticalTo } from './relations.js';
32
+ import { isIdentifierText } from './scanner.js';
33
+ import { getSymbolId } from './symbol.js';
34
+ import { SymbolAccessibilityResult, SymbolTracker, accessible, } from './transformers/declarations-resolver.js';
35
+ import { getMeaningOfEntityNameReference } from './transformers/declarations-syntactic.js';
36
+ import { formatUnionTypes, symbolToString } from './type-printer.js';
37
+ import { hasVisibleDeclarations, isSymbolAccessible, isTypeSymbolAccessible, isValueSymbolAccessible, } from './symbol-accessibility.js';
38
+ import { getPropertyNameNodeForSymbol, symbolToEntityNameNode, symbolToExpression, symbolToName, symbolToTypeNode, appendReferenceToType, } from './node-builder-names.js';
39
+ import { tryReuseExistingNode } from './node-builder-reuse.js';
40
+ import { containsNonMissingUndefinedType, hasInferredTypeKind, hasQuestionToken, isAccessorKind, pseudoReturnTypeMatchesPredicate, pseudoTypeEquivalentToType, pseudoTypeToNodeWithCheckerFallback, pseudoTypeToType, newPseudoChecker, requiresAddingImplicitUndefinedForDeclaration, } from './node-builder-pseudo.js';
41
+ import { InferredType, UnionType as PseudoUnionType, couldAlreadyReferToUndefined, undefinedType as pseudoUndefinedType, } from './transformers/declarations-pseudo.js';
42
+ const defaultMaximumTruncationLength = 160;
43
+ const noTruncationMaximumTruncationLength = 1_000_000;
44
+ const maxReverseMappedNestingInspectionDepth = 3;
45
+ /** A symbol the builder named, kept with a cached result so it can be tracked again. */
46
+ export class TrackedSymbol {
47
+ symbol;
48
+ enclosingDeclaration;
49
+ meaning;
50
+ constructor(symbol, enclosingDeclaration, meaning) {
51
+ this.symbol = symbol;
52
+ this.enclosingDeclaration = enclosingDeclaration;
53
+ this.meaning = meaning;
54
+ }
55
+ }
56
+ class SerializedTypeEntry {
57
+ node;
58
+ truncating;
59
+ addedLength;
60
+ trackedSymbols;
61
+ constructor(node, truncating, addedLength, trackedSymbols) {
62
+ this.node = node;
63
+ this.truncating = truncating;
64
+ this.addedLength = addedLength;
65
+ this.trackedSymbols = trackedSymbols;
66
+ }
67
+ }
68
+ /**
69
+ * What a builder's tracker records for it. The builder and its tracker share it, so the tracker doesn't refer to
70
+ * the builder: a builder and a tracker that pointed at each other made every builder a reference cycle.
71
+ */
72
+ export class BuilderReports {
73
+ reportedDiagnostic = false;
74
+ trackedSymbols = [];
75
+ }
76
+ /**
77
+ * The tracker a builder reports to: records the symbols it names and that a diagnostic was
78
+ * reported (`BuilderReports`), and forwards to the caller's tracker, if any.
79
+ */
80
+ export class BuilderTracker extends SymbolTracker {
81
+ reports;
82
+ inner;
83
+ constructor(reports, inner) {
84
+ super();
85
+ this.reports = reports;
86
+ // Don't stack builder trackers.
87
+ let unwrapped = inner;
88
+ while (unwrapped instanceof BuilderTracker)
89
+ unwrapped = unwrapped.inner;
90
+ this.inner = unwrapped;
91
+ }
92
+ trackSymbol(symbol, enclosingDeclaration, meaning) {
93
+ if (this.inner !== undefined && this.inner.trackSymbol(symbol, enclosingDeclaration, meaning)) {
94
+ this.reports.reportedDiagnostic = true;
95
+ return true;
96
+ }
97
+ // Type parameters don't need late painted statements.
98
+ if ((symbol.flags & 262144 /* SymbolFlags.TypeParameter */) === 0)
99
+ this.reports.trackedSymbols.push(new TrackedSymbol(symbol, enclosingDeclaration, meaning));
100
+ return false;
101
+ }
102
+ reportInferenceFallback(node) {
103
+ return this.inner !== undefined && this.inner.reportInferenceFallback(node);
104
+ }
105
+ reportCyclicStructureError() {
106
+ this.reports.reportedDiagnostic = true;
107
+ return this.inner !== undefined && this.inner.reportCyclicStructureError();
108
+ }
109
+ reportInaccessibleThisError() {
110
+ this.reports.reportedDiagnostic = true;
111
+ return this.inner !== undefined && this.inner.reportInaccessibleThisError();
112
+ }
113
+ reportInaccessibleUniqueSymbolError() {
114
+ this.reports.reportedDiagnostic = true;
115
+ return this.inner !== undefined && this.inner.reportInaccessibleUniqueSymbolError();
116
+ }
117
+ reportLikelyUnsafeImportRequiredError(specifier, symbolName) {
118
+ this.reports.reportedDiagnostic = true;
119
+ return this.inner !== undefined && this.inner.reportLikelyUnsafeImportRequiredError(specifier, symbolName);
120
+ }
121
+ reportNonSerializableProperty(propertyName) {
122
+ this.reports.reportedDiagnostic = true;
123
+ return this.inner !== undefined && this.inner.reportNonSerializableProperty(propertyName);
124
+ }
125
+ reportPrivateInBaseOfClassExpression(propertyName) {
126
+ this.reports.reportedDiagnostic = true;
127
+ return this.inner !== undefined && this.inner.reportPrivateInBaseOfClassExpression(propertyName);
128
+ }
129
+ reportTruncationError() {
130
+ this.reports.reportedDiagnostic = true;
131
+ return this.inner !== undefined && this.inner.reportTruncationError();
132
+ }
133
+ reportNonlocalAugmentation(containingFile, parentSymbol, augmentingSymbol) {
134
+ this.reports.reportedDiagnostic = true;
135
+ return (this.inner !== undefined && this.inner.reportNonlocalAugmentation(containingFile, parentSymbol, augmentingSymbol));
136
+ }
137
+ pushErrorFallbackNode(node) {
138
+ return this.inner !== undefined && this.inner.pushErrorFallbackNode(node);
139
+ }
140
+ popErrorFallbackNode() {
141
+ return this.inner !== undefined && this.inner.popErrorFallbackNode();
142
+ }
143
+ }
144
+ /** What `signatureToSignatureDeclaration` may add to the declaration. */
145
+ class SignatureDeclarationOptions {
146
+ modifiers;
147
+ name;
148
+ questionToken;
149
+ constructor(modifiers, name, questionToken) {
150
+ this.modifiers = modifiers;
151
+ this.name = name;
152
+ this.questionToken = questionToken;
153
+ }
154
+ }
155
+ export function classifyPropertyName(name, stringNamed, isMethod) {
156
+ if (isMethod && name === 'new')
157
+ return 2 /* PropertyNameKind.StringLiteral */;
158
+ if (isIdentifierText(name))
159
+ return 0 /* PropertyNameKind.Identifier */;
160
+ return !stringNamed && isNumericLiteralName(name) && Number(name) >= 0
161
+ ? 1 /* PropertyNameKind.NumericLiteral */
162
+ : 2 /* PropertyNameKind.StringLiteral */;
163
+ }
164
+ export function isNumericLiteralName(name) {
165
+ return String(Number(name)) === name;
166
+ }
167
+ /** One serialization of types to nodes. */
168
+ export class NodeBuilder {
169
+ c;
170
+ context;
171
+ factory;
172
+ tracker;
173
+ flags;
174
+ internalFlags;
175
+ approximateLength = 0;
176
+ encounteredError = false;
177
+ truncating = false;
178
+ enclosingDeclaration;
179
+ enclosingFile;
180
+ inferTypeParameters = [];
181
+ visitedTypesStore = undefined;
182
+ symbolDepthStore = undefined;
183
+ /** What its tracker records (`reportedDiagnostic`, `trackedSymbols`). */
184
+ reports = new BuilderReports();
185
+ mapper = undefined;
186
+ reverseMappedStackStore = undefined;
187
+ enclosingSymbolTypesStore = undefined;
188
+ suppressReportInferenceFallback = false;
189
+ remappedSymbolReferencesStore = undefined;
190
+ // Per signature scope; undefined while empty.
191
+ typeParameterNames = undefined;
192
+ typeParameterNamesByText = undefined;
193
+ typeParameterNamesByTextNextNameCount = undefined;
194
+ typeParameterSymbolList = undefined;
195
+ serializedTypesStore = undefined;
196
+ fakeScopesStore = undefined;
197
+ /**
198
+ * Declaration emit's pseudochecker: with it, types of declarations are written from what the
199
+ * source wrote where that denotes the checker's type.
200
+ */
201
+ pseudo = undefined;
202
+ /** Set for declaration emit, which writes unions in an order that doesn't depend on the checker's history. */
203
+ declarationOrder = false;
204
+ constructor(c, enclosingDeclaration, flags, internalFlags, tracker, context = undefined) {
205
+ this.c = c;
206
+ this.context = context ?? new EmitContext();
207
+ this.factory = this.context.factory;
208
+ this.flags = flags;
209
+ this.internalFlags = internalFlags;
210
+ this.enclosingDeclaration = enclosingDeclaration;
211
+ this.enclosingFile = enclosingDeclaration === undefined ? undefined : getSourceFileOfNode(enclosingDeclaration);
212
+ this.tracker = new BuilderTracker(this.reports, tracker);
213
+ }
214
+ get reportedDiagnostic() {
215
+ return this.reports.reportedDiagnostic;
216
+ }
217
+ set reportedDiagnostic(value) {
218
+ this.reports.reportedDiagnostic = value;
219
+ }
220
+ get trackedSymbols() {
221
+ return this.reports.trackedSymbols;
222
+ }
223
+ set trackedSymbols(value) {
224
+ this.reports.trackedSymbols = value;
225
+ }
226
+ // Created when first used: most types a builder writes need none of these.
227
+ get visitedTypes() {
228
+ return (this.visitedTypesStore ??= new Set());
229
+ }
230
+ /** Nesting depth of each symbol, node or constructor being written. */
231
+ get symbolDepth() {
232
+ return (this.symbolDepthStore ??= new Map());
233
+ }
234
+ get reverseMappedStack() {
235
+ return (this.reverseMappedStackStore ??= []);
236
+ }
237
+ /** Types of symbols being written, which may differ from their declared types. */
238
+ get enclosingSymbolTypes() {
239
+ return (this.enclosingSymbolTypesStore ??= new Map());
240
+ }
241
+ get remappedSymbolReferences() {
242
+ return (this.remappedSymbolReferencesStore ??= new Map());
243
+ }
244
+ /** Serialized types by enclosing declaration id, then type, flags and internal flags. */
245
+ get serializedTypes() {
246
+ return (this.serializedTypesStore ??= new Map());
247
+ }
248
+ /** The kind of fake scope a block stands for: `params` or `typeParams`. */
249
+ get fakeScopes() {
250
+ return (this.fakeScopesStore ??= new Map());
251
+ }
252
+ /** `result`, or undefined if serialization failed. */
253
+ finish(result) {
254
+ if (this.truncating && (this.flags & 1 /* NodeBuilderFlags.NoTruncation */) !== 0)
255
+ this.tracker.reportTruncationError();
256
+ return this.encounteredError ? undefined : result;
257
+ }
258
+ /** Reports a symbol the builder names; without a location it's only recorded. */
259
+ trackSymbol(symbol, enclosingDeclaration, meaning) {
260
+ if (enclosingDeclaration !== undefined)
261
+ this.tracker.trackSymbol(symbol, enclosingDeclaration, meaning);
262
+ else if ((symbol.flags & 262144 /* SymbolFlags.TypeParameter */) === 0)
263
+ this.trackedSymbols.push(new TrackedSymbol(symbol, enclosingDeclaration, meaning));
264
+ }
265
+ checkTruncationLength() {
266
+ if (this.truncating)
267
+ return true;
268
+ const maxLength = (this.flags & 1 /* NodeBuilderFlags.NoTruncation */) !== 0
269
+ ? noTruncationMaximumTruncationLength
270
+ : defaultMaximumTruncationLength;
271
+ this.truncating = this.approximateLength > maxLength;
272
+ return this.truncating;
273
+ }
274
+ // ---- Node creation
275
+ created(node) {
276
+ return this.factory.created(node);
277
+ }
278
+ list(nodes) {
279
+ return this.factory.createNodeList(nodes);
280
+ }
281
+ modifierList(nodes) {
282
+ return nodes.length === 0 ? undefined : this.factory.createModifierList(nodes);
283
+ }
284
+ keyword(kind) {
285
+ return this.created(new KeywordTypeNode(kind));
286
+ }
287
+ token(kind) {
288
+ return this.factory.createToken(kind);
289
+ }
290
+ identifier(text) {
291
+ return this.factory.createIdentifier(text);
292
+ }
293
+ stringLiteral(text, isSingleQuote) {
294
+ const flags = isSingleQuote || (this.flags & 268435456 /* NodeBuilderFlags.UseSingleQuotesForStringLiteralType */) !== 0
295
+ ? 65536 /* TokenFlags.SingleQuote */
296
+ : 0 /* TokenFlags.None */;
297
+ return this.factory.createStringLiteral(text, flags);
298
+ }
299
+ typeReference(name, typeArguments) {
300
+ return this.created(new TypeReferenceNode(name, typeArguments));
301
+ }
302
+ /** `...`, or `any /*elided*\/` without truncation. */
303
+ createElidedInformationPlaceholder() {
304
+ this.approximateLength += 3;
305
+ if ((this.flags & 1 /* NodeBuilderFlags.NoTruncation */) === 0)
306
+ return this.typeReference(this.identifier('...'), undefined);
307
+ return this.context.addSyntheticLeadingComment(this.keyword(132 /* SyntaxKind.AnyKeyword */), 3 /* SyntaxKind.MultiLineCommentTrivia */, 'elided', false);
308
+ }
309
+ // ---- Scopes
310
+ /** Sets the type `symbol` is written with until the returned function restores it. */
311
+ addSymbolTypeToContext(symbol, t) {
312
+ const id = getSymbolId(symbol);
313
+ const old = this.enclosingSymbolTypes.get(id);
314
+ this.enclosingSymbolTypes.set(id, t);
315
+ return () => {
316
+ if (old !== undefined)
317
+ this.enclosingSymbolTypes.set(id, old);
318
+ else
319
+ this.enclosingSymbolTypes.delete(id);
320
+ };
321
+ }
322
+ /** Enters the scope of a signature, returning its exit; `expandedParameters` holds its parameters. */
323
+ enterSignatureScope(signature) {
324
+ const expandedParams = getExpandedParameters(this.c, signature, true)[0];
325
+ this.expandedParameters = expandedParams;
326
+ return this.enterNewScope(signature.declaration, expandedParams, signature.typeParameters, signature.parameters, signature.mapper);
327
+ }
328
+ /** The parameters of the signature scope entered last. */
329
+ expandedParameters = [];
330
+ /**
331
+ * Enters a scope introducing parameters and type parameters. Names generated within it don't
332
+ * consume names outside it. The enclosing declaration gets a fake scope making the parameters
333
+ * visible, so names they shadow are qualified; it's shared along a chain of scopes.
334
+ */
335
+ enterNewScope(declaration, expandedParams, typeParameters, originalParameters, mapper) {
336
+ const savedNames = this.typeParameterNames;
337
+ const savedNamesByText = this.typeParameterNamesByText;
338
+ const savedNextNameCount = this.typeParameterNamesByTextNextNameCount;
339
+ const savedSymbolList = this.typeParameterSymbolList;
340
+ // The scope starts from the enclosing one's names, copied where there are any.
341
+ this.typeParameterNames = savedNames === undefined ? undefined : new Map(savedNames);
342
+ this.typeParameterNamesByText = savedNamesByText === undefined ? undefined : new Set(savedNamesByText);
343
+ this.typeParameterNamesByTextNextNameCount =
344
+ savedNextNameCount === undefined ? undefined : new Map(savedNextNameCount);
345
+ this.typeParameterSymbolList = savedSymbolList === undefined ? undefined : new Set(savedSymbolList);
346
+ const oldEnclosingDeclaration = this.enclosingDeclaration;
347
+ const oldMapper = this.mapper;
348
+ if (mapper !== undefined)
349
+ this.mapper = mapper;
350
+ let cleanupParams = undefined;
351
+ let cleanupTypeParams = undefined;
352
+ if (this.enclosingDeclaration !== undefined && declaration !== undefined) {
353
+ if (expandedParams !== undefined && expandedParams.length > 0) {
354
+ const table = new Map();
355
+ for (let i = 0; i < expandedParams.length; i++) {
356
+ const param = expandedParams[i];
357
+ const originalParam = originalParameters !== undefined && i < originalParameters.length ? originalParameters[i] : undefined;
358
+ if (originalParameters !== undefined && originalParam !== param) {
359
+ // An expanded parameter can't be named; the original can.
360
+ if (originalParam !== undefined)
361
+ table.set(originalParam.name, originalParam);
362
+ }
363
+ else if (!this.addBindingPatternParameters(param, table))
364
+ table.set(param.name, param);
365
+ }
366
+ cleanupParams = this.pushFakeScope('params', table);
367
+ }
368
+ if ((this.flags & 4 /* NodeBuilderFlags.GenerateNamesForShadowedTypeParams */) !== 0 &&
369
+ typeParameters !== undefined &&
370
+ typeParameters.length > 0) {
371
+ const table = new Map();
372
+ for (const typeParameter of typeParameters)
373
+ table.set(this.typeParameterToName(typeParameter).text, typeParameter.symbol);
374
+ cleanupTypeParams = this.pushFakeScope('typeParams', table);
375
+ }
376
+ }
377
+ return () => {
378
+ if (cleanupParams !== undefined)
379
+ cleanupParams();
380
+ if (cleanupTypeParams !== undefined)
381
+ cleanupTypeParams();
382
+ this.typeParameterNames = savedNames;
383
+ this.typeParameterNamesByText = savedNamesByText;
384
+ this.typeParameterNamesByTextNextNameCount = savedNextNameCount;
385
+ this.typeParameterSymbolList = savedSymbolList;
386
+ this.enclosingDeclaration = oldEnclosingDeclaration;
387
+ this.mapper = oldMapper;
388
+ };
389
+ }
390
+ /** Adds the names bound by a destructured parameter; false if `param` isn't one. */
391
+ addBindingPatternParameters(param, table) {
392
+ for (const d of param.declarations) {
393
+ if (d.kind !== 170 /* SyntaxKind.Parameter */)
394
+ continue;
395
+ const name = asBindingPattern(getName(d));
396
+ if (name !== undefined) {
397
+ this.addBindingPattern(name, table);
398
+ return true;
399
+ }
400
+ }
401
+ return false;
402
+ }
403
+ addBindingPattern(pattern, table) {
404
+ // Only the first element is visited, as tsgo does.
405
+ for (const e of pattern.elements.nodes) {
406
+ if (!(e instanceof BindingElement))
407
+ return;
408
+ const name = asBindingPattern(e.name);
409
+ if (name !== undefined) {
410
+ this.addBindingPattern(name, table);
411
+ return;
412
+ }
413
+ const symbol = getSymbolOfDeclaration(this.c, e);
414
+ if (symbol !== undefined)
415
+ table.set(symbol.name, symbol);
416
+ return;
417
+ }
418
+ }
419
+ /** Adds `names` to the fake scope of `kind` at the enclosing declaration, creating it if needed. */
420
+ pushFakeScope(kind, names) {
421
+ const enclosing = this.enclosingDeclaration;
422
+ let existing = undefined;
423
+ if (this.fakeScopes.get(enclosing) === kind)
424
+ existing = enclosing;
425
+ else if (enclosing.parent !== undefined && this.fakeScopes.get(enclosing.parent) === kind)
426
+ existing = enclosing.parent;
427
+ if (existing === undefined) {
428
+ const fakeScope = this.created(new Block(this.list([]), false));
429
+ fakeScope.locals = names;
430
+ fakeScope.parent = enclosing;
431
+ this.fakeScopes.set(fakeScope, kind);
432
+ this.enclosingDeclaration = fakeScope;
433
+ return undefined;
434
+ }
435
+ const locals = existing.locals;
436
+ const added = [];
437
+ const replaced = new Map();
438
+ for (const [name, symbol] of names) {
439
+ const old = locals.get(name);
440
+ if (old === undefined)
441
+ added.push(name);
442
+ else
443
+ replaced.set(name, old);
444
+ locals.set(name, symbol);
445
+ }
446
+ return () => {
447
+ for (const name of added)
448
+ locals.delete(name);
449
+ for (const [name, symbol] of replaced)
450
+ locals.set(name, symbol);
451
+ };
452
+ }
453
+ /** The enclosing declaration without fake scopes. */
454
+ getEnclosingDeclarationIgnoringFakeScope() {
455
+ let enclosing = this.enclosingDeclaration;
456
+ while (enclosing !== undefined && this.fakeScopes.has(enclosing))
457
+ enclosing = enclosing.parent;
458
+ return enclosing;
459
+ }
460
+ // ---- Type lists
461
+ elidedCount(count, noTruncation) {
462
+ if (noTruncation)
463
+ return this.context.addSyntheticLeadingComment(this.keyword(132 /* SyntaxKind.AnyKeyword */), 3 /* SyntaxKind.MultiLineCommentTrivia */, '... ' + count + ' more elided ...', false);
464
+ return this.typeReference(this.identifier('... ' + count + ' more ...'), undefined);
465
+ }
466
+ /** Type nodes of `list`; a bare list (union or intersection members) truncates in the middle. */
467
+ mapToTypeNodes(list, isBareList) {
468
+ if (list.length === 0)
469
+ return undefined;
470
+ const noTruncation = (this.flags & 1 /* NodeBuilderFlags.NoTruncation */) !== 0;
471
+ if (this.checkTruncationLength()) {
472
+ if (!isBareList) {
473
+ const node = noTruncation
474
+ ? this.context.addSyntheticLeadingComment(this.keyword(132 /* SyntaxKind.AnyKeyword */), 3 /* SyntaxKind.MultiLineCommentTrivia */, 'elided', false)
475
+ : this.typeReference(this.identifier('...'), undefined);
476
+ return this.list([node]);
477
+ }
478
+ if (list.length > 2) {
479
+ const nodes = [];
480
+ const first = this.typeToTypeNode(list[0]);
481
+ if (first !== undefined)
482
+ nodes.push(first);
483
+ nodes.push(this.elidedCount(list.length - 2, noTruncation));
484
+ const last = this.typeToTypeNode(list[list.length - 1]);
485
+ if (last !== undefined)
486
+ nodes.push(last);
487
+ return this.list(nodes);
488
+ }
489
+ }
490
+ const mayHaveNameCollisions = (this.flags & 64 /* NodeBuilderFlags.UseFullyQualifiedType */) === 0;
491
+ // Single-identifier references: indexes into `seenTypes`/`seenIndexes` by name.
492
+ const seenNames = new Map();
493
+ const seenTypes = [];
494
+ const seenIndexes = [];
495
+ const result = [];
496
+ for (let i = 0; i < list.length; i++) {
497
+ const t = list[i];
498
+ const displayIndex = i + 1;
499
+ if (this.checkTruncationLength() && displayIndex + 2 < list.length - 1) {
500
+ result.push(this.elidedCount(list.length - displayIndex, noTruncation));
501
+ const last = this.typeToTypeNode(list[list.length - 1]);
502
+ if (last !== undefined)
503
+ result.push(last);
504
+ break;
505
+ }
506
+ this.approximateLength += 2;
507
+ const typeNode = this.typeToTypeNode(t);
508
+ if (typeNode === undefined)
509
+ continue;
510
+ result.push(typeNode);
511
+ if (mayHaveNameCollisions && typeNode instanceof TypeReferenceNode && typeNode.typeName instanceof Identifier) {
512
+ const name = typeNode.typeName.text;
513
+ let indexes = seenNames.get(name);
514
+ if (indexes === undefined) {
515
+ indexes = [];
516
+ seenNames.set(name, indexes);
517
+ }
518
+ indexes.push(seenTypes.length);
519
+ seenTypes.push(t);
520
+ seenIndexes.push(result.length - 1);
521
+ }
522
+ }
523
+ if (mayHaveNameCollisions) {
524
+ // References by one name to different types are written qualified, so `[Foo, Foo]`
525
+ // doesn't hide that they come from different namespaces.
526
+ const savedFlags = this.flags;
527
+ this.flags |= 64 /* NodeBuilderFlags.UseFullyQualifiedType */;
528
+ for (const indexes of seenNames.values()) {
529
+ let homogeneous = true;
530
+ for (let k = 1; k < indexes.length; k++)
531
+ if (!typesAreSameReference(seenTypes[indexes[0]], seenTypes[indexes[k]]))
532
+ homogeneous = false;
533
+ if (homogeneous)
534
+ continue;
535
+ for (const k of indexes) {
536
+ const node = this.typeToTypeNode(seenTypes[k]);
537
+ if (node !== undefined)
538
+ result[seenIndexes[k]] = node;
539
+ }
540
+ }
541
+ this.flags = savedFlags;
542
+ }
543
+ return this.list(result);
544
+ }
545
+ // ---- Types
546
+ typeToTypeNode(type) {
547
+ const c = this.c;
548
+ const inTypeAlias = this.flags & 8388608 /* NodeBuilderFlags.InTypeAlias */;
549
+ this.flags &= ~8388608 /* NodeBuilderFlags.InTypeAlias */;
550
+ if (type === undefined) {
551
+ if ((this.flags & 262144 /* NodeBuilderFlags.AllowEmptyUnionOrIntersection */) === 0) {
552
+ this.encounteredError = true;
553
+ return undefined;
554
+ }
555
+ this.approximateLength += 3;
556
+ return this.keyword(132 /* SyntaxKind.AnyKeyword */);
557
+ }
558
+ let t = type;
559
+ if ((this.flags & 536870912 /* NodeBuilderFlags.NoTypeReduction */) === 0)
560
+ t = getReducedType(c, t);
561
+ const flags = t.flags;
562
+ if ((flags & 1 /* TypeFlags.Any */) !== 0) {
563
+ if (t.alias !== undefined)
564
+ return this.typeReference(symbolToEntityNameNode(this, t.alias.symbol), this.mapToTypeNodes(t.alias.typeArguments, false));
565
+ if (t === c.unresolvedType)
566
+ return this.context.addSyntheticLeadingComment(this.keyword(132 /* SyntaxKind.AnyKeyword */), 3 /* SyntaxKind.MultiLineCommentTrivia */, 'unresolved', false);
567
+ this.approximateLength += 3;
568
+ return this.keyword(t === c.intrinsicMarkerType ? 141 /* SyntaxKind.IntrinsicKeyword */ : 132 /* SyntaxKind.AnyKeyword */);
569
+ }
570
+ if ((flags & 2 /* TypeFlags.Unknown */) !== 0)
571
+ return this.keyword(159 /* SyntaxKind.UnknownKeyword */);
572
+ if ((flags & 32 /* TypeFlags.String */) !== 0) {
573
+ this.approximateLength += 6;
574
+ return this.keyword(154 /* SyntaxKind.StringKeyword */);
575
+ }
576
+ if ((flags & 64 /* TypeFlags.Number */) !== 0) {
577
+ this.approximateLength += 6;
578
+ return this.keyword(150 /* SyntaxKind.NumberKeyword */);
579
+ }
580
+ if ((flags & 128 /* TypeFlags.BigInt */) !== 0) {
581
+ this.approximateLength += 6;
582
+ return this.keyword(163 /* SyntaxKind.BigIntKeyword */);
583
+ }
584
+ if ((flags & 256 /* TypeFlags.Boolean */) !== 0 && t.alias === undefined) {
585
+ this.approximateLength += 7;
586
+ return this.keyword(135 /* SyntaxKind.BooleanKeyword */);
587
+ }
588
+ if ((flags & 98304 /* TypeFlags.EnumLike */) !== 0) {
589
+ const symbol = t.symbol;
590
+ if ((symbol.flags & 8 /* SymbolFlags.EnumMember */) !== 0) {
591
+ const parentSymbol = getParentOfSymbol(c, symbol);
592
+ const parentName = symbolToTypeNode(this, parentSymbol, 788968 /* SymbolFlags.Type */, undefined);
593
+ if (getDeclaredTypeOfSymbol(c, parentSymbol) === t)
594
+ return parentName;
595
+ const memberName = symbol.name;
596
+ if (isIdentifierText(memberName))
597
+ return appendReferenceToType(this, parentName, this.typeReference(this.identifier(memberName), undefined));
598
+ if (parentName instanceof ImportTypeNode) {
599
+ // Freshly made, so it can be changed in place.
600
+ parentName.isTypeOf = true;
601
+ return this.created(new IndexedAccessTypeNode(parentName, this.created(new LiteralTypeNode(this.stringLiteral(memberName, false)))));
602
+ }
603
+ if (parentName instanceof TypeReferenceNode)
604
+ return this.created(new IndexedAccessTypeNode(this.created(new TypeQueryNode(parentName.typeName, undefined)), this.created(new LiteralTypeNode(this.stringLiteral(memberName, false)))));
605
+ throw new Error('Unhandled type node kind returned from symbolToTypeNode');
606
+ }
607
+ return symbolToTypeNode(this, symbol, 788968 /* SymbolFlags.Type */, undefined);
608
+ }
609
+ if ((flags & 1024 /* TypeFlags.StringLiteral */) !== 0) {
610
+ const value = t.stringValue;
611
+ this.approximateLength += value.length + 2;
612
+ const literal = this.stringLiteral(value, false);
613
+ this.context.addEmitFlags(literal, 131072 /* EmitFlags.NoAsciiEscaping */);
614
+ return this.created(new LiteralTypeNode(literal));
615
+ }
616
+ if ((flags & 2048 /* TypeFlags.NumberLiteral */) !== 0) {
617
+ const value = t.numberValue;
618
+ const text = String(value);
619
+ this.approximateLength += text.length;
620
+ if (value < 0)
621
+ return this.created(new LiteralTypeNode(this.created(new PrefixUnaryExpression(40 /* SyntaxKind.MinusToken */, this.factory.createNumericLiteral(text.substring(1))))));
622
+ return this.created(new LiteralTypeNode(this.factory.createNumericLiteral(text)));
623
+ }
624
+ if ((flags & 4096 /* TypeFlags.BigIntLiteral */) !== 0) {
625
+ const text = t.stringValue;
626
+ this.approximateLength += text.length + 1;
627
+ return this.created(new LiteralTypeNode(this.created(new BigIntLiteral(text + 'n', 0 /* TokenFlags.None */))));
628
+ }
629
+ if ((flags & 8192 /* TypeFlags.BooleanLiteral */) !== 0) {
630
+ const isTrue = t.stringValue === 'true';
631
+ this.approximateLength += isTrue ? 4 : 5;
632
+ return this.created(new LiteralTypeNode(this.factory.createKeywordExpression(isTrue ? 111 /* SyntaxKind.TrueKeyword */ : 96 /* SyntaxKind.FalseKeyword */)));
633
+ }
634
+ if ((flags & 16384 /* TypeFlags.UniqueESSymbol */) !== 0) {
635
+ if ((this.flags & 1048576 /* NodeBuilderFlags.AllowUniqueESSymbolType */) === 0) {
636
+ if (isValueSymbolAccessible(c, t.symbol, this.enclosingDeclaration)) {
637
+ this.approximateLength += 6;
638
+ return symbolToTypeNode(this, t.symbol, 111551 /* SymbolFlags.Value */, undefined);
639
+ }
640
+ this.tracker.reportInaccessibleUniqueSymbolError();
641
+ }
642
+ this.approximateLength += 13;
643
+ return this.created(new TypeOperatorNode(158 /* SyntaxKind.UniqueKeyword */, this.keyword(155 /* SyntaxKind.SymbolKeyword */)));
644
+ }
645
+ if ((flags & 16 /* TypeFlags.Void */) !== 0) {
646
+ this.approximateLength += 4;
647
+ return this.keyword(115 /* SyntaxKind.VoidKeyword */);
648
+ }
649
+ if ((flags & 4 /* TypeFlags.Undefined */) !== 0) {
650
+ this.approximateLength += 9;
651
+ return this.keyword(157 /* SyntaxKind.UndefinedKeyword */);
652
+ }
653
+ if ((flags & 8 /* TypeFlags.Null */) !== 0) {
654
+ this.approximateLength += 4;
655
+ return this.created(new LiteralTypeNode(this.factory.createKeywordExpression(105 /* SyntaxKind.NullKeyword */)));
656
+ }
657
+ if ((flags & 262144 /* TypeFlags.Never */) !== 0) {
658
+ this.approximateLength += 5;
659
+ return this.keyword(146 /* SyntaxKind.NeverKeyword */);
660
+ }
661
+ if ((flags & 512 /* TypeFlags.ESSymbol */) !== 0) {
662
+ this.approximateLength += 6;
663
+ return this.keyword(155 /* SyntaxKind.SymbolKeyword */);
664
+ }
665
+ if ((flags & 131072 /* TypeFlags.NonPrimitive */) !== 0) {
666
+ this.approximateLength += 6;
667
+ return this.keyword(151 /* SyntaxKind.ObjectKeyword */);
668
+ }
669
+ if ((flags & 524288 /* TypeFlags.TypeParameter */) !== 0 && t.isThisType) {
670
+ if ((this.flags & 4194304 /* NodeBuilderFlags.InObjectTypeLiteral */) !== 0) {
671
+ if (!this.encounteredError && (this.flags & 32768 /* NodeBuilderFlags.AllowThisInObjectLiteral */) === 0)
672
+ this.encounteredError = true;
673
+ this.tracker.reportInaccessibleThisError();
674
+ }
675
+ this.approximateLength += 4;
676
+ return this.created(new ThisTypeNode());
677
+ }
678
+ if (inTypeAlias === 0 &&
679
+ t.alias !== undefined &&
680
+ ((this.flags & 16384 /* NodeBuilderFlags.UseAliasDefinedOutsideCurrentScope */) !== 0 ||
681
+ isTypeSymbolAccessible(c, t.alias.symbol, this.enclosingDeclaration))) {
682
+ const symbol = t.alias.symbol;
683
+ const typeArgumentNodes = this.mapToTypeNodes(t.alias.typeArguments, false);
684
+ if (isReservedMemberName(symbol.name) && (symbol.flags & 32 /* SymbolFlags.Class */) === 0)
685
+ return this.typeReference(this.identifier(''), typeArgumentNodes);
686
+ if (typeArgumentNodes !== undefined &&
687
+ typeArgumentNodes.nodes.length === 1 &&
688
+ symbol === c.globalArrayType.symbol)
689
+ return this.created(new ArrayTypeNode(typeArgumentNodes.nodes[0]));
690
+ return symbolToTypeNode(this, symbol, 788968 /* SymbolFlags.Type */, typeArgumentNodes);
691
+ }
692
+ const objectFlags = t.objectFlags;
693
+ if ((objectFlags & 4 /* ObjectFlags.Reference */) !== 0) {
694
+ if (t.node !== undefined)
695
+ return this.visitAndTransformType(t, 1 /* TransformKind.TypeReference */);
696
+ return this.typeReferenceToTypeNode(t);
697
+ }
698
+ if ((flags & 524288 /* TypeFlags.TypeParameter */) !== 0 || (objectFlags & 3 /* ObjectFlags.ClassOrInterface */) !== 0) {
699
+ if ((flags & 524288 /* TypeFlags.TypeParameter */) !== 0 && this.inferTypeParameters.indexOf(t) >= 0) {
700
+ this.approximateLength += t.symbol.name.length + 6;
701
+ let constraintNode = undefined;
702
+ const constraint = getConstraintOfTypeParameter(c, t);
703
+ if (constraint !== undefined) {
704
+ // Write `infer T extends C` unless the position implies the same constraint.
705
+ const inferredConstraint = getInferredTypeParameterConstraint(c, t, true);
706
+ if (inferredConstraint === undefined || !isTypeIdenticalTo(c, constraint, inferredConstraint)) {
707
+ this.approximateLength += 9;
708
+ constraintNode = this.typeToTypeNode(constraint);
709
+ }
710
+ }
711
+ return this.created(new InferTypeNode(this.typeParameterToDeclarationWithConstraint(t, constraintNode)));
712
+ }
713
+ if ((this.flags & 4 /* NodeBuilderFlags.GenerateNamesForShadowedTypeParams */) !== 0 &&
714
+ (flags & 524288 /* TypeFlags.TypeParameter */) !== 0) {
715
+ const name = this.typeParameterToName(t);
716
+ this.approximateLength += name.text.length;
717
+ return this.typeReference(this.identifier(name.text), undefined);
718
+ }
719
+ // A use of a type parameter, not its declaration: no constraint or default.
720
+ if (t.symbol !== undefined)
721
+ return symbolToTypeNode(this, t.symbol, 788968 /* SymbolFlags.Type */, undefined);
722
+ const varianceTypeParameter = c.varianceTypeParameter;
723
+ let name = '?';
724
+ if ((t === c.markerSuperTypeForCheck || t === c.markerSubTypeForCheck) &&
725
+ varianceTypeParameter !== undefined &&
726
+ varianceTypeParameter.symbol !== undefined)
727
+ name = (t === c.markerSubTypeForCheck ? 'sub-' : 'super-') + varianceTypeParameter.symbol.name;
728
+ return this.typeReference(this.identifier(name), undefined);
729
+ }
730
+ let u = t;
731
+ if ((flags & 134217728 /* TypeFlags.Union */) !== 0 && t.origin !== undefined)
732
+ u = t.origin;
733
+ if ((u.flags & (134217728 /* TypeFlags.Union */ | 268435456 /* TypeFlags.Intersection */)) !== 0) {
734
+ let types = (u.flags & 134217728 /* TypeFlags.Union */) !== 0
735
+ ? formatUnionTypes(c, u.types, false)
736
+ : u.types;
737
+ // Declaration emit writes unions in an order that doesn't depend on the checker's history; type
738
+ // text in messages keeps the union's order.
739
+ if (this.declarationOrder && (u.flags & 134217728 /* TypeFlags.Union */) !== 0)
740
+ types = inDeclarationOrder(c, types);
741
+ if (types.length === 1)
742
+ return this.typeToTypeNode(types[0]);
743
+ const typeNodes = this.mapToTypeNodes(types, true);
744
+ if (typeNodes !== undefined && typeNodes.nodes.length > 0)
745
+ return (u.flags & 134217728 /* TypeFlags.Union */) !== 0
746
+ ? this.created(new UnionTypeNode(typeNodes))
747
+ : this.created(new IntersectionTypeNode(typeNodes));
748
+ if (!this.encounteredError && (this.flags & 262144 /* NodeBuilderFlags.AllowEmptyUnionOrIntersection */) === 0)
749
+ this.encounteredError = true;
750
+ return undefined;
751
+ }
752
+ if ((objectFlags & (16 /* ObjectFlags.Anonymous */ | 32 /* ObjectFlags.Mapped */)) !== 0)
753
+ return this.createAnonymousTypeNode(u, false, false);
754
+ if ((u.flags & 2097152 /* TypeFlags.Index */) !== 0) {
755
+ this.approximateLength += 6;
756
+ const indexTypeNode = this.typeToTypeNode(u.target);
757
+ return this.created(new TypeOperatorNode(143 /* SyntaxKind.KeyOfKeyword */, indexTypeNode));
758
+ }
759
+ if ((u.flags & 4194304 /* TypeFlags.TemplateLiteral */) !== 0) {
760
+ const texts = u.texts;
761
+ const types = u.types;
762
+ const head = this.created(new TemplateHead(texts[0], '', 0 /* TokenFlags.None */));
763
+ this.context.addEmitFlags(head, 131072 /* EmitFlags.NoAsciiEscaping */);
764
+ const spans = [];
765
+ for (let i = 0; i < types.length; i++) {
766
+ let literal;
767
+ if (i < types.length - 1)
768
+ literal = this.created(new TemplateMiddle(texts[i + 1], '', 0 /* TokenFlags.None */));
769
+ else
770
+ literal = this.created(new TemplateTail(texts[i + 1], '', 0 /* TokenFlags.None */));
771
+ this.context.addEmitFlags(literal, 131072 /* EmitFlags.NoAsciiEscaping */);
772
+ spans.push(this.created(new TemplateLiteralTypeSpan(this.typeToTypeNode(types[i]), literal)));
773
+ }
774
+ this.approximateLength += 2;
775
+ return this.created(new TemplateLiteralTypeNode(head, this.list(spans)));
776
+ }
777
+ if ((u.flags & 8388608 /* TypeFlags.StringMapping */) !== 0) {
778
+ const typeNode = this.typeToTypeNode(u.target);
779
+ return symbolToTypeNode(this, u.symbol, 788968 /* SymbolFlags.Type */, this.list(typeNode === undefined ? [] : [typeNode]));
780
+ }
781
+ if ((u.flags & 33554432 /* TypeFlags.IndexedAccess */) !== 0) {
782
+ const objectTypeNode = this.typeToTypeNode(u.objectType);
783
+ const indexTypeNode = this.typeToTypeNode(u.indexType);
784
+ this.approximateLength += 2;
785
+ return this.created(new IndexedAccessTypeNode(objectTypeNode, indexTypeNode));
786
+ }
787
+ if ((u.flags & 67108864 /* TypeFlags.Conditional */) !== 0)
788
+ return this.visitAndTransformType(u, 2 /* TransformKind.Conditional */);
789
+ if ((u.flags & 16777216 /* TypeFlags.Substitution */) !== 0) {
790
+ const typeNode = this.typeToTypeNode(u.baseType);
791
+ if (!isNoInferType(c, u))
792
+ return typeNode;
793
+ const noInferSymbol = getGlobalTypeAliasSymbol(c, 'NoInfer', 1, false);
794
+ if (noInferSymbol === undefined)
795
+ return typeNode;
796
+ return symbolToTypeNode(this, noInferSymbol, 788968 /* SymbolFlags.Type */, this.list(typeNode === undefined ? [] : [typeNode]));
797
+ }
798
+ throw new Error('Unhandled type in typeToTypeNode');
799
+ }
800
+ /** Writes `t` with `transform`, eliding its circular references; cached per enclosing declaration. */
801
+ visitAndTransformType(t, transform) {
802
+ const typeId = t.id;
803
+ const isConstructorObject = (t.objectFlags & 16 /* ObjectFlags.Anonymous */) !== 0 &&
804
+ t.symbol !== undefined &&
805
+ (t.symbol.flags & 32 /* SymbolFlags.Class */) !== 0;
806
+ // Instantiations of one anonymous type share a symbol, so tracking symbols rather than
807
+ // types catches circular references through them.
808
+ let id = undefined;
809
+ if ((t.objectFlags & 4 /* ObjectFlags.Reference */) !== 0 && t.node !== undefined)
810
+ id = 'n' + getNodeId(t.node);
811
+ else if ((t.flags & 67108864 /* TypeFlags.Conditional */) !== 0)
812
+ id = 'n' + getNodeId(t.root.node);
813
+ else if (t.symbol !== undefined)
814
+ id = (isConstructorObject ? 'c' : 's') + getSymbolId(t.symbol);
815
+ const key = typeId + ':' + this.flags + ':' + this.internalFlags;
816
+ if (this.enclosingDeclaration !== undefined) {
817
+ const cached = this.serializedTypes.get(getNodeId(this.enclosingDeclaration))?.get(key);
818
+ if (cached !== undefined) {
819
+ for (const tracked of cached.trackedSymbols)
820
+ this.trackSymbol(tracked.symbol, tracked.enclosingDeclaration, tracked.meaning);
821
+ if (cached.truncating)
822
+ this.truncating = true;
823
+ this.approximateLength += cached.addedLength;
824
+ return this.deepCloneNode(cached.node);
825
+ }
826
+ }
827
+ let depth = 0;
828
+ if (id !== undefined) {
829
+ depth = this.symbolDepth.get(id) ?? 0;
830
+ if (depth > 10)
831
+ return this.createElidedInformationPlaceholder();
832
+ this.symbolDepth.set(id, depth + 1);
833
+ }
834
+ this.visitedTypes.add(typeId);
835
+ const prevTrackedSymbols = this.trackedSymbols;
836
+ this.trackedSymbols = [];
837
+ const startLength = this.approximateLength;
838
+ let result;
839
+ switch (transform) {
840
+ case 1 /* TransformKind.TypeReference */:
841
+ result = this.typeReferenceToTypeNode(t);
842
+ break;
843
+ case 2 /* TransformKind.Conditional */:
844
+ result = this.conditionalTypeToTypeNode(t);
845
+ break;
846
+ case 3 /* TransformKind.ObjectType */:
847
+ result = this.createTypeNodeFromObjectType(t);
848
+ break;
849
+ default:
850
+ result = this.typeToTypeNode(t);
851
+ break;
852
+ }
853
+ const addedLength = this.approximateLength - startLength;
854
+ if (this.enclosingDeclaration !== undefined &&
855
+ !this.reportedDiagnostic &&
856
+ !this.encounteredError &&
857
+ result !== undefined) {
858
+ const enclosingId = getNodeId(this.enclosingDeclaration);
859
+ let entries = this.serializedTypes.get(enclosingId);
860
+ if (entries === undefined) {
861
+ entries = new Map();
862
+ this.serializedTypes.set(enclosingId, entries);
863
+ }
864
+ entries.set(key, new SerializedTypeEntry(result, this.truncating, addedLength, this.trackedSymbols));
865
+ }
866
+ this.visitedTypes.delete(typeId);
867
+ if (id !== undefined)
868
+ this.symbolDepth.set(id, depth);
869
+ this.trackedSymbols = prevTrackedSymbols;
870
+ return result;
871
+ }
872
+ typeToTypeNodeOrCircularityElision(t) {
873
+ if ((t.flags & 134217728 /* TypeFlags.Union */) !== 0) {
874
+ if (this.visitedTypes.has(t.id)) {
875
+ if ((this.flags & 131072 /* NodeBuilderFlags.AllowAnonymousIdentifier */) === 0) {
876
+ this.encounteredError = true;
877
+ this.tracker.reportCyclicStructureError();
878
+ }
879
+ return this.createElidedInformationPlaceholder();
880
+ }
881
+ return this.visitAndTransformType(t, 0 /* TransformKind.Type */);
882
+ }
883
+ return this.typeToTypeNode(t);
884
+ }
885
+ conditionalTypeToTypeNode(t) {
886
+ const c = this.c;
887
+ if (this.checkTruncationLength())
888
+ return this.createElidedInformationPlaceholder();
889
+ const checkTypeNode = this.typeToTypeNode(t.checkType);
890
+ this.approximateLength += 15;
891
+ const root = t.root;
892
+ const node = root.node;
893
+ if ((this.flags & 4 /* NodeBuilderFlags.GenerateNamesForShadowedTypeParams */) !== 0 &&
894
+ root.isDistributive &&
895
+ (t.checkType.flags & 524288 /* TypeFlags.TypeParameter */) === 0) {
896
+ // `checkType extends infer T ? T extends checkType ? T extends extendsType<T> ? trueType<T> :
897
+ // falseType<T> : never : never` keeps the conditional distributive over a non-parameter.
898
+ const newParam = c.newTypeParameter(c.newSymbol(262144 /* SymbolFlags.TypeParameter */, 'T'));
899
+ const name = this.typeParameterToName(newParam);
900
+ const newTypeVariable = this.typeReference(name, undefined);
901
+ this.approximateLength += 37;
902
+ const newMapper = prependTypeMapping(root.checkType, newParam, t.mapper);
903
+ const saveInferTypeParameters = this.inferTypeParameters;
904
+ this.inferTypeParameters = root.inferTypeParameters;
905
+ const extendsTypeNode = this.typeToTypeNode(instantiateType(c, root.extendsType, newMapper));
906
+ this.inferTypeParameters = saveInferTypeParameters;
907
+ const trueTypeNode = this.typeToTypeNodeOrCircularityElision(instantiateType(c, this.getTypeFromTypeNode(node.trueType, false), newMapper));
908
+ const falseTypeNode = this.typeToTypeNodeOrCircularityElision(instantiateType(c, this.getTypeFromTypeNode(node.falseType, false), newMapper));
909
+ const newId = this.factory.cloneIdentifier(newTypeVariable.typeName);
910
+ const syntheticExtendsNode = this.created(new InferTypeNode(this.created(new TypeParameterDeclaration(undefined, newId, undefined, undefined, undefined))));
911
+ const innerCheckConditionalNode = this.created(new ConditionalTypeNode(newTypeVariable, extendsTypeNode, trueTypeNode, falseTypeNode));
912
+ const syntheticTrueNode = this.created(new ConditionalTypeNode(this.typeReference(this.factory.cloneIdentifier(name), undefined), checkTypeNode.deepClone(), innerCheckConditionalNode, this.keyword(146 /* SyntaxKind.NeverKeyword */)));
913
+ return this.created(new ConditionalTypeNode(checkTypeNode, syntheticExtendsNode, syntheticTrueNode, this.keyword(146 /* SyntaxKind.NeverKeyword */)));
914
+ }
915
+ const saveInferTypeParameters = this.inferTypeParameters;
916
+ this.inferTypeParameters = root.inferTypeParameters;
917
+ const extendsTypeNode = this.typeToTypeNode(t.extendsType);
918
+ this.inferTypeParameters = saveInferTypeParameters;
919
+ const trueTypeNode = this.typeToTypeNodeOrCircularityElision(getTrueTypeFromConditionalType(c, t));
920
+ const falseTypeNode = this.typeToTypeNodeOrCircularityElision(getFalseTypeFromConditionalType(c, t));
921
+ return this.created(new ConditionalTypeNode(checkTypeNode, extendsTypeNode, trueTypeNode, falseTypeNode));
922
+ }
923
+ getParentSymbolOfTypeParameter(typeParameter) {
924
+ const tp = getDeclarationOfKind(typeParameter.symbol, 169 /* SyntaxKind.TypeParameter */);
925
+ const host = tp?.parent;
926
+ if (host === undefined)
927
+ return undefined;
928
+ return getSymbolOfDeclaration(this.c, host);
929
+ }
930
+ typeReferenceToTypeNode(t) {
931
+ const c = this.c;
932
+ let typeArguments = getTypeArguments(c, t);
933
+ const target = t.target;
934
+ if (target === c.globalArrayType || target === c.globalReadonlyArrayType) {
935
+ if ((this.flags & 2 /* NodeBuilderFlags.WriteArrayAsGenericType */) !== 0) {
936
+ const typeArgumentNode = this.typeToTypeNode(typeArguments[0]);
937
+ return this.typeReference(this.identifier(target === c.globalArrayType ? 'Array' : 'ReadonlyArray'), this.list([typeArgumentNode]));
938
+ }
939
+ const elementType = this.typeToTypeNode(typeArguments[0]);
940
+ const arrayType = this.created(new ArrayTypeNode(elementType));
941
+ return target === c.globalArrayType
942
+ ? arrayType
943
+ : this.created(new TypeOperatorNode(148 /* SyntaxKind.ReadonlyKeyword */, arrayType));
944
+ }
945
+ if ((target.objectFlags & 8 /* ObjectFlags.Tuple */) !== 0) {
946
+ const tuple = target;
947
+ const elementInfos = tuple.elementInfos;
948
+ const elementTypes = [];
949
+ for (let i = 0; i < typeArguments.length; i++)
950
+ elementTypes.push(removeMissingType(c, typeArguments[i], i < elementInfos.length && (elementInfos[i].flags & 2 /* ElementFlags.Optional */) !== 0));
951
+ typeArguments = elementTypes;
952
+ if (typeArguments.length > 0) {
953
+ const arity = getTypeReferenceArity(t);
954
+ const nodes = this.mapToTypeNodes(typeArguments.slice(0, arity), false);
955
+ if (nodes !== undefined) {
956
+ const elements = nodes.nodes;
957
+ for (let i = 0; i < elements.length; i++) {
958
+ const flags = elementInfos[i].flags;
959
+ const labeledDeclaration = elementInfos[i].labeledDeclaration;
960
+ const element = elements[i];
961
+ if (labeledDeclaration !== undefined)
962
+ elements[i] = this.created(new NamedTupleMember((flags & 12 /* ElementFlags.Variable */) !== 0 ? this.token(25 /* SyntaxKind.DotDotDotToken */) : undefined, this.identifier(getTupleElementLabel(c, elementInfos[i].flags, labeledDeclaration, undefined, i)), (flags & 2 /* ElementFlags.Optional */) !== 0 ? this.token(57 /* SyntaxKind.QuestionToken */) : undefined, (flags & 4 /* ElementFlags.Rest */) !== 0 ? this.created(new ArrayTypeNode(element)) : element));
963
+ else if ((flags & 12 /* ElementFlags.Variable */) !== 0)
964
+ elements[i] = this.created(new RestTypeNode((flags & 4 /* ElementFlags.Rest */) !== 0 ? this.created(new ArrayTypeNode(element)) : element));
965
+ else if ((flags & 2 /* ElementFlags.Optional */) !== 0)
966
+ elements[i] = this.created(new OptionalTypeNode(element));
967
+ }
968
+ const tupleTypeNode = this.created(new TupleTypeNode(nodes));
969
+ this.context.setEmitFlags(tupleTypeNode, 1 /* EmitFlags.SingleLine */);
970
+ return tuple.readonly
971
+ ? this.created(new TypeOperatorNode(148 /* SyntaxKind.ReadonlyKeyword */, tupleTypeNode))
972
+ : tupleTypeNode;
973
+ }
974
+ }
975
+ if (this.encounteredError || (this.flags & 524288 /* NodeBuilderFlags.AllowEmptyTuple */) !== 0) {
976
+ const tupleTypeNode = this.created(new TupleTypeNode(this.list([])));
977
+ this.context.setEmitFlags(tupleTypeNode, 1 /* EmitFlags.SingleLine */);
978
+ return tuple.readonly
979
+ ? this.created(new TypeOperatorNode(148 /* SyntaxKind.ReadonlyKeyword */, tupleTypeNode))
980
+ : tupleTypeNode;
981
+ }
982
+ this.encounteredError = true;
983
+ return undefined;
984
+ }
985
+ const symbol = t.symbol;
986
+ if ((this.flags & 2048 /* NodeBuilderFlags.WriteClassExpressionAsTypeLiteral */) !== 0 &&
987
+ symbol.valueDeclaration !== undefined &&
988
+ isClassLike(symbol.valueDeclaration) &&
989
+ !isValueSymbolAccessible(c, symbol, this.enclosingDeclaration))
990
+ return this.createAnonymousTypeNode(t, false, false);
991
+ const interfaceTarget = target;
992
+ const outerTypeParameters = interfaceTarget.outerTypeParameters();
993
+ let i = 0;
994
+ let resultType = undefined;
995
+ const length = outerTypeParameters.length;
996
+ while (i < length) {
997
+ // A group of type arguments for type parameters of one declaring container.
998
+ const start = i;
999
+ const parent = this.getParentSymbolOfTypeParameter(outerTypeParameters[i]);
1000
+ do
1001
+ i++;
1002
+ while (i < length && this.getParentSymbolOfTypeParameter(outerTypeParameters[i]) === parent);
1003
+ // A group of its own type parameters (the default outer type arguments) isn't written.
1004
+ let same = true;
1005
+ for (let k = start; k < i; k++)
1006
+ if (outerTypeParameters[k] !== typeArguments[k])
1007
+ same = false;
1008
+ if (same)
1009
+ continue;
1010
+ const typeArgumentSlice = this.mapToTypeNodes(typeArguments.slice(start, i), false);
1011
+ const savedFlags = this.flags;
1012
+ this.flags |= 16 /* NodeBuilderFlags.ForbidIndexedAccessSymbolReferences */;
1013
+ const ref = symbolToTypeNode(this, parent, 788968 /* SymbolFlags.Type */, typeArgumentSlice);
1014
+ this.flags = savedFlags;
1015
+ if (ref !== undefined)
1016
+ resultType = resultType === undefined ? ref : appendReferenceToType(this, resultType, ref);
1017
+ }
1018
+ let typeArgumentNodes = undefined;
1019
+ if (typeArguments.length > 0) {
1020
+ const typeParameters = interfaceTarget.typeParameters();
1021
+ let typeParameterCount = Math.min(typeParameters.length, typeArguments.length);
1022
+ // Iterable types elide type arguments equal to their defaults, for backwards compatible
1023
+ // declaration emit since they gained type parameters.
1024
+ if (isReferenceToType(t, getGlobalIterableType(c, false)) ||
1025
+ isReferenceToType(t, getGlobalIterableIteratorType(c, false)) ||
1026
+ isReferenceToType(t, getGlobalIterableType(c, true)) ||
1027
+ isReferenceToType(t, getGlobalIterableIteratorType(c, true))) {
1028
+ const node = t.node;
1029
+ const written = node instanceof TypeReferenceNode && node.typeArguments !== undefined ? node.typeArguments.nodes.length : -1;
1030
+ if (written < typeParameterCount)
1031
+ while (typeParameterCount > 0) {
1032
+ const typeArgument = typeArguments[typeParameterCount - 1];
1033
+ const defaultType = getDefaultFromTypeParameter(c, typeParameters[typeParameterCount - 1]);
1034
+ if (defaultType === undefined || !isTypeIdenticalTo(c, typeArgument, defaultType))
1035
+ break;
1036
+ typeParameterCount--;
1037
+ }
1038
+ }
1039
+ typeArgumentNodes = this.mapToTypeNodes(typeArguments.slice(i, Math.max(i, typeParameterCount)), false);
1040
+ }
1041
+ const savedFlags = this.flags;
1042
+ this.flags |= 16 /* NodeBuilderFlags.ForbidIndexedAccessSymbolReferences */;
1043
+ const finalRef = symbolToTypeNode(this, symbol, 788968 /* SymbolFlags.Type */, typeArgumentNodes);
1044
+ this.flags = savedFlags;
1045
+ if (resultType === undefined)
1046
+ return finalRef;
1047
+ return finalRef === undefined ? resultType : appendReferenceToType(this, resultType, finalRef);
1048
+ }
1049
+ // ---- Object types
1050
+ shouldWriteTypeOfFunctionSymbol(symbol, typeId) {
1051
+ const c = this.c;
1052
+ let isStaticMethodSymbol = false;
1053
+ if ((symbol.flags & 8192 /* SymbolFlags.Method */) !== 0)
1054
+ for (const d of symbol.declarations)
1055
+ if (isStatic(d) && !hasLateBindableIndexSignature(c, d))
1056
+ isStaticMethodSymbol = true;
1057
+ let isNonLocalFunctionSymbol = false;
1058
+ let isFunctionExpressionSymbol = false;
1059
+ if ((symbol.flags & 16 /* SymbolFlags.Function */) !== 0) {
1060
+ if (symbol.parent !== undefined)
1061
+ isNonLocalFunctionSymbol = true;
1062
+ else
1063
+ for (const d of symbol.declarations) {
1064
+ const parent = d.parent;
1065
+ if (parent.kind === 307 /* SyntaxKind.SourceFile */ || parent.kind === 269 /* SyntaxKind.ModuleBlock */) {
1066
+ isNonLocalFunctionSymbol = true;
1067
+ break;
1068
+ }
1069
+ const statement = parent.parent?.parent;
1070
+ const container = statement?.parent;
1071
+ if ((d.kind === 219 /* SyntaxKind.FunctionExpression */ || d.kind === 220 /* SyntaxKind.ArrowFunction */) &&
1072
+ parent.kind === 261 /* SyntaxKind.VariableDeclaration */ &&
1073
+ parent.parent.kind === 262 /* SyntaxKind.VariableDeclarationList */ &&
1074
+ statement !== undefined &&
1075
+ statement.kind === 244 /* SyntaxKind.VariableStatement */ &&
1076
+ container !== undefined &&
1077
+ (container.kind === 307 /* SyntaxKind.SourceFile */ || container.kind === 269 /* SyntaxKind.ModuleBlock */)) {
1078
+ isNonLocalFunctionSymbol = true;
1079
+ isFunctionExpressionSymbol = true;
1080
+ break;
1081
+ }
1082
+ }
1083
+ }
1084
+ if (!isStaticMethodSymbol && !isNonLocalFunctionSymbol)
1085
+ return undefined;
1086
+ let named = symbol;
1087
+ const valueDeclaration = symbol.valueDeclaration;
1088
+ if (isFunctionExpressionSymbol &&
1089
+ valueDeclaration !== undefined &&
1090
+ valueDeclaration.parent !== undefined &&
1091
+ valueDeclaration.parent !== this.enclosingDeclaration) {
1092
+ const variable = getSymbol(valueDeclaration.parent);
1093
+ if (variable !== undefined)
1094
+ named = getMergedSymbol(c, variable);
1095
+ }
1096
+ // `typeof f` is allowed for static and non-local functions, or a function referring to itself,
1097
+ // when it can be named or there's no structural fallback.
1098
+ if (((this.flags & 4096 /* NodeBuilderFlags.UseTypeOfFunction */) !== 0 || this.visitedTypes.has(typeId)) &&
1099
+ ((this.flags & 8 /* NodeBuilderFlags.UseStructuralFallback */) === 0 ||
1100
+ isValueSymbolAccessible(c, named, this.enclosingDeclaration)))
1101
+ return named;
1102
+ return undefined;
1103
+ }
1104
+ /** The symbol to write `typeof` of for an anonymous type, if any. */
1105
+ shouldEmitTypeOfSymbol(forceExpansion, forceClassExpansion, isInstanceType, symbol, typeId) {
1106
+ if (forceExpansion)
1107
+ return undefined;
1108
+ const c = this.c;
1109
+ const valueDeclaration = symbol.valueDeclaration;
1110
+ if (((symbol.flags & 32 /* SymbolFlags.Class */) !== 0 &&
1111
+ !forceClassExpansion &&
1112
+ getBaseTypeVariableOfClass(c, symbol) === undefined &&
1113
+ !(valueDeclaration !== undefined &&
1114
+ isClassLike(valueDeclaration) &&
1115
+ (this.flags & 2048 /* NodeBuilderFlags.WriteClassExpressionAsTypeLiteral */) !== 0 &&
1116
+ (valueDeclaration.kind !== 264 /* SyntaxKind.ClassDeclaration */ ||
1117
+ isSymbolAccessible(c, symbol, this.enclosingDeclaration, isInstanceType, false).accessibility !==
1118
+ 0 /* SymbolAccessibility.Accessible */))) ||
1119
+ (symbol.flags & (384 /* SymbolFlags.Enum */ | 512 /* SymbolFlags.ValueModule */)) !== 0)
1120
+ return symbol;
1121
+ return this.shouldWriteTypeOfFunctionSymbol(symbol, typeId);
1122
+ }
1123
+ createAnonymousTypeNode(t, forceClassExpansion, forceExpansion) {
1124
+ const c = this.c;
1125
+ const typeId = t.id;
1126
+ const symbol = t.symbol;
1127
+ // Anonymous types without a symbol are never circular.
1128
+ if (symbol === undefined)
1129
+ return this.createTypeNodeFromObjectType(t);
1130
+ if ((t.objectFlags & 16777216 /* ObjectFlags.InstantiationExpressionType */) !== 0) {
1131
+ const existing = t.node;
1132
+ // The node is unreliable for members of unions and intersections, so it's checked.
1133
+ if (existing !== undefined &&
1134
+ existing.kind === 187 /* SyntaxKind.TypeQuery */ &&
1135
+ this.getTypeFromTypeNode(existing, false) === t) {
1136
+ if (this.visitedTypes.has(typeId))
1137
+ return this.createElidedInformationPlaceholder();
1138
+ this.visitedTypes.add(typeId);
1139
+ const typeNode = this.tryReuseExistingNonParameterTypeNode(existing, t, undefined, undefined);
1140
+ this.visitedTypes.delete(typeId);
1141
+ if (typeNode !== undefined)
1142
+ return typeNode;
1143
+ }
1144
+ if (this.visitedTypes.has(typeId))
1145
+ return this.createElidedInformationPlaceholder();
1146
+ return this.visitAndTransformType(t, 3 /* TransformKind.ObjectType */);
1147
+ }
1148
+ const isInstanceType = isClassInstanceSide(c, t) ? 788968 /* SymbolFlags.Type */ : 111551 /* SymbolFlags.Value */;
1149
+ const typeOfSymbol = this.shouldEmitTypeOfSymbol(forceExpansion, forceClassExpansion, isInstanceType, symbol, typeId);
1150
+ if (typeOfSymbol !== undefined)
1151
+ return symbolToTypeNode(this, typeOfSymbol, isInstanceType, undefined);
1152
+ if (this.visitedTypes.has(typeId)) {
1153
+ // An anonymous type literal in a type alias is written as the alias.
1154
+ const typeAlias = getTypeAliasForTypeLiteral(c, t);
1155
+ if (typeAlias !== undefined)
1156
+ return symbolToTypeNode(this, typeAlias, 788968 /* SymbolFlags.Type */, undefined);
1157
+ return this.createElidedInformationPlaceholder();
1158
+ }
1159
+ return this.visitAndTransformType(t, 3 /* TransformKind.ObjectType */);
1160
+ }
1161
+ createTypeNodeFromObjectType(t) {
1162
+ const c = this.c;
1163
+ if (isGenericMappedType(c, t) ||
1164
+ ((t.objectFlags & 32 /* ObjectFlags.Mapped */) !== 0 && sideOf(c, t).containsError))
1165
+ return this.createMappedTypeNodeFromType(t);
1166
+ const resolved = resolveStructuredTypeMembers(c, t);
1167
+ const callSignatures = resolved.callSignatures;
1168
+ const constructSignatures = resolved.constructSignatures;
1169
+ if (resolved.properties.length === 0 && resolved.indexInfos.length === 0) {
1170
+ if (callSignatures.length === 0 && constructSignatures.length === 0) {
1171
+ this.approximateLength += 2;
1172
+ const result = this.created(new TypeLiteralNode(this.list([])));
1173
+ this.context.setEmitFlags(result, 1 /* EmitFlags.SingleLine */);
1174
+ return result;
1175
+ }
1176
+ if (callSignatures.length === 1 && constructSignatures.length === 0)
1177
+ return this.signatureToSignatureDeclaration(callSignatures[0], 185 /* SyntaxKind.FunctionType */, undefined);
1178
+ if (constructSignatures.length === 1 && callSignatures.length === 0)
1179
+ return this.signatureToSignatureDeclaration(constructSignatures[0], 186 /* SyntaxKind.ConstructorType */, undefined);
1180
+ }
1181
+ const abstractSignatures = constructSignatures.filter((s) => (s.flags & 8 /* SignatureFlags.Abstract */) !== 0);
1182
+ if (abstractSignatures.length > 0) {
1183
+ const types = [];
1184
+ for (const s of abstractSignatures)
1185
+ types.push(getOrCreateTypeFromSignature(c, s));
1186
+ // Type elements other than abstract construct signatures.
1187
+ let propertyCount = resolved.properties.length;
1188
+ if ((this.flags & 2048 /* NodeBuilderFlags.WriteClassExpressionAsTypeLiteral */) !== 0) {
1189
+ propertyCount = 0;
1190
+ for (const p of resolved.properties)
1191
+ if ((p.flags & 4194304 /* SymbolFlags.Prototype */) === 0)
1192
+ propertyCount++;
1193
+ }
1194
+ const typeElementCount = callSignatures.length +
1195
+ (constructSignatures.length - abstractSignatures.length) +
1196
+ resolved.indexInfos.length +
1197
+ propertyCount;
1198
+ // `abstract class C {}` is `abstract new () => C`, not `(abstract new () => C) & {}`.
1199
+ if (typeElementCount !== 0)
1200
+ types.push(getResolvedTypeWithoutAbstractConstructSignatures(c, t, resolved));
1201
+ return this.typeToTypeNode(getIntersectionType(c, types));
1202
+ }
1203
+ const savedFlags = this.flags;
1204
+ this.flags |= 4194304 /* NodeBuilderFlags.InObjectTypeLiteral */;
1205
+ const members = this.createTypeNodesFromResolvedType(t, resolved);
1206
+ this.flags = savedFlags;
1207
+ const typeLiteralNode = this.created(new TypeLiteralNode(members ?? this.list([])));
1208
+ this.approximateLength += 2;
1209
+ this.context.setEmitFlags(typeLiteralNode, (this.flags & 1024 /* NodeBuilderFlags.MultilineObjectLiterals */) !== 0 ? 0 /* EmitFlags.None */ : 1 /* EmitFlags.SingleLine */);
1210
+ return typeLiteralNode;
1211
+ }
1212
+ /** The type elements of `t`, whose members are `resolved`. */
1213
+ createTypeNodesFromResolvedType(t, resolved) {
1214
+ if (this.checkTruncationLength()) {
1215
+ if ((this.flags & 1 /* NodeBuilderFlags.NoTruncation */) !== 0) {
1216
+ const element = this.created(new NotEmittedTypeElement());
1217
+ this.context.addSyntheticTrailingComment(element, 3 /* SyntaxKind.MultiLineCommentTrivia */, 'elided', false);
1218
+ return this.list([element]);
1219
+ }
1220
+ return this.list([
1221
+ this.created(new PropertySignatureDeclaration(undefined, this.identifier('...'), undefined, undefined, undefined)),
1222
+ ]);
1223
+ }
1224
+ const typeElements = [];
1225
+ for (const signature of resolved.callSignatures)
1226
+ typeElements.push(this.signatureToSignatureDeclaration(signature, 180 /* SyntaxKind.CallSignature */, undefined));
1227
+ for (const signature of resolved.constructSignatures) {
1228
+ if ((signature.flags & 8 /* SignatureFlags.Abstract */) !== 0)
1229
+ continue;
1230
+ typeElements.push(this.signatureToSignatureDeclaration(signature, 181 /* SyntaxKind.ConstructSignature */, undefined));
1231
+ }
1232
+ for (const info of resolved.indexInfos) {
1233
+ // tsgo creates the placeholder for every index signature, and its length counts toward truncation.
1234
+ const placeholder = this.createElidedInformationPlaceholder();
1235
+ const typeNode = (t.objectFlags & 1024 /* ObjectFlags.ReverseMapped */) !== 0 ? placeholder : undefined;
1236
+ for (const element of this.indexInfoToObjectComputedNamesOrSignatureDeclaration(info, typeNode))
1237
+ typeElements.push(element);
1238
+ }
1239
+ const properties = resolved.properties;
1240
+ if (properties.length === 0)
1241
+ return this.list(typeElements);
1242
+ let i = 0;
1243
+ for (const propertySymbol of properties) {
1244
+ i++;
1245
+ if ((this.flags & 2048 /* NodeBuilderFlags.WriteClassExpressionAsTypeLiteral */) !== 0) {
1246
+ if ((propertySymbol.flags & 4194304 /* SymbolFlags.Prototype */) !== 0)
1247
+ continue;
1248
+ if ((getDeclarationModifierFlagsFromSymbol(this.c, propertySymbol, false) &
1249
+ (2 /* ModifierFlags.Private */ | 4 /* ModifierFlags.Protected */)) !==
1250
+ 0)
1251
+ this.tracker.reportPrivateInBaseOfClassExpression(propertySymbol.name);
1252
+ if (isPrivateIdentifierSymbol(propertySymbol))
1253
+ this.tracker.reportPrivateInBaseOfClassExpression(symbolName(propertySymbol));
1254
+ }
1255
+ if (this.checkTruncationLength() && i + 2 < properties.length - 1) {
1256
+ if ((this.flags & 1 /* NodeBuilderFlags.NoTruncation */) !== 0) {
1257
+ if (typeElements.length > 0)
1258
+ this.context.addSyntheticTrailingComment(typeElements[typeElements.length - 1], 3 /* SyntaxKind.MultiLineCommentTrivia */, '... ' + (properties.length - i) + ' more elided ...', false);
1259
+ }
1260
+ else
1261
+ typeElements.push(this.created(new PropertySignatureDeclaration(undefined, this.identifier('... ' + (properties.length - i) + ' more ...'), undefined, undefined, undefined)));
1262
+ this.addPropertyToElementList(properties[properties.length - 1], typeElements);
1263
+ break;
1264
+ }
1265
+ this.addPropertyToElementList(propertySymbol, typeElements);
1266
+ }
1267
+ return typeElements.length !== 0 ? this.list(typeElements) : undefined;
1268
+ }
1269
+ shouldUsePlaceholderForProperty(propertySymbol) {
1270
+ // Placeholders for reverse mapped types (1) already being written, (2) nested in a mapping
1271
+ // over a non-anonymous type, or (3) nested deeply in the same mapped type.
1272
+ if ((propertySymbol.checkFlags & 8192 /* CheckFlags.ReverseMapped */) === 0)
1273
+ return false;
1274
+ const stack = this.reverseMappedStack;
1275
+ if (stack.indexOf(propertySymbol) >= 0)
1276
+ return true;
1277
+ if (stack.length > 0) {
1278
+ const propertyType = this.c.symbolLinks(stack[stack.length - 1]).reverseMappedPropertyType;
1279
+ if (propertyType !== undefined && (propertyType.objectFlags & 16 /* ObjectFlags.Anonymous */) === 0)
1280
+ return true;
1281
+ }
1282
+ if (stack.length < maxReverseMappedNestingInspectionDepth)
1283
+ return false;
1284
+ const propMappedType = this.c.symbolLinks(propertySymbol).reverseMappedMappedType;
1285
+ if (propMappedType === undefined || propMappedType.symbol === undefined)
1286
+ return false;
1287
+ for (let i = 0; i < stack.length; i++) {
1288
+ if (i > maxReverseMappedNestingInspectionDepth)
1289
+ break;
1290
+ const mappedType = this.c.symbolLinks(stack[stack.length - 1 - i]).reverseMappedMappedType;
1291
+ if (mappedType !== undefined && mappedType.symbol === propMappedType.symbol)
1292
+ return true;
1293
+ }
1294
+ return false;
1295
+ }
1296
+ trackComputedName(accessExpression, enclosingDeclaration) {
1297
+ const c = this.c;
1298
+ const firstIdentifier = getFirstIdentifier(accessExpression);
1299
+ const name = resolveName(c, enclosingDeclaration, getText(firstIdentifier), 111551 /* SymbolFlags.Value */ | 1048576 /* SymbolFlags.ExportValue */, undefined, true, false);
1300
+ if (name !== undefined) {
1301
+ this.trackSymbol(name, enclosingDeclaration, 111551 /* SymbolFlags.Value */);
1302
+ return;
1303
+ }
1304
+ // Unresolved at the target: track the symbol at its own location, which is inaccessible.
1305
+ const fallback = resolveName(c, firstIdentifier, getText(firstIdentifier), 111551 /* SymbolFlags.Value */ | 1048576 /* SymbolFlags.ExportValue */, undefined, true, false);
1306
+ if (fallback !== undefined)
1307
+ this.trackSymbol(fallback, enclosingDeclaration, 111551 /* SymbolFlags.Value */);
1308
+ }
1309
+ addPropertyToElementList(propertySymbol, typeElements) {
1310
+ const c = this.c;
1311
+ const propertyIsReverseMapped = (propertySymbol.checkFlags & 8192 /* CheckFlags.ReverseMapped */) !== 0;
1312
+ const propertyType = this.shouldUsePlaceholderForProperty(propertySymbol)
1313
+ ? c.anyType
1314
+ : getNonMissingTypeOfSymbol(c, propertySymbol);
1315
+ const saveEnclosingDeclaration = this.enclosingDeclaration;
1316
+ this.enclosingDeclaration = undefined;
1317
+ if (isLateBoundName(propertySymbol.name)) {
1318
+ if (propertySymbol.declarations.length > 0) {
1319
+ const decl = propertySymbol.declarations[0];
1320
+ if (hasLateBindableName(c, decl)) {
1321
+ if (decl instanceof BinaryExpression) {
1322
+ const name = getNameOfDeclaration(decl);
1323
+ if (name instanceof ElementAccessExpression &&
1324
+ isPropertyAccessEntityNameExpression(name.argumentExpression))
1325
+ this.trackComputedName(name.argumentExpression, saveEnclosingDeclaration);
1326
+ }
1327
+ else
1328
+ this.trackComputedName(getExpression(getName(decl)), saveEnclosingDeclaration);
1329
+ }
1330
+ }
1331
+ else
1332
+ this.tracker.reportNonSerializableProperty(symbolToString(c, propertySymbol));
1333
+ }
1334
+ this.enclosingDeclaration =
1335
+ propertySymbol.valueDeclaration ??
1336
+ (propertySymbol.declarations.length > 0 ? propertySymbol.declarations[0] : saveEnclosingDeclaration);
1337
+ const propertyName = getPropertyNameNodeForSymbol(this, propertySymbol);
1338
+ this.enclosingDeclaration = saveEnclosingDeclaration;
1339
+ this.approximateLength += symbolName(propertySymbol).length + 1;
1340
+ if ((propertySymbol.flags & 98304 /* SymbolFlags.Accessor */) !== 0) {
1341
+ const writeType = getWriteTypeOfSymbol(c, propertySymbol);
1342
+ if (!isErrorType(c, propertyType) && !isErrorType(c, writeType)) {
1343
+ const propDeclaration = getDeclarationOfKind(propertySymbol, 173 /* SyntaxKind.PropertyDeclaration */);
1344
+ const parentIsClass = propertySymbol.parent !== undefined && (propertySymbol.parent.flags & 32 /* SymbolFlags.Class */) !== 0;
1345
+ if (propertyType !== writeType || (parentIsClass && propDeclaration === undefined)) {
1346
+ const symbolMapper = c.symbolMappers.get(getSymbolId(propertySymbol));
1347
+ const getterDeclaration = getDeclarationOfKind(propertySymbol, 178 /* SyntaxKind.GetAccessor */);
1348
+ if (getterDeclaration !== undefined) {
1349
+ let getterSignature = getSignatureFromDeclaration(c, getterDeclaration);
1350
+ if (symbolMapper !== undefined)
1351
+ getterSignature = instantiateSignature(c, getterSignature, symbolMapper);
1352
+ const getter = this.signatureToSignatureDeclaration(getterSignature, 178 /* SyntaxKind.GetAccessor */, new SignatureDeclarationOptions([], propertyName, undefined));
1353
+ this.setCommentRange(getter, getterDeclaration);
1354
+ typeElements.push(getter);
1355
+ }
1356
+ const setterDeclaration = getDeclarationOfKind(propertySymbol, 179 /* SyntaxKind.SetAccessor */);
1357
+ if (setterDeclaration !== undefined) {
1358
+ let setterSignature = getSignatureFromDeclaration(c, setterDeclaration);
1359
+ if (symbolMapper !== undefined)
1360
+ setterSignature = instantiateSignature(c, setterSignature, symbolMapper);
1361
+ const setter = this.signatureToSignatureDeclaration(setterSignature, 179 /* SyntaxKind.SetAccessor */, new SignatureDeclarationOptions([], propertyName, undefined));
1362
+ this.setCommentRange(setter, setterDeclaration);
1363
+ typeElements.push(setter);
1364
+ }
1365
+ return;
1366
+ }
1367
+ if (parentIsClass && propDeclaration !== undefined && hasAccessorKeyword(propDeclaration)) {
1368
+ const fakeGetterSignature = c.newSignature(0 /* SignatureFlags.None */, undefined, [], undefined, [], propertyType, 0);
1369
+ const fakeGetter = this.signatureToSignatureDeclaration(fakeGetterSignature, 178 /* SyntaxKind.GetAccessor */, new SignatureDeclarationOptions([], propertyName, undefined));
1370
+ this.setCommentRange(fakeGetter, propDeclaration);
1371
+ typeElements.push(fakeGetter);
1372
+ const setterParam = c.newSymbol(1 /* SymbolFlags.FunctionScopedVariable */, 'arg');
1373
+ c.symbolTypes.set(getSymbolId(setterParam), writeType);
1374
+ const fakeSetterSignature = c.newSignature(0 /* SignatureFlags.None */, undefined, [], undefined, [setterParam], c.voidType, 0);
1375
+ typeElements.push(this.signatureToSignatureDeclaration(fakeSetterSignature, 179 /* SyntaxKind.SetAccessor */, new SignatureDeclarationOptions([], propertyName, undefined)));
1376
+ return;
1377
+ }
1378
+ }
1379
+ }
1380
+ const optionalToken = (propertySymbol.flags & 16777216 /* SymbolFlags.Optional */) !== 0 ? this.token(57 /* SyntaxKind.QuestionToken */) : undefined;
1381
+ if ((propertySymbol.flags & (16 /* SymbolFlags.Function */ | 8192 /* SymbolFlags.Method */)) !== 0 &&
1382
+ getPropertiesOfObjectType(c, propertyType).length === 0 &&
1383
+ !isReadonlySymbol(c, propertySymbol)) {
1384
+ const signatures = getSignaturesOfType(c, filterType(c, propertyType, (u) => (u.flags & 4 /* TypeFlags.Undefined */) === 0), 0 /* SignatureKind.Call */);
1385
+ for (const signature of signatures) {
1386
+ const methodDeclaration = this.signatureToSignatureDeclaration(signature, 174 /* SyntaxKind.MethodSignature */, new SignatureDeclarationOptions([], propertyName, optionalToken));
1387
+ this.setCommentRange(methodDeclaration, signature.declaration ?? propertySymbol.valueDeclaration);
1388
+ typeElements.push(methodDeclaration);
1389
+ }
1390
+ if (signatures.length !== 0 || optionalToken === undefined)
1391
+ return;
1392
+ }
1393
+ let propertyTypeNode;
1394
+ if (this.shouldUsePlaceholderForProperty(propertySymbol))
1395
+ propertyTypeNode = this.createElidedInformationPlaceholder();
1396
+ else {
1397
+ if (propertyIsReverseMapped)
1398
+ this.reverseMappedStack.push(propertySymbol);
1399
+ propertyTypeNode = this.serializeTypeForDeclaration(undefined, propertyType, propertySymbol, true);
1400
+ if (propertyIsReverseMapped)
1401
+ this.reverseMappedStack.pop();
1402
+ }
1403
+ let modifiers = undefined;
1404
+ if (isReadonlySymbol(c, propertySymbol)) {
1405
+ modifiers = this.modifierList([this.token(148 /* SyntaxKind.ReadonlyKeyword */)]);
1406
+ this.approximateLength += 9;
1407
+ }
1408
+ const propertySignature = this.created(new PropertySignatureDeclaration(modifiers, propertyName, optionalToken, propertyTypeNode, undefined));
1409
+ this.setCommentRange(propertySignature, propertySymbol.valueDeclaration);
1410
+ typeElements.push(propertySignature);
1411
+ }
1412
+ setCommentRange(node, range) {
1413
+ // Comments are copied only within the file being written, for declaration emit.
1414
+ if (range !== undefined && this.enclosingFile !== undefined && this.enclosingFile === getSourceFileOfNode(range))
1415
+ this.context.assignCommentRange(node, range);
1416
+ }
1417
+ isDeclaredInEnclosingFile(symbol) {
1418
+ for (const d of symbol.declarations)
1419
+ if (getSourceFileOfNode(d) === this.enclosingFile)
1420
+ return true;
1421
+ return false;
1422
+ }
1423
+ areTriviallySerializableComputedNames(components) {
1424
+ for (const e of components)
1425
+ if (!this.isTriviallySerializableComputedName(e))
1426
+ return false;
1427
+ return true;
1428
+ }
1429
+ isTriviallySerializableComputedName(e) {
1430
+ const name = getName(e);
1431
+ if (name === undefined || name.kind !== 168 /* SyntaxKind.ComputedPropertyName */)
1432
+ return false;
1433
+ const expression = getExpression(name);
1434
+ if (!isEntityNameExpression(expression, false))
1435
+ return false;
1436
+ return (isEntityNameVisible(this.c, expression, this.enclosingDeclaration).accessibility ===
1437
+ 0 /* SymbolAccessibility.Accessible */);
1438
+ }
1439
+ indexInfoToObjectComputedNamesOrSignatureDeclaration(indexInfo, typeNode) {
1440
+ const components = indexInfo.components;
1441
+ // An index info from computed property names is written as those names when all are visible `a.b.c`.
1442
+ if (components.length > 0 &&
1443
+ this.enclosingDeclaration !== undefined &&
1444
+ this.areTriviallySerializableComputedNames(components)) {
1445
+ const results = [];
1446
+ let bailed = false;
1447
+ for (const e of components) {
1448
+ // Late-bound members are written as properties anyway.
1449
+ if (hasLateBindableName(this.c, e))
1450
+ continue;
1451
+ const eName = getName(e);
1452
+ const name = tryReuseExistingNode(this, eName);
1453
+ if (name === undefined) {
1454
+ bailed = true;
1455
+ break;
1456
+ }
1457
+ this.trackComputedName(getExpression(eName), this.enclosingDeclaration);
1458
+ const modifiers = indexInfo.isReadonly
1459
+ ? this.modifierList([this.token(148 /* SyntaxKind.ReadonlyKeyword */)])
1460
+ : undefined;
1461
+ const postfixToken = getPostfixToken(e);
1462
+ const signature = this.created(new PropertySignatureDeclaration(modifiers, name, postfixToken === undefined ? undefined : this.token(postfixToken.kind), typeNode !== undefined ? typeNode.deepClone() : this.typeToTypeNode(getTypeOfSymbol(this.c, getSymbol(e))), undefined));
1463
+ signature.pos = e.pos;
1464
+ signature.end = e.end;
1465
+ results.push(signature);
1466
+ }
1467
+ if (!bailed)
1468
+ return results;
1469
+ }
1470
+ return [this.indexInfoToIndexSignatureDeclaration(indexInfo, typeNode)];
1471
+ }
1472
+ indexInfoToIndexSignatureDeclaration(indexInfo, typeNode) {
1473
+ const name = getNameFromIndexInfo(indexInfo);
1474
+ const indexerTypeNode = this.typeToTypeNode(indexInfo.keyType);
1475
+ const indexingParameter = this.created(new ParameterDeclaration(undefined, undefined, this.identifier(name), undefined, indexerTypeNode, undefined));
1476
+ const valueTypeNode = typeNode ?? this.typeToTypeNode(indexInfo.valueType);
1477
+ this.approximateLength += name.length + 4;
1478
+ let modifiers = undefined;
1479
+ if (indexInfo.isReadonly) {
1480
+ this.approximateLength += 9;
1481
+ modifiers = this.modifierList([this.token(148 /* SyntaxKind.ReadonlyKeyword */)]);
1482
+ }
1483
+ return this.created(new IndexSignatureDeclaration(modifiers, this.list([indexingParameter]), valueTypeNode));
1484
+ }
1485
+ // ---- Mapped types
1486
+ isMappedTypeHomomorphic(mapped) {
1487
+ return getHomomorphicTypeVariable(this.c, mapped) !== undefined;
1488
+ }
1489
+ isHomomorphicMappedTypeWithNonHomomorphicInstantiation(mapped) {
1490
+ return (mapped.target !== undefined &&
1491
+ !this.isMappedTypeHomomorphic(mapped) &&
1492
+ this.isMappedTypeHomomorphic(mapped.target));
1493
+ }
1494
+ createMappedTypeNodeFromType(t) {
1495
+ const c = this.c;
1496
+ const declaration = t.declaration;
1497
+ const readonlyToken = declaration.readonlyToken !== undefined ? this.token(declaration.readonlyToken.kind) : undefined;
1498
+ const questionToken = declaration.questionToken !== undefined ? this.token(declaration.questionToken.kind) : undefined;
1499
+ let appropriateConstraintTypeNode;
1500
+ let newTypeVariable = undefined;
1501
+ let templateType = getTemplateTypeFromMappedType(c, t);
1502
+ const typeParameter = getTypeParameterFromMappedType(c, t);
1503
+ const generateNames = (this.flags & 4 /* NodeBuilderFlags.GenerateNamesForShadowedTypeParams */) !== 0;
1504
+ // A mapped type preserving modifiers without a `keyof` constraint needs a wrapper to keep
1505
+ // preserving them when inlined.
1506
+ const constraintType = getConstraintTypeFromMappedType(c, t);
1507
+ const needsModifierPreservingWrapper = !isMappedTypeWithKeyofConstraintDeclaration(c, t) &&
1508
+ (getModifiersTypeFromMappedType(c, t).flags & 2 /* TypeFlags.Unknown */) === 0 &&
1509
+ generateNames &&
1510
+ !((constraintType.flags & 524288 /* TypeFlags.TypeParameter */) !== 0 &&
1511
+ ((getConstraintOfTypeParameter(c, constraintType)?.flags ?? 0) & 2097152 /* TypeFlags.Index */) !== 0);
1512
+ if (isMappedTypeWithKeyofConstraintDeclaration(c, t)) {
1513
+ // `{ [P in keyof T]: X }` keeps its `keyof`, which distribution may lose.
1514
+ if (generateNames && this.isHomomorphicMappedTypeWithNonHomomorphicInstantiation(t)) {
1515
+ const newConstraintParam = c.newTypeParameter(c.newSymbol(262144 /* SymbolFlags.TypeParameter */, 'T'));
1516
+ const name = this.typeParameterToName(newConstraintParam);
1517
+ const target = t.target;
1518
+ newTypeVariable = this.typeReference(name, undefined);
1519
+ templateType = instantiateType(c, getTemplateTypeFromMappedType(c, target), newTypeMapper([getTypeParameterFromMappedType(c, target), getModifiersTypeFromMappedType(c, target)], [typeParameter, newConstraintParam]));
1520
+ }
1521
+ let indexTarget;
1522
+ if (newTypeVariable !== undefined)
1523
+ indexTarget = newTypeVariable;
1524
+ else
1525
+ indexTarget = this.typeToTypeNode(getModifiersTypeFromMappedType(c, t));
1526
+ appropriateConstraintTypeNode = this.created(new TypeOperatorNode(143 /* SyntaxKind.KeyOfKeyword */, indexTarget));
1527
+ }
1528
+ else if (needsModifierPreservingWrapper) {
1529
+ // `{ [K in T_1]: Template }` with a new type variable as the constraint.
1530
+ const newParam = c.newTypeParameter(c.newSymbol(262144 /* SymbolFlags.TypeParameter */, 'T'));
1531
+ const name = this.typeParameterToName(newParam);
1532
+ newTypeVariable = this.typeReference(name, undefined);
1533
+ appropriateConstraintTypeNode = newTypeVariable;
1534
+ }
1535
+ else
1536
+ appropriateConstraintTypeNode = this.typeToTypeNode(constraintType);
1537
+ // The name and template types are in the new scope.
1538
+ const exit = this.enterNewScope(declaration, undefined, [typeParameter], undefined, undefined);
1539
+ const typeParameterNode = this.typeParameterToDeclarationWithConstraint(typeParameter, appropriateConstraintTypeNode);
1540
+ let nameTypeNode = undefined;
1541
+ if (declaration.nameType !== undefined)
1542
+ nameTypeNode = this.typeToTypeNode(getNameTypeFromMappedType(c, t));
1543
+ const templateTypeNode = this.typeToTypeNode(removeMissingType(c, templateType, (getMappedTypeModifiers(t) & 4 /* MappedTypeModifiers.IncludeOptional */) !== 0));
1544
+ exit();
1545
+ const result = this.created(new MappedTypeNode(readonlyToken, typeParameterNode, nameTypeNode, questionToken, templateTypeNode, undefined));
1546
+ this.approximateLength += 10;
1547
+ this.context.addEmitFlags(result, 1 /* EmitFlags.SingleLine */);
1548
+ if (generateNames && this.isHomomorphicMappedTypeWithNonHomomorphicInstantiation(t)) {
1549
+ // `ModifiersType extends infer U ? { ...mapped type... } : never` stays homomorphic.
1550
+ const declaredConstraint = getEffectiveConstraint(declaration.typeParameter);
1551
+ let rawConstraint = declaredConstraint !== undefined && getType(declaredConstraint) !== undefined
1552
+ ? this.getTypeFromTypeNode(getType(declaredConstraint), false)
1553
+ : undefined;
1554
+ if (rawConstraint !== undefined)
1555
+ rawConstraint = getConstraintOfTypeParameter(c, rawConstraint);
1556
+ const originalConstraint = instantiateType(c, rawConstraint ?? c.unknownType, t.mapper);
1557
+ const originalConstraintNode = (originalConstraint.flags & 2 /* TypeFlags.Unknown */) === 0 ? this.typeToTypeNode(originalConstraint) : undefined;
1558
+ return this.created(new ConditionalTypeNode(this.typeToTypeNode(getModifiersTypeFromMappedType(c, t)), this.created(new InferTypeNode(this.created(new TypeParameterDeclaration(undefined, this.factory.cloneIdentifier(newTypeVariable.typeName), originalConstraintNode, undefined, undefined)))), result, this.keyword(146 /* SyntaxKind.NeverKeyword */)));
1559
+ }
1560
+ if (needsModifierPreservingWrapper) {
1561
+ // `ConstraintType extends infer T_1 extends keyof ModifiersType ? { [K in T_1]: Template } : never`.
1562
+ return this.created(new ConditionalTypeNode(this.typeToTypeNode(constraintType), this.created(new InferTypeNode(this.created(new TypeParameterDeclaration(undefined, this.factory.cloneIdentifier(newTypeVariable.typeName), this.created(new TypeOperatorNode(143 /* SyntaxKind.KeyOfKeyword */, this.typeToTypeNode(getModifiersTypeFromMappedType(c, t)))), undefined, undefined)))), result, this.keyword(146 /* SyntaxKind.NeverKeyword */)));
1563
+ }
1564
+ return result;
1565
+ }
1566
+ // ---- Type parameters
1567
+ typeParameterToName(typeParameter) {
1568
+ const generateNames = (this.flags & 4 /* NodeBuilderFlags.GenerateNamesForShadowedTypeParams */) !== 0;
1569
+ if (generateNames) {
1570
+ const cached = this.typeParameterNames?.get(typeParameter.id);
1571
+ if (cached !== undefined)
1572
+ return cached;
1573
+ }
1574
+ let result = symbolToName(this, typeParameter.symbol, 788968 /* SymbolFlags.Type */, true);
1575
+ if (!(result instanceof Identifier))
1576
+ return this.identifier('(Missing type parameter)');
1577
+ const symbol = typeParameter.symbol;
1578
+ if (symbol !== undefined && symbol.declarations.length > 0) {
1579
+ const decl = symbol.declarations[0];
1580
+ if (decl.kind === 169 /* SyntaxKind.TypeParameter */)
1581
+ result = this.setTextRange(result, getName(decl));
1582
+ }
1583
+ if (generateNames) {
1584
+ const rawText = result.text;
1585
+ let i = this.typeParameterNamesByTextNextNameCount?.get(rawText) ?? 0;
1586
+ let text = rawText;
1587
+ while (this.typeParameterNamesByText?.has(text) === true ||
1588
+ this.typeParameterShadowsOtherTypeParameterInScope(text, typeParameter)) {
1589
+ i++;
1590
+ text = rawText + '_' + i;
1591
+ }
1592
+ if (text !== rawText)
1593
+ result = this.identifier(text);
1594
+ // Caching the largest suffix saves iterations when it grows large.
1595
+ const nextNameCount = this.typeParameterNamesByTextNextNameCount ?? new Map();
1596
+ const names = this.typeParameterNames ?? new Map();
1597
+ const namesByText = this.typeParameterNamesByText ?? new Set();
1598
+ nextNameCount.set(rawText, i);
1599
+ names.set(typeParameter.id, result);
1600
+ namesByText.add(text);
1601
+ this.typeParameterNamesByTextNextNameCount = nextNameCount;
1602
+ this.typeParameterNames = names;
1603
+ this.typeParameterNamesByText = namesByText;
1604
+ }
1605
+ return result;
1606
+ }
1607
+ typeParameterShadowsOtherTypeParameterInScope(name, typeParameter) {
1608
+ const result = resolveName(this.c, this.enclosingDeclaration, name, 788968 /* SymbolFlags.Type */, undefined, false, false);
1609
+ return result !== undefined && (result.flags & 262144 /* SymbolFlags.TypeParameter */) !== 0 && result !== typeParameter.symbol;
1610
+ }
1611
+ typeParameterToDeclarationWithConstraint(typeParameter, constraintNode) {
1612
+ const savedFlags = this.flags;
1613
+ // Avoids an infinite loop on a generic in a qualified name.
1614
+ this.flags &= ~512 /* NodeBuilderFlags.WriteTypeParametersInQualifiedName */;
1615
+ const modifiers = this.factory.createModifiersFromFlags(getTypeParameterModifiers(typeParameter));
1616
+ const name = this.typeParameterToName(typeParameter);
1617
+ const defaultParameter = getDefaultFromTypeParameter(this.c, typeParameter);
1618
+ const defaultNode = defaultParameter !== undefined ? this.typeToTypeNode(defaultParameter) : undefined;
1619
+ this.flags = savedFlags;
1620
+ return this.created(new TypeParameterDeclaration(modifiers.nodes.length > 0 ? modifiers : undefined, name, constraintNode, undefined, defaultNode));
1621
+ }
1622
+ typeParameterToDeclaration(parameter) {
1623
+ const constraint = getConstraintOfTypeParameter(this.c, parameter);
1624
+ const constraintNode = constraint !== undefined
1625
+ ? this.typeToTypeNodeWithPossibleReusableTypeNode(constraint, getConstraintDeclaration(parameter))
1626
+ : undefined;
1627
+ return this.typeParameterToDeclarationWithConstraint(parameter, constraintNode);
1628
+ }
1629
+ /** The type node for `t`, reusing `typeNode` if it denotes `t`. */
1630
+ typeToTypeNodeWithPossibleReusableTypeNode(t, typeNode) {
1631
+ if (t === undefined)
1632
+ return this.keyword(132 /* SyntaxKind.AnyKeyword */);
1633
+ if (typeNode !== undefined && this.getTypeFromTypeNode(typeNode, false) === t) {
1634
+ const reused = tryReuseExistingNode(this, typeNode);
1635
+ if (reused !== undefined)
1636
+ return reused;
1637
+ }
1638
+ return this.typeToTypeNode(t);
1639
+ }
1640
+ typeParametersToTypeParameterDeclarations(symbol) {
1641
+ const c = this.c;
1642
+ const targetSymbol = getTargetSymbol(c, symbol);
1643
+ const results = [];
1644
+ if ((targetSymbol.flags & (32 /* SymbolFlags.Class */ | 64 /* SymbolFlags.Interface */ | 2097152 /* SymbolFlags.Alias */)) !== 0) {
1645
+ for (const param of getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(c, symbol))
1646
+ results.push(this.typeParameterToDeclaration(param));
1647
+ }
1648
+ else if ((targetSymbol.flags & 16 /* SymbolFlags.Function */) !== 0 && symbol.valueDeclaration !== undefined) {
1649
+ for (const param of getTypeParametersFromDeclaration(c, symbol.valueDeclaration))
1650
+ results.push(this.typeParameterToDeclaration(param));
1651
+ }
1652
+ return results;
1653
+ }
1654
+ getTypeParametersOfClassOrInterface(symbol) {
1655
+ const declared = getDeclaredTypeOfClassOrInterface(this.c, symbol);
1656
+ return declared.outerTypeParameters().concat(declared.localTypeParameters());
1657
+ }
1658
+ // ---- Signatures
1659
+ signatureToSignatureDeclaration(signature, kind, options) {
1660
+ const c = this.c;
1661
+ const exit = this.enterSignatureScope(signature);
1662
+ const expandedParams = this.expandedParameters;
1663
+ // Usually more, but 3 is the minimum.
1664
+ this.approximateLength += 3;
1665
+ const typeParameters = [];
1666
+ if ((this.flags & 32 /* NodeBuilderFlags.WriteTypeArgumentsOfSignature */) !== 0 &&
1667
+ signature.target !== undefined &&
1668
+ signature.mapper !== undefined &&
1669
+ signature.target.typeParameters.length !== 0) {
1670
+ for (const parameter of signature.target.typeParameters) {
1671
+ const node = this.typeToTypeNode(instantiateType(c, parameter, signature.mapper));
1672
+ if (node !== undefined)
1673
+ typeParameters.push(node);
1674
+ }
1675
+ }
1676
+ else
1677
+ for (const parameter of signature.typeParameters)
1678
+ typeParameters.push(this.typeParameterToDeclaration(parameter));
1679
+ const savedFlags = this.flags;
1680
+ this.flags &= ~256 /* NodeBuilderFlags.SuppressAnyReturnType */;
1681
+ // An expanded parameter list with a variadic before its end isn't used.
1682
+ let useOriginal = false;
1683
+ for (const p of expandedParams)
1684
+ if (p !== expandedParams[expandedParams.length - 1] && (p.checkFlags & 32768 /* CheckFlags.RestParameter */) !== 0)
1685
+ useOriginal = true;
1686
+ const parameters = [];
1687
+ const thisParameter = (this.flags & 33554432 /* NodeBuilderFlags.OmitThisParameter */) !== 0
1688
+ ? undefined
1689
+ : this.tryGetThisParameterDeclaration(signature);
1690
+ if (thisParameter !== undefined)
1691
+ parameters.push(thisParameter);
1692
+ for (const parameter of useOriginal ? signature.parameters : expandedParams)
1693
+ parameters.push(this.symbolToParameterDeclaration(parameter, kind === 177 /* SyntaxKind.Constructor */));
1694
+ this.flags = savedFlags;
1695
+ let returnTypeNode = this.serializeReturnTypeForSignature(signature);
1696
+ let modifiers = options !== undefined ? options.modifiers : [];
1697
+ if (kind === 186 /* SyntaxKind.ConstructorType */ && (signature.flags & 8 /* SignatureFlags.Abstract */) !== 0) {
1698
+ let flags = 64 /* ModifierFlags.Abstract */;
1699
+ for (const m of modifiers)
1700
+ flags |= modifierToFlag(m.kind);
1701
+ modifiers = this.factory.createModifiersFromFlags(flags).nodes;
1702
+ }
1703
+ const paramList = this.list(parameters);
1704
+ const typeParamList = typeParameters.length !== 0 ? this.list(typeParameters) : undefined;
1705
+ const modifierList = this.modifierList(modifiers);
1706
+ const name = (options !== undefined ? options.name : undefined) ?? this.identifier('');
1707
+ let node;
1708
+ switch (kind) {
1709
+ case 180 /* SyntaxKind.CallSignature */:
1710
+ node = this.created(new CallSignatureDeclaration(typeParamList, paramList, returnTypeNode));
1711
+ break;
1712
+ case 181 /* SyntaxKind.ConstructSignature */:
1713
+ node = this.created(new ConstructSignatureDeclaration(typeParamList, paramList, returnTypeNode));
1714
+ break;
1715
+ case 174 /* SyntaxKind.MethodSignature */:
1716
+ node = this.created(new MethodSignatureDeclaration(modifierList, name, options !== undefined ? options.questionToken : undefined, typeParamList, paramList, returnTypeNode));
1717
+ break;
1718
+ case 175 /* SyntaxKind.MethodDeclaration */:
1719
+ node = this.created(new MethodDeclaration(modifierList, undefined, name, undefined, typeParamList, paramList, returnTypeNode, undefined, undefined));
1720
+ break;
1721
+ case 177 /* SyntaxKind.Constructor */:
1722
+ node = this.created(new ConstructorDeclaration(modifierList, undefined, paramList, undefined, undefined, undefined));
1723
+ break;
1724
+ case 178 /* SyntaxKind.GetAccessor */:
1725
+ node = this.created(new GetAccessorDeclaration(modifierList, name, undefined, paramList, returnTypeNode, undefined, undefined));
1726
+ break;
1727
+ case 179 /* SyntaxKind.SetAccessor */:
1728
+ node = this.created(new SetAccessorDeclaration(modifierList, name, undefined, paramList, undefined, undefined, undefined));
1729
+ break;
1730
+ case 182 /* SyntaxKind.IndexSignature */:
1731
+ node = this.created(new IndexSignatureDeclaration(modifierList, paramList, returnTypeNode));
1732
+ break;
1733
+ case 185 /* SyntaxKind.FunctionType */:
1734
+ if (returnTypeNode === undefined)
1735
+ returnTypeNode = this.typeReference(this.identifier(''), undefined);
1736
+ node = this.created(new FunctionTypeNode(typeParamList, paramList, returnTypeNode));
1737
+ break;
1738
+ case 186 /* SyntaxKind.ConstructorType */:
1739
+ if (returnTypeNode === undefined)
1740
+ returnTypeNode = this.typeReference(this.identifier(''), undefined);
1741
+ node = this.created(new ConstructorTypeNode(modifierList, typeParamList, paramList, returnTypeNode));
1742
+ break;
1743
+ case 263 /* SyntaxKind.FunctionDeclaration */:
1744
+ node = this.created(new FunctionDeclaration(modifierList, undefined, name, typeParamList, paramList, returnTypeNode, undefined, undefined));
1745
+ break;
1746
+ case 219 /* SyntaxKind.FunctionExpression */:
1747
+ node = this.created(new FunctionExpression(modifierList, undefined, name, typeParamList, paramList, returnTypeNode, undefined, this.created(new Block(this.list([]), false))));
1748
+ break;
1749
+ case 220 /* SyntaxKind.ArrowFunction */:
1750
+ node = this.created(new ArrowFunction(modifierList, typeParamList, paramList, returnTypeNode, undefined, undefined, this.created(new Block(this.list([]), false))));
1751
+ break;
1752
+ default:
1753
+ throw new Error('Unhandled kind in signatureToSignatureDeclaration');
1754
+ }
1755
+ exit();
1756
+ return node;
1757
+ }
1758
+ tryGetThisParameterDeclaration(signature) {
1759
+ if (signature.thisParameter !== undefined)
1760
+ return this.symbolToParameterDeclaration(signature.thisParameter, false);
1761
+ return undefined;
1762
+ }
1763
+ symbolToParameterDeclaration(parameterSymbol, preserveModifierFlags) {
1764
+ const c = this.c;
1765
+ const parameterDeclaration = getEffectiveParameterDeclaration(parameterSymbol);
1766
+ const parameterType = getTypeOfSymbol(c, parameterSymbol);
1767
+ const parameterTypeNode = this.serializeTypeForDeclaration(parameterDeclaration, parameterType, parameterSymbol, true);
1768
+ let modifiers = undefined;
1769
+ if ((this.flags & 8192 /* NodeBuilderFlags.OmitParameterModifiers */) === 0 &&
1770
+ preserveModifierFlags &&
1771
+ parameterDeclaration !== undefined) {
1772
+ const original = getModifiers(parameterDeclaration);
1773
+ if (original !== undefined) {
1774
+ // Copies keep the source positions and flags, as tsgo does; its positions are UTF-8 offsets.
1775
+ const text = getSourceFileOfNode(parameterDeclaration).text;
1776
+ const clones = [];
1777
+ for (const m of original.nodes) {
1778
+ if (!isModifierKind(m.kind))
1779
+ continue;
1780
+ const clone = m.deepClone();
1781
+ clone.pos = utf8Offset(text, m.pos) | 0;
1782
+ clone.end = utf8Offset(text, m.end) | 0;
1783
+ clones.push(clone);
1784
+ }
1785
+ modifiers = this.modifierList(clones);
1786
+ }
1787
+ }
1788
+ const isRest = (parameterDeclaration instanceof ParameterDeclaration && parameterDeclaration.dotDotDotToken !== undefined) ||
1789
+ (parameterSymbol.checkFlags & 32768 /* CheckFlags.RestParameter */) !== 0;
1790
+ const name = this.parameterToParameterDeclarationName(parameterSymbol, parameterDeclaration);
1791
+ const isOptional = (parameterDeclaration !== undefined && isOptionalParameter(c, parameterDeclaration)) ||
1792
+ (parameterSymbol.checkFlags & 16384 /* CheckFlags.OptionalParameter */) !== 0;
1793
+ const parameterNode = this.created(new ParameterDeclaration(modifiers, isRest ? this.token(25 /* SyntaxKind.DotDotDotToken */) : undefined, name, isOptional ? this.token(57 /* SyntaxKind.QuestionToken */) : undefined, parameterTypeNode, undefined));
1794
+ this.approximateLength += parameterSymbol.name.length + 3;
1795
+ return parameterNode;
1796
+ }
1797
+ parameterToParameterDeclarationName(parameterSymbol, parameterDeclaration) {
1798
+ const name = parameterDeclaration === undefined ? undefined : getName(parameterDeclaration);
1799
+ if (name === undefined)
1800
+ return this.identifier(parameterSymbol.name);
1801
+ switch (name.kind) {
1802
+ case 79 /* SyntaxKind.Identifier */: {
1803
+ const cloned = this.cloneSynthesized(name);
1804
+ this.context.setEmitFlags(cloned, 131072 /* EmitFlags.NoAsciiEscaping */);
1805
+ return cloned;
1806
+ }
1807
+ case 167 /* SyntaxKind.QualifiedName */: {
1808
+ const cloned = this.cloneSynthesized(name.right);
1809
+ this.context.setEmitFlags(cloned, 131072 /* EmitFlags.NoAsciiEscaping */);
1810
+ return cloned;
1811
+ }
1812
+ }
1813
+ return cloneBindingName(this, name);
1814
+ }
1815
+ /**
1816
+ * A copy of `node`'s subtree without positions, as tsgo's `DeepCloneNode`: each copy has its
1817
+ * node as original, and so its emit flags.
1818
+ */
1819
+ deepCloneNode(node) {
1820
+ const clone = node.deepClone();
1821
+ clearPositions(clone);
1822
+ linkClones(this.context, clone, node);
1823
+ return clone;
1824
+ }
1825
+ /** A copy of `node` without positions. */
1826
+ cloneSynthesized(node) {
1827
+ const clone = node.deepClone();
1828
+ clearPositions(clone);
1829
+ return clone;
1830
+ }
1831
+ /**
1832
+ * The type node for `t` declared by `declaration` (or `symbol`'s declaration). A symbol's own
1833
+ * `unique symbol` type is written as such rather than `typeof symbol`.
1834
+ */
1835
+ serializeTypeForDeclaration(declaration, type, symbol, tryReuse) {
1836
+ const c = this.c;
1837
+ if (declaration === undefined && symbol !== undefined)
1838
+ declaration = symbol.valueDeclaration ?? (symbol.declarations.length > 0 ? symbol.declarations[0] : undefined);
1839
+ if (symbol === undefined && declaration !== undefined)
1840
+ symbol = getSymbolOfDeclaration(c, declaration);
1841
+ let t = type;
1842
+ if (t === undefined && symbol !== undefined) {
1843
+ t = this.enclosingSymbolTypes.get(getSymbolId(symbol));
1844
+ if (t === undefined) {
1845
+ if ((symbol.flags & 98304 /* SymbolFlags.Accessor */) !== 0 &&
1846
+ declaration !== undefined &&
1847
+ declaration.kind === 179 /* SyntaxKind.SetAccessor */)
1848
+ t = instantiateType(c, getWriteTypeOfSymbol(c, symbol), this.mapper);
1849
+ else if ((symbol.flags & (2048 /* SymbolFlags.TypeLiteral */ | 131072 /* SymbolFlags.Signature */)) === 0)
1850
+ t = instantiateType(c, getWidenedLiteralType(c, getTypeOfSymbol(c, symbol)), this.mapper);
1851
+ else
1852
+ t = c.errorType;
1853
+ }
1854
+ }
1855
+ if (t === undefined)
1856
+ t = c.errorType;
1857
+ if (this.pseudo !== undefined)
1858
+ return this.serializeTypeForDeclarationReusing(declaration, t, symbol, tryReuse);
1859
+ if (declaration !== undefined &&
1860
+ declaration.kind === 170 /* SyntaxKind.Parameter */ &&
1861
+ requiresAddingImplicitUndefined(c, declaration, this.enclosingDeclaration))
1862
+ t = getOptionalType(c, t, false);
1863
+ const savedFlags = this.flags;
1864
+ if ((t.flags & 16384 /* TypeFlags.UniqueESSymbol */) !== 0 &&
1865
+ symbol !== undefined &&
1866
+ t.symbol === symbol &&
1867
+ (this.enclosingDeclaration === undefined || this.isDeclaredInEnclosingFile(symbol)))
1868
+ this.flags |= 1048576 /* NodeBuilderFlags.AllowUniqueESSymbolType */;
1869
+ const result = this.typeToTypeNode(t);
1870
+ this.flags = savedFlags;
1871
+ return result ?? this.keyword(132 /* SyntaxKind.AnyKeyword */);
1872
+ }
1873
+ /** `serializeTypeForDeclaration` with declaration emit's reuse of what the source wrote. */
1874
+ serializeTypeForDeclarationReusing(declaration, typeIn, symbol, tryReuse) {
1875
+ const c = this.c;
1876
+ const pseudo = this.pseudo;
1877
+ let t = typeIn;
1878
+ const isPropertyLike = declaration !== undefined &&
1879
+ (declaration.kind === 170 /* SyntaxKind.Parameter */ ||
1880
+ declaration.kind === 172 /* SyntaxKind.PropertySignature */ ||
1881
+ declaration.kind === 173 /* SyntaxKind.PropertyDeclaration */);
1882
+ const requiresAddingUndefined = isPropertyLike &&
1883
+ requiresAddingImplicitUndefinedForDeclaration(c, declaration, symbol, this.enclosingDeclaration);
1884
+ if (requiresAddingUndefined && declaration.kind === 170 /* SyntaxKind.Parameter */)
1885
+ t = getOptionalType(c, t, false);
1886
+ const savedFlags = this.flags;
1887
+ if ((t.flags & 16384 /* TypeFlags.UniqueESSymbol */) !== 0 &&
1888
+ symbol !== undefined &&
1889
+ t.symbol === symbol &&
1890
+ (this.enclosingDeclaration === undefined || this.isDeclaredInEnclosingFile(symbol)))
1891
+ this.flags |= 1048576 /* NodeBuilderFlags.AllowUniqueESSymbolType */;
1892
+ let result = undefined;
1893
+ let reportedInferenceFallback = false;
1894
+ if (tryReuse &&
1895
+ this.enclosingDeclaration !== undefined &&
1896
+ declaration !== undefined &&
1897
+ symbol !== undefined &&
1898
+ (isAccessorKind(declaration) ||
1899
+ (hasInferredTypeKind(declaration) &&
1900
+ (declaration.flags & 16 /* NodeFlags.Synthesized */) === 0 &&
1901
+ (t.objectFlags & 196608 /* ObjectFlags.RequiresWidening */) === 0))) {
1902
+ const remove = this.addSymbolTypeToContext(symbol, t);
1903
+ let pt = isAccessorKind(declaration)
1904
+ ? pseudo.getTypeOfAccessor(declaration)
1905
+ : pseudo.getTypeOfDeclaration(declaration);
1906
+ if (pt.kind === 2 /* PseudoTypeKind.NoResult */ && declaration.kind === 227 /* SyntaxKind.BinaryExpression */) {
1907
+ // The first annotated assignment declares the type for the rest.
1908
+ for (const d of symbol.declarations)
1909
+ if (getType(d) !== undefined) {
1910
+ pt = pseudo.getTypeOfDeclaration(d);
1911
+ break;
1912
+ }
1913
+ }
1914
+ const reportErrors = !this.suppressReportInferenceFallback;
1915
+ if (pseudoTypeEquivalentToType(this, pt, t, !requiresAddingUndefined && isPropertyLike && hasQuestionToken(declaration), reportErrors)) {
1916
+ const ptt = pseudoTypeToType(this, pt);
1917
+ if (ptt !== undefined &&
1918
+ requiresAddingUndefined &&
1919
+ containsNonMissingUndefinedType(c, t) &&
1920
+ !containsNonMissingUndefinedType(c, ptt))
1921
+ pt = new PseudoUnionType([pt, pseudoUndefinedType]);
1922
+ result = pseudoTypeToNodeWithCheckerFallback(this, pt, t);
1923
+ }
1924
+ else {
1925
+ // Errors reported inside an inferred pseudo-type aren't reported again by the fallback.
1926
+ reportedInferenceFallback = reportErrors && pt instanceof InferredType && pt.errorNodes.length > 0;
1927
+ let shouldAddUndefined = false;
1928
+ if (requiresAddingUndefined) {
1929
+ const ptt = pseudoTypeToType(this, pt);
1930
+ shouldAddUndefined =
1931
+ ptt !== undefined ? !containsNonMissingUndefinedType(c, ptt) : !couldAlreadyReferToUndefined(pt);
1932
+ }
1933
+ if (shouldAddUndefined) {
1934
+ pt = new PseudoUnionType([pt, pseudoUndefinedType]);
1935
+ if (pseudoTypeEquivalentToType(this, pt, t, false, reportErrors)) {
1936
+ result = pseudoTypeToNodeWithCheckerFallback(this, pt, t);
1937
+ reportedInferenceFallback = false;
1938
+ }
1939
+ }
1940
+ }
1941
+ remove();
1942
+ }
1943
+ if (result === undefined) {
1944
+ if (reportedInferenceFallback) {
1945
+ const oldSuppress = this.suppressReportInferenceFallback;
1946
+ this.suppressReportInferenceFallback = true;
1947
+ result = this.typeToTypeNode(t);
1948
+ this.suppressReportInferenceFallback = oldSuppress;
1949
+ }
1950
+ else
1951
+ result = this.typeToTypeNode(t);
1952
+ }
1953
+ this.flags = savedFlags;
1954
+ return result ?? this.keyword(132 /* SyntaxKind.AnyKeyword */);
1955
+ }
1956
+ /** The return type node of `signature`; `any` is omitted with `SuppressAnyReturnType`. */
1957
+ serializeReturnTypeForSignature(signature) {
1958
+ return this.serializeReturnTypeForSignatureEx(signature, true);
1959
+ }
1960
+ /** `serializeReturnTypeForSignature`; with `tryReuse` and a pseudochecker, the source's return type where it matches. */
1961
+ serializeReturnTypeForSignatureEx(signature, tryReuse) {
1962
+ const c = this.c;
1963
+ const suppressAny = (this.flags & 256 /* NodeBuilderFlags.SuppressAnyReturnType */) !== 0;
1964
+ const savedFlags = this.flags;
1965
+ // Only top-level `any`s are suppressed.
1966
+ if (suppressAny)
1967
+ this.flags &= ~256 /* NodeBuilderFlags.SuppressAnyReturnType */;
1968
+ let returnType;
1969
+ const declaration = signature.declaration;
1970
+ if (declaration !== undefined && (declaration.flags & 16 /* NodeFlags.Synthesized */) === 0) {
1971
+ const symbol = getSymbolOfDeclaration(c, declaration);
1972
+ const known = symbol !== undefined ? this.enclosingSymbolTypes.get(getSymbolId(symbol)) : undefined;
1973
+ returnType = known ?? instantiateType(c, getReturnTypeOfSignature(c, signature), this.mapper);
1974
+ }
1975
+ else
1976
+ returnType = getReturnTypeOfSignature(c, signature);
1977
+ let returnTypeNode = undefined;
1978
+ if (!(suppressAny && (returnType.flags & 1 /* TypeFlags.Any */) !== 0)) {
1979
+ if (this.pseudo !== undefined &&
1980
+ tryReuse &&
1981
+ this.enclosingDeclaration !== undefined &&
1982
+ declaration !== undefined &&
1983
+ (declaration.flags & 16 /* NodeFlags.Synthesized */) === 0)
1984
+ returnTypeNode = this.serializeReturnTypeReusing(signature, declaration, returnType);
1985
+ if (returnTypeNode === undefined)
1986
+ returnTypeNode = this.serializeInferredReturnTypeForSignature(signature, returnType);
1987
+ }
1988
+ if (returnTypeNode === undefined && !suppressAny)
1989
+ returnTypeNode = this.keyword(132 /* SyntaxKind.AnyKeyword */);
1990
+ this.flags = savedFlags;
1991
+ return returnTypeNode;
1992
+ }
1993
+ serializeReturnTypeReusing(signature, declaration, returnType) {
1994
+ const declarationSymbol = getSymbolOfDeclaration(this.c, declaration);
1995
+ if (declarationSymbol === undefined)
1996
+ return undefined;
1997
+ const restore = this.addSymbolTypeToContext(declarationSymbol, returnType);
1998
+ let result = undefined;
1999
+ let pt = this.pseudo.getReturnTypeOfSignature(declaration);
2000
+ if (pseudoTypeEquivalentToType(this, pt, returnType, false, !this.suppressReportInferenceFallback)) {
2001
+ // The pseudochecker doesn't infer type predicates, which the checker may have.
2002
+ const typePredicate = getTypePredicateOfSignature(this.c, signature);
2003
+ if (typePredicate !== undefined && !pseudoReturnTypeMatchesPredicate(this, pt, typePredicate)) {
2004
+ if (!this.suppressReportInferenceFallback)
2005
+ this.tracker.reportInferenceFallback(declaration);
2006
+ pt = undefined;
2007
+ }
2008
+ if (pt !== undefined)
2009
+ result = pseudoTypeToNodeWithCheckerFallback(this, pt, returnType);
2010
+ }
2011
+ restore();
2012
+ return result;
2013
+ }
2014
+ serializeInferredReturnTypeForSignature(signature, returnType) {
2015
+ const oldSuppress = this.suppressReportInferenceFallback;
2016
+ this.suppressReportInferenceFallback = true;
2017
+ const typePredicate = getTypePredicateOfSignature(this.c, signature);
2018
+ let returnTypeNode;
2019
+ if (typePredicate !== undefined) {
2020
+ const predicate = this.mapper !== undefined ? instantiateTypePredicate(this.c, typePredicate, this.mapper) : typePredicate;
2021
+ returnTypeNode = this.typePredicateToTypePredicateNode(predicate);
2022
+ }
2023
+ else
2024
+ returnTypeNode = this.typeToTypeNode(returnType);
2025
+ this.suppressReportInferenceFallback = oldSuppress;
2026
+ return returnTypeNode;
2027
+ }
2028
+ typePredicateToTypePredicateNode(predicate) {
2029
+ const isAsserts = predicate.kind === 2 /* TypePredicateKind.AssertsThis */ || predicate.kind === 3 /* TypePredicateKind.AssertsIdentifier */;
2030
+ let parameterName;
2031
+ if (predicate.kind === 1 /* TypePredicateKind.Identifier */ || predicate.kind === 3 /* TypePredicateKind.AssertsIdentifier */) {
2032
+ parameterName = this.identifier(predicate.parameterName);
2033
+ this.context.setEmitFlags(parameterName, 131072 /* EmitFlags.NoAsciiEscaping */);
2034
+ }
2035
+ else
2036
+ parameterName = this.created(new ThisTypeNode());
2037
+ const typeNode = predicate.type !== undefined ? this.typeToTypeNode(predicate.type) : undefined;
2038
+ return this.created(new TypePredicateNode(isAsserts ? this.token(130 /* SyntaxKind.AssertsKeyword */) : undefined, parameterName, typeNode));
2039
+ }
2040
+ // ---- Existing type nodes
2041
+ /** The type of a type node, instantiated with the scope's mapper; with `noMappedTypes`, undefined if that changes it. */
2042
+ getTypeFromTypeNode(node, noMappedTypes) {
2043
+ const t = getTypeFromTypeNode(this.c, node);
2044
+ if (this.mapper === undefined)
2045
+ return t;
2046
+ const instantiated = instantiateType(this.c, t, this.mapper);
2047
+ if (noMappedTypes && instantiated !== t)
2048
+ return undefined;
2049
+ return instantiated;
2050
+ }
2051
+ typeNodeIsEquivalentToType(annotatedDeclaration, t, typeFromTypeNode) {
2052
+ if (typeFromTypeNode === t)
2053
+ return true;
2054
+ if (annotatedDeclaration === undefined)
2055
+ return false;
2056
+ if (getQuestionToken(annotatedDeclaration) !== undefined)
2057
+ return getTypeWithFacts(this.c, t, 524288 /* TypeFacts.NEUndefined */) === typeFromTypeNode;
2058
+ return false;
2059
+ }
2060
+ tryReuseExistingNonParameterTypeNode(existing, t, host, annotationType) {
2061
+ const annotation = annotationType ?? this.getTypeFromTypeNode(existing, true);
2062
+ if (annotation !== undefined &&
2063
+ this.typeNodeIsEquivalentToType(host ?? this.enclosingDeclaration, t, annotation) &&
2064
+ canReuseExistingJSTypeNode(this, existing, t))
2065
+ return tryReuseExistingNode(this, existing);
2066
+ return undefined;
2067
+ }
2068
+ /**
2069
+ * A copy of `range` positioned like `location`: without positions unless both are in the file
2070
+ * being written, with `location` as its original.
2071
+ */
2072
+ setTextRange(range, location) {
2073
+ // Always a copy, so positions from other files never leak into the result. As tsgo's
2074
+ // shallow clone, the copy and its descendants keep their emit flags.
2075
+ const result = range.deepClone();
2076
+ copyEmitNodes(this.context, result, range, true);
2077
+ result.pos = -1;
2078
+ result.end = -1;
2079
+ this.context.setOriginal(result, range);
2080
+ if (location === undefined || result === location)
2081
+ return result;
2082
+ let original = this.context.getOriginal(result);
2083
+ while (original !== undefined && original !== location)
2084
+ original = this.context.getOriginal(original);
2085
+ if (original === undefined)
2086
+ this.context.setOriginalEx(result, location, true);
2087
+ if (this.enclosingFile !== undefined &&
2088
+ this.enclosingFile === getSourceFileOfNode(this.context.mostOriginal(location))) {
2089
+ result.pos = location.pos;
2090
+ result.end = location.end;
2091
+ }
2092
+ else {
2093
+ result.pos = -1;
2094
+ result.end = -1;
2095
+ }
2096
+ return result;
2097
+ }
2098
+ }
2099
+ // ---- Helpers
2100
+ function asBindingPattern(node) {
2101
+ if (node === undefined)
2102
+ return undefined;
2103
+ if (node instanceof BindingPattern)
2104
+ return node;
2105
+ return undefined;
2106
+ }
2107
+ function typesAreSameReference(a, b) {
2108
+ return a === b || (a.symbol !== undefined && a.symbol === b.symbol) || (a.alias !== undefined && a.alias === b.alias);
2109
+ }
2110
+ /** Internal names other than late-bound and private names. */
2111
+ function isReservedMemberName(name) {
2112
+ return (name.length >= 2 && name.charCodeAt(0) === 0xfffe && name.charCodeAt(1) !== 0x40 && name.charCodeAt(1) !== 0x23);
2113
+ }
2114
+ function isPrivateIdentifierSymbol(symbol) {
2115
+ return symbol.name.startsWith('￾#');
2116
+ }
2117
+ function isClassInstanceSide(c, t) {
2118
+ const symbol = t.symbol;
2119
+ return (symbol !== undefined &&
2120
+ (symbol.flags & 32 /* SymbolFlags.Class */) !== 0 &&
2121
+ (t === getDeclaredTypeOfClassOrInterface(c, symbol) ||
2122
+ ((t.flags & 1048576 /* TypeFlags.Object */) !== 0 && (t.objectFlags & 67108864 /* ObjectFlags.IsClassInstanceClone */) !== 0)));
2123
+ }
2124
+ function getTypeAliasForTypeLiteral(c, t) {
2125
+ const symbol = t.symbol;
2126
+ if (symbol === undefined || (symbol.flags & 2048 /* SymbolFlags.TypeLiteral */) === 0 || symbol.declarations.length === 0)
2127
+ return undefined;
2128
+ let node = symbol.declarations[0].parent;
2129
+ while (node !== undefined && node.kind === 197 /* SyntaxKind.ParenthesizedType */)
2130
+ node = node.parent;
2131
+ if (node !== undefined && node.kind === 266 /* SyntaxKind.TypeAliasDeclaration */)
2132
+ return getSymbolOfDeclaration(c, node);
2133
+ return undefined;
2134
+ }
2135
+ /** A copy of `t`, whose members are `resolved`, without its abstract construct signatures. */
2136
+ function getResolvedTypeWithoutAbstractConstructSignatures(c, t, resolved) {
2137
+ if (resolved.constructSignatures.length === 0)
2138
+ return t;
2139
+ const side = sideOf(c, t);
2140
+ if (side.objectTypeWithoutAbstractConstructSignatures !== undefined)
2141
+ return side.objectTypeWithoutAbstractConstructSignatures;
2142
+ const constructSignatures = resolved.constructSignatures.filter((s) => (s.flags & 8 /* SignatureFlags.Abstract */) === 0);
2143
+ if (constructSignatures.length === resolved.constructSignatures.length) {
2144
+ side.objectTypeWithoutAbstractConstructSignatures = t;
2145
+ return t;
2146
+ }
2147
+ const copy = newAnonymousType(c, t.symbol);
2148
+ const copied = membersHolder(c, copy);
2149
+ copied.objectFlags |= 2097152 /* ObjectFlags.MembersResolved */;
2150
+ copied.members = resolved.members;
2151
+ copied.properties = resolved.properties;
2152
+ copied.callSignatures = resolved.callSignatures;
2153
+ copied.constructSignatures = constructSignatures;
2154
+ copied.indexInfos = resolved.indexInfos;
2155
+ side.objectTypeWithoutAbstractConstructSignatures = copy;
2156
+ sideOf(c, copy).objectTypeWithoutAbstractConstructSignatures = copy;
2157
+ return copy;
2158
+ }
2159
+ function getNameFromIndexInfo(info) {
2160
+ const declaration = info.declaration;
2161
+ if (declaration === undefined)
2162
+ return 'x';
2163
+ const parameters = getParameters(declaration);
2164
+ const name = parameters !== undefined && parameters.nodes.length > 0 ? getName(parameters.nodes[0]) : undefined;
2165
+ return name === undefined ? 'x' : declarationNameToString(getSourceFileOfNode(name), name);
2166
+ }
2167
+ function hasAccessorKeyword(node) {
2168
+ const modifiers = getModifiers(node);
2169
+ return modifiers !== undefined && modifiers.nodes.some((m) => m.kind === 128 /* SyntaxKind.AccessorKeyword */);
2170
+ }
2171
+ function getEffectiveConstraint(typeParameter) {
2172
+ return typeParameter instanceof TypeParameterDeclaration ? typeParameter.constraint : undefined;
2173
+ }
2174
+ function getTypeParameterModifiers(tp) {
2175
+ let flags = 0 /* ModifierFlags.None */;
2176
+ if (tp.symbol !== undefined)
2177
+ for (const d of tp.symbol.declarations)
2178
+ flags |= getCombinedModifierFlags(d);
2179
+ return flags & (8192 /* ModifierFlags.In */ | 16384 /* ModifierFlags.Out */ | 4096 /* ModifierFlags.Const */);
2180
+ }
2181
+ function getEffectiveParameterDeclaration(symbol) {
2182
+ const parameter = getDeclarationOfKind(symbol, 170 /* SyntaxKind.Parameter */);
2183
+ if (parameter !== undefined)
2184
+ return parameter;
2185
+ if ((symbol.flags & 33554432 /* SymbolFlags.Transient */) === 0)
2186
+ return getDeclarationOfKind(symbol, 333 /* SyntaxKind.JSDocParameterTag */);
2187
+ return undefined;
2188
+ }
2189
+ function isPropertyAccessEntityNameExpression(node) {
2190
+ return node.kind === 212 /* SyntaxKind.PropertyAccessExpression */ && isEntityNameExpression(node, false);
2191
+ }
2192
+ /** Whether an existing type reference node can stand for `t`: JS `Foo` meaning `Foo<any>` can't. */
2193
+ export function canReuseExistingJSTypeNode(b, existing, t) {
2194
+ const c = b.c;
2195
+ if (getIntendedTypeFromJSDocTypeReference(c, existing) !== undefined)
2196
+ return false;
2197
+ if ((t.objectFlags & 4 /* ObjectFlags.Reference */) === 0 || !(existing instanceof TypeReferenceNode))
2198
+ return true;
2199
+ getTypeFromTypeNode(c, existing);
2200
+ const symbol = c.resolvedSymbols.get(existing.id);
2201
+ if (symbol === undefined)
2202
+ return true;
2203
+ const existingTarget = getDeclaredTypeOfSymbol(c, symbol);
2204
+ if (existingTarget !== t.target)
2205
+ return true;
2206
+ const written = existing.typeArguments === undefined ? 0 : existing.typeArguments.nodes.length;
2207
+ return written >= getMinTypeArgumentCount(c, existingTarget.typeParameters());
2208
+ }
2209
+ /** Copies the emit nodes of `original`'s descendants to the same nodes of its deep clone `clone`. */
2210
+ function copyEmitNodes(context, clone, original, isRoot) {
2211
+ // The root is a copy, which gets the original's emit node without its comments when the
2212
+ // original is set; the descendants stand for the original's own.
2213
+ if (!isRoot)
2214
+ context.copyEmitNode(clone, original);
2215
+ const cloneChildren = new ChildCollector();
2216
+ clone.forEachChild(cloneChildren);
2217
+ const originalChildren = new ChildCollector();
2218
+ original.forEachChild(originalChildren);
2219
+ const count = Math.min(cloneChildren.nodes.length, originalChildren.nodes.length);
2220
+ for (let i = 0; i < count; i++)
2221
+ copyEmitNodes(context, cloneChildren.nodes[i], originalChildren.nodes[i], false);
2222
+ }
2223
+ class ChildCollector extends NodeVisitor {
2224
+ nodes = [];
2225
+ lists = [];
2226
+ visitNode(node) {
2227
+ this.nodes.push(node);
2228
+ return false;
2229
+ }
2230
+ visitList(list) {
2231
+ this.lists.push(list);
2232
+ return super.visitList(list);
2233
+ }
2234
+ }
2235
+ /** Sets each node of `original`'s subtree as the original of its copy in `clone`, keeping trailing commas. */
2236
+ function linkClones(context, clone, original) {
2237
+ if (context.getOriginal(clone) === undefined)
2238
+ context.setOriginal(clone, original);
2239
+ const cloneChildren = new ChildCollector();
2240
+ clone.forEachChild(cloneChildren);
2241
+ const originalChildren = new ChildCollector();
2242
+ original.forEachChild(originalChildren);
2243
+ const lists = Math.min(cloneChildren.lists.length, originalChildren.lists.length);
2244
+ for (let i = 0; i < lists; i++) {
2245
+ const list = cloneChildren.lists[i];
2246
+ if (originalChildren.lists[i].hasTrailingComma() && list.nodes.length > 0) {
2247
+ const last = list.nodes[list.nodes.length - 1];
2248
+ last.pos = -2;
2249
+ last.end = -2;
2250
+ }
2251
+ }
2252
+ const count = Math.min(cloneChildren.nodes.length, originalChildren.nodes.length);
2253
+ for (let i = 0; i < count; i++)
2254
+ linkClones(context, cloneChildren.nodes[i], originalChildren.nodes[i]);
2255
+ }
2256
+ /** A copy of a binding name without initializers, written on one line. */
2257
+ function cloneBindingName(b, node) {
2258
+ node.forEachChild(new ComputedNameTracker(b));
2259
+ const clone = node.deepClone();
2260
+ removeBindingInitializers(clone);
2261
+ clearPositions(clone);
2262
+ keepTrailingCommas(clone, node);
2263
+ b.context.setEmitFlags(clone, 1 /* EmitFlags.SingleLine */ | 131072 /* EmitFlags.NoAsciiEscaping */);
2264
+ return clone;
2265
+ }
2266
+ /**
2267
+ * Marks the element lists of `clone` that have a trailing comma in `original`, which the printer
2268
+ * keeps: tsgo's copy keeps the lists' positions.
2269
+ */
2270
+ function keepTrailingCommas(clone, original) {
2271
+ if (!(clone instanceof BindingPattern) || !(original instanceof BindingPattern))
2272
+ return;
2273
+ // As tsgo's deep clone: a last element ending before the list's end.
2274
+ if (original.elements.hasTrailingComma() && clone.elements.nodes.length > 0) {
2275
+ const last = clone.elements.nodes[clone.elements.nodes.length - 1];
2276
+ last.pos = -2;
2277
+ last.end = -2;
2278
+ }
2279
+ const elements = clone.elements.nodes;
2280
+ const originals = original.elements.nodes;
2281
+ for (let i = 0; i < elements.length && i < originals.length; i++) {
2282
+ const element = elements[i];
2283
+ const originalElement = originals[i];
2284
+ if (element instanceof BindingElement &&
2285
+ originalElement instanceof BindingElement &&
2286
+ element.name !== undefined &&
2287
+ originalElement.name !== undefined)
2288
+ keepTrailingCommas(element.name, originalElement.name);
2289
+ }
2290
+ }
2291
+ function removeBindingInitializers(node) {
2292
+ if (node instanceof BindingPattern) {
2293
+ for (const e of node.elements.nodes)
2294
+ removeBindingInitializers(e);
2295
+ return;
2296
+ }
2297
+ if (node instanceof BindingElement) {
2298
+ node.initializer = undefined;
2299
+ if (node.name !== undefined)
2300
+ removeBindingInitializers(node.name);
2301
+ }
2302
+ }
2303
+ /** Tracks the late-bound computed names of a binding name, which the copy writes. */
2304
+ class ComputedNameTracker extends NodeVisitor {
2305
+ b;
2306
+ constructor(b) {
2307
+ super();
2308
+ this.b = b;
2309
+ }
2310
+ visitNode(node) {
2311
+ if (node.kind === 168 /* SyntaxKind.ComputedPropertyName */ && isLateBindableName(this.b.c, node))
2312
+ this.b.trackComputedName(getExpression(node), this.b.enclosingDeclaration);
2313
+ return node.forEachChild(this);
2314
+ }
2315
+ }
2316
+ class PositionClearer extends NodeVisitor {
2317
+ visitNode(node) {
2318
+ clearPositions(node);
2319
+ return false;
2320
+ }
2321
+ // A list keeping its range would print a trailing comma after its now unpositioned nodes.
2322
+ visitList(list) {
2323
+ list.pos = -1;
2324
+ list.end = -1;
2325
+ for (const node of list.nodes)
2326
+ clearPositions(node);
2327
+ return false;
2328
+ }
2329
+ }
2330
+ /** Drops the positions of a copied subtree; its flags stay those of the original, as in tsgo. */
2331
+ export function clearPositions(node) {
2332
+ node.pos = -1;
2333
+ node.end = -1;
2334
+ node.forEachChild(new PositionClearer());
2335
+ }
2336
+ /** Whether a parameter is optional in its signature, as tsgo's `isOptionalParameter`. */
2337
+ export function isOptionalParameter(c, node) {
2338
+ if (!(node instanceof ParameterDeclaration))
2339
+ return false;
2340
+ if (node.questionToken !== undefined)
2341
+ return true;
2342
+ const parent = node.parent;
2343
+ const parameters = getParameters(parent);
2344
+ const index = parameters === undefined ? -1 : parameters.nodes.indexOf(node);
2345
+ if (node.initializer !== undefined) {
2346
+ const signature = getSignatureFromDeclaration(c, parent);
2347
+ // Without treating `void` parameters as optional, as grammar checks use this.
2348
+ let minArgumentCount = signature.minArgumentCount;
2349
+ if (signature.hasRestParameter()) {
2350
+ const restType = getTypeOfSymbol(c, signature.parameters[signature.parameters.length - 1]);
2351
+ if (isTupleType(restType)) {
2352
+ const tuple = restType.target;
2353
+ let requiredCount = tuple.fixedLength;
2354
+ for (let i = 0; i < tuple.elementInfos.length; i++)
2355
+ if ((tuple.elementInfos[i].flags & 1 /* ElementFlags.Required */) === 0) {
2356
+ requiredCount = i;
2357
+ break;
2358
+ }
2359
+ if (requiredCount > 0)
2360
+ minArgumentCount = signature.parameters.length - 1 + requiredCount;
2361
+ }
2362
+ }
2363
+ return index >= minArgumentCount;
2364
+ }
2365
+ const iife = getImmediatelyInvokedFunctionExpression(parent);
2366
+ if (iife !== undefined)
2367
+ return (node.type === undefined && node.dotDotDotToken === undefined && index >= getEffectiveCallArguments(c, iife).length);
2368
+ return false;
2369
+ }
2370
+ /** Whether a parameter's written type needs `| undefined`: initialized before a required parameter. */
2371
+ export function requiresAddingImplicitUndefined(c, parameter, enclosingDeclaration) {
2372
+ if (!(parameter instanceof ParameterDeclaration) || (parameter.flags & 16 /* NodeFlags.Synthesized */) !== 0)
2373
+ return false;
2374
+ const isPropertyParameter = hasSyntacticModifier(parameter, 31 /* ModifierFlags.ParameterPropertyModifier */);
2375
+ let required = false;
2376
+ if (c.strictNullChecks && !isOptionalParameter(c, parameter) && parameter.initializer !== undefined)
2377
+ required =
2378
+ !isPropertyParameter || (enclosingDeclaration !== undefined && isFunctionLikeDeclaration(enclosingDeclaration));
2379
+ const optionalProperty = c.strictNullChecks &&
2380
+ isOptionalParameter(c, parameter) &&
2381
+ parameter.initializer === undefined &&
2382
+ isPropertyParameter;
2383
+ if (!required && !optionalProperty)
2384
+ return false;
2385
+ const typeNode = parameter.type;
2386
+ if (typeNode === undefined)
2387
+ return true;
2388
+ const t = getTypeFromTypeNode(c, typeNode);
2389
+ return !isErrorType(c, t) && !containsUndefinedType(c, t);
2390
+ }
2391
+ function containsUndefinedType(c, t) {
2392
+ const types = (t.flags & 134217728 /* TypeFlags.Union */) !== 0 ? t.types : [t];
2393
+ return (types[0].flags & 4 /* TypeFlags.Undefined */) !== 0;
2394
+ }
2395
+ function isFunctionLikeDeclaration(node) {
2396
+ switch (node.kind) {
2397
+ case 263 /* SyntaxKind.FunctionDeclaration */:
2398
+ case 175 /* SyntaxKind.MethodDeclaration */:
2399
+ case 177 /* SyntaxKind.Constructor */:
2400
+ case 178 /* SyntaxKind.GetAccessor */:
2401
+ case 179 /* SyntaxKind.SetAccessor */:
2402
+ case 219 /* SyntaxKind.FunctionExpression */:
2403
+ case 220 /* SyntaxKind.ArrowFunction */:
2404
+ return true;
2405
+ }
2406
+ return false;
2407
+ }
2408
+ /** Whether the first identifier of an entity name can be named from `enclosingDeclaration`. */
2409
+ export function isEntityNameVisible(c, entityName, enclosingDeclaration, shouldComputeAliasesToMakeVisible = false) {
2410
+ if ((entityName.flags & 16 /* NodeFlags.Synthesized */) !== 0)
2411
+ return new SymbolAccessibilityResult(1 /* SymbolAccessibility.NotAccessible */, [], '', undefined, '');
2412
+ const meaning = getMeaningOfEntityNameReference(entityName);
2413
+ const firstIdentifier = getFirstIdentifier(entityName);
2414
+ const text = getText(firstIdentifier);
2415
+ const symbol = resolveName(c, enclosingDeclaration, text, meaning, undefined, false, false);
2416
+ if (symbol !== undefined && (symbol.flags & 262144 /* SymbolFlags.TypeParameter */) !== 0 && (meaning & 788968 /* SymbolFlags.Type */) !== 0)
2417
+ return accessible([]);
2418
+ if (symbol === undefined && firstIdentifier.kind === 109 /* SyntaxKind.ThisKeyword */) {
2419
+ const container = getThisContainer(firstIdentifier, false, false);
2420
+ const sym = container === undefined ? undefined : getSymbolOfDeclaration(c, container);
2421
+ if (isSymbolAccessible(c, sym, enclosingDeclaration, meaning, false).accessibility === 0 /* SymbolAccessibility.Accessible */)
2422
+ return accessible([]);
2423
+ }
2424
+ if (symbol === undefined)
2425
+ return new SymbolAccessibilityResult(3 /* SymbolAccessibility.NotResolved */, [], text, firstIdentifier, '');
2426
+ const visible = hasVisibleDeclarations(c, symbol, shouldComputeAliasesToMakeVisible);
2427
+ if (visible !== undefined)
2428
+ return visible;
2429
+ return new SymbolAccessibilityResult(1 /* SymbolAccessibility.NotAccessible */, [], text, firstIdentifier, '');
2430
+ }
2431
+ /**
2432
+ * The parameter lists of a signature with a tuple rest parameter spread into parameters; one
2433
+ * list per member of a union of tuples unless `skipUnionExpanding`.
2434
+ */
2435
+ export function getExpandedParameters(c, signature, skipUnionExpanding) {
2436
+ if (signature.hasRestParameter()) {
2437
+ const restIndex = signature.parameters.length - 1;
2438
+ const restSymbol = signature.parameters[restIndex];
2439
+ const restType = getTypeOfSymbol(c, restSymbol);
2440
+ if (isTupleType(restType))
2441
+ return [expandSignatureParametersWithTupleMembers(c, signature, restType, restIndex, restSymbol)];
2442
+ if (!skipUnionExpanding && (restType.flags & 134217728 /* TypeFlags.Union */) !== 0) {
2443
+ const types = restType.types;
2444
+ for (const t of types)
2445
+ if (!isTupleType(t))
2446
+ return [signature.parameters];
2447
+ const lists = [];
2448
+ for (const t of types)
2449
+ lists.push(expandSignatureParametersWithTupleMembers(c, signature, t, restIndex, restSymbol));
2450
+ return lists;
2451
+ }
2452
+ }
2453
+ return [signature.parameters];
2454
+ }
2455
+ function expandSignatureParametersWithTupleMembers(c, signature, restType, restIndex, restSymbol) {
2456
+ const elementTypes = getTypeArguments(c, restType);
2457
+ const tuple = restType.target;
2458
+ const names = getUniqueAssociatedNamesFromTupleType(c, tuple, restSymbol);
2459
+ const result = signature.parameters.slice(0, restIndex);
2460
+ for (let i = 0; i < elementTypes.length; i++) {
2461
+ const flags = tuple.elementInfos[i].flags;
2462
+ let checkFlags = 0 /* CheckFlags.None */;
2463
+ if ((flags & 12 /* ElementFlags.Variable */) !== 0)
2464
+ checkFlags = 32768 /* CheckFlags.RestParameter */;
2465
+ else if ((flags & 2 /* ElementFlags.Optional */) !== 0)
2466
+ checkFlags = 16384 /* CheckFlags.OptionalParameter */;
2467
+ const symbol = c.newSymbolWithCheckFlags(1 /* SymbolFlags.FunctionScopedVariable */, names[i], checkFlags);
2468
+ const elementType = elementTypes[i];
2469
+ c.symbolTypes.set(getSymbolId(symbol), (flags & 4 /* ElementFlags.Rest */) !== 0 ? createArrayType(c, elementType) : elementType);
2470
+ result.push(symbol);
2471
+ }
2472
+ return result;
2473
+ }
2474
+ function getUniqueAssociatedNamesFromTupleType(c, tuple, restSymbol) {
2475
+ const names = [];
2476
+ for (let i = 0; i < tuple.elementInfos.length; i++) {
2477
+ const info = tuple.elementInfos[i];
2478
+ names.push(getTupleElementLabel(c, info.flags, info.labeledDeclaration, restSymbol, i));
2479
+ }
2480
+ if (names.length === 0)
2481
+ return names;
2482
+ const duplicates = [];
2483
+ const uniqueNames = new Set();
2484
+ for (let i = 0; i < names.length; i++) {
2485
+ const name = names[i];
2486
+ if (uniqueNames.has(name))
2487
+ duplicates.push(i);
2488
+ else
2489
+ uniqueNames.add(name);
2490
+ }
2491
+ const counters = new Map();
2492
+ for (const i of duplicates) {
2493
+ const base = names[i];
2494
+ let counter = counters.get(base) ?? 1;
2495
+ let name;
2496
+ for (;;) {
2497
+ name = base + '_' + counter;
2498
+ if (uniqueNames.has(name)) {
2499
+ counter++;
2500
+ continue;
2501
+ }
2502
+ uniqueNames.add(name);
2503
+ break;
2504
+ }
2505
+ names[i] = name;
2506
+ counters.set(name, counter + 1);
2507
+ }
2508
+ return names;
2509
+ }
2510
+ /** The name a tuple element gets as a parameter. */
2511
+ export function getTupleElementLabel(c, flags, labeledDeclaration, restSymbol, index) {
2512
+ if (labeledDeclaration !== undefined)
2513
+ return getText(getName(labeledDeclaration));
2514
+ if (restSymbol !== undefined && restSymbol.valueDeclaration instanceof ParameterDeclaration)
2515
+ return getTupleElementLabelFromBindingElement(restSymbol.valueDeclaration, index, flags);
2516
+ return (restSymbol !== undefined ? restSymbol.name : 'arg') + '_' + index;
2517
+ }
2518
+ function getTupleElementLabelFromBindingElement(node, index, elementFlags) {
2519
+ const name = getName(node);
2520
+ const hasDotDotDot = (node instanceof ParameterDeclaration && node.dotDotDotToken !== undefined) ||
2521
+ (node instanceof BindingElement && node.dotDotDotToken !== undefined);
2522
+ if (name !== undefined) {
2523
+ if (name.kind === 79 /* SyntaxKind.Identifier */) {
2524
+ const text = getText(name);
2525
+ // `(...[x, y, ...z]: [number, number, ...number[]])` keeps `z`; fixed elements of a rest get suffixes.
2526
+ if (hasDotDotDot)
2527
+ return (elementFlags & 12 /* ElementFlags.Variable */) !== 0 ? text : text + '_' + index;
2528
+ return (elementFlags & 3 /* ElementFlags.Fixed */) !== 0 ? text : text + '_n';
2529
+ }
2530
+ if (name.kind === 208 /* SyntaxKind.ArrayBindingPattern */ && hasDotDotDot) {
2531
+ const elements = name.elements.nodes;
2532
+ const lastElement = elements.length > 0 ? elements[elements.length - 1] : undefined;
2533
+ const lastIsRest = lastElement instanceof BindingElement && lastElement.dotDotDotToken !== undefined;
2534
+ const elementCount = elements.length - (lastIsRest ? 1 : 0);
2535
+ if (index < elementCount) {
2536
+ const element = elements[index];
2537
+ if (element instanceof BindingElement)
2538
+ return getTupleElementLabelFromBindingElement(element, index, elementFlags);
2539
+ }
2540
+ else if (lastIsRest)
2541
+ return getTupleElementLabelFromBindingElement(lastElement, index - elementCount, elementFlags);
2542
+ }
2543
+ }
2544
+ return 'arg_' + index;
2545
+ }
2546
+ // ---- Entry points
2547
+ /**
2548
+ * The type node TypeScript would write for `type`. As in tsgo, the builder has a pseudochecker, so types
2549
+ * of declarations are written from what the source wrote where that denotes the type.
2550
+ */
2551
+ export function typeToTypeNode(c, type, enclosingDeclaration, flags, internalFlags = 0 /* NodeBuilderInternalFlags.None */, tracker = undefined) {
2552
+ const b = new NodeBuilder(c, enclosingDeclaration, flags, internalFlags, tracker);
2553
+ b.pseudo = newPseudoChecker(c);
2554
+ return b.finish(b.typeToTypeNode(type));
2555
+ }
2556
+ /** The declaration of kind `kind` TypeScript would write for `signature`, with a pseudochecker as `typeToTypeNode`. */
2557
+ export function signatureToSignatureDeclaration(c, signature, kind, enclosingDeclaration, flags, internalFlags = 0 /* NodeBuilderInternalFlags.None */, tracker = undefined) {
2558
+ const b = new NodeBuilder(c, enclosingDeclaration, flags, internalFlags, tracker);
2559
+ b.pseudo = newPseudoChecker(c);
2560
+ return b.finish(b.signatureToSignatureDeclaration(signature, kind, undefined));
2561
+ }
2562
+ /** The type format flags that are node builder flags. */
2563
+ function toNodeBuilderFlags(typeFormatFlags) {
2564
+ return (typeFormatFlags &
2565
+ (1 /* NodeBuilderFlags.NoTruncation */ |
2566
+ 2 /* NodeBuilderFlags.WriteArrayAsGenericType */ |
2567
+ 4 /* NodeBuilderFlags.GenerateNamesForShadowedTypeParams */ |
2568
+ 8 /* NodeBuilderFlags.UseStructuralFallback */ |
2569
+ 32 /* NodeBuilderFlags.WriteTypeArgumentsOfSignature */ |
2570
+ 64 /* NodeBuilderFlags.UseFullyQualifiedType */ |
2571
+ 256 /* NodeBuilderFlags.SuppressAnyReturnType */ |
2572
+ 1024 /* NodeBuilderFlags.MultilineObjectLiterals */ |
2573
+ 2048 /* NodeBuilderFlags.WriteClassExpressionAsTypeLiteral */ |
2574
+ 4096 /* NodeBuilderFlags.UseTypeOfFunction */ |
2575
+ 8192 /* NodeBuilderFlags.OmitParameterModifiers */ |
2576
+ 16384 /* NodeBuilderFlags.UseAliasDefinedOutsideCurrentScope */ |
2577
+ 1048576 /* NodeBuilderFlags.AllowUniqueESSymbolType */ |
2578
+ 8388608 /* NodeBuilderFlags.InTypeAlias */ |
2579
+ 1073741824 /* NodeBuilderFlags.UseInstantiationExpressions */ |
2580
+ 268435456 /* NodeBuilderFlags.UseSingleQuotesForStringLiteralType */ |
2581
+ 536870912 /* NodeBuilderFlags.NoTypeReduction */ |
2582
+ 33554432 /* NodeBuilderFlags.OmitThisParameter */));
2583
+ }
2584
+ /**
2585
+ * `type` as text, printed from its type node as tsgo's `TypeToStringEx` does; `typeFormatFlags`
2586
+ * are `TypeFormatFlags`. Undefined if the builder fails.
2587
+ */
2588
+ export function typeToStringFromTypeNode(c, type, enclosingDeclaration, typeFormatFlags) {
2589
+ // Serializing can resolve members and report diagnostics needing serialization in turn.
2590
+ if (c.serializationLevel >= maxSerializationLevel)
2591
+ return '?';
2592
+ const multiline = (typeFormatFlags & 1024 /* NodeBuilderFlags.MultilineObjectLiterals */) !== 0;
2593
+ const noTruncation = c.compilerOptions.noErrorTruncation === true || (typeFormatFlags & 1 /* NodeBuilderFlags.NoTruncation */) !== 0;
2594
+ let flags = toNodeBuilderFlags(typeFormatFlags) | 70221824 /* NodeBuilderFlags.IgnoreErrors */;
2595
+ if (noTruncation)
2596
+ flags |= 1 /* NodeBuilderFlags.NoTruncation */;
2597
+ const b = new NodeBuilder(c, enclosingDeclaration, flags, 0 /* NodeBuilderInternalFlags.None */, undefined);
2598
+ b.pseudo = newPseudoChecker(c);
2599
+ c.serializationLevel++;
2600
+ const typeNode = b.finish(b.typeToTypeNode(type));
2601
+ c.serializationLevel--;
2602
+ if (typeNode === undefined)
2603
+ return undefined;
2604
+ const options = new PrinterOptions();
2605
+ // Only the unresolved type keeps its comment, a hint that it isn't a plain `any`.
2606
+ options.removeComments = type !== c.unresolvedType;
2607
+ options.newLine = multiline ? '\n' : '';
2608
+ const writer = new TextWriter(options.newLine, 0);
2609
+ const sourceFile = enclosingDeclaration === undefined ? undefined : getSourceFileOfNode(enclosingDeclaration);
2610
+ new Printer(options, b.context).write(typeNode, sourceFile, writer, undefined);
2611
+ const result = writer.getText();
2612
+ const maxLength = noTruncation ? noTruncationMaximumTruncationLength * 2 : defaultMaximumTruncationLength * 2;
2613
+ if (result.length >= maxLength)
2614
+ return result.substring(0, maxLength - 3) + '...';
2615
+ return result;
2616
+ }
2617
+ /** The index signature TypeScript would write for `info`. */
2618
+ export function indexInfoToIndexSignatureDeclaration(c, info, enclosingDeclaration, flags, tracker) {
2619
+ const b = new NodeBuilder(c, enclosingDeclaration, flags, 0 /* NodeBuilderInternalFlags.None */, tracker);
2620
+ return b.finish(b.indexInfoToIndexSignatureDeclaration(info, undefined));
2621
+ }
2622
+ /** The type parameter declaration TypeScript would write for `parameter`. */
2623
+ export function typeParameterToDeclaration(c, parameter, enclosingDeclaration, flags, tracker) {
2624
+ const b = new NodeBuilder(c, enclosingDeclaration, flags, 0 /* NodeBuilderInternalFlags.None */, tracker);
2625
+ return b.finish(b.typeParameterToDeclaration(parameter));
2626
+ }
2627
+ /** The type predicate node TypeScript would write for `predicate`. */
2628
+ export function typePredicateToTypePredicateNode(c, predicate, enclosingDeclaration, flags, tracker) {
2629
+ const b = new NodeBuilder(c, enclosingDeclaration, flags, 0 /* NodeBuilderInternalFlags.None */, tracker);
2630
+ return b.finish(b.typePredicateToTypePredicateNode(predicate));
2631
+ }
2632
+ /** The entity name TypeScript would write for `symbol` with `meaning`. */
2633
+ export function symbolToEntityName(c, symbol, meaning, enclosingDeclaration, flags, tracker) {
2634
+ const b = new NodeBuilder(c, enclosingDeclaration, flags, 0 /* NodeBuilderInternalFlags.None */, tracker);
2635
+ return b.finish(symbolToName(b, symbol, meaning, false));
2636
+ }
2637
+ /** The expression TypeScript would write for `symbol` with `meaning`. */
2638
+ export function symbolToExpressionNode(c, symbol, meaning, enclosingDeclaration, flags, tracker) {
2639
+ const b = new NodeBuilder(c, enclosingDeclaration, flags, 0 /* NodeBuilderInternalFlags.None */, tracker);
2640
+ return b.finish(symbolToExpression(b, symbol, meaning));
2641
+ }
2642
+ /** The UTF-8 offset of UTF-16 offset `pos` in `text`. */
2643
+ function utf8Offset(text, pos) {
2644
+ return pos <= 0 ? pos : utf8Length(text.slice(0, pos));
2645
+ }