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
@@ -2,24 +2,31 @@
2
2
  // declaration, written as an entity name, `import("…")` type, indexed access or expression.
3
3
  import { ComputedPropertyName, ElementAccessExpression, ExpressionWithTypeArguments, ImportAttribute, ImportAttributes, ImportTypeNode, IndexedAccessTypeNode, LiteralTypeNode, ParenthesizedTypeNode, PrefixUnaryExpression, PropertyAccessExpression, QualifiedName, SourceFile, StringLiteral, TypeQueryNode, TypeReferenceNode, getArguments, getExpression, getInitializer, getModuleSpecifier, getName, getSymbol, getText, } from './ast.js';
4
4
  import { declarationNameToString, getDeclarationOfKind, getNameOfDeclaration, getSourceFileOfNode, isModuleAugmentationExternal, } from './binder-utilities.js';
5
- import { getExternalModuleName, isAmbientModule, isGlobalScopeAugmentation, isRequireCall } from './ast-utilities.js';
5
+ import { getExternalModuleName, isAmbientModule, isGlobalScopeAugmentation, isImportCall, isRequireCall, } from './ast-utilities.js';
6
6
  import { getSymbolAtLocation } from './checker-services.js';
7
7
  import { checkExpression } from './checker-expressions.js';
8
- import { getExportsOfSymbol, getMembersOfSymbol, isAmbientModuleSymbolName, resolveAlias } from './checker-symbols.js';
9
- import { compareSymbols } from './checker-type-factory.js';
8
+ import { getExportsOfSymbol, getMembersOfSymbol, getMergedSymbol, resolveAlias } from './checker-symbols.js';
9
+ import { getImportAttributesTypeForModuleSpecifier, getTypeOfModuleImportAttributes, resolveExternalModule, } from './checker-modules.js';
10
+ import { getPropertiesOfType } from './checker-members.js';
11
+ import { getTypeOfSymbol } from './checker-symbol-types.js';
12
+ import { compareSymbols, isEmptyObjectType } from './checker-type-factory.js';
10
13
  import { isLateBoundName } from './checker-utilities.js';
11
14
  import { isExternalModuleNameRelative, pathIsRelative } from './path.js';
12
15
  import { ModuleSpecifierHost, ModuleSpecifierPreferences, countPathComponents, getModuleSpecifiersForFile, } from './module-specifiers.js';
13
16
  import { ModuleKind, ModuleResolutionKind, getModuleResolutionKind } from './options.js';
14
17
  import { isExternalModuleAugmentation } from './transformers/declarations-syntactic.js';
15
18
  import { isIdentifierText } from './scanner.js';
16
- import { getAccessibleSymbolChain, getAliasForSymbolInContainer, getContainersOfSymbol, getFileSymbolIfFileSymbolExportEqualsContainer, getQualifiedLeftMeaning, getSymbolIfSameReference, hasNonGlobalAugmentationExternalModuleDeclaration, needsQualification, } from './symbol-accessibility.js';
19
+ import { getAccessibleSymbolChain, getAliasForSymbolInContainer, getContainersOfSymbol, getFileSymbolIfFileSymbolExportEqualsContainer, getQualifiedLeftMeaning, getSymbolIfSameReference, hasNonGlobalAugmentationExternalModuleDeclaration, isSymbolAccessibleByFlags, needsQualification, } from './symbol-accessibility.js';
17
20
  import { classifyPropertyName, isNumericLiteralName } from './node-builder.js';
18
- import { declarationCount, escapeInternalSymbolName, getDeclarations, getSymbolId, } from './symbol.js';
21
+ import { declarationCount, escapeInternalSymbolName, getDeclarations, getSymbolId, tryGetAmbientModuleNameFromSymbolName, } from './symbol.js';
19
22
  // ---- Symbol chains
20
23
  /** The chain of symbols naming `symbol`, reported to the tracker. */
21
24
  export function lookupSymbolChain(b, symbol, meaning, yieldModuleSymbol) {
22
25
  b.trackSymbol(symbol, b.enclosingDeclaration, meaning);
26
+ return lookupSymbolChainWorker(b, symbol, meaning, yieldModuleSymbol);
27
+ }
28
+ /** `lookupSymbolChain` without tracking the symbol's accessibility. */
29
+ function lookupSymbolChainWorker(b, symbol, meaning, yieldModuleSymbol) {
23
30
  // Qualified only with somewhere to qualify from, and never for type parameters.
24
31
  if ((symbol.flags & 262144 /* SymbolFlags.TypeParameter */) === 0 &&
25
32
  (b.enclosingDeclaration !== undefined || (b.flags & 64 /* NodeBuilderFlags.UseFullyQualifiedType */) !== 0) &&
@@ -42,7 +49,7 @@ function getSymbolChain(b, symbol, meaning, endOfChain, yieldModuleSymbol) {
42
49
  for (const p of parents) {
43
50
  order.push(specifiers.length);
44
51
  specifiers.push(hasNonGlobalAugmentationExternalModuleDeclaration(p)
45
- ? getSpecifierForModuleSymbol(b, p, ModuleKind.None)
52
+ ? getSpecifierForModuleSymbol(b, p, ModuleKind.None).specifier
46
53
  : '');
47
54
  }
48
55
  order.sort((x, y) => compareByBestName(b, parents[x], specifiers[x], parents[y], specifiers[y]) || x - y);
@@ -95,8 +102,8 @@ export function symbolToTypeNode(b, symbol, mask, typeArguments) {
95
102
  // A module root needs an `import` type.
96
103
  const nonRootParts = chain.length > 1 ? createAccessFromSymbolChain(b, chain, chain.length - 1, 1, typeArguments) : undefined;
97
104
  const typeParameterNodes = typeArguments ?? lookupTypeParameterNodes(b, chain, 0);
98
- let specifier = '';
99
- let attributes = undefined;
105
+ let specifier = new ModuleSpecifierResult('', undefined);
106
+ let importModeOverride = ModuleKind.None;
100
107
  const c = b.c;
101
108
  const resolution = getModuleResolutionKind(c.compilerOptions);
102
109
  const nodeNext = resolution === ModuleResolutionKind.Node16 || resolution === ModuleResolutionKind.NodeNext;
@@ -110,31 +117,33 @@ export function symbolToTypeNode(b, symbol, mask, typeArguments) {
110
117
  const targetFormat = c.host.getEmitModuleFormatOfFile(targetFile);
111
118
  if (targetFormat === ModuleKind.ESNext && targetFormat !== c.host.getEmitModuleFormatOfFile(contextFile)) {
112
119
  specifier = getSpecifierForModuleSymbol(b, chain[0], ModuleKind.ESNext);
113
- attributes = resolutionModeAttributes(b, 'import');
120
+ importModeOverride = ModuleKind.ESNext;
114
121
  }
115
122
  }
116
123
  }
117
- if (specifier === '')
124
+ if (specifier.specifier === '')
118
125
  specifier = getSpecifierForModuleSymbol(b, chain[0], ModuleKind.None);
119
- if ((b.flags & 67108864 /* NodeBuilderFlags.AllowNodeModulesRelativePaths */) === 0 && specifier.includes('/node_modules/')) {
126
+ if ((b.flags & 67108864 /* NodeBuilderFlags.AllowNodeModulesRelativePaths */) === 0 &&
127
+ specifier.specifier.includes('/node_modules/')) {
120
128
  const oldSpecifier = specifier;
121
129
  if (nodeNext && contextFile !== undefined) {
122
130
  // The other mode may reach the module portably.
123
131
  const swappedMode = c.host.getEmitModuleFormatOfFile(contextFile) === ModuleKind.ESNext ? ModuleKind.CommonJS : ModuleKind.ESNext;
124
132
  specifier = getSpecifierForModuleSymbol(b, chain[0], swappedMode);
125
- if (specifier.includes('/node_modules/'))
133
+ if (specifier.specifier.includes('/node_modules/'))
126
134
  specifier = oldSpecifier;
127
135
  else
128
- attributes = resolutionModeAttributes(b, swappedMode === ModuleKind.ESNext ? 'import' : 'require');
136
+ importModeOverride = swappedMode;
129
137
  }
130
- if (attributes === undefined) {
138
+ if (importModeOverride === ModuleKind.None) {
131
139
  // A reference into `node_modules` is likely to break when published.
132
140
  b.encounteredError = true;
133
- b.tracker.reportLikelyUnsafeImportRequiredError(oldSpecifier, symbol.name);
141
+ b.tracker.reportLikelyUnsafeImportRequiredError(oldSpecifier.specifier, symbol.name);
134
142
  }
135
143
  }
136
- const literal = b.created(new LiteralTypeNode(b.stringLiteral(specifier, false)));
137
- b.approximateLength += specifier.length + 10;
144
+ const attributes = createImportAttributesForModuleSpecifier(b, specifier, importModeOverride);
145
+ const literal = b.created(new LiteralTypeNode(b.stringLiteral(specifier.specifier, false)));
146
+ b.approximateLength += specifier.specifier.length + 10;
138
147
  if (nonRootParts === undefined || isEntityName(nonRootParts))
139
148
  return b.created(new ImportTypeNode(isTypeOf, literal, attributes, nonRootParts, typeParameterNodes));
140
149
  const splitNode = getTopmostIndexedAccessType(nonRootParts);
@@ -154,12 +163,48 @@ export function symbolToTypeNode(b, symbol, mask, typeArguments) {
154
163
  return entityName;
155
164
  }
156
165
  function isEntityName(node) {
157
- return node.kind === 79 /* SyntaxKind.Identifier */ || node.kind === 167 /* SyntaxKind.QualifiedName */;
166
+ return node.kind === 79 /* SyntaxKind.Identifier */ || node.kind === 168 /* SyntaxKind.QualifiedName */;
158
167
  }
159
- /** `with { "resolution-mode": "import" }` or `"require"`. */
160
- function resolutionModeAttributes(b, mode) {
161
- const attribute = b.created(new ImportAttribute(b.stringLiteral('resolution-mode', false), b.stringLiteral(mode, false)));
162
- return b.created(new ImportAttributes(117 /* SyntaxKind.WithKeyword */, b.list([attribute]), false));
168
+ /**
169
+ * The attributes of an `import()` type: a `resolution-mode` for `importModeOverride`, then the
170
+ * string literal properties of the specifier's import attributes type, by name.
171
+ */
172
+ function createImportAttributesForModuleSpecifier(b, result, importModeOverride) {
173
+ const c = b.c;
174
+ const attributesType = result.importAttributesType;
175
+ const isEmptyAttributesType = attributesType === undefined || isEmptyObjectType(c, attributesType);
176
+ if (isEmptyAttributesType && importModeOverride === ModuleKind.None)
177
+ return undefined;
178
+ const attributes = [];
179
+ if (importModeOverride !== ModuleKind.None) {
180
+ const mode = importModeOverride === ModuleKind.ESNext ? 'import' : 'require';
181
+ attributes.push(b.created(new ImportAttribute(b.stringLiteral('resolution-mode', false), b.stringLiteral(mode, false))));
182
+ b.approximateLength += 'resolution-mode'.length + mode.length + 6;
183
+ }
184
+ if (!isEmptyAttributesType) {
185
+ const properties = getPropertiesOfType(c, attributesType).slice();
186
+ properties.sort((x, y) => (x.name < y.name ? -1 : x.name > y.name ? 1 : 0));
187
+ for (const property of properties) {
188
+ const name = property.name;
189
+ const propertyType = getTypeOfSymbol(c, property);
190
+ if ((propertyType.flags & 1024 /* TypeFlags.StringLiteral */) === 0)
191
+ continue;
192
+ const value = propertyType.stringValue;
193
+ let nameNode;
194
+ if (isIdentifierText(name))
195
+ nameNode = b.factory.createIdentifier(name);
196
+ else {
197
+ nameNode = b.stringLiteral(name, false);
198
+ b.approximateLength += 2;
199
+ }
200
+ attributes.push(b.created(new ImportAttribute(nameNode, b.stringLiteral(value, false))));
201
+ b.approximateLength += name.length + value.length + 4;
202
+ }
203
+ }
204
+ if (attributes.length === 0)
205
+ return undefined;
206
+ b.approximateLength += 16 + 2 * (attributes.length - 1);
207
+ return b.created(new ImportAttributes(117 /* SyntaxKind.WithKeyword */, b.list(attributes), false));
163
208
  }
164
209
  function getTopmostIndexedAccessType(node) {
165
210
  const objectType = node.objectType;
@@ -212,7 +257,7 @@ function createAccessFromSymbolChain(b, chain, index, stopper, overrideTypeArgum
212
257
  if (name !== undefined)
213
258
  break;
214
259
  }
215
- if (name !== undefined && name.kind === 168 /* SyntaxKind.ComputedPropertyName */ && isEntityName(getExpression(name))) {
260
+ if (name !== undefined && name.kind === 169 /* SyntaxKind.ComputedPropertyName */ && isEntityName(getExpression(name))) {
216
261
  const lhs = createAccessFromSymbolChain(b, chain, index - 1, stopper, overrideTypeArguments);
217
262
  if (isEntityName(lhs))
218
263
  return b.created(new IndexedAccessTypeNode(b.created(new ParenthesizedTypeNode(b.created(new TypeQueryNode(lhs, undefined)))), b.created(new TypeQueryNode(getExpression(name), undefined))));
@@ -232,7 +277,7 @@ function createAccessFromSymbolChain(b, chain, index, stopper, overrideTypeArgum
232
277
  return b.created(new IndexedAccessTypeNode(b.created(new TypeReferenceNode(lhs, typeParameterNodes)), literal));
233
278
  }
234
279
  }
235
- const identifier = b.identifier(symbolName);
280
+ const identifier = b.symbolIdentifier(symbolName, symbol);
236
281
  b.context.addEmitFlags(identifier, 131072 /* EmitFlags.NoAsciiEscaping */);
237
282
  if (index > stopper) {
238
283
  const lhs = createAccessFromSymbolChain(b, chain, index - 1, stopper, overrideTypeArguments);
@@ -316,7 +361,7 @@ function createEntityNameFromSymbolChain(b, chain, index) {
316
361
  const symbolName = getNameOfSymbolAsWritten(b, symbol);
317
362
  if (index === 0)
318
363
  b.flags ^= 16777216 /* NodeBuilderFlags.InInitialEntityName */;
319
- const identifier = b.identifier(symbolName);
364
+ const identifier = b.symbolIdentifier(symbolName, symbol);
320
365
  b.context.addEmitFlags(identifier, 131072 /* EmitFlags.NoAsciiEscaping */);
321
366
  if (index > 0)
322
367
  return b.created(new QualifiedName(createEntityNameFromSymbolChain(b, chain, index - 1), identifier));
@@ -330,7 +375,12 @@ export function symbolToEntityNameNode(b, symbol) {
330
375
  return identifier;
331
376
  }
332
377
  export function symbolToExpression(b, symbol, meaning) {
333
- const chain = lookupSymbolChain(b, symbol, meaning, false);
378
+ b.trackSymbol(symbol, b.enclosingDeclaration, meaning);
379
+ return symbolToExpressionWorker(b, symbol, meaning);
380
+ }
381
+ /** `symbolToExpression` without tracking the symbol's accessibility. */
382
+ function symbolToExpressionWorker(b, symbol, meaning) {
383
+ const chain = lookupSymbolChainWorker(b, symbol, meaning, false);
334
384
  return createExpressionFromSymbolChain(b, chain, chain.length - 1);
335
385
  }
336
386
  function createExpressionFromSymbolChain(b, chain, index) {
@@ -342,7 +392,7 @@ function createExpressionFromSymbolChain(b, chain, index) {
342
392
  if (index === 0)
343
393
  b.flags ^= 16777216 /* NodeBuilderFlags.InInitialEntityName */;
344
394
  if (startsWithQuote(symbolName) && hasNonGlobalAugmentationExternalModuleDeclaration(symbol)) {
345
- const specifier = getSpecifierForModuleSymbol(b, symbol, ModuleKind.None);
395
+ const specifier = getSpecifierForModuleSymbol(b, symbol, ModuleKind.None).specifier;
346
396
  b.approximateLength += 2 + specifier.length;
347
397
  return b.stringLiteral(specifier, false);
348
398
  }
@@ -449,7 +499,7 @@ function lookupExpressionChainTypeArgumentNodes(b, chain, index) {
449
499
  }
450
500
  // ---- Names as written
451
501
  function isDefaultBindingContext(node) {
452
- return node.kind === 307 /* SyntaxKind.SourceFile */ || isAmbientModule(node);
502
+ return node.kind === 308 /* SyntaxKind.SourceFile */ || isAmbientModule(node);
453
503
  }
454
504
  function findDefaultBindingContext(node) {
455
505
  for (let current = node; current !== undefined; current = current.parent)
@@ -502,7 +552,7 @@ export function getNameOfSymbolAsWritten(b, symbol) {
502
552
  break;
503
553
  }
504
554
  if (name !== undefined) {
505
- if (name.kind === 168 /* SyntaxKind.ComputedPropertyName */ && (symbol.checkFlags & 4096 /* CheckFlags.Late */) === 0) {
555
+ if (name.kind === 169 /* SyntaxKind.ComputedPropertyName */ && (symbol.checkFlags & 32768 /* CheckFlags.Late */) === 0) {
506
556
  const nameType = b.c.symbolNameTypes.get(getSymbolId(symbol));
507
557
  if (nameType !== undefined && (nameType.flags & 3072 /* TypeFlags.StringOrNumberLiteral */) !== 0) {
508
558
  const result = getNameOfSymbolFromNameType(b, symbol);
@@ -514,17 +564,17 @@ export function getNameOfSymbolAsWritten(b, symbol) {
514
564
  }
515
565
  const declaration = symbol.declaration;
516
566
  const parent = declaration.parent;
517
- if (parent !== undefined && parent.kind === 261 /* SyntaxKind.VariableDeclaration */) {
567
+ if (parent !== undefined && parent.kind === 262 /* SyntaxKind.VariableDeclaration */) {
518
568
  const parentName = getName(parent);
519
569
  return declarationNameToString(getSourceFileOfNode(parentName), parentName);
520
570
  }
521
571
  switch (declaration.kind) {
522
- case 232 /* SyntaxKind.ClassExpression */:
523
- case 219 /* SyntaxKind.FunctionExpression */:
524
- case 220 /* SyntaxKind.ArrowFunction */:
572
+ case 233 /* SyntaxKind.ClassExpression */:
573
+ case 220 /* SyntaxKind.FunctionExpression */:
574
+ case 221 /* SyntaxKind.ArrowFunction */:
525
575
  if (!b.encounteredError && (b.flags & 131072 /* NodeBuilderFlags.AllowAnonymousIdentifier */) === 0)
526
576
  b.encounteredError = true;
527
- return declaration.kind === 232 /* SyntaxKind.ClassExpression */ ? '(Anonymous class)' : '(Anonymous function)';
577
+ return declaration.kind === 233 /* SyntaxKind.ClassExpression */ ? '(Anonymous class)' : '(Anonymous function)';
528
578
  }
529
579
  }
530
580
  const name = getNameOfSymbolFromNameType(b, symbol);
@@ -548,7 +598,7 @@ function isSingleQuotedStringNamed(d) {
548
598
  return name instanceof StringLiteral && (name.tokenFlags & 65536 /* TokenFlags.SingleQuote */) !== 0;
549
599
  }
550
600
  /** The name node of a property. */
551
- export function getPropertyNameNodeForSymbol(b, symbol) {
601
+ export function getPropertyNameNodeForSymbol(b, symbol, enclosingDeclaration) {
552
602
  // A private name is the declaration's.
553
603
  const valueDeclaration = symbol.valueDeclaration;
554
604
  if (valueDeclaration !== undefined) {
@@ -570,7 +620,7 @@ export function getPropertyNameNodeForSymbol(b, symbol) {
570
620
  break;
571
621
  }
572
622
  const isMethod = (symbol.flags & 8192 /* SymbolFlags.Method */) !== 0;
573
- const fromNameType = getPropertyNameNodeForSymbolFromNameType(b, symbol, singleQuote, stringNamed, isMethod);
623
+ const fromNameType = getPropertyNameNodeForSymbolFromNameType(b, symbol, enclosingDeclaration, singleQuote, stringNamed, isMethod);
574
624
  if (fromNameType !== undefined)
575
625
  return fromNameType;
576
626
  let name = symbol.name;
@@ -595,10 +645,23 @@ function createPropertyNameNodeForIdentifierOrLiteral(b, name, singleQuote, stri
595
645
  }
596
646
  return b.factory.createStringLiteral(name, singleQuote ? 65536 /* TokenFlags.SingleQuote */ : 0 /* TokenFlags.None */);
597
647
  }
598
- function getPropertyNameNodeForSymbolFromNameType(b, symbol, singleQuote, stringNamed, isMethod) {
648
+ function getPropertyNameNodeForSymbolFromNameType(b, symbol, enclosingDeclaration, singleQuote, stringNamed, isMethod) {
599
649
  const nameType = b.c.symbolNameTypes.get(getSymbolId(symbol));
600
650
  if (nameType === undefined)
601
651
  return undefined;
652
+ // A name from an enum member stays a computed name, `[E.A]`, where the enum can be named.
653
+ if ((nameType.flags & 32768 /* TypeFlags.EnumLiteral */) !== 0) {
654
+ const enumEnclosingDeclaration = enclosingDeclaration !== undefined ? enclosingDeclaration : b.enclosingFile;
655
+ const enumSymbol = nameType.symbol.parent !== undefined ? nameType.symbol.parent : nameType.symbol;
656
+ if (enumEnclosingDeclaration !== undefined &&
657
+ isSymbolAccessibleByFlags(b.c, enumSymbol, enumEnclosingDeclaration, 111551 /* SymbolFlags.Value */)) {
658
+ const saveEnclosingDeclaration = b.enclosingDeclaration;
659
+ b.enclosingDeclaration = enumEnclosingDeclaration;
660
+ const result = b.created(new ComputedPropertyName(symbolToExpression(b, nameType.symbol, 111551 /* SymbolFlags.Value */)));
661
+ b.enclosingDeclaration = saveEnclosingDeclaration;
662
+ return result;
663
+ }
664
+ }
602
665
  if ((nameType.flags & 3072 /* TypeFlags.StringOrNumberLiteral */) !== 0) {
603
666
  const literal = nameType;
604
667
  const name = (nameType.flags & 1024 /* TypeFlags.StringLiteral */) !== 0 ? literal.stringValue : String(literal.numberValue);
@@ -608,40 +671,66 @@ function getPropertyNameNodeForSymbolFromNameType(b, symbol, singleQuote, string
608
671
  return b.created(new ComputedPropertyName(b.created(new PrefixUnaryExpression(40 /* SyntaxKind.MinusToken */, b.factory.createNumericLiteral(name.substring(1))))));
609
672
  return createPropertyNameNodeForIdentifierOrLiteral(b, name, singleQuote, stringNamed, isMethod);
610
673
  }
674
+ // The reference is tracked where the name is used; spelling it here must not track it in this scope.
611
675
  if ((nameType.flags & 16384 /* TypeFlags.UniqueESSymbol */) !== 0)
612
- return b.created(new ComputedPropertyName(symbolToExpression(b, nameType.symbol, 111551 /* SymbolFlags.Value */)));
676
+ return b.created(new ComputedPropertyName(symbolToExpressionWorker(b, nameType.symbol, 111551 /* SymbolFlags.Value */)));
613
677
  return undefined;
614
678
  }
615
679
  // ---- Module specifiers
680
+ /** A module specifier, and the import attributes type an `import()` type with it needs. */
681
+ export class ModuleSpecifierResult {
682
+ specifier;
683
+ importAttributesType;
684
+ constructor(specifier, importAttributesType) {
685
+ this.specifier = specifier;
686
+ this.importAttributesType = importAttributesType;
687
+ }
688
+ }
616
689
  /**
617
690
  * The specifier an `import("…")` type names a module with: an ambient module's name, the file
618
691
  * name without an enclosing file, else what module specifier generation gives for the enclosing
619
- * file. `overrideImportMode` is `None` for the mode of the enclosing import or file.
692
+ * file. `overrideImportMode` is `None` for the mode of the enclosing import or file. A pattern
693
+ * ambient module's specifier comes with the attributes type that resolves it.
620
694
  */
621
695
  export function getSpecifierForModuleSymbol(b, symbol, overrideImportMode) {
622
696
  const c = b.c;
623
- let file = asSourceFile(getDeclarationOfKind(symbol, 307 /* SyntaxKind.SourceFile */));
697
+ const enclosingDeclaration = b.enclosingDeclaration === undefined ? undefined : b.context.mostOriginal(b.enclosingDeclaration);
698
+ const originalModuleSpecifier = enclosingDeclaration !== undefined && canHaveModuleSpecifier(enclosingDeclaration)
699
+ ? tryGetModuleSpecifierFromDeclaration(enclosingDeclaration)
700
+ : undefined;
701
+ const originalImportAttributesType = originalModuleSpecifier !== undefined
702
+ ? getImportAttributesTypeForModuleSpecifier(c, originalModuleSpecifier)
703
+ : undefined;
704
+ let file = asSourceFile(getDeclarationOfKind(symbol, 308 /* SyntaxKind.SourceFile */));
624
705
  if (file === undefined)
625
706
  for (const d of getDeclarations(symbol)) {
626
707
  const equivalent = getFileSymbolIfFileSymbolExportEqualsContainer(c, d, symbol);
627
708
  if (equivalent !== undefined) {
628
- file = asSourceFile(getDeclarationOfKind(equivalent, 307 /* SyntaxKind.SourceFile */));
709
+ file = asSourceFile(getDeclarationOfKind(equivalent, 308 /* SyntaxKind.SourceFile */));
629
710
  break;
630
711
  }
631
712
  }
632
- if (file === undefined && isAmbientModuleSymbolName(symbol.name))
633
- return symbol.name.substring(1, symbol.name.length - 1);
713
+ if (file === undefined) {
714
+ for (const declaration of getDeclarations(symbol))
715
+ if (isModuleWithStringLiteralName(declaration)) {
716
+ const specifier = getText(getName(declaration));
717
+ if (originalImportAttributesType !== undefined &&
718
+ moduleSpecifierResolvesToSymbol(b, specifier, originalImportAttributesType, symbol))
719
+ return new ModuleSpecifierResult(specifier, originalImportAttributesType);
720
+ return new ModuleSpecifierResult(specifier, getTypeOfModuleImportAttributes(c, symbol));
721
+ }
722
+ const ambientName = tryGetAmbientModuleNameFromSymbolName(symbol.name);
723
+ if (ambientName !== undefined)
724
+ return new ModuleSpecifierResult(ambientName, undefined);
725
+ }
634
726
  const contextFile = b.enclosingFile;
635
727
  if (contextFile === undefined) {
636
- if (isAmbientModuleSymbolName(symbol.name))
637
- return symbol.name.substring(1, symbol.name.length - 1);
728
+ const ambientName = tryGetAmbientModuleNameFromSymbolName(symbol.name);
729
+ if (ambientName !== undefined)
730
+ return new ModuleSpecifierResult(ambientName, undefined);
638
731
  const moduleFile = getSourceFileOfModule(symbol);
639
- return moduleFile === undefined ? '' : moduleFile.fileName;
732
+ return new ModuleSpecifierResult(moduleFile === undefined ? '' : moduleFile.fileName, undefined);
640
733
  }
641
- const enclosingDeclaration = b.enclosingDeclaration === undefined ? undefined : b.context.mostOriginal(b.enclosingDeclaration);
642
- const originalModuleSpecifier = enclosingDeclaration !== undefined && canHaveModuleSpecifier(enclosingDeclaration)
643
- ? tryGetModuleSpecifierFromDeclaration(enclosingDeclaration)
644
- : undefined;
645
734
  let resolutionMode = overrideImportMode;
646
735
  if (resolutionMode === ModuleKind.None)
647
736
  resolutionMode =
@@ -651,25 +740,56 @@ export function getSpecifierForModuleSymbol(b, symbol, overrideImportMode) {
651
740
  const key = getSymbolId(symbol) + '|' + contextFile.path + '|' + resolutionMode;
652
741
  const cached = c.moduleSpecifiers.get(key);
653
742
  if (cached !== undefined)
654
- return cached;
743
+ return moduleSpecifierResultForSymbol(b, cached, originalImportAttributesType, symbol);
655
744
  // Declaration emit prefers project-relative specifiers, with `.js` extensions in ES modules.
656
745
  const preferences = new ModuleSpecifierPreferences('project-relative', resolutionMode === ModuleKind.ESNext ? 'js' : '');
657
- const specifiers = getModuleSpecifiers(c, symbol, contextFile, preferences, overrideImportMode);
658
- const specifier = specifiers.length > 0 ? specifiers[0] : '';
659
- c.moduleSpecifiers.set(key, specifier);
660
- return specifier;
746
+ const specifiers = getModuleSpecifiersWithAmbientModule(c, symbol, contextFile, preferences, overrideImportMode);
747
+ const result = new ModuleSpecifierResult(specifiers.specifiers.length > 0 ? specifiers.specifiers[0] : '', specifiers.ambientModuleSymbol !== undefined
748
+ ? getTypeOfModuleImportAttributes(c, specifiers.ambientModuleSymbol)
749
+ : undefined);
750
+ c.moduleSpecifiers.set(key, result);
751
+ return moduleSpecifierResultForSymbol(b, result, originalImportAttributesType, symbol);
752
+ }
753
+ /** `result` with `importAttributesType`, if its specifier resolves to `symbol` with those attributes. */
754
+ function moduleSpecifierResultForSymbol(b, result, importAttributesType, symbol) {
755
+ if (importAttributesType !== undefined &&
756
+ moduleSpecifierResolvesToSymbol(b, result.specifier, importAttributesType, symbol))
757
+ return new ModuleSpecifierResult(result.specifier, importAttributesType);
758
+ return result;
759
+ }
760
+ function moduleSpecifierResolvesToSymbol(b, specifier, importAttributesType, symbol) {
761
+ const location = b.enclosingDeclaration ?? b.enclosingFile;
762
+ if (location === undefined)
763
+ return false;
764
+ const c = b.c;
765
+ const resolved = resolveExternalModule(c, location, specifier, undefined, undefined, false, importAttributesType);
766
+ return resolved !== undefined && getMergedSymbol(c, resolved) === getMergedSymbol(c, symbol);
767
+ }
768
+ /** The specifiers of `getModuleSpecifiers`, and the ambient module symbol that gives an ambient module's name. */
769
+ class ModuleSpecifiers {
770
+ specifiers;
771
+ ambientModuleSymbol;
772
+ constructor(specifiers, ambientModuleSymbol) {
773
+ this.specifiers = specifiers;
774
+ this.ambientModuleSymbol = ambientModuleSymbol;
775
+ }
661
776
  }
662
777
  /** Specifiers `importingFile` can import the module `moduleSymbol` with, best first. */
663
778
  export function getModuleSpecifiers(c, moduleSymbol, importingFile, preferences, overrideImportMode) {
779
+ return getModuleSpecifiersWithAmbientModule(c, moduleSymbol, importingFile, preferences, overrideImportMode)
780
+ .specifiers;
781
+ }
782
+ function getModuleSpecifiersWithAmbientModule(c, moduleSymbol, importingFile, preferences, overrideImportMode) {
664
783
  const ambient = tryGetModuleNameFromAmbientModule(c, moduleSymbol);
665
- if (ambient !== '')
666
- return [ambient];
784
+ if (ambient !== undefined)
785
+ return new ModuleSpecifiers([getText(getName(ambient))], getSymbol(ambient));
667
786
  const moduleFile = getSourceFileOfModule(moduleSymbol);
668
787
  if (moduleFile === undefined)
669
- return [];
788
+ return new ModuleSpecifiers([], undefined);
670
789
  const host = getModuleSpecifierHost(c);
671
790
  // A referenced project's declaration output is named by its source.
672
- return getModuleSpecifiersForFile(importingFile, host.getSourceOfProjectReferenceIfOutputIncluded(moduleFile), c.compilerOptions, host, preferences, overrideImportMode, false);
791
+ const specifiers = getModuleSpecifiersForFile(importingFile, host.getSourceOfProjectReferenceIfOutputIncluded(moduleFile), c.compilerOptions, host, preferences, overrideImportMode, false);
792
+ return new ModuleSpecifiers(specifiers, undefined);
673
793
  }
674
794
  function getModuleSpecifierHost(c) {
675
795
  let host = c.host.getModuleSpecifierHost();
@@ -682,26 +802,26 @@ function getModuleSpecifierHost(c) {
682
802
  }
683
803
  return host;
684
804
  }
685
- /** The name of an ambient module declaring `moduleSymbol`, or of the one whose `export =` it is, else `''`. */
805
+ /** The ambient module declaring `moduleSymbol`, or the one whose `export =` it is. */
686
806
  function tryGetModuleNameFromAmbientModule(c, moduleSymbol) {
687
807
  for (const d of getDeclarations(moduleSymbol)) {
688
808
  const name = isModuleWithStringLiteralName(d) ? getName(d) : undefined;
689
809
  if (name !== undefined && (!isModuleAugmentationExternal(d) || !isExternalModuleNameRelative(getText(name))))
690
- return getText(name);
810
+ return d;
691
811
  }
692
812
  // A namespace exported with `export =` from an ambient module: `import { c } from "m"` names
693
813
  // `ns.c` for `declare module "m" { namespace ns { class c {} } export = ns; }`.
694
814
  for (const d of getDeclarations(moduleSymbol)) {
695
- if (d.kind !== 268 /* SyntaxKind.ModuleDeclaration */)
815
+ if (d.kind !== 269 /* SyntaxKind.ModuleDeclaration */)
696
816
  continue;
697
817
  let container = d;
698
818
  while (container !== undefined && !isModuleWithStringLiteralName(container))
699
819
  container = container.parent;
700
- if (container === undefined || container.parent === undefined || container.parent.kind !== 307 /* SyntaxKind.SourceFile */)
820
+ if (container === undefined || container.parent === undefined || container.parent.kind !== 308 /* SyntaxKind.SourceFile */)
701
821
  continue;
702
822
  const exportEquals = getSymbol(container)?.exports?.get("export=" /* InternalSymbolName.ExportEquals */);
703
823
  const assignment = exportEquals?.valueDeclaration;
704
- if (assignment === undefined || assignment.kind !== 278 /* SyntaxKind.ExportAssignment */)
824
+ if (assignment === undefined || assignment.kind !== 279 /* SyntaxKind.ExportAssignment */)
705
825
  continue;
706
826
  let exported = getSymbolAtLocation(c, getExpression(assignment));
707
827
  if (exported === undefined)
@@ -709,26 +829,26 @@ function tryGetModuleNameFromAmbientModule(c, moduleSymbol) {
709
829
  if ((exported.flags & 2097152 /* SymbolFlags.Alias */) !== 0)
710
830
  exported = resolveAlias(c, exported);
711
831
  if (exported === getSymbol(d))
712
- return getText(getName(container));
832
+ return container;
713
833
  }
714
- return '';
834
+ return undefined;
715
835
  }
716
836
  function isModuleWithStringLiteralName(node) {
717
- return node.kind === 268 /* SyntaxKind.ModuleDeclaration */ && getName(node)?.kind === 10 /* SyntaxKind.StringLiteral */;
837
+ return node.kind === 269 /* SyntaxKind.ModuleDeclaration */ && getName(node)?.kind === 10 /* SyntaxKind.StringLiteral */;
718
838
  }
719
839
  function canHaveModuleSpecifier(node) {
720
840
  switch (node.kind) {
721
- case 261 /* SyntaxKind.VariableDeclaration */:
722
- case 209 /* SyntaxKind.BindingElement */:
723
- case 273 /* SyntaxKind.ImportDeclaration */:
724
- case 279 /* SyntaxKind.ExportDeclaration */:
725
- case 272 /* SyntaxKind.ImportEqualsDeclaration */:
726
- case 274 /* SyntaxKind.ImportClause */:
727
- case 281 /* SyntaxKind.NamespaceExport */:
728
- case 275 /* SyntaxKind.NamespaceImport */:
729
- case 282 /* SyntaxKind.ExportSpecifier */:
730
- case 277 /* SyntaxKind.ImportSpecifier */:
731
- case 206 /* SyntaxKind.ImportType */:
841
+ case 262 /* SyntaxKind.VariableDeclaration */:
842
+ case 210 /* SyntaxKind.BindingElement */:
843
+ case 274 /* SyntaxKind.ImportDeclaration */:
844
+ case 280 /* SyntaxKind.ExportDeclaration */:
845
+ case 273 /* SyntaxKind.ImportEqualsDeclaration */:
846
+ case 275 /* SyntaxKind.ImportClause */:
847
+ case 282 /* SyntaxKind.NamespaceExport */:
848
+ case 276 /* SyntaxKind.NamespaceImport */:
849
+ case 283 /* SyntaxKind.ExportSpecifier */:
850
+ case 278 /* SyntaxKind.ImportSpecifier */:
851
+ case 207 /* SyntaxKind.ImportType */:
732
852
  return true;
733
853
  }
734
854
  return false;
@@ -737,33 +857,33 @@ function canHaveModuleSpecifier(node) {
737
857
  function tryGetModuleSpecifierFromDeclaration(node) {
738
858
  let specifier;
739
859
  switch (node.kind) {
740
- case 261 /* SyntaxKind.VariableDeclaration */:
741
- case 209 /* SyntaxKind.BindingElement */: {
860
+ case 262 /* SyntaxKind.VariableDeclaration */:
861
+ case 210 /* SyntaxKind.BindingElement */: {
742
862
  let call = getInitializer(node);
743
- while (call !== undefined && !isRequireCall(call, true))
863
+ while (call !== undefined && !isRequireCall(call, true) && !isImportCall(call))
744
864
  call = call.parent;
745
865
  specifier = call === undefined ? undefined : getArguments(call).nodes[0];
746
866
  break;
747
867
  }
748
- case 273 /* SyntaxKind.ImportDeclaration */:
749
- case 279 /* SyntaxKind.ExportDeclaration */:
868
+ case 274 /* SyntaxKind.ImportDeclaration */:
869
+ case 280 /* SyntaxKind.ExportDeclaration */:
750
870
  specifier = getModuleSpecifier(node);
751
871
  break;
752
- case 272 /* SyntaxKind.ImportEqualsDeclaration */:
872
+ case 273 /* SyntaxKind.ImportEqualsDeclaration */:
753
873
  specifier = getExternalModuleName(node);
754
874
  break;
755
- case 274 /* SyntaxKind.ImportClause */:
756
- case 281 /* SyntaxKind.NamespaceExport */:
875
+ case 275 /* SyntaxKind.ImportClause */:
876
+ case 282 /* SyntaxKind.NamespaceExport */:
757
877
  specifier = getModuleSpecifier(node.parent);
758
878
  break;
759
- case 275 /* SyntaxKind.NamespaceImport */:
760
- case 282 /* SyntaxKind.ExportSpecifier */:
879
+ case 276 /* SyntaxKind.NamespaceImport */:
880
+ case 283 /* SyntaxKind.ExportSpecifier */:
761
881
  specifier = getModuleSpecifier(node.parent.parent);
762
882
  break;
763
- case 277 /* SyntaxKind.ImportSpecifier */:
883
+ case 278 /* SyntaxKind.ImportSpecifier */:
764
884
  specifier = getModuleSpecifier(node.parent.parent.parent);
765
885
  break;
766
- case 206 /* SyntaxKind.ImportType */: {
886
+ case 207 /* SyntaxKind.ImportType */: {
767
887
  const argument = node.argument;
768
888
  specifier = argument instanceof LiteralTypeNode ? argument.literal : undefined;
769
889
  break;