tsc-ts 0.0.10 → 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 (367) hide show
  1. package/README.md +1 -1
  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 +20 -15
  6. package/dist/api/compiler/ast.js +1023 -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 +173 -123
  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 +469 -438
  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 -113
  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 +210 -74
  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 +137 -34
  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 +93 -31
  73. package/dist/api/compiler/checker.js +143 -35
  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 +19 -4
  77. package/dist/api/compiler/compile-program.js +45 -26
  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.js +7 -7
  81. package/dist/api/compiler/emitter.d.ts +7 -1
  82. package/dist/api/compiler/emitter.js +53 -11
  83. package/dist/api/compiler/file-include.d.ts +2 -1
  84. package/dist/api/compiler/file-include.js +11 -7
  85. package/dist/api/compiler/file-loader.d.ts +10 -0
  86. package/dist/api/compiler/file-loader.js +138 -41
  87. package/dist/api/compiler/instantiation.d.ts +7 -0
  88. package/dist/api/compiler/instantiation.js +101 -49
  89. package/dist/api/compiler/jsdoc.js +23 -23
  90. package/dist/api/compiler/link-tables.d.ts +48 -18
  91. package/dist/api/compiler/link-tables.js +80 -37
  92. package/dist/api/compiler/locales/cs-CZ.d.ts +1 -1
  93. package/dist/api/compiler/locales/cs-CZ.js +1 -1
  94. package/dist/api/compiler/locales/de-DE.d.ts +1 -1
  95. package/dist/api/compiler/locales/de-DE.js +1 -1
  96. package/dist/api/compiler/locales/es-ES.d.ts +1 -1
  97. package/dist/api/compiler/locales/es-ES.js +1 -1
  98. package/dist/api/compiler/locales/fr-FR.d.ts +1 -1
  99. package/dist/api/compiler/locales/fr-FR.js +1 -1
  100. package/dist/api/compiler/locales/it-IT.d.ts +1 -1
  101. package/dist/api/compiler/locales/it-IT.js +1 -1
  102. package/dist/api/compiler/locales/ja-JP.d.ts +1 -1
  103. package/dist/api/compiler/locales/ja-JP.js +1 -1
  104. package/dist/api/compiler/locales/ko-KR.d.ts +1 -1
  105. package/dist/api/compiler/locales/ko-KR.js +1 -1
  106. package/dist/api/compiler/locales/pl-PL.d.ts +1 -1
  107. package/dist/api/compiler/locales/pl-PL.js +1 -1
  108. package/dist/api/compiler/locales/pt-BR.d.ts +1 -1
  109. package/dist/api/compiler/locales/pt-BR.js +1 -1
  110. package/dist/api/compiler/locales/ru-RU.d.ts +1 -1
  111. package/dist/api/compiler/locales/ru-RU.js +1 -1
  112. package/dist/api/compiler/locales/tr-TR.d.ts +1 -1
  113. package/dist/api/compiler/locales/tr-TR.js +1 -1
  114. package/dist/api/compiler/locales/zh-CN.d.ts +1 -1
  115. package/dist/api/compiler/locales/zh-CN.js +1 -1
  116. package/dist/api/compiler/locales/zh-TW.d.ts +1 -1
  117. package/dist/api/compiler/locales/zh-TW.js +1 -1
  118. package/dist/api/compiler/module-resolution-types.js +6 -6
  119. package/dist/api/compiler/module-resolution.d.ts +10 -1
  120. package/dist/api/compiler/module-resolution.js +115 -84
  121. package/dist/api/compiler/module-specifiers.d.ts +15 -0
  122. package/dist/api/compiler/module-specifiers.js +24 -18
  123. package/dist/api/compiler/name-resolver.js +74 -65
  124. package/dist/api/compiler/node-builder-names.d.ts +11 -3
  125. package/dist/api/compiler/node-builder-names.js +210 -90
  126. package/dist/api/compiler/node-builder-pseudo.js +29 -31
  127. package/dist/api/compiler/node-builder-reuse.js +23 -22
  128. package/dist/api/compiler/node-builder.d.ts +18 -1
  129. package/dist/api/compiler/node-builder.js +191 -102
  130. package/dist/api/compiler/option-declarations.d.ts +2 -6
  131. package/dist/api/compiler/option-declarations.js +315 -375
  132. package/dist/api/compiler/options.d.ts +15 -33
  133. package/dist/api/compiler/options.js +21 -54
  134. package/dist/api/compiler/output-paths.d.ts +4 -1
  135. package/dist/api/compiler/output-paths.js +6 -11
  136. package/dist/api/compiler/package-json.d.ts +3 -3
  137. package/dist/api/compiler/package-json.js +11 -10
  138. package/dist/api/compiler/parser.d.ts +40 -19
  139. package/dist/api/compiler/parser.js +308 -216
  140. package/dist/api/compiler/path.d.ts +9 -0
  141. package/dist/api/compiler/path.js +20 -3
  142. package/dist/api/compiler/printer/emit-context.d.ts +3 -1
  143. package/dist/api/compiler/printer/emit-context.js +16 -1
  144. package/dist/api/compiler/printer/factory-base.d.ts +2 -2
  145. package/dist/api/compiler/printer/factory-base.js +7 -3
  146. package/dist/api/compiler/printer/factory.js +3 -1
  147. package/dist/api/compiler/printer/helpers.js +10 -1
  148. package/dist/api/compiler/printer/name-generator.d.ts +1 -1
  149. package/dist/api/compiler/printer/name-generator.js +35 -16
  150. package/dist/api/compiler/printer/printer.d.ts +1 -0
  151. package/dist/api/compiler/printer/printer.js +303 -281
  152. package/dist/api/compiler/printer/utilities.js +149 -147
  153. package/dist/api/compiler/program-checker.d.ts +8 -2
  154. package/dist/api/compiler/program-checker.js +84 -34
  155. package/dist/api/compiler/program-utilities.d.ts +3 -1
  156. package/dist/api/compiler/program-utilities.js +28 -15
  157. package/dist/api/compiler/program.d.ts +2 -0
  158. package/dist/api/compiler/program.js +69 -57
  159. package/dist/api/compiler/pseudo-bigint.d.ts +2 -0
  160. package/dist/api/compiler/pseudo-bigint.js +18 -0
  161. package/dist/api/compiler/regexp-checker.d.ts +1 -1
  162. package/dist/api/compiler/regexp-checker.js +93 -76
  163. package/dist/api/compiler/relations.d.ts +27 -4
  164. package/dist/api/compiler/relations.js +337 -180
  165. package/dist/api/compiler/reparser.js +60 -56
  166. package/dist/api/compiler/scanner.d.ts +19 -2
  167. package/dist/api/compiler/scanner.js +123 -108
  168. package/dist/api/compiler/shared-results.d.ts +463 -0
  169. package/dist/api/compiler/shared-results.js +2128 -0
  170. package/dist/api/compiler/sourcemap.js +2 -2
  171. package/dist/api/compiler/symbol-accessibility.js +87 -74
  172. package/dist/api/compiler/symbol.d.ts +22 -13
  173. package/dist/api/compiler/symbol.js +15 -1
  174. package/dist/api/compiler/syntax-kind.d.ts +198 -197
  175. package/dist/api/compiler/transformers/alias-references.js +247 -139
  176. package/dist/api/compiler/transformers/async-utilities.js +25 -25
  177. package/dist/api/compiler/transformers/async.d.ts +0 -1
  178. package/dist/api/compiler/transformers/async.js +64 -77
  179. package/dist/api/compiler/transformers/class-fields.d.ts +1 -0
  180. package/dist/api/compiler/transformers/class-fields.js +81 -78
  181. package/dist/api/compiler/transformers/commonjs-module.js +18 -15
  182. package/dist/api/compiler/transformers/const-enum-inliner.js +1 -1
  183. package/dist/api/compiler/transformers/declarations-diagnostics.js +247 -244
  184. package/dist/api/compiler/transformers/declarations-pseudo.js +100 -100
  185. package/dist/api/compiler/transformers/declarations-resolver.d.ts +0 -3
  186. package/dist/api/compiler/transformers/declarations-syntactic.d.ts +1 -2
  187. package/dist/api/compiler/transformers/declarations-syntactic.js +134 -156
  188. package/dist/api/compiler/transformers/declarations-tracker.js +18 -18
  189. package/dist/api/compiler/transformers/declarations.d.ts +4 -1
  190. package/dist/api/compiler/transformers/declarations.js +305 -238
  191. package/dist/api/compiler/transformers/decorator-metadata.d.ts +1 -1
  192. package/dist/api/compiler/transformers/decorator-metadata.js +53 -45
  193. package/dist/api/compiler/transformers/decorator-utilities.js +24 -24
  194. package/dist/api/compiler/transformers/destructuring.js +19 -18
  195. package/dist/api/compiler/transformers/emit-resolver.js +1 -1
  196. package/dist/api/compiler/transformers/es-decorators.js +55 -55
  197. package/dist/api/compiler/transformers/external-module-info.js +3 -3
  198. package/dist/api/compiler/transformers/for-await.js +25 -25
  199. package/dist/api/compiler/transformers/import-elision.js +14 -14
  200. package/dist/api/compiler/transformers/jsx.js +12 -12
  201. package/dist/api/compiler/transformers/legacy-decorators.js +17 -17
  202. package/dist/api/compiler/transformers/module.js +8 -8
  203. package/dist/api/compiler/transformers/named-evaluation.js +4 -4
  204. package/dist/api/compiler/transformers/object-rest-spread.js +20 -20
  205. package/dist/api/compiler/transformers/optional-chain.js +10 -10
  206. package/dist/api/compiler/transformers/reference-resolver.d.ts +12 -1
  207. package/dist/api/compiler/transformers/reference-resolver.js +131 -69
  208. package/dist/api/compiler/transformers/runtime-syntax.js +35 -31
  209. package/dist/api/compiler/transformers/subtree-facts.js +47 -47
  210. package/dist/api/compiler/transformers/syntax-facts.js +56 -58
  211. package/dist/api/compiler/transformers/type-eraser.js +73 -66
  212. package/dist/api/compiler/transformers/type-serialization.js +24 -24
  213. package/dist/api/compiler/transformers/using.js +12 -12
  214. package/dist/api/compiler/transformers/utilities.js +77 -77
  215. package/dist/api/compiler/transformers/visitor-base.js +172 -172
  216. package/dist/api/compiler/transformers/visitor-hooks.js +6 -2
  217. package/dist/api/compiler/tsconfig.d.ts +10 -2
  218. package/dist/api/compiler/tsconfig.js +136 -48
  219. package/dist/api/compiler/type-printer.js +40 -3
  220. package/dist/api/compiler/types.d.ts +2 -1
  221. package/dist/api/library/ast.generated.d.ts +42 -39
  222. package/dist/api/library/ast.generated.js +1 -1
  223. package/dist/api/library/compiler-options.generated.d.ts +111 -100
  224. package/dist/api/library/compiler-options.generated.js +1 -1
  225. package/dist/api/library/disk.js +12 -1
  226. package/dist/api/library/enums.generated.d.ts +206 -206
  227. package/dist/api/library/enums.generated.js +206 -206
  228. package/dist/api/library/nodes.js +26 -26
  229. package/package.json +9 -9
  230. package/src/compiler/ast-utilities.ts +99 -7
  231. package/src/compiler/ast.ts +55 -26
  232. package/src/compiler/binder.ts +39 -4
  233. package/src/compiler/character-codes.ts +2 -2
  234. package/src/compiler/checker-calls.ts +76 -8
  235. package/src/compiler/checker-classes.ts +78 -24
  236. package/src/compiler/checker-contextual.ts +6 -1
  237. package/src/compiler/checker-declarations.ts +31 -4
  238. package/src/compiler/checker-declared-types.ts +8 -5
  239. package/src/compiler/checker-decorators.ts +1 -1
  240. package/src/compiler/checker-deprecation.ts +29 -8
  241. package/src/compiler/checker-destructuring.ts +10 -3
  242. package/src/compiler/checker-emit-helpers.ts +1 -0
  243. package/src/compiler/checker-emit-resolver.ts +16 -6
  244. package/src/compiler/checker-expressions.ts +79 -46
  245. package/src/compiler/checker-functions.ts +21 -6
  246. package/src/compiler/checker-generated-code.ts +2 -22
  247. package/src/compiler/checker-grammar.ts +133 -60
  248. package/src/compiler/checker-heritage.ts +22 -21
  249. package/src/compiler/checker-inference.ts +514 -87
  250. package/src/compiler/checker-iteration.ts +18 -31
  251. package/src/compiler/checker-javascript.ts +1 -1
  252. package/src/compiler/checker-jsdoc.ts +50 -27
  253. package/src/compiler/checker-jsx.ts +26 -4
  254. package/src/compiler/checker-members.ts +197 -55
  255. package/src/compiler/checker-modules.ts +332 -65
  256. package/src/compiler/checker-narrowing.ts +98 -19
  257. package/src/compiler/checker-object-literals.ts +3 -0
  258. package/src/compiler/checker-operators.ts +11 -4
  259. package/src/compiler/checker-property-access.ts +7 -2
  260. package/src/compiler/checker-services.ts +39 -12
  261. package/src/compiler/checker-signatures.ts +15 -1
  262. package/src/compiler/checker-source-file.ts +39 -13
  263. package/src/compiler/checker-statements.ts +3 -2
  264. package/src/compiler/checker-symbol-types.ts +29 -6
  265. package/src/compiler/checker-symbols.ts +158 -15
  266. package/src/compiler/checker-type-factory.ts +120 -21
  267. package/src/compiler/checker-type-nodes.ts +46 -3
  268. package/src/compiler/checker-type-operators.ts +83 -26
  269. package/src/compiler/checker-types.ts +147 -4
  270. package/src/compiler/checker-unused.ts +9 -14
  271. package/src/compiler/checker.ts +168 -41
  272. package/src/compiler/command-line.ts +28 -28
  273. package/src/compiler/compile-program.ts +51 -25
  274. package/src/compiler/decoder.ts +13 -4
  275. package/src/compiler/diagnostic-messages.ts +1973 -1892
  276. package/src/compiler/emitter.ts +57 -8
  277. package/src/compiler/encoder.ts +23 -8
  278. package/src/compiler/file-include.ts +9 -3
  279. package/src/compiler/file-loader.ts +139 -32
  280. package/src/compiler/help.ts +10 -14
  281. package/src/compiler/incremental.ts +86 -18
  282. package/src/compiler/init.ts +2 -7
  283. package/src/compiler/instantiation.ts +77 -22
  284. package/src/compiler/jsdoc.ts +3 -1
  285. package/src/compiler/link-tables.ts +82 -37
  286. package/src/compiler/locales/cs-CZ.ts +1 -1
  287. package/src/compiler/locales/de-DE.ts +1 -1
  288. package/src/compiler/locales/es-ES.ts +1 -1
  289. package/src/compiler/locales/fr-FR.ts +1 -1
  290. package/src/compiler/locales/it-IT.ts +1 -1
  291. package/src/compiler/locales/ja-JP.ts +1 -1
  292. package/src/compiler/locales/ko-KR.ts +1 -1
  293. package/src/compiler/locales/pl-PL.ts +1 -1
  294. package/src/compiler/locales/pt-BR.ts +1 -1
  295. package/src/compiler/locales/ru-RU.ts +1 -1
  296. package/src/compiler/locales/tr-TR.ts +1 -1
  297. package/src/compiler/locales/zh-CN.ts +1 -1
  298. package/src/compiler/locales/zh-TW.ts +1 -1
  299. package/src/compiler/module-resolution.ts +44 -8
  300. package/src/compiler/module-specifiers.ts +62 -20
  301. package/src/compiler/name-resolver.ts +9 -1
  302. package/src/compiler/node-builder-names.ts +236 -54
  303. package/src/compiler/node-builder-pseudo.ts +4 -7
  304. package/src/compiler/node-builder-reuse.ts +5 -4
  305. package/src/compiler/node-builder.ts +130 -31
  306. package/src/compiler/option-declarations.ts +33 -103
  307. package/src/compiler/options.ts +23 -62
  308. package/src/compiler/output-paths.ts +5 -18
  309. package/src/compiler/package-entrypoints.ts +345 -0
  310. package/src/compiler/package-json.ts +4 -4
  311. package/src/compiler/parallel-check.ts +197 -8
  312. package/src/compiler/parallel-emit.ts +1 -1
  313. package/src/compiler/parser.ts +156 -39
  314. package/src/compiler/path.ts +22 -2
  315. package/src/compiler/printer/emit-context.ts +16 -0
  316. package/src/compiler/printer/factory-base.ts +10 -3
  317. package/src/compiler/printer/factory.ts +4 -1
  318. package/src/compiler/printer/helpers.ts +10 -1
  319. package/src/compiler/printer/name-generator.ts +24 -2
  320. package/src/compiler/printer/printer.ts +35 -14
  321. package/src/compiler/printer/utilities.ts +8 -2
  322. package/src/compiler/program-checker.ts +53 -5
  323. package/src/compiler/program-utilities.ts +23 -10
  324. package/src/compiler/program.ts +13 -1
  325. package/src/compiler/pseudo-bigint.ts +17 -0
  326. package/src/compiler/regexp-checker.ts +63 -30
  327. package/src/compiler/relations.ts +233 -77
  328. package/src/compiler/reparser.ts +7 -2
  329. package/src/compiler/scanner.ts +109 -79
  330. package/src/compiler/shared-results.ts +2414 -0
  331. package/src/compiler/show-config.ts +18 -1
  332. package/src/compiler/sourcemap.ts +2 -2
  333. package/src/compiler/symbol-accessibility.ts +26 -3
  334. package/src/compiler/symbol.ts +31 -14
  335. package/src/compiler/syntax-kind.ts +188 -187
  336. package/src/compiler/thread-entry.ts +19 -2
  337. package/src/compiler/transformers/alias-references.ts +123 -4
  338. package/src/compiler/transformers/async.ts +2 -17
  339. package/src/compiler/transformers/class-fields.ts +13 -12
  340. package/src/compiler/transformers/commonjs-module.ts +11 -7
  341. package/src/compiler/transformers/declarations-diagnostics.ts +5 -3
  342. package/src/compiler/transformers/declarations-pseudo.ts +2 -4
  343. package/src/compiler/transformers/declarations-resolver.ts +0 -3
  344. package/src/compiler/transformers/declarations-syntactic.ts +1 -21
  345. package/src/compiler/transformers/declarations.ts +134 -48
  346. package/src/compiler/transformers/decorator-metadata.ts +9 -1
  347. package/src/compiler/transformers/destructuring.ts +4 -3
  348. package/src/compiler/transformers/external-module-info.ts +1 -1
  349. package/src/compiler/transformers/jsx.ts +2 -1
  350. package/src/compiler/transformers/reference-resolver.ts +83 -19
  351. package/src/compiler/transformers/runtime-syntax.ts +6 -1
  352. package/src/compiler/transformers/syntax-facts.ts +2 -7
  353. package/src/compiler/transformers/type-eraser.ts +10 -1
  354. package/src/compiler/transformers/type-serialization.ts +3 -2
  355. package/src/compiler/transformers/visitor-base.ts +2 -1
  356. package/src/compiler/transformers/visitor-hooks.ts +9 -4
  357. package/src/compiler/tsc-build.ts +3 -0
  358. package/src/compiler/tsc-cli.ts +2 -0
  359. package/src/compiler/tsc-compile.ts +7 -2
  360. package/src/compiler/tsc-watch.ts +74 -45
  361. package/src/compiler/tsconfig.ts +176 -19
  362. package/src/compiler/type-printer.ts +36 -2
  363. package/src/compiler/types.ts +2 -1
  364. package/src/library/ast.generated.ts +57 -41
  365. package/src/library/compiler-options.generated.ts +117 -103
  366. package/src/library/disk.ts +10 -1
  367. package/src/library/enums.generated.ts +196 -196
@@ -36,11 +36,24 @@ import {
36
36
  getSourceFileOfNode,
37
37
  isModuleAugmentationExternal,
38
38
  } from './binder-utilities.js';
39
- import { getExternalModuleName, isAmbientModule, isGlobalScopeAugmentation, isRequireCall } from './ast-utilities.js';
39
+ import {
40
+ getExternalModuleName,
41
+ isAmbientModule,
42
+ isGlobalScopeAugmentation,
43
+ isImportCall,
44
+ isRequireCall,
45
+ } from './ast-utilities.js';
40
46
  import { getSymbolAtLocation } from './checker-services.js';
41
47
  import { checkExpression } from './checker-expressions.js';
42
- import { getExportsOfSymbol, getMembersOfSymbol, isAmbientModuleSymbolName, resolveAlias } from './checker-symbols.js';
43
- import { compareSymbols } from './checker-type-factory.js';
48
+ import { getExportsOfSymbol, getMembersOfSymbol, getMergedSymbol, resolveAlias } from './checker-symbols.js';
49
+ import {
50
+ getImportAttributesTypeForModuleSpecifier,
51
+ getTypeOfModuleImportAttributes,
52
+ resolveExternalModule,
53
+ } from './checker-modules.js';
54
+ import { getPropertiesOfType } from './checker-members.js';
55
+ import { getTypeOfSymbol } from './checker-symbol-types.js';
56
+ import { compareSymbols, isEmptyObjectType } from './checker-type-factory.js';
44
57
  import { TypeFlags, type LiteralType, type Type } from './checker-types.js';
45
58
  import { isLateBoundName } from './checker-utilities.js';
46
59
  import { isExternalModuleNameRelative, pathIsRelative } from './path.js';
@@ -67,6 +80,7 @@ import {
67
80
  getQualifiedLeftMeaning,
68
81
  getSymbolIfSameReference,
69
82
  hasNonGlobalAugmentationExternalModuleDeclaration,
83
+ isSymbolAccessibleByFlags,
70
84
  needsQualification,
71
85
  } from './symbol-accessibility.js';
72
86
  import { SyntaxKind } from './syntax-kind.js';
@@ -82,6 +96,7 @@ import {
82
96
  InternalSymbolName,
83
97
  type Symbol,
84
98
  SymbolFlags,
99
+ tryGetAmbientModuleNameFromSymbolName,
85
100
  } from './symbol.js';
86
101
 
87
102
  // ---- Symbol chains
@@ -94,6 +109,16 @@ export function lookupSymbolChain(
94
109
  yieldModuleSymbol: boolean,
95
110
  ): Symbol[] {
96
111
  b.trackSymbol(symbol, b.enclosingDeclaration, meaning);
112
+ return lookupSymbolChainWorker(b, symbol, meaning, yieldModuleSymbol);
113
+ }
114
+
115
+ /** `lookupSymbolChain` without tracking the symbol's accessibility. */
116
+ function lookupSymbolChainWorker(
117
+ b: NodeBuilder,
118
+ symbol: Symbol,
119
+ meaning: SymbolFlags,
120
+ yieldModuleSymbol: boolean,
121
+ ): Symbol[] {
97
122
  // Qualified only with somewhere to qualify from, and never for type parameters.
98
123
  if (
99
124
  (symbol.flags & SymbolFlags.TypeParameter) === 0 &&
@@ -132,7 +157,7 @@ function getSymbolChain(
132
157
  order.push(specifiers.length);
133
158
  specifiers.push(
134
159
  hasNonGlobalAugmentationExternalModuleDeclaration(p)
135
- ? getSpecifierForModuleSymbol(b, p, ModuleKind.None)
160
+ ? getSpecifierForModuleSymbol(b, p, ModuleKind.None).specifier
136
161
  : '',
137
162
  );
138
163
  }
@@ -197,8 +222,8 @@ export function symbolToTypeNode(
197
222
  const nonRootParts =
198
223
  chain.length > 1 ? createAccessFromSymbolChain(b, chain, chain.length - 1, 1, typeArguments) : undefined;
199
224
  const typeParameterNodes = typeArguments ?? lookupTypeParameterNodes(b, chain, 0);
200
- let specifier = '';
201
- let attributes: ImportAttributes | undefined = undefined;
225
+ let specifier = new ModuleSpecifierResult('', undefined);
226
+ let importModeOverride = ModuleKind.None;
202
227
  const c = b.c;
203
228
  const resolution = getModuleResolutionKind(c.compilerOptions);
204
229
  const nodeNext = resolution === ModuleResolutionKind.Node16 || resolution === ModuleResolutionKind.NodeNext;
@@ -213,29 +238,33 @@ export function symbolToTypeNode(
213
238
  const targetFormat = c.host.getEmitModuleFormatOfFile(targetFile);
214
239
  if (targetFormat === ModuleKind.ESNext && targetFormat !== c.host.getEmitModuleFormatOfFile(contextFile)) {
215
240
  specifier = getSpecifierForModuleSymbol(b, chain[0]!, ModuleKind.ESNext);
216
- attributes = resolutionModeAttributes(b, 'import');
241
+ importModeOverride = ModuleKind.ESNext;
217
242
  }
218
243
  }
219
244
  }
220
- if (specifier === '') specifier = getSpecifierForModuleSymbol(b, chain[0]!, ModuleKind.None);
221
- if ((b.flags & NodeBuilderFlags.AllowNodeModulesRelativePaths) === 0 && specifier.includes('/node_modules/')) {
245
+ if (specifier.specifier === '') specifier = getSpecifierForModuleSymbol(b, chain[0]!, ModuleKind.None);
246
+ if (
247
+ (b.flags & NodeBuilderFlags.AllowNodeModulesRelativePaths) === 0 &&
248
+ specifier.specifier.includes('/node_modules/')
249
+ ) {
222
250
  const oldSpecifier = specifier;
223
251
  if (nodeNext && contextFile !== undefined) {
224
252
  // The other mode may reach the module portably.
225
253
  const swappedMode =
226
254
  c.host.getEmitModuleFormatOfFile(contextFile) === ModuleKind.ESNext ? ModuleKind.CommonJS : ModuleKind.ESNext;
227
255
  specifier = getSpecifierForModuleSymbol(b, chain[0]!, swappedMode);
228
- if (specifier.includes('/node_modules/')) specifier = oldSpecifier;
229
- else attributes = resolutionModeAttributes(b, swappedMode === ModuleKind.ESNext ? 'import' : 'require');
256
+ if (specifier.specifier.includes('/node_modules/')) specifier = oldSpecifier;
257
+ else importModeOverride = swappedMode;
230
258
  }
231
- if (attributes === undefined) {
259
+ if (importModeOverride === ModuleKind.None) {
232
260
  // A reference into `node_modules` is likely to break when published.
233
261
  b.encounteredError = true;
234
- b.tracker.reportLikelyUnsafeImportRequiredError(oldSpecifier, symbol.name);
262
+ b.tracker.reportLikelyUnsafeImportRequiredError(oldSpecifier.specifier, symbol.name);
235
263
  }
236
264
  }
237
- const literal = b.created(new LiteralTypeNode(b.stringLiteral(specifier, false)));
238
- b.approximateLength += specifier.length + 10;
265
+ const attributes = createImportAttributesForModuleSpecifier(b, specifier, importModeOverride);
266
+ const literal = b.created(new LiteralTypeNode(b.stringLiteral(specifier.specifier, false)));
267
+ b.approximateLength += specifier.specifier.length + 10;
239
268
  if (nonRootParts === undefined || isEntityName(nonRootParts))
240
269
  return b.created(new ImportTypeNode(isTypeOf, literal, attributes, nonRootParts, typeParameterNodes));
241
270
  const splitNode = getTopmostIndexedAccessType(nonRootParts as IndexedAccessTypeNode);
@@ -263,12 +292,48 @@ function isEntityName(node: Node): boolean {
263
292
  return node.kind === SyntaxKind.Identifier || node.kind === SyntaxKind.QualifiedName;
264
293
  }
265
294
 
266
- /** `with { "resolution-mode": "import" }` or `"require"`. */
267
- function resolutionModeAttributes(b: NodeBuilder, mode: string): ImportAttributes {
268
- const attribute = b.created(
269
- new ImportAttribute(b.stringLiteral('resolution-mode', false), b.stringLiteral(mode, false)),
270
- );
271
- return b.created(new ImportAttributes(SyntaxKind.WithKeyword, b.list([attribute]), false));
295
+ /**
296
+ * The attributes of an `import()` type: a `resolution-mode` for `importModeOverride`, then the
297
+ * string literal properties of the specifier's import attributes type, by name.
298
+ */
299
+ function createImportAttributesForModuleSpecifier(
300
+ b: NodeBuilder,
301
+ result: ModuleSpecifierResult,
302
+ importModeOverride: ModuleKind,
303
+ ): ImportAttributes | undefined {
304
+ const c = b.c;
305
+ const attributesType = result.importAttributesType;
306
+ const isEmptyAttributesType = attributesType === undefined || isEmptyObjectType(c, attributesType);
307
+ if (isEmptyAttributesType && importModeOverride === ModuleKind.None) return undefined;
308
+ const attributes: Node[] = [];
309
+ if (importModeOverride !== ModuleKind.None) {
310
+ const mode = importModeOverride === ModuleKind.ESNext ? 'import' : 'require';
311
+ attributes.push(
312
+ b.created(new ImportAttribute(b.stringLiteral('resolution-mode', false), b.stringLiteral(mode, false))),
313
+ );
314
+ b.approximateLength += 'resolution-mode'.length + mode.length + 6;
315
+ }
316
+ if (!isEmptyAttributesType) {
317
+ const properties = getPropertiesOfType(c, attributesType).slice();
318
+ properties.sort((x: Symbol, y: Symbol) => (x.name < y.name ? -1 : x.name > y.name ? 1 : 0));
319
+ for (const property of properties) {
320
+ const name = property.name;
321
+ const propertyType = getTypeOfSymbol(c, property);
322
+ if ((propertyType.flags & TypeFlags.StringLiteral) === 0) continue;
323
+ const value = (propertyType as LiteralType).stringValue;
324
+ let nameNode: Node;
325
+ if (isIdentifierText(name)) nameNode = b.factory.createIdentifier(name);
326
+ else {
327
+ nameNode = b.stringLiteral(name, false);
328
+ b.approximateLength += 2;
329
+ }
330
+ attributes.push(b.created(new ImportAttribute(nameNode, b.stringLiteral(value, false))));
331
+ b.approximateLength += name.length + value.length + 4;
332
+ }
333
+ }
334
+ if (attributes.length === 0) return undefined;
335
+ b.approximateLength += 16 + 2 * (attributes.length - 1);
336
+ return b.created(new ImportAttributes(SyntaxKind.WithKeyword, b.list(attributes), false));
272
337
  }
273
338
 
274
339
  function getTopmostIndexedAccessType(node: IndexedAccessTypeNode): IndexedAccessTypeNode {
@@ -355,7 +420,7 @@ function createAccessFromSymbolChain(
355
420
  return b.created(new IndexedAccessTypeNode(b.created(new TypeReferenceNode(lhs, typeParameterNodes)), literal));
356
421
  }
357
422
  }
358
- const identifier = b.identifier(symbolName);
423
+ const identifier = b.symbolIdentifier(symbolName, symbol);
359
424
  b.context.addEmitFlags(identifier, EmitFlags.NoAsciiEscaping);
360
425
  if (index > stopper) {
361
426
  const lhs = createAccessFromSymbolChain(b, chain, index - 1, stopper, overrideTypeArguments);
@@ -467,7 +532,7 @@ function createEntityNameFromSymbolChain(b: NodeBuilder, chain: Symbol[], index:
467
532
  if (index === 0) b.flags |= NodeBuilderFlags.InInitialEntityName;
468
533
  const symbolName = getNameOfSymbolAsWritten(b, symbol);
469
534
  if (index === 0) b.flags ^= NodeBuilderFlags.InInitialEntityName;
470
- const identifier = b.identifier(symbolName);
535
+ const identifier = b.symbolIdentifier(symbolName, symbol);
471
536
  b.context.addEmitFlags(identifier, EmitFlags.NoAsciiEscaping);
472
537
  if (index > 0) return b.created(new QualifiedName(createEntityNameFromSymbolChain(b, chain, index - 1), identifier));
473
538
  return identifier;
@@ -482,7 +547,13 @@ export function symbolToEntityNameNode(b: NodeBuilder, symbol: Symbol): Node {
482
547
  }
483
548
 
484
549
  export function symbolToExpression(b: NodeBuilder, symbol: Symbol, meaning: SymbolFlags): Node {
485
- const chain = lookupSymbolChain(b, symbol, meaning, false);
550
+ b.trackSymbol(symbol, b.enclosingDeclaration, meaning);
551
+ return symbolToExpressionWorker(b, symbol, meaning);
552
+ }
553
+
554
+ /** `symbolToExpression` without tracking the symbol's accessibility. */
555
+ function symbolToExpressionWorker(b: NodeBuilder, symbol: Symbol, meaning: SymbolFlags): Node {
556
+ const chain = lookupSymbolChainWorker(b, symbol, meaning, false);
486
557
  return createExpressionFromSymbolChain(b, chain, chain.length - 1);
487
558
  }
488
559
 
@@ -493,7 +564,7 @@ function createExpressionFromSymbolChain(b: NodeBuilder, chain: Symbol[], index:
493
564
  let symbolName = getNameOfSymbolAsWritten(b, symbol);
494
565
  if (index === 0) b.flags ^= NodeBuilderFlags.InInitialEntityName;
495
566
  if (startsWithQuote(symbolName) && hasNonGlobalAugmentationExternalModuleDeclaration(symbol)) {
496
- const specifier = getSpecifierForModuleSymbol(b, symbol, ModuleKind.None);
567
+ const specifier = getSpecifierForModuleSymbol(b, symbol, ModuleKind.None).specifier;
497
568
  b.approximateLength += 2 + specifier.length;
498
569
  return b.stringLiteral(specifier, false);
499
570
  }
@@ -719,7 +790,11 @@ function isSingleQuotedStringNamed(d: Node): boolean {
719
790
  }
720
791
 
721
792
  /** The name node of a property. */
722
- export function getPropertyNameNodeForSymbol(b: NodeBuilder, symbol: Symbol): Node {
793
+ export function getPropertyNameNodeForSymbol(
794
+ b: NodeBuilder,
795
+ symbol: Symbol,
796
+ enclosingDeclaration: Node | undefined,
797
+ ): Node {
723
798
  // A private name is the declaration's.
724
799
  const valueDeclaration = symbol.valueDeclaration;
725
800
  if (valueDeclaration !== undefined) {
@@ -741,7 +816,14 @@ export function getPropertyNameNodeForSymbol(b: NodeBuilder, symbol: Symbol): No
741
816
  break;
742
817
  }
743
818
  const isMethod = (symbol.flags & SymbolFlags.Method) !== 0;
744
- const fromNameType = getPropertyNameNodeForSymbolFromNameType(b, symbol, singleQuote, stringNamed, isMethod);
819
+ const fromNameType = getPropertyNameNodeForSymbolFromNameType(
820
+ b,
821
+ symbol,
822
+ enclosingDeclaration,
823
+ singleQuote,
824
+ stringNamed,
825
+ isMethod,
826
+ );
745
827
  if (fromNameType !== undefined) return fromNameType;
746
828
  let name = symbol.name;
747
829
  const privateNamePrefix = '￾#';
@@ -775,12 +857,28 @@ function createPropertyNameNodeForIdentifierOrLiteral(
775
857
  function getPropertyNameNodeForSymbolFromNameType(
776
858
  b: NodeBuilder,
777
859
  symbol: Symbol,
860
+ enclosingDeclaration: Node | undefined,
778
861
  singleQuote: boolean,
779
862
  stringNamed: boolean,
780
863
  isMethod: boolean,
781
864
  ): Node | undefined {
782
865
  const nameType = b.c.symbolNameTypes.get(getSymbolId(symbol));
783
866
  if (nameType === undefined) return undefined;
867
+ // A name from an enum member stays a computed name, `[E.A]`, where the enum can be named.
868
+ if ((nameType.flags & TypeFlags.EnumLiteral) !== 0) {
869
+ const enumEnclosingDeclaration = enclosingDeclaration !== undefined ? enclosingDeclaration : b.enclosingFile;
870
+ const enumSymbol = nameType.symbol!.parent !== undefined ? nameType.symbol!.parent : nameType.symbol!;
871
+ if (
872
+ enumEnclosingDeclaration !== undefined &&
873
+ isSymbolAccessibleByFlags(b.c, enumSymbol, enumEnclosingDeclaration, SymbolFlags.Value)
874
+ ) {
875
+ const saveEnclosingDeclaration = b.enclosingDeclaration;
876
+ b.enclosingDeclaration = enumEnclosingDeclaration;
877
+ const result = b.created(new ComputedPropertyName(symbolToExpression(b, nameType.symbol!, SymbolFlags.Value)));
878
+ b.enclosingDeclaration = saveEnclosingDeclaration;
879
+ return result;
880
+ }
881
+ }
784
882
  if ((nameType.flags & TypeFlags.StringOrNumberLiteral) !== 0) {
785
883
  const literal = nameType as LiteralType;
786
884
  const name = (nameType.flags & TypeFlags.StringLiteral) !== 0 ? literal.stringValue : String(literal.numberValue);
@@ -796,20 +894,44 @@ function getPropertyNameNodeForSymbolFromNameType(
796
894
  );
797
895
  return createPropertyNameNodeForIdentifierOrLiteral(b, name, singleQuote, stringNamed, isMethod);
798
896
  }
897
+ // The reference is tracked where the name is used; spelling it here must not track it in this scope.
799
898
  if ((nameType.flags & TypeFlags.UniqueESSymbol) !== 0)
800
- return b.created(new ComputedPropertyName(symbolToExpression(b, nameType.symbol!, SymbolFlags.Value)));
899
+ return b.created(new ComputedPropertyName(symbolToExpressionWorker(b, nameType.symbol!, SymbolFlags.Value)));
801
900
  return undefined;
802
901
  }
803
902
 
804
903
  // ---- Module specifiers
805
904
 
905
+ /** A module specifier, and the import attributes type an `import()` type with it needs. */
906
+ export class ModuleSpecifierResult {
907
+ constructor(
908
+ readonly specifier: string,
909
+ readonly importAttributesType: Type | undefined,
910
+ ) {}
911
+ }
912
+
806
913
  /**
807
914
  * The specifier an `import("…")` type names a module with: an ambient module's name, the file
808
915
  * name without an enclosing file, else what module specifier generation gives for the enclosing
809
- * file. `overrideImportMode` is `None` for the mode of the enclosing import or file.
916
+ * file. `overrideImportMode` is `None` for the mode of the enclosing import or file. A pattern
917
+ * ambient module's specifier comes with the attributes type that resolves it.
810
918
  */
811
- export function getSpecifierForModuleSymbol(b: NodeBuilder, symbol: Symbol, overrideImportMode: ModuleKind): string {
919
+ export function getSpecifierForModuleSymbol(
920
+ b: NodeBuilder,
921
+ symbol: Symbol,
922
+ overrideImportMode: ModuleKind,
923
+ ): ModuleSpecifierResult {
812
924
  const c = b.c;
925
+ const enclosingDeclaration =
926
+ b.enclosingDeclaration === undefined ? undefined : b.context.mostOriginal(b.enclosingDeclaration);
927
+ const originalModuleSpecifier =
928
+ enclosingDeclaration !== undefined && canHaveModuleSpecifier(enclosingDeclaration)
929
+ ? tryGetModuleSpecifierFromDeclaration(enclosingDeclaration)
930
+ : undefined;
931
+ const originalImportAttributesType =
932
+ originalModuleSpecifier !== undefined
933
+ ? getImportAttributesTypeForModuleSpecifier(c, originalModuleSpecifier)
934
+ : undefined;
813
935
  let file = asSourceFile(getDeclarationOfKind(symbol, SyntaxKind.SourceFile));
814
936
  if (file === undefined)
815
937
  for (const d of getDeclarations(symbol)) {
@@ -819,20 +941,27 @@ export function getSpecifierForModuleSymbol(b: NodeBuilder, symbol: Symbol, over
819
941
  break;
820
942
  }
821
943
  }
822
- if (file === undefined && isAmbientModuleSymbolName(symbol.name))
823
- return symbol.name.substring(1, symbol.name.length - 1);
944
+ if (file === undefined) {
945
+ for (const declaration of getDeclarations(symbol))
946
+ if (isModuleWithStringLiteralName(declaration)) {
947
+ const specifier = getText(getName(declaration)!);
948
+ if (
949
+ originalImportAttributesType !== undefined &&
950
+ moduleSpecifierResolvesToSymbol(b, specifier, originalImportAttributesType, symbol)
951
+ )
952
+ return new ModuleSpecifierResult(specifier, originalImportAttributesType);
953
+ return new ModuleSpecifierResult(specifier, getTypeOfModuleImportAttributes(c, symbol));
954
+ }
955
+ const ambientName = tryGetAmbientModuleNameFromSymbolName(symbol.name);
956
+ if (ambientName !== undefined) return new ModuleSpecifierResult(ambientName, undefined);
957
+ }
824
958
  const contextFile = b.enclosingFile;
825
959
  if (contextFile === undefined) {
826
- if (isAmbientModuleSymbolName(symbol.name)) return symbol.name.substring(1, symbol.name.length - 1);
960
+ const ambientName = tryGetAmbientModuleNameFromSymbolName(symbol.name);
961
+ if (ambientName !== undefined) return new ModuleSpecifierResult(ambientName, undefined);
827
962
  const moduleFile = getSourceFileOfModule(symbol);
828
- return moduleFile === undefined ? '' : moduleFile.fileName;
963
+ return new ModuleSpecifierResult(moduleFile === undefined ? '' : moduleFile.fileName, undefined);
829
964
  }
830
- const enclosingDeclaration =
831
- b.enclosingDeclaration === undefined ? undefined : b.context.mostOriginal(b.enclosingDeclaration);
832
- const originalModuleSpecifier =
833
- enclosingDeclaration !== undefined && canHaveModuleSpecifier(enclosingDeclaration)
834
- ? tryGetModuleSpecifierFromDeclaration(enclosingDeclaration)
835
- : undefined;
836
965
  let resolutionMode = overrideImportMode;
837
966
  if (resolutionMode === ModuleKind.None)
838
967
  resolutionMode =
@@ -841,16 +970,57 @@ export function getSpecifierForModuleSymbol(b: NodeBuilder, symbol: Symbol, over
841
970
  : c.host.getDefaultResolutionModeForFile(contextFile);
842
971
  const key = getSymbolId(symbol) + '|' + contextFile.path + '|' + resolutionMode;
843
972
  const cached = c.moduleSpecifiers.get(key);
844
- if (cached !== undefined) return cached;
973
+ if (cached !== undefined) return moduleSpecifierResultForSymbol(b, cached, originalImportAttributesType, symbol);
845
974
  // Declaration emit prefers project-relative specifiers, with `.js` extensions in ES modules.
846
975
  const preferences = new ModuleSpecifierPreferences(
847
976
  'project-relative',
848
977
  resolutionMode === ModuleKind.ESNext ? 'js' : '',
849
978
  );
850
- const specifiers = getModuleSpecifiers(c, symbol, contextFile, preferences, overrideImportMode);
851
- const specifier = specifiers.length > 0 ? specifiers[0]! : '';
852
- c.moduleSpecifiers.set(key, specifier);
853
- return specifier;
979
+ const specifiers = getModuleSpecifiersWithAmbientModule(c, symbol, contextFile, preferences, overrideImportMode);
980
+ const result = new ModuleSpecifierResult(
981
+ specifiers.specifiers.length > 0 ? specifiers.specifiers[0]! : '',
982
+ specifiers.ambientModuleSymbol !== undefined
983
+ ? getTypeOfModuleImportAttributes(c, specifiers.ambientModuleSymbol)
984
+ : undefined,
985
+ );
986
+ c.moduleSpecifiers.set(key, result);
987
+ return moduleSpecifierResultForSymbol(b, result, originalImportAttributesType, symbol);
988
+ }
989
+
990
+ /** `result` with `importAttributesType`, if its specifier resolves to `symbol` with those attributes. */
991
+ function moduleSpecifierResultForSymbol(
992
+ b: NodeBuilder,
993
+ result: ModuleSpecifierResult,
994
+ importAttributesType: Type | undefined,
995
+ symbol: Symbol,
996
+ ): ModuleSpecifierResult {
997
+ if (
998
+ importAttributesType !== undefined &&
999
+ moduleSpecifierResolvesToSymbol(b, result.specifier, importAttributesType, symbol)
1000
+ )
1001
+ return new ModuleSpecifierResult(result.specifier, importAttributesType);
1002
+ return result;
1003
+ }
1004
+
1005
+ function moduleSpecifierResolvesToSymbol(
1006
+ b: NodeBuilder,
1007
+ specifier: string,
1008
+ importAttributesType: Type,
1009
+ symbol: Symbol,
1010
+ ): boolean {
1011
+ const location = b.enclosingDeclaration ?? b.enclosingFile;
1012
+ if (location === undefined) return false;
1013
+ const c = b.c;
1014
+ const resolved = resolveExternalModule(c, location, specifier, undefined, undefined, false, importAttributesType);
1015
+ return resolved !== undefined && getMergedSymbol(c, resolved) === getMergedSymbol(c, symbol);
1016
+ }
1017
+
1018
+ /** The specifiers of `getModuleSpecifiers`, and the ambient module symbol that gives an ambient module's name. */
1019
+ class ModuleSpecifiers {
1020
+ constructor(
1021
+ readonly specifiers: string[],
1022
+ readonly ambientModuleSymbol: Symbol | undefined,
1023
+ ) {}
854
1024
  }
855
1025
 
856
1026
  /** Specifiers `importingFile` can import the module `moduleSymbol` with, best first. */
@@ -861,13 +1031,24 @@ export function getModuleSpecifiers(
861
1031
  preferences: ModuleSpecifierPreferences,
862
1032
  overrideImportMode: ModuleKind,
863
1033
  ): string[] {
1034
+ return getModuleSpecifiersWithAmbientModule(c, moduleSymbol, importingFile, preferences, overrideImportMode)
1035
+ .specifiers;
1036
+ }
1037
+
1038
+ function getModuleSpecifiersWithAmbientModule(
1039
+ c: Checker,
1040
+ moduleSymbol: Symbol,
1041
+ importingFile: SourceFile,
1042
+ preferences: ModuleSpecifierPreferences,
1043
+ overrideImportMode: ModuleKind,
1044
+ ): ModuleSpecifiers {
864
1045
  const ambient = tryGetModuleNameFromAmbientModule(c, moduleSymbol);
865
- if (ambient !== '') return [ambient];
1046
+ if (ambient !== undefined) return new ModuleSpecifiers([getText(getName(ambient)!)], getSymbol(ambient));
866
1047
  const moduleFile = getSourceFileOfModule(moduleSymbol);
867
- if (moduleFile === undefined) return [];
1048
+ if (moduleFile === undefined) return new ModuleSpecifiers([], undefined);
868
1049
  const host = getModuleSpecifierHost(c);
869
1050
  // A referenced project's declaration output is named by its source.
870
- return getModuleSpecifiersForFile(
1051
+ const specifiers = getModuleSpecifiersForFile(
871
1052
  importingFile,
872
1053
  host.getSourceOfProjectReferenceIfOutputIncluded(moduleFile),
873
1054
  c.compilerOptions,
@@ -876,6 +1057,7 @@ export function getModuleSpecifiers(
876
1057
  overrideImportMode,
877
1058
  false,
878
1059
  );
1060
+ return new ModuleSpecifiers(specifiers, undefined);
879
1061
  }
880
1062
 
881
1063
  function getModuleSpecifierHost(c: Checker): ModuleSpecifierHost {
@@ -890,12 +1072,12 @@ function getModuleSpecifierHost(c: Checker): ModuleSpecifierHost {
890
1072
  return host;
891
1073
  }
892
1074
 
893
- /** The name of an ambient module declaring `moduleSymbol`, or of the one whose `export =` it is, else `''`. */
894
- function tryGetModuleNameFromAmbientModule(c: Checker, moduleSymbol: Symbol): string {
1075
+ /** The ambient module declaring `moduleSymbol`, or the one whose `export =` it is. */
1076
+ function tryGetModuleNameFromAmbientModule(c: Checker, moduleSymbol: Symbol): Node | undefined {
895
1077
  for (const d of getDeclarations(moduleSymbol)) {
896
1078
  const name = isModuleWithStringLiteralName(d) ? getName(d)! : undefined;
897
1079
  if (name !== undefined && (!isModuleAugmentationExternal(d) || !isExternalModuleNameRelative(getText(name))))
898
- return getText(name);
1080
+ return d;
899
1081
  }
900
1082
  // A namespace exported with `export =` from an ambient module: `import { c } from "m"` names
901
1083
  // `ns.c` for `declare module "m" { namespace ns { class c {} } export = ns; }`.
@@ -911,9 +1093,9 @@ function tryGetModuleNameFromAmbientModule(c: Checker, moduleSymbol: Symbol): st
911
1093
  let exported = getSymbolAtLocation(c, getExpression(assignment)!);
912
1094
  if (exported === undefined) continue;
913
1095
  if ((exported.flags & SymbolFlags.Alias) !== 0) exported = resolveAlias(c, exported);
914
- if (exported === getSymbol(d)) return getText(getName(container)!);
1096
+ if (exported === getSymbol(d)) return container;
915
1097
  }
916
- return '';
1098
+ return undefined;
917
1099
  }
918
1100
 
919
1101
  function isModuleWithStringLiteralName(node: Node): boolean {
@@ -945,7 +1127,7 @@ function tryGetModuleSpecifierFromDeclaration(node: Node): Node | undefined {
945
1127
  case SyntaxKind.VariableDeclaration:
946
1128
  case SyntaxKind.BindingElement: {
947
1129
  let call = getInitializer(node);
948
- while (call !== undefined && !isRequireCall(call, true)) call = call.parent;
1130
+ while (call !== undefined && !isRequireCall(call, true) && !isImportCall(call)) call = call.parent;
949
1131
  specifier = call === undefined ? undefined : getArguments(call)!.nodes[0];
950
1132
  break;
951
1133
  }
@@ -33,7 +33,7 @@ import { isFunctionLike } from './ast-utilities.js';
33
33
  import { getSourceFileOfNode, isEntityNameExpression } from './binder-utilities.js';
34
34
  import type { Checker } from './checker.js';
35
35
  import { ContextFlags, getContextualType, instantiateContextualType } from './checker-contextual.js';
36
- import { checkExpressionCached, isConstContext, isLiteralOfContextualType } from './checker-expressions.js';
36
+ import { getTypeOfExpression, isConstContext, isLiteralOfContextualType } from './checker-expressions.js';
37
37
  import { getTypeWithFacts, TypeFacts } from './checker-flow.js';
38
38
  import { getPropertiesOfType, getPropertyOfType } from './checker-members.js';
39
39
  import {
@@ -154,7 +154,8 @@ export function getRegularTypeOfExpression(c: Checker, node: Node): Type {
154
154
  (parent instanceof PropertyAccessExpression && parent.name === node)
155
155
  )
156
156
  expr = parent;
157
- return getRegularTypeOfLiteralType(c, checkExpressionCached(c, expr));
157
+ // Rechecks the expression, as tsgo does, unless its type needed control flow analysis.
158
+ return getRegularTypeOfLiteralType(c, getTypeOfExpression(c, expr));
158
159
  }
159
160
 
160
161
  function keyword(b: NodeBuilder, kind: SyntaxKind): Node {
@@ -219,7 +220,7 @@ export function pseudoTypeToNode(b: NodeBuilder, t: PseudoType): Node | undefine
219
220
  if (parent.kind === SyntaxKind.ArrowFunction && getBody(parent) === node)
220
221
  return b.serializeReturnTypeForSignatureEx(getSignatureFromDeclaration(c, parent), false);
221
222
  if (isDeclaration(parent)) return b.serializeTypeForDeclaration(parent, undefined, undefined, false);
222
- return b.typeToTypeNode(getTypeOfExpressionForPseudo(c, node));
223
+ return b.typeToTypeNode(getTypeOfExpression(c, node));
223
224
  }
224
225
  case PseudoTypeKind.NoResult: {
225
226
  const node = (t as NoResultType).declaration;
@@ -762,10 +763,6 @@ export function pseudoReturnTypeMatchesPredicate(b: NodeBuilder, rt: PseudoType,
762
763
  return true;
763
764
  }
764
765
 
765
- function getTypeOfExpressionForPseudo(c: Checker, node: Node): Type {
766
- return checkExpressionCached(c, node);
767
- }
768
-
769
766
  /** The type a pseudo-type denotes, for the kinds that map to one directly. */
770
767
  export function pseudoTypeToType(b: NodeBuilder, t: PseudoType): Type | undefined {
771
768
  const c = b.c;
@@ -82,6 +82,7 @@ import { BuilderTracker, type NodeBuilder, TrackedSymbol, canReuseExistingJSType
82
82
  import { getSpecifierForModuleSymbol, lookupSymbolChain, symbolToTypeNode } from './node-builder-names.js';
83
83
  import { getExternalModuleFileFromDeclaration } from './checker-modules.js';
84
84
  import { getResolutionModeOverride } from './program-utilities.js';
85
+ import { getMappedType } from './checker-types.js';
85
86
 
86
87
  /** Errors and names tracked while reusing a node, replayed only if the reuse succeeds. */
87
88
  class RecoveryBoundary {
@@ -435,7 +436,7 @@ class ExistingNodeReuser extends VisitorBase {
435
436
  if ((symbol.flags & SymbolFlags.TypeParameter) !== 0) {
436
437
  const declaredType = getDeclaredTypeOfSymbol(b.c, symbol);
437
438
  // A type parameter remapped by the scope.
438
- if (b.mapper !== undefined && b.mapper.map(declaredType) !== declaredType) return undefined;
439
+ if (b.mapper !== undefined && getMappedType(declaredType, b.mapper) !== declaredType) return undefined;
439
440
  }
440
441
  if (!canReuseExistingJSTypeNode(b, node, b.getTypeFromTypeNode(node, false)!)) return undefined;
441
442
  const name = this.trackExistingEntityName(node.typeName);
@@ -700,11 +701,11 @@ function getModuleSpecifierOverride(b: NodeBuilder, parent: ImportTypeNode, lite
700
701
  ? lookupSymbolChain(b, nodeSymbol, meaning, true)[0]
701
702
  : undefined;
702
703
  if (parentSymbol !== undefined && isExternalModuleSymbol(parentSymbol))
703
- name = getSpecifierForModuleSymbol(b, parentSymbol, mode);
704
+ name = getSpecifierForModuleSymbol(b, parentSymbol, mode).specifier;
704
705
  else {
705
706
  const targetFile = getExternalModuleFileFromDeclaration(c, parent);
706
707
  if (targetFile !== undefined && targetFile.symbol !== undefined)
707
- name = getSpecifierForModuleSymbol(b, targetFile.symbol, mode);
708
+ name = getSpecifierForModuleSymbol(b, targetFile.symbol, mode).specifier;
708
709
  }
709
710
  if (name.includes('/node_modules/')) {
710
711
  b.encounteredError = true;
@@ -714,7 +715,7 @@ function getModuleSpecifierOverride(b: NodeBuilder, parent: ImportTypeNode, lite
714
715
  }
715
716
 
716
717
  function isExternalModuleSymbol(symbol: Symbol): boolean {
717
- return (symbol.flags & SymbolFlags.Module) !== 0 && symbol.name.startsWith('"');
718
+ return symbol.isExternalModule();
718
719
  }
719
720
 
720
721
  function isLiteralImportType(node: ImportTypeNode): boolean {