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
@@ -6,7 +6,7 @@
6
6
  import { checkCollisionsForDeclarationName } from './checker-generated-code.js';
7
7
  import { checkDeprecatedImportSpecifier } from './checker-deprecation.js';
8
8
  import { getExpression, getInitializer, getIsTypeOnly, getLocals, getModuleSpecifier, getName, getPropertyName, getSymbol, getText, getType, } from './ast.js';
9
- import { getExternalModuleName, isAmbientModule, isImportCall, isFunctionLike, isGlobalScopeAugmentation, isInJSFile, isLiteralImportTypeNode, isRequireCall, isStringLiteralLike, isTypeOnly, nodeIsMissing, } from './ast-utilities.js';
9
+ import { getExternalModuleName, isAmbientModule, isImportCall, isFunctionLike, isGlobalScopeAugmentation, isInJSFile, isLiteralImportTypeNode, isRequireCall, isStringLiteralLike, isTypeOnly, nodeIsMissing, isImportPhaseMetaProperty, isSourcePhaseImport, isSourcePhaseImportCall, } from './ast-utilities.js';
10
10
  import { declarationNameToString, getDeclarationOfKind, getModifierFlags, isAccessExpression, getRootDeclaration, getSourceTextOfNode, getThisContainer, getSourceFileOfNode, hasSyntacticModifier, isGlobalSourceFile, isJsonSourceFile, isModuleAugmentationExternal, isPartOfTypeQuery, isVariableDeclarationInitializedToRequire, moduleExportNameIsDefault, } from './binder-utilities.js';
11
11
  import { chainDiagnostic, RepopulateInfo, } from './diagnostics.js';
12
12
  import { JsxEmit, ModuleKind, ModuleResolutionKind, getAllowImportingTsExtensions, getEmitModuleKind, getModuleResolutionKind, getResolveJsonModule, } from './options.js';
@@ -15,30 +15,32 @@ import { getResolutionModeOverride, moduleKindName } from './program-utilities.j
15
15
  import { hasExtension } from './vfs-match.js';
16
16
  import { isNodeCoreModule } from './parser.js';
17
17
  import { combinePaths, extensionIsTs, fileExtensionIsOneOf, getDeclarationFileExtension, getDirectoryPath, getNormalizedAbsolutePath, isDeclarationFileName, isExternalModuleNameRelative, pathIsRelative, removeExtension, supportedTSExtensionsFlat, tryExtractTSExtension, tryGetExtensionFromPath, } from './path.js';
18
+ import { getContainerFlags } from './binder.js';
18
19
  import { isExpressionNode } from './transformers/alias-references.js';
19
20
  import { createDiagnosticForNode } from './checker.js';
20
21
  import { checkExternalEmitHelpers } from './checker-emit-helpers.js';
21
- import { createAnonymousType, getRegularTypeOfLiteralType, getStringLiteralType, isErrorType, } from './checker-type-factory.js';
22
+ import { createAnonymousType, getRegularTypeOfLiteralType, getStringLiteralType, isEmptyObjectType, isErrorType, } from './checker-type-factory.js';
22
23
  import { getFullyQualifiedName, getMergedSymbol, getSpellingSuggestionForName, getSymbolFlags, getSymbolOfDeclaration, getSymbolOfMeaning, getDeclarationOfAliasSymbol, getExportSymbolOfValueSymbolIfExported, getExportsOfModule, getExportsOfSymbol, resolveAlias, resolveEntityName, resolveName, resolveSymbol, resolveSymbolEx, isNonLocalAlias, getCachedGlobalType, } from './checker-symbols.js';
23
24
  import { getTypeOfSymbol, getNullableType } from './checker-symbol-types.js';
24
- import { getPropertyOfType, getPropertyOfTypeEx, getSignaturesOfStructuredType, resolveStructuredTypeMembers, } from './checker-members.js';
25
+ import { getPropertyOfType, getPropertyOfTypeEx, getTypeOfPropertyOfType, getSignaturesOfStructuredType, resolveStructuredTypeMembers, } from './checker-members.js';
25
26
  import { getTypeFromTypeNode, getTypeReferenceType } from './checker-type-nodes.js';
26
- import { checkExpression, checkExpressionCached, getResolvedSymbol } from './checker-expressions.js';
27
- import { isTypeAssignableTo, checkTypeAssignableTo } from './relations.js';
27
+ import { checkExpressionCached, getResolvedSymbol } from './checker-expressions.js';
28
+ import { isTypeAssignableTo, isTypeIdenticalTo, isTypeStrictSubtypeOf, checkTypeAssignableTo } from './relations.js';
28
29
  import { getSpreadType } from './checker-object-literals.js';
29
30
  import { checkExternalModuleExports, shouldCheckErasableSyntax } from './checker-declarations.js';
30
31
  import { checkTypeNameIsReserved } from './checker-classes.js';
31
32
  import { getDeclaredTypeOfSymbol } from './checker-declared-types.js';
32
33
  import { isValidSpreadType } from './checker-destructuring.js';
33
34
  import { createPromiseType } from './checker-iteration.js';
35
+ import { getInstantiationExpressionType } from './checker-calls.js';
34
36
  import { symbolToString, typeToString } from './type-printer.js';
35
37
  import { checkTypeAssignableToAndOptionallyElaborate } from './checker-expressions.js';
36
38
  import { grammarErrorOnNode } from './checker-operators.js';
37
- import { declarationAt, declarationCount, getDeclarations, getSymbolId, setDeclarations, } from './symbol.js';
39
+ import { declarationAt, declarationCount, getDeclarations, getSymbolId, setDeclarations, copyDeclarations, } from './symbol.js';
38
40
  // ---- Resolution
39
41
  /** The module symbol `moduleReference` names, reporting it when it isn't found unless `ignoreErrors`. */
40
- export function resolveExternalModuleName(c, location, moduleReference, ignoreErrors) {
41
- return resolveExternalModuleNameWorker(c, location, moduleReference, ignoreErrors ? undefined : getCannotResolveModuleNameError(c, moduleReference), ignoreErrors, false);
42
+ export function resolveExternalModuleName(c, location, moduleReference, ignoreErrors, importAttributesType) {
43
+ return resolveExternalModuleNameWorker(c, location, moduleReference, ignoreErrors ? undefined : getCannotResolveModuleNameError(c, moduleReference), ignoreErrors, false, importAttributesType);
42
44
  }
43
45
  /** Node core modules suggest installing `@types/node`. */
44
46
  function getCannotResolveModuleNameError(c, moduleReference) {
@@ -47,26 +49,31 @@ function getCannotResolveModuleNameError(c, moduleReference) {
47
49
  isNodeCoreModule(getText(moduleReference))) {
48
50
  const types = c.compilerOptions.types;
49
51
  return types !== undefined && types.includes('*')
50
- ? 730 /* Diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_node_Try_npm_i_save_dev_types_Slashnode */
51
- : 739 /* Diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_node_Try_npm_i_save_dev_types_Slashnode_and_then_add_node_to_the_types_field_in_your_tsconfig */;
52
+ ? 737 /* Diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_node_Try_npm_i_save_dev_types_Slashnode */
53
+ : 746 /* Diagnostics.Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_node_Try_npm_i_save_dev_types_Slashnode_and_then_add_node_to_the_types_field_in_your_tsconfig */;
52
54
  }
53
- return 485 /* Diagnostics.Cannot_find_module_0_or_its_corresponding_type_declarations */;
55
+ return 492 /* Diagnostics.Cannot_find_module_0_or_its_corresponding_type_declarations */;
54
56
  }
55
- export function resolveExternalModuleNameWorker(c, location, moduleReference, moduleNotFoundError, ignoreErrors, isForAugmentation) {
57
+ export function resolveExternalModuleNameWorker(c, location, moduleReference, moduleNotFoundError, ignoreErrors, isForAugmentation, importAttributesType) {
56
58
  if (moduleReference === undefined || !isStringLiteralLike(moduleReference))
57
59
  return undefined;
58
- return resolveExternalModule(c, location, getText(moduleReference), moduleNotFoundError, ignoreErrors ? undefined : moduleReference, isForAugmentation);
60
+ // A source phase import loads no module declarations.
61
+ if (isSourcePhaseImport(moduleReference.parent))
62
+ return undefined;
63
+ return resolveExternalModule(c, location, getText(moduleReference), moduleNotFoundError, ignoreErrors ? undefined : moduleReference, isForAugmentation, importAttributesType);
59
64
  }
60
65
  /** A `resolveExternalModule` result that reported nothing, and the arguments it was computed for. */
61
66
  export class ModuleResolution {
62
67
  moduleReference;
63
68
  moduleNotFoundError;
64
69
  isForAugmentation;
70
+ importAttributesType;
65
71
  symbol;
66
- constructor(moduleReference, moduleNotFoundError, isForAugmentation, symbol) {
72
+ constructor(moduleReference, moduleNotFoundError, isForAugmentation, importAttributesType, symbol) {
67
73
  this.moduleReference = moduleReference;
68
74
  this.moduleNotFoundError = moduleNotFoundError;
69
75
  this.isForAugmentation = isForAugmentation;
76
+ this.importAttributesType = importAttributesType;
70
77
  this.symbol = symbol;
71
78
  }
72
79
  }
@@ -76,7 +83,7 @@ export class ModuleResolution {
76
83
  * with the same result and the same diagnostics: a result that reported nothing is kept for the
77
84
  * specifier and returned to later calls from the same declaration (`sharesSpecifierContext`).
78
85
  */
79
- export function resolveExternalModule(c, location, moduleReference, moduleNotFoundError, errorNode, isForAugmentation) {
86
+ export function resolveExternalModule(c, location, moduleReference, moduleNotFoundError, errorNode, isForAugmentation, importAttributesType) {
80
87
  // An augmentation merged later can give the resolved module a new merged symbol, so results are
81
88
  // kept only once every augmentation is merged.
82
89
  const shared = c.modulesMerged && errorNode !== undefined && sharesSpecifierContext(location, errorNode);
@@ -85,13 +92,14 @@ export function resolveExternalModule(c, location, moduleReference, moduleNotFou
85
92
  if (known !== undefined &&
86
93
  known.moduleReference === moduleReference &&
87
94
  known.moduleNotFoundError === moduleNotFoundError &&
88
- known.isForAugmentation === isForAugmentation)
95
+ known.isForAugmentation === isForAugmentation &&
96
+ known.importAttributesType === importAttributesType)
89
97
  return known.symbol;
90
98
  }
91
99
  const reports = c.reports;
92
- const symbol = resolveExternalModuleWorker(c, location, moduleReference, moduleNotFoundError, errorNode, isForAugmentation);
100
+ const symbol = resolveExternalModuleWorker(c, location, moduleReference, moduleNotFoundError, errorNode, isForAugmentation, importAttributesType ?? c.emptyObjectType);
93
101
  if (shared && c.reports === reports)
94
- c.moduleResolutions.set(errorNode, new ModuleResolution(moduleReference, moduleNotFoundError, isForAugmentation, symbol));
102
+ c.moduleResolutions.set(errorNode, new ModuleResolution(moduleReference, moduleNotFoundError, isForAugmentation, importAttributesType, symbol));
95
103
  return symbol;
96
104
  }
97
105
  /**
@@ -103,24 +111,24 @@ export function resolveExternalModule(c, location, moduleReference, moduleNotFou
103
111
  function sharesSpecifierContext(location, errorNode) {
104
112
  const declaration = errorNode.parent;
105
113
  if (declaration === undefined ||
106
- (declaration.kind !== 273 /* SyntaxKind.ImportDeclaration */ &&
107
- declaration.kind !== 346 /* SyntaxKind.JSImportDeclaration */ &&
108
- declaration.kind !== 279 /* SyntaxKind.ExportDeclaration */) ||
114
+ (declaration.kind !== 274 /* SyntaxKind.ImportDeclaration */ &&
115
+ declaration.kind !== 347 /* SyntaxKind.JSImportDeclaration */ &&
116
+ declaration.kind !== 280 /* SyntaxKind.ExportDeclaration */) ||
109
117
  getModuleSpecifier(declaration) !== errorNode)
110
118
  return false;
111
119
  for (let current = location; current !== undefined; current = current.parent)
112
120
  switch (current.kind) {
113
- case 273 /* SyntaxKind.ImportDeclaration */:
114
- case 346 /* SyntaxKind.JSImportDeclaration */:
115
- case 279 /* SyntaxKind.ExportDeclaration */:
121
+ case 274 /* SyntaxKind.ImportDeclaration */:
122
+ case 347 /* SyntaxKind.JSImportDeclaration */:
123
+ case 280 /* SyntaxKind.ExportDeclaration */:
116
124
  return current === declaration;
117
- case 274 /* SyntaxKind.ImportClause */:
118
- case 276 /* SyntaxKind.NamedImports */:
119
- case 275 /* SyntaxKind.NamespaceImport */:
120
- case 277 /* SyntaxKind.ImportSpecifier */:
121
- case 280 /* SyntaxKind.NamedExports */:
122
- case 281 /* SyntaxKind.NamespaceExport */:
123
- case 282 /* SyntaxKind.ExportSpecifier */:
125
+ case 275 /* SyntaxKind.ImportClause */:
126
+ case 277 /* SyntaxKind.NamedImports */:
127
+ case 276 /* SyntaxKind.NamespaceImport */:
128
+ case 278 /* SyntaxKind.ImportSpecifier */:
129
+ case 281 /* SyntaxKind.NamedExports */:
130
+ case 282 /* SyntaxKind.NamespaceExport */:
131
+ case 283 /* SyntaxKind.ExportSpecifier */:
124
132
  break;
125
133
  default:
126
134
  if (current !== errorNode)
@@ -128,12 +136,12 @@ function sharesSpecifierContext(location, errorNode) {
128
136
  }
129
137
  return false;
130
138
  }
131
- function resolveExternalModuleWorker(c, location, moduleReference, moduleNotFoundError, errorNode, isForAugmentation) {
139
+ function resolveExternalModuleWorker(c, location, moduleReference, moduleNotFoundError, errorNode, isForAugmentation, importAttributesType) {
132
140
  if (errorNode !== undefined && moduleReference.startsWith('@types/'))
133
- c.error(errorNode, 1302 /* Diagnostics.Cannot_import_type_declaration_files_Consider_importing_0_instead_of_1 */, moduleReference.substring(7), moduleReference);
141
+ c.error(errorNode, 1313 /* Diagnostics.Cannot_import_type_declaration_files_Consider_importing_0_instead_of_1 */, moduleReference.substring(7), moduleReference);
134
142
  const ambient = tryFindAmbientModule(c, moduleReference, true);
135
143
  if (ambient !== undefined)
136
- return ambient;
144
+ return tryResolvePatternAmbientModule(c, ambient, moduleReference, importAttributesType);
137
145
  const importingFile = getSourceFileOfNode(location);
138
146
  const contextSpecifier = getContextSpecifier(location);
139
147
  const mode = contextSpecifier !== undefined && isStringLiteralLike(contextSpecifier)
@@ -146,7 +154,7 @@ function resolveExternalModuleWorker(c, location, moduleReference, moduleNotFoun
146
154
  : undefined;
147
155
  const file = isResolved &&
148
156
  (resolutionDiagnostic === undefined ||
149
- resolutionDiagnostic === 1307 /* Diagnostics.Module_0_was_resolved_to_1_but_jsx_is_not_set */)
157
+ resolutionDiagnostic === 1318 /* Diagnostics.Module_0_was_resolved_to_1_but_jsx_is_not_set */)
150
158
  ? c.host.getSourceFileForResolvedModule(resolved.resolvedFileName)
151
159
  : undefined;
152
160
  if (file !== undefined) {
@@ -162,30 +170,25 @@ function resolveExternalModuleWorker(c, location, moduleReference, moduleNotFoun
162
170
  errorOnImplicitAnyModule(c, false, errorNode, mode, resolved, moduleReference);
163
171
  checkSyncImportOfESModule(c, location, moduleReference, importingFile, file, errorNode);
164
172
  }
165
- return getMergedSymbol(c, file.symbol);
173
+ return tryResolvePatternAmbientModule(c, getMergedSymbol(c, file.symbol), moduleReference, importAttributesType);
166
174
  }
175
+ const patternModule = tryResolvePatternAmbientModule(c, undefined, moduleReference, importAttributesType);
176
+ if (patternModule !== undefined)
177
+ return patternModule;
167
178
  if (errorNode !== undefined && moduleNotFoundError !== undefined && !isSideEffectImport(errorNode))
168
- c.error(errorNode, 484 /* Diagnostics.File_0_is_not_a_module */, resolved.resolvedFileName);
179
+ c.error(errorNode, 491 /* Diagnostics.File_0_is_not_a_module */, resolved.resolvedFileName);
169
180
  return undefined;
170
181
  }
171
- // The pattern with the longest prefix wins.
172
- let best;
173
- let bestPrefix = -1;
174
- for (const pattern of c.patternAmbientModules) {
175
- if (pattern.matches(moduleReference) && pattern.starIndex > bestPrefix) {
176
- bestPrefix = pattern.starIndex;
177
- best = pattern.symbol;
178
- }
179
- }
180
- if (best !== undefined)
181
- return getMergedSymbol(c, c.patternAmbientModuleAugmentations.get(moduleReference) ?? best);
182
+ const patternModule = tryResolvePatternAmbientModule(c, undefined, moduleReference, importAttributesType);
183
+ if (patternModule !== undefined)
184
+ return patternModule;
182
185
  if (errorNode === undefined)
183
186
  return undefined;
184
187
  // A module that resolved to JavaScript is untyped.
185
188
  if ((isResolved && !resolutionExtensionIsTSOrJson(resolved.extension) && resolutionDiagnostic === undefined) ||
186
- resolutionDiagnostic === 1688 /* Diagnostics.Could_not_find_a_declaration_file_for_module_0_1_implicitly_has_an_any_type */) {
189
+ resolutionDiagnostic === 1707 /* Diagnostics.Could_not_find_a_declaration_file_for_module_0_1_implicitly_has_an_any_type */) {
187
190
  if (isForAugmentation)
188
- c.error(errorNode, 799 /* Diagnostics.Invalid_module_name_in_augmentation_Module_0_resolves_to_an_untyped_module_at_1_which_cannot_be_augmented */, moduleReference, resolved.resolvedFileName);
191
+ c.error(errorNode, 806 /* Diagnostics.Invalid_module_name_in_augmentation_Module_0_resolves_to_an_untyped_module_at_1_which_cannot_be_augmented */, moduleReference, resolved.resolvedFileName);
189
192
  else
190
193
  errorOnImplicitAnyModule(c, c.noImplicitAny && moduleNotFoundError !== undefined, errorNode, mode, resolved, moduleReference);
191
194
  return undefined;
@@ -196,7 +199,7 @@ function resolveExternalModuleWorker(c, location, moduleReference, moduleNotFoun
196
199
  // A source file of a referenced project whose output hasn't been built.
197
200
  const outputDts = c.host.getProjectReferenceOutputDts(resolved.resolvedFileName);
198
201
  if (outputDts !== '') {
199
- c.error(errorNode, 1444 /* Diagnostics.Output_file_0_has_not_been_built_from_source_file_1 */, outputDts, resolved.resolvedFileName);
202
+ c.error(errorNode, 1455 /* Diagnostics.Output_file_0_has_not_been_built_from_source_file_1 */, outputDts, resolved.resolvedFileName);
200
203
  return undefined;
201
204
  }
202
205
  }
@@ -206,7 +209,7 @@ function resolveExternalModuleWorker(c, location, moduleReference, moduleNotFoun
206
209
  }
207
210
  const resolution = getModuleResolutionKind(c.compilerOptions);
208
211
  if (!getResolveJsonModule(c.compilerOptions) && moduleReference.endsWith('.json'))
209
- c.error(errorNode, 864 /* Diagnostics.Cannot_find_module_0_Consider_using_resolveJsonModule_to_import_module_with_json_extension */, moduleReference);
212
+ c.error(errorNode, 871 /* Diagnostics.Cannot_find_module_0_Consider_using_resolveJsonModule_to_import_module_with_json_extension */, moduleReference);
210
213
  else if (mode === ModuleKind.ESNext &&
211
214
  (resolution === ModuleResolutionKind.Node16 || resolution === ModuleResolutionKind.NodeNext) &&
212
215
  pathIsRelative(moduleReference) &&
@@ -214,9 +217,9 @@ function resolveExternalModuleWorker(c, location, moduleReference, moduleNotFoun
214
217
  const absolute = getNormalizedAbsolutePath(moduleReference, getDirectoryPath(importingFile.fileName));
215
218
  const extension = getSuggestedImportExtension(c, absolute);
216
219
  if (extension !== '')
217
- c.error(errorNode, 957 /* Diagnostics.Relative_import_paths_need_explicit_file_extensions_in_ECMAScript_imports_when_moduleResolution_is_node16_or_nodenext_Did_you_mean_0 */, moduleReference + extension);
220
+ c.error(errorNode, 964 /* Diagnostics.Relative_import_paths_need_explicit_file_extensions_in_ECMAScript_imports_when_moduleResolution_is_node16_or_nodenext_Did_you_mean_0 */, moduleReference + extension);
218
221
  else
219
- c.error(errorNode, 956 /* Diagnostics.Relative_import_paths_need_explicit_file_extensions_in_ECMAScript_imports_when_moduleResolution_is_node16_or_nodenext_Consider_adding_an_extension_to_the_import_path */);
222
+ c.error(errorNode, 963 /* Diagnostics.Relative_import_paths_need_explicit_file_extensions_in_ECMAScript_imports_when_moduleResolution_is_node16_or_nodenext_Consider_adding_an_extension_to_the_import_path */);
220
223
  }
221
224
  else if (resolved !== undefined && resolved.alternateResult !== '')
222
225
  c.addDiagnostic(chainDiagnostic(createModuleNotFoundChain(c, errorNode, moduleReference, mode, moduleReference), moduleNotFoundError, moduleReference));
@@ -224,13 +227,76 @@ function resolveExternalModuleWorker(c, location, moduleReference, moduleNotFoun
224
227
  c.error(errorNode, moduleNotFoundError, moduleReference);
225
228
  return undefined;
226
229
  }
230
+ /**
231
+ * The pattern ambient module `moduleReference` resolves to under `importAttributesType`, or
232
+ * `resolvedSymbol`. Without import attributes a module found by name or resolution wins. Among the
233
+ * patterns that match and accept the attributes, the one with the most specific attributes type wins,
234
+ * then the one with the longest prefix.
235
+ */
236
+ function tryResolvePatternAmbientModule(c, resolvedSymbol, moduleReference, importAttributesType) {
237
+ if (resolvedSymbol !== undefined && isEmptyObjectType(c, importAttributesType))
238
+ return resolvedSymbol;
239
+ if (c.patternAmbientModules.length === 0)
240
+ return resolvedSymbol;
241
+ const candidates = [];
242
+ for (const pattern of c.patternAmbientModules)
243
+ if (pattern.matches(moduleReference) &&
244
+ isTypeAssignableTo(c, importAttributesType, getTypeOfModuleImportAttributes(c, pattern.symbol)))
245
+ candidates.push(pattern);
246
+ if (candidates.length === 0)
247
+ return resolvedSymbol;
248
+ let best = candidates[0];
249
+ if (candidates.length > 1) {
250
+ const bestTypeCandidates = [];
251
+ for (let i = 0; i < candidates.length; i++) {
252
+ const candidateType = getTypeOfModuleImportAttributes(c, candidates[i].symbol);
253
+ let isBest = true;
254
+ for (let j = 0; j < candidates.length && isBest; j++) {
255
+ const otherType = getTypeOfModuleImportAttributes(c, candidates[j].symbol);
256
+ if (i !== j &&
257
+ isTypeStrictSubtypeOf(c, otherType, candidateType) &&
258
+ !isTypeIdenticalTo(c, otherType, candidateType))
259
+ isBest = false;
260
+ }
261
+ if (isBest)
262
+ bestTypeCandidates.push(candidates[i]);
263
+ }
264
+ // The pattern with the longest prefix wins.
265
+ best = bestTypeCandidates[0];
266
+ for (const pattern of bestTypeCandidates)
267
+ if (pattern.starIndex > best.starIndex)
268
+ best = pattern;
269
+ }
270
+ const merged = getMergedSymbol(c, best.symbol);
271
+ const augmentation = c.patternAmbientModuleAugmentations.get(moduleReference);
272
+ if (augmentation !== undefined && c.patternAmbientModuleAugmentationTargets.get(moduleReference) === merged)
273
+ return getMergedSymbol(c, augmentation);
274
+ return merged;
275
+ }
276
+ /** The import attributes type an ambient module declares, or the empty object type. */
277
+ export function getTypeOfModuleImportAttributes(c, symbol) {
278
+ let result = c.moduleImportAttributesTypes.get(symbol);
279
+ if (result === undefined) {
280
+ result = c.emptyObjectType;
281
+ for (const declaration of getDeclarations(symbol))
282
+ if (declaration.kind === 269 /* SyntaxKind.ModuleDeclaration */ &&
283
+ getName(declaration).kind === 10 /* SyntaxKind.StringLiteral */) {
284
+ const attributes = declaration.attributes;
285
+ if (attributes !== undefined)
286
+ result = getTypeFromTypeNode(c, attributes);
287
+ break;
288
+ }
289
+ c.moduleImportAttributesTypes.set(symbol, result);
290
+ }
291
+ return result;
292
+ }
227
293
  /** The module specifier that decides the resolution mode of a module reference at `location`. */
228
294
  function getContextSpecifier(location) {
229
295
  const parent = location.parent;
230
296
  if (isStringLiteralLike(location) ||
231
- (parent !== undefined && parent.kind === 268 /* SyntaxKind.ModuleDeclaration */ && getName(parent) === location))
297
+ (parent !== undefined && parent.kind === 269 /* SyntaxKind.ModuleDeclaration */ && getName(parent) === location))
232
298
  return location;
233
- if (location.kind === 268 /* SyntaxKind.ModuleDeclaration */)
299
+ if (location.kind === 269 /* SyntaxKind.ModuleDeclaration */)
234
300
  return getName(location);
235
301
  if (isLiteralImportTypeNode(location))
236
302
  return location.argument.literal;
@@ -241,21 +307,21 @@ function getContextSpecifier(location) {
241
307
  if (isImportCall(current))
242
308
  return current.arguments.nodes[0];
243
309
  for (let current = location; current !== undefined; current = current.parent)
244
- if (current.kind === 273 /* SyntaxKind.ImportDeclaration */ || current.kind === 346 /* SyntaxKind.JSImportDeclaration */)
310
+ if (current.kind === 274 /* SyntaxKind.ImportDeclaration */ || current.kind === 347 /* SyntaxKind.JSImportDeclaration */)
245
311
  return getModuleSpecifier(current);
246
312
  for (let current = location; current !== undefined; current = current.parent)
247
- if (current.kind === 279 /* SyntaxKind.ExportDeclaration */)
313
+ if (current.kind === 280 /* SyntaxKind.ExportDeclaration */)
248
314
  return getModuleSpecifier(current);
249
315
  for (let current = location; current !== undefined; current = current.parent)
250
- if (current.kind === 272 /* SyntaxKind.ImportEqualsDeclaration */) {
316
+ if (current.kind === 273 /* SyntaxKind.ImportEqualsDeclaration */) {
251
317
  const reference = current.moduleReference;
252
- return reference.kind === 284 /* SyntaxKind.ExternalModuleReference */ ? getExpression(reference) : undefined;
318
+ return reference.kind === 285 /* SyntaxKind.ExternalModuleReference */ ? getExpression(reference) : undefined;
253
319
  }
254
320
  return undefined;
255
321
  }
256
322
  /** The specifier of `const x = require("m")` or `const x = require("m").a.b` in JavaScript. */
257
323
  function getModuleSpecifierOfBareOrAccessedRequire(node) {
258
- if (node.kind !== 261 /* SyntaxKind.VariableDeclaration */ || !isInJSFile(node))
324
+ if (node.kind !== 262 /* SyntaxKind.VariableDeclaration */ || !isInJSFile(node))
259
325
  return undefined;
260
326
  const declaration = node;
261
327
  let initializer = declaration.initializer;
@@ -276,7 +342,7 @@ function checkResolvedModuleExtension(c, location, moduleReference, resolved, im
276
342
  return;
277
343
  if (isDeclarationFileName(moduleReference)) {
278
344
  if (isInEmittableImport(location))
279
- c.error(errorNode, 967 /* Diagnostics.A_declaration_file_cannot_be_imported_without_import_type_Did_you_mean_to_import_an_implementation_file_0_instead */, getSuggestedImportSource(c, moduleReference, tryExtractTSExtension(moduleReference), mode));
345
+ c.error(errorNode, 974 /* Diagnostics.A_declaration_file_cannot_be_imported_without_import_type_Did_you_mean_to_import_an_implementation_file_0_instead */, getSuggestedImportSource(c, moduleReference, tryExtractTSExtension(moduleReference), mode));
280
346
  }
281
347
  else if (!getAllowImportingTsExtensions(c.compilerOptions) &&
282
348
  !isDeclarationFileName(importingFile.fileName) &&
@@ -289,24 +355,24 @@ function checkResolvedModuleExtension(c, location, moduleReference, resolved, im
289
355
  extension = candidate;
290
356
  break;
291
357
  }
292
- c.error(errorNode, 1171 /* Diagnostics.An_import_path_can_only_end_with_a_0_extension_when_allowImportingTsExtensions_is_enabled */, extension);
358
+ c.error(errorNode, 1178 /* Diagnostics.An_import_path_can_only_end_with_a_0_extension_when_allowImportingTsExtensions_is_enabled */, extension);
293
359
  }
294
360
  }
295
361
  function isInEmittableImport(location) {
296
362
  for (let current = location; current !== undefined; current = current.parent) {
297
363
  switch (current.kind) {
298
- case 273 /* SyntaxKind.ImportDeclaration */: {
364
+ case 274 /* SyntaxKind.ImportDeclaration */: {
299
365
  const clause = current.importClause;
300
366
  if (clause !== undefined && !isTypeOnly(clause))
301
367
  return true;
302
368
  break;
303
369
  }
304
- case 279 /* SyntaxKind.ExportDeclaration */:
305
- case 272 /* SyntaxKind.ImportEqualsDeclaration */:
370
+ case 280 /* SyntaxKind.ExportDeclaration */:
371
+ case 273 /* SyntaxKind.ImportEqualsDeclaration */:
306
372
  if (!getIsTypeOnly(current))
307
373
  return true;
308
374
  break;
309
- case 214 /* SyntaxKind.CallExpression */:
375
+ case 215 /* SyntaxKind.CallExpression */:
310
376
  if (isImportCall(current))
311
377
  return true;
312
378
  break;
@@ -355,7 +421,7 @@ function checkSyncImportOfESModule(c, location, moduleReference, importingFile,
355
421
  const moduleKind = getEmitModuleKind(c.compilerOptions);
356
422
  if (moduleKind !== ModuleKind.Node16 && moduleKind !== ModuleKind.Node18)
357
423
  return;
358
- const importEquals = findAncestorOfKind(location, 272 /* SyntaxKind.ImportEqualsDeclaration */);
424
+ const importEquals = findAncestorOfKind(location, 273 /* SyntaxKind.ImportEqualsDeclaration */);
359
425
  const isSyncImport = (c.host.getDefaultResolutionModeForFile(importingFile) === ModuleKind.CommonJS && !isInImportCall(location)) ||
360
426
  importEquals !== undefined;
361
427
  if (!isSyncImport || c.host.getDefaultResolutionModeForFile(file) !== ModuleKind.ESNext)
@@ -364,7 +430,7 @@ function checkSyncImportOfESModule(c, location, moduleReference, importingFile,
364
430
  if (overrideHost !== undefined && hasResolutionModeOverride(overrideHost))
365
431
  return;
366
432
  if (importEquals !== undefined) {
367
- c.error(errorNode, 386 /* Diagnostics.Module_0_cannot_be_imported_using_this_construct_The_specifier_only_resolves_to_an_ES_module_which_cannot_be_imported_with_require_Use_an_ECMAScript_import_instead */, moduleReference);
433
+ c.error(errorNode, 384 /* Diagnostics.Module_0_cannot_be_imported_using_this_construct_The_specifier_only_resolves_to_an_ES_module_which_cannot_be_imported_with_require_Use_an_ECMAScript_import_instead */, moduleReference);
368
434
  return;
369
435
  }
370
436
  let details;
@@ -373,16 +439,16 @@ function checkSyncImportOfESModule(c, location, moduleReference, importingFile,
373
439
  details = detailsAt(errorNode, modeMismatchDetails(c.host, importingFile));
374
440
  details.repopulateInfo = new RepopulateInfo(1 /* RepopulateKind.ModeMismatch */);
375
441
  }
376
- let message = 394 /* Diagnostics.The_current_file_is_a_CommonJS_module_whose_imports_will_produce_require_calls_however_the_referenced_file_is_an_ECMAScript_module_and_cannot_be_imported_with_require_Consider_writing_a_dynamic_import_0_call_instead */;
377
- if (overrideHost !== undefined && overrideHost.kind === 273 /* SyntaxKind.ImportDeclaration */) {
442
+ let message = 392 /* Diagnostics.The_current_file_is_a_CommonJS_module_whose_imports_will_produce_require_calls_however_the_referenced_file_is_an_ECMAScript_module_and_cannot_be_imported_with_require_Consider_writing_a_dynamic_import_0_call_instead */;
443
+ if (overrideHost !== undefined && overrideHost.kind === 274 /* SyntaxKind.ImportDeclaration */) {
378
444
  const clause = overrideHost.importClause;
379
445
  if (clause !== undefined && isTypeOnly(clause))
380
446
  message =
381
- 456 /* Diagnostics.Type_only_import_of_an_ECMAScript_module_from_a_CommonJS_module_must_have_a_resolution_mode_attribute */;
447
+ 454 /* Diagnostics.Type_only_import_of_an_ECMAScript_module_from_a_CommonJS_module_must_have_a_resolution_mode_attribute */;
382
448
  }
383
- else if (overrideHost !== undefined && overrideHost.kind === 206 /* SyntaxKind.ImportType */)
449
+ else if (overrideHost !== undefined && overrideHost.kind === 207 /* SyntaxKind.ImportType */)
384
450
  message =
385
- 457 /* Diagnostics.Type_import_of_an_ECMAScript_module_from_a_CommonJS_module_must_have_a_resolution_mode_attribute */;
451
+ 455 /* Diagnostics.Type_import_of_an_ECMAScript_module_from_a_CommonJS_module_must_have_a_resolution_mode_attribute */;
386
452
  c.addDiagnostic(details !== undefined
387
453
  ? chainDiagnostic(details, message, moduleReference)
388
454
  : createDiagnosticForNode(errorNode, message, [moduleReference]));
@@ -402,19 +468,19 @@ function isInImportCall(node) {
402
468
  function findResolutionModeOverrideHost(node) {
403
469
  for (let current = node; current !== undefined; current = current.parent)
404
470
  switch (current.kind) {
405
- case 206 /* SyntaxKind.ImportType */:
406
- case 279 /* SyntaxKind.ExportDeclaration */:
407
- case 273 /* SyntaxKind.ImportDeclaration */:
408
- case 346 /* SyntaxKind.JSImportDeclaration */:
471
+ case 207 /* SyntaxKind.ImportType */:
472
+ case 280 /* SyntaxKind.ExportDeclaration */:
473
+ case 274 /* SyntaxKind.ImportDeclaration */:
474
+ case 347 /* SyntaxKind.JSImportDeclaration */:
409
475
  return current;
410
476
  }
411
477
  return undefined;
412
478
  }
413
479
  function hasResolutionModeOverride(node) {
414
480
  let attributes;
415
- if (node.kind === 206 /* SyntaxKind.ImportType */)
481
+ if (node.kind === 207 /* SyntaxKind.ImportType */)
416
482
  attributes = node.attributes;
417
- else if (node.kind === 279 /* SyntaxKind.ExportDeclaration */)
483
+ else if (node.kind === 280 /* SyntaxKind.ExportDeclaration */)
418
484
  attributes = node.attributes;
419
485
  else
420
486
  attributes = node.attributes;
@@ -444,12 +510,12 @@ export function modeMismatchDetails(host, file) {
444
510
  if (packageJsonDirectory !== '' && metadata.packageJsonType === '') {
445
511
  const packageJson = combinePaths(packageJsonDirectory, 'package.json');
446
512
  return targetExtension !== ''
447
- ? new DiagnosticDetails(396 /* Diagnostics.To_convert_this_file_to_an_ECMAScript_module_change_its_file_extension_to_0_or_add_the_field_type_Colon_module_to_1 */, [targetExtension, packageJson])
448
- : new DiagnosticDetails(397 /* Diagnostics.To_convert_this_file_to_an_ECMAScript_module_add_the_field_type_Colon_module_to_0 */, [packageJson]);
513
+ ? new DiagnosticDetails(394 /* Diagnostics.To_convert_this_file_to_an_ECMAScript_module_change_its_file_extension_to_0_or_add_the_field_type_Colon_module_to_1 */, [targetExtension, packageJson])
514
+ : new DiagnosticDetails(395 /* Diagnostics.To_convert_this_file_to_an_ECMAScript_module_add_the_field_type_Colon_module_to_0 */, [packageJson]);
449
515
  }
450
516
  return targetExtension !== ''
451
- ? new DiagnosticDetails(395 /* Diagnostics.To_convert_this_file_to_an_ECMAScript_module_change_its_file_extension_to_0_or_create_a_local_package_json_file_with_type_Colon_module */, [targetExtension])
452
- : new DiagnosticDetails(398 /* Diagnostics.To_convert_this_file_to_an_ECMAScript_module_create_a_local_package_json_file_with_type_Colon_module */, []);
517
+ ? new DiagnosticDetails(393 /* Diagnostics.To_convert_this_file_to_an_ECMAScript_module_change_its_file_extension_to_0_or_create_a_local_package_json_file_with_type_Colon_module */, [targetExtension])
518
+ : new DiagnosticDetails(396 /* Diagnostics.To_convert_this_file_to_an_ECMAScript_module_create_a_local_package_json_file_with_type_Colon_module */, []);
453
519
  }
454
520
  /** Reports a module without types: an error under `noImplicitAny`, otherwise a suggestion. */
455
521
  function errorOnImplicitAnyModule(c, isError, errorNode, mode, resolved, moduleReference) {
@@ -459,7 +525,7 @@ function errorOnImplicitAnyModule(c, isError, errorNode, mode, resolved, moduleR
459
525
  const chain = !isExternalModuleNameRelative(moduleReference) && packageName !== ''
460
526
  ? createModuleNotFoundChain(c, errorNode, moduleReference, mode, packageName)
461
527
  : undefined;
462
- const message = 1688 /* Diagnostics.Could_not_find_a_declaration_file_for_module_0_1_implicitly_has_an_any_type */;
528
+ const message = 1707 /* Diagnostics.Could_not_find_a_declaration_file_for_module_0_1_implicitly_has_an_any_type */;
463
529
  c.addErrorOrSuggestion(isError, chain !== undefined
464
530
  ? chainDiagnostic(chain, message, moduleReference, resolved.resolvedFileName)
465
531
  : createDiagnosticForNode(errorNode, message, [moduleReference, resolved.resolvedFileName]));
@@ -481,18 +547,18 @@ export function moduleNotFoundDetails(host, file, moduleReference, mode, package
481
547
  if (resolved !== undefined && resolved.alternateResult !== '') {
482
548
  if (resolved.alternateResult.includes('/node_modules/@types/'))
483
549
  packageName = '@types/' + mangleScopedPackageName(packageName);
484
- return new DiagnosticDetails(1427 /* Diagnostics.There_are_types_at_0_but_this_result_could_not_be_resolved_when_respecting_package_json_exports_The_1_library_may_need_to_update_its_package_json_or_typings */, [resolved.alternateResult, packageName]);
550
+ return new DiagnosticDetails(1438 /* Diagnostics.There_are_types_at_0_but_this_result_could_not_be_resolved_when_respecting_package_json_exports_The_1_library_may_need_to_update_its_package_json_or_typings */, [resolved.alternateResult, packageName]);
485
551
  }
486
552
  const packages = host.getPackagesMap();
487
553
  if (packages.has(getTypesPackageName(packageName)))
488
- return new DiagnosticDetails(1711 /* Diagnostics.If_the_0_package_actually_exposes_this_module_consider_sending_a_pull_request_to_amend_https_Colon_Slash_Slashgithub_com_SlashDefinitelyTyped_SlashDefinitelyTyped_Slashtree_Slashmaster_Slashtypes_Slash_1 */, [packageName, mangleScopedPackageName(packageName)]);
554
+ return new DiagnosticDetails(1730 /* Diagnostics.If_the_0_package_actually_exposes_this_module_consider_sending_a_pull_request_to_amend_https_Colon_Slash_Slashgithub_com_SlashDefinitelyTyped_SlashDefinitelyTyped_Slashtree_Slashmaster_Slashtypes_Slash_1 */, [packageName, mangleScopedPackageName(packageName)]);
489
555
  if (packages.get(packageName) === true)
490
- return new DiagnosticDetails(1729 /* Diagnostics.If_the_0_package_actually_exposes_this_module_try_adding_a_new_declaration_d_ts_file_containing_declare_module_1 */, [packageName, moduleReference]);
491
- return new DiagnosticDetails(1706 /* Diagnostics.Try_npm_i_save_dev_types_Slash_1_if_it_exists_or_add_a_new_declaration_d_ts_file_containing_declare_module_0 */, [moduleReference, mangleScopedPackageName(packageName)]);
556
+ return new DiagnosticDetails(1748 /* Diagnostics.If_the_0_package_actually_exposes_this_module_try_adding_a_new_declaration_d_ts_file_containing_declare_module_1 */, [packageName, moduleReference]);
557
+ return new DiagnosticDetails(1725 /* Diagnostics.Try_npm_i_save_dev_types_Slash_1_if_it_exists_or_add_a_new_declaration_d_ts_file_containing_declare_module_0 */, [moduleReference, mangleScopedPackageName(packageName)]);
492
558
  }
493
559
  function isSideEffectImport(node) {
494
560
  let current = node;
495
- while (current !== undefined && current.kind !== 273 /* SyntaxKind.ImportDeclaration */)
561
+ while (current !== undefined && current.kind !== 274 /* SyntaxKind.ImportDeclaration */)
496
562
  current = current.parent;
497
563
  return current !== undefined && current.importClause === undefined;
498
564
  }
@@ -521,14 +587,14 @@ export function resolveESModuleSymbol(c, moduleSymbol, node, moduleSpecifier) {
521
587
  if (symbol === undefined || moduleSymbol === undefined)
522
588
  return symbol;
523
589
  const referenceParent = moduleSpecifier.parent;
524
- const namespaceImport = referenceParent.kind === 273 /* SyntaxKind.ImportDeclaration */ ? getNamespaceImport(referenceParent) : undefined;
590
+ const namespaceImport = referenceParent.kind === 274 /* SyntaxKind.ImportDeclaration */ ? getNamespaceImport(referenceParent) : undefined;
525
591
  if (namespaceImport === undefined && !isImportCall(referenceParent))
526
592
  return symbol;
527
593
  const reference = isImportCall(referenceParent)
528
594
  ? referenceParent.arguments.nodes[0]
529
595
  : getModuleSpecifier(referenceParent);
530
596
  const type = getTypeOfSymbol(c, symbol);
531
- const defaultOnlyType = getTypeWithSyntheticDefaultOnly(c, type, symbol, moduleSymbol, reference);
597
+ const defaultOnlyType = getTypeWithSyntheticDefaultOnly(c, type, symbol, moduleSymbol, reference, getImportAttributesTypeForModuleSpecifier(c, reference));
532
598
  if (defaultOnlyType !== undefined)
533
599
  return cloneTypeAsModuleType(c, symbol, defaultOnlyType);
534
600
  if (hasSignatures(c, type) || getPropertyOfTypeEx(c, type, "default" /* InternalSymbolName.Default */, true, false) !== undefined) {
@@ -542,7 +608,7 @@ export function resolveESModuleSymbol(c, moduleSymbol, node, moduleSpecifier) {
542
608
  function getNamespaceImport(declaration) {
543
609
  const clause = declaration.importClause;
544
610
  const bindings = clause?.namedBindings;
545
- return bindings !== undefined && bindings.kind === 275 /* SyntaxKind.NamespaceImport */ ? bindings : undefined;
611
+ return bindings !== undefined && bindings.kind === 276 /* SyntaxKind.NamespaceImport */ ? bindings : undefined;
546
612
  }
547
613
  function hasSignatures(c, type) {
548
614
  return (getSignaturesOfStructuredType(c, type, 0 /* SignatureKind.Call */).length > 0 ||
@@ -552,13 +618,13 @@ function hasSignatures(c, type) {
552
618
  * Whether the module `usage` names is a JSON module imported into an ES module under `--module node16` to
553
619
  * `nodenext`, which Node.js gives only a default export.
554
620
  */
555
- function isOnlyImportableAsDefault(c, usage, resolvedModule) {
621
+ function isOnlyImportableAsDefault(c, usage, resolvedModule, importAttributesType) {
556
622
  const moduleKind = getEmitModuleKind(c.compilerOptions);
557
623
  if (moduleKind < ModuleKind.Node16 || moduleKind > ModuleKind.NodeNext)
558
624
  return false;
559
625
  if (getEmitSyntaxForModuleSpecifierExpression(c, usage) !== ModuleKind.ESNext)
560
626
  return false;
561
- const moduleSymbol = resolvedModule ?? resolveExternalModuleName(c, usage, usage, true);
627
+ const moduleSymbol = resolvedModule ?? resolveExternalModuleName(c, usage, usage, true, importAttributesType);
562
628
  const targetFile = moduleSymbol !== undefined ? getSourceFileOfModuleSymbol(moduleSymbol) : undefined;
563
629
  return (targetFile !== undefined &&
564
630
  (isJsonSourceFile(targetFile) ||
@@ -576,8 +642,8 @@ function getSourceFileOfModuleSymbol(symbol) {
576
642
  return declaration !== undefined ? getSourceFileOfNode(declaration) : undefined;
577
643
  }
578
644
  /** For a module only importable as default, the type of its namespace: an object with only `default`. */
579
- function getTypeWithSyntheticDefaultOnly(c, type, symbol, originalSymbol, moduleSpecifier) {
580
- if (!isOnlyImportableAsDefault(c, moduleSpecifier, undefined) || isErrorType(c, type))
645
+ function getTypeWithSyntheticDefaultOnly(c, type, symbol, originalSymbol, moduleSpecifier, importAttributesType) {
646
+ if (!isOnlyImportableAsDefault(c, moduleSpecifier, undefined, importAttributesType) || isErrorType(c, type))
581
647
  return undefined;
582
648
  const key = 'defaultOnly:' + type.id;
583
649
  const cached = c.moduleTypeCache.get(key);
@@ -599,6 +665,7 @@ function getTypeWithSyntheticDefaultImportType(c, type, symbol, originalSymbol,
599
665
  let result = type;
600
666
  if (canHaveSyntheticDefault(c, file, originalSymbol, false, moduleSpecifier)) {
601
667
  const anonymousSymbol = c.newSymbol(2048 /* SymbolFlags.TypeLiteral */, "\uFFFEtype" /* InternalSymbolName.Type */);
668
+ copyDeclarations(anonymousSymbol, originalSymbol);
602
669
  const defaultContainingObject = createDefaultPropertyWrapperForModule(c, symbol, originalSymbol, anonymousSymbol);
603
670
  c.symbolTypes.set(getSymbolId(anonymousSymbol), defaultContainingObject);
604
671
  result = isValidSpreadType(c, type)
@@ -617,6 +684,10 @@ function createDefaultPropertyWrapperForModule(c, symbol, originalSymbol, anonym
617
684
  links.aliasTarget = resolveSymbol(c, symbol);
618
685
  const members = new Map();
619
686
  members.set("default" /* InternalSymbolName.Default */, defaultSymbol);
687
+ if (anonymousSymbol === undefined && originalSymbol !== undefined) {
688
+ anonymousSymbol = c.newSymbol(4096 /* SymbolFlags.ObjectLiteral */, "\uFFFEobject" /* InternalSymbolName.Object */);
689
+ copyDeclarations(anonymousSymbol, originalSymbol);
690
+ }
620
691
  return createAnonymousType(c, anonymousSymbol, members, [], [], []);
621
692
  }
622
693
  function cloneTypeAsModuleType(c, symbol, moduleType) {
@@ -636,12 +707,12 @@ function getSourceFileDeclaration(symbol) {
636
707
  if (symbol === undefined)
637
708
  return undefined;
638
709
  for (const d of getDeclarations(symbol))
639
- if (d.kind === 307 /* SyntaxKind.SourceFile */)
710
+ if (d.kind === 308 /* SyntaxKind.SourceFile */)
640
711
  return d;
641
712
  return undefined;
642
713
  }
643
714
  /** The module syntax of the import or export containing `usage`, or `None` for non-literals. */
644
- function getEmitSyntaxForModuleSpecifierExpression(c, usage) {
715
+ export function getEmitSyntaxForModuleSpecifierExpression(c, usage) {
645
716
  return isStringLiteralLike(usage)
646
717
  ? c.host.getEmitSyntaxForUsageLocation(getSourceFileOfNode(usage), usage)
647
718
  : ModuleKind.None;
@@ -683,17 +754,17 @@ function hasSyntacticDefault(symbol) {
683
754
  return false;
684
755
  }
685
756
  function isSyntacticDefault(node) {
686
- return ((node.kind === 278 /* SyntaxKind.ExportAssignment */ && !node.isExportEquals) ||
757
+ return ((node.kind === 279 /* SyntaxKind.ExportAssignment */ && !node.isExportEquals) ||
687
758
  hasSyntacticModifier(node, 2048 /* ModifierFlags.Default */) ||
688
- node.kind === 282 /* SyntaxKind.ExportSpecifier */ ||
689
- node.kind === 281 /* SyntaxKind.NamespaceExport */);
759
+ node.kind === 283 /* SyntaxKind.ExportSpecifier */ ||
760
+ node.kind === 282 /* SyntaxKind.NamespaceExport */);
690
761
  }
691
762
  function hasExportAssignmentSymbol(moduleSymbol) {
692
763
  return moduleSymbol.exports?.get("export=" /* InternalSymbolName.ExportEquals */) !== undefined;
693
764
  }
694
765
  function isShorthandAmbientModuleSymbol(symbol) {
695
766
  const d = symbol?.valueDeclaration;
696
- return d !== undefined && d.kind === 268 /* SyntaxKind.ModuleDeclaration */ && d.body === undefined;
767
+ return d !== undefined && d.kind === 269 /* SyntaxKind.ModuleDeclaration */ && d.body === undefined;
697
768
  }
698
769
  // ---- Alias targets
699
770
  /** The symbol an alias declaration refers to, without resolving further aliases. */
@@ -701,38 +772,41 @@ export function getTargetOfAliasDeclaration(c, node) {
701
772
  if (node === undefined)
702
773
  return undefined;
703
774
  switch (node.kind) {
704
- case 272 /* SyntaxKind.ImportEqualsDeclaration */:
705
- case 261 /* SyntaxKind.VariableDeclaration */:
775
+ case 273 /* SyntaxKind.ImportEqualsDeclaration */:
776
+ case 262 /* SyntaxKind.VariableDeclaration */:
706
777
  return getTargetOfImportEqualsDeclaration(c, node);
707
- case 274 /* SyntaxKind.ImportClause */:
778
+ case 275 /* SyntaxKind.ImportClause */:
708
779
  return getTargetOfImportClause(c, node);
709
- case 275 /* SyntaxKind.NamespaceImport */:
780
+ case 276 /* SyntaxKind.NamespaceImport */:
710
781
  return getTargetOfNamespaceImport(c, node);
711
- case 281 /* SyntaxKind.NamespaceExport */:
782
+ case 282 /* SyntaxKind.NamespaceExport */:
712
783
  return getTargetOfNamespaceExport(c, node);
713
- case 277 /* SyntaxKind.ImportSpecifier */:
714
- case 209 /* SyntaxKind.BindingElement */:
784
+ case 278 /* SyntaxKind.ImportSpecifier */:
785
+ case 210 /* SyntaxKind.BindingElement */:
715
786
  return getTargetOfImportSpecifier(c, node);
716
- case 282 /* SyntaxKind.ExportSpecifier */:
787
+ case 283 /* SyntaxKind.ExportSpecifier */:
717
788
  return getTargetOfExportSpecifier(c, node, 111551 /* SymbolFlags.Value */ | 788968 /* SymbolFlags.Type */ | 1920 /* SymbolFlags.Namespace */, true);
718
- case 278 /* SyntaxKind.ExportAssignment */:
789
+ case 279 /* SyntaxKind.ExportAssignment */:
790
+ // An export assignment in a namespace is an error, and its expression is not resolved.
791
+ if (isContainedByNamespace(node))
792
+ return undefined;
719
793
  return withTypeOnlyMark(c, node, getTargetOfAliasLikeExpression(c, getExpression(node)));
720
- case 227 /* SyntaxKind.BinaryExpression */:
794
+ case 228 /* SyntaxKind.BinaryExpression */:
721
795
  return withTypeOnlyMark(c, node, getTargetOfAliasLikeExpression(c, node.right));
722
- case 271 /* SyntaxKind.NamespaceExportDeclaration */: {
796
+ case 272 /* SyntaxKind.NamespaceExportDeclaration */: {
723
797
  const resolved = resolveExternalModuleSymbol(c, getSymbol(node.parent), true);
724
798
  markSymbolOfAliasDeclarationIfTypeOnly(c, node, undefined);
725
799
  return resolved;
726
800
  }
727
- case 304 /* SyntaxKind.ShorthandPropertyAssignment */:
801
+ case 305 /* SyntaxKind.ShorthandPropertyAssignment */:
728
802
  return resolveEntityName(c, getName(node), 111551 /* SymbolFlags.Value */ | 788968 /* SymbolFlags.Type */ | 1920 /* SymbolFlags.Namespace */, true, true, undefined);
729
- case 303 /* SyntaxKind.PropertyAssignment */:
803
+ case 304 /* SyntaxKind.PropertyAssignment */:
730
804
  return getTargetOfAliasLikeExpression(c, getInitializer(node));
731
- case 213 /* SyntaxKind.ElementAccessExpression */:
732
- case 212 /* SyntaxKind.PropertyAccessExpression */: {
805
+ case 214 /* SyntaxKind.ElementAccessExpression */:
806
+ case 213 /* SyntaxKind.PropertyAccessExpression */: {
733
807
  const parent = node.parent;
734
808
  if (parent !== undefined &&
735
- parent.kind === 227 /* SyntaxKind.BinaryExpression */ &&
809
+ parent.kind === 228 /* SyntaxKind.BinaryExpression */ &&
736
810
  parent.left === node &&
737
811
  parent.operatorToken.kind === 63 /* SyntaxKind.EqualsToken */)
738
812
  return getTargetOfAliasLikeExpression(c, parent.right);
@@ -746,11 +820,11 @@ function withTypeOnlyMark(c, node, resolved) {
746
820
  return resolved;
747
821
  }
748
822
  function getTargetOfImportEqualsDeclaration(c, node) {
749
- if (node.kind === 261 /* SyntaxKind.VariableDeclaration */ || isExternalModuleImportEquals(node)) {
823
+ if (node.kind === 262 /* SyntaxKind.VariableDeclaration */ || isExternalModuleImportEquals(node)) {
750
824
  const moduleReference = isVariableDeclarationInitializedToRequire(node)
751
825
  ? getInitializer(node).arguments.nodes[0]
752
826
  : getExpression(node.moduleReference);
753
- const immediate = resolveExternalModuleName(c, node, moduleReference, false);
827
+ const immediate = resolveExternalModuleName(c, node, moduleReference, false, undefined);
754
828
  const resolved = resolveExternalModuleSymbol(c, immediate, true);
755
829
  const moduleKind = getEmitModuleKind(c.compilerOptions);
756
830
  if (resolved !== undefined && moduleKind >= ModuleKind.Node20 && moduleKind <= ModuleKind.NodeNext) {
@@ -766,8 +840,8 @@ function getTargetOfImportEqualsDeclaration(c, node) {
766
840
  return resolved;
767
841
  }
768
842
  function isExternalModuleImportEquals(node) {
769
- return (node.kind === 272 /* SyntaxKind.ImportEqualsDeclaration */ &&
770
- node.moduleReference.kind === 284 /* SyntaxKind.ExternalModuleReference */);
843
+ return (node.kind === 273 /* SyntaxKind.ImportEqualsDeclaration */ &&
844
+ node.moduleReference.kind === 285 /* SyntaxKind.ExternalModuleReference */);
771
845
  }
772
846
  /**
773
847
  * Resolves the entity name of `import a = b.c`: `b` alone or the left part of a longer name is a
@@ -776,10 +850,10 @@ function isExternalModuleImportEquals(node) {
776
850
  export function getSymbolOfPartOfRightHandSideOfImportEquals(c, entityName) {
777
851
  if (entityName.kind === 79 /* SyntaxKind.Identifier */ &&
778
852
  entityName.parent !== undefined &&
779
- entityName.parent.kind === 167 /* SyntaxKind.QualifiedName */ &&
853
+ entityName.parent.kind === 168 /* SyntaxKind.QualifiedName */ &&
780
854
  entityName.parent.right === entityName)
781
855
  entityName = entityName.parent;
782
- if (entityName.kind === 79 /* SyntaxKind.Identifier */ || entityName.parent.kind === 167 /* SyntaxKind.QualifiedName */)
856
+ if (entityName.kind === 79 /* SyntaxKind.Identifier */ || entityName.parent.kind === 168 /* SyntaxKind.QualifiedName */)
783
857
  return resolveEntityName(c, entityName, 1920 /* SymbolFlags.Namespace */, false, true, undefined);
784
858
  return resolveEntityName(c, entityName, 111551 /* SymbolFlags.Value */ | 788968 /* SymbolFlags.Type */ | 1920 /* SymbolFlags.Namespace */, false, true, undefined);
785
859
  }
@@ -788,28 +862,40 @@ function checkAndReportErrorForResolvingImportAliasToTypeOnlySymbol(c, node) {
788
862
  for (;;) {
789
863
  const typeOnlyDeclaration = getTypeOnlyDeclarationOfEntityName(c, name);
790
864
  if (typeOnlyDeclaration !== undefined) {
791
- const isExport = typeOnlyDeclaration.kind === 282 /* SyntaxKind.ExportSpecifier */ ||
792
- typeOnlyDeclaration.kind === 279 /* SyntaxKind.ExportDeclaration */;
865
+ const isExport = typeOnlyDeclaration.kind === 283 /* SyntaxKind.ExportSpecifier */ ||
866
+ typeOnlyDeclaration.kind === 280 /* SyntaxKind.ExportDeclaration */;
793
867
  const diagnostic = c.error(node.moduleReference, isExport
794
868
  ? 308 /* Diagnostics.An_import_alias_cannot_reference_a_declaration_that_was_exported_using_export_type */
795
869
  : 309 /* Diagnostics.An_import_alias_cannot_reference_a_declaration_that_was_imported_using_import_type */);
796
- const typeOnlyName = typeOnlyDeclaration.kind === 279 /* SyntaxKind.ExportDeclaration */ ? '*' : getText(getName(typeOnlyDeclaration));
870
+ const typeOnlyName = typeOnlyDeclaration.kind === 280 /* SyntaxKind.ExportDeclaration */ ? '*' : getText(getName(typeOnlyDeclaration));
797
871
  diagnostic.addRelatedInfo(createDiagnosticForNode(typeOnlyDeclaration, isExport ? 306 /* Diagnostics.X_0_was_exported_here */ : 305 /* Diagnostics.X_0_was_imported_here */, [typeOnlyName]));
798
872
  return;
799
873
  }
800
- if (name.kind !== 167 /* SyntaxKind.QualifiedName */)
874
+ if (name.kind !== 168 /* SyntaxKind.QualifiedName */)
801
875
  return;
802
876
  name = name.left;
803
877
  }
804
878
  }
805
879
  function getTypeOnlyDeclarationOfEntityName(c, name) {
806
- if (name.kind !== 79 /* SyntaxKind.Identifier */ && name.kind !== 167 /* SyntaxKind.QualifiedName */)
880
+ if (name.kind !== 79 /* SyntaxKind.Identifier */ && name.kind !== 168 /* SyntaxKind.QualifiedName */)
807
881
  return undefined;
808
882
  const symbol = resolveEntityName(c, name, 111551 /* SymbolFlags.Value */ | 788968 /* SymbolFlags.Type */ | 1920 /* SymbolFlags.Namespace */, true, true, undefined);
809
883
  return symbol !== undefined ? getTypeOnlyAliasDeclaration(c, symbol) : undefined;
810
884
  }
811
885
  function getTargetOfImportClause(c, node) {
812
- const moduleSymbol = resolveExternalModuleName(c, node, getModuleSpecifier(node.parent), false);
886
+ // `import source x from "m"` binds a module source object, not the module's default export.
887
+ if (node.phaseModifier === 167 /* SyntaxKind.SourceKeyword */) {
888
+ const alias = getSymbolOfDeclaration(c, node);
889
+ const links = c.symbolLinks(alias);
890
+ if (links.immediateTarget === undefined) {
891
+ const symbol = c.newSymbol(1 /* SymbolFlags.FunctionScopedVariable */, getText(node.name));
892
+ setDeclarations(symbol, getDeclarations(alias).slice());
893
+ c.symbolTypes.set(getSymbolId(symbol), getGlobalAbstractModuleSourceType(c));
894
+ links.immediateTarget = symbol;
895
+ }
896
+ return links.immediateTarget;
897
+ }
898
+ const moduleSymbol = resolveExternalModuleName(c, node, getModuleSpecifier(node.parent), false, getTypeFromImportAttributes(c, getImportAttributes(node.parent)));
813
899
  return moduleSymbol !== undefined ? getTargetOfModuleDefault(c, moduleSymbol, node, true) : undefined;
814
900
  }
815
901
  function getTargetOfModuleDefault(c, moduleSymbol, node, dontResolveAlias) {
@@ -820,13 +906,20 @@ function getTargetOfModuleDefault(c, moduleSymbol, node, dontResolveAlias) {
820
906
  : resolveExportByName(c, moduleSymbol, "default" /* InternalSymbolName.Default */, node, dontResolveAlias);
821
907
  if (specifier === undefined)
822
908
  return exportDefaultSymbol;
823
- const hasDefaultOnly = isOnlyImportableAsDefault(c, specifier, moduleSymbol);
909
+ let attributes;
910
+ if (node.kind === 275 /* SyntaxKind.ImportClause */)
911
+ attributes = getImportAttributes(node.parent);
912
+ else if (node.kind === 278 /* SyntaxKind.ImportSpecifier */)
913
+ attributes = getImportAttributes(node.parent.parent.parent);
914
+ else if (node.kind === 283 /* SyntaxKind.ExportSpecifier */)
915
+ attributes = getImportAttributes(node.parent.parent);
916
+ const hasDefaultOnly = isOnlyImportableAsDefault(c, specifier, moduleSymbol, getTypeFromImportAttributes(c, attributes));
824
917
  const hasSyntheticDefault = canHaveSyntheticDefault(c, file, moduleSymbol, dontResolveAlias, specifier);
825
918
  if (exportDefaultSymbol === undefined && !hasSyntheticDefault && !hasDefaultOnly) {
826
- if (node.kind === 274 /* SyntaxKind.ImportClause */)
919
+ if (node.kind === 275 /* SyntaxKind.ImportClause */)
827
920
  reportNonDefaultExport(c, moduleSymbol, node);
828
921
  else {
829
- const name = node.kind === 277 /* SyntaxKind.ImportSpecifier */ || node.kind === 282 /* SyntaxKind.ExportSpecifier */
922
+ const name = node.kind === 278 /* SyntaxKind.ImportSpecifier */ || node.kind === 283 /* SyntaxKind.ExportSpecifier */
830
923
  ? getPropertyNameOrName(node)
831
924
  : getName(node);
832
925
  errorNoModuleMemberSymbol(c, moduleSymbol, moduleSymbol, node, name);
@@ -845,7 +938,7 @@ function getTargetOfModuleDefault(c, moduleSymbol, node, dontResolveAlias) {
845
938
  function reportNonDefaultExport(c, moduleSymbol, node) {
846
939
  const local = getSymbol(node);
847
940
  if (moduleSymbol.exports?.get(local.name) !== undefined) {
848
- c.error(node, 757 /* Diagnostics.Module_0_has_no_default_export_Did_you_mean_to_use_import_1_from_0_instead */, symbolToString(c, moduleSymbol), symbolToString(c, local));
941
+ c.error(node, 764 /* Diagnostics.Module_0_has_no_default_export_Did_you_mean_to_use_import_1_from_0_instead */, symbolToString(c, moduleSymbol), symbolToString(c, local));
849
942
  return;
850
943
  }
851
944
  const diagnostic = c.error(getName(node), 148 /* Diagnostics.Module_0_has_no_default_export */, symbolToString(c, moduleSymbol));
@@ -854,9 +947,9 @@ function reportNonDefaultExport(c, moduleSymbol, node) {
854
947
  return;
855
948
  for (const d of getDeclarations(exportStar)) {
856
949
  const specifier = getModuleSpecifier(d);
857
- if (d.kind !== 279 /* SyntaxKind.ExportDeclaration */ || specifier === undefined)
950
+ if (d.kind !== 280 /* SyntaxKind.ExportDeclaration */ || specifier === undefined)
858
951
  continue;
859
- const resolved = resolveExternalModuleName(c, d, specifier, false);
952
+ const resolved = resolveExternalModuleName(c, d, specifier, false, getTypeFromImportAttributes(c, getImportAttributes(d)));
860
953
  if (resolved !== undefined && resolved.exports?.get("default" /* InternalSymbolName.Default */) !== undefined) {
861
954
  diagnostic.addRelatedInfo(createDiagnosticForNode(d, 151 /* Diagnostics.X_export_Asterisk_does_not_re_export_a_default */, []));
862
955
  return;
@@ -874,7 +967,7 @@ function resolveExportByName(c, moduleSymbol, name, sourceNode, dontResolveAlias
874
967
  }
875
968
  function getTargetOfNamespaceImport(c, node) {
876
969
  const moduleSpecifier = getModuleSpecifierForImportOrExport(node);
877
- const immediate = resolveExternalModuleName(c, node, moduleSpecifier, false);
970
+ const immediate = resolveExternalModuleName(c, node, moduleSpecifier, false, getTypeFromImportAttributes(c, getImportAttributes(node.parent.parent)));
878
971
  const resolved = resolveESModuleSymbol(c, immediate, node, moduleSpecifier);
879
972
  markSymbolOfAliasDeclarationIfTypeOnly(c, node, undefined);
880
973
  return resolved;
@@ -883,22 +976,22 @@ function getTargetOfNamespaceExport(c, node) {
883
976
  const moduleSpecifier = getModuleSpecifierForImportOrExport(node);
884
977
  if (moduleSpecifier === undefined)
885
978
  return undefined;
886
- const immediate = resolveExternalModuleName(c, node, moduleSpecifier, false);
979
+ const immediate = resolveExternalModuleName(c, node, moduleSpecifier, false, getTypeFromImportAttributes(c, getImportAttributes(node.parent)));
887
980
  const resolved = resolveESModuleSymbol(c, immediate, node, moduleSpecifier);
888
981
  markSymbolOfAliasDeclarationIfTypeOnly(c, node, undefined);
889
982
  return resolved;
890
983
  }
891
984
  function getTargetOfImportSpecifier(c, node) {
892
985
  const name = getPropertyNameOrName(node);
893
- if (node.kind === 277 /* SyntaxKind.ImportSpecifier */ && moduleExportNameIsDefault(name)) {
986
+ if (node.kind === 278 /* SyntaxKind.ImportSpecifier */ && moduleExportNameIsDefault(name)) {
894
987
  const specifier = getModuleSpecifierForImportOrExport(node);
895
988
  if (specifier !== undefined) {
896
- const moduleSymbol = resolveExternalModuleName(c, node, specifier, false);
989
+ const moduleSymbol = resolveExternalModuleName(c, node, specifier, false, getTypeFromImportAttributes(c, getImportAttributes(node.parent.parent.parent)));
897
990
  if (moduleSymbol !== undefined)
898
991
  return getTargetOfModuleDefault(c, moduleSymbol, node, true);
899
992
  }
900
993
  }
901
- const root = node.kind === 209 /* SyntaxKind.BindingElement */ ? getRootDeclaration(node) : node.parent.parent.parent;
994
+ const root = node.kind === 210 /* SyntaxKind.BindingElement */ ? getRootDeclaration(node) : node.parent.parent.parent;
902
995
  const resolved = getExternalModuleMember(c, root, node, true);
903
996
  markSymbolOfAliasDeclarationIfTypeOnly(c, node, undefined);
904
997
  return resolved;
@@ -908,8 +1001,9 @@ export function getExternalModuleMember(c, node, specifier, dontResolveAlias) {
908
1001
  const moduleSpecifier = isVariableDeclarationInitializedToRequire(node)
909
1002
  ? getInitializer(node).arguments.nodes[0]
910
1003
  : getExternalModuleName(node);
911
- const moduleSymbol = resolveExternalModuleName(c, node, moduleSpecifier, false);
912
- const name = specifier.kind === 212 /* SyntaxKind.PropertyAccessExpression */ ? getName(specifier) : getPropertyNameOrName(specifier);
1004
+ const importAttributesType = getTypeFromImportAttributes(c, getImportAttributes(node));
1005
+ const moduleSymbol = resolveExternalModuleName(c, node, moduleSpecifier, false, importAttributesType);
1006
+ const name = specifier.kind === 213 /* SyntaxKind.PropertyAccessExpression */ ? getName(specifier) : getPropertyNameOrName(specifier);
913
1007
  if (name.kind !== 79 /* SyntaxKind.Identifier */ && name.kind !== 10 /* SyntaxKind.StringLiteral */)
914
1008
  return undefined;
915
1009
  const nameText = getText(name);
@@ -932,7 +1026,7 @@ export function getExternalModuleMember(c, node, specifier, dontResolveAlias) {
932
1026
  let symbolFromModule = getExportOfModule(c, exportEquals ? moduleSymbol : targetSymbol, nameText, specifier, dontResolveAlias);
933
1027
  if (symbolFromModule === undefined &&
934
1028
  nameText === "default" /* InternalSymbolName.Default */ &&
935
- (isOnlyImportableAsDefault(c, moduleSpecifier, moduleSymbol) ||
1029
+ (isOnlyImportableAsDefault(c, moduleSpecifier, moduleSymbol, importAttributesType) ||
936
1030
  canHaveSyntheticDefault(c, getSourceFileDeclaration(moduleSymbol), moduleSymbol, dontResolveAlias, moduleSpecifier)))
937
1031
  symbolFromModule =
938
1032
  resolveExternalModuleSymbol(c, moduleSymbol, dontResolveAlias) ??
@@ -942,10 +1036,10 @@ export function getExternalModuleMember(c, node, specifier, dontResolveAlias) {
942
1036
  : symbolFromVariable === undefined
943
1037
  ? symbolFromModule
944
1038
  : combineValueAndTypeSymbols(c, symbolFromVariable, symbolFromModule);
945
- if ((specifier.kind === 277 /* SyntaxKind.ImportSpecifier */ || specifier.kind === 282 /* SyntaxKind.ExportSpecifier */) &&
1039
+ if ((specifier.kind === 278 /* SyntaxKind.ImportSpecifier */ || specifier.kind === 283 /* SyntaxKind.ExportSpecifier */) &&
946
1040
  nameText !== "default" /* InternalSymbolName.Default */ &&
947
- isOnlyImportableAsDefault(c, moduleSpecifier, moduleSymbol))
948
- c.error(name, 459 /* Diagnostics.Named_imports_from_a_JSON_file_into_an_ECMAScript_module_are_not_allowed_when_module_is_set_to_0 */, moduleKindName(getEmitModuleKind(c.compilerOptions)));
1041
+ isOnlyImportableAsDefault(c, moduleSpecifier, moduleSymbol, importAttributesType))
1042
+ c.error(name, 457 /* Diagnostics.Named_imports_from_a_JSON_file_into_an_ECMAScript_module_are_not_allowed_when_module_is_set_to_0 */, moduleKindName(getEmitModuleKind(c.compilerOptions)));
949
1043
  else if (symbol === undefined)
950
1044
  errorNoModuleMemberSymbol(c, moduleSymbol, targetSymbol, node, name);
951
1045
  return symbol;
@@ -998,13 +1092,13 @@ function errorNoModuleMemberSymbol(c, moduleSymbol, targetSymbol, node, name) {
998
1092
  : undefined;
999
1093
  if (suggestion !== undefined) {
1000
1094
  const suggestionName = symbolToString(c, suggestion);
1001
- const diagnostic = c.error(name, 856 /* Diagnostics.X_0_has_no_exported_member_named_1_Did_you_mean_2 */, moduleName, declarationName, suggestionName);
1095
+ const diagnostic = c.error(name, 863 /* Diagnostics.X_0_has_no_exported_member_named_1_Did_you_mean_2 */, moduleName, declarationName, suggestionName);
1002
1096
  if (suggestion.valueDeclaration !== undefined)
1003
- diagnostic.addRelatedInfo(createDiagnosticForNode(suggestion.valueDeclaration, 860 /* Diagnostics.X_0_is_declared_here */, [suggestionName]));
1097
+ diagnostic.addRelatedInfo(createDiagnosticForNode(suggestion.valueDeclaration, 867 /* Diagnostics.X_0_is_declared_here */, [suggestionName]));
1004
1098
  return;
1005
1099
  }
1006
1100
  if (moduleSymbol.exports?.get("default" /* InternalSymbolName.Default */) !== undefined) {
1007
- c.error(name, 758 /* Diagnostics.Module_0_has_no_exported_member_1_Did_you_mean_to_use_import_1_from_0_instead */, moduleName, declarationName);
1101
+ c.error(name, 765 /* Diagnostics.Module_0_has_no_exported_member_1_Did_you_mean_to_use_import_1_from_0_instead */, moduleName, declarationName);
1008
1102
  return;
1009
1103
  }
1010
1104
  reportNonExportedMember(c, name, declarationName, moduleSymbol, moduleName);
@@ -1013,7 +1107,7 @@ function reportNonExportedMember(c, name, declarationName, moduleSymbol, moduleN
1013
1107
  const locals = moduleSymbol.valueDeclaration !== undefined ? getLocals(moduleSymbol.valueDeclaration) : undefined;
1014
1108
  const localSymbol = locals?.get(getText(name));
1015
1109
  if (localSymbol === undefined) {
1016
- c.error(name, 483 /* Diagnostics.Module_0_has_no_exported_member_1 */, moduleName, declarationName);
1110
+ c.error(name, 490 /* Diagnostics.Module_0_has_no_exported_member_1 */, moduleName, declarationName);
1017
1111
  return;
1018
1112
  }
1019
1113
  const exports = moduleSymbol.exports;
@@ -1022,7 +1116,7 @@ function reportNonExportedMember(c, name, declarationName, moduleSymbol, moduleN
1022
1116
  if (isSameReference(c, exportEquals, localSymbol))
1023
1117
  reportInvalidImportEqualsExportMember(c, name, declarationName, moduleName);
1024
1118
  else
1025
- c.error(name, 483 /* Diagnostics.Module_0_has_no_exported_member_1 */, moduleName, declarationName);
1119
+ c.error(name, 490 /* Diagnostics.Module_0_has_no_exported_member_1 */, moduleName, declarationName);
1026
1120
  return;
1027
1121
  }
1028
1122
  let exportedSymbol;
@@ -1033,10 +1127,10 @@ function reportNonExportedMember(c, name, declarationName, moduleSymbol, moduleN
1033
1127
  break;
1034
1128
  }
1035
1129
  const diagnostic = exportedSymbol !== undefined
1036
- ? c.error(name, 626 /* Diagnostics.Module_0_declares_1_locally_but_it_is_exported_as_2 */, moduleName, declarationName, symbolToString(c, exportedSymbol))
1037
- : c.error(name, 625 /* Diagnostics.Module_0_declares_1_locally_but_it_is_not_exported */, moduleName, declarationName);
1130
+ ? c.error(name, 633 /* Diagnostics.Module_0_declares_1_locally_but_it_is_exported_as_2 */, moduleName, declarationName, symbolToString(c, exportedSymbol))
1131
+ : c.error(name, 632 /* Diagnostics.Module_0_declares_1_locally_but_it_is_not_exported */, moduleName, declarationName);
1038
1132
  for (let i = 0; i < declarationCount(localSymbol); i++)
1039
- diagnostic.addRelatedInfo(createDiagnosticForNode(declarationAt(localSymbol, i), i === 0 ? 860 /* Diagnostics.X_0_is_declared_here */ : 1357 /* Diagnostics.X_and_here */, [declarationName]));
1133
+ diagnostic.addRelatedInfo(createDiagnosticForNode(declarationAt(localSymbol, i), i === 0 ? 867 /* Diagnostics.X_0_is_declared_here */ : 1368 /* Diagnostics.X_and_here */, [declarationName]));
1040
1134
  }
1041
1135
  function isSameReference(c, s1, s2) {
1042
1136
  return (getMergedSymbol(c, resolveSymbol(c, getMergedSymbol(c, s1))) ===
@@ -1044,18 +1138,18 @@ function isSameReference(c, s1, s2) {
1044
1138
  }
1045
1139
  function reportInvalidImportEqualsExportMember(c, name, declarationName, moduleName) {
1046
1140
  if (getEmitModuleKind(c.compilerOptions) >= ModuleKind.ES2015)
1047
- c.error(name, 743 /* Diagnostics.X_0_can_only_be_imported_by_using_a_default_import */, declarationName);
1141
+ c.error(name, 750 /* Diagnostics.X_0_can_only_be_imported_by_using_a_default_import */, declarationName);
1048
1142
  else if (isInJSFile(name))
1049
- c.error(name, 745 /* Diagnostics.X_0_can_only_be_imported_by_using_a_require_call_or_by_using_a_default_import */, declarationName);
1143
+ c.error(name, 752 /* Diagnostics.X_0_can_only_be_imported_by_using_a_require_call_or_by_using_a_default_import */, declarationName);
1050
1144
  else
1051
- c.error(name, 760 /* Diagnostics.X_0_can_only_be_imported_by_using_import_1_require_2_or_a_default_import */, declarationName, declarationName, moduleName);
1145
+ c.error(name, 767 /* Diagnostics.X_0_can_only_be_imported_by_using_import_1_require_2_or_a_default_import */, declarationName, declarationName, moduleName);
1052
1146
  }
1053
1147
  export function getTargetOfExportSpecifier(c, node, meaning, dontResolveAlias) {
1054
1148
  const name = getPropertyNameOrName(node);
1055
1149
  if (moduleExportNameIsDefault(name)) {
1056
1150
  const specifier = getModuleSpecifierForImportOrExport(node);
1057
1151
  if (specifier !== undefined) {
1058
- const moduleSymbol = resolveExternalModuleName(c, node, specifier, false);
1152
+ const moduleSymbol = resolveExternalModuleName(c, node, specifier, false, getTypeFromImportAttributes(c, getImportAttributes(node.parent.parent)));
1059
1153
  if (moduleSymbol !== undefined)
1060
1154
  return getTargetOfModuleDefault(c, moduleSymbol, node, dontResolveAlias);
1061
1155
  }
@@ -1070,7 +1164,7 @@ export function getTargetOfExportSpecifier(c, node, meaning, dontResolveAlias) {
1070
1164
  return resolved;
1071
1165
  }
1072
1166
  function getTargetOfAliasLikeExpression(c, expression) {
1073
- if (expression.kind === 232 /* SyntaxKind.ClassExpression */)
1167
+ if (expression.kind === 233 /* SyntaxKind.ClassExpression */)
1074
1168
  return checkExpressionCached(c, expression).symbol;
1075
1169
  if (!isEntityNameOrEntityNameExpression(expression))
1076
1170
  return undefined;
@@ -1083,9 +1177,9 @@ function getTargetOfAliasLikeExpression(c, expression) {
1083
1177
  function isEntityNameOrEntityNameExpression(node) {
1084
1178
  if (node.kind === 79 /* SyntaxKind.Identifier */)
1085
1179
  return true;
1086
- if (node.kind === 167 /* SyntaxKind.QualifiedName */)
1180
+ if (node.kind === 168 /* SyntaxKind.QualifiedName */)
1087
1181
  return true;
1088
- if (node.kind === 212 /* SyntaxKind.PropertyAccessExpression */) {
1182
+ if (node.kind === 213 /* SyntaxKind.PropertyAccessExpression */) {
1089
1183
  const name = getName(node);
1090
1184
  return (name !== undefined &&
1091
1185
  name.kind === 79 /* SyntaxKind.Identifier */ &&
@@ -1098,25 +1192,25 @@ function getPropertyNameOrName(node) {
1098
1192
  }
1099
1193
  function getModuleSpecifierForImportOrExport(node) {
1100
1194
  switch (node.kind) {
1101
- case 274 /* SyntaxKind.ImportClause */:
1195
+ case 275 /* SyntaxKind.ImportClause */:
1102
1196
  return getModuleSpecifierOfDeclaration(node.parent);
1103
- case 272 /* SyntaxKind.ImportEqualsDeclaration */: {
1197
+ case 273 /* SyntaxKind.ImportEqualsDeclaration */: {
1104
1198
  const reference = node.moduleReference;
1105
- return reference.kind === 284 /* SyntaxKind.ExternalModuleReference */ ? getExpression(reference) : undefined;
1199
+ return reference.kind === 285 /* SyntaxKind.ExternalModuleReference */ ? getExpression(reference) : undefined;
1106
1200
  }
1107
- case 275 /* SyntaxKind.NamespaceImport */:
1201
+ case 276 /* SyntaxKind.NamespaceImport */:
1108
1202
  return getModuleSpecifierOfDeclaration(node.parent.parent);
1109
- case 277 /* SyntaxKind.ImportSpecifier */:
1203
+ case 278 /* SyntaxKind.ImportSpecifier */:
1110
1204
  return getModuleSpecifierOfDeclaration(node.parent.parent.parent);
1111
- case 281 /* SyntaxKind.NamespaceExport */:
1205
+ case 282 /* SyntaxKind.NamespaceExport */:
1112
1206
  return getModuleSpecifierOfDeclaration(node.parent);
1113
- case 282 /* SyntaxKind.ExportSpecifier */:
1207
+ case 283 /* SyntaxKind.ExportSpecifier */:
1114
1208
  return getModuleSpecifierOfDeclaration(node.parent.parent);
1115
1209
  }
1116
1210
  return undefined;
1117
1211
  }
1118
1212
  function getModuleSpecifierOfDeclaration(node) {
1119
- if (node.kind === 279 /* SyntaxKind.ExportDeclaration */)
1213
+ if (node.kind === 280 /* SyntaxKind.ExportDeclaration */)
1120
1214
  return node.moduleSpecifier;
1121
1215
  return getModuleSpecifier(node);
1122
1216
  }
@@ -1124,27 +1218,27 @@ function getModuleSpecifierOfDeclaration(node) {
1124
1218
  /** Whether the declaration itself is written `import type` or `export type`. */
1125
1219
  export function isTypeOnlyImportOrExportDeclaration(node) {
1126
1220
  switch (node.kind) {
1127
- case 277 /* SyntaxKind.ImportSpecifier */:
1221
+ case 278 /* SyntaxKind.ImportSpecifier */:
1128
1222
  return getIsTypeOnly(node) || isTypeOnlyImportClause(node.parent.parent);
1129
- case 275 /* SyntaxKind.NamespaceImport */:
1223
+ case 276 /* SyntaxKind.NamespaceImport */:
1130
1224
  return isTypeOnlyImportClause(node.parent);
1131
- case 274 /* SyntaxKind.ImportClause */:
1225
+ case 275 /* SyntaxKind.ImportClause */:
1132
1226
  return isTypeOnlyImportClause(node);
1133
- case 272 /* SyntaxKind.ImportEqualsDeclaration */:
1227
+ case 273 /* SyntaxKind.ImportEqualsDeclaration */:
1134
1228
  return getIsTypeOnly(node);
1135
- case 282 /* SyntaxKind.ExportSpecifier */:
1229
+ case 283 /* SyntaxKind.ExportSpecifier */:
1136
1230
  return getIsTypeOnly(node) || getIsTypeOnly(node.parent.parent);
1137
- case 279 /* SyntaxKind.ExportDeclaration */: {
1231
+ case 280 /* SyntaxKind.ExportDeclaration */: {
1138
1232
  const declaration = node;
1139
1233
  return (declaration.isTypeOnly && declaration.moduleSpecifier !== undefined && declaration.exportClause === undefined);
1140
1234
  }
1141
- case 281 /* SyntaxKind.NamespaceExport */:
1235
+ case 282 /* SyntaxKind.NamespaceExport */:
1142
1236
  return getIsTypeOnly(node.parent);
1143
1237
  }
1144
1238
  return false;
1145
1239
  }
1146
1240
  function isTypeOnlyImportClause(node) {
1147
- return node.kind === 274 /* SyntaxKind.ImportClause */ && node.phaseModifier === 156 /* SyntaxKind.TypeKeyword */;
1241
+ return node.kind === 275 /* SyntaxKind.ImportClause */ && node.phaseModifier === 156 /* SyntaxKind.TypeKeyword */;
1148
1242
  }
1149
1243
  /**
1150
1244
  * Marks an alias declared `import type`/`export type`, or reached through a type-only `export *`,
@@ -1170,19 +1264,19 @@ function markSymbolOfAliasDeclarationIfTypeOnly(c, aliasDeclaration, exportStarD
1170
1264
  /** Marks the alias declaration an entity name is part of, if it is type-only. */
1171
1265
  export function markAliasDeclarationOfNameIfTypeOnly(c, name) {
1172
1266
  let current = name;
1173
- while (current.parent !== undefined && current.parent.kind === 167 /* SyntaxKind.QualifiedName */)
1267
+ while (current.parent !== undefined && current.parent.kind === 168 /* SyntaxKind.QualifiedName */)
1174
1268
  current = current.parent;
1175
1269
  const parent = current.parent;
1176
1270
  if (parent === undefined)
1177
1271
  return;
1178
1272
  switch (parent.kind) {
1179
- case 274 /* SyntaxKind.ImportClause */:
1180
- case 277 /* SyntaxKind.ImportSpecifier */:
1181
- case 275 /* SyntaxKind.NamespaceImport */:
1182
- case 282 /* SyntaxKind.ExportSpecifier */:
1183
- case 278 /* SyntaxKind.ExportAssignment */:
1184
- case 272 /* SyntaxKind.ImportEqualsDeclaration */:
1185
- case 281 /* SyntaxKind.NamespaceExport */:
1273
+ case 275 /* SyntaxKind.ImportClause */:
1274
+ case 278 /* SyntaxKind.ImportSpecifier */:
1275
+ case 276 /* SyntaxKind.NamespaceImport */:
1276
+ case 283 /* SyntaxKind.ExportSpecifier */:
1277
+ case 279 /* SyntaxKind.ExportAssignment */:
1278
+ case 273 /* SyntaxKind.ImportEqualsDeclaration */:
1279
+ case 282 /* SyntaxKind.NamespaceExport */:
1186
1280
  markSymbolOfAliasDeclarationIfTypeOnly(c, parent, undefined);
1187
1281
  }
1188
1282
  }
@@ -1217,9 +1311,9 @@ export function getTypeOnlyAliasDeclarationOfMeaning(c, symbol, meaning) {
1217
1311
  function addTypeOnlyDeclarationRelatedInfo(diagnostic, typeOnlyDeclaration, name) {
1218
1312
  if (typeOnlyDeclaration === undefined)
1219
1313
  return;
1220
- const isExport = typeOnlyDeclaration.kind === 282 /* SyntaxKind.ExportSpecifier */ ||
1221
- typeOnlyDeclaration.kind === 279 /* SyntaxKind.ExportDeclaration */ ||
1222
- typeOnlyDeclaration.kind === 281 /* SyntaxKind.NamespaceExport */;
1314
+ const isExport = typeOnlyDeclaration.kind === 283 /* SyntaxKind.ExportSpecifier */ ||
1315
+ typeOnlyDeclaration.kind === 280 /* SyntaxKind.ExportDeclaration */ ||
1316
+ typeOnlyDeclaration.kind === 282 /* SyntaxKind.NamespaceExport */;
1223
1317
  diagnostic.addRelatedInfo(createDiagnosticForNode(typeOnlyDeclaration, isExport ? 306 /* Diagnostics.X_0_was_exported_here */ : 305 /* Diagnostics.X_0_was_imported_here */, [name]));
1224
1318
  }
1225
1319
  /** Reports a value use of a name that only resolves to a value through a type-only import or export. */
@@ -1231,9 +1325,9 @@ export function checkTypeOnlyAliasUse(c, location, result, name) {
1231
1325
  const typeOnlyDeclaration = getTypeOnlyAliasDeclarationOfMeaning(c, result, 111551 /* SymbolFlags.Value */);
1232
1326
  if (typeOnlyDeclaration === undefined)
1233
1327
  return;
1234
- const isExport = typeOnlyDeclaration.kind === 282 /* SyntaxKind.ExportSpecifier */ ||
1235
- typeOnlyDeclaration.kind === 279 /* SyntaxKind.ExportDeclaration */ ||
1236
- typeOnlyDeclaration.kind === 281 /* SyntaxKind.NamespaceExport */;
1328
+ const isExport = typeOnlyDeclaration.kind === 283 /* SyntaxKind.ExportSpecifier */ ||
1329
+ typeOnlyDeclaration.kind === 280 /* SyntaxKind.ExportDeclaration */ ||
1330
+ typeOnlyDeclaration.kind === 282 /* SyntaxKind.NamespaceExport */;
1237
1331
  const diagnostic = c.error(location, isExport
1238
1332
  ? 296 /* Diagnostics.X_0_cannot_be_used_as_a_value_because_it_was_exported_using_export_type */
1239
1333
  : 295 /* Diagnostics.X_0_cannot_be_used_as_a_value_because_it_was_imported_using_import_type */, name);
@@ -1250,26 +1344,26 @@ function isIdentifierInNonEmittingHeritageClause(node) {
1250
1344
  if (node.kind !== 79 /* SyntaxKind.Identifier */)
1251
1345
  return false;
1252
1346
  let parent = node.parent;
1253
- while (parent.kind === 212 /* SyntaxKind.PropertyAccessExpression */ || parent.kind === 234 /* SyntaxKind.ExpressionWithTypeArguments */)
1347
+ while (parent.kind === 213 /* SyntaxKind.PropertyAccessExpression */ || parent.kind === 235 /* SyntaxKind.ExpressionWithTypeArguments */)
1254
1348
  parent = parent.parent;
1255
- return (parent.kind === 299 /* SyntaxKind.HeritageClause */ &&
1349
+ return (parent.kind === 300 /* SyntaxKind.HeritageClause */ &&
1256
1350
  (parent.token === 118 /* SyntaxKind.ImplementsKeyword */ ||
1257
- parent.parent.kind === 265 /* SyntaxKind.InterfaceDeclaration */));
1351
+ parent.parent.kind === 266 /* SyntaxKind.InterfaceDeclaration */));
1258
1352
  }
1259
1353
  function isPartOfPossiblyValidTypeOrAbstractComputedPropertyName(node) {
1260
1354
  let current = node;
1261
- while (current.kind === 79 /* SyntaxKind.Identifier */ || current.kind === 212 /* SyntaxKind.PropertyAccessExpression */)
1355
+ while (current.kind === 79 /* SyntaxKind.Identifier */ || current.kind === 213 /* SyntaxKind.PropertyAccessExpression */)
1262
1356
  current = current.parent;
1263
- if (current.kind !== 168 /* SyntaxKind.ComputedPropertyName */)
1357
+ if (current.kind !== 169 /* SyntaxKind.ComputedPropertyName */)
1264
1358
  return false;
1265
1359
  if (hasSyntacticModifier(current.parent, 64 /* ModifierFlags.Abstract */))
1266
1360
  return true;
1267
1361
  const container = current.parent.parent.kind;
1268
- return container === 265 /* SyntaxKind.InterfaceDeclaration */ || container === 188 /* SyntaxKind.TypeLiteral */;
1362
+ return container === 266 /* SyntaxKind.InterfaceDeclaration */ || container === 189 /* SyntaxKind.TypeLiteral */;
1269
1363
  }
1270
1364
  function isShorthandPropertyNameUseSite(useSite) {
1271
1365
  return (useSite.kind === 79 /* SyntaxKind.Identifier */ &&
1272
- useSite.parent.kind === 304 /* SyntaxKind.ShorthandPropertyAssignment */ &&
1366
+ useSite.parent.kind === 305 /* SyntaxKind.ShorthandPropertyAssignment */ &&
1273
1367
  getName(useSite.parent) === useSite);
1274
1368
  }
1275
1369
  // ---- Referenced aliases
@@ -1298,14 +1392,14 @@ function shouldMarkIdentifierAliasReferenced(node) {
1298
1392
  if (parent === undefined)
1299
1393
  return true;
1300
1394
  // The left of a property access is marked with the property.
1301
- if (parent.kind === 212 /* SyntaxKind.PropertyAccessExpression */ && getExpression(parent) === node)
1395
+ if (parent.kind === 213 /* SyntaxKind.PropertyAccessExpression */ && getExpression(parent) === node)
1302
1396
  return false;
1303
1397
  // Names of type-only exports aren't emitted.
1304
- if (parent.kind === 282 /* SyntaxKind.ExportSpecifier */ && getIsTypeOnly(parent))
1398
+ if (parent.kind === 283 /* SyntaxKind.ExportSpecifier */ && getIsTypeOnly(parent))
1305
1399
  return false;
1306
1400
  const greatGrandparent = parent.parent?.parent;
1307
1401
  return !(greatGrandparent !== undefined &&
1308
- greatGrandparent.kind === 279 /* SyntaxKind.ExportDeclaration */ &&
1402
+ greatGrandparent.kind === 280 /* SyntaxKind.ExportDeclaration */ &&
1309
1403
  getIsTypeOnly(greatGrandparent));
1310
1404
  }
1311
1405
  /**
@@ -1317,7 +1411,7 @@ export function markPropertyAliasReferenced(c, location, prop, leftType) {
1317
1411
  return;
1318
1412
  if ((location.flags & 8388608 /* NodeFlags.Ambient */) !== 0 || isPartOfImportEqualsModuleReference(location))
1319
1413
  return;
1320
- const left = location.kind === 212 /* SyntaxKind.PropertyAccessExpression */ ? getExpression(location) : location.left;
1414
+ const left = location.kind === 213 /* SyntaxKind.PropertyAccessExpression */ ? getExpression(location) : location.left;
1321
1415
  if (left.kind !== 79 /* SyntaxKind.Identifier */ || getText(left) === 'this')
1322
1416
  return;
1323
1417
  const parentSymbol = getResolvedSymbol(c, left);
@@ -1332,13 +1426,13 @@ export function markPropertyAliasReferenced(c, location, prop, leftType) {
1332
1426
  }
1333
1427
  if (prop !== undefined &&
1334
1428
  (isConstEnumOrConstEnumOnlyModule(prop) ||
1335
- ((prop.flags & 8 /* SymbolFlags.EnumMember */) !== 0 && location.parent.kind === 306 /* SyntaxKind.EnumMember */)))
1429
+ ((prop.flags & 8 /* SymbolFlags.EnumMember */) !== 0 && location.parent.kind === 307 /* SyntaxKind.EnumMember */)))
1336
1430
  return;
1337
1431
  markAliasReferenced(c, parentSymbol, location);
1338
1432
  }
1339
1433
  function isPartOfImportEqualsModuleReference(location) {
1340
1434
  let importEquals = location;
1341
- while (importEquals !== undefined && importEquals.kind !== 272 /* SyntaxKind.ImportEqualsDeclaration */)
1435
+ while (importEquals !== undefined && importEquals.kind !== 273 /* SyntaxKind.ImportEqualsDeclaration */)
1342
1436
  importEquals = importEquals.parent;
1343
1437
  if (importEquals === undefined)
1344
1438
  return false;
@@ -1378,8 +1472,8 @@ function markAliasSymbolAsReferenced(c, symbol) {
1378
1472
  links.aliasReferenced = true;
1379
1473
  const node = getDeclarationOfAliasSymbol(symbol);
1380
1474
  if (node !== undefined &&
1381
- node.kind === 272 /* SyntaxKind.ImportEqualsDeclaration */ &&
1382
- node.moduleReference.kind !== 284 /* SyntaxKind.ExternalModuleReference */ &&
1475
+ node.kind === 273 /* SyntaxKind.ImportEqualsDeclaration */ &&
1476
+ node.moduleReference.kind !== 285 /* SyntaxKind.ExternalModuleReference */ &&
1383
1477
  (getSymbolFlags(c, resolveSymbol(c, symbol)) & 111551 /* SymbolFlags.Value */) !== 0)
1384
1478
  markIdentifierAliasReferenced(c, getFirstIdentifierOfEntityName(node.moduleReference));
1385
1479
  }
@@ -1416,9 +1510,9 @@ function isExportOrExportExpression(location) {
1416
1510
  const parent = n.parent;
1417
1511
  if (parent === undefined)
1418
1512
  return false;
1419
- if (parent.kind === 278 /* SyntaxKind.ExportAssignment */)
1420
- return (getExpression(parent) === n && isEntityNameOrEntityNameExpression(n) && n.kind !== 167 /* SyntaxKind.QualifiedName */);
1421
- if (parent.kind === 282 /* SyntaxKind.ExportSpecifier */) {
1513
+ if (parent.kind === 279 /* SyntaxKind.ExportAssignment */)
1514
+ return (getExpression(parent) === n && isEntityNameOrEntityNameExpression(n) && n.kind !== 168 /* SyntaxKind.QualifiedName */);
1515
+ if (parent.kind === 283 /* SyntaxKind.ExportSpecifier */) {
1422
1516
  if (getName(parent) === n || getPropertyName(parent) === n)
1423
1517
  return true;
1424
1518
  }
@@ -1510,7 +1604,7 @@ class ExportCollector {
1510
1604
  const lookupTable = new Map();
1511
1605
  for (const node of getDeclarations(exportStars)) {
1512
1606
  const specifier = node.moduleSpecifier;
1513
- const resolved = resolveExternalModuleName(this.c, node, specifier, false);
1607
+ const resolved = resolveExternalModuleName(this.c, node, specifier, false, getTypeFromImportAttributes(this.c, getImportAttributes(node)));
1514
1608
  const exported = this.visit(resolved, node, isTypeOnly || getIsTypeOnly(node));
1515
1609
  this.extendExportSymbols(nested, exported, lookupTable, node);
1516
1610
  }
@@ -1519,7 +1613,7 @@ class ExportCollector {
1519
1613
  if (id === "export=" /* InternalSymbolName.ExportEquals */ || collision.exportsWithDuplicate.length === 0 || symbols.has(id))
1520
1614
  continue;
1521
1615
  for (const node of collision.exportsWithDuplicate)
1522
- this.c.error(node, 486 /* Diagnostics.Module_0_has_already_exported_a_member_named_1_Consider_explicitly_re_exporting_to_resolve_the_ambiguity */, collision.specifierText, id);
1616
+ this.c.error(node, 493 /* Diagnostics.Module_0_has_already_exported_a_member_named_1_Consider_explicitly_re_exporting_to_resolve_the_ambiguity */, collision.specifierText, id);
1523
1617
  }
1524
1618
  this.extendExportSymbols(symbols, nested, undefined, undefined);
1525
1619
  }
@@ -1567,7 +1661,7 @@ export function getTypeFromImportTypeNode(c, node) {
1567
1661
  }
1568
1662
  const targetMeaning = importType.isTypeOf ? 111551 /* SymbolFlags.Value */ : 788968 /* SymbolFlags.Type */;
1569
1663
  const literal = importType.argument.literal;
1570
- const innerModuleSymbol = resolveExternalModuleName(c, node, literal, false);
1664
+ const innerModuleSymbol = resolveExternalModuleName(c, node, literal, false, getTypeFromImportAttributes(c, importType.attributes));
1571
1665
  if (innerModuleSymbol === undefined) {
1572
1666
  c.resolvedSymbols.set(node.id, c.unknownSymbol);
1573
1667
  c.resolvedTypes.set(node.id, c.errorType);
@@ -1587,7 +1681,7 @@ export function getTypeFromImportTypeNode(c, node) {
1587
1681
  ? getPropertyOfTypeEx(c, getTypeOfSymbol(c, merged), text, false, true)
1588
1682
  : getSymbolOfMeaning(c, getExportsOfSymbol(c, merged), text, meaning);
1589
1683
  if (next === undefined) {
1590
- c.error(current, 826 /* Diagnostics.Namespace_0_has_no_exported_member_1 */, getFullyQualifiedName(c, currentNamespace), declarationNameToString(getSourceFileOfNode(current), current));
1684
+ c.error(current, 833 /* Diagnostics.Namespace_0_has_no_exported_member_1 */, getFullyQualifiedName(c, currentNamespace), declarationNameToString(getSourceFileOfNode(current), current));
1591
1685
  c.resolvedTypes.set(node.id, c.errorType);
1592
1686
  return c.resolvedTypes.get(node.id);
1593
1687
  }
@@ -1619,9 +1713,9 @@ function getIdentifierChain(node) {
1619
1713
  function resolveImportSymbolType(c, node, symbol, meaning) {
1620
1714
  const resolvedSymbol = resolveSymbol(c, symbol);
1621
1715
  c.resolvedSymbols.set(node.id, resolvedSymbol);
1622
- // The alias itself caches the type of a value.
1716
+ // A value's type comes from the alias, which caches it, instantiated with the node's type arguments.
1623
1717
  if (meaning === 111551 /* SymbolFlags.Value */)
1624
- return getTypeOfSymbol(c, symbol);
1718
+ return getInstantiationExpressionType(c, getTypeOfSymbol(c, symbol), node);
1625
1719
  return getTypeReferenceType(c, node, resolvedSymbol);
1626
1720
  }
1627
1721
  /** `import(specifier, options)`: a promise of the module namespace. */
@@ -1636,49 +1730,57 @@ export function checkImportCallExpression(c, node) {
1636
1730
  for (let i = 2; i < args.length; i++)
1637
1731
  checkExpressionCached(c, args[i]);
1638
1732
  if ((specifierType.flags & 12 /* TypeFlags.Nullable */) !== 0 || !isTypeAssignableTo(c, specifierType, c.stringType))
1639
- c.error(specifier, 1707 /* Diagnostics.Dynamic_import_s_specifier_must_be_of_type_string_but_here_has_type_0 */, typeToString(c, specifierType));
1733
+ c.error(specifier, 1726 /* Diagnostics.Dynamic_import_s_specifier_must_be_of_type_string_but_here_has_type_0 */, typeToString(c, specifierType));
1734
+ let importAttributesType;
1640
1735
  if (optionsType !== undefined) {
1641
1736
  const importCallOptionsType = getCachedGlobalType(c, 'ImportCallOptions', 0, true);
1642
1737
  if (importCallOptionsType !== c.emptyObjectType)
1643
1738
  checkTypeAssignableTo(c, optionsType, getNullableType(c, importCallOptionsType, 4 /* TypeFlags.Undefined */), args[1], undefined);
1644
- if (args[1].kind === 211 /* SyntaxKind.ObjectLiteralExpression */)
1739
+ if (args[1].kind === 212 /* SyntaxKind.ObjectLiteralExpression */)
1645
1740
  for (const property of args[1].properties.nodes) {
1646
1741
  const name = getName(property);
1647
- if (property.kind === 303 /* SyntaxKind.PropertyAssignment */ &&
1742
+ if (property.kind === 304 /* SyntaxKind.PropertyAssignment */ &&
1648
1743
  name !== undefined &&
1649
1744
  name.kind === 79 /* SyntaxKind.Identifier */ &&
1650
1745
  getText(name) === 'assert') {
1651
- c.error(name, 1000 /* Diagnostics.Import_assertions_have_been_replaced_by_import_attributes_Use_with_instead_of_assert */);
1746
+ c.error(name, 1007 /* Diagnostics.Import_assertions_have_been_replaced_by_import_attributes_Use_with_instead_of_assert */);
1652
1747
  break;
1653
1748
  }
1654
1749
  }
1750
+ importAttributesType = getTypeOfPropertyOfType(c, optionsType, 'with');
1655
1751
  }
1656
- const moduleSymbol = resolveExternalModuleName(c, node, specifier, false);
1752
+ if (isSourcePhaseImportCall(node))
1753
+ return createPromiseReturnType(c, node, getGlobalAbstractModuleSourceType(c));
1754
+ const moduleSymbol = resolveExternalModuleName(c, node, specifier, false, importAttributesType);
1657
1755
  if (moduleSymbol !== undefined) {
1658
1756
  const esModuleSymbol = resolveExternalModuleSymbol(c, moduleSymbol, true);
1659
1757
  if (esModuleSymbol !== undefined)
1660
- return createPromiseReturnType(c, node, getTypeWithSyntheticDefaultOnly(c, getTypeOfSymbol(c, esModuleSymbol), esModuleSymbol, moduleSymbol, specifier) ??
1758
+ return createPromiseReturnType(c, node, getTypeWithSyntheticDefaultOnly(c, getTypeOfSymbol(c, esModuleSymbol), esModuleSymbol, moduleSymbol, specifier, importAttributesType) ??
1661
1759
  getTypeWithSyntheticDefaultImportType(c, getTypeOfSymbol(c, esModuleSymbol), esModuleSymbol, moduleSymbol, specifier));
1662
1760
  }
1663
1761
  return createPromiseReturnType(c, node, c.anyType);
1664
1762
  }
1763
+ /** `AbstractModuleSource`, the type of a source phase import's binding (lib.esnext.modulesource). */
1764
+ function getGlobalAbstractModuleSourceType(c) {
1765
+ return getCachedGlobalType(c, 'AbstractModuleSource', 0, true);
1766
+ }
1665
1767
  function createPromiseReturnType(c, node, promisedType) {
1666
1768
  const promiseType = createPromiseType(c, promisedType);
1667
1769
  if (promiseType !== c.unknownType)
1668
1770
  return promiseType;
1669
- c.error(node, 843 /* Diagnostics.A_dynamic_import_call_returns_a_Promise_Make_sure_you_have_a_declaration_for_Promise_or_include_ES2015_in_your_lib_option */);
1771
+ c.error(node, 850 /* Diagnostics.A_dynamic_import_call_returns_a_Promise_Make_sure_you_have_a_declaration_for_Promise_or_include_ES2015_in_your_lib_option */);
1670
1772
  return c.errorType;
1671
1773
  }
1672
1774
  // ---- JSDoc links
1673
1775
  /** The symbol a `{@link}` name refers to, as an entity or a member of one. */
1674
1776
  export function resolveJSDocMemberName(c, name) {
1675
- if (name === undefined || (name.kind !== 79 /* SyntaxKind.Identifier */ && name.kind !== 167 /* SyntaxKind.QualifiedName */))
1777
+ if (name === undefined || (name.kind !== 79 /* SyntaxKind.Identifier */ && name.kind !== 168 /* SyntaxKind.QualifiedName */))
1676
1778
  return undefined;
1677
1779
  const meaning = 788968 /* SymbolFlags.Type */ | 1920 /* SymbolFlags.Namespace */ | 111551 /* SymbolFlags.Value */;
1678
1780
  const symbol = resolveEntityName(c, name, meaning, true, true, getHostSignatureFromJSDoc(name));
1679
1781
  if (symbol !== undefined)
1680
1782
  return symbol;
1681
- if (name.kind !== 167 /* SyntaxKind.QualifiedName */)
1783
+ if (name.kind !== 168 /* SyntaxKind.QualifiedName */)
1682
1784
  return undefined;
1683
1785
  const left = resolveJSDocMemberName(c, name.left);
1684
1786
  if (left === undefined)
@@ -1689,11 +1791,11 @@ export function resolveJSDocMemberName(c, name) {
1689
1791
  if (prototype !== undefined)
1690
1792
  type = getTypeOfSymbol(c, prototype);
1691
1793
  }
1692
- return getPropertyOfType(c, type ?? getDeclaredTypeOfSymbol(c, left), name.right.text);
1794
+ return getPropertyOfType(c, type ?? getDeclaredTypeOfSymbol(c, left), getText(name.right));
1693
1795
  }
1694
1796
  export function getHostSignatureFromJSDoc(node) {
1695
1797
  let current = node;
1696
- while (current !== undefined && current.kind !== 315 /* SyntaxKind.JSDoc */)
1798
+ while (current !== undefined && current.kind !== 316 /* SyntaxKind.JSDoc */)
1697
1799
  current = current.parent;
1698
1800
  const host = current?.parent;
1699
1801
  return host !== undefined && isFunctionLike(host) ? host : undefined;
@@ -1704,13 +1806,13 @@ export function checkMetaProperty(c, node) {
1704
1806
  const meta = node;
1705
1807
  if (meta.keywordToken === 104 /* SyntaxKind.NewKeyword */)
1706
1808
  return checkNewTargetMetaProperty(c, node);
1707
- // `import.defer` is only valid as a callee.
1708
- if (meta.name.text === 'defer')
1809
+ // `import.defer` and `import.source` are only valid as callees.
1810
+ if (isImportPhaseMetaProperty(node))
1709
1811
  return c.errorType;
1710
1812
  const moduleKind = getEmitModuleKind(c.compilerOptions);
1711
1813
  if (moduleKind >= ModuleKind.Node16 && moduleKind <= ModuleKind.NodeNext) {
1712
1814
  if (c.host.getImpliedNodeFormatForEmit(getSourceFileOfNode(node)) === ModuleKind.CommonJS)
1713
- c.error(node, 385 /* Diagnostics.The_import_meta_meta_property_is_not_allowed_in_files_which_will_build_into_CommonJS_output */);
1815
+ c.error(node, 383 /* Diagnostics.The_import_meta_meta_property_is_not_allowed_in_files_which_will_build_into_CommonJS_output */);
1714
1816
  }
1715
1817
  else if (moduleKind < ModuleKind.ES2020 && moduleKind !== ModuleKind.System)
1716
1818
  c.error(node, 277 /* Diagnostics.The_import_meta_meta_property_is_only_allowed_when_the_module_option_is_es2020_es2022_esnext_system_node16_node18_node20_or_nodenext */);
@@ -1718,13 +1820,13 @@ export function checkMetaProperty(c, node) {
1718
1820
  }
1719
1821
  export function checkNewTargetMetaProperty(c, node) {
1720
1822
  const container = getThisContainer(node, false, false);
1721
- if (container.kind !== 177 /* SyntaxKind.Constructor */ &&
1722
- container.kind !== 263 /* SyntaxKind.FunctionDeclaration */ &&
1723
- container.kind !== 219 /* SyntaxKind.FunctionExpression */) {
1724
- c.error(node, 1816 /* Diagnostics.Meta_property_0_is_only_allowed_in_the_body_of_a_function_declaration_function_expression_or_constructor */, 'new.target');
1823
+ if (container.kind !== 178 /* SyntaxKind.Constructor */ &&
1824
+ container.kind !== 264 /* SyntaxKind.FunctionDeclaration */ &&
1825
+ container.kind !== 220 /* SyntaxKind.FunctionExpression */) {
1826
+ c.error(node, 1836 /* Diagnostics.Meta_property_0_is_only_allowed_in_the_body_of_a_function_declaration_function_expression_or_constructor */, 'new.target');
1725
1827
  return c.errorType;
1726
1828
  }
1727
- const symbol = getSymbolOfDeclaration(c, container.kind === 177 /* SyntaxKind.Constructor */ ? container.parent : container);
1829
+ const symbol = getSymbolOfDeclaration(c, container.kind === 178 /* SyntaxKind.Constructor */ ? container.parent : container);
1728
1830
  return symbol !== undefined ? getTypeOfSymbol(c, symbol) : c.errorType;
1729
1831
  }
1730
1832
  // ---- Import and export declarations
@@ -1737,14 +1839,14 @@ function isValidExternalImportOrExportDeclaration(node) {
1737
1839
  if (moduleName === undefined || nodeIsMissing(moduleName) || moduleName.kind !== 10 /* SyntaxKind.StringLiteral */)
1738
1840
  return false;
1739
1841
  const parent = node.parent;
1740
- const inAmbientExternalModule = parent.kind === 269 /* SyntaxKind.ModuleBlock */ && isAmbientModule(parent.parent);
1741
- if (parent.kind !== 307 /* SyntaxKind.SourceFile */ && !inAmbientExternalModule)
1842
+ const inAmbientExternalModule = parent.kind === 270 /* SyntaxKind.ModuleBlock */ && isAmbientModule(parent.parent);
1843
+ if (parent.kind !== 308 /* SyntaxKind.SourceFile */ && !inAmbientExternalModule)
1742
1844
  return false;
1743
1845
  if (inAmbientExternalModule &&
1744
1846
  isExternalModuleNameRelative(getText(moduleName)) &&
1745
1847
  !isModuleAugmentationExternal(parent.parent))
1746
1848
  return false;
1747
- if (node.kind === 272 /* SyntaxKind.ImportEqualsDeclaration */)
1849
+ if (node.kind === 273 /* SyntaxKind.ImportEqualsDeclaration */)
1748
1850
  return true;
1749
1851
  const attributes = getImportAttributes(node);
1750
1852
  if (attributes === undefined)
@@ -1754,14 +1856,33 @@ function isValidExternalImportOrExportDeclaration(node) {
1754
1856
  return false;
1755
1857
  return true;
1756
1858
  }
1859
+ /**
1860
+ * Resolves the module an import or export in an illegal context names, when that context is still
1861
+ * in a file's global scope (a block), to report a missing module. A side-effect import isn't resolved.
1862
+ */
1863
+ function checkExternalModuleNameInGlobalScope(c, node) {
1864
+ let container = node.parent;
1865
+ while (container !== undefined && (getContainerFlags(container) & 1 /* ContainerFlags.IsContainer */) === 0)
1866
+ container = container.parent;
1867
+ if (container === undefined || container.kind !== 308 /* SyntaxKind.SourceFile */)
1868
+ return;
1869
+ if ((node.kind === 274 /* SyntaxKind.ImportDeclaration */ || node.kind === 347 /* SyntaxKind.JSImportDeclaration */) &&
1870
+ node.importClause === undefined)
1871
+ return;
1872
+ const moduleName = getExternalModuleName(node);
1873
+ if (moduleName !== undefined)
1874
+ resolveExternalModuleName(c, node, moduleName, false, getTypeFromImportAttributes(c, getImportAttributes(node)));
1875
+ }
1757
1876
  function isInModuleElementContext(node) {
1758
1877
  const parent = node.parent.kind;
1759
- return (parent === 307 /* SyntaxKind.SourceFile */ || parent === 269 /* SyntaxKind.ModuleBlock */ || parent === 268 /* SyntaxKind.ModuleDeclaration */);
1878
+ return (parent === 308 /* SyntaxKind.SourceFile */ || parent === 270 /* SyntaxKind.ModuleBlock */ || parent === 269 /* SyntaxKind.ModuleDeclaration */);
1760
1879
  }
1761
1880
  function getImportAttributes(node) {
1762
- if (node.kind === 273 /* SyntaxKind.ImportDeclaration */ || node.kind === 346 /* SyntaxKind.JSImportDeclaration */)
1881
+ if (node.kind === 274 /* SyntaxKind.ImportDeclaration */ || node.kind === 347 /* SyntaxKind.JSImportDeclaration */)
1882
+ return node.attributes;
1883
+ if (node.kind === 280 /* SyntaxKind.ExportDeclaration */)
1763
1884
  return node.attributes;
1764
- if (node.kind === 279 /* SyntaxKind.ExportDeclaration */)
1885
+ if (node.kind === 207 /* SyntaxKind.ImportType */)
1765
1886
  return node.attributes;
1766
1887
  return undefined;
1767
1888
  }
@@ -1771,7 +1892,7 @@ function hasImportClauseGrammarError(c, node) {
1771
1892
  if (node.phaseModifier === 156 /* SyntaxKind.TypeKeyword */) {
1772
1893
  if ((node.flags & 4194304 /* NodeFlags.JSDoc */) === 0 && node.name !== undefined && namedBindings !== undefined)
1773
1894
  return !hasParseErrors(node);
1774
- if (namedBindings !== undefined && namedBindings.kind === 276 /* SyntaxKind.NamedImports */)
1895
+ if (namedBindings !== undefined && namedBindings.kind === 277 /* SyntaxKind.NamedImports */)
1775
1896
  for (const specifier of namedBindings.elements.nodes)
1776
1897
  if (getIsTypeOnly(specifier))
1777
1898
  return !hasParseErrors(node);
@@ -1779,7 +1900,7 @@ function hasImportClauseGrammarError(c, node) {
1779
1900
  else if (node.phaseModifier === 166 /* SyntaxKind.DeferKeyword */) {
1780
1901
  if (node.name !== undefined)
1781
1902
  return !hasParseErrors(node);
1782
- if (namedBindings !== undefined && namedBindings.kind === 276 /* SyntaxKind.NamedImports */)
1903
+ if (namedBindings !== undefined && namedBindings.kind === 277 /* SyntaxKind.NamedImports */)
1783
1904
  return !hasParseErrors(node);
1784
1905
  const moduleKind = getEmitModuleKind(c.compilerOptions);
1785
1906
  if (moduleKind !== ModuleKind.ESNext && moduleKind !== ModuleKind.Preserve)
@@ -1791,6 +1912,8 @@ function hasParseErrors(node) {
1791
1912
  return getSourceFileOfNode(node).diagnostics.length > 0;
1792
1913
  }
1793
1914
  export function checkImportDeclaration(c, node) {
1915
+ if (!isInModuleElementContext(node))
1916
+ checkExternalModuleNameInGlobalScope(c, node);
1794
1917
  if (!isInModuleElementContext(node) || !isValidExternalImportOrExportDeclaration(node)) {
1795
1918
  checkImportAttributes(c, node);
1796
1919
  return;
@@ -1805,7 +1928,7 @@ export function checkImportDeclaration(c, node) {
1805
1928
  const emittedAsCommonJS = c.host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) === ModuleKind.CommonJS;
1806
1929
  let needsImportStar = false;
1807
1930
  if (namedBindings !== undefined) {
1808
- if (namedBindings.kind === 275 /* SyntaxKind.NamespaceImport */) {
1931
+ if (namedBindings.kind === 276 /* SyntaxKind.NamespaceImport */) {
1809
1932
  checkImportBinding(c, namedBindings);
1810
1933
  if (emittedAsCommonJS) {
1811
1934
  needsImportStar = true;
@@ -1813,7 +1936,7 @@ export function checkImportDeclaration(c, node) {
1813
1936
  }
1814
1937
  }
1815
1938
  else {
1816
- resolvedModule = resolveExternalModuleName(c, node, declaration.moduleSpecifier, false);
1939
+ resolvedModule = resolveExternalModuleName(c, node, declaration.moduleSpecifier, false, getTypeFromImportAttributes(c, declaration.attributes));
1817
1940
  if (resolvedModule !== undefined)
1818
1941
  for (const binding of namedBindings.elements.nodes)
1819
1942
  checkImportBinding(c, binding);
@@ -1825,12 +1948,12 @@ export function checkImportDeclaration(c, node) {
1825
1948
  if (!isTypeOnly(clause) &&
1826
1949
  moduleKind >= ModuleKind.Node18 &&
1827
1950
  moduleKind <= ModuleKind.NodeNext &&
1828
- isOnlyImportableAsDefault(c, declaration.moduleSpecifier, resolvedModule) &&
1951
+ isOnlyImportableAsDefault(c, declaration.moduleSpecifier, resolvedModule, getTypeFromImportAttributes(c, declaration.attributes)) &&
1829
1952
  !hasTypeJsonImportAttribute(declaration))
1830
- c.error(declaration.moduleSpecifier, 458 /* Diagnostics.Importing_a_JSON_file_into_an_ECMAScript_module_requires_a_type_Colon_json_import_attribute_when_module_is_set_to_0 */, moduleKindName(moduleKind));
1953
+ c.error(declaration.moduleSpecifier, 456 /* Diagnostics.Importing_a_JSON_file_into_an_ECMAScript_module_requires_a_type_Colon_json_import_attribute_when_module_is_set_to_0 */, moduleKindName(moduleKind));
1831
1954
  }
1832
1955
  else if (clause === undefined && c.compilerOptions.noUncheckedSideEffectImports !== false)
1833
- resolveExternalModuleNameWorker(c, node, declaration.moduleSpecifier, 1002 /* Diagnostics.Cannot_find_module_or_type_declarations_for_side_effect_import_of_0 */, false, false);
1956
+ resolveExternalModuleNameWorker(c, node, declaration.moduleSpecifier, 1009 /* Diagnostics.Cannot_find_module_or_type_declarations_for_side_effect_import_of_0 */, false, false, getTypeFromImportAttributes(c, declaration.attributes));
1834
1957
  checkImportAttributes(c, node);
1835
1958
  }
1836
1959
  function hasTypeJsonImportAttribute(node) {
@@ -1847,28 +1970,57 @@ function hasTypeJsonImportAttribute(node) {
1847
1970
  function checkImportBinding(c, node) {
1848
1971
  checkCollisionsForDeclarationName(c, node, getName(node));
1849
1972
  checkAliasSymbol(c, node);
1850
- if (node.kind === 277 /* SyntaxKind.ImportSpecifier */ &&
1973
+ if (node.kind === 278 /* SyntaxKind.ImportSpecifier */ &&
1851
1974
  moduleExportNameIsDefault(getPropertyNameOrName(node)) &&
1852
1975
  c.host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) === ModuleKind.CommonJS)
1853
1976
  checkExternalEmitHelpers(c, node, 2048 /* ExternalEmitHelpers.ImportDefault */);
1854
1977
  }
1855
1978
  /** Import attributes must be assignable to the global `ImportAttributes`. */
1856
- function checkImportAttributes(c, declaration) {
1979
+ export function checkImportAttributes(c, declaration) {
1857
1980
  const node = getImportAttributes(declaration);
1858
1981
  if (node === undefined)
1859
1982
  return;
1860
1983
  const importAttributesType = getCachedGlobalType(c, 'ImportAttributes', 0, true);
1861
1984
  if (importAttributesType !== c.emptyObjectType)
1862
- checkTypeAssignableTo(c, getTypeFromImportAttributes(c, node), getNullableType(c, importAttributesType, 4 /* TypeFlags.Undefined */), node, undefined);
1985
+ checkTypeAssignableTo(c, checkImportAttributesExpression(c, node), getNullableType(c, importAttributesType, 4 /* TypeFlags.Undefined */), node, undefined);
1863
1986
  }
1987
+ /** The type of import attributes, which resolution matches against the attributes types of pattern ambient modules. */
1864
1988
  function getTypeFromImportAttributes(c, node) {
1989
+ if (node === undefined)
1990
+ return undefined;
1991
+ if (node.kind === 302 /* SyntaxKind.ImportAttributes */)
1992
+ return checkImportAttributesExpression(c, node);
1993
+ return checkExpressionCached(c, node);
1994
+ }
1995
+ /** The import attributes type of the declaration `node` is the module specifier of. */
1996
+ export function getImportAttributesTypeForModuleSpecifier(c, moduleSpecifier) {
1997
+ const parent = moduleSpecifier.parent;
1998
+ switch (parent.kind) {
1999
+ case 274 /* SyntaxKind.ImportDeclaration */:
2000
+ case 347 /* SyntaxKind.JSImportDeclaration */:
2001
+ case 280 /* SyntaxKind.ExportDeclaration */:
2002
+ return getTypeFromImportAttributes(c, getImportAttributes(parent));
2003
+ case 203 /* SyntaxKind.LiteralType */:
2004
+ if (parent.parent.kind === 207 /* SyntaxKind.ImportType */)
2005
+ return getTypeFromImportAttributes(c, parent.parent.attributes);
2006
+ return undefined;
2007
+ case 215 /* SyntaxKind.CallExpression */: {
2008
+ const args = parent.arguments.nodes;
2009
+ if (isImportCall(parent) && args.length > 1)
2010
+ return getTypeOfPropertyOfType(c, checkExpressionCached(c, args[1]), 'with');
2011
+ return undefined;
2012
+ }
2013
+ }
2014
+ return undefined;
2015
+ }
2016
+ export function checkImportAttributesExpression(c, node) {
1865
2017
  if (c.resolvedTypes.get(node.id) === undefined) {
1866
2018
  const symbol = c.newSymbol(4096 /* SymbolFlags.ObjectLiteral */, "\uFFFEimportAttributes" /* InternalSymbolName.ImportAttributes */);
1867
2019
  const members = new Map();
1868
2020
  for (const attribute of node.attributes.nodes) {
1869
2021
  const name = getText(attribute.name);
1870
2022
  const member = c.newSymbol(4 /* SymbolFlags.Property */, name);
1871
- c.symbolTypes.set(getSymbolId(member), getRegularTypeOfLiteralType(c, checkExpression(c, attribute.value)));
2023
+ c.symbolTypes.set(getSymbolId(member), getRegularTypeOfLiteralType(c, checkExpressionCached(c, attribute.value)));
1872
2024
  members.set(name, member);
1873
2025
  }
1874
2026
  const type = createAnonymousType(c, symbol, members, [], [], []);
@@ -1878,11 +2030,13 @@ function getTypeFromImportAttributes(c, node) {
1878
2030
  return c.resolvedTypes.get(node.id);
1879
2031
  }
1880
2032
  export function checkImportEqualsDeclaration(c, node) {
1881
- if (!isInModuleElementContext(node))
2033
+ if (!isInModuleElementContext(node)) {
2034
+ checkExternalModuleNameInGlobalScope(c, node);
1882
2035
  return;
2036
+ }
1883
2037
  const declaration = node;
1884
2038
  const reference = declaration.moduleReference;
1885
- const isExternal = reference.kind === 284 /* SyntaxKind.ExternalModuleReference */;
2039
+ const isExternal = reference.kind === 285 /* SyntaxKind.ExternalModuleReference */;
1886
2040
  if (shouldCheckErasableSyntax(c, node) && (node.flags & 8388608 /* NodeFlags.Ambient */) === 0)
1887
2041
  c.error(node, 243 /* Diagnostics.This_syntax_is_not_allowed_when_erasableSyntaxOnly_is_enabled */);
1888
2042
  if (isExternal && !isValidExternalImportOrExportDeclaration(node))
@@ -1901,14 +2055,14 @@ export function checkImportEqualsDeclaration(c, node) {
1901
2055
  const moduleName = getFirstIdentifierOfEntityName(reference);
1902
2056
  const resolved = resolveEntityName(c, moduleName, 111551 /* SymbolFlags.Value */ | 1920 /* SymbolFlags.Namespace */, false, false, undefined);
1903
2057
  if (resolved !== undefined && (resolved.flags & 1920 /* SymbolFlags.Namespace */) === 0)
1904
- c.error(moduleName, 605 /* Diagnostics.Module_0_is_hidden_by_a_local_declaration_with_the_same_name */, declarationNameToString(getSourceFileOfNode(moduleName), moduleName));
2058
+ c.error(moduleName, 612 /* Diagnostics.Module_0_is_hidden_by_a_local_declaration_with_the_same_name */, declarationNameToString(getSourceFileOfNode(moduleName), moduleName));
1905
2059
  }
1906
2060
  if ((targetFlags & 788968 /* SymbolFlags.Type */) !== 0)
1907
- checkTypeNameIsReserved(c, declaration.name, 606 /* Diagnostics.Import_name_cannot_be_0 */);
2061
+ checkTypeNameIsReserved(c, declaration.name, 613 /* Diagnostics.Import_name_cannot_be_0 */);
1908
2062
  }
1909
2063
  function getFirstIdentifierOfEntityName(node) {
1910
2064
  let current = node;
1911
- while (current.kind === 167 /* SyntaxKind.QualifiedName */)
2065
+ while (current.kind === 168 /* SyntaxKind.QualifiedName */)
1912
2066
  current = current.left;
1913
2067
  return current;
1914
2068
  }
@@ -1919,22 +2073,24 @@ function checkNamespaceExportName(c, name) {
1919
2073
  const moduleKind = getEmitModuleKind(c.compilerOptions);
1920
2074
  if ((moduleKind === ModuleKind.ES2015 || moduleKind === ModuleKind.ES2020) &&
1921
2075
  !getSourceFileOfNode(name).isDeclarationFile)
1922
- grammarErrorOnNode(c, name, 1872 /* Diagnostics.String_literal_import_and_export_names_are_not_supported_when_the_module_flag_is_set_to_es2015_or_es2020 */);
2076
+ grammarErrorOnNode(c, name, 1892 /* Diagnostics.String_literal_import_and_export_names_are_not_supported_when_the_module_flag_is_set_to_es2015_or_es2020 */);
1923
2077
  }
1924
2078
  export function checkExportDeclaration(c, node) {
1925
- if (!isInModuleElementContext(node))
2079
+ if (!isInModuleElementContext(node)) {
2080
+ checkExternalModuleNameInGlobalScope(c, node);
1926
2081
  return;
2082
+ }
1927
2083
  const declaration = node;
1928
2084
  if (declaration.moduleSpecifier === undefined || isValidExternalImportOrExportDeclaration(node)) {
1929
2085
  const clause = declaration.exportClause;
1930
- if (clause !== undefined && clause.kind === 280 /* SyntaxKind.NamedExports */) {
2086
+ if (clause !== undefined && clause.kind === 281 /* SyntaxKind.NamedExports */) {
1931
2087
  for (const specifier of clause.elements.nodes)
1932
2088
  checkExportSpecifier(c, specifier);
1933
2089
  }
1934
2090
  else {
1935
- const moduleSymbol = resolveExternalModuleName(c, node, declaration.moduleSpecifier, false);
2091
+ const moduleSymbol = resolveExternalModuleName(c, node, declaration.moduleSpecifier, false, getTypeFromImportAttributes(c, declaration.attributes));
1936
2092
  if (moduleSymbol !== undefined && hasExportAssignmentSymbol(moduleSymbol))
1937
- c.error(declaration.moduleSpecifier, 658 /* Diagnostics.Module_0_uses_export_and_cannot_be_used_with_export_Asterisk */, symbolToString(c, moduleSymbol));
2093
+ c.error(declaration.moduleSpecifier, 665 /* Diagnostics.Module_0_uses_export_and_cannot_be_used_with_export_Asterisk */, symbolToString(c, moduleSymbol));
1938
2094
  else if (clause !== undefined) {
1939
2095
  checkAliasSymbol(c, clause);
1940
2096
  checkNamespaceExportName(c, getName(clause));
@@ -1963,7 +2119,7 @@ function checkExportSpecifier(c, node) {
1963
2119
  (symbol === c.undefinedSymbol ||
1964
2120
  symbol === c.globalThisSymbol ||
1965
2121
  (declarationCount(symbol) > 0 && isGlobalSourceFile(getDeclarationContainer(symbol.declaration)))))
1966
- c.error(exportedName, 795 /* Diagnostics.Cannot_export_0_Only_local_declarations_can_be_exported_from_a_module */, getText(exportedName));
2122
+ c.error(exportedName, 802 /* Diagnostics.Cannot_export_0_Only_local_declarations_can_be_exported_from_a_module */, getText(exportedName));
1967
2123
  else
1968
2124
  markExportSpecifierAliasReferenced(c, node, symbol, exportedName);
1969
2125
  }
@@ -1974,12 +2130,12 @@ export function getDeclarationContainer(node) {
1974
2130
  if (parent === undefined)
1975
2131
  return current;
1976
2132
  switch (current.kind) {
1977
- case 261 /* SyntaxKind.VariableDeclaration */:
1978
- case 262 /* SyntaxKind.VariableDeclarationList */:
1979
- case 277 /* SyntaxKind.ImportSpecifier */:
1980
- case 276 /* SyntaxKind.NamedImports */:
1981
- case 275 /* SyntaxKind.NamespaceImport */:
1982
- case 274 /* SyntaxKind.ImportClause */:
2133
+ case 262 /* SyntaxKind.VariableDeclaration */:
2134
+ case 263 /* SyntaxKind.VariableDeclarationList */:
2135
+ case 278 /* SyntaxKind.ImportSpecifier */:
2136
+ case 277 /* SyntaxKind.NamedImports */:
2137
+ case 276 /* SyntaxKind.NamespaceImport */:
2138
+ case 275 /* SyntaxKind.ImportClause */:
1983
2139
  current = parent;
1984
2140
  continue;
1985
2141
  }
@@ -1987,17 +2143,24 @@ export function getDeclarationContainer(node) {
1987
2143
  }
1988
2144
  }
1989
2145
  /** `export = e` and `export default e`; the grammar checker reports misplaced ones. */
2146
+ /** Whether an export assignment is in a namespace, rather than a file or an ambient module. */
2147
+ function isContainedByNamespace(node) {
2148
+ const container = node.parent.kind === 308 /* SyntaxKind.SourceFile */ ? node.parent : node.parent.parent;
2149
+ return container.kind === 269 /* SyntaxKind.ModuleDeclaration */ && !isAmbientModule(container);
2150
+ }
1990
2151
  export function checkExportAssignment(c, node) {
2152
+ const declaration = node;
2153
+ // The expression is checked also where an export assignment is a grammar error.
2154
+ const exprType = checkExpressionCached(c, declaration.expression);
1991
2155
  if (!isInModuleElementContext(node))
1992
2156
  return;
1993
- const declaration = node;
1994
2157
  const isExportEquals = declaration.isExportEquals;
1995
2158
  const ambient = (node.flags & 8388608 /* NodeFlags.Ambient */) !== 0;
1996
2159
  if (shouldCheckErasableSyntax(c, node) && isExportEquals && !ambient)
1997
2160
  c.error(node, 243 /* Diagnostics.This_syntax_is_not_allowed_when_erasableSyntaxOnly_is_enabled */);
1998
- const container = node.parent.kind === 307 /* SyntaxKind.SourceFile */ ? node.parent : node.parent.parent;
1999
- if (container.kind === 268 /* SyntaxKind.ModuleDeclaration */ && !isAmbientModule(container))
2161
+ if (isContainedByNamespace(node))
2000
2162
  return;
2163
+ const container = node.parent.kind === 308 /* SyntaxKind.SourceFile */ ? node.parent : node.parent.parent;
2001
2164
  const verbatimModuleSyntax = c.compilerOptions.verbatimModuleSyntax === true;
2002
2165
  const isIllegalExportDefaultInCJS = !isExportEquals &&
2003
2166
  !ambient &&
@@ -2015,7 +2178,6 @@ export function checkExportAssignment(c, node) {
2015
2178
  const name = getText(id);
2016
2179
  // A non-value is exported as a type, like `export { Id as default }`.
2017
2180
  if ((getSymbolFlags(c, sym) & 111551 /* SymbolFlags.Value */) !== 0) {
2018
- checkExpressionCached(c, id);
2019
2181
  if (!isIllegalExportDefaultInCJS && !ambient && verbatimModuleSyntax && typeOnlyDeclaration !== undefined)
2020
2182
  c.error(id, isExportEquals
2021
2183
  ? 232 /* Diagnostics.An_export_declaration_must_reference_a_real_value_when_verbatimModuleSyntax_is_enabled_but_0_resolves_to_a_type_only_declaration */
@@ -2028,11 +2190,7 @@ export function checkExportAssignment(c, node) {
2028
2190
  if (!isIllegalExportDefaultInCJS && !ambient && c.isolatedModules && (sym.flags & 111551 /* SymbolFlags.Value */) === 0)
2029
2191
  checkIsolatedModulesExportAssignment(c, node, sym, typeOnlyDeclaration, isExportEquals);
2030
2192
  }
2031
- else
2032
- checkExpressionCached(c, id);
2033
2193
  }
2034
- else
2035
- checkExpressionCached(c, expression);
2036
2194
  if (isIllegalExportDefaultInCJS)
2037
2195
  c.error(node, verbatimModuleSyntaxErrorMessage(node));
2038
2196
  checkExternalModuleExports(c, container);
@@ -2040,7 +2198,7 @@ export function checkExportAssignment(c, node) {
2040
2198
  const typeNode = getType(node);
2041
2199
  if (typeNode !== undefined) {
2042
2200
  const expr = getExpression(node);
2043
- checkTypeAssignableToAndOptionallyElaborate(c, checkExpressionCached(c, expr), getTypeFromTypeNode(c, typeNode), expr, expr);
2201
+ checkTypeAssignableToAndOptionallyElaborate(c, exprType, getTypeFromTypeNode(c, typeNode), expr, expr);
2044
2202
  }
2045
2203
  }
2046
2204
  function checkIsolatedModulesExportAssignment(c, node, sym, typeOnlyDeclaration, isExportEquals) {
@@ -2080,36 +2238,36 @@ export function checkAliasSymbol(c, node) {
2080
2238
  ((symbol.flags & 788968 /* SymbolFlags.Type */) !== 0 ? 788968 /* SymbolFlags.Type */ : 0) |
2081
2239
  ((symbol.flags & 1920 /* SymbolFlags.Namespace */) !== 0 ? 1920 /* SymbolFlags.Namespace */ : 0);
2082
2240
  if ((targetFlags & excludedMeanings) !== 0)
2083
- c.error(node, node.kind === 282 /* SyntaxKind.ExportSpecifier */
2084
- ? 646 /* Diagnostics.Export_declaration_conflicts_with_exported_declaration_of_0 */
2085
- : 608 /* Diagnostics.Import_declaration_conflicts_with_local_declaration_of_0 */, symbolToString(c, symbol));
2086
- else if (node.kind !== 282 /* SyntaxKind.ExportSpecifier */ &&
2241
+ c.error(node, node.kind === 283 /* SyntaxKind.ExportSpecifier */
2242
+ ? 653 /* Diagnostics.Export_declaration_conflicts_with_exported_declaration_of_0 */
2243
+ : 615 /* Diagnostics.Import_declaration_conflicts_with_local_declaration_of_0 */, symbolToString(c, symbol));
2244
+ else if (node.kind !== 283 /* SyntaxKind.ExportSpecifier */ &&
2087
2245
  c.compilerOptions.isolatedModules === true &&
2088
2246
  !isPartOfTypeOnlyImportOrExportDeclaration(node) &&
2089
2247
  (symbol.flags & (111551 /* SymbolFlags.Value */ | 1048576 /* SymbolFlags.ExportValue */)) !== 0)
2090
2248
  // A transpiler sees a value import that collides with the local value.
2091
- c.error(node, 985 /* Diagnostics.Import_0_conflicts_with_local_value_so_must_be_declared_with_a_type_only_import_when_isolatedModules_is_enabled */, symbolToString(c, symbol), getIsolatedModulesLikeFlagName(c));
2249
+ c.error(node, 992 /* Diagnostics.Import_0_conflicts_with_local_value_so_must_be_declared_with_a_type_only_import_when_isolatedModules_is_enabled */, symbolToString(c, symbol), getIsolatedModulesLikeFlagName(c));
2092
2250
  if (c.isolatedModules && !isTypeOnlyImportOrExportDeclaration(node) && (node.flags & 8388608 /* NodeFlags.Ambient */) === 0)
2093
2251
  checkIsolatedModulesAlias(c, node, symbol, target, targetFlags);
2094
- if (node.kind === 277 /* SyntaxKind.ImportSpecifier */)
2252
+ if (node.kind === 278 /* SyntaxKind.ImportSpecifier */)
2095
2253
  checkDeprecatedImportSpecifier(c, node, symbol);
2096
2254
  }
2097
2255
  function reportJSTypeAlias(c, node, symbol) {
2098
2256
  const errorNode = getPropertyName(node) ?? getName(node) ?? node;
2099
- if (node.kind === 282 /* SyntaxKind.ExportSpecifier */) {
2100
- c.error(errorNode, 1859 /* Diagnostics.Types_cannot_appear_in_export_declarations_in_JavaScript_files */);
2257
+ if (node.kind === 283 /* SyntaxKind.ExportSpecifier */) {
2258
+ c.error(errorNode, 1879 /* Diagnostics.Types_cannot_appear_in_export_declarations_in_JavaScript_files */);
2101
2259
  return;
2102
2260
  }
2103
2261
  const identifierText = errorNode.kind === 79 /* SyntaxKind.Identifier */ ? getText(errorNode) : symbol.name;
2104
2262
  let specifierText = '...';
2105
2263
  let declaration = node;
2106
2264
  while (declaration !== undefined &&
2107
- declaration.kind !== 273 /* SyntaxKind.ImportDeclaration */ &&
2108
- declaration.kind !== 272 /* SyntaxKind.ImportEqualsDeclaration */ &&
2109
- declaration.kind !== 261 /* SyntaxKind.VariableDeclaration */)
2265
+ declaration.kind !== 274 /* SyntaxKind.ImportDeclaration */ &&
2266
+ declaration.kind !== 273 /* SyntaxKind.ImportEqualsDeclaration */ &&
2267
+ declaration.kind !== 262 /* SyntaxKind.VariableDeclaration */)
2110
2268
  declaration = declaration.parent;
2111
2269
  if (declaration !== undefined) {
2112
- const specifier = declaration.kind === 261 /* SyntaxKind.VariableDeclaration */
2270
+ const specifier = declaration.kind === 262 /* SyntaxKind.VariableDeclaration */
2113
2271
  ? isVariableDeclarationInitializedToRequire(declaration)
2114
2272
  ? getInitializer(declaration).arguments.nodes[0]
2115
2273
  : undefined
@@ -2118,9 +2276,9 @@ function reportJSTypeAlias(c, node, symbol) {
2118
2276
  specifierText = getText(specifier);
2119
2277
  }
2120
2278
  let importText = 'import("' + specifierText + '")';
2121
- if (node.kind === 277 /* SyntaxKind.ImportSpecifier */)
2279
+ if (node.kind === 278 /* SyntaxKind.ImportSpecifier */)
2122
2280
  importText += '.' + identifierText;
2123
- c.error(errorNode, 1858 /* Diagnostics.X_0_is_a_type_and_cannot_be_imported_in_JavaScript_files_Use_1_in_a_JSDoc_type_annotation */, identifierText, importText);
2281
+ c.error(errorNode, 1878 /* Diagnostics.X_0_is_a_type_and_cannot_be_imported_in_JavaScript_files_Use_1_in_a_JSDoc_type_annotation */, identifierText, importText);
2124
2282
  }
2125
2283
  function checkIsolatedModulesAlias(c, node, symbol, target, targetFlags) {
2126
2284
  const verbatimModuleSyntax = c.compilerOptions.verbatimModuleSyntax === true;
@@ -2128,26 +2286,26 @@ function checkIsolatedModulesAlias(c, node, symbol, target, targetFlags) {
2128
2286
  const isType = (targetFlags & 111551 /* SymbolFlags.Value */) === 0;
2129
2287
  if (isType || typeOnlyAlias !== undefined) {
2130
2288
  switch (node.kind) {
2131
- case 274 /* SyntaxKind.ImportClause */:
2132
- case 277 /* SyntaxKind.ImportSpecifier */:
2133
- case 272 /* SyntaxKind.ImportEqualsDeclaration */: {
2289
+ case 275 /* SyntaxKind.ImportClause */:
2290
+ case 278 /* SyntaxKind.ImportSpecifier */:
2291
+ case 273 /* SyntaxKind.ImportEqualsDeclaration */: {
2134
2292
  if (verbatimModuleSyntax) {
2135
- const message = node.kind === 272 /* SyntaxKind.ImportEqualsDeclaration */ &&
2136
- node.moduleReference.kind !== 284 /* SyntaxKind.ExternalModuleReference */
2293
+ const message = node.kind === 273 /* SyntaxKind.ImportEqualsDeclaration */ &&
2294
+ node.moduleReference.kind !== 285 /* SyntaxKind.ExternalModuleReference */
2137
2295
  ? 237 /* Diagnostics.An_import_alias_cannot_resolve_to_a_type_or_type_only_declaration_when_verbatimModuleSyntax_is_enabled */
2138
2296
  : isType
2139
- ? 399 /* Diagnostics.X_0_is_a_type_and_must_be_imported_using_a_type_only_import_when_verbatimModuleSyntax_is_enabled */
2140
- : 400 /* Diagnostics.X_0_resolves_to_a_type_only_declaration_and_must_be_imported_using_a_type_only_import_when_verbatimModuleSyntax_is_enabled */;
2297
+ ? 397 /* Diagnostics.X_0_is_a_type_and_must_be_imported_using_a_type_only_import_when_verbatimModuleSyntax_is_enabled */
2298
+ : 398 /* Diagnostics.X_0_resolves_to_a_type_only_declaration_and_must_be_imported_using_a_type_only_import_when_verbatimModuleSyntax_is_enabled */;
2141
2299
  const name = getText(getPropertyNameOrName(node));
2142
2300
  addTypeOnlyDeclarationRelatedInfo(c.error(node, message, name), isType ? undefined : typeOnlyAlias, name);
2143
2301
  }
2144
2302
  if (isType &&
2145
- node.kind === 272 /* SyntaxKind.ImportEqualsDeclaration */ &&
2303
+ node.kind === 273 /* SyntaxKind.ImportEqualsDeclaration */ &&
2146
2304
  hasSyntacticModifier(node, 32 /* ModifierFlags.Export */))
2147
2305
  c.error(node, 218 /* Diagnostics.Cannot_use_export_import_on_a_type_or_type_only_namespace_when_0_is_enabled */, getIsolatedModulesLikeFlagName(c));
2148
2306
  break;
2149
2307
  }
2150
- case 282 /* SyntaxKind.ExportSpecifier */:
2308
+ case 283 /* SyntaxKind.ExportSpecifier */:
2151
2309
  // `import type { A } from './a'; export { A }` is fine: one file shows the export is a type.
2152
2310
  if (verbatimModuleSyntax ||
2153
2311
  typeOnlyAlias === undefined ||
@@ -2162,13 +2320,14 @@ function checkIsolatedModulesAlias(c, node, symbol, target, targetFlags) {
2162
2320
  }
2163
2321
  }
2164
2322
  if (verbatimModuleSyntax &&
2165
- node.kind !== 272 /* SyntaxKind.ImportEqualsDeclaration */ &&
2323
+ node.kind !== 273 /* SyntaxKind.ImportEqualsDeclaration */ &&
2166
2324
  !isInJSFile(node) &&
2167
2325
  c.host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) === ModuleKind.CommonJS)
2168
2326
  c.error(node, verbatimModuleSyntaxErrorMessage(node));
2169
2327
  else if (getEmitModuleKind(c.compilerOptions) === ModuleKind.Preserve &&
2170
- node.kind !== 272 /* SyntaxKind.ImportEqualsDeclaration */ &&
2171
- node.kind !== 261 /* SyntaxKind.VariableDeclaration */ &&
2328
+ node.kind !== 273 /* SyntaxKind.ImportEqualsDeclaration */ &&
2329
+ node.kind !== 262 /* SyntaxKind.VariableDeclaration */ &&
2330
+ node.kind !== 210 /* SyntaxKind.BindingElement */ &&
2172
2331
  c.host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) === ModuleKind.CommonJS)
2173
2332
  // Under `--module preserve` ESM syntax emits as ESM, so it is an error in a file that is CommonJS (.cts, .cjs).
2174
2333
  c.error(node, 242 /* Diagnostics.ECMAScript_module_syntax_is_not_allowed_in_a_CommonJS_module_when_module_is_set_to_preserve */);
@@ -2176,7 +2335,7 @@ function checkIsolatedModulesAlias(c, node, symbol, target, targetFlags) {
2176
2335
  (targetFlags & 128 /* SymbolFlags.ConstEnum */) !== 0 &&
2177
2336
  target.valueDeclaration !== undefined &&
2178
2337
  (target.valueDeclaration.flags & 8388608 /* NodeFlags.Ambient */) !== 0)
2179
- c.error(node, 880 /* Diagnostics.Cannot_access_ambient_const_enums_when_0_is_enabled */, getIsolatedModulesLikeFlagName(c));
2338
+ c.error(node, 887 /* Diagnostics.Cannot_access_ambient_const_enums_when_0_is_enabled */, getIsolatedModulesLikeFlagName(c));
2180
2339
  }
2181
2340
  /** The error for ESM syntax in a CommonJS file under `verbatimModuleSyntax`: shorter in a .cts or .cjs file. */
2182
2341
  function verbatimModuleSyntaxErrorMessage(node) {
@@ -2196,7 +2355,7 @@ export function getIsolatedModulesLikeFlagName(c) {
2196
2355
  /** The file a module declaration or import names. */
2197
2356
  export function getExternalModuleFileFromDeclaration(c, declaration) {
2198
2357
  let specifier = undefined;
2199
- if (declaration.kind === 268 /* SyntaxKind.ModuleDeclaration */) {
2358
+ if (declaration.kind === 269 /* SyntaxKind.ModuleDeclaration */) {
2200
2359
  const name = getName(declaration);
2201
2360
  if (name !== undefined && name.kind === 10 /* SyntaxKind.StringLiteral */)
2202
2361
  specifier = name;
@@ -2205,9 +2364,10 @@ export function getExternalModuleFileFromDeclaration(c, declaration) {
2205
2364
  specifier = getExternalModuleName(declaration);
2206
2365
  if (specifier === undefined)
2207
2366
  return undefined;
2208
- const moduleSymbol = resolveExternalModuleNameWorker(c, specifier, specifier, undefined, false, false);
2367
+ // Used by emit and type printing after checking reported any resolution errors, so it adds none.
2368
+ const moduleSymbol = resolveExternalModuleNameWorker(c, specifier, specifier, undefined, true, false, getTypeFromImportAttributes(c, getImportAttributes(declaration)));
2209
2369
  if (moduleSymbol === undefined)
2210
2370
  return undefined;
2211
- const file = getDeclarationOfKind(moduleSymbol, 307 /* SyntaxKind.SourceFile */);
2371
+ const file = getDeclarationOfKind(moduleSymbol, 308 /* SyntaxKind.SourceFile */);
2212
2372
  return file === undefined ? undefined : file;
2213
2373
  }