tsc-ts 0.0.9 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (373) hide show
  1. package/README.md +2 -2
  2. package/bin/tsc-ts.js +70 -1
  3. package/dist/api/compiler/ast-utilities.d.ts +19 -1
  4. package/dist/api/compiler/ast-utilities.js +180 -95
  5. package/dist/api/compiler/ast.d.ts +22 -15
  6. package/dist/api/compiler/ast.js +1026 -995
  7. package/dist/api/compiler/astnav.js +15 -15
  8. package/dist/api/compiler/binder-utilities.js +186 -186
  9. package/dist/api/compiler/binder.js +290 -263
  10. package/dist/api/compiler/character-codes.js +2 -2
  11. package/dist/api/compiler/checker-calls.js +178 -124
  12. package/dist/api/compiler/checker-classes.d.ts +14 -3
  13. package/dist/api/compiler/checker-classes.js +134 -90
  14. package/dist/api/compiler/checker-contextual.js +64 -61
  15. package/dist/api/compiler/checker-declaration-order.js +79 -79
  16. package/dist/api/compiler/checker-declarations.d.ts +1 -0
  17. package/dist/api/compiler/checker-declarations.js +160 -136
  18. package/dist/api/compiler/checker-declared-types.js +67 -65
  19. package/dist/api/compiler/checker-decorators.js +77 -77
  20. package/dist/api/compiler/checker-deprecation.d.ts +8 -3
  21. package/dist/api/compiler/checker-deprecation.js +76 -55
  22. package/dist/api/compiler/checker-destructuring.js +47 -45
  23. package/dist/api/compiler/checker-elaboration.js +24 -24
  24. package/dist/api/compiler/checker-emit-helpers.js +4 -4
  25. package/dist/api/compiler/checker-emit-resolver.d.ts +4 -2
  26. package/dist/api/compiler/checker-emit-resolver.js +25 -13
  27. package/dist/api/compiler/checker-evaluator.js +9 -9
  28. package/dist/api/compiler/checker-expressions.js +244 -211
  29. package/dist/api/compiler/checker-functions.js +113 -107
  30. package/dist/api/compiler/checker-generated-code.d.ts +0 -11
  31. package/dist/api/compiler/checker-generated-code.js +28 -52
  32. package/dist/api/compiler/checker-grammar.d.ts +1 -0
  33. package/dist/api/compiler/checker-grammar.js +472 -440
  34. package/dist/api/compiler/checker-heritage.js +91 -93
  35. package/dist/api/compiler/checker-inference.d.ts +77 -5
  36. package/dist/api/compiler/checker-inference.js +487 -107
  37. package/dist/api/compiler/checker-iteration.d.ts +0 -10
  38. package/dist/api/compiler/checker-iteration.js +35 -52
  39. package/dist/api/compiler/checker-javascript.js +14 -14
  40. package/dist/api/compiler/checker-jsdoc.d.ts +8 -10
  41. package/dist/api/compiler/checker-jsdoc.js +67 -58
  42. package/dist/api/compiler/checker-jsx.js +105 -88
  43. package/dist/api/compiler/checker-members.d.ts +9 -2
  44. package/dist/api/compiler/checker-members.js +212 -75
  45. package/dist/api/compiler/checker-modules.d.ts +15 -6
  46. package/dist/api/compiler/checker-modules.js +469 -309
  47. package/dist/api/compiler/checker-narrowing.js +273 -189
  48. package/dist/api/compiler/checker-object-literals.js +25 -22
  49. package/dist/api/compiler/checker-operators.js +126 -118
  50. package/dist/api/compiler/checker-overloads.js +27 -27
  51. package/dist/api/compiler/checker-property-access.js +59 -55
  52. package/dist/api/compiler/checker-services.d.ts +1 -0
  53. package/dist/api/compiler/checker-services.js +222 -210
  54. package/dist/api/compiler/checker-signatures.js +65 -49
  55. package/dist/api/compiler/checker-source-file.d.ts +5 -0
  56. package/dist/api/compiler/checker-source-file.js +154 -130
  57. package/dist/api/compiler/checker-statements.js +33 -32
  58. package/dist/api/compiler/checker-super.js +50 -50
  59. package/dist/api/compiler/checker-symbol-types.js +109 -93
  60. package/dist/api/compiler/checker-symbols.d.ts +13 -1
  61. package/dist/api/compiler/checker-symbols.js +264 -149
  62. package/dist/api/compiler/checker-type-factory.d.ts +5 -0
  63. package/dist/api/compiler/checker-type-factory.js +145 -36
  64. package/dist/api/compiler/checker-type-nodes.d.ts +1 -0
  65. package/dist/api/compiler/checker-type-nodes.js +179 -141
  66. package/dist/api/compiler/checker-type-operators.d.ts +2 -0
  67. package/dist/api/compiler/checker-type-operators.js +110 -63
  68. package/dist/api/compiler/checker-types.d.ts +80 -3
  69. package/dist/api/compiler/checker-types.js +121 -2
  70. package/dist/api/compiler/checker-unused.js +114 -118
  71. package/dist/api/compiler/checker-utilities.js +11 -11
  72. package/dist/api/compiler/checker.d.ts +104 -31
  73. package/dist/api/compiler/checker.js +181 -33
  74. package/dist/api/compiler/command-line.d.ts +1 -3
  75. package/dist/api/compiler/command-line.js +47 -44
  76. package/dist/api/compiler/compile-program.d.ts +42 -3
  77. package/dist/api/compiler/compile-program.js +139 -27
  78. package/dist/api/compiler/diagnostic-messages.d.ts +1849 -1774
  79. package/dist/api/compiler/diagnostic-messages.js +128 -122
  80. package/dist/api/compiler/diagnostics.d.ts +22 -0
  81. package/dist/api/compiler/diagnostics.js +93 -11
  82. package/dist/api/compiler/emitter.d.ts +7 -1
  83. package/dist/api/compiler/emitter.js +53 -11
  84. package/dist/api/compiler/file-include.d.ts +2 -1
  85. package/dist/api/compiler/file-include.js +11 -7
  86. package/dist/api/compiler/file-loader.d.ts +21 -1
  87. package/dist/api/compiler/file-loader.js +201 -48
  88. package/dist/api/compiler/instantiation.d.ts +7 -0
  89. package/dist/api/compiler/instantiation.js +101 -49
  90. package/dist/api/compiler/jsdoc.js +23 -23
  91. package/dist/api/compiler/link-tables.d.ts +48 -18
  92. package/dist/api/compiler/link-tables.js +80 -37
  93. package/dist/api/compiler/locales/cs-CZ.d.ts +1 -1
  94. package/dist/api/compiler/locales/cs-CZ.js +1 -1
  95. package/dist/api/compiler/locales/de-DE.d.ts +1 -1
  96. package/dist/api/compiler/locales/de-DE.js +1 -1
  97. package/dist/api/compiler/locales/es-ES.d.ts +1 -1
  98. package/dist/api/compiler/locales/es-ES.js +1 -1
  99. package/dist/api/compiler/locales/fr-FR.d.ts +1 -1
  100. package/dist/api/compiler/locales/fr-FR.js +1 -1
  101. package/dist/api/compiler/locales/it-IT.d.ts +1 -1
  102. package/dist/api/compiler/locales/it-IT.js +1 -1
  103. package/dist/api/compiler/locales/ja-JP.d.ts +1 -1
  104. package/dist/api/compiler/locales/ja-JP.js +1 -1
  105. package/dist/api/compiler/locales/ko-KR.d.ts +1 -1
  106. package/dist/api/compiler/locales/ko-KR.js +1 -1
  107. package/dist/api/compiler/locales/pl-PL.d.ts +1 -1
  108. package/dist/api/compiler/locales/pl-PL.js +1 -1
  109. package/dist/api/compiler/locales/pt-BR.d.ts +1 -1
  110. package/dist/api/compiler/locales/pt-BR.js +1 -1
  111. package/dist/api/compiler/locales/ru-RU.d.ts +1 -1
  112. package/dist/api/compiler/locales/ru-RU.js +1 -1
  113. package/dist/api/compiler/locales/tr-TR.d.ts +1 -1
  114. package/dist/api/compiler/locales/tr-TR.js +1 -1
  115. package/dist/api/compiler/locales/zh-CN.d.ts +1 -1
  116. package/dist/api/compiler/locales/zh-CN.js +1 -1
  117. package/dist/api/compiler/locales/zh-TW.d.ts +1 -1
  118. package/dist/api/compiler/locales/zh-TW.js +1 -1
  119. package/dist/api/compiler/module-resolution-types.js +6 -6
  120. package/dist/api/compiler/module-resolution.d.ts +10 -1
  121. package/dist/api/compiler/module-resolution.js +115 -84
  122. package/dist/api/compiler/module-specifiers.d.ts +15 -0
  123. package/dist/api/compiler/module-specifiers.js +24 -18
  124. package/dist/api/compiler/name-resolver.js +74 -65
  125. package/dist/api/compiler/node-builder-names.d.ts +11 -3
  126. package/dist/api/compiler/node-builder-names.js +210 -90
  127. package/dist/api/compiler/node-builder-pseudo.js +29 -31
  128. package/dist/api/compiler/node-builder-reuse.js +23 -22
  129. package/dist/api/compiler/node-builder.d.ts +18 -1
  130. package/dist/api/compiler/node-builder.js +191 -102
  131. package/dist/api/compiler/option-declarations.d.ts +2 -6
  132. package/dist/api/compiler/option-declarations.js +315 -375
  133. package/dist/api/compiler/options.d.ts +15 -33
  134. package/dist/api/compiler/options.js +21 -54
  135. package/dist/api/compiler/output-paths.d.ts +4 -1
  136. package/dist/api/compiler/output-paths.js +6 -11
  137. package/dist/api/compiler/package-json.d.ts +3 -3
  138. package/dist/api/compiler/package-json.js +11 -10
  139. package/dist/api/compiler/parallel-parse.d.ts +3 -2
  140. package/dist/api/compiler/parallel-parse.js +17 -5
  141. package/dist/api/compiler/parser.d.ts +40 -19
  142. package/dist/api/compiler/parser.js +308 -216
  143. package/dist/api/compiler/path.d.ts +9 -0
  144. package/dist/api/compiler/path.js +20 -3
  145. package/dist/api/compiler/printer/emit-context.d.ts +5 -1
  146. package/dist/api/compiler/printer/emit-context.js +20 -1
  147. package/dist/api/compiler/printer/factory-base.d.ts +2 -2
  148. package/dist/api/compiler/printer/factory-base.js +7 -3
  149. package/dist/api/compiler/printer/factory.js +3 -1
  150. package/dist/api/compiler/printer/helpers.js +10 -1
  151. package/dist/api/compiler/printer/name-generator.d.ts +1 -1
  152. package/dist/api/compiler/printer/name-generator.js +35 -16
  153. package/dist/api/compiler/printer/printer.d.ts +49 -2
  154. package/dist/api/compiler/printer/printer.js +539 -293
  155. package/dist/api/compiler/printer/utilities.js +149 -147
  156. package/dist/api/compiler/program-checker.d.ts +12 -2
  157. package/dist/api/compiler/program-checker.js +88 -34
  158. package/dist/api/compiler/program-utilities.d.ts +3 -1
  159. package/dist/api/compiler/program-utilities.js +28 -15
  160. package/dist/api/compiler/program.d.ts +4 -6
  161. package/dist/api/compiler/program.js +74 -87
  162. package/dist/api/compiler/pseudo-bigint.d.ts +2 -0
  163. package/dist/api/compiler/pseudo-bigint.js +18 -0
  164. package/dist/api/compiler/regexp-checker.d.ts +1 -1
  165. package/dist/api/compiler/regexp-checker.js +93 -76
  166. package/dist/api/compiler/relations.d.ts +27 -4
  167. package/dist/api/compiler/relations.js +347 -180
  168. package/dist/api/compiler/reparser.js +60 -56
  169. package/dist/api/compiler/scanner.d.ts +19 -2
  170. package/dist/api/compiler/scanner.js +123 -108
  171. package/dist/api/compiler/shared-results.d.ts +463 -0
  172. package/dist/api/compiler/shared-results.js +2128 -0
  173. package/dist/api/compiler/sourcemap.js +2 -2
  174. package/dist/api/compiler/symbol-accessibility.js +87 -74
  175. package/dist/api/compiler/symbol.d.ts +23 -14
  176. package/dist/api/compiler/symbol.js +23 -11
  177. package/dist/api/compiler/syntax-kind.d.ts +198 -197
  178. package/dist/api/compiler/transformers/alias-references.js +247 -139
  179. package/dist/api/compiler/transformers/async-utilities.js +25 -25
  180. package/dist/api/compiler/transformers/async.d.ts +0 -1
  181. package/dist/api/compiler/transformers/async.js +64 -77
  182. package/dist/api/compiler/transformers/class-fields.d.ts +1 -0
  183. package/dist/api/compiler/transformers/class-fields.js +81 -78
  184. package/dist/api/compiler/transformers/commonjs-module.js +18 -15
  185. package/dist/api/compiler/transformers/const-enum-inliner.js +1 -1
  186. package/dist/api/compiler/transformers/declarations-diagnostics.js +247 -244
  187. package/dist/api/compiler/transformers/declarations-pseudo.js +100 -100
  188. package/dist/api/compiler/transformers/declarations-resolver.d.ts +0 -3
  189. package/dist/api/compiler/transformers/declarations-syntactic.d.ts +1 -2
  190. package/dist/api/compiler/transformers/declarations-syntactic.js +134 -156
  191. package/dist/api/compiler/transformers/declarations-tracker.js +18 -18
  192. package/dist/api/compiler/transformers/declarations.d.ts +4 -1
  193. package/dist/api/compiler/transformers/declarations.js +305 -238
  194. package/dist/api/compiler/transformers/decorator-metadata.d.ts +1 -1
  195. package/dist/api/compiler/transformers/decorator-metadata.js +53 -45
  196. package/dist/api/compiler/transformers/decorator-utilities.js +24 -24
  197. package/dist/api/compiler/transformers/destructuring.js +19 -18
  198. package/dist/api/compiler/transformers/emit-resolver.js +1 -1
  199. package/dist/api/compiler/transformers/es-decorators.js +55 -55
  200. package/dist/api/compiler/transformers/external-module-info.js +3 -3
  201. package/dist/api/compiler/transformers/for-await.js +25 -25
  202. package/dist/api/compiler/transformers/import-elision.js +14 -14
  203. package/dist/api/compiler/transformers/jsx.js +12 -12
  204. package/dist/api/compiler/transformers/legacy-decorators.js +17 -17
  205. package/dist/api/compiler/transformers/module.js +8 -8
  206. package/dist/api/compiler/transformers/named-evaluation.js +4 -4
  207. package/dist/api/compiler/transformers/object-rest-spread.js +20 -20
  208. package/dist/api/compiler/transformers/optional-chain.js +10 -10
  209. package/dist/api/compiler/transformers/reference-resolver.d.ts +12 -1
  210. package/dist/api/compiler/transformers/reference-resolver.js +131 -69
  211. package/dist/api/compiler/transformers/runtime-syntax.js +35 -31
  212. package/dist/api/compiler/transformers/subtree-facts.js +47 -47
  213. package/dist/api/compiler/transformers/syntax-facts.js +56 -58
  214. package/dist/api/compiler/transformers/type-eraser.js +73 -66
  215. package/dist/api/compiler/transformers/type-serialization.js +24 -24
  216. package/dist/api/compiler/transformers/using.js +12 -12
  217. package/dist/api/compiler/transformers/utilities.js +77 -77
  218. package/dist/api/compiler/transformers/visitor-base.js +172 -172
  219. package/dist/api/compiler/transformers/visitor-hooks.js +6 -2
  220. package/dist/api/compiler/tsconfig.d.ts +10 -2
  221. package/dist/api/compiler/tsconfig.js +136 -48
  222. package/dist/api/compiler/type-printer.js +40 -3
  223. package/dist/api/compiler/types.d.ts +2 -1
  224. package/dist/api/library/ast.generated.d.ts +42 -39
  225. package/dist/api/library/ast.generated.js +1 -1
  226. package/dist/api/library/compiler-options.generated.d.ts +111 -100
  227. package/dist/api/library/compiler-options.generated.js +1 -1
  228. package/dist/api/library/disk.js +12 -1
  229. package/dist/api/library/enums.generated.d.ts +206 -206
  230. package/dist/api/library/enums.generated.js +206 -206
  231. package/dist/api/library/nodes.js +26 -26
  232. package/package.json +9 -9
  233. package/src/compiler/ast-utilities.ts +99 -7
  234. package/src/compiler/ast.ts +58 -26
  235. package/src/compiler/binder.ts +39 -4
  236. package/src/compiler/character-codes.ts +2 -2
  237. package/src/compiler/checker-calls.ts +79 -9
  238. package/src/compiler/checker-classes.ts +78 -24
  239. package/src/compiler/checker-contextual.ts +6 -1
  240. package/src/compiler/checker-declarations.ts +31 -4
  241. package/src/compiler/checker-declared-types.ts +8 -5
  242. package/src/compiler/checker-decorators.ts +1 -1
  243. package/src/compiler/checker-deprecation.ts +29 -8
  244. package/src/compiler/checker-destructuring.ts +10 -3
  245. package/src/compiler/checker-emit-helpers.ts +1 -0
  246. package/src/compiler/checker-emit-resolver.ts +16 -6
  247. package/src/compiler/checker-expressions.ts +79 -46
  248. package/src/compiler/checker-functions.ts +21 -6
  249. package/src/compiler/checker-generated-code.ts +2 -22
  250. package/src/compiler/checker-grammar.ts +136 -62
  251. package/src/compiler/checker-heritage.ts +22 -21
  252. package/src/compiler/checker-inference.ts +514 -82
  253. package/src/compiler/checker-iteration.ts +18 -31
  254. package/src/compiler/checker-javascript.ts +1 -1
  255. package/src/compiler/checker-jsdoc.ts +50 -27
  256. package/src/compiler/checker-jsx.ts +26 -4
  257. package/src/compiler/checker-members.ts +200 -56
  258. package/src/compiler/checker-modules.ts +332 -65
  259. package/src/compiler/checker-narrowing.ts +98 -19
  260. package/src/compiler/checker-object-literals.ts +3 -0
  261. package/src/compiler/checker-operators.ts +11 -4
  262. package/src/compiler/checker-property-access.ts +7 -2
  263. package/src/compiler/checker-services.ts +39 -12
  264. package/src/compiler/checker-signatures.ts +15 -1
  265. package/src/compiler/checker-source-file.ts +39 -13
  266. package/src/compiler/checker-statements.ts +3 -2
  267. package/src/compiler/checker-symbol-types.ts +29 -6
  268. package/src/compiler/checker-symbols.ts +158 -15
  269. package/src/compiler/checker-type-factory.ts +124 -23
  270. package/src/compiler/checker-type-nodes.ts +46 -3
  271. package/src/compiler/checker-type-operators.ts +83 -26
  272. package/src/compiler/checker-types.ts +147 -4
  273. package/src/compiler/checker-unused.ts +9 -14
  274. package/src/compiler/checker.ts +203 -39
  275. package/src/compiler/command-line.ts +28 -28
  276. package/src/compiler/compile-program.ts +167 -27
  277. package/src/compiler/decoder.ts +13 -4
  278. package/src/compiler/diagnostic-messages.ts +1973 -1892
  279. package/src/compiler/diagnostics.ts +84 -3
  280. package/src/compiler/emitter.ts +57 -8
  281. package/src/compiler/encoder.ts +23 -8
  282. package/src/compiler/file-include.ts +9 -3
  283. package/src/compiler/file-loader.ts +197 -38
  284. package/src/compiler/help.ts +10 -14
  285. package/src/compiler/incremental.ts +165 -30
  286. package/src/compiler/init.ts +2 -7
  287. package/src/compiler/instantiation.ts +77 -22
  288. package/src/compiler/jsdoc.ts +3 -1
  289. package/src/compiler/link-tables.ts +82 -37
  290. package/src/compiler/locales/cs-CZ.ts +1 -1
  291. package/src/compiler/locales/de-DE.ts +1 -1
  292. package/src/compiler/locales/es-ES.ts +1 -1
  293. package/src/compiler/locales/fr-FR.ts +1 -1
  294. package/src/compiler/locales/it-IT.ts +1 -1
  295. package/src/compiler/locales/ja-JP.ts +1 -1
  296. package/src/compiler/locales/ko-KR.ts +1 -1
  297. package/src/compiler/locales/pl-PL.ts +1 -1
  298. package/src/compiler/locales/pt-BR.ts +1 -1
  299. package/src/compiler/locales/ru-RU.ts +1 -1
  300. package/src/compiler/locales/tr-TR.ts +1 -1
  301. package/src/compiler/locales/zh-CN.ts +1 -1
  302. package/src/compiler/locales/zh-TW.ts +1 -1
  303. package/src/compiler/module-resolution.ts +44 -8
  304. package/src/compiler/module-specifiers.ts +62 -20
  305. package/src/compiler/name-resolver.ts +9 -1
  306. package/src/compiler/node-builder-names.ts +236 -54
  307. package/src/compiler/node-builder-pseudo.ts +4 -7
  308. package/src/compiler/node-builder-reuse.ts +5 -4
  309. package/src/compiler/node-builder.ts +130 -31
  310. package/src/compiler/option-declarations.ts +33 -103
  311. package/src/compiler/options.ts +23 -62
  312. package/src/compiler/output-paths.ts +5 -18
  313. package/src/compiler/package-entrypoints.ts +345 -0
  314. package/src/compiler/package-json.ts +4 -4
  315. package/src/compiler/parallel-check.ts +326 -52
  316. package/src/compiler/parallel-emit.ts +320 -0
  317. package/src/compiler/parallel-parse.ts +16 -5
  318. package/src/compiler/parse-thread.ts +3 -0
  319. package/src/compiler/parser.ts +156 -39
  320. package/src/compiler/path.ts +22 -2
  321. package/src/compiler/printer/emit-context.ts +21 -0
  322. package/src/compiler/printer/factory-base.ts +10 -3
  323. package/src/compiler/printer/factory.ts +4 -1
  324. package/src/compiler/printer/helpers.ts +10 -1
  325. package/src/compiler/printer/name-generator.ts +24 -2
  326. package/src/compiler/printer/printer.ts +266 -30
  327. package/src/compiler/printer/utilities.ts +8 -2
  328. package/src/compiler/program-checker.ts +57 -5
  329. package/src/compiler/program-utilities.ts +23 -10
  330. package/src/compiler/program.ts +18 -26
  331. package/src/compiler/pseudo-bigint.ts +17 -0
  332. package/src/compiler/regexp-checker.ts +63 -30
  333. package/src/compiler/relations.ts +240 -77
  334. package/src/compiler/reparser.ts +7 -2
  335. package/src/compiler/scanner.ts +109 -79
  336. package/src/compiler/shared-results.ts +2414 -0
  337. package/src/compiler/show-config.ts +18 -1
  338. package/src/compiler/sourcemap.ts +2 -2
  339. package/src/compiler/symbol-accessibility.ts +26 -3
  340. package/src/compiler/symbol.ts +46 -24
  341. package/src/compiler/syntax-kind.ts +188 -187
  342. package/src/compiler/thread-entry.ts +64 -4
  343. package/src/compiler/transformers/alias-references.ts +123 -4
  344. package/src/compiler/transformers/async.ts +2 -17
  345. package/src/compiler/transformers/class-fields.ts +13 -12
  346. package/src/compiler/transformers/commonjs-module.ts +11 -7
  347. package/src/compiler/transformers/declarations-diagnostics.ts +5 -3
  348. package/src/compiler/transformers/declarations-pseudo.ts +2 -4
  349. package/src/compiler/transformers/declarations-resolver.ts +0 -3
  350. package/src/compiler/transformers/declarations-syntactic.ts +1 -21
  351. package/src/compiler/transformers/declarations.ts +134 -48
  352. package/src/compiler/transformers/decorator-metadata.ts +9 -1
  353. package/src/compiler/transformers/destructuring.ts +4 -3
  354. package/src/compiler/transformers/external-module-info.ts +1 -1
  355. package/src/compiler/transformers/jsx.ts +2 -1
  356. package/src/compiler/transformers/reference-resolver.ts +83 -19
  357. package/src/compiler/transformers/runtime-syntax.ts +6 -1
  358. package/src/compiler/transformers/syntax-facts.ts +2 -7
  359. package/src/compiler/transformers/type-eraser.ts +10 -1
  360. package/src/compiler/transformers/type-serialization.ts +3 -2
  361. package/src/compiler/transformers/visitor-base.ts +2 -1
  362. package/src/compiler/transformers/visitor-hooks.ts +9 -4
  363. package/src/compiler/tsc-build.ts +66 -9
  364. package/src/compiler/tsc-cli.ts +7 -0
  365. package/src/compiler/tsc-compile.ts +284 -4
  366. package/src/compiler/tsc-watch.ts +74 -45
  367. package/src/compiler/tsconfig.ts +176 -19
  368. package/src/compiler/type-printer.ts +36 -2
  369. package/src/compiler/types.ts +2 -1
  370. package/src/library/ast.generated.ts +57 -41
  371. package/src/library/compiler-options.generated.ts +117 -103
  372. package/src/library/disk.ts +10 -1
  373. package/src/library/enums.generated.ts +196 -196
@@ -50,6 +50,9 @@ import {
50
50
  newTypeMapper,
51
51
  SimpleTypeMapper,
52
52
  type TypeMapper,
53
+ isDistributedTypeParameter,
54
+ type TypeParameter,
55
+ type SymbolLinks,
53
56
  } from './checker-types.js';
54
57
  import { InferenceFlags, InferencePriority, createInferenceContext, inferTypes } from './checker-inference.js';
55
58
  import {
@@ -94,6 +97,7 @@ import {
94
97
  createNormalizedTypeReference,
95
98
  typeListKey,
96
99
  getRegularTypeOfLiteralType,
100
+ compareSymbols,
97
101
  } from './checker-type-factory.js';
98
102
  import {
99
103
  findApplicableIndexInfo,
@@ -236,9 +240,8 @@ export const enum RelationComparisonResult {
236
240
  ReportsUnmeasurable = 1 << 3,
237
241
  ReportsUnreliable = 1 << 4,
238
242
  ComplexityOverflow = 1 << 5,
239
- StackDepthOverflow = 1 << 6,
240
243
  ReportsMask = ReportsUnmeasurable | ReportsUnreliable,
241
- Overflow = ComplexityOverflow | StackDepthOverflow,
244
+ Overflow = ComplexityOverflow,
242
245
  }
243
246
 
244
247
  /**
@@ -263,25 +266,46 @@ export class Relation {
263
266
  }
264
267
  }
265
268
 
266
- set(key: number, result: number): void {
269
+ /** Sets the result of `key`, and returns whether the key is new. */
270
+ set(key: number, result: number): boolean {
267
271
  const keys = this.keys;
268
272
  const mask = keys.length - 1;
269
273
  for (let i = relationSlot(key) & mask; ; i = (i + 1) & mask) {
270
274
  const k = keys[i]!;
271
275
  if (k === key) {
272
276
  this.results[i] = result;
273
- return;
277
+ return false;
274
278
  }
275
279
  if (k === 0) {
276
280
  keys[i] = key;
277
281
  this.results[i] = result;
278
282
  this.count++;
279
283
  if (this.count * 4 > keys.length * 3) this.grow();
280
- return;
284
+ return true;
281
285
  }
282
286
  }
283
287
  }
284
288
 
289
+ /** Removes `key`, moving later entries of its probe run back so lookups still find them. */
290
+ delete(key: number): void {
291
+ const keys = this.keys;
292
+ const results = this.results;
293
+ const mask = keys.length - 1;
294
+ let i = relationSlot(key) & mask;
295
+ for (; keys[i] !== key; i = (i + 1) & mask) if (keys[i] === 0) return;
296
+ for (let j = (i + 1) & mask; keys[j] !== 0; j = (j + 1) & mask) {
297
+ // An entry stays where it is when its home slot is cyclically after the freed slot and at or before it.
298
+ const home = relationSlot(keys[j]!) & mask;
299
+ if (i <= j ? i < home && home <= j : i < home || home <= j) continue;
300
+ keys[i] = keys[j]!;
301
+ results[i] = results[j]!;
302
+ i = j;
303
+ }
304
+ keys[i] = 0;
305
+ results[i] = 0;
306
+ this.count--;
307
+ }
308
+
285
309
  size(): number {
286
310
  return this.count;
287
311
  }
@@ -517,6 +541,13 @@ export function isTypeRelatedTo(c: Checker, source: Type, target: Type, relation
517
541
  // Types that can't simplify must have identical flags.
518
542
  if (source.flags !== target.flags) return false;
519
543
  if ((source.flags & TypeFlags.Singleton) !== 0) return true;
544
+ } else {
545
+ // What the relater decides first for types that may simplify (Relater.isRelatedToEx): their normal forms are
546
+ // one type, or can be identical only with identical flags.
547
+ const s = getNormalizedType(c, source, false);
548
+ const t = getNormalizedType(c, target, true);
549
+ if (s === t) return true;
550
+ if (s.flags !== t.flags) return false;
520
551
  }
521
552
  if ((source.flags & TypeFlags.Object) !== 0 && (target.flags & TypeFlags.Object) !== 0) {
522
553
  const related = relation.get(
@@ -1003,8 +1034,25 @@ export function checkTypeRelatedTo(
1003
1034
  // Nested checks (from resolving types during the relation) find no spare and allocate their own.
1004
1035
  const r = c.spareRelater ?? new Relater(c, relation, errorNode);
1005
1036
  c.spareRelater = undefined;
1037
+ const relationCount = Math.trunc((16000000 - relation.size()) / 8);
1038
+ if (errorNode !== undefined) {
1039
+ // Relate without reporting first: reporting builds a message for every comparison that fails on the way,
1040
+ // even when the relation holds. When the relation fails, the results this pass added are removed, since
1041
+ // the comparisons it assumed related while comparing would change which failure the report elaborates.
1042
+ r.reset(relation, undefined);
1043
+ r.relationCount = relationCount;
1044
+ const addedKeys: number[] = [];
1045
+ r.addedKeys = addedKeys;
1046
+ const quiet = r.isRelatedToEx(source, target, RecursionFlags.Both, false, undefined, IntersectionState.None);
1047
+ r.addedKeys = undefined;
1048
+ if (quiet !== Ternary.False && !r.overflow) {
1049
+ c.spareRelater = r;
1050
+ return true;
1051
+ }
1052
+ for (const key of addedKeys) relation.delete(key);
1053
+ }
1006
1054
  r.reset(relation, errorNode);
1007
- r.relationCount = Math.trunc((16000000 - relation.size()) / 8);
1055
+ r.relationCount = relationCount;
1008
1056
  const result = r.isRelatedToEx(
1009
1057
  source,
1010
1058
  target,
@@ -1016,20 +1064,13 @@ export function checkTypeRelatedTo(
1016
1064
  if (r.overflow) {
1017
1065
  // Remember the overflow so it isn't attempted again.
1018
1066
  const key = getRelationKey(c, source, target, IntersectionState.None, relation === c.identityRelation, false).key;
1019
- relation.set(
1020
- key,
1021
- RelationComparisonResult.Failed |
1022
- (r.relationCount <= 0
1023
- ? RelationComparisonResult.ComplexityOverflow
1024
- : RelationComparisonResult.StackDepthOverflow),
1025
- );
1026
- const message =
1027
- r.relationCount <= 0
1028
- ? Diagnostics.Excessive_complexity_comparing_types_0_and_1
1029
- : Diagnostics.Excessive_stack_depth_comparing_types_0_and_1;
1067
+ relation.set(key, RelationComparisonResult.Failed | RelationComparisonResult.ComplexityOverflow);
1030
1068
  reportDiagnostic(
1031
1069
  c,
1032
- createDiagnosticForNode(errorNode ?? c.currentNode, message, [typeToString(c, source), typeToString(c, target)]),
1070
+ createDiagnosticForNode(errorNode ?? c.currentNode, Diagnostics.Excessive_complexity_comparing_types_0_and_1, [
1071
+ typeToString(c, source),
1072
+ typeToString(c, target),
1073
+ ]),
1033
1074
  diagnosticOutput,
1034
1075
  );
1035
1076
  } else if (r.errorChain !== undefined) {
@@ -1143,6 +1184,8 @@ export class Relater extends TypeComparer {
1143
1184
  expandingFlags: ExpandingFlags = ExpandingFlags.None;
1144
1185
  overflow = false;
1145
1186
  relationCount = 0;
1187
+ /** The keys this check added to the relation, while relating without reporting first. */
1188
+ addedKeys: number[] | undefined = undefined;
1146
1189
  /** The intersection state passed to `compare` during signature comparisons. */
1147
1190
  signatureIntersectionState: IntersectionState = IntersectionState.None;
1148
1191
  // What `relateVariances` changes in its caller's state when it falls back to structure.
@@ -1674,13 +1717,11 @@ export class Relater extends TypeComparer {
1674
1717
  } else {
1675
1718
  c.reliabilityFlags |=
1676
1719
  entry & (RelationComparisonResult.ReportsUnmeasurable | RelationComparisonResult.ReportsUnreliable);
1677
- if (reportErrors && (entry & RelationComparisonResult.Overflow) !== 0) {
1678
- const message =
1679
- (entry & RelationComparisonResult.ComplexityOverflow) !== 0
1680
- ? Diagnostics.Excessive_complexity_comparing_types_0_and_1
1681
- : Diagnostics.Excessive_stack_depth_comparing_types_0_and_1;
1682
- this.reportError(message, [typeToString(c, source), typeToString(c, target)]);
1683
- }
1720
+ if (reportErrors && (entry & RelationComparisonResult.Overflow) !== 0)
1721
+ this.reportError(Diagnostics.Excessive_complexity_comparing_types_0_and_1, [
1722
+ typeToString(c, source),
1723
+ typeToString(c, target),
1724
+ ]);
1684
1725
  return (entry & RelationComparisonResult.Succeeded) !== 0 ? Ternary.True : Ternary.False;
1685
1726
  }
1686
1727
  }
@@ -1703,10 +1744,9 @@ export class Relater extends TypeComparer {
1703
1744
  }
1704
1745
  const sourceDepth = this.sourceDepth;
1705
1746
  const targetDepth = this.targetDepth;
1706
- if (sourceDepth === 100 || targetDepth === 100) {
1707
- this.overflow = true;
1708
- return Ternary.False;
1709
- }
1747
+ // A backstop for infinite recursion that isDeeplyNestedType misses, which also stops relating the exceedingly
1748
+ // rare types that are truly more than 100 levels deep.
1749
+ if (sourceDepth === 100 || targetDepth === 100) return Ternary.Maybe;
1710
1750
  const maybeStart = this.maybeKeys.length;
1711
1751
  this.maybeKeys.push(id);
1712
1752
  this.maybeKeysSet.add(id);
@@ -1747,18 +1787,22 @@ export class Relater extends TypeComparer {
1747
1787
  }
1748
1788
  } else {
1749
1789
  // False under assumptions is false without them.
1750
- this.relation.set(id, RelationComparisonResult.Failed | propagatingVarianceFlags);
1790
+ this.record(id, RelationComparisonResult.Failed | propagatingVarianceFlags);
1751
1791
  this.relationCount--;
1752
1792
  this.resetMaybeStack(maybeStart, propagatingVarianceFlags, false);
1753
1793
  }
1754
1794
  return result;
1755
1795
  }
1756
1796
 
1797
+ record(key: number, result: number): void {
1798
+ if (this.relation.set(key, result) && this.addedKeys !== undefined) this.addedKeys.push(key);
1799
+ }
1800
+
1757
1801
  resetMaybeStack(maybeStart: number, propagatingVarianceFlags: number, markAllAsSucceeded: boolean): void {
1758
1802
  for (let i = maybeStart; i < this.maybeKeys.length; i++) {
1759
1803
  this.maybeKeysSet.delete(this.maybeKeys[i]!);
1760
1804
  if (markAllAsSucceeded) {
1761
- this.relation.set(this.maybeKeys[i]!, RelationComparisonResult.Succeeded | propagatingVarianceFlags);
1805
+ this.record(this.maybeKeys[i]!, RelationComparisonResult.Succeeded | propagatingVarianceFlags);
1762
1806
  this.relationCount--;
1763
1807
  }
1764
1808
  }
@@ -2617,7 +2661,7 @@ export class Relater extends TypeComparer {
2617
2661
  ? this.isRelatedTo(s, t, RecursionFlags.Both, false)
2618
2662
  : compareTypesIdentical(c, s, t);
2619
2663
  else {
2620
- if (c.inVarianceComputation && (varianceFlags & VarianceFlags.Unreliable) !== 0)
2664
+ if (c.varianceStack.length !== 0 && (varianceFlags & VarianceFlags.Unreliable) !== 0)
2621
2665
  instantiateType(c, s, c.reportUnreliableMapper);
2622
2666
  if (variance === VarianceFlags.Covariant)
2623
2667
  related = this.isRelatedToEx(s, t, RecursionFlags.Both, reportErrors, undefined, intersectionState);
@@ -2701,7 +2745,8 @@ export class Relater extends TypeComparer {
2701
2745
  const sourceArity = getTypeReferenceArity(source);
2702
2746
  const targetArity = getTypeReferenceArity(target);
2703
2747
  const sourceRest = isTupleType(source) ? (tupleTargetOf(source).combinedFlags & ElementFlags.Rest) !== 0 : true;
2704
- const targetHasRestElement = (targetTuple.combinedFlags & ElementFlags.Variable) !== 0;
2748
+ const targetHasRestElement = (targetTuple.combinedFlags & ElementFlags.Rest) !== 0;
2749
+ const targetHasVariableElement = (targetTuple.combinedFlags & ElementFlags.Variable) !== 0;
2705
2750
  const sourceMinLength = isTupleType(source) ? tupleTargetOf(source).minLength : 0;
2706
2751
  const targetMinLength = targetTuple.minLength;
2707
2752
  if (!sourceRest && sourceArity < targetMinLength) {
@@ -2712,7 +2757,7 @@ export class Relater extends TypeComparer {
2712
2757
  ]);
2713
2758
  return Ternary.False;
2714
2759
  }
2715
- if (!targetHasRestElement && targetArity < sourceMinLength) {
2760
+ if (!targetHasVariableElement && targetArity < sourceMinLength) {
2716
2761
  if (reportErrors)
2717
2762
  this.reportError(Diagnostics.Source_has_0_element_s_but_target_allows_only_1, [
2718
2763
  String(sourceMinLength),
@@ -2720,7 +2765,7 @@ export class Relater extends TypeComparer {
2720
2765
  ]);
2721
2766
  return Ternary.False;
2722
2767
  }
2723
- if (!targetHasRestElement && (sourceRest || targetArity < sourceArity)) {
2768
+ if (!targetHasVariableElement && (sourceRest || targetArity < sourceArity)) {
2724
2769
  if (reportErrors) {
2725
2770
  if (sourceMinLength < targetMinLength)
2726
2771
  this.reportError(Diagnostics.Target_requires_0_element_s_but_source_may_have_fewer, [
@@ -2743,10 +2788,18 @@ export class Relater extends TypeComparer {
2743
2788
  ? tupleTargetOf(source).elementInfos[sourcePosition]!.flags
2744
2789
  : ElementFlags.Rest;
2745
2790
  const sourcePositionFromEnd = sourceArity - 1 - sourcePosition;
2746
- const targetPosition =
2747
- targetHasRestElement && sourcePosition >= targetStartCount
2748
- ? targetArity - 1 - Math.min(sourcePositionFromEnd, targetEndCount)
2749
- : sourcePosition;
2791
+ const restMapped = targetHasRestElement && sourcePosition >= targetStartCount;
2792
+ // A source element past the target's last element (a target with variadic but no rest elements).
2793
+ if (!restMapped && sourcePosition >= targetArity) {
2794
+ if (reportErrors)
2795
+ this.reportError(Diagnostics.Target_allows_only_0_element_s_but_source_may_have_more, [
2796
+ String(targetArity),
2797
+ ]);
2798
+ return Ternary.False;
2799
+ }
2800
+ const targetPosition = restMapped
2801
+ ? targetArity - 1 - Math.min(sourcePositionFromEnd, targetEndCount)
2802
+ : sourcePosition;
2750
2803
  const targetFlags = targetPosition >= 0 ? targetTuple.elementInfos[targetPosition]!.flags : ElementFlags.None;
2751
2804
  if ((targetFlags & ElementFlags.Variadic) !== 0 && (sourceFlags & ElementFlags.Variadic) === 0) {
2752
2805
  if (reportErrors)
@@ -3550,7 +3603,15 @@ export class Relater extends TypeComparer {
3550
3603
  target !== c.markerSubTypeForCheck
3551
3604
  ) {
3552
3605
  const constraint = getBaseConstraintOfType(c, target);
3553
- if (constraint !== undefined && isTypeAssignableTo(c, generalizedSource, constraint))
3606
+ if (
3607
+ isDistributedTypeParameter(target) &&
3608
+ isTypeAssignableTo(c, generalizedSource, (target as TypeParameter).constraint!)
3609
+ )
3610
+ this.reportError(Diagnostics.X_0_is_only_assignable_to_the_non_distributed_1_but_1_has_been_distributed_here, [
3611
+ generalizedSourceType,
3612
+ targetType,
3613
+ ]);
3614
+ else if (constraint !== undefined && isTypeAssignableTo(c, generalizedSource, constraint))
3554
3615
  this.reportError(
3555
3616
  Diagnostics.X_0_is_assignable_to_the_constraint_of_type_1_but_1_could_be_instantiated_with_a_different_subtype_of_constraint_2,
3556
3617
  [generalizedSourceType, targetType, typeToString(c, constraint)],
@@ -3604,7 +3665,6 @@ export class Relater extends TypeComparer {
3604
3665
  case Diagnostics.Object_literal_may_only_specify_known_properties_but_0_does_not_exist_in_type_1_Did_you_mean_to_write_2:
3605
3666
  return;
3606
3667
  case Diagnostics.Excessive_complexity_comparing_types_0_and_1:
3607
- case Diagnostics.Excessive_stack_depth_comparing_types_0_and_1:
3608
3668
  case Diagnostics.The_type_0_is_readonly_and_cannot_be_assigned_to_the_mutable_type_1:
3609
3669
  if (this.chainArgsMatch(generalizedSourceType, targetType, undefined)) return;
3610
3670
  break;
@@ -4328,14 +4388,12 @@ export function isDeeplyNestedType(
4328
4388
  maxDepth: number,
4329
4389
  ): boolean {
4330
4390
  if (depth < maxDepth) return false;
4331
- if (
4332
- (t.objectFlags & ObjectFlags.InstantiatedMapped) === ObjectFlags.InstantiatedMapped &&
4333
- (t.flags & TypeFlags.Object) !== 0
4334
- )
4335
- t = getMappedTargetWithSymbol(c, t);
4336
- if ((t.flags & TypeFlags.Intersection) !== 0)
4337
- for (const u of typesOf(t)) if (isDeeplyNestedType(c, u, stack, depth, maxDepth)) return true;
4338
- const identity = getRecursionIdentity(t);
4391
+ const target = getRecursionIdentityTarget(c, t);
4392
+ if ((target.flags & TypeFlags.Intersection) !== 0) {
4393
+ for (const u of typesOf(target)) if (isDeeplyNestedType(c, u, stack, depth, maxDepth)) return true;
4394
+ return false;
4395
+ }
4396
+ const identity = getRecursionIdentityFromTarget(target);
4339
4397
  let count = 0;
4340
4398
  let lastTypeId = 0;
4341
4399
  for (let i = 0; i < depth; i++) {
@@ -4351,8 +4409,77 @@ export function isDeeplyNestedType(
4351
4409
  return false;
4352
4410
  }
4353
4411
 
4354
- function getMappedTargetWithSymbol(c: Checker, t: Type): Type {
4412
+ /**
4413
+ * isDeeplyNestedType for the newest entry of `stack[start..end)`, counting only the entries in that range.
4414
+ * `identities` holds the recursion identity of each entry of the range once a check has computed it: 0 before
4415
+ * that, and -1 for an entry whose recursion identity target is an intersection, which is matched by its
4416
+ * constituents each time. Later checks compare the kept identities. The identities are computed when and in the
4417
+ * order isDeeplyNestedType computes them, so the types and symbol ids they create come in the same order.
4418
+ */
4419
+ export function isDeeplyNestedStackEntry(
4420
+ c: Checker,
4421
+ stack: readonly Type[],
4422
+ identities: RecursionId[],
4423
+ start: number,
4424
+ end: number,
4425
+ maxDepth: number,
4426
+ ): boolean {
4427
+ if (end - start < maxDepth) return false;
4428
+ return isDeeplyNestedInRange(c, stack[end - 1]!, true, stack, identities, start, end, maxDepth);
4429
+ }
4430
+
4431
+ function isDeeplyNestedInRange(
4432
+ c: Checker,
4433
+ t: Type,
4434
+ isEntry: boolean,
4435
+ stack: readonly Type[],
4436
+ identities: RecursionId[],
4437
+ start: number,
4438
+ end: number,
4439
+ maxDepth: number,
4440
+ ): boolean {
4441
+ const target = getRecursionIdentityTarget(c, t);
4442
+ if ((target.flags & TypeFlags.Intersection) !== 0) {
4443
+ if (isEntry) identities[end - 1] = -1;
4444
+ for (const u of typesOf(target))
4445
+ if (isDeeplyNestedInRange(c, u, false, stack, identities, start, end, maxDepth)) return true;
4446
+ return false;
4447
+ }
4448
+ const identity = getRecursionIdentityFromTarget(target);
4449
+ if (isEntry) identities[end - 1] = identity;
4450
+ let count = 0;
4451
+ let lastTypeId = 0;
4452
+ for (let i = start; i < end; i++) {
4453
+ const s = stack[i]!;
4454
+ let known = identities[i]!;
4455
+ if (known === 0) {
4456
+ const sourceTarget = getRecursionIdentityTarget(c, s);
4457
+ known = (sourceTarget.flags & TypeFlags.Intersection) !== 0 ? -1 : getRecursionIdentityFromTarget(sourceTarget);
4458
+ identities[i] = known;
4459
+ }
4460
+ if (known >= 0 ? known === identity : hasMatchingRecursionIdentity(c, s, identity)) {
4461
+ if (s.id >= lastTypeId) {
4462
+ count++;
4463
+ if (count >= maxDepth) return true;
4464
+ }
4465
+ lastTypeId = s.id;
4466
+ }
4467
+ }
4468
+ return false;
4469
+ }
4470
+
4471
+ /**
4472
+ * The type whose recursion identity `t` has: the object type of an indexed access (T in T[K]), and for a
4473
+ * homomorphic mapped type the deepest target type that has a symbol. Unwrapping mapped types keeps the identities of
4474
+ * mapped types applied to written object literals unique: in `Mapped<{ x: Mapped<{ x: Mapped<{ x: string }>}>}>`,
4475
+ * each application has the identity of its object literal and does not appear deeply nested.
4476
+ */
4477
+ function getRecursionIdentityTarget(c: Checker, t: Type): Type {
4355
4478
  for (;;) {
4479
+ if ((t.flags & TypeFlags.IndexedAccess) !== 0) {
4480
+ t = (t as IndexedAccessType).objectType;
4481
+ continue;
4482
+ }
4356
4483
  if (
4357
4484
  (t.objectFlags & ObjectFlags.InstantiatedMapped) === ObjectFlags.InstantiatedMapped &&
4358
4485
  (t.flags & TypeFlags.Object) !== 0
@@ -4371,20 +4498,20 @@ function getMappedTargetWithSymbol(c: Checker, t: Type): Type {
4371
4498
  }
4372
4499
 
4373
4500
  function hasMatchingRecursionIdentity(c: Checker, t: Type, identity: RecursionId): boolean {
4374
- if (
4375
- (t.objectFlags & ObjectFlags.InstantiatedMapped) === ObjectFlags.InstantiatedMapped &&
4376
- (t.flags & TypeFlags.Object) !== 0
4377
- )
4378
- t = getMappedTargetWithSymbol(c, t);
4379
- if ((t.flags & TypeFlags.Intersection) !== 0) {
4380
- for (const u of typesOf(t)) if (hasMatchingRecursionIdentity(c, u, identity)) return true;
4501
+ const target = getRecursionIdentityTarget(c, t);
4502
+ if ((target.flags & TypeFlags.Intersection) !== 0) {
4503
+ for (const u of typesOf(target)) if (hasMatchingRecursionIdentity(c, u, identity)) return true;
4381
4504
  return false;
4382
4505
  }
4383
- return getRecursionIdentity(t) === identity;
4506
+ return getRecursionIdentityFromTarget(target) === identity;
4384
4507
  }
4385
4508
 
4386
4509
  /** An identity shared by instantiations of a type, so infinitely expanding instantiations can be detected. */
4387
- export function getRecursionIdentity(t: Type): RecursionId {
4510
+ export function getRecursionIdentity(c: Checker, t: Type): RecursionId {
4511
+ return getRecursionIdentityFromTarget(getRecursionIdentityTarget(c, t));
4512
+ }
4513
+
4514
+ function getRecursionIdentityFromTarget(t: Type): RecursionId {
4388
4515
  if (
4389
4516
  (t.flags & TypeFlags.Object) !== 0 &&
4390
4517
  (t.objectFlags & (ObjectFlags.ObjectLiteral | ObjectFlags.ArrayLiteral)) === 0
@@ -4401,12 +4528,6 @@ export function getRecursionIdentity(t: Type): RecursionId {
4401
4528
  return typeRecursionId((t as TypeReference).target!);
4402
4529
  }
4403
4530
  if ((t.flags & TypeFlags.TypeParameter) !== 0 && t.symbol !== undefined) return symbolRecursionId(t.symbol);
4404
- if ((t.flags & TypeFlags.IndexedAccess) !== 0) {
4405
- let objectType = (t as IndexedAccessType).objectType;
4406
- while ((objectType.flags & TypeFlags.IndexedAccess) !== 0)
4407
- objectType = (objectType as IndexedAccessType).objectType;
4408
- return typeRecursionId(objectType);
4409
- }
4410
4531
  if ((t.flags & TypeFlags.Conditional) !== 0) return nodeRecursionId((t as ConditionalType).root.node);
4411
4532
  return typeRecursionId(t);
4412
4533
  }
@@ -4444,16 +4565,45 @@ export function getAliasVariances(c: Checker, symbol: Symbol): VarianceFlags[] {
4444
4565
  * The measured variance of each type parameter, from relating marker instantiations; empty when
4445
4566
  * requested recursively.
4446
4567
  */
4568
+ /** A generic type whose variances are being computed. */
4569
+ export class VarianceStackEntry {
4570
+ constructor(
4571
+ readonly symbol: Symbol,
4572
+ readonly typeParameters: readonly Type[],
4573
+ ) {}
4574
+ }
4575
+
4447
4576
  function getVariancesWorker(c: Checker, symbol: Symbol, typeParameters: readonly Type[]): VarianceFlags[] {
4448
4577
  const links = c.symbolLinks(symbol);
4449
4578
  if (links.variances !== undefined) return links.variances;
4450
- const oldVarianceComputation = c.inVarianceComputation;
4451
- const saveResolutionStart = c.resolutionStart;
4452
- if (!c.inVarianceComputation) {
4453
- c.inVarianceComputation = true;
4454
- c.resolutionStart = c.resolutionDepth;
4579
+ let stackIndex = -1;
4580
+ for (let i = 0; i < c.varianceStack.length; i++)
4581
+ if (c.varianceStack[i]!.symbol === symbol) {
4582
+ stackIndex = i;
4583
+ break;
4584
+ }
4585
+ if (stackIndex >= 0) {
4586
+ // A circularity. The variances computed can depend on where the circular region is entered, so the
4587
+ // computation restarts from the generic type with the smallest symbol in the region if that is not this one,
4588
+ // which keeps the results of circular generic types stable.
4589
+ let minIndex = stackIndex;
4590
+ for (let i = stackIndex + 1; i < c.varianceStack.length; i++)
4591
+ if (compareSymbols(c, c.varianceStack[i]!.symbol, c.varianceStack[minIndex]!.symbol) < 0) minIndex = i;
4592
+ if (minIndex > stackIndex) {
4593
+ const saveVarianceStack = c.varianceStack;
4594
+ c.varianceStack = [];
4595
+ getVariancesWorker(c, saveVarianceStack[minIndex]!.symbol, saveVarianceStack[minIndex]!.typeParameters);
4596
+ c.varianceStack = saveVarianceStack;
4597
+ }
4598
+ // Variances that cannot be computed: the type parameters are treated as covariant. The computation in
4599
+ // progress stores its results over this.
4600
+ const stored = storedVariances(links);
4601
+ if (stored === undefined || stored.length === 0) links.variances = [];
4602
+ return links.variances!;
4455
4603
  }
4456
- links.variances = [];
4604
+ const saveResolutionStart = c.resolutionStart;
4605
+ if (c.varianceStack.length === 0) c.resolutionStart = c.resolutionDepth;
4606
+ c.varianceStack.push(new VarianceStackEntry(symbol, typeParameters));
4457
4607
  const variances: VarianceFlags[] = [];
4458
4608
  for (const tp of typeParameters) {
4459
4609
  const modifiers = getTypeParameterModifiers(tp);
@@ -4480,14 +4630,22 @@ function getVariancesWorker(c: Checker, symbol: Symbol, typeParameters: readonly
4480
4630
  if ((c.reliabilityFlags & RelationComparisonResult.ReportsUnreliable) !== 0) variance |= VarianceFlags.Unreliable;
4481
4631
  c.reliabilityFlags = saveReliabilityFlags;
4482
4632
  }
4633
+ // A computation restarted because of a circularity may have stored the variances already.
4634
+ const restarted = storedVariances(links);
4635
+ if (restarted !== undefined && restarted.length !== 0) break;
4483
4636
  variances.push(variance);
4484
4637
  }
4485
- if (!oldVarianceComputation) {
4486
- c.inVarianceComputation = false;
4487
- c.resolutionStart = saveResolutionStart;
4488
- }
4489
- links.variances = variances;
4490
- return variances;
4638
+ // Unless a restarted computation stored them.
4639
+ const stored = storedVariances(links);
4640
+ if (stored === undefined || stored.length === 0) links.variances = variances;
4641
+ c.varianceStack.pop();
4642
+ if (c.varianceStack.length === 0) c.resolutionStart = saveResolutionStart;
4643
+ return links.variances!;
4644
+ }
4645
+
4646
+ /** The variances stored in `links`, read again after computations that may have stored them. */
4647
+ function storedVariances(links: SymbolLinks): VarianceFlags[] | undefined {
4648
+ return links.variances;
4491
4649
  }
4492
4650
 
4493
4651
  export function createMarkerType(c: Checker, symbol: Symbol, source: Type, target: Type): Type {
@@ -5131,6 +5289,8 @@ export function isExactOptionalPropertyMismatch(
5131
5289
  }
5132
5290
 
5133
5291
  /** The string literal member of `target` closest to the string literal `source`. */
5292
+ const maxStringLiteralSuggestionCandidates = 1000;
5293
+
5134
5294
  function getSuggestedTypeForNonexistentStringLiteralType(c: Checker, source: Type, target: Type): Type | undefined {
5135
5295
  const value = (source as LiteralType).stringValue;
5136
5296
  const valueCodePoints = new CodePoints();
@@ -5139,8 +5299,11 @@ function getSuggestedTypeForNonexistentStringLiteralType(c: Checker, source: Typ
5139
5299
  let bestDistance = Math.floor(valueCodePoints.length * 0.4) + 0.9;
5140
5300
  let best: Type | undefined = undefined;
5141
5301
  const lowerValue = value.toLowerCase();
5302
+ // A target with more string literal candidates than this gets no suggestion.
5303
+ let candidates = 0;
5142
5304
  for (const t of typesOf(target)) {
5143
5305
  if ((t.flags & TypeFlags.StringLiteral) === 0) continue;
5306
+ if (++candidates > maxStringLiteralSuggestionCandidates) return undefined;
5144
5307
  const name = (t as LiteralType).stringValue;
5145
5308
  const nameLength = utf8Length(name);
5146
5309
  if (name === '' || Math.abs(nameLength - valueCodePoints.length) > maximumLengthDifference || name === value)
@@ -891,11 +891,15 @@ export class Reparser {
891
891
  if ((clause as HeritageClause).types.nodes.length !== 1) return false;
892
892
  const target = (clause as HeritageClause).types.nodes[0]!;
893
893
  const source = tag.className;
894
+ // The tag's type arguments apply to an `extends` clause without any: one naming the same
895
+ // entity, or another expression such as a call (`extends mixin(Base)`), but not `null`.
894
896
  if (
895
897
  target instanceof ExpressionWithTypeArguments &&
896
- hasSamePropertyAccessName((target as ExpressionWithTypeArguments).expression, source.expression) &&
897
898
  (target as ExpressionWithTypeArguments).typeArguments === undefined &&
898
- source.typeArguments !== undefined
899
+ source.typeArguments !== undefined &&
900
+ (target as ExpressionWithTypeArguments).expression.kind !== SyntaxKind.NullKeyword &&
901
+ (!isEntityNameExpression((target as ExpressionWithTypeArguments).expression, false) ||
902
+ hasSamePropertyAccessName((target as ExpressionWithTypeArguments).expression, source.expression))
899
903
  ) {
900
904
  const newArguments: Node[] = [];
901
905
  for (const arg of source.typeArguments.nodes) newArguments.push(this.addDeepCloneReparse(arg));
@@ -966,6 +970,7 @@ export class Reparser {
966
970
  modifiers,
967
971
  SyntaxKind.NamespaceKeyword,
968
972
  this.addDeepCloneReparse((fullName as ModuleDeclaration).name),
973
+ undefined,
969
974
  block,
970
975
  );
971
976
  this.finishReparsedNode(result, fullName);