tsc-ts 0.0.9 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (373) hide show
  1. package/README.md +2 -2
  2. package/bin/tsc-ts.js +70 -1
  3. package/dist/api/compiler/ast-utilities.d.ts +19 -1
  4. package/dist/api/compiler/ast-utilities.js +180 -95
  5. package/dist/api/compiler/ast.d.ts +22 -15
  6. package/dist/api/compiler/ast.js +1026 -995
  7. package/dist/api/compiler/astnav.js +15 -15
  8. package/dist/api/compiler/binder-utilities.js +186 -186
  9. package/dist/api/compiler/binder.js +290 -263
  10. package/dist/api/compiler/character-codes.js +2 -2
  11. package/dist/api/compiler/checker-calls.js +178 -124
  12. package/dist/api/compiler/checker-classes.d.ts +14 -3
  13. package/dist/api/compiler/checker-classes.js +134 -90
  14. package/dist/api/compiler/checker-contextual.js +64 -61
  15. package/dist/api/compiler/checker-declaration-order.js +79 -79
  16. package/dist/api/compiler/checker-declarations.d.ts +1 -0
  17. package/dist/api/compiler/checker-declarations.js +160 -136
  18. package/dist/api/compiler/checker-declared-types.js +67 -65
  19. package/dist/api/compiler/checker-decorators.js +77 -77
  20. package/dist/api/compiler/checker-deprecation.d.ts +8 -3
  21. package/dist/api/compiler/checker-deprecation.js +76 -55
  22. package/dist/api/compiler/checker-destructuring.js +47 -45
  23. package/dist/api/compiler/checker-elaboration.js +24 -24
  24. package/dist/api/compiler/checker-emit-helpers.js +4 -4
  25. package/dist/api/compiler/checker-emit-resolver.d.ts +4 -2
  26. package/dist/api/compiler/checker-emit-resolver.js +25 -13
  27. package/dist/api/compiler/checker-evaluator.js +9 -9
  28. package/dist/api/compiler/checker-expressions.js +244 -211
  29. package/dist/api/compiler/checker-functions.js +113 -107
  30. package/dist/api/compiler/checker-generated-code.d.ts +0 -11
  31. package/dist/api/compiler/checker-generated-code.js +28 -52
  32. package/dist/api/compiler/checker-grammar.d.ts +1 -0
  33. package/dist/api/compiler/checker-grammar.js +472 -440
  34. package/dist/api/compiler/checker-heritage.js +91 -93
  35. package/dist/api/compiler/checker-inference.d.ts +77 -5
  36. package/dist/api/compiler/checker-inference.js +487 -107
  37. package/dist/api/compiler/checker-iteration.d.ts +0 -10
  38. package/dist/api/compiler/checker-iteration.js +35 -52
  39. package/dist/api/compiler/checker-javascript.js +14 -14
  40. package/dist/api/compiler/checker-jsdoc.d.ts +8 -10
  41. package/dist/api/compiler/checker-jsdoc.js +67 -58
  42. package/dist/api/compiler/checker-jsx.js +105 -88
  43. package/dist/api/compiler/checker-members.d.ts +9 -2
  44. package/dist/api/compiler/checker-members.js +212 -75
  45. package/dist/api/compiler/checker-modules.d.ts +15 -6
  46. package/dist/api/compiler/checker-modules.js +469 -309
  47. package/dist/api/compiler/checker-narrowing.js +273 -189
  48. package/dist/api/compiler/checker-object-literals.js +25 -22
  49. package/dist/api/compiler/checker-operators.js +126 -118
  50. package/dist/api/compiler/checker-overloads.js +27 -27
  51. package/dist/api/compiler/checker-property-access.js +59 -55
  52. package/dist/api/compiler/checker-services.d.ts +1 -0
  53. package/dist/api/compiler/checker-services.js +222 -210
  54. package/dist/api/compiler/checker-signatures.js +65 -49
  55. package/dist/api/compiler/checker-source-file.d.ts +5 -0
  56. package/dist/api/compiler/checker-source-file.js +154 -130
  57. package/dist/api/compiler/checker-statements.js +33 -32
  58. package/dist/api/compiler/checker-super.js +50 -50
  59. package/dist/api/compiler/checker-symbol-types.js +109 -93
  60. package/dist/api/compiler/checker-symbols.d.ts +13 -1
  61. package/dist/api/compiler/checker-symbols.js +264 -149
  62. package/dist/api/compiler/checker-type-factory.d.ts +5 -0
  63. package/dist/api/compiler/checker-type-factory.js +145 -36
  64. package/dist/api/compiler/checker-type-nodes.d.ts +1 -0
  65. package/dist/api/compiler/checker-type-nodes.js +179 -141
  66. package/dist/api/compiler/checker-type-operators.d.ts +2 -0
  67. package/dist/api/compiler/checker-type-operators.js +110 -63
  68. package/dist/api/compiler/checker-types.d.ts +80 -3
  69. package/dist/api/compiler/checker-types.js +121 -2
  70. package/dist/api/compiler/checker-unused.js +114 -118
  71. package/dist/api/compiler/checker-utilities.js +11 -11
  72. package/dist/api/compiler/checker.d.ts +104 -31
  73. package/dist/api/compiler/checker.js +181 -33
  74. package/dist/api/compiler/command-line.d.ts +1 -3
  75. package/dist/api/compiler/command-line.js +47 -44
  76. package/dist/api/compiler/compile-program.d.ts +42 -3
  77. package/dist/api/compiler/compile-program.js +139 -27
  78. package/dist/api/compiler/diagnostic-messages.d.ts +1849 -1774
  79. package/dist/api/compiler/diagnostic-messages.js +128 -122
  80. package/dist/api/compiler/diagnostics.d.ts +22 -0
  81. package/dist/api/compiler/diagnostics.js +93 -11
  82. package/dist/api/compiler/emitter.d.ts +7 -1
  83. package/dist/api/compiler/emitter.js +53 -11
  84. package/dist/api/compiler/file-include.d.ts +2 -1
  85. package/dist/api/compiler/file-include.js +11 -7
  86. package/dist/api/compiler/file-loader.d.ts +21 -1
  87. package/dist/api/compiler/file-loader.js +201 -48
  88. package/dist/api/compiler/instantiation.d.ts +7 -0
  89. package/dist/api/compiler/instantiation.js +101 -49
  90. package/dist/api/compiler/jsdoc.js +23 -23
  91. package/dist/api/compiler/link-tables.d.ts +48 -18
  92. package/dist/api/compiler/link-tables.js +80 -37
  93. package/dist/api/compiler/locales/cs-CZ.d.ts +1 -1
  94. package/dist/api/compiler/locales/cs-CZ.js +1 -1
  95. package/dist/api/compiler/locales/de-DE.d.ts +1 -1
  96. package/dist/api/compiler/locales/de-DE.js +1 -1
  97. package/dist/api/compiler/locales/es-ES.d.ts +1 -1
  98. package/dist/api/compiler/locales/es-ES.js +1 -1
  99. package/dist/api/compiler/locales/fr-FR.d.ts +1 -1
  100. package/dist/api/compiler/locales/fr-FR.js +1 -1
  101. package/dist/api/compiler/locales/it-IT.d.ts +1 -1
  102. package/dist/api/compiler/locales/it-IT.js +1 -1
  103. package/dist/api/compiler/locales/ja-JP.d.ts +1 -1
  104. package/dist/api/compiler/locales/ja-JP.js +1 -1
  105. package/dist/api/compiler/locales/ko-KR.d.ts +1 -1
  106. package/dist/api/compiler/locales/ko-KR.js +1 -1
  107. package/dist/api/compiler/locales/pl-PL.d.ts +1 -1
  108. package/dist/api/compiler/locales/pl-PL.js +1 -1
  109. package/dist/api/compiler/locales/pt-BR.d.ts +1 -1
  110. package/dist/api/compiler/locales/pt-BR.js +1 -1
  111. package/dist/api/compiler/locales/ru-RU.d.ts +1 -1
  112. package/dist/api/compiler/locales/ru-RU.js +1 -1
  113. package/dist/api/compiler/locales/tr-TR.d.ts +1 -1
  114. package/dist/api/compiler/locales/tr-TR.js +1 -1
  115. package/dist/api/compiler/locales/zh-CN.d.ts +1 -1
  116. package/dist/api/compiler/locales/zh-CN.js +1 -1
  117. package/dist/api/compiler/locales/zh-TW.d.ts +1 -1
  118. package/dist/api/compiler/locales/zh-TW.js +1 -1
  119. package/dist/api/compiler/module-resolution-types.js +6 -6
  120. package/dist/api/compiler/module-resolution.d.ts +10 -1
  121. package/dist/api/compiler/module-resolution.js +115 -84
  122. package/dist/api/compiler/module-specifiers.d.ts +15 -0
  123. package/dist/api/compiler/module-specifiers.js +24 -18
  124. package/dist/api/compiler/name-resolver.js +74 -65
  125. package/dist/api/compiler/node-builder-names.d.ts +11 -3
  126. package/dist/api/compiler/node-builder-names.js +210 -90
  127. package/dist/api/compiler/node-builder-pseudo.js +29 -31
  128. package/dist/api/compiler/node-builder-reuse.js +23 -22
  129. package/dist/api/compiler/node-builder.d.ts +18 -1
  130. package/dist/api/compiler/node-builder.js +191 -102
  131. package/dist/api/compiler/option-declarations.d.ts +2 -6
  132. package/dist/api/compiler/option-declarations.js +315 -375
  133. package/dist/api/compiler/options.d.ts +15 -33
  134. package/dist/api/compiler/options.js +21 -54
  135. package/dist/api/compiler/output-paths.d.ts +4 -1
  136. package/dist/api/compiler/output-paths.js +6 -11
  137. package/dist/api/compiler/package-json.d.ts +3 -3
  138. package/dist/api/compiler/package-json.js +11 -10
  139. package/dist/api/compiler/parallel-parse.d.ts +3 -2
  140. package/dist/api/compiler/parallel-parse.js +17 -5
  141. package/dist/api/compiler/parser.d.ts +40 -19
  142. package/dist/api/compiler/parser.js +308 -216
  143. package/dist/api/compiler/path.d.ts +9 -0
  144. package/dist/api/compiler/path.js +20 -3
  145. package/dist/api/compiler/printer/emit-context.d.ts +5 -1
  146. package/dist/api/compiler/printer/emit-context.js +20 -1
  147. package/dist/api/compiler/printer/factory-base.d.ts +2 -2
  148. package/dist/api/compiler/printer/factory-base.js +7 -3
  149. package/dist/api/compiler/printer/factory.js +3 -1
  150. package/dist/api/compiler/printer/helpers.js +10 -1
  151. package/dist/api/compiler/printer/name-generator.d.ts +1 -1
  152. package/dist/api/compiler/printer/name-generator.js +35 -16
  153. package/dist/api/compiler/printer/printer.d.ts +49 -2
  154. package/dist/api/compiler/printer/printer.js +539 -293
  155. package/dist/api/compiler/printer/utilities.js +149 -147
  156. package/dist/api/compiler/program-checker.d.ts +12 -2
  157. package/dist/api/compiler/program-checker.js +88 -34
  158. package/dist/api/compiler/program-utilities.d.ts +3 -1
  159. package/dist/api/compiler/program-utilities.js +28 -15
  160. package/dist/api/compiler/program.d.ts +4 -6
  161. package/dist/api/compiler/program.js +74 -87
  162. package/dist/api/compiler/pseudo-bigint.d.ts +2 -0
  163. package/dist/api/compiler/pseudo-bigint.js +18 -0
  164. package/dist/api/compiler/regexp-checker.d.ts +1 -1
  165. package/dist/api/compiler/regexp-checker.js +93 -76
  166. package/dist/api/compiler/relations.d.ts +27 -4
  167. package/dist/api/compiler/relations.js +347 -180
  168. package/dist/api/compiler/reparser.js +60 -56
  169. package/dist/api/compiler/scanner.d.ts +19 -2
  170. package/dist/api/compiler/scanner.js +123 -108
  171. package/dist/api/compiler/shared-results.d.ts +463 -0
  172. package/dist/api/compiler/shared-results.js +2128 -0
  173. package/dist/api/compiler/sourcemap.js +2 -2
  174. package/dist/api/compiler/symbol-accessibility.js +87 -74
  175. package/dist/api/compiler/symbol.d.ts +23 -14
  176. package/dist/api/compiler/symbol.js +23 -11
  177. package/dist/api/compiler/syntax-kind.d.ts +198 -197
  178. package/dist/api/compiler/transformers/alias-references.js +247 -139
  179. package/dist/api/compiler/transformers/async-utilities.js +25 -25
  180. package/dist/api/compiler/transformers/async.d.ts +0 -1
  181. package/dist/api/compiler/transformers/async.js +64 -77
  182. package/dist/api/compiler/transformers/class-fields.d.ts +1 -0
  183. package/dist/api/compiler/transformers/class-fields.js +81 -78
  184. package/dist/api/compiler/transformers/commonjs-module.js +18 -15
  185. package/dist/api/compiler/transformers/const-enum-inliner.js +1 -1
  186. package/dist/api/compiler/transformers/declarations-diagnostics.js +247 -244
  187. package/dist/api/compiler/transformers/declarations-pseudo.js +100 -100
  188. package/dist/api/compiler/transformers/declarations-resolver.d.ts +0 -3
  189. package/dist/api/compiler/transformers/declarations-syntactic.d.ts +1 -2
  190. package/dist/api/compiler/transformers/declarations-syntactic.js +134 -156
  191. package/dist/api/compiler/transformers/declarations-tracker.js +18 -18
  192. package/dist/api/compiler/transformers/declarations.d.ts +4 -1
  193. package/dist/api/compiler/transformers/declarations.js +305 -238
  194. package/dist/api/compiler/transformers/decorator-metadata.d.ts +1 -1
  195. package/dist/api/compiler/transformers/decorator-metadata.js +53 -45
  196. package/dist/api/compiler/transformers/decorator-utilities.js +24 -24
  197. package/dist/api/compiler/transformers/destructuring.js +19 -18
  198. package/dist/api/compiler/transformers/emit-resolver.js +1 -1
  199. package/dist/api/compiler/transformers/es-decorators.js +55 -55
  200. package/dist/api/compiler/transformers/external-module-info.js +3 -3
  201. package/dist/api/compiler/transformers/for-await.js +25 -25
  202. package/dist/api/compiler/transformers/import-elision.js +14 -14
  203. package/dist/api/compiler/transformers/jsx.js +12 -12
  204. package/dist/api/compiler/transformers/legacy-decorators.js +17 -17
  205. package/dist/api/compiler/transformers/module.js +8 -8
  206. package/dist/api/compiler/transformers/named-evaluation.js +4 -4
  207. package/dist/api/compiler/transformers/object-rest-spread.js +20 -20
  208. package/dist/api/compiler/transformers/optional-chain.js +10 -10
  209. package/dist/api/compiler/transformers/reference-resolver.d.ts +12 -1
  210. package/dist/api/compiler/transformers/reference-resolver.js +131 -69
  211. package/dist/api/compiler/transformers/runtime-syntax.js +35 -31
  212. package/dist/api/compiler/transformers/subtree-facts.js +47 -47
  213. package/dist/api/compiler/transformers/syntax-facts.js +56 -58
  214. package/dist/api/compiler/transformers/type-eraser.js +73 -66
  215. package/dist/api/compiler/transformers/type-serialization.js +24 -24
  216. package/dist/api/compiler/transformers/using.js +12 -12
  217. package/dist/api/compiler/transformers/utilities.js +77 -77
  218. package/dist/api/compiler/transformers/visitor-base.js +172 -172
  219. package/dist/api/compiler/transformers/visitor-hooks.js +6 -2
  220. package/dist/api/compiler/tsconfig.d.ts +10 -2
  221. package/dist/api/compiler/tsconfig.js +136 -48
  222. package/dist/api/compiler/type-printer.js +40 -3
  223. package/dist/api/compiler/types.d.ts +2 -1
  224. package/dist/api/library/ast.generated.d.ts +42 -39
  225. package/dist/api/library/ast.generated.js +1 -1
  226. package/dist/api/library/compiler-options.generated.d.ts +111 -100
  227. package/dist/api/library/compiler-options.generated.js +1 -1
  228. package/dist/api/library/disk.js +12 -1
  229. package/dist/api/library/enums.generated.d.ts +206 -206
  230. package/dist/api/library/enums.generated.js +206 -206
  231. package/dist/api/library/nodes.js +26 -26
  232. package/package.json +9 -9
  233. package/src/compiler/ast-utilities.ts +99 -7
  234. package/src/compiler/ast.ts +58 -26
  235. package/src/compiler/binder.ts +39 -4
  236. package/src/compiler/character-codes.ts +2 -2
  237. package/src/compiler/checker-calls.ts +79 -9
  238. package/src/compiler/checker-classes.ts +78 -24
  239. package/src/compiler/checker-contextual.ts +6 -1
  240. package/src/compiler/checker-declarations.ts +31 -4
  241. package/src/compiler/checker-declared-types.ts +8 -5
  242. package/src/compiler/checker-decorators.ts +1 -1
  243. package/src/compiler/checker-deprecation.ts +29 -8
  244. package/src/compiler/checker-destructuring.ts +10 -3
  245. package/src/compiler/checker-emit-helpers.ts +1 -0
  246. package/src/compiler/checker-emit-resolver.ts +16 -6
  247. package/src/compiler/checker-expressions.ts +79 -46
  248. package/src/compiler/checker-functions.ts +21 -6
  249. package/src/compiler/checker-generated-code.ts +2 -22
  250. package/src/compiler/checker-grammar.ts +136 -62
  251. package/src/compiler/checker-heritage.ts +22 -21
  252. package/src/compiler/checker-inference.ts +514 -82
  253. package/src/compiler/checker-iteration.ts +18 -31
  254. package/src/compiler/checker-javascript.ts +1 -1
  255. package/src/compiler/checker-jsdoc.ts +50 -27
  256. package/src/compiler/checker-jsx.ts +26 -4
  257. package/src/compiler/checker-members.ts +200 -56
  258. package/src/compiler/checker-modules.ts +332 -65
  259. package/src/compiler/checker-narrowing.ts +98 -19
  260. package/src/compiler/checker-object-literals.ts +3 -0
  261. package/src/compiler/checker-operators.ts +11 -4
  262. package/src/compiler/checker-property-access.ts +7 -2
  263. package/src/compiler/checker-services.ts +39 -12
  264. package/src/compiler/checker-signatures.ts +15 -1
  265. package/src/compiler/checker-source-file.ts +39 -13
  266. package/src/compiler/checker-statements.ts +3 -2
  267. package/src/compiler/checker-symbol-types.ts +29 -6
  268. package/src/compiler/checker-symbols.ts +158 -15
  269. package/src/compiler/checker-type-factory.ts +124 -23
  270. package/src/compiler/checker-type-nodes.ts +46 -3
  271. package/src/compiler/checker-type-operators.ts +83 -26
  272. package/src/compiler/checker-types.ts +147 -4
  273. package/src/compiler/checker-unused.ts +9 -14
  274. package/src/compiler/checker.ts +203 -39
  275. package/src/compiler/command-line.ts +28 -28
  276. package/src/compiler/compile-program.ts +167 -27
  277. package/src/compiler/decoder.ts +13 -4
  278. package/src/compiler/diagnostic-messages.ts +1973 -1892
  279. package/src/compiler/diagnostics.ts +84 -3
  280. package/src/compiler/emitter.ts +57 -8
  281. package/src/compiler/encoder.ts +23 -8
  282. package/src/compiler/file-include.ts +9 -3
  283. package/src/compiler/file-loader.ts +197 -38
  284. package/src/compiler/help.ts +10 -14
  285. package/src/compiler/incremental.ts +165 -30
  286. package/src/compiler/init.ts +2 -7
  287. package/src/compiler/instantiation.ts +77 -22
  288. package/src/compiler/jsdoc.ts +3 -1
  289. package/src/compiler/link-tables.ts +82 -37
  290. package/src/compiler/locales/cs-CZ.ts +1 -1
  291. package/src/compiler/locales/de-DE.ts +1 -1
  292. package/src/compiler/locales/es-ES.ts +1 -1
  293. package/src/compiler/locales/fr-FR.ts +1 -1
  294. package/src/compiler/locales/it-IT.ts +1 -1
  295. package/src/compiler/locales/ja-JP.ts +1 -1
  296. package/src/compiler/locales/ko-KR.ts +1 -1
  297. package/src/compiler/locales/pl-PL.ts +1 -1
  298. package/src/compiler/locales/pt-BR.ts +1 -1
  299. package/src/compiler/locales/ru-RU.ts +1 -1
  300. package/src/compiler/locales/tr-TR.ts +1 -1
  301. package/src/compiler/locales/zh-CN.ts +1 -1
  302. package/src/compiler/locales/zh-TW.ts +1 -1
  303. package/src/compiler/module-resolution.ts +44 -8
  304. package/src/compiler/module-specifiers.ts +62 -20
  305. package/src/compiler/name-resolver.ts +9 -1
  306. package/src/compiler/node-builder-names.ts +236 -54
  307. package/src/compiler/node-builder-pseudo.ts +4 -7
  308. package/src/compiler/node-builder-reuse.ts +5 -4
  309. package/src/compiler/node-builder.ts +130 -31
  310. package/src/compiler/option-declarations.ts +33 -103
  311. package/src/compiler/options.ts +23 -62
  312. package/src/compiler/output-paths.ts +5 -18
  313. package/src/compiler/package-entrypoints.ts +345 -0
  314. package/src/compiler/package-json.ts +4 -4
  315. package/src/compiler/parallel-check.ts +326 -52
  316. package/src/compiler/parallel-emit.ts +320 -0
  317. package/src/compiler/parallel-parse.ts +16 -5
  318. package/src/compiler/parse-thread.ts +3 -0
  319. package/src/compiler/parser.ts +156 -39
  320. package/src/compiler/path.ts +22 -2
  321. package/src/compiler/printer/emit-context.ts +21 -0
  322. package/src/compiler/printer/factory-base.ts +10 -3
  323. package/src/compiler/printer/factory.ts +4 -1
  324. package/src/compiler/printer/helpers.ts +10 -1
  325. package/src/compiler/printer/name-generator.ts +24 -2
  326. package/src/compiler/printer/printer.ts +266 -30
  327. package/src/compiler/printer/utilities.ts +8 -2
  328. package/src/compiler/program-checker.ts +57 -5
  329. package/src/compiler/program-utilities.ts +23 -10
  330. package/src/compiler/program.ts +18 -26
  331. package/src/compiler/pseudo-bigint.ts +17 -0
  332. package/src/compiler/regexp-checker.ts +63 -30
  333. package/src/compiler/relations.ts +240 -77
  334. package/src/compiler/reparser.ts +7 -2
  335. package/src/compiler/scanner.ts +109 -79
  336. package/src/compiler/shared-results.ts +2414 -0
  337. package/src/compiler/show-config.ts +18 -1
  338. package/src/compiler/sourcemap.ts +2 -2
  339. package/src/compiler/symbol-accessibility.ts +26 -3
  340. package/src/compiler/symbol.ts +46 -24
  341. package/src/compiler/syntax-kind.ts +188 -187
  342. package/src/compiler/thread-entry.ts +64 -4
  343. package/src/compiler/transformers/alias-references.ts +123 -4
  344. package/src/compiler/transformers/async.ts +2 -17
  345. package/src/compiler/transformers/class-fields.ts +13 -12
  346. package/src/compiler/transformers/commonjs-module.ts +11 -7
  347. package/src/compiler/transformers/declarations-diagnostics.ts +5 -3
  348. package/src/compiler/transformers/declarations-pseudo.ts +2 -4
  349. package/src/compiler/transformers/declarations-resolver.ts +0 -3
  350. package/src/compiler/transformers/declarations-syntactic.ts +1 -21
  351. package/src/compiler/transformers/declarations.ts +134 -48
  352. package/src/compiler/transformers/decorator-metadata.ts +9 -1
  353. package/src/compiler/transformers/destructuring.ts +4 -3
  354. package/src/compiler/transformers/external-module-info.ts +1 -1
  355. package/src/compiler/transformers/jsx.ts +2 -1
  356. package/src/compiler/transformers/reference-resolver.ts +83 -19
  357. package/src/compiler/transformers/runtime-syntax.ts +6 -1
  358. package/src/compiler/transformers/syntax-facts.ts +2 -7
  359. package/src/compiler/transformers/type-eraser.ts +10 -1
  360. package/src/compiler/transformers/type-serialization.ts +3 -2
  361. package/src/compiler/transformers/visitor-base.ts +2 -1
  362. package/src/compiler/transformers/visitor-hooks.ts +9 -4
  363. package/src/compiler/tsc-build.ts +66 -9
  364. package/src/compiler/tsc-cli.ts +7 -0
  365. package/src/compiler/tsc-compile.ts +284 -4
  366. package/src/compiler/tsc-watch.ts +74 -45
  367. package/src/compiler/tsconfig.ts +176 -19
  368. package/src/compiler/type-printer.ts +36 -2
  369. package/src/compiler/types.ts +2 -1
  370. package/src/library/ast.generated.ts +57 -41
  371. package/src/library/compiler-options.generated.ts +117 -103
  372. package/src/library/disk.ts +10 -1
  373. package/src/library/enums.generated.ts +196 -196
@@ -11,7 +11,6 @@ import {
11
11
  type ExportAssignment,
12
12
  type ExportDeclaration,
13
13
  type HeritageClause,
14
- type Identifier,
15
14
  type ImportAttribute,
16
15
  type ImportAttributes,
17
16
  type ImportClause,
@@ -21,6 +20,7 @@ import {
21
20
  type LiteralTypeNode,
22
21
  type MetaProperty,
23
22
  type ModuleDeclaration,
23
+ type PatternAmbientModule,
24
24
  type NamedExports,
25
25
  type NamedImports,
26
26
  type Node,
@@ -53,6 +53,9 @@ import {
53
53
  isStringLiteralLike,
54
54
  isTypeOnly,
55
55
  nodeIsMissing,
56
+ isImportPhaseMetaProperty,
57
+ isSourcePhaseImport,
58
+ isSourcePhaseImportCall,
56
59
  } from './ast-utilities.js';
57
60
  import {
58
61
  declarationNameToString,
@@ -112,6 +115,7 @@ import {
112
115
  tryExtractTSExtension,
113
116
  tryGetExtensionFromPath,
114
117
  } from './path.js';
118
+ import { ContainerFlags, getContainerFlags } from './binder.js';
115
119
  import { SyntaxKind } from './syntax-kind.js';
116
120
  import { isExpressionNode } from './transformers/alias-references.js';
117
121
  import { type Checker, type CheckerHost, createDiagnosticForNode } from './checker.js';
@@ -121,6 +125,7 @@ import {
121
125
  createAnonymousType,
122
126
  getRegularTypeOfLiteralType,
123
127
  getStringLiteralType,
128
+ isEmptyObjectType,
124
129
  isErrorType,
125
130
  } from './checker-type-factory.js';
126
131
  import {
@@ -146,18 +151,20 @@ import { getTypeOfSymbol, getNullableType } from './checker-symbol-types.js';
146
151
  import {
147
152
  getPropertyOfType,
148
153
  getPropertyOfTypeEx,
154
+ getTypeOfPropertyOfType,
149
155
  getSignaturesOfStructuredType,
150
156
  resolveStructuredTypeMembers,
151
157
  } from './checker-members.js';
152
158
  import { getTypeFromTypeNode, getTypeReferenceType } from './checker-type-nodes.js';
153
- import { checkExpression, checkExpressionCached, getResolvedSymbol } from './checker-expressions.js';
154
- import { isTypeAssignableTo, checkTypeAssignableTo } from './relations.js';
159
+ import { checkExpressionCached, getResolvedSymbol } from './checker-expressions.js';
160
+ import { isTypeAssignableTo, isTypeIdenticalTo, isTypeStrictSubtypeOf, checkTypeAssignableTo } from './relations.js';
155
161
  import { getSpreadType } from './checker-object-literals.js';
156
162
  import { checkExternalModuleExports, shouldCheckErasableSyntax } from './checker-declarations.js';
157
163
  import { checkTypeNameIsReserved } from './checker-classes.js';
158
164
  import { getDeclaredTypeOfSymbol } from './checker-declared-types.js';
159
165
  import { isValidSpreadType } from './checker-destructuring.js';
160
166
  import { createPromiseType } from './checker-iteration.js';
167
+ import { getInstantiationExpressionType } from './checker-calls.js';
161
168
  import { symbolToString, typeToString } from './type-printer.js';
162
169
  import { checkTypeAssignableToAndOptionallyElaborate } from './checker-expressions.js';
163
170
  import { grammarErrorOnNode } from './checker-operators.js';
@@ -171,6 +178,7 @@ import {
171
178
  type Symbol,
172
179
  SymbolFlags,
173
180
  type SymbolTable,
181
+ copyDeclarations,
174
182
  } from './symbol.js';
175
183
 
176
184
  // ---- Resolution
@@ -181,6 +189,7 @@ export function resolveExternalModuleName(
181
189
  location: Node,
182
190
  moduleReference: Node | undefined,
183
191
  ignoreErrors: boolean,
192
+ importAttributesType: Type | undefined,
184
193
  ): Symbol | undefined {
185
194
  return resolveExternalModuleNameWorker(
186
195
  c,
@@ -189,6 +198,7 @@ export function resolveExternalModuleName(
189
198
  ignoreErrors ? undefined : getCannotResolveModuleNameError(c, moduleReference),
190
199
  ignoreErrors,
191
200
  false,
201
+ importAttributesType,
192
202
  );
193
203
  }
194
204
 
@@ -214,8 +224,11 @@ export function resolveExternalModuleNameWorker(
214
224
  moduleNotFoundError: DiagnosticMessage | undefined,
215
225
  ignoreErrors: boolean,
216
226
  isForAugmentation: boolean,
227
+ importAttributesType: Type | undefined,
217
228
  ): Symbol | undefined {
218
229
  if (moduleReference === undefined || !isStringLiteralLike(moduleReference)) return undefined;
230
+ // A source phase import loads no module declarations.
231
+ if (isSourcePhaseImport(moduleReference.parent!)) return undefined;
219
232
  return resolveExternalModule(
220
233
  c,
221
234
  location,
@@ -223,6 +236,7 @@ export function resolveExternalModuleNameWorker(
223
236
  moduleNotFoundError,
224
237
  ignoreErrors ? undefined : moduleReference,
225
238
  isForAugmentation,
239
+ importAttributesType,
226
240
  );
227
241
  }
228
242
 
@@ -232,6 +246,7 @@ export class ModuleResolution {
232
246
  readonly moduleReference: string,
233
247
  readonly moduleNotFoundError: DiagnosticMessage | undefined,
234
248
  readonly isForAugmentation: boolean,
249
+ readonly importAttributesType: Type | undefined,
235
250
  readonly symbol: Symbol | undefined,
236
251
  ) {}
237
252
  }
@@ -249,6 +264,7 @@ export function resolveExternalModule(
249
264
  moduleNotFoundError: DiagnosticMessage | undefined,
250
265
  errorNode: Node | undefined,
251
266
  isForAugmentation: boolean,
267
+ importAttributesType: Type | undefined,
252
268
  ): Symbol | undefined {
253
269
  // An augmentation merged later can give the resolved module a new merged symbol, so results are
254
270
  // kept only once every augmentation is merged.
@@ -259,7 +275,8 @@ export function resolveExternalModule(
259
275
  known !== undefined &&
260
276
  known.moduleReference === moduleReference &&
261
277
  known.moduleNotFoundError === moduleNotFoundError &&
262
- known.isForAugmentation === isForAugmentation
278
+ known.isForAugmentation === isForAugmentation &&
279
+ known.importAttributesType === importAttributesType
263
280
  )
264
281
  return known.symbol;
265
282
  }
@@ -271,11 +288,12 @@ export function resolveExternalModule(
271
288
  moduleNotFoundError,
272
289
  errorNode,
273
290
  isForAugmentation,
291
+ importAttributesType ?? c.emptyObjectType,
274
292
  );
275
293
  if (shared && c.reports === reports)
276
294
  c.moduleResolutions.set(
277
295
  errorNode,
278
- new ModuleResolution(moduleReference, moduleNotFoundError, isForAugmentation, symbol),
296
+ new ModuleResolution(moduleReference, moduleNotFoundError, isForAugmentation, importAttributesType, symbol),
279
297
  );
280
298
  return symbol;
281
299
  }
@@ -323,6 +341,7 @@ function resolveExternalModuleWorker(
323
341
  moduleNotFoundError: DiagnosticMessage | undefined,
324
342
  errorNode: Node | undefined,
325
343
  isForAugmentation: boolean,
344
+ importAttributesType: Type,
326
345
  ): Symbol | undefined {
327
346
  if (errorNode !== undefined && moduleReference.startsWith('@types/'))
328
347
  c.error(
@@ -332,7 +351,7 @@ function resolveExternalModuleWorker(
332
351
  moduleReference,
333
352
  );
334
353
  const ambient = tryFindAmbientModule(c, moduleReference, true);
335
- if (ambient !== undefined) return ambient;
354
+ if (ambient !== undefined) return tryResolvePatternAmbientModule(c, ambient, moduleReference, importAttributesType);
336
355
  const importingFile = getSourceFileOfNode(location);
337
356
  const contextSpecifier = getContextSpecifier(location);
338
357
  const mode =
@@ -364,22 +383,16 @@ function resolveExternalModuleWorker(
364
383
  errorOnImplicitAnyModule(c, false, errorNode, mode, resolved!, moduleReference);
365
384
  checkSyncImportOfESModule(c, location, moduleReference, importingFile, file, errorNode);
366
385
  }
367
- return getMergedSymbol(c, file.symbol);
386
+ return tryResolvePatternAmbientModule(c, getMergedSymbol(c, file.symbol), moduleReference, importAttributesType);
368
387
  }
388
+ const patternModule = tryResolvePatternAmbientModule(c, undefined, moduleReference, importAttributesType);
389
+ if (patternModule !== undefined) return patternModule;
369
390
  if (errorNode !== undefined && moduleNotFoundError !== undefined && !isSideEffectImport(errorNode))
370
391
  c.error(errorNode, Diagnostics.File_0_is_not_a_module, resolved!.resolvedFileName);
371
392
  return undefined;
372
393
  }
373
- // The pattern with the longest prefix wins.
374
- let best: Symbol | undefined;
375
- let bestPrefix = -1;
376
- for (const pattern of c.patternAmbientModules) {
377
- if (pattern.matches(moduleReference) && pattern.starIndex > bestPrefix) {
378
- bestPrefix = pattern.starIndex;
379
- best = pattern.symbol;
380
- }
381
- }
382
- if (best !== undefined) return getMergedSymbol(c, c.patternAmbientModuleAugmentations.get(moduleReference) ?? best);
394
+ const patternModule = tryResolvePatternAmbientModule(c, undefined, moduleReference, importAttributesType);
395
+ if (patternModule !== undefined) return patternModule;
383
396
  if (errorNode === undefined) return undefined;
384
397
  // A module that resolved to JavaScript is untyped.
385
398
  if (
@@ -460,6 +473,75 @@ function resolveExternalModuleWorker(
460
473
  return undefined;
461
474
  }
462
475
 
476
+ /**
477
+ * The pattern ambient module `moduleReference` resolves to under `importAttributesType`, or
478
+ * `resolvedSymbol`. Without import attributes a module found by name or resolution wins. Among the
479
+ * patterns that match and accept the attributes, the one with the most specific attributes type wins,
480
+ * then the one with the longest prefix.
481
+ */
482
+ function tryResolvePatternAmbientModule(
483
+ c: Checker,
484
+ resolvedSymbol: Symbol | undefined,
485
+ moduleReference: string,
486
+ importAttributesType: Type,
487
+ ): Symbol | undefined {
488
+ if (resolvedSymbol !== undefined && isEmptyObjectType(c, importAttributesType)) return resolvedSymbol;
489
+ if (c.patternAmbientModules.length === 0) return resolvedSymbol;
490
+ const candidates: PatternAmbientModule[] = [];
491
+ for (const pattern of c.patternAmbientModules)
492
+ if (
493
+ pattern.matches(moduleReference) &&
494
+ isTypeAssignableTo(c, importAttributesType, getTypeOfModuleImportAttributes(c, pattern.symbol))
495
+ )
496
+ candidates.push(pattern);
497
+ if (candidates.length === 0) return resolvedSymbol;
498
+ let best = candidates[0]!;
499
+ if (candidates.length > 1) {
500
+ const bestTypeCandidates: PatternAmbientModule[] = [];
501
+ for (let i = 0; i < candidates.length; i++) {
502
+ const candidateType = getTypeOfModuleImportAttributes(c, candidates[i]!.symbol);
503
+ let isBest = true;
504
+ for (let j = 0; j < candidates.length && isBest; j++) {
505
+ const otherType = getTypeOfModuleImportAttributes(c, candidates[j]!.symbol);
506
+ if (
507
+ i !== j &&
508
+ isTypeStrictSubtypeOf(c, otherType, candidateType) &&
509
+ !isTypeIdenticalTo(c, otherType, candidateType)
510
+ )
511
+ isBest = false;
512
+ }
513
+ if (isBest) bestTypeCandidates.push(candidates[i]!);
514
+ }
515
+ // The pattern with the longest prefix wins.
516
+ best = bestTypeCandidates[0]!;
517
+ for (const pattern of bestTypeCandidates) if (pattern.starIndex > best.starIndex) best = pattern;
518
+ }
519
+ const merged = getMergedSymbol(c, best.symbol);
520
+ const augmentation = c.patternAmbientModuleAugmentations.get(moduleReference);
521
+ if (augmentation !== undefined && c.patternAmbientModuleAugmentationTargets.get(moduleReference) === merged)
522
+ return getMergedSymbol(c, augmentation);
523
+ return merged;
524
+ }
525
+
526
+ /** The import attributes type an ambient module declares, or the empty object type. */
527
+ export function getTypeOfModuleImportAttributes(c: Checker, symbol: Symbol): Type {
528
+ let result = c.moduleImportAttributesTypes.get(symbol);
529
+ if (result === undefined) {
530
+ result = c.emptyObjectType;
531
+ for (const declaration of getDeclarations(symbol))
532
+ if (
533
+ declaration.kind === SyntaxKind.ModuleDeclaration &&
534
+ getName(declaration)!.kind === SyntaxKind.StringLiteral
535
+ ) {
536
+ const attributes = (declaration as ModuleDeclaration).attributes;
537
+ if (attributes !== undefined) result = getTypeFromTypeNode(c, attributes);
538
+ break;
539
+ }
540
+ c.moduleImportAttributesTypes.set(symbol, result);
541
+ }
542
+ return result;
543
+ }
544
+
463
545
  /** The module specifier that decides the resolution mode of a module reference at `location`. */
464
546
  function getContextSpecifier(location: Node): Node | undefined {
465
547
  const parent = location.parent;
@@ -842,7 +924,14 @@ export function resolveESModuleSymbol(
842
924
  ? (referenceParent as CallExpression).arguments.nodes[0]!
843
925
  : getModuleSpecifier(referenceParent)!;
844
926
  const type = getTypeOfSymbol(c, symbol);
845
- const defaultOnlyType = getTypeWithSyntheticDefaultOnly(c, type, symbol, moduleSymbol, reference);
927
+ const defaultOnlyType = getTypeWithSyntheticDefaultOnly(
928
+ c,
929
+ type,
930
+ symbol,
931
+ moduleSymbol,
932
+ reference,
933
+ getImportAttributesTypeForModuleSpecifier(c, reference),
934
+ );
846
935
  if (defaultOnlyType !== undefined) return cloneTypeAsModuleType(c, symbol, defaultOnlyType);
847
936
  if (hasSignatures(c, type) || getPropertyOfTypeEx(c, type, InternalSymbolName.Default, true, false) !== undefined) {
848
937
  const moduleType =
@@ -871,11 +960,16 @@ function hasSignatures(c: Checker, type: Type): boolean {
871
960
  * Whether the module `usage` names is a JSON module imported into an ES module under `--module node16` to
872
961
  * `nodenext`, which Node.js gives only a default export.
873
962
  */
874
- function isOnlyImportableAsDefault(c: Checker, usage: Node, resolvedModule: Symbol | undefined): boolean {
963
+ function isOnlyImportableAsDefault(
964
+ c: Checker,
965
+ usage: Node,
966
+ resolvedModule: Symbol | undefined,
967
+ importAttributesType: Type | undefined,
968
+ ): boolean {
875
969
  const moduleKind = getEmitModuleKind(c.compilerOptions);
876
970
  if (moduleKind < ModuleKind.Node16 || moduleKind > ModuleKind.NodeNext) return false;
877
971
  if (getEmitSyntaxForModuleSpecifierExpression(c, usage) !== ModuleKind.ESNext) return false;
878
- const moduleSymbol = resolvedModule ?? resolveExternalModuleName(c, usage, usage, true);
972
+ const moduleSymbol = resolvedModule ?? resolveExternalModuleName(c, usage, usage, true, importAttributesType);
879
973
  const targetFile = moduleSymbol !== undefined ? getSourceFileOfModuleSymbol(moduleSymbol) : undefined;
880
974
  return (
881
975
  targetFile !== undefined &&
@@ -903,8 +997,10 @@ function getTypeWithSyntheticDefaultOnly(
903
997
  symbol: Symbol,
904
998
  originalSymbol: Symbol,
905
999
  moduleSpecifier: Node,
1000
+ importAttributesType: Type | undefined,
906
1001
  ): Type | undefined {
907
- if (!isOnlyImportableAsDefault(c, moduleSpecifier, undefined) || isErrorType(c, type)) return undefined;
1002
+ if (!isOnlyImportableAsDefault(c, moduleSpecifier, undefined, importAttributesType) || isErrorType(c, type))
1003
+ return undefined;
908
1004
  const key = 'defaultOnly:' + type.id;
909
1005
  const cached = c.moduleTypeCache.get(key);
910
1006
  if (cached !== undefined) return cached;
@@ -929,6 +1025,7 @@ function getTypeWithSyntheticDefaultImportType(
929
1025
  let result = type;
930
1026
  if (canHaveSyntheticDefault(c, file, originalSymbol, false, moduleSpecifier)) {
931
1027
  const anonymousSymbol = c.newSymbol(SymbolFlags.TypeLiteral, InternalSymbolName.Type);
1028
+ copyDeclarations(anonymousSymbol, originalSymbol);
932
1029
  const defaultContainingObject = createDefaultPropertyWrapperForModule(c, symbol, originalSymbol, anonymousSymbol);
933
1030
  c.symbolTypes.set(getSymbolId(anonymousSymbol), defaultContainingObject);
934
1031
  result = isValidSpreadType(c, type)
@@ -953,6 +1050,10 @@ function createDefaultPropertyWrapperForModule(
953
1050
  links.aliasTarget = resolveSymbol(c, symbol);
954
1051
  const members: SymbolTable = new Map<string, Symbol>();
955
1052
  members.set(InternalSymbolName.Default, defaultSymbol);
1053
+ if (anonymousSymbol === undefined && originalSymbol !== undefined) {
1054
+ anonymousSymbol = c.newSymbol(SymbolFlags.ObjectLiteral, InternalSymbolName.Object);
1055
+ copyDeclarations(anonymousSymbol, originalSymbol);
1056
+ }
956
1057
  return createAnonymousType(c, anonymousSymbol, members, [], [], []);
957
1058
  }
958
1059
 
@@ -975,7 +1076,7 @@ function getSourceFileDeclaration(symbol: Symbol | undefined): SourceFile | unde
975
1076
  }
976
1077
 
977
1078
  /** The module syntax of the import or export containing `usage`, or `None` for non-literals. */
978
- function getEmitSyntaxForModuleSpecifierExpression(c: Checker, usage: Node): ModuleKind {
1079
+ export function getEmitSyntaxForModuleSpecifierExpression(c: Checker, usage: Node): ModuleKind {
979
1080
  return isStringLiteralLike(usage)
980
1081
  ? c.host.getEmitSyntaxForUsageLocation(getSourceFileOfNode(usage), usage)
981
1082
  : ModuleKind.None;
@@ -1063,6 +1164,8 @@ export function getTargetOfAliasDeclaration(c: Checker, node: Node | undefined):
1063
1164
  case SyntaxKind.ExportSpecifier:
1064
1165
  return getTargetOfExportSpecifier(c, node, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace, true);
1065
1166
  case SyntaxKind.ExportAssignment:
1167
+ // An export assignment in a namespace is an error, and its expression is not resolved.
1168
+ if (isContainedByNamespace(node)) return undefined;
1066
1169
  return withTypeOnlyMark(c, node, getTargetOfAliasLikeExpression(c, getExpression(node)!));
1067
1170
  case SyntaxKind.BinaryExpression:
1068
1171
  return withTypeOnlyMark(c, node, getTargetOfAliasLikeExpression(c, (node as BinaryExpression).right));
@@ -1108,7 +1211,7 @@ function getTargetOfImportEqualsDeclaration(c: Checker, node: Node): Symbol | un
1108
1211
  const moduleReference = isVariableDeclarationInitializedToRequire(node)
1109
1212
  ? (getInitializer(node) as CallExpression).arguments.nodes[0]!
1110
1213
  : getExpression((node as ImportEqualsDeclaration).moduleReference);
1111
- const immediate = resolveExternalModuleName(c, node, moduleReference, false);
1214
+ const immediate = resolveExternalModuleName(c, node, moduleReference, false, undefined);
1112
1215
  const resolved = resolveExternalModuleSymbol(c, immediate, true);
1113
1216
  const moduleKind = getEmitModuleKind(c.compilerOptions);
1114
1217
  if (resolved !== undefined && moduleKind >= ModuleKind.Node20 && moduleKind <= ModuleKind.NodeNext) {
@@ -1198,7 +1301,25 @@ function getTypeOnlyDeclarationOfEntityName(c: Checker, name: Node): Node | unde
1198
1301
  }
1199
1302
 
1200
1303
  function getTargetOfImportClause(c: Checker, node: Node): Symbol | undefined {
1201
- const moduleSymbol = resolveExternalModuleName(c, node, getModuleSpecifier(node.parent!), false);
1304
+ // `import source x from "m"` binds a module source object, not the module's default export.
1305
+ if ((node as ImportClause).phaseModifier === SyntaxKind.SourceKeyword) {
1306
+ const alias = getSymbolOfDeclaration(c, node)!;
1307
+ const links = c.symbolLinks(alias);
1308
+ if (links.immediateTarget === undefined) {
1309
+ const symbol = c.newSymbol(SymbolFlags.FunctionScopedVariable, getText((node as ImportClause).name!));
1310
+ setDeclarations(symbol, getDeclarations(alias).slice());
1311
+ c.symbolTypes.set(getSymbolId(symbol), getGlobalAbstractModuleSourceType(c));
1312
+ links.immediateTarget = symbol;
1313
+ }
1314
+ return links.immediateTarget;
1315
+ }
1316
+ const moduleSymbol = resolveExternalModuleName(
1317
+ c,
1318
+ node,
1319
+ getModuleSpecifier(node.parent!),
1320
+ false,
1321
+ getTypeFromImportAttributes(c, getImportAttributes(node.parent!)),
1322
+ );
1202
1323
  return moduleSymbol !== undefined ? getTargetOfModuleDefault(c, moduleSymbol, node, true) : undefined;
1203
1324
  }
1204
1325
 
@@ -1214,7 +1335,16 @@ function getTargetOfModuleDefault(
1214
1335
  ? undefined
1215
1336
  : resolveExportByName(c, moduleSymbol, InternalSymbolName.Default, node, dontResolveAlias);
1216
1337
  if (specifier === undefined) return exportDefaultSymbol;
1217
- const hasDefaultOnly = isOnlyImportableAsDefault(c, specifier, moduleSymbol);
1338
+ let attributes: ImportAttributes | undefined;
1339
+ if (node.kind === SyntaxKind.ImportClause) attributes = getImportAttributes(node.parent!);
1340
+ else if (node.kind === SyntaxKind.ImportSpecifier) attributes = getImportAttributes(node.parent!.parent!.parent!);
1341
+ else if (node.kind === SyntaxKind.ExportSpecifier) attributes = getImportAttributes(node.parent!.parent!);
1342
+ const hasDefaultOnly = isOnlyImportableAsDefault(
1343
+ c,
1344
+ specifier,
1345
+ moduleSymbol,
1346
+ getTypeFromImportAttributes(c, attributes),
1347
+ );
1218
1348
  const hasSyntheticDefault = canHaveSyntheticDefault(c, file, moduleSymbol, dontResolveAlias, specifier);
1219
1349
  if (exportDefaultSymbol === undefined && !hasSyntheticDefault && !hasDefaultOnly) {
1220
1350
  if (node.kind === SyntaxKind.ImportClause) reportNonDefaultExport(c, moduleSymbol, node);
@@ -1258,7 +1388,13 @@ function reportNonDefaultExport(c: Checker, moduleSymbol: Symbol, node: Node): v
1258
1388
  for (const d of getDeclarations(exportStar)) {
1259
1389
  const specifier = getModuleSpecifier(d);
1260
1390
  if (d.kind !== SyntaxKind.ExportDeclaration || specifier === undefined) continue;
1261
- const resolved = resolveExternalModuleName(c, d, specifier, false);
1391
+ const resolved = resolveExternalModuleName(
1392
+ c,
1393
+ d,
1394
+ specifier,
1395
+ false,
1396
+ getTypeFromImportAttributes(c, getImportAttributes(d)),
1397
+ );
1262
1398
  if (resolved !== undefined && resolved.exports?.get(InternalSymbolName.Default) !== undefined) {
1263
1399
  diagnostic.addRelatedInfo(
1264
1400
  createDiagnosticForNode(d, Diagnostics.X_export_Asterisk_does_not_re_export_a_default, []),
@@ -1287,7 +1423,13 @@ function resolveExportByName(
1287
1423
 
1288
1424
  function getTargetOfNamespaceImport(c: Checker, node: Node): Symbol | undefined {
1289
1425
  const moduleSpecifier = getModuleSpecifierForImportOrExport(node)!;
1290
- const immediate = resolveExternalModuleName(c, node, moduleSpecifier, false);
1426
+ const immediate = resolveExternalModuleName(
1427
+ c,
1428
+ node,
1429
+ moduleSpecifier,
1430
+ false,
1431
+ getTypeFromImportAttributes(c, getImportAttributes(node.parent!.parent!)),
1432
+ );
1291
1433
  const resolved = resolveESModuleSymbol(c, immediate, node, moduleSpecifier);
1292
1434
  markSymbolOfAliasDeclarationIfTypeOnly(c, node, undefined);
1293
1435
  return resolved;
@@ -1296,7 +1438,13 @@ function getTargetOfNamespaceImport(c: Checker, node: Node): Symbol | undefined
1296
1438
  function getTargetOfNamespaceExport(c: Checker, node: Node): Symbol | undefined {
1297
1439
  const moduleSpecifier = getModuleSpecifierForImportOrExport(node);
1298
1440
  if (moduleSpecifier === undefined) return undefined;
1299
- const immediate = resolveExternalModuleName(c, node, moduleSpecifier, false);
1441
+ const immediate = resolveExternalModuleName(
1442
+ c,
1443
+ node,
1444
+ moduleSpecifier,
1445
+ false,
1446
+ getTypeFromImportAttributes(c, getImportAttributes(node.parent!)),
1447
+ );
1300
1448
  const resolved = resolveESModuleSymbol(c, immediate, node, moduleSpecifier);
1301
1449
  markSymbolOfAliasDeclarationIfTypeOnly(c, node, undefined);
1302
1450
  return resolved;
@@ -1307,7 +1455,13 @@ function getTargetOfImportSpecifier(c: Checker, node: Node): Symbol | undefined
1307
1455
  if (node.kind === SyntaxKind.ImportSpecifier && moduleExportNameIsDefault(name)) {
1308
1456
  const specifier = getModuleSpecifierForImportOrExport(node);
1309
1457
  if (specifier !== undefined) {
1310
- const moduleSymbol = resolveExternalModuleName(c, node, specifier, false);
1458
+ const moduleSymbol = resolveExternalModuleName(
1459
+ c,
1460
+ node,
1461
+ specifier,
1462
+ false,
1463
+ getTypeFromImportAttributes(c, getImportAttributes(node.parent!.parent!.parent!)),
1464
+ );
1311
1465
  if (moduleSymbol !== undefined) return getTargetOfModuleDefault(c, moduleSymbol, node, true);
1312
1466
  }
1313
1467
  }
@@ -1327,7 +1481,8 @@ export function getExternalModuleMember(
1327
1481
  const moduleSpecifier = isVariableDeclarationInitializedToRequire(node)
1328
1482
  ? (getInitializer(node) as CallExpression).arguments.nodes[0]!
1329
1483
  : getExternalModuleName(node);
1330
- const moduleSymbol = resolveExternalModuleName(c, node, moduleSpecifier, false);
1484
+ const importAttributesType = getTypeFromImportAttributes(c, getImportAttributes(node));
1485
+ const moduleSymbol = resolveExternalModuleName(c, node, moduleSpecifier, false, importAttributesType);
1331
1486
  const name =
1332
1487
  specifier.kind === SyntaxKind.PropertyAccessExpression ? getName(specifier)! : getPropertyNameOrName(specifier);
1333
1488
  if (name.kind !== SyntaxKind.Identifier && name.kind !== SyntaxKind.StringLiteral) return undefined;
@@ -1359,7 +1514,7 @@ export function getExternalModuleMember(
1359
1514
  if (
1360
1515
  symbolFromModule === undefined &&
1361
1516
  nameText === InternalSymbolName.Default &&
1362
- (isOnlyImportableAsDefault(c, moduleSpecifier!, moduleSymbol) ||
1517
+ (isOnlyImportableAsDefault(c, moduleSpecifier!, moduleSymbol, importAttributesType) ||
1363
1518
  canHaveSyntheticDefault(
1364
1519
  c,
1365
1520
  getSourceFileDeclaration(moduleSymbol),
@@ -1380,7 +1535,7 @@ export function getExternalModuleMember(
1380
1535
  if (
1381
1536
  (specifier.kind === SyntaxKind.ImportSpecifier || specifier.kind === SyntaxKind.ExportSpecifier) &&
1382
1537
  nameText !== InternalSymbolName.Default &&
1383
- isOnlyImportableAsDefault(c, moduleSpecifier!, moduleSymbol)
1538
+ isOnlyImportableAsDefault(c, moduleSpecifier!, moduleSymbol, importAttributesType)
1384
1539
  )
1385
1540
  c.error(
1386
1541
  name,
@@ -1564,7 +1719,13 @@ export function getTargetOfExportSpecifier(
1564
1719
  if (moduleExportNameIsDefault(name)) {
1565
1720
  const specifier = getModuleSpecifierForImportOrExport(node);
1566
1721
  if (specifier !== undefined) {
1567
- const moduleSymbol = resolveExternalModuleName(c, node, specifier, false);
1722
+ const moduleSymbol = resolveExternalModuleName(
1723
+ c,
1724
+ node,
1725
+ specifier,
1726
+ false,
1727
+ getTypeFromImportAttributes(c, getImportAttributes(node.parent!.parent!)),
1728
+ );
1568
1729
  if (moduleSymbol !== undefined) return getTargetOfModuleDefault(c, moduleSymbol, node, dontResolveAlias);
1569
1730
  }
1570
1731
  }
@@ -2088,7 +2249,13 @@ class ExportCollector {
2088
2249
  const lookupTable = new Map<string, ExportCollision>();
2089
2250
  for (const node of getDeclarations(exportStars)) {
2090
2251
  const specifier = (node as ExportDeclaration).moduleSpecifier;
2091
- const resolved = resolveExternalModuleName(this.c, node, specifier, false);
2252
+ const resolved = resolveExternalModuleName(
2253
+ this.c,
2254
+ node,
2255
+ specifier,
2256
+ false,
2257
+ getTypeFromImportAttributes(this.c, getImportAttributes(node)),
2258
+ );
2092
2259
  const exported = this.visit(resolved, node, isTypeOnly || getIsTypeOnly(node));
2093
2260
  this.extendExportSymbols(nested, exported, lookupTable, node);
2094
2261
  }
@@ -2154,7 +2321,13 @@ export function getTypeFromImportTypeNode(c: Checker, node: Node): Type {
2154
2321
  }
2155
2322
  const targetMeaning = importType.isTypeOf ? SymbolFlags.Value : SymbolFlags.Type;
2156
2323
  const literal = (importType.argument as LiteralTypeNode).literal;
2157
- const innerModuleSymbol = resolveExternalModuleName(c, node, literal, false);
2324
+ const innerModuleSymbol = resolveExternalModuleName(
2325
+ c,
2326
+ node,
2327
+ literal,
2328
+ false,
2329
+ getTypeFromImportAttributes(c, importType.attributes),
2330
+ );
2158
2331
  if (innerModuleSymbol === undefined) {
2159
2332
  c.resolvedSymbols.set(node.id, c.unknownSymbol);
2160
2333
  c.resolvedTypes.set(node.id, c.errorType);
@@ -2204,8 +2377,8 @@ export function getTypeFromImportTypeNode(c: Checker, node: Node): Type {
2204
2377
  return c.resolvedTypes.get(node.id)!;
2205
2378
  }
2206
2379
 
2207
- function getIdentifierChain(node: Node): Identifier[] {
2208
- if (node.kind === SyntaxKind.Identifier) return [node as Identifier];
2380
+ function getIdentifierChain(node: Node): Node[] {
2381
+ if (node.kind === SyntaxKind.Identifier) return [node];
2209
2382
  const chain = getIdentifierChain((node as QualifiedName).left);
2210
2383
  chain.push((node as QualifiedName).right);
2211
2384
  return chain;
@@ -2214,8 +2387,8 @@ function getIdentifierChain(node: Node): Identifier[] {
2214
2387
  function resolveImportSymbolType(c: Checker, node: Node, symbol: Symbol, meaning: SymbolFlags): Type {
2215
2388
  const resolvedSymbol = resolveSymbol(c, symbol)!;
2216
2389
  c.resolvedSymbols.set(node.id, resolvedSymbol);
2217
- // The alias itself caches the type of a value.
2218
- if (meaning === SymbolFlags.Value) return getTypeOfSymbol(c, symbol);
2390
+ // A value's type comes from the alias, which caches it, instantiated with the node's type arguments.
2391
+ if (meaning === SymbolFlags.Value) return getInstantiationExpressionType(c, getTypeOfSymbol(c, symbol), node);
2219
2392
  return getTypeReferenceType(c, node, resolvedSymbol);
2220
2393
  }
2221
2394
 
@@ -2234,6 +2407,7 @@ export function checkImportCallExpression(c: Checker, node: Node): Type {
2234
2407
  Diagnostics.Dynamic_import_s_specifier_must_be_of_type_string_but_here_has_type_0,
2235
2408
  typeToString(c, specifierType),
2236
2409
  );
2410
+ let importAttributesType: Type | undefined;
2237
2411
  if (optionsType !== undefined) {
2238
2412
  const importCallOptionsType = getCachedGlobalType(c, 'ImportCallOptions', 0, true);
2239
2413
  if (importCallOptionsType !== c.emptyObjectType)
@@ -2260,8 +2434,10 @@ export function checkImportCallExpression(c: Checker, node: Node): Type {
2260
2434
  break;
2261
2435
  }
2262
2436
  }
2437
+ importAttributesType = getTypeOfPropertyOfType(c, optionsType, 'with');
2263
2438
  }
2264
- const moduleSymbol = resolveExternalModuleName(c, node, specifier, false);
2439
+ if (isSourcePhaseImportCall(node)) return createPromiseReturnType(c, node, getGlobalAbstractModuleSourceType(c));
2440
+ const moduleSymbol = resolveExternalModuleName(c, node, specifier, false, importAttributesType);
2265
2441
  if (moduleSymbol !== undefined) {
2266
2442
  const esModuleSymbol = resolveExternalModuleSymbol(c, moduleSymbol, true);
2267
2443
  if (esModuleSymbol !== undefined)
@@ -2274,6 +2450,7 @@ export function checkImportCallExpression(c: Checker, node: Node): Type {
2274
2450
  esModuleSymbol,
2275
2451
  moduleSymbol,
2276
2452
  specifier,
2453
+ importAttributesType,
2277
2454
  ) ??
2278
2455
  getTypeWithSyntheticDefaultImportType(
2279
2456
  c,
@@ -2287,6 +2464,11 @@ export function checkImportCallExpression(c: Checker, node: Node): Type {
2287
2464
  return createPromiseReturnType(c, node, c.anyType);
2288
2465
  }
2289
2466
 
2467
+ /** `AbstractModuleSource`, the type of a source phase import's binding (lib.esnext.modulesource). */
2468
+ function getGlobalAbstractModuleSourceType(c: Checker): Type {
2469
+ return getCachedGlobalType(c, 'AbstractModuleSource', 0, true);
2470
+ }
2471
+
2290
2472
  function createPromiseReturnType(c: Checker, node: Node, promisedType: Type): Type {
2291
2473
  const promiseType = createPromiseType(c, promisedType);
2292
2474
  if (promiseType !== c.unknownType) return promiseType;
@@ -2314,7 +2496,7 @@ export function resolveJSDocMemberName(c: Checker, name: Node | undefined): Symb
2314
2496
  const prototype = getPropertyOfType(c, getTypeOfSymbol(c, left), 'prototype');
2315
2497
  if (prototype !== undefined) type = getTypeOfSymbol(c, prototype);
2316
2498
  }
2317
- return getPropertyOfType(c, type ?? getDeclaredTypeOfSymbol(c, left), (name as QualifiedName).right.text);
2499
+ return getPropertyOfType(c, type ?? getDeclaredTypeOfSymbol(c, left), getText((name as QualifiedName).right));
2318
2500
  }
2319
2501
 
2320
2502
  export function getHostSignatureFromJSDoc(node: Node): Node | undefined {
@@ -2330,8 +2512,8 @@ export function getHostSignatureFromJSDoc(node: Node): Node | undefined {
2330
2512
  export function checkMetaProperty(c: Checker, node: Node): Type {
2331
2513
  const meta = node as MetaProperty;
2332
2514
  if (meta.keywordToken === SyntaxKind.NewKeyword) return checkNewTargetMetaProperty(c, node);
2333
- // `import.defer` is only valid as a callee.
2334
- if (meta.name.text === 'defer') return c.errorType;
2515
+ // `import.defer` and `import.source` are only valid as callees.
2516
+ if (isImportPhaseMetaProperty(node)) return c.errorType;
2335
2517
  const moduleKind = getEmitModuleKind(c.compilerOptions);
2336
2518
  if (moduleKind >= ModuleKind.Node16 && moduleKind <= ModuleKind.NodeNext) {
2337
2519
  if (c.host.getImpliedNodeFormatForEmit(getSourceFileOfNode(node)) === ModuleKind.CommonJS)
@@ -2392,6 +2574,25 @@ function isValidExternalImportOrExportDeclaration(node: Node): boolean {
2392
2574
  return true;
2393
2575
  }
2394
2576
 
2577
+ /**
2578
+ * Resolves the module an import or export in an illegal context names, when that context is still
2579
+ * in a file's global scope (a block), to report a missing module. A side-effect import isn't resolved.
2580
+ */
2581
+ function checkExternalModuleNameInGlobalScope(c: Checker, node: Node): void {
2582
+ let container = node.parent;
2583
+ while (container !== undefined && (getContainerFlags(container) & ContainerFlags.IsContainer) === 0)
2584
+ container = container.parent;
2585
+ if (container === undefined || container.kind !== SyntaxKind.SourceFile) return;
2586
+ if (
2587
+ (node.kind === SyntaxKind.ImportDeclaration || node.kind === SyntaxKind.JSImportDeclaration) &&
2588
+ (node as ImportDeclaration).importClause === undefined
2589
+ )
2590
+ return;
2591
+ const moduleName = getExternalModuleName(node);
2592
+ if (moduleName !== undefined)
2593
+ resolveExternalModuleName(c, node, moduleName, false, getTypeFromImportAttributes(c, getImportAttributes(node)));
2594
+ }
2595
+
2395
2596
  function isInModuleElementContext(node: Node): boolean {
2396
2597
  const parent = node.parent!.kind;
2397
2598
  return (
@@ -2403,6 +2604,7 @@ function getImportAttributes(node: Node): ImportAttributes | undefined {
2403
2604
  if (node.kind === SyntaxKind.ImportDeclaration || node.kind === SyntaxKind.JSImportDeclaration)
2404
2605
  return (node as ImportDeclaration).attributes;
2405
2606
  if (node.kind === SyntaxKind.ExportDeclaration) return (node as ExportDeclaration).attributes;
2607
+ if (node.kind === SyntaxKind.ImportType) return (node as ImportTypeNode).attributes;
2406
2608
  return undefined;
2407
2609
  }
2408
2610
 
@@ -2429,6 +2631,7 @@ function hasParseErrors(node: Node): boolean {
2429
2631
  }
2430
2632
 
2431
2633
  export function checkImportDeclaration(c: Checker, node: Node): void {
2634
+ if (!isInModuleElementContext(node)) checkExternalModuleNameInGlobalScope(c, node);
2432
2635
  if (!isInModuleElementContext(node) || !isValidExternalImportOrExportDeclaration(node)) {
2433
2636
  checkImportAttributes(c, node);
2434
2637
  return;
@@ -2449,7 +2652,13 @@ export function checkImportDeclaration(c: Checker, node: Node): void {
2449
2652
  checkExternalEmitHelpers(c, node, ExternalEmitHelpers.ImportStar);
2450
2653
  }
2451
2654
  } else {
2452
- resolvedModule = resolveExternalModuleName(c, node, declaration.moduleSpecifier, false);
2655
+ resolvedModule = resolveExternalModuleName(
2656
+ c,
2657
+ node,
2658
+ declaration.moduleSpecifier,
2659
+ false,
2660
+ getTypeFromImportAttributes(c, declaration.attributes),
2661
+ );
2453
2662
  if (resolvedModule !== undefined)
2454
2663
  for (const binding of (namedBindings as NamedImports).elements.nodes) checkImportBinding(c, binding);
2455
2664
  }
@@ -2461,7 +2670,12 @@ export function checkImportDeclaration(c: Checker, node: Node): void {
2461
2670
  !isTypeOnly(clause) &&
2462
2671
  moduleKind >= ModuleKind.Node18 &&
2463
2672
  moduleKind <= ModuleKind.NodeNext &&
2464
- isOnlyImportableAsDefault(c, declaration.moduleSpecifier, resolvedModule) &&
2673
+ isOnlyImportableAsDefault(
2674
+ c,
2675
+ declaration.moduleSpecifier,
2676
+ resolvedModule,
2677
+ getTypeFromImportAttributes(c, declaration.attributes),
2678
+ ) &&
2465
2679
  !hasTypeJsonImportAttribute(declaration)
2466
2680
  )
2467
2681
  c.error(
@@ -2477,6 +2691,7 @@ export function checkImportDeclaration(c: Checker, node: Node): void {
2477
2691
  Diagnostics.Cannot_find_module_or_type_declarations_for_side_effect_import_of_0,
2478
2692
  false,
2479
2693
  false,
2694
+ getTypeFromImportAttributes(c, declaration.attributes),
2480
2695
  );
2481
2696
  checkImportAttributes(c, node);
2482
2697
  }
@@ -2503,21 +2718,50 @@ function checkImportBinding(c: Checker, node: Node): void {
2503
2718
  }
2504
2719
 
2505
2720
  /** Import attributes must be assignable to the global `ImportAttributes`. */
2506
- function checkImportAttributes(c: Checker, declaration: Node): void {
2721
+ export function checkImportAttributes(c: Checker, declaration: Node): void {
2507
2722
  const node = getImportAttributes(declaration);
2508
2723
  if (node === undefined) return;
2509
2724
  const importAttributesType = getCachedGlobalType(c, 'ImportAttributes', 0, true);
2510
2725
  if (importAttributesType !== c.emptyObjectType)
2511
2726
  checkTypeAssignableTo(
2512
2727
  c,
2513
- getTypeFromImportAttributes(c, node),
2728
+ checkImportAttributesExpression(c, node),
2514
2729
  getNullableType(c, importAttributesType, TypeFlags.Undefined),
2515
2730
  node,
2516
2731
  undefined,
2517
2732
  );
2518
2733
  }
2519
2734
 
2520
- function getTypeFromImportAttributes(c: Checker, node: ImportAttributes): Type {
2735
+ /** The type of import attributes, which resolution matches against the attributes types of pattern ambient modules. */
2736
+ function getTypeFromImportAttributes(c: Checker, node: Node | undefined): Type | undefined {
2737
+ if (node === undefined) return undefined;
2738
+ if (node.kind === SyntaxKind.ImportAttributes) return checkImportAttributesExpression(c, node as ImportAttributes);
2739
+ return checkExpressionCached(c, node);
2740
+ }
2741
+
2742
+ /** The import attributes type of the declaration `node` is the module specifier of. */
2743
+ export function getImportAttributesTypeForModuleSpecifier(c: Checker, moduleSpecifier: Node): Type | undefined {
2744
+ const parent = moduleSpecifier.parent!;
2745
+ switch (parent.kind) {
2746
+ case SyntaxKind.ImportDeclaration:
2747
+ case SyntaxKind.JSImportDeclaration:
2748
+ case SyntaxKind.ExportDeclaration:
2749
+ return getTypeFromImportAttributes(c, getImportAttributes(parent));
2750
+ case SyntaxKind.LiteralType:
2751
+ if (parent.parent!.kind === SyntaxKind.ImportType)
2752
+ return getTypeFromImportAttributes(c, (parent.parent as ImportTypeNode).attributes);
2753
+ return undefined;
2754
+ case SyntaxKind.CallExpression: {
2755
+ const args = (parent as CallExpression).arguments.nodes;
2756
+ if (isImportCall(parent) && args.length > 1)
2757
+ return getTypeOfPropertyOfType(c, checkExpressionCached(c, args[1]!), 'with');
2758
+ return undefined;
2759
+ }
2760
+ }
2761
+ return undefined;
2762
+ }
2763
+
2764
+ export function checkImportAttributesExpression(c: Checker, node: ImportAttributes): Type {
2521
2765
  if (c.resolvedTypes.get(node.id) === undefined) {
2522
2766
  const symbol = c.newSymbol(SymbolFlags.ObjectLiteral, InternalSymbolName.ImportAttributes);
2523
2767
  const members: SymbolTable = new Map<string, Symbol>();
@@ -2526,7 +2770,7 @@ function getTypeFromImportAttributes(c: Checker, node: ImportAttributes): Type {
2526
2770
  const member = c.newSymbol(SymbolFlags.Property, name);
2527
2771
  c.symbolTypes.set(
2528
2772
  getSymbolId(member),
2529
- getRegularTypeOfLiteralType(c, checkExpression(c, (attribute as ImportAttribute).value)),
2773
+ getRegularTypeOfLiteralType(c, checkExpressionCached(c, (attribute as ImportAttribute).value)),
2530
2774
  );
2531
2775
  members.set(name, member);
2532
2776
  }
@@ -2538,7 +2782,10 @@ function getTypeFromImportAttributes(c: Checker, node: ImportAttributes): Type {
2538
2782
  }
2539
2783
 
2540
2784
  export function checkImportEqualsDeclaration(c: Checker, node: Node): void {
2541
- if (!isInModuleElementContext(node)) return;
2785
+ if (!isInModuleElementContext(node)) {
2786
+ checkExternalModuleNameInGlobalScope(c, node);
2787
+ return;
2788
+ }
2542
2789
  const declaration = node as ImportEqualsDeclaration;
2543
2790
  const reference = declaration.moduleReference;
2544
2791
  const isExternal = reference.kind === SyntaxKind.ExternalModuleReference;
@@ -2596,14 +2843,23 @@ function checkNamespaceExportName(c: Checker, name: Node | undefined): void {
2596
2843
  }
2597
2844
 
2598
2845
  export function checkExportDeclaration(c: Checker, node: Node): void {
2599
- if (!isInModuleElementContext(node)) return;
2846
+ if (!isInModuleElementContext(node)) {
2847
+ checkExternalModuleNameInGlobalScope(c, node);
2848
+ return;
2849
+ }
2600
2850
  const declaration = node as ExportDeclaration;
2601
2851
  if (declaration.moduleSpecifier === undefined || isValidExternalImportOrExportDeclaration(node)) {
2602
2852
  const clause = declaration.exportClause;
2603
2853
  if (clause !== undefined && clause.kind === SyntaxKind.NamedExports) {
2604
2854
  for (const specifier of (clause as NamedExports).elements.nodes) checkExportSpecifier(c, specifier);
2605
2855
  } else {
2606
- const moduleSymbol = resolveExternalModuleName(c, node, declaration.moduleSpecifier, false);
2856
+ const moduleSymbol = resolveExternalModuleName(
2857
+ c,
2858
+ node,
2859
+ declaration.moduleSpecifier,
2860
+ false,
2861
+ getTypeFromImportAttributes(c, declaration.attributes),
2862
+ );
2607
2863
  if (moduleSymbol !== undefined && hasExportAssignmentSymbol(moduleSymbol))
2608
2864
  c.error(
2609
2865
  declaration.moduleSpecifier,
@@ -2682,15 +2938,23 @@ export function getDeclarationContainer(node: Node): Node {
2682
2938
  }
2683
2939
 
2684
2940
  /** `export = e` and `export default e`; the grammar checker reports misplaced ones. */
2941
+ /** Whether an export assignment is in a namespace, rather than a file or an ambient module. */
2942
+ function isContainedByNamespace(node: Node): boolean {
2943
+ const container = node.parent!.kind === SyntaxKind.SourceFile ? node.parent! : node.parent!.parent!;
2944
+ return container.kind === SyntaxKind.ModuleDeclaration && !isAmbientModule(container);
2945
+ }
2946
+
2685
2947
  export function checkExportAssignment(c: Checker, node: Node): void {
2686
- if (!isInModuleElementContext(node)) return;
2687
2948
  const declaration = node as ExportAssignment;
2949
+ // The expression is checked also where an export assignment is a grammar error.
2950
+ const exprType = checkExpressionCached(c, declaration.expression);
2951
+ if (!isInModuleElementContext(node)) return;
2688
2952
  const isExportEquals = declaration.isExportEquals;
2689
2953
  const ambient = (node.flags & NodeFlags.Ambient) !== 0;
2690
2954
  if (shouldCheckErasableSyntax(c, node) && isExportEquals && !ambient)
2691
2955
  c.error(node, Diagnostics.This_syntax_is_not_allowed_when_erasableSyntaxOnly_is_enabled);
2956
+ if (isContainedByNamespace(node)) return;
2692
2957
  const container = node.parent!.kind === SyntaxKind.SourceFile ? node.parent! : node.parent!.parent!;
2693
- if (container.kind === SyntaxKind.ModuleDeclaration && !isAmbientModule(container)) return;
2694
2958
  const verbatimModuleSyntax = c.compilerOptions.verbatimModuleSyntax === true;
2695
2959
  const isIllegalExportDefaultInCJS =
2696
2960
  !isExportEquals &&
@@ -2708,7 +2972,6 @@ export function checkExportAssignment(c: Checker, node: Node): void {
2708
2972
  const name = getText(id);
2709
2973
  // A non-value is exported as a type, like `export { Id as default }`.
2710
2974
  if ((getSymbolFlags(c, sym) & SymbolFlags.Value) !== 0) {
2711
- checkExpressionCached(c, id);
2712
2975
  if (!isIllegalExportDefaultInCJS && !ambient && verbatimModuleSyntax && typeOnlyDeclaration !== undefined)
2713
2976
  c.error(
2714
2977
  id,
@@ -2727,21 +2990,15 @@ export function checkExportAssignment(c: Checker, node: Node): void {
2727
2990
  );
2728
2991
  if (!isIllegalExportDefaultInCJS && !ambient && c.isolatedModules && (sym.flags & SymbolFlags.Value) === 0)
2729
2992
  checkIsolatedModulesExportAssignment(c, node, sym, typeOnlyDeclaration, isExportEquals);
2730
- } else checkExpressionCached(c, id);
2731
- } else checkExpressionCached(c, expression);
2993
+ }
2994
+ }
2732
2995
  if (isIllegalExportDefaultInCJS) c.error(node, verbatimModuleSyntaxErrorMessage(node));
2733
2996
  checkExternalModuleExports(c, container);
2734
2997
  // A JSDoc `@type` on `export default`.
2735
2998
  const typeNode = getType(node);
2736
2999
  if (typeNode !== undefined) {
2737
3000
  const expr = getExpression(node)!;
2738
- checkTypeAssignableToAndOptionallyElaborate(
2739
- c,
2740
- checkExpressionCached(c, expr),
2741
- getTypeFromTypeNode(c, typeNode),
2742
- expr,
2743
- expr,
2744
- );
3001
+ checkTypeAssignableToAndOptionallyElaborate(c, exprType, getTypeFromTypeNode(c, typeNode), expr, expr);
2745
3002
  }
2746
3003
  }
2747
3004
 
@@ -2939,6 +3196,7 @@ function checkIsolatedModulesAlias(
2939
3196
  getEmitModuleKind(c.compilerOptions) === ModuleKind.Preserve &&
2940
3197
  node.kind !== SyntaxKind.ImportEqualsDeclaration &&
2941
3198
  node.kind !== SyntaxKind.VariableDeclaration &&
3199
+ node.kind !== SyntaxKind.BindingElement &&
2942
3200
  c.host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) === ModuleKind.CommonJS
2943
3201
  )
2944
3202
  // Under `--module preserve` ESM syntax emits as ESM, so it is an error in a file that is CommonJS (.cts, .cjs).
@@ -2980,7 +3238,16 @@ export function getExternalModuleFileFromDeclaration(c: Checker, declaration: No
2980
3238
  if (name !== undefined && name.kind === SyntaxKind.StringLiteral) specifier = name;
2981
3239
  } else specifier = getExternalModuleName(declaration);
2982
3240
  if (specifier === undefined) return undefined;
2983
- const moduleSymbol = resolveExternalModuleNameWorker(c, specifier, specifier, undefined, false, false);
3241
+ // Used by emit and type printing after checking reported any resolution errors, so it adds none.
3242
+ const moduleSymbol = resolveExternalModuleNameWorker(
3243
+ c,
3244
+ specifier,
3245
+ specifier,
3246
+ undefined,
3247
+ true,
3248
+ false,
3249
+ getTypeFromImportAttributes(c, getImportAttributes(declaration)),
3250
+ );
2984
3251
  if (moduleSymbol === undefined) return undefined;
2985
3252
  const file = getDeclarationOfKind(moduleSymbol, SyntaxKind.SourceFile);
2986
3253
  return file === undefined ? undefined : (file as SourceFile);