tsc-ts 0.0.4 → 0.0.5

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 (584) hide show
  1. package/README.md +33 -1
  2. package/dist/api/compiler/ast-utilities.d.ts +82 -0
  3. package/dist/api/compiler/ast-utilities.js +462 -0
  4. package/dist/api/compiler/ast.d.ts +2350 -0
  5. package/dist/api/compiler/ast.js +11206 -0
  6. package/dist/api/compiler/astnav.d.ts +37 -0
  7. package/dist/api/compiler/astnav.js +767 -0
  8. package/dist/api/compiler/binder-utilities.d.ts +182 -0
  9. package/dist/api/compiler/binder-utilities.js +1240 -0
  10. package/dist/api/compiler/binder.d.ts +33 -0
  11. package/dist/api/compiler/binder.js +2358 -0
  12. package/dist/api/compiler/character-codes.d.ts +161 -0
  13. package/dist/api/compiler/character-codes.js +160 -0
  14. package/dist/api/compiler/checker-calls.d.ts +46 -0
  15. package/dist/api/compiler/checker-calls.js +1640 -0
  16. package/dist/api/compiler/checker-classes.d.ts +30 -0
  17. package/dist/api/compiler/checker-classes.js +582 -0
  18. package/dist/api/compiler/checker-contextual.d.ts +77 -0
  19. package/dist/api/compiler/checker-contextual.js +1136 -0
  20. package/dist/api/compiler/checker-declaration-order.d.ts +12 -0
  21. package/dist/api/compiler/checker-declaration-order.js +356 -0
  22. package/dist/api/compiler/checker-declarations.d.ts +33 -0
  23. package/dist/api/compiler/checker-declarations.js +888 -0
  24. package/dist/api/compiler/checker-declared-types.d.ts +48 -0
  25. package/dist/api/compiler/checker-declared-types.js +787 -0
  26. package/dist/api/compiler/checker-decorators.d.ts +26 -0
  27. package/dist/api/compiler/checker-decorators.js +562 -0
  28. package/dist/api/compiler/checker-deprecation.d.ts +33 -0
  29. package/dist/api/compiler/checker-deprecation.js +315 -0
  30. package/dist/api/compiler/checker-destructuring.d.ts +34 -0
  31. package/dist/api/compiler/checker-destructuring.js +584 -0
  32. package/dist/api/compiler/checker-elaboration.d.ts +15 -0
  33. package/dist/api/compiler/checker-elaboration.js +290 -0
  34. package/dist/api/compiler/checker-emit-helpers.d.ts +58 -0
  35. package/dist/api/compiler/checker-emit-helpers.js +154 -0
  36. package/dist/api/compiler/checker-emit-resolver.d.ts +75 -0
  37. package/dist/api/compiler/checker-emit-resolver.js +579 -0
  38. package/dist/api/compiler/checker-evaluator.d.ts +27 -0
  39. package/dist/api/compiler/checker-evaluator.js +188 -0
  40. package/dist/api/compiler/checker-expressions.d.ts +67 -0
  41. package/dist/api/compiler/checker-expressions.js +1351 -0
  42. package/dist/api/compiler/checker-features.d.ts +6 -0
  43. package/dist/api/compiler/checker-features.js +354 -0
  44. package/dist/api/compiler/checker-flow.d.ts +86 -0
  45. package/dist/api/compiler/checker-flow.js +169 -0
  46. package/dist/api/compiler/checker-functions.d.ts +43 -0
  47. package/dist/api/compiler/checker-functions.js +1002 -0
  48. package/dist/api/compiler/checker-generated-code.d.ts +25 -0
  49. package/dist/api/compiler/checker-generated-code.js +168 -0
  50. package/dist/api/compiler/checker-globals.d.ts +14 -0
  51. package/dist/api/compiler/checker-globals.js +37 -0
  52. package/dist/api/compiler/checker-grammar.d.ts +35 -0
  53. package/dist/api/compiler/checker-grammar.js +2573 -0
  54. package/dist/api/compiler/checker-heritage.d.ts +28 -0
  55. package/dist/api/compiler/checker-heritage.js +900 -0
  56. package/dist/api/compiler/checker-inference.d.ts +179 -0
  57. package/dist/api/compiler/checker-inference.js +2105 -0
  58. package/dist/api/compiler/checker-iteration.d.ts +115 -0
  59. package/dist/api/compiler/checker-iteration.js +857 -0
  60. package/dist/api/compiler/checker-javascript.d.ts +42 -0
  61. package/dist/api/compiler/checker-javascript.js +441 -0
  62. package/dist/api/compiler/checker-jsdoc.d.ts +30 -0
  63. package/dist/api/compiler/checker-jsdoc.js +320 -0
  64. package/dist/api/compiler/checker-jsx.d.ts +94 -0
  65. package/dist/api/compiler/checker-jsx.js +1433 -0
  66. package/dist/api/compiler/checker-literals.d.ts +6 -0
  67. package/dist/api/compiler/checker-literals.js +43 -0
  68. package/dist/api/compiler/checker-members.d.ts +198 -0
  69. package/dist/api/compiler/checker-members.js +2126 -0
  70. package/dist/api/compiler/checker-modules.d.ts +85 -0
  71. package/dist/api/compiler/checker-modules.js +2141 -0
  72. package/dist/api/compiler/checker-narrowing.d.ts +120 -0
  73. package/dist/api/compiler/checker-narrowing.js +2797 -0
  74. package/dist/api/compiler/checker-object-literals.d.ts +14 -0
  75. package/dist/api/compiler/checker-object-literals.js +479 -0
  76. package/dist/api/compiler/checker-operators.d.ts +33 -0
  77. package/dist/api/compiler/checker-operators.js +1040 -0
  78. package/dist/api/compiler/checker-overloads.d.ts +7 -0
  79. package/dist/api/compiler/checker-overloads.js +270 -0
  80. package/dist/api/compiler/checker-property-access.d.ts +34 -0
  81. package/dist/api/compiler/checker-property-access.js +672 -0
  82. package/dist/api/compiler/checker-services.d.ts +49 -0
  83. package/dist/api/compiler/checker-services.js +995 -0
  84. package/dist/api/compiler/checker-signatures.d.ts +55 -0
  85. package/dist/api/compiler/checker-signatures.js +788 -0
  86. package/dist/api/compiler/checker-source-file.d.ts +27 -0
  87. package/dist/api/compiler/checker-source-file.js +619 -0
  88. package/dist/api/compiler/checker-statements.d.ts +18 -0
  89. package/dist/api/compiler/checker-statements.js +226 -0
  90. package/dist/api/compiler/checker-super.d.ts +13 -0
  91. package/dist/api/compiler/checker-super.js +241 -0
  92. package/dist/api/compiler/checker-symbol-types.d.ts +67 -0
  93. package/dist/api/compiler/checker-symbol-types.js +1885 -0
  94. package/dist/api/compiler/checker-symbols.d.ts +181 -0
  95. package/dist/api/compiler/checker-symbols.js +1782 -0
  96. package/dist/api/compiler/checker-type-factory.d.ts +142 -0
  97. package/dist/api/compiler/checker-type-factory.js +2501 -0
  98. package/dist/api/compiler/checker-type-nodes.d.ts +26 -0
  99. package/dist/api/compiler/checker-type-nodes.js +828 -0
  100. package/dist/api/compiler/checker-type-operators.d.ts +109 -0
  101. package/dist/api/compiler/checker-type-operators.js +1842 -0
  102. package/dist/api/compiler/checker-types.d.ts +1027 -0
  103. package/dist/api/compiler/checker-types.js +1697 -0
  104. package/dist/api/compiler/checker-unused.d.ts +19 -0
  105. package/dist/api/compiler/checker-unused.js +524 -0
  106. package/dist/api/compiler/checker-utilities.d.ts +33 -0
  107. package/dist/api/compiler/checker-utilities.js +141 -0
  108. package/dist/api/compiler/checker.d.ts +491 -0
  109. package/dist/api/compiler/checker.js +912 -0
  110. package/dist/api/compiler/command-line.d.ts +32 -0
  111. package/dist/api/compiler/command-line.js +383 -0
  112. package/dist/api/compiler/compile-program.d.ts +118 -0
  113. package/dist/api/compiler/compile-program.js +384 -0
  114. package/dist/api/compiler/diagnostic-locales.d.ts +22 -0
  115. package/dist/api/compiler/diagnostic-locales.js +64 -0
  116. package/dist/api/compiler/diagnostic-messages.d.ts +2166 -0
  117. package/dist/api/compiler/diagnostic-messages.js +184 -0
  118. package/dist/api/compiler/diagnostics.d.ts +167 -0
  119. package/dist/api/compiler/diagnostics.js +820 -0
  120. package/dist/api/compiler/emitter.d.ts +71 -0
  121. package/dist/api/compiler/emitter.js +327 -0
  122. package/dist/api/compiler/file-include.d.ts +117 -0
  123. package/dist/api/compiler/file-include.js +536 -0
  124. package/dist/api/compiler/file-loader.d.ts +261 -0
  125. package/dist/api/compiler/file-loader.js +1257 -0
  126. package/dist/api/compiler/file-system.d.ts +51 -0
  127. package/dist/api/compiler/file-system.js +132 -0
  128. package/dist/api/compiler/flow.d.ts +60 -0
  129. package/dist/api/compiler/flow.js +45 -0
  130. package/dist/api/compiler/instantiation.d.ts +74 -0
  131. package/dist/api/compiler/instantiation.js +799 -0
  132. package/dist/api/compiler/jsdoc.d.ts +75 -0
  133. package/dist/api/compiler/jsdoc.js +1229 -0
  134. package/dist/api/compiler/link-tables.d.ts +36 -0
  135. package/dist/api/compiler/link-tables.js +83 -0
  136. package/dist/api/compiler/locale-data.d.ts +24 -0
  137. package/dist/api/compiler/locale-data.js +183 -0
  138. package/dist/api/compiler/locale.d.ts +4 -0
  139. package/dist/api/compiler/locale.js +317 -0
  140. package/dist/api/compiler/locales/cs-CZ.d.ts +2 -0
  141. package/dist/api/compiler/locales/cs-CZ.js +3 -0
  142. package/dist/api/compiler/locales/de-DE.d.ts +2 -0
  143. package/dist/api/compiler/locales/de-DE.js +3 -0
  144. package/dist/api/compiler/locales/es-ES.d.ts +2 -0
  145. package/dist/api/compiler/locales/es-ES.js +3 -0
  146. package/dist/api/compiler/locales/fr-FR.d.ts +2 -0
  147. package/dist/api/compiler/locales/fr-FR.js +3 -0
  148. package/dist/api/compiler/locales/it-IT.d.ts +2 -0
  149. package/dist/api/compiler/locales/it-IT.js +3 -0
  150. package/dist/api/compiler/locales/ja-JP.d.ts +2 -0
  151. package/dist/api/compiler/locales/ja-JP.js +3 -0
  152. package/dist/api/compiler/locales/ko-KR.d.ts +2 -0
  153. package/dist/api/compiler/locales/ko-KR.js +3 -0
  154. package/dist/api/compiler/locales/pl-PL.d.ts +2 -0
  155. package/dist/api/compiler/locales/pl-PL.js +3 -0
  156. package/dist/api/compiler/locales/pt-BR.d.ts +2 -0
  157. package/dist/api/compiler/locales/pt-BR.js +3 -0
  158. package/dist/api/compiler/locales/ru-RU.d.ts +2 -0
  159. package/dist/api/compiler/locales/ru-RU.js +3 -0
  160. package/dist/api/compiler/locales/tr-TR.d.ts +2 -0
  161. package/dist/api/compiler/locales/tr-TR.js +3 -0
  162. package/dist/api/compiler/locales/zh-CN.d.ts +2 -0
  163. package/dist/api/compiler/locales/zh-CN.js +3 -0
  164. package/dist/api/compiler/locales/zh-TW.d.ts +2 -0
  165. package/dist/api/compiler/locales/zh-TW.js +3 -0
  166. package/dist/api/compiler/module-resolution-types.d.ts +83 -0
  167. package/dist/api/compiler/module-resolution-types.js +176 -0
  168. package/dist/api/compiler/module-resolution.d.ts +71 -0
  169. package/dist/api/compiler/module-resolution.js +1598 -0
  170. package/dist/api/compiler/module-specifiers.d.ts +64 -0
  171. package/dist/api/compiler/module-specifiers.js +1101 -0
  172. package/dist/api/compiler/name-resolver.d.ts +43 -0
  173. package/dist/api/compiler/name-resolver.js +509 -0
  174. package/dist/api/compiler/node-builder-names.d.ts +32 -0
  175. package/dist/api/compiler/node-builder-names.js +854 -0
  176. package/dist/api/compiler/node-builder-pseudo.d.ts +36 -0
  177. package/dist/api/compiler/node-builder-pseudo.js +744 -0
  178. package/dist/api/compiler/node-builder-reuse.d.ts +4 -0
  179. package/dist/api/compiler/node-builder-reuse.js +647 -0
  180. package/dist/api/compiler/node-builder.d.ts +270 -0
  181. package/dist/api/compiler/node-builder.js +2645 -0
  182. package/dist/api/compiler/option-declarations.d.ts +90 -0
  183. package/dist/api/compiler/option-declarations.js +1460 -0
  184. package/dist/api/compiler/options.d.ts +289 -0
  185. package/dist/api/compiler/options.js +1197 -0
  186. package/dist/api/compiler/output-paths.d.ts +42 -0
  187. package/dist/api/compiler/output-paths.js +195 -0
  188. package/dist/api/compiler/package-json.d.ts +175 -0
  189. package/dist/api/compiler/package-json.js +1015 -0
  190. package/dist/api/compiler/parallel-parse.d.ts +219 -0
  191. package/dist/api/compiler/parallel-parse.js +537 -0
  192. package/dist/api/compiler/parser.d.ts +587 -0
  193. package/dist/api/compiler/parser.js +6407 -0
  194. package/dist/api/compiler/path.d.ts +91 -0
  195. package/dist/api/compiler/path.js +705 -0
  196. package/dist/api/compiler/printer/async-helpers.d.ts +22 -0
  197. package/dist/api/compiler/printer/async-helpers.js +91 -0
  198. package/dist/api/compiler/printer/auto-generate.d.ts +13 -0
  199. package/dist/api/compiler/printer/auto-generate.js +20 -0
  200. package/dist/api/compiler/printer/decorator-helpers.d.ts +24 -0
  201. package/dist/api/compiler/printer/decorator-helpers.js +118 -0
  202. package/dist/api/compiler/printer/emit-context.d.ts +154 -0
  203. package/dist/api/compiler/printer/emit-context.js +576 -0
  204. package/dist/api/compiler/printer/emit-flags.d.ts +60 -0
  205. package/dist/api/compiler/printer/emit-flags.js +2 -0
  206. package/dist/api/compiler/printer/factory-base.d.ts +171 -0
  207. package/dist/api/compiler/printer/factory-base.js +1505 -0
  208. package/dist/api/compiler/printer/factory.d.ts +147 -0
  209. package/dist/api/compiler/printer/factory.js +542 -0
  210. package/dist/api/compiler/printer/helpers.d.ts +27 -0
  211. package/dist/api/compiler/printer/helpers.js +164 -0
  212. package/dist/api/compiler/printer/name-generator.d.ts +41 -0
  213. package/dist/api/compiler/printer/name-generator.js +283 -0
  214. package/dist/api/compiler/printer/printer.d.ts +411 -0
  215. package/dist/api/compiler/printer/printer.js +4517 -0
  216. package/dist/api/compiler/printer/text-writer.d.ts +46 -0
  217. package/dist/api/compiler/printer/text-writer.js +172 -0
  218. package/dist/api/compiler/printer/utilities.d.ts +82 -0
  219. package/dist/api/compiler/printer/utilities.js +817 -0
  220. package/dist/api/compiler/program-checker.d.ts +156 -0
  221. package/dist/api/compiler/program-checker.js +526 -0
  222. package/dist/api/compiler/program-utilities.d.ts +52 -0
  223. package/dist/api/compiler/program-utilities.js +365 -0
  224. package/dist/api/compiler/program.d.ts +180 -0
  225. package/dist/api/compiler/program.js +1011 -0
  226. package/dist/api/compiler/pseudo-bigint.d.ts +5 -0
  227. package/dist/api/compiler/pseudo-bigint.js +61 -0
  228. package/dist/api/compiler/regexp-checker.d.ts +38 -0
  229. package/dist/api/compiler/regexp-checker.js +942 -0
  230. package/dist/api/compiler/relations.d.ts +263 -0
  231. package/dist/api/compiler/relations.js +4002 -0
  232. package/dist/api/compiler/reparser.d.ts +48 -0
  233. package/dist/api/compiler/reparser.js +1323 -0
  234. package/dist/api/compiler/scanner.d.ts +256 -0
  235. package/dist/api/compiler/scanner.js +2853 -0
  236. package/dist/api/compiler/side-state.d.ts +16 -0
  237. package/dist/api/compiler/side-state.js +89 -0
  238. package/dist/api/compiler/sourcemap.d.ts +55 -0
  239. package/dist/api/compiler/sourcemap.js +340 -0
  240. package/dist/api/compiler/spelling.d.ts +14 -0
  241. package/dist/api/compiler/spelling.js +128 -0
  242. package/dist/api/compiler/symbol-accessibility.d.ts +57 -0
  243. package/dist/api/compiler/symbol-accessibility.js +894 -0
  244. package/dist/api/compiler/symbol.d.ts +240 -0
  245. package/dist/api/compiler/symbol.js +228 -0
  246. package/dist/api/compiler/symlinks.d.ts +32 -0
  247. package/dist/api/compiler/symlinks.js +114 -0
  248. package/dist/api/compiler/syntax-kind.d.ts +389 -0
  249. package/dist/api/compiler/syntax-kind.js +2 -0
  250. package/dist/api/compiler/timeline.d.ts +9 -0
  251. package/dist/api/compiler/timeline.js +54 -0
  252. package/dist/api/compiler/transformers/alias-references.d.ts +39 -0
  253. package/dist/api/compiler/transformers/alias-references.js +676 -0
  254. package/dist/api/compiler/transformers/async-utilities.d.ts +51 -0
  255. package/dist/api/compiler/transformers/async-utilities.js +260 -0
  256. package/dist/api/compiler/transformers/async.d.ts +53 -0
  257. package/dist/api/compiler/transformers/async.js +645 -0
  258. package/dist/api/compiler/transformers/class-fields.d.ts +206 -0
  259. package/dist/api/compiler/transformers/class-fields.js +2418 -0
  260. package/dist/api/compiler/transformers/class-utilities.d.ts +46 -0
  261. package/dist/api/compiler/transformers/class-utilities.js +261 -0
  262. package/dist/api/compiler/transformers/commonjs-module.d.ts +103 -0
  263. package/dist/api/compiler/transformers/commonjs-module.js +1180 -0
  264. package/dist/api/compiler/transformers/const-enum-inliner.d.ts +11 -0
  265. package/dist/api/compiler/transformers/const-enum-inliner.js +36 -0
  266. package/dist/api/compiler/transformers/declarations-diagnostics.d.ts +52 -0
  267. package/dist/api/compiler/transformers/declarations-diagnostics.js +538 -0
  268. package/dist/api/compiler/transformers/declarations-pseudo.d.ts +160 -0
  269. package/dist/api/compiler/transformers/declarations-pseudo.js +797 -0
  270. package/dist/api/compiler/transformers/declarations-resolver.d.ts +152 -0
  271. package/dist/api/compiler/transformers/declarations-resolver.js +35 -0
  272. package/dist/api/compiler/transformers/declarations-syntactic.d.ts +119 -0
  273. package/dist/api/compiler/transformers/declarations-syntactic.js +1582 -0
  274. package/dist/api/compiler/transformers/declarations-tracker.d.ts +46 -0
  275. package/dist/api/compiler/transformers/declarations-tracker.js +197 -0
  276. package/dist/api/compiler/transformers/declarations.d.ts +175 -0
  277. package/dist/api/compiler/transformers/declarations.js +2380 -0
  278. package/dist/api/compiler/transformers/decorator-metadata.d.ts +54 -0
  279. package/dist/api/compiler/transformers/decorator-metadata.js +554 -0
  280. package/dist/api/compiler/transformers/decorator-utilities.d.ts +38 -0
  281. package/dist/api/compiler/transformers/decorator-utilities.js +238 -0
  282. package/dist/api/compiler/transformers/destructuring.d.ts +25 -0
  283. package/dist/api/compiler/transformers/destructuring.js +626 -0
  284. package/dist/api/compiler/transformers/downlevel.d.ts +6 -0
  285. package/dist/api/compiler/transformers/downlevel.js +45 -0
  286. package/dist/api/compiler/transformers/emit-resolver.d.ts +61 -0
  287. package/dist/api/compiler/transformers/emit-resolver.js +197 -0
  288. package/dist/api/compiler/transformers/es-decorators.d.ts +118 -0
  289. package/dist/api/compiler/transformers/es-decorators.js +1901 -0
  290. package/dist/api/compiler/transformers/exponentiation.d.ts +11 -0
  291. package/dist/api/compiler/transformers/exponentiation.js +76 -0
  292. package/dist/api/compiler/transformers/external-module-info.d.ts +35 -0
  293. package/dist/api/compiler/transformers/external-module-info.js +351 -0
  294. package/dist/api/compiler/transformers/for-await.d.ts +43 -0
  295. package/dist/api/compiler/transformers/for-await.js +469 -0
  296. package/dist/api/compiler/transformers/import-elision.d.ts +16 -0
  297. package/dist/api/compiler/transformers/import-elision.js +124 -0
  298. package/dist/api/compiler/transformers/jsx-entities.d.ts +1 -0
  299. package/dist/api/compiler/transformers/jsx-entities.js +256 -0
  300. package/dist/api/compiler/transformers/jsx.d.ts +71 -0
  301. package/dist/api/compiler/transformers/jsx.js +700 -0
  302. package/dist/api/compiler/transformers/legacy-decorators.d.ts +56 -0
  303. package/dist/api/compiler/transformers/legacy-decorators.js +564 -0
  304. package/dist/api/compiler/transformers/logical-assignment.d.ts +14 -0
  305. package/dist/api/compiler/transformers/logical-assignment.js +62 -0
  306. package/dist/api/compiler/transformers/module-utilities.d.ts +9 -0
  307. package/dist/api/compiler/transformers/module-utilities.js +36 -0
  308. package/dist/api/compiler/transformers/module.d.ts +49 -0
  309. package/dist/api/compiler/transformers/module.js +296 -0
  310. package/dist/api/compiler/transformers/named-evaluation.d.ts +26 -0
  311. package/dist/api/compiler/transformers/named-evaluation.js +266 -0
  312. package/dist/api/compiler/transformers/nullish-coalescing.d.ts +9 -0
  313. package/dist/api/compiler/transformers/nullish-coalescing.js +26 -0
  314. package/dist/api/compiler/transformers/object-rest-spread.d.ts +34 -0
  315. package/dist/api/compiler/transformers/object-rest-spread.js +411 -0
  316. package/dist/api/compiler/transformers/optional-catch.d.ts +9 -0
  317. package/dist/api/compiler/transformers/optional-catch.js +20 -0
  318. package/dist/api/compiler/transformers/optional-chain.d.ts +14 -0
  319. package/dist/api/compiler/transformers/optional-chain.js +188 -0
  320. package/dist/api/compiler/transformers/reference-resolver.d.ts +128 -0
  321. package/dist/api/compiler/transformers/reference-resolver.js +1155 -0
  322. package/dist/api/compiler/transformers/runtime-syntax.d.ts +71 -0
  323. package/dist/api/compiler/transformers/runtime-syntax.js +753 -0
  324. package/dist/api/compiler/transformers/subtree-facts.d.ts +9 -0
  325. package/dist/api/compiler/transformers/subtree-facts.js +203 -0
  326. package/dist/api/compiler/transformers/syntax-facts.d.ts +51 -0
  327. package/dist/api/compiler/transformers/syntax-facts.js +254 -0
  328. package/dist/api/compiler/transformers/tagged-template.d.ts +17 -0
  329. package/dist/api/compiler/transformers/tagged-template.js +148 -0
  330. package/dist/api/compiler/transformers/transformer.d.ts +17 -0
  331. package/dist/api/compiler/transformers/transformer.js +54 -0
  332. package/dist/api/compiler/transformers/type-eraser.d.ts +21 -0
  333. package/dist/api/compiler/transformers/type-eraser.js +346 -0
  334. package/dist/api/compiler/transformers/type-serialization.d.ts +20 -0
  335. package/dist/api/compiler/transformers/type-serialization.js +347 -0
  336. package/dist/api/compiler/transformers/using.d.ts +56 -0
  337. package/dist/api/compiler/transformers/using.js +453 -0
  338. package/dist/api/compiler/transformers/utilities.d.ts +50 -0
  339. package/dist/api/compiler/transformers/utilities.js +347 -0
  340. package/dist/api/compiler/transformers/visitor-base.d.ts +6 -0
  341. package/dist/api/compiler/transformers/visitor-base.js +817 -0
  342. package/dist/api/compiler/transformers/visitor-hooks.d.ts +29 -0
  343. package/dist/api/compiler/transformers/visitor-hooks.js +189 -0
  344. package/dist/api/compiler/tsconfig.d.ts +177 -0
  345. package/dist/api/compiler/tsconfig.js +1311 -0
  346. package/dist/api/compiler/type-printer.d.ts +15 -0
  347. package/dist/api/compiler/type-printer.js +74 -0
  348. package/dist/api/compiler/types.d.ts +87 -0
  349. package/dist/api/compiler/types.js +23 -0
  350. package/dist/api/compiler/unicode-identifiers.d.ts +2 -0
  351. package/dist/api/compiler/unicode-identifiers.js +209 -0
  352. package/dist/api/compiler/unicode-properties.d.ts +8 -0
  353. package/dist/api/compiler/unicode-properties.js +531 -0
  354. package/dist/api/compiler/vfs-match.d.ts +24 -0
  355. package/dist/api/compiler/vfs-match.js +587 -0
  356. package/dist/api/library/ast.d.ts +3 -2
  357. package/dist/api/library/ast.generated.d.ts +127 -139
  358. package/dist/api/library/checker.d.ts +51 -0
  359. package/dist/api/library/checker.js +318 -0
  360. package/dist/api/library/diagnostics.d.ts +13 -0
  361. package/dist/api/library/diagnostics.js +50 -0
  362. package/dist/api/library/disk.d.ts +13 -0
  363. package/dist/api/library/disk.js +66 -0
  364. package/dist/api/library/errors.d.ts +13 -0
  365. package/dist/api/library/errors.js +24 -0
  366. package/dist/api/library/host.d.ts +24 -0
  367. package/dist/api/library/host.js +52 -0
  368. package/dist/api/library/index.d.ts +5 -1
  369. package/dist/api/library/index.js +4 -0
  370. package/dist/api/library/nodes.d.ts +51 -0
  371. package/dist/api/library/nodes.js +196 -0
  372. package/dist/api/library/options.d.ts +144 -0
  373. package/dist/api/library/options.js +308 -0
  374. package/dist/api/library/parse.d.ts +19 -0
  375. package/dist/api/library/parse.js +41 -0
  376. package/dist/api/library/program.d.ts +21 -0
  377. package/dist/api/library/program.js +234 -0
  378. package/dist/api/library/types.d.ts +14 -1
  379. package/package.json +12 -8
  380. package/src/compiler/ast-utilities.ts +548 -0
  381. package/src/compiler/ast.ts +12862 -0
  382. package/src/compiler/astnav.ts +799 -0
  383. package/src/compiler/binder-utilities.ts +1392 -0
  384. package/src/compiler/binder.ts +2703 -0
  385. package/src/compiler/build-info.ts +1197 -0
  386. package/src/compiler/character-codes.ts +323 -0
  387. package/src/compiler/checker-calls.ts +2155 -0
  388. package/src/compiler/checker-classes.ts +706 -0
  389. package/src/compiler/checker-contextual.ts +1457 -0
  390. package/src/compiler/checker-declaration-order.ts +438 -0
  391. package/src/compiler/checker-declarations.ts +1194 -0
  392. package/src/compiler/checker-declared-types.ts +919 -0
  393. package/src/compiler/checker-decorators.ts +694 -0
  394. package/src/compiler/checker-deprecation.ts +359 -0
  395. package/src/compiler/checker-destructuring.ts +805 -0
  396. package/src/compiler/checker-elaboration.ts +477 -0
  397. package/src/compiler/checker-emit-helpers.ts +224 -0
  398. package/src/compiler/checker-emit-resolver.ts +769 -0
  399. package/src/compiler/checker-evaluator.ts +243 -0
  400. package/src/compiler/checker-expressions.ts +1831 -0
  401. package/src/compiler/checker-features.ts +361 -0
  402. package/src/compiler/checker-flow.ts +394 -0
  403. package/src/compiler/checker-functions.ts +1296 -0
  404. package/src/compiler/checker-generated-code.ts +227 -0
  405. package/src/compiler/checker-globals.ts +52 -0
  406. package/src/compiler/checker-grammar.ts +3584 -0
  407. package/src/compiler/checker-heritage.ts +1233 -0
  408. package/src/compiler/checker-inference.ts +2576 -0
  409. package/src/compiler/checker-iteration.ts +1206 -0
  410. package/src/compiler/checker-javascript.ts +502 -0
  411. package/src/compiler/checker-jsdoc.ts +360 -0
  412. package/src/compiler/checker-jsx.ts +1924 -0
  413. package/src/compiler/checker-literals.ts +61 -0
  414. package/src/compiler/checker-members.ts +2436 -0
  415. package/src/compiler/checker-modules.ts +2886 -0
  416. package/src/compiler/checker-narrowing.ts +3230 -0
  417. package/src/compiler/checker-object-literals.ts +575 -0
  418. package/src/compiler/checker-operators.ts +1422 -0
  419. package/src/compiler/checker-overloads.ts +328 -0
  420. package/src/compiler/checker-property-access.ts +906 -0
  421. package/src/compiler/checker-services.ts +1149 -0
  422. package/src/compiler/checker-signatures.ts +1032 -0
  423. package/src/compiler/checker-source-file.ts +732 -0
  424. package/src/compiler/checker-statements.ts +292 -0
  425. package/src/compiler/checker-super.ts +261 -0
  426. package/src/compiler/checker-symbol-types.ts +2107 -0
  427. package/src/compiler/checker-symbols.ts +2150 -0
  428. package/src/compiler/checker-type-factory.ts +2579 -0
  429. package/src/compiler/checker-type-nodes.ts +1033 -0
  430. package/src/compiler/checker-type-operators.ts +2502 -0
  431. package/src/compiler/checker-types.ts +2340 -0
  432. package/src/compiler/checker-unused.ts +642 -0
  433. package/src/compiler/checker-utilities.ts +161 -0
  434. package/src/compiler/checker.ts +1116 -0
  435. package/src/compiler/command-line.ts +436 -0
  436. package/src/compiler/compile-program.ts +439 -0
  437. package/src/compiler/decoder.ts +1209 -0
  438. package/src/compiler/diagnostic-locales.ts +86 -0
  439. package/src/compiler/diagnostic-messages.ts +2349 -0
  440. package/src/compiler/diagnostics.ts +897 -0
  441. package/src/compiler/emitter.ts +434 -0
  442. package/src/compiler/encoder.ts +1945 -0
  443. package/src/compiler/file-include.ts +673 -0
  444. package/src/compiler/file-loader.ts +1528 -0
  445. package/src/compiler/file-system.ts +143 -0
  446. package/src/compiler/flow.ts +89 -0
  447. package/src/compiler/help.ts +473 -0
  448. package/src/compiler/incremental.ts +2784 -0
  449. package/src/compiler/init.ts +141 -0
  450. package/src/compiler/instantiation.ts +894 -0
  451. package/src/compiler/jsdoc.ts +1386 -0
  452. package/src/compiler/link-tables.ts +98 -0
  453. package/src/compiler/locale-data.ts +203 -0
  454. package/src/compiler/locale.ts +307 -0
  455. package/src/compiler/locales/cs-CZ.ts +5 -0
  456. package/src/compiler/locales/de-DE.ts +5 -0
  457. package/src/compiler/locales/es-ES.ts +5 -0
  458. package/src/compiler/locales/fr-FR.ts +5 -0
  459. package/src/compiler/locales/it-IT.ts +5 -0
  460. package/src/compiler/locales/ja-JP.ts +5 -0
  461. package/src/compiler/locales/ko-KR.ts +5 -0
  462. package/src/compiler/locales/pl-PL.ts +5 -0
  463. package/src/compiler/locales/pt-BR.ts +5 -0
  464. package/src/compiler/locales/ru-RU.ts +5 -0
  465. package/src/compiler/locales/tr-TR.ts +5 -0
  466. package/src/compiler/locales/zh-CN.ts +5 -0
  467. package/src/compiler/locales/zh-TW.ts +5 -0
  468. package/src/compiler/module-resolution-types.ts +243 -0
  469. package/src/compiler/module-resolution.ts +2072 -0
  470. package/src/compiler/module-specifiers.ts +1491 -0
  471. package/src/compiler/name-resolver.ts +646 -0
  472. package/src/compiler/node-builder-names.ts +1069 -0
  473. package/src/compiler/node-builder-pseudo.ts +892 -0
  474. package/src/compiler/node-builder-reuse.ts +764 -0
  475. package/src/compiler/node-builder.ts +3425 -0
  476. package/src/compiler/option-declarations.ts +1560 -0
  477. package/src/compiler/options.ts +1576 -0
  478. package/src/compiler/output-paths.ts +334 -0
  479. package/src/compiler/package-json.ts +1083 -0
  480. package/src/compiler/parallel-check.ts +1951 -0
  481. package/src/compiler/parallel-parse.ts +590 -0
  482. package/src/compiler/parse-thread.ts +140 -0
  483. package/src/compiler/parser.ts +7716 -0
  484. package/src/compiler/path.ts +717 -0
  485. package/src/compiler/printer/async-helpers.ts +183 -0
  486. package/src/compiler/printer/auto-generate.ts +27 -0
  487. package/src/compiler/printer/decorator-helpers.ts +218 -0
  488. package/src/compiler/printer/emit-context.ts +679 -0
  489. package/src/compiler/printer/emit-flags.ts +64 -0
  490. package/src/compiler/printer/factory-base.ts +2577 -0
  491. package/src/compiler/printer/factory.ts +764 -0
  492. package/src/compiler/printer/helpers.ts +291 -0
  493. package/src/compiler/printer/name-generator.ts +372 -0
  494. package/src/compiler/printer/printer.ts +5072 -0
  495. package/src/compiler/printer/text-writer.ts +183 -0
  496. package/src/compiler/printer/utilities.ts +884 -0
  497. package/src/compiler/program-checker.ts +592 -0
  498. package/src/compiler/program-utilities.ts +435 -0
  499. package/src/compiler/program.ts +1419 -0
  500. package/src/compiler/pseudo-bigint.ts +62 -0
  501. package/src/compiler/regexp-checker.ts +1142 -0
  502. package/src/compiler/relations.ts +5149 -0
  503. package/src/compiler/reparser.ts +1566 -0
  504. package/src/compiler/scanner.ts +2951 -0
  505. package/src/compiler/show-config.ts +239 -0
  506. package/src/compiler/side-state.ts +125 -0
  507. package/src/compiler/sourcemap.ts +366 -0
  508. package/src/compiler/spelling.ts +122 -0
  509. package/src/compiler/symbol-accessibility.ts +1071 -0
  510. package/src/compiler/symbol.ts +439 -0
  511. package/src/compiler/symlinks.ts +137 -0
  512. package/src/compiler/syntax-kind.ts +391 -0
  513. package/src/compiler/thread-entry.ts +191 -0
  514. package/src/compiler/timeline.ts +53 -0
  515. package/src/compiler/transformers/alias-references.ts +757 -0
  516. package/src/compiler/transformers/async-utilities.ts +335 -0
  517. package/src/compiler/transformers/async.ts +838 -0
  518. package/src/compiler/transformers/class-fields.ts +2967 -0
  519. package/src/compiler/transformers/class-utilities.ts +324 -0
  520. package/src/compiler/transformers/commonjs-module.ts +1621 -0
  521. package/src/compiler/transformers/const-enum-inliner.ts +50 -0
  522. package/src/compiler/transformers/declarations-diagnostics.ts +832 -0
  523. package/src/compiler/transformers/declarations-pseudo.ts +966 -0
  524. package/src/compiler/transformers/declarations-resolver.ts +249 -0
  525. package/src/compiler/transformers/declarations-syntactic.ts +1859 -0
  526. package/src/compiler/transformers/declarations-tracker.ts +269 -0
  527. package/src/compiler/transformers/declarations.ts +3120 -0
  528. package/src/compiler/transformers/decorator-metadata.ts +697 -0
  529. package/src/compiler/transformers/decorator-utilities.ts +283 -0
  530. package/src/compiler/transformers/destructuring.ts +708 -0
  531. package/src/compiler/transformers/downlevel.ts +50 -0
  532. package/src/compiler/transformers/emit-resolver.ts +258 -0
  533. package/src/compiler/transformers/es-decorators.ts +2682 -0
  534. package/src/compiler/transformers/exponentiation.ts +80 -0
  535. package/src/compiler/transformers/external-module-info.ts +412 -0
  536. package/src/compiler/transformers/for-await.ts +687 -0
  537. package/src/compiler/transformers/import-elision.ts +152 -0
  538. package/src/compiler/transformers/jsx-entities.ts +256 -0
  539. package/src/compiler/transformers/jsx.ts +824 -0
  540. package/src/compiler/transformers/legacy-decorators.ts +726 -0
  541. package/src/compiler/transformers/logical-assignment.ts +75 -0
  542. package/src/compiler/transformers/module-utilities.ts +42 -0
  543. package/src/compiler/transformers/module.ts +474 -0
  544. package/src/compiler/transformers/named-evaluation.ts +389 -0
  545. package/src/compiler/transformers/nullish-coalescing.ts +35 -0
  546. package/src/compiler/transformers/object-rest-spread.ts +577 -0
  547. package/src/compiler/transformers/optional-catch.ts +29 -0
  548. package/src/compiler/transformers/optional-chain.ts +246 -0
  549. package/src/compiler/transformers/reference-resolver.ts +1201 -0
  550. package/src/compiler/transformers/runtime-syntax.ts +942 -0
  551. package/src/compiler/transformers/subtree-facts.ts +245 -0
  552. package/src/compiler/transformers/syntax-facts.ts +353 -0
  553. package/src/compiler/transformers/tagged-template.ts +167 -0
  554. package/src/compiler/transformers/transformer.ts +56 -0
  555. package/src/compiler/transformers/type-eraser.ts +520 -0
  556. package/src/compiler/transformers/type-serialization.ts +374 -0
  557. package/src/compiler/transformers/using.ts +613 -0
  558. package/src/compiler/transformers/utilities.ts +419 -0
  559. package/src/compiler/transformers/visitor-base.ts +1601 -0
  560. package/src/compiler/transformers/visitor-hooks.ts +252 -0
  561. package/src/compiler/tsc-build.ts +1418 -0
  562. package/src/compiler/tsc-cli.ts +666 -0
  563. package/src/compiler/tsc-compile.ts +437 -0
  564. package/src/compiler/tsc-watch.ts +854 -0
  565. package/src/compiler/tsconfig.ts +1574 -0
  566. package/src/compiler/type-printer.ts +110 -0
  567. package/src/compiler/types.ts +115 -0
  568. package/src/compiler/unicode-identifiers.ts +212 -0
  569. package/src/compiler/unicode-properties.ts +537 -0
  570. package/src/compiler/vfs-match.ts +597 -0
  571. package/src/compiler/xxh3.ts +650 -0
  572. package/src/library/ast.generated.ts +141 -167
  573. package/src/library/ast.ts +4 -1
  574. package/src/library/checker.ts +384 -0
  575. package/src/library/diagnostics.ts +72 -0
  576. package/src/library/disk.ts +73 -0
  577. package/src/library/errors.ts +26 -0
  578. package/src/library/host.ts +63 -0
  579. package/src/library/index.ts +21 -0
  580. package/src/library/nodes.ts +232 -0
  581. package/src/library/options.ts +449 -0
  582. package/src/library/parse.ts +63 -0
  583. package/src/library/program.ts +293 -0
  584. package/src/library/types.ts +14 -1
@@ -0,0 +1,1598 @@
1
+ /**
2
+ * Module and type reference resolution for `node16`, `nodenext` and `bundler`.
3
+ *
4
+ * ```ts
5
+ * const resolver = new Resolver(host, options);
6
+ * const traces: MessageWithArgs[] = [];
7
+ * const resolved = resolver.resolveModuleName('pkg', '/app/src/index.ts', ModuleKind.ESNext, undefined, traces);
8
+ * ```
9
+ */
10
+ import { createDiagnostic, messageWithArgs, } from './diagnostics.js';
11
+ import { ModuleKind, ModuleResolutionKind, comparePatternKeys, getConditions, getEffectiveTypeRoots, inferredTypesContainingFile, mangleScopedPackageName, moduleResolutionKindName, packageIdToString, parseNodeModuleFromPath, parsePackageName, } from './module-resolution-types.js';
12
+ import { PackageJsonInfoCache, isApplicableVersionedTypesKey, isFalsyJson, parsePackageJson, typeScriptVersion, withPackageDirectory, } from './package-json.js';
13
+ import { getAllowJS, getModuleResolutionKind, getResolveJsonModule } from './options.js';
14
+ import { changeExtension, combinePaths, comparePaths, containsPath, ensureTrailingDirectorySeparator, extensionIsTs, fileExtensionIs, getBaseFileName, getDirectoryPath, getNormalizedAbsolutePath, getPathComponents, getPossibleOriginalInputExtensionForExtension, getRelativePathFromDirectory, getRootLength, hasImplementationTSFileExtension, hasTrailingDirectorySeparator, isDeclarationFileName, isExternalModuleNameRelative, isRootedDiskPath, normalizePath, normalizeSlashes, pathIsRelative, removeExtension, removeFileExtension, removeTrailingDirectorySeparator, removeTrailingDirectorySeparators, supportedTSExtensionsWithJsonFlat, tryExtractTSExtension, tryGetExtensionFromPath, } from './path.js';
15
+ export * from './module-resolution-types.js';
16
+ function extensionsToString(extensions) {
17
+ let result = '';
18
+ if ((extensions & 1 /* Extensions.TypeScript */) !== 0)
19
+ result = 'TypeScript';
20
+ if ((extensions & 2 /* Extensions.JavaScript */) !== 0)
21
+ result += result === '' ? 'JavaScript' : ', JavaScript';
22
+ if ((extensions & 4 /* Extensions.Declaration */) !== 0)
23
+ result += result === '' ? 'Declaration' : ', Declaration';
24
+ if ((extensions & 8 /* Extensions.Json */) !== 0)
25
+ result += result === '' ? 'JSON' : ', JSON';
26
+ return result;
27
+ }
28
+ /** Whether `extension` is one of `extensions`. */
29
+ function extensionIsOk(extensions, extension) {
30
+ return (((extensions & 2 /* Extensions.JavaScript */) !== 0 &&
31
+ (extension === '.js' || extension === '.jsx' || extension === '.mjs' || extension === '.cjs')) ||
32
+ ((extensions & 1 /* Extensions.TypeScript */) !== 0 &&
33
+ (extension === '.ts' || extension === '.tsx' || extension === '.mts' || extension === '.cts')) ||
34
+ ((extensions & 4 /* Extensions.Declaration */) !== 0 &&
35
+ (extension === '.d.ts' || extension === '.d.mts' || extension === '.d.cts')) ||
36
+ ((extensions & 8 /* Extensions.Json */) !== 0 && extension === '.json'));
37
+ }
38
+ function resolvedFile(path, extension, resolvedUsingTsExtension) {
39
+ return { path, extension, packageId: undefined, originalPath: '', resolvedUsingTsExtension };
40
+ }
41
+ function unresolved() {
42
+ return resolvedFile('', '', false);
43
+ }
44
+ export function parsePatterns(paths) {
45
+ const exact = new Set();
46
+ const patterns = [];
47
+ for (const key of paths.keys()) {
48
+ const star = key.indexOf('*');
49
+ if (star === -1)
50
+ exact.add(key);
51
+ else if (key.indexOf('*', star + 1) === -1)
52
+ patterns.push({ text: key, starIndex: star });
53
+ }
54
+ return { exact, patterns };
55
+ }
56
+ function patternMatches(pattern, candidate) {
57
+ return (candidate.length >= pattern.text.length - 1 &&
58
+ candidate.startsWith(pattern.text.slice(0, pattern.starIndex)) &&
59
+ candidate.endsWith(pattern.text.slice(pattern.starIndex + 1)));
60
+ }
61
+ /** The exact key equal to `candidate`, else the matching pattern with the longest prefix. */
62
+ export function matchPatternOrExact(parsed, candidate) {
63
+ if (parsed.exact.has(candidate))
64
+ return { text: candidate, starIndex: -1 };
65
+ let best;
66
+ let longestPrefix = -1;
67
+ for (const pattern of parsed.patterns) {
68
+ if (pattern.starIndex > longestPrefix && patternMatches(pattern, candidate)) {
69
+ best = pattern;
70
+ longestPrefix = pattern.starIndex;
71
+ }
72
+ }
73
+ return best;
74
+ }
75
+ function matchedText(pattern, candidate) {
76
+ if (pattern.starIndex === -1)
77
+ return '';
78
+ return candidate.slice(pattern.starIndex, candidate.length - pattern.text.length + pattern.starIndex + 1);
79
+ }
80
+ function replaceFirstStar(text, replacement) {
81
+ const star = text.indexOf('*');
82
+ return star === -1 ? text : text.slice(0, star) + replacement + text.slice(star + 1);
83
+ }
84
+ function replaceAllStars(text, replacement) {
85
+ let star = text.indexOf('*');
86
+ if (star === -1)
87
+ return text;
88
+ let result = '';
89
+ let start = 0;
90
+ while (star !== -1) {
91
+ result += text.slice(start, star) + replacement;
92
+ start = star + 1;
93
+ star = text.indexOf('*', start);
94
+ }
95
+ return result + text.slice(start);
96
+ }
97
+ /** Whether a `/`-separated segment of `path` after `start` is `.`, `..` or `node_modules`. */
98
+ function hasInvalidTargetSegment(path, start) {
99
+ while (start <= path.length) {
100
+ let end = path.indexOf('/', start);
101
+ if (end === -1)
102
+ end = path.length;
103
+ const length = end - start;
104
+ if ((length === 1 && path.charCodeAt(start) === 0x2e) ||
105
+ (length === 2 && path.startsWith('..', start)) ||
106
+ (length === 12 && path.startsWith('node_modules', start))) {
107
+ return true;
108
+ }
109
+ start = end + 1;
110
+ }
111
+ return false;
112
+ }
113
+ function matchesPatternWithTrailer(target, name) {
114
+ if (target.endsWith('*'))
115
+ return false;
116
+ const star = target.indexOf('*');
117
+ if (star === -1)
118
+ return false;
119
+ return name.startsWith(target.slice(0, star)) && name.endsWith(target.slice(star + 1));
120
+ }
121
+ /**
122
+ * `.` and `..` at the end of a relative name mean a directory, so they normalize to a trailing `/`.
123
+ */
124
+ function normalizePathForCJSResolution(containingDirectory, moduleName) {
125
+ const combined = combinePaths(containingDirectory, moduleName);
126
+ const rootLength = getRootLength(combined);
127
+ let end = combined.length;
128
+ if (end > rootLength && combined.charCodeAt(end - 1) === 0x2f)
129
+ end--;
130
+ let isDotSegment = false;
131
+ if (end > rootLength) {
132
+ const start = Math.max(rootLength, combined.lastIndexOf('/', end - 1) + 1);
133
+ const length = end - start;
134
+ isDotSegment = (length === 1 || length === 2) && combined.startsWith(length === 1 ? '.' : '..', start);
135
+ }
136
+ return isDotSegment ? ensureTrailingDirectorySeparator(normalizePath(combined)) : normalizePath(combined);
137
+ }
138
+ const RELATIVE_LOADER = { kind: 'relative' };
139
+ const NO_DIAGNOSTICS = [];
140
+ function unresolvedModule(diagnostics) {
141
+ return {
142
+ resolvedFileName: '',
143
+ originalPath: '',
144
+ extension: '',
145
+ resolvedUsingTsExtension: false,
146
+ packageId: undefined,
147
+ isExternalLibraryImport: false,
148
+ alternateResult: '',
149
+ resolutionDiagnostics: diagnostics,
150
+ };
151
+ }
152
+ // The results each resolver shared with other threads (and so immutable) did not have yet when it was
153
+ // shared, as this thread resolved them.
154
+ const threadModuleCaches = new Map();
155
+ const threadTypeReferenceCaches = new Map();
156
+ export class Resolver {
157
+ host;
158
+ options;
159
+ typingsLocation;
160
+ projectName;
161
+ packageJsonInfoCache;
162
+ moduleCache = new Map();
163
+ typeReferenceCache = new Map();
164
+ pathPatterns;
165
+ shared = false;
166
+ constructor(host, options,
167
+ /** Global typings cache for automatic type acquisition, or `''`. */
168
+ typingsLocation = '', projectName = '', packageJsonInfoCache) {
169
+ this.host = host;
170
+ this.options = options;
171
+ this.typingsLocation = typingsLocation;
172
+ this.projectName = projectName;
173
+ this.packageJsonInfoCache =
174
+ packageJsonInfoCache ?? new PackageJsonInfoCache(host.getCurrentDirectory(), host.useCaseSensitiveFileNames());
175
+ }
176
+ /**
177
+ * Called before the resolver is shared with other threads, which makes it immutable
178
+ * (parallel-check.ts): from then on, each thread caches the results and `package.json` lookups the
179
+ * resolver did not have yet in tables of its own.
180
+ */
181
+ prepareForSharing() {
182
+ this.getPathPatterns();
183
+ this.packageJsonInfoCache.prepareForSharing();
184
+ this.shared = true;
185
+ }
186
+ cachedModule(key) {
187
+ const cached = this.moduleCache.get(key);
188
+ if (cached !== undefined || !this.shared)
189
+ return cached;
190
+ return threadModuleCaches.get(this)?.get(key);
191
+ }
192
+ cacheModule(key, resolved) {
193
+ if (this.cachedModule(key) !== undefined)
194
+ return;
195
+ if (!this.shared) {
196
+ this.moduleCache.set(key, resolved);
197
+ return;
198
+ }
199
+ let cache = threadModuleCaches.get(this);
200
+ if (cache === undefined) {
201
+ cache = new Map();
202
+ threadModuleCaches.set(this, cache);
203
+ }
204
+ cache.set(key, resolved);
205
+ }
206
+ cachedTypeReference(key) {
207
+ const cached = this.typeReferenceCache.get(key);
208
+ if (cached !== undefined || !this.shared)
209
+ return cached;
210
+ return threadTypeReferenceCaches.get(this)?.get(key);
211
+ }
212
+ cacheTypeReference(key, resolved) {
213
+ if (!this.shared) {
214
+ this.typeReferenceCache.set(key, resolved);
215
+ return;
216
+ }
217
+ let cache = threadTypeReferenceCaches.get(this);
218
+ if (cache === undefined) {
219
+ cache = new Map();
220
+ threadTypeReferenceCaches.set(this, cache);
221
+ }
222
+ cache.set(key, resolved);
223
+ }
224
+ /** Parsed `paths` of the resolver's own options. */
225
+ getPathPatterns() {
226
+ if (this.pathPatterns === undefined)
227
+ this.pathPatterns = parsePatterns(this.options.paths ?? new Map());
228
+ return this.pathPatterns;
229
+ }
230
+ /**
231
+ * Resolves an import specifier. With `traceResolution` set, trace messages are appended to `traces` and the
232
+ * result cache is bypassed.
233
+ */
234
+ resolveModuleName(moduleName, containingFile, mode, redirect, traces) {
235
+ const containingDirectory = getDirectoryPath(containingFile);
236
+ const tracer = this.options.traceResolution === true ? (traces ?? []) : undefined;
237
+ const cacheKey = mode + '|' + (redirect?.configName ?? '') + '|' + containingDirectory + '|' + moduleName;
238
+ if (tracer === undefined) {
239
+ const cached = this.cachedModule(cacheKey);
240
+ if (cached !== undefined)
241
+ return cached;
242
+ }
243
+ const options = optionsWithRedirect(this.options, redirect);
244
+ tracer?.push(messageWithArgs(1255 /* Diagnostics.Resolving_module_0_from_1 */, moduleName, containingFile));
245
+ if (tracer !== undefined)
246
+ traceRedirect(tracer, redirect);
247
+ const kind = getModuleResolutionKind(options);
248
+ tracer?.push(options.moduleResolution !== kind
249
+ ? messageWithArgs(1257 /* Diagnostics.Module_resolution_kind_is_not_specified_using_0 */, moduleResolutionKindName(kind))
250
+ : messageWithArgs(1256 /* Diagnostics.Explicitly_specified_module_resolution_kind_Colon_0 */, moduleResolutionKindName(kind)));
251
+ const state = new ResolutionState(this, tracer, moduleName, containingDirectory, false, mode, options);
252
+ const result = state.resolveNodeLike();
253
+ if (tracer !== undefined) {
254
+ if (result.resolvedFileName === '') {
255
+ tracer.push(messageWithArgs(1259 /* Diagnostics.Module_name_0_was_not_resolved */, moduleName));
256
+ }
257
+ else if (result.packageId !== undefined) {
258
+ tracer.push(messageWithArgs(1371 /* Diagnostics.Module_name_0_was_successfully_resolved_to_1_with_Package_ID_2 */, moduleName, result.resolvedFileName, packageIdToString(result.packageId)));
259
+ }
260
+ else {
261
+ tracer.push(messageWithArgs(1258 /* Diagnostics.Module_name_0_was_successfully_resolved_to_1 */, moduleName, result.resolvedFileName));
262
+ }
263
+ }
264
+ const final = this.tryResolveFromTypingsLocation(moduleName, containingDirectory, result, tracer);
265
+ this.cacheModule(cacheKey, final);
266
+ return final;
267
+ }
268
+ /** Resolves a `/// <reference types>` directive or an entry of `types`. */
269
+ resolveTypeReferenceDirective(name, containingFile, mode, redirect, traces) {
270
+ const containingDirectory = getDirectoryPath(containingFile);
271
+ const tracer = this.options.traceResolution === true ? (traces ?? []) : undefined;
272
+ const fromInferredTypes = containingFile.endsWith(inferredTypesContainingFile);
273
+ const cacheKey = mode +
274
+ '|' +
275
+ (fromInferredTypes ? '1' : '0') +
276
+ (redirect?.configName ?? '') +
277
+ '|' +
278
+ containingDirectory +
279
+ '|' +
280
+ name;
281
+ if (tracer === undefined) {
282
+ const cached = this.cachedTypeReference(cacheKey);
283
+ if (cached !== undefined)
284
+ return cached;
285
+ }
286
+ const options = optionsWithRedirect(this.options, redirect);
287
+ const typeRoots = getEffectiveTypeRoots(options, this.host.getCurrentDirectory());
288
+ const fromConfig = options.typeRoots !== undefined;
289
+ if (tracer !== undefined) {
290
+ tracer.push(messageWithArgs(1284 /* Diagnostics.Resolving_type_reference_directive_0_containing_file_1_root_directory_2 */, name, containingFile, typeRoots.join(',')));
291
+ traceRedirect(tracer, redirect);
292
+ }
293
+ const state = new ResolutionState(this, tracer, name, containingDirectory, true, mode, options);
294
+ const result = state.resolveTypeReferenceDirective(typeRoots, fromConfig, fromInferredTypes);
295
+ if (tracer !== undefined) {
296
+ if (result.resolvedFileName === '') {
297
+ tracer.push(messageWithArgs(1286 /* Diagnostics.Type_reference_directive_0_was_not_resolved */, name));
298
+ }
299
+ else if (result.packageId !== undefined) {
300
+ tracer.push(messageWithArgs(1372 /* Diagnostics.Type_reference_directive_0_was_successfully_resolved_to_1_with_Package_ID_2_primary_Colon_3 */, name, result.resolvedFileName, packageIdToString(result.packageId), String(result.primary)));
301
+ }
302
+ else {
303
+ tracer.push(messageWithArgs(1285 /* Diagnostics.Type_reference_directive_0_was_successfully_resolved_to_1_primary_Colon_2 */, name, result.resolvedFileName, String(result.primary)));
304
+ }
305
+ }
306
+ this.cacheTypeReference(cacheKey, result);
307
+ return result;
308
+ }
309
+ /** Finds the directory of package `moduleName` in the nearest `node_modules`, without loading files. */
310
+ resolvePackageDirectory(moduleName, containingFile, mode, redirect) {
311
+ const options = optionsWithRedirect(this.options, redirect);
312
+ const state = new ResolutionState(this, undefined, moduleName, getDirectoryPath(containingFile), false, mode, options);
313
+ state.resolvePackageDirectoryOnly = true;
314
+ const result = state.loadModuleFromNearestNodeModulesDirectory(false);
315
+ if (result !== undefined && result.path !== '')
316
+ return state.createResolvedModuleHandlingSymlink(result);
317
+ return undefined;
318
+ }
319
+ /** The nearest `package.json` at or above `directory`. */
320
+ getPackageScopeForPath(directory) {
321
+ const state = new ResolutionState(this, undefined, '', directory, false, ModuleKind.None, this.options);
322
+ return state.getPackageScopeForPath(directory);
323
+ }
324
+ /** Resolves an `extends` specifier of a tsconfig file. */
325
+ resolveConfig(moduleName, containingFile) {
326
+ const state = new ResolutionState(this, undefined, moduleName, getDirectoryPath(containingFile), false, ModuleKind.CommonJS, this.options);
327
+ state.isConfigLookup = true;
328
+ state.extensions = 8 /* Extensions.Json */;
329
+ return state.resolveNodeLike();
330
+ }
331
+ tryResolveFromTypingsLocation(moduleName, containingDirectory, original, tracer) {
332
+ if (this.typingsLocation === '' ||
333
+ isExternalModuleNameRelative(moduleName) ||
334
+ (original.resolvedFileName !== '' && supportedTSExtensionsWithJsonFlat.includes(original.extension))) {
335
+ return original;
336
+ }
337
+ const state = new ResolutionState(this, tracer, moduleName, containingDirectory, false, ModuleKind.None, this.options);
338
+ tracer?.push(messageWithArgs(1305 /* Diagnostics.Auto_discovery_for_typings_is_enabled_in_project_0_Running_extra_resolution_pass_for_module_1_using_cache_location_2 */, this.projectName, moduleName, this.typingsLocation));
339
+ const global = state.loadModuleFromImmediateNodeModulesDirectory(4 /* Extensions.Declaration */, this.typingsLocation, false);
340
+ if (global === undefined)
341
+ return original;
342
+ const result = state.createResolvedModule(global, true);
343
+ result.resolutionDiagnostics = original.resolutionDiagnostics.concat(result.resolutionDiagnostics);
344
+ return result;
345
+ }
346
+ }
347
+ function optionsWithRedirect(options, redirect) {
348
+ return redirect?.options ?? options;
349
+ }
350
+ function traceRedirect(tracer, redirect) {
351
+ if (redirect !== undefined && redirect.options !== undefined) {
352
+ tracer.push(messageWithArgs(1368 /* Diagnostics.Using_compiler_options_of_project_reference_redirect_0 */, redirect.configName));
353
+ }
354
+ }
355
+ /** Resolves an `extends` specifier of a tsconfig file with `nodenext` rules. */
356
+ export function resolveConfig(moduleName, containingFile, host) {
357
+ return new Resolver(host, { moduleResolution: ModuleResolutionKind.NodeNext }).resolveConfig(moduleName, containingFile);
358
+ }
359
+ /** The `types` entries to include automatically, expanding `*` to every package in the type roots. */
360
+ export function getAutomaticTypeDirectiveNames(options, host) {
361
+ const types = options.types ?? [];
362
+ if (!types.includes('*'))
363
+ return types.slice();
364
+ const wildcardMatches = [];
365
+ for (const root of getEffectiveTypeRoots(options, host.getCurrentDirectory())) {
366
+ if (!host.directoryExists(root))
367
+ continue;
368
+ for (const directory of host.getDirectories(root)) {
369
+ const normalized = normalizePath(directory);
370
+ const packageJsonPath = combinePaths(combinePaths(root, normalized), 'package.json');
371
+ // types-publisher writes `"typings": null` for packages that ship their own types.
372
+ let isNotNeeded = false;
373
+ if (host.fileExists(packageJsonPath)) {
374
+ isNotNeeded = parsePackageJson(host.readFile(packageJsonPath) ?? '').typings.isNull;
375
+ }
376
+ if (isNotNeeded)
377
+ continue;
378
+ const base = getBaseFileName(normalized);
379
+ if (!base.startsWith('.'))
380
+ wildcardMatches.push(base);
381
+ }
382
+ }
383
+ const result = [];
384
+ const seen = new Set();
385
+ for (const type of types) {
386
+ if (type === '*') {
387
+ for (const match of wildcardMatches) {
388
+ if (!seen.has(match)) {
389
+ seen.add(match);
390
+ result.push(match);
391
+ }
392
+ }
393
+ }
394
+ else if (!seen.has(type)) {
395
+ seen.add(type);
396
+ result.push(type);
397
+ }
398
+ }
399
+ return result;
400
+ }
401
+ /** One resolution request: the name being resolved plus the knobs that change along the way. */
402
+ class ResolutionState {
403
+ resolver;
404
+ traces;
405
+ name;
406
+ containingDirectory;
407
+ options;
408
+ host;
409
+ isConfigLookup = false;
410
+ features = 0 /* Features.None */;
411
+ esmMode = false;
412
+ conditions = [];
413
+ extensions;
414
+ resolvePackageDirectoryOnly = false;
415
+ /**
416
+ * Set while the candidate's extension comes from configuration (package.json, `paths`, wildcard
417
+ * substitutions) rather than the specifier, which suppresses `resolvedUsingTsExtension`.
418
+ */
419
+ candidateEndingIsFromConfig = false;
420
+ resolvedPackageDirectory = false;
421
+ diagnostics = [];
422
+ pathPatterns;
423
+ constructor(resolver, traces, name, containingDirectory, isTypeReferenceDirective, mode, options) {
424
+ this.resolver = resolver;
425
+ this.traces = traces;
426
+ this.name = name;
427
+ this.containingDirectory = containingDirectory;
428
+ this.options = options;
429
+ this.host = resolver.host;
430
+ if (isTypeReferenceDirective)
431
+ this.extensions = 4 /* Extensions.Declaration */;
432
+ else if (options.noDtsResolution === true)
433
+ this.extensions = 3 /* Extensions.ImplementationFiles */;
434
+ else
435
+ this.extensions = 1 /* Extensions.TypeScript */ | 2 /* Extensions.JavaScript */ | 4 /* Extensions.Declaration */;
436
+ if (!isTypeReferenceDirective && getResolveJsonModule(options))
437
+ this.extensions |= 8 /* Extensions.Json */;
438
+ switch (getModuleResolutionKind(options)) {
439
+ case ModuleResolutionKind.Node16:
440
+ this.features = 15 /* Features.Node16Default */;
441
+ this.esmMode = mode === ModuleKind.ESNext;
442
+ this.conditions = getConditions(options, mode);
443
+ break;
444
+ case ModuleResolutionKind.NodeNext:
445
+ this.features = 31 /* Features.NodeNextDefault */;
446
+ this.esmMode = mode === ModuleKind.ESNext;
447
+ this.conditions = getConditions(options, mode);
448
+ break;
449
+ case ModuleResolutionKind.Bundler:
450
+ this.features = bundlerFeatures(options);
451
+ this.conditions = getConditions(options, mode);
452
+ break;
453
+ }
454
+ }
455
+ trace(message, ...args) {
456
+ this.traces?.push({ message, args });
457
+ }
458
+ //// Type reference directives
459
+ resolveTypeReferenceDirective(typeRoots, fromConfig, fromInferredTypes) {
460
+ const traces = this.traces;
461
+ if (typeRoots.length > 0) {
462
+ if (traces !== undefined)
463
+ this.trace(1287 /* Diagnostics.Resolving_with_primary_search_path_0 */, typeRoots.join(', '));
464
+ for (const typeRoot of typeRoots) {
465
+ const candidate = this.getCandidateFromTypeRoot(typeRoot);
466
+ if (!this.host.directoryExists(typeRoot)) {
467
+ if (traces !== undefined)
468
+ this.trace(1311 /* Diagnostics.Directory_0_does_not_exist_skipping_all_lookups_in_it */, typeRoot);
469
+ continue;
470
+ }
471
+ if (fromConfig) {
472
+ // Configured type roots resolve as files or directories, like modules.
473
+ const fromFile = this.loadModuleFromFile(4 /* Extensions.Declaration */, candidate);
474
+ if (fromFile !== undefined) {
475
+ this.setPackageIdFromNodeModulesPath(fromFile);
476
+ return this.createResolvedTypeReferenceDirective(fromFile, true);
477
+ }
478
+ }
479
+ const fromDirectory = this.loadNodeModuleFromDirectory(4 /* Extensions.Declaration */, candidate, true);
480
+ if (fromDirectory !== undefined)
481
+ return this.createResolvedTypeReferenceDirective(fromDirectory, true);
482
+ }
483
+ }
484
+ else if (traces !== undefined) {
485
+ this.trace(1288 /* Diagnostics.Root_directory_cannot_be_determined_skipping_primary_search_paths */);
486
+ }
487
+ let resolved;
488
+ if (!fromConfig || !fromInferredTypes) {
489
+ if (traces !== undefined)
490
+ this.trace(1291 /* Diagnostics.Looking_up_in_node_modules_folder_initial_location_0 */, this.containingDirectory);
491
+ if (!isExternalModuleNameRelative(this.name)) {
492
+ resolved = this.loadModuleFromNearestNodeModulesDirectory(false);
493
+ }
494
+ else {
495
+ const candidate = normalizePathForCJSResolution(this.containingDirectory, this.name);
496
+ resolved = this.nodeLoadModuleByRelativeName(4 /* Extensions.Declaration */, candidate, true);
497
+ }
498
+ }
499
+ else if (traces !== undefined) {
500
+ this.trace(1417 /* Diagnostics.Resolving_type_reference_directive_for_program_that_specifies_custom_typeRoots_skipping_lookup_in_node_modules_folder */);
501
+ }
502
+ return this.createResolvedTypeReferenceDirective(resolved, false);
503
+ }
504
+ setPackageIdFromNodeModulesPath(resolved) {
505
+ const packageDirectory = parseNodeModuleFromPath(resolved.path, false);
506
+ if (packageDirectory !== '') {
507
+ resolved.packageId = this.getPackageId(resolved.path, this.getPackageJsonInfo(packageDirectory));
508
+ }
509
+ }
510
+ getCandidateFromTypeRoot(typeRoot) {
511
+ const name = typeRoot.endsWith('/node_modules/@types') || typeRoot.endsWith('/node_modules/@types/')
512
+ ? this.mangleScopedPackageName(this.name)
513
+ : this.name;
514
+ return combinePaths(typeRoot, name);
515
+ }
516
+ mangleScopedPackageName(name) {
517
+ const mangled = mangleScopedPackageName(name);
518
+ if (this.traces !== undefined && mangled !== name)
519
+ this.trace(1337 /* Diagnostics.Scoped_package_detected_looking_in_0 */, mangled);
520
+ return mangled;
521
+ }
522
+ /** Falls back to configured `typeRoots` for declaration lookups of bare names. */
523
+ resolveFromTypeRoot() {
524
+ const typeRoots = this.options.typeRoots;
525
+ if (typeRoots === undefined)
526
+ return undefined;
527
+ for (const typeRoot of typeRoots) {
528
+ const candidate = this.getCandidateFromTypeRoot(typeRoot);
529
+ if (!this.host.directoryExists(typeRoot)) {
530
+ if (this.traces !== undefined)
531
+ this.trace(1311 /* Diagnostics.Directory_0_does_not_exist_skipping_all_lookups_in_it */, typeRoot);
532
+ continue;
533
+ }
534
+ const fromFile = this.loadModuleFromFile(4 /* Extensions.Declaration */, candidate);
535
+ if (fromFile !== undefined) {
536
+ this.setPackageIdFromNodeModulesPath(fromFile);
537
+ return fromFile;
538
+ }
539
+ const fromDirectory = this.loadNodeModuleFromDirectory(4 /* Extensions.Declaration */, candidate, true);
540
+ if (fromDirectory !== undefined)
541
+ return fromDirectory;
542
+ }
543
+ return undefined;
544
+ }
545
+ getPackageScopeForPath(directory) {
546
+ const stop = this.resolver.typingsLocation;
547
+ for (;;) {
548
+ const result = this.getPackageJsonInfo(directory);
549
+ if (result !== undefined || directory === stop)
550
+ return result;
551
+ const parent = getDirectoryPath(directory);
552
+ if (parent === directory)
553
+ return undefined;
554
+ directory = parent;
555
+ }
556
+ }
557
+ //// Module names
558
+ resolveNodeLike() {
559
+ if (this.traces !== undefined) {
560
+ const conditions = this.conditions.map((c) => "'" + c + "'").join(', ');
561
+ this.trace(1492 /* Diagnostics.Resolving_in_0_mode_with_conditions_1 */, this.esmMode ? 'ESM' : 'CJS', conditions);
562
+ }
563
+ const result = this.resolveNodeLikeWorker();
564
+ if (this.resolvedPackageDirectory &&
565
+ !this.isConfigLookup &&
566
+ (this.features & 4 /* Features.Exports */) !== 0 &&
567
+ (this.extensions & (1 /* Extensions.TypeScript */ | 4 /* Extensions.Declaration */)) !== 0 &&
568
+ !isExternalModuleNameRelative(this.name) &&
569
+ result.resolvedFileName !== '' &&
570
+ result.isExternalLibraryImport &&
571
+ !extensionIsOk(1 /* Extensions.TypeScript */ | 4 /* Extensions.Declaration */, result.extension) &&
572
+ this.conditions.includes('import')) {
573
+ // Find out whether the package would resolve to types without `exports`, to suggest a fix.
574
+ if (this.traces !== undefined) {
575
+ this.trace(1426 /* Diagnostics.Resolution_of_non_relative_name_failed_trying_with_modern_Node_resolution_features_disabled_to_see_if_npm_library_needs_configuration_update */);
576
+ }
577
+ this.features &= ~4 /* Features.Exports */;
578
+ this.extensions &= 1 /* Extensions.TypeScript */ | 4 /* Extensions.Declaration */;
579
+ const diagnosticsCount = this.diagnostics.length;
580
+ const alternate = this.resolveNodeLikeWorker();
581
+ if (alternate.resolvedFileName !== '' && alternate.isExternalLibraryImport) {
582
+ result.alternateResult = alternate.resolvedFileName;
583
+ }
584
+ // Results share the array, so truncate a copy.
585
+ if (this.diagnostics.length !== diagnosticsCount)
586
+ this.diagnostics = this.diagnostics.slice(0, diagnosticsCount);
587
+ }
588
+ return result;
589
+ }
590
+ resolveNodeLikeWorker() {
591
+ const fromSettings = this.tryLoadModuleUsingOptionalResolutionSettings();
592
+ if (fromSettings !== undefined)
593
+ return this.createResolvedModuleHandlingSymlink(fromSettings);
594
+ if (isExternalModuleNameRelative(this.name)) {
595
+ const candidate = normalizePathForCJSResolution(this.containingDirectory, this.name);
596
+ const resolved = this.nodeLoadModuleByRelativeName(this.extensions, candidate, true);
597
+ return this.createResolvedModule(resolved, resolved !== undefined && resolved.path.includes('/node_modules/'));
598
+ }
599
+ if ((this.features & 1 /* Features.Imports */) !== 0 && this.name.startsWith('#')) {
600
+ const resolved = this.loadModuleFromImports();
601
+ if (resolved !== undefined)
602
+ return this.createResolvedModuleHandlingSymlink(resolved);
603
+ }
604
+ if ((this.features & 2 /* Features.SelfName */) !== 0) {
605
+ const resolved = this.loadModuleFromSelfNameReference();
606
+ if (resolved !== undefined)
607
+ return this.createResolvedModuleHandlingSymlink(resolved);
608
+ }
609
+ if (this.name.includes(':')) {
610
+ if (this.traces !== undefined) {
611
+ this.trace(1327 /* Diagnostics.Skipping_module_0_that_looks_like_an_absolute_URI_target_file_types_Colon_1 */, this.name, extensionsToString(this.extensions));
612
+ }
613
+ return this.createResolvedModule(undefined, false);
614
+ }
615
+ if (this.traces !== undefined) {
616
+ this.trace(1267 /* Diagnostics.Loading_module_0_from_node_modules_folder_target_file_types_Colon_1 */, this.name, extensionsToString(this.extensions));
617
+ }
618
+ const fromNodeModules = this.loadModuleFromNearestNodeModulesDirectory(false);
619
+ if (fromNodeModules !== undefined)
620
+ return this.createResolvedModuleHandlingSymlink(fromNodeModules);
621
+ if ((this.extensions & 4 /* Extensions.Declaration */) !== 0) {
622
+ const fromTypeRoot = this.resolveFromTypeRoot();
623
+ if (fromTypeRoot !== undefined)
624
+ return this.createResolvedModuleHandlingSymlink(fromTypeRoot);
625
+ }
626
+ return this.createResolvedModule(undefined, false);
627
+ }
628
+ loadModuleFromSelfNameReference() {
629
+ const directory = getNormalizedAbsolutePath(this.containingDirectory, this.host.getCurrentDirectory());
630
+ const scope = this.getPackageScopeForPath(directory);
631
+ const contents = scope?.contents;
632
+ if (scope === undefined || contents === undefined || isFalsyJson(contents.exports))
633
+ return undefined;
634
+ const name = contents.name.value;
635
+ if (name === undefined)
636
+ return undefined;
637
+ // Cheap rejection before the component-wise comparison.
638
+ if (!this.name.includes('\\') &&
639
+ !name.includes('\\') &&
640
+ !this.name.startsWith(removeTrailingDirectorySeparators(name))) {
641
+ return undefined;
642
+ }
643
+ const parts = getPathComponents(this.name);
644
+ const nameParts = getPathComponents(name);
645
+ if (parts.length < nameParts.length)
646
+ return undefined;
647
+ for (let i = 0; i < nameParts.length; i++)
648
+ if (parts[i] !== nameParts[i])
649
+ return undefined;
650
+ let subpath = '.';
651
+ for (let i = nameParts.length; i < parts.length; i++)
652
+ subpath = combinePaths(subpath, parts[i]);
653
+ // Two passes keep @types packages higher in the tree ahead of untyped implementations, as in
654
+ // node_modules lookups. With allowJs, one pass lets self-names map back to input JS files.
655
+ if (getAllowJS(this.options) && !this.containingDirectory.includes('/node_modules/')) {
656
+ return this.loadModuleFromExports(scope, this.extensions, subpath);
657
+ }
658
+ const priority = this.extensions & (1 /* Extensions.TypeScript */ | 4 /* Extensions.Declaration */);
659
+ const secondary = this.extensions & ~(1 /* Extensions.TypeScript */ | 4 /* Extensions.Declaration */);
660
+ return (this.loadModuleFromExports(scope, priority, subpath) ?? this.loadModuleFromExports(scope, secondary, subpath));
661
+ }
662
+ loadModuleFromImports() {
663
+ if (this.name === '#' || (this.name.startsWith('#/') && (this.features & 16 /* Features.ImportsPatternRoot */) === 0)) {
664
+ if (this.traces !== undefined)
665
+ this.trace(1421 /* Diagnostics.Invalid_import_specifier_0_has_no_possible_resolutions */, this.name);
666
+ return undefined;
667
+ }
668
+ const directory = getNormalizedAbsolutePath(this.containingDirectory, this.host.getCurrentDirectory());
669
+ const scope = this.getPackageScopeForPath(directory);
670
+ const contents = scope?.contents;
671
+ if (scope === undefined || contents === undefined) {
672
+ if (this.traces !== undefined) {
673
+ this.trace(1419 /* Diagnostics.Directory_0_has_no_containing_package_json_scope_Imports_will_not_resolve */, directory);
674
+ }
675
+ return undefined;
676
+ }
677
+ const imports = contents.imports;
678
+ if (imports === undefined || imports.type !== 'object') {
679
+ if (this.traces !== undefined)
680
+ this.trace(1422 /* Diagnostics.X_package_json_scope_0_has_no_imports_defined */, scope.packageDirectory);
681
+ return undefined;
682
+ }
683
+ const result = this.loadModuleFromExportsOrImports(this.extensions, this.name, imports, scope, true);
684
+ if (result !== undefined)
685
+ return result;
686
+ if (this.traces !== undefined) {
687
+ this.trace(1420 /* Diagnostics.Import_specifier_0_does_not_exist_in_package_json_scope_at_path_1 */, this.name, scope.packageDirectory);
688
+ }
689
+ return undefined;
690
+ }
691
+ loadModuleFromExports(scope, extensions, subpath) {
692
+ const exports = scope.contents?.exports;
693
+ if (exports === undefined || isFalsyJson(exports))
694
+ return undefined;
695
+ if (subpath === '.') {
696
+ let mainExport;
697
+ if (exports.type === 'string' || exports.type === 'array')
698
+ mainExport = exports;
699
+ else if (exports.type === 'object') {
700
+ mainExport = exports.kind === 0 /* JsonObjectKind.Conditions */ ? exports : exports.entries.get('.');
701
+ }
702
+ if (mainExport !== undefined) {
703
+ return this.loadModuleFromTargetExportOrImport(extensions, subpath, scope, false, mainExport, '', false, '.');
704
+ }
705
+ }
706
+ else if (exports.type === 'object' && exports.kind === 1 /* JsonObjectKind.Subpaths */) {
707
+ const result = this.loadModuleFromExportsOrImports(extensions, subpath, exports, scope, false);
708
+ if (result !== undefined)
709
+ return result;
710
+ }
711
+ if (this.traces !== undefined) {
712
+ this.trace(1425 /* Diagnostics.Export_specifier_0_does_not_exist_in_package_json_scope_at_path_1 */, subpath, scope.packageDirectory);
713
+ }
714
+ return undefined;
715
+ }
716
+ loadModuleFromExportsOrImports(extensions, moduleName, lookupTable, scope, isImports) {
717
+ const entries = lookupTable.entries;
718
+ if (!moduleName.endsWith('/') && !moduleName.includes('*')) {
719
+ const target = entries.get(moduleName);
720
+ if (target !== undefined) {
721
+ return this.loadModuleFromTargetExportOrImport(extensions, moduleName, scope, isImports, target, '', false, moduleName);
722
+ }
723
+ }
724
+ const expandingKeys = [];
725
+ for (const key of entries.keys()) {
726
+ const star = key.indexOf('*');
727
+ if ((star !== -1 && key.indexOf('*', star + 1) === -1) || key.endsWith('/'))
728
+ expandingKeys.push(key);
729
+ }
730
+ expandingKeys.sort(comparePatternKeys);
731
+ for (const key of expandingKeys) {
732
+ const target = entries.get(key);
733
+ if (target === undefined)
734
+ continue;
735
+ if ((this.features & 8 /* Features.ExportsPatternTrailers */) !== 0 && matchesPatternWithTrailer(key, moduleName)) {
736
+ const star = key.indexOf('*');
737
+ const subpath = moduleName.slice(star, moduleName.length - (key.length - 1 - star));
738
+ return this.loadModuleFromTargetExportOrImport(extensions, moduleName, scope, isImports, target, subpath, true, key);
739
+ }
740
+ if (key.endsWith('*') && moduleName.startsWith(key.slice(0, -1))) {
741
+ const subpath = moduleName.slice(key.length - 1);
742
+ return this.loadModuleFromTargetExportOrImport(extensions, moduleName, scope, isImports, target, subpath, true, key);
743
+ }
744
+ if (moduleName.startsWith(key)) {
745
+ const subpath = moduleName.slice(key.length);
746
+ return this.loadModuleFromTargetExportOrImport(extensions, moduleName, scope, isImports, target, subpath, false, key);
747
+ }
748
+ }
749
+ return undefined;
750
+ }
751
+ invalidTarget(scope, moduleName) {
752
+ if (this.traces !== undefined) {
753
+ this.trace(1424 /* Diagnostics.X_package_json_scope_0_has_invalid_type_for_target_of_specifier_1 */, scope.packageDirectory, moduleName);
754
+ }
755
+ return undefined;
756
+ }
757
+ loadModuleFromTargetExportOrImport(extensions, moduleName, scope, isImports, target, subpath, isPattern, key) {
758
+ const traces = this.traces;
759
+ switch (target.type) {
760
+ case 'string': {
761
+ const targetString = target.value;
762
+ const normalizedTarget = normalizeSlashes(targetString);
763
+ if (!isPattern && subpath.length > 0 && !targetString.endsWith('/'))
764
+ return this.invalidTarget(scope, moduleName);
765
+ if (!targetString.startsWith('./')) {
766
+ if (isImports &&
767
+ !targetString.startsWith('../') &&
768
+ !targetString.startsWith('/') &&
769
+ !isRootedDiskPath(targetString)) {
770
+ return this.resolveImportsTargetAsModule(targetString, subpath, isPattern, scope, key);
771
+ }
772
+ return this.invalidTarget(scope, moduleName);
773
+ }
774
+ if (hasInvalidTargetSegment(normalizedTarget, 2))
775
+ return this.invalidTarget(scope, moduleName);
776
+ const resolvedTarget = combinePaths(scope.packageDirectory, targetString);
777
+ const normalizedSubpath = normalizeSlashes(subpath);
778
+ if (hasInvalidTargetSegment(normalizedSubpath, getRootLength(normalizedSubpath))) {
779
+ return this.invalidTarget(scope, moduleName);
780
+ }
781
+ if (traces !== undefined) {
782
+ this.trace(1494 /* Diagnostics.Using_0_subpath_1_with_target_2 */, isImports ? 'imports' : 'exports', key, isPattern ? replaceAllStars(targetString, subpath) : targetString + subpath);
783
+ }
784
+ const finalPath = getNormalizedAbsolutePath(isPattern ? replaceAllStars(resolvedTarget, subpath) : resolvedTarget + subpath, this.host.getCurrentDirectory());
785
+ const inputLink = this.tryLoadInputFileForPath(finalPath, subpath, combinePaths(scope.packageDirectory, 'package.json'), isImports);
786
+ if (inputLink !== undefined) {
787
+ inputLink.packageId = this.getPackageId(inputLink.path, scope);
788
+ return inputLink;
789
+ }
790
+ const result = this.loadFileNameFromPackageJsonField(extensions, finalPath, targetString);
791
+ if (result !== undefined) {
792
+ result.packageId = this.getPackageId(result.path, scope);
793
+ return result;
794
+ }
795
+ return undefined;
796
+ }
797
+ case 'object': {
798
+ if (traces !== undefined)
799
+ this.trace(1503 /* Diagnostics.Entering_conditional_exports */);
800
+ for (const [condition, subTarget] of target.entries) {
801
+ if (!this.conditionMatches(condition)) {
802
+ if (traces !== undefined)
803
+ this.trace(1495 /* Diagnostics.Saw_non_matching_condition_0 */, condition);
804
+ continue;
805
+ }
806
+ if (traces !== undefined)
807
+ this.trace(1493 /* Diagnostics.Matched_0_condition_1 */, isImports ? 'imports' : 'exports', condition);
808
+ const result = this.loadModuleFromTargetExportOrImport(extensions, moduleName, scope, isImports, subTarget, subpath, isPattern, key);
809
+ if (result !== undefined) {
810
+ if (traces !== undefined) {
811
+ if (result.path !== '')
812
+ this.trace(1504 /* Diagnostics.Resolved_under_condition_0 */, condition);
813
+ this.trace(1506 /* Diagnostics.Exiting_conditional_exports */);
814
+ }
815
+ return result;
816
+ }
817
+ if (traces !== undefined)
818
+ this.trace(1505 /* Diagnostics.Failed_to_resolve_under_condition_0 */, condition);
819
+ }
820
+ if (traces !== undefined)
821
+ this.trace(1506 /* Diagnostics.Exiting_conditional_exports */);
822
+ return undefined;
823
+ }
824
+ case 'array':
825
+ if (target.items.length === 0)
826
+ return this.invalidTarget(scope, moduleName);
827
+ for (const item of target.items) {
828
+ const result = this.loadModuleFromTargetExportOrImport(extensions, moduleName, scope, isImports, item, subpath, isPattern, key);
829
+ if (result !== undefined)
830
+ return result;
831
+ }
832
+ return this.invalidTarget(scope, moduleName);
833
+ case 'null':
834
+ if (traces !== undefined) {
835
+ this.trace(1423 /* Diagnostics.X_package_json_scope_0_explicitly_maps_specifier_1_to_null */, scope.packageDirectory, moduleName);
836
+ }
837
+ return unresolved();
838
+ default:
839
+ return this.invalidTarget(scope, moduleName);
840
+ }
841
+ }
842
+ /** An `imports` target naming a package resolves as a module from the scope's directory. */
843
+ resolveImportsTargetAsModule(targetString, subpath, isPattern, scope, key) {
844
+ const combinedLookup = isPattern ? replaceAllStars(targetString, subpath) : targetString + subpath;
845
+ const scopeDirectory = ensureTrailingDirectorySeparator(scope.packageDirectory);
846
+ if (this.traces !== undefined) {
847
+ this.trace(1494 /* Diagnostics.Using_0_subpath_1_with_target_2 */, 'imports', key, combinedLookup);
848
+ this.trace(1255 /* Diagnostics.Resolving_module_0_from_1 */, combinedLookup, scopeDirectory);
849
+ }
850
+ const name = this.name;
851
+ const containingDirectory = this.containingDirectory;
852
+ this.name = combinedLookup;
853
+ this.containingDirectory = scopeDirectory;
854
+ const result = this.resolveNodeLike();
855
+ this.name = name;
856
+ this.containingDirectory = containingDirectory;
857
+ if (result.resolvedFileName === '')
858
+ return undefined;
859
+ return {
860
+ path: result.resolvedFileName,
861
+ extension: result.extension,
862
+ packageId: result.packageId,
863
+ originalPath: result.originalPath,
864
+ resolvedUsingTsExtension: result.resolvedUsingTsExtension,
865
+ };
866
+ }
867
+ /** Maps a path into `outDir`/`declarationDir` back to the input file, so self-names work before a build. */
868
+ tryLoadInputFileForPath(finalPath, entry, packagePath, isImports) {
869
+ const options = this.options;
870
+ const outDir = options.outDir ?? '';
871
+ const declarationDir = options.declarationDir ?? '';
872
+ const configFilePath = options.configFilePath ?? '';
873
+ const caseSensitive = this.host.useCaseSensitiveFileNames();
874
+ const currentDirectory = this.host.getCurrentDirectory();
875
+ if (this.isConfigLookup ||
876
+ (declarationDir === '' && outDir === '') ||
877
+ finalPath.includes('/node_modules/') ||
878
+ (configFilePath !== '' &&
879
+ !containsPath(getDirectoryPath(packagePath), configFilePath, caseSensitive, currentDirectory))) {
880
+ return undefined;
881
+ }
882
+ // Unlike tsc 5.x, no guessing: the root comes from `rootDir` or the config file location.
883
+ let rootDir;
884
+ if (options.rootDir !== undefined && options.rootDir !== '') {
885
+ rootDir = options.rootDir;
886
+ }
887
+ else if (configFilePath !== '') {
888
+ rootDir = getDirectoryPath(configFilePath);
889
+ }
890
+ else {
891
+ this.diagnostics.push(createDiagnostic(undefined, 0, 0, isImports
892
+ ? 475 /* Diagnostics.The_project_root_is_ambiguous_but_is_required_to_resolve_import_map_entry_0_in_file_1_Supply_the_rootDir_compiler_option_to_disambiguate */
893
+ : 474 /* Diagnostics.The_project_root_is_ambiguous_but_is_required_to_resolve_export_map_entry_0_in_file_1_Supply_the_rootDir_compiler_option_to_disambiguate */, entry === '' ? '.' : entry, packagePath));
894
+ return unresolved();
895
+ }
896
+ // Output paths in a config are relative to the current directory; otherwise to the root.
897
+ const base = configFilePath !== '' ? currentDirectory : rootDir;
898
+ const candidateDirectories = [];
899
+ if (declarationDir !== '') {
900
+ candidateDirectories.push(getNormalizedAbsolutePath(combinePaths(base, declarationDir), currentDirectory));
901
+ }
902
+ if (outDir !== '' && outDir !== declarationDir) {
903
+ candidateDirectories.push(getNormalizedAbsolutePath(combinePaths(base, outDir), currentDirectory));
904
+ }
905
+ for (const candidateDirectory of candidateDirectories) {
906
+ if (!containsPath(candidateDirectory, finalPath, caseSensitive, currentDirectory))
907
+ continue;
908
+ const fragment = finalPath.length > candidateDirectory.length ? finalPath.slice(candidateDirectory.length + 1) : '';
909
+ const possibleInputBase = combinePaths(rootDir, fragment);
910
+ for (const ext of OUTPUT_EXTENSIONS) {
911
+ if (!fileExtensionIs(possibleInputBase, ext))
912
+ continue;
913
+ for (const inputExt of getPossibleOriginalInputExtensionForExtension(possibleInputBase)) {
914
+ if (!extensionIsOk(this.extensions, inputExt))
915
+ continue;
916
+ const input = changeExtension(possibleInputBase, inputExt);
917
+ if (this.host.fileExists(input)) {
918
+ const resolved = this.loadFileNameFromPackageJsonField(this.extensions, input, '');
919
+ if (resolved !== undefined)
920
+ return resolved;
921
+ }
922
+ }
923
+ }
924
+ }
925
+ return undefined;
926
+ }
927
+ //// node_modules
928
+ loadModuleFromNearestNodeModulesDirectory(typesScopeOnly) {
929
+ // First TS/DTS in implementation packages and @types in every ancestor, then JS in every ancestor.
930
+ const priority = this.extensions & (1 /* Extensions.TypeScript */ | 4 /* Extensions.Declaration */);
931
+ const secondary = this.extensions & ~(1 /* Extensions.TypeScript */ | 4 /* Extensions.Declaration */);
932
+ if (priority !== 0) {
933
+ if (this.traces !== undefined) {
934
+ this.trace(1507 /* Diagnostics.Searching_all_ancestor_node_modules_directories_for_preferred_extensions_Colon_0 */, extensionsToString(priority));
935
+ }
936
+ const result = this.loadModuleFromAncestorNodeModules(priority, typesScopeOnly);
937
+ if (result !== undefined)
938
+ return result;
939
+ }
940
+ if (secondary !== 0 && !typesScopeOnly) {
941
+ if (this.traces !== undefined) {
942
+ this.trace(1508 /* Diagnostics.Searching_all_ancestor_node_modules_directories_for_fallback_extensions_Colon_0 */, extensionsToString(secondary));
943
+ }
944
+ return this.loadModuleFromAncestorNodeModules(secondary, typesScopeOnly);
945
+ }
946
+ return undefined;
947
+ }
948
+ loadModuleFromAncestorNodeModules(extensions, typesScopeOnly) {
949
+ let directory = this.containingDirectory;
950
+ for (;;) {
951
+ if (getBaseFileName(directory) !== 'node_modules') {
952
+ const result = this.loadModuleFromImmediateNodeModulesDirectory(extensions, directory, typesScopeOnly);
953
+ if (result !== undefined)
954
+ return result;
955
+ }
956
+ const parent = getDirectoryPath(directory);
957
+ if (parent === directory)
958
+ return undefined;
959
+ directory = parent;
960
+ }
961
+ }
962
+ loadModuleFromImmediateNodeModulesDirectory(extensions, directory, typesScopeOnly) {
963
+ const nodeModules = combinePaths(directory, 'node_modules');
964
+ if (!this.host.directoryExists(nodeModules)) {
965
+ if (this.traces !== undefined)
966
+ this.trace(1311 /* Diagnostics.Directory_0_does_not_exist_skipping_all_lookups_in_it */, nodeModules);
967
+ return undefined;
968
+ }
969
+ if (!typesScopeOnly) {
970
+ const result = this.loadModuleFromSpecificNodeModulesDirectory(extensions, this.name, nodeModules);
971
+ if (result !== undefined)
972
+ return result;
973
+ }
974
+ if ((extensions & 4 /* Extensions.Declaration */) !== 0) {
975
+ const atTypes = combinePaths(nodeModules, '@types');
976
+ if (!this.host.directoryExists(atTypes)) {
977
+ if (this.traces !== undefined)
978
+ this.trace(1311 /* Diagnostics.Directory_0_does_not_exist_skipping_all_lookups_in_it */, atTypes);
979
+ return undefined;
980
+ }
981
+ return this.loadModuleFromSpecificNodeModulesDirectory(4 /* Extensions.Declaration */, this.mangleScopedPackageName(this.name), atTypes);
982
+ }
983
+ return undefined;
984
+ }
985
+ loadModuleFromSpecificNodeModulesDirectory(extensions, moduleName, nodeModulesDirectory) {
986
+ // Without the trailing separator, `pkg/` and `pkg` share their candidate and package directory.
987
+ const candidate = removeTrailingDirectorySeparator(normalizePath(combinePaths(nodeModulesDirectory, moduleName)));
988
+ const { packageName, rest } = parsePackageName(moduleName);
989
+ const packageDirectory = packageName === '' ? candidate : combinePaths(nodeModulesDirectory, packageName);
990
+ if (this.resolvePackageDirectoryOnly) {
991
+ return this.host.directoryExists(packageDirectory) ? resolvedFile(packageDirectory, '', false) : undefined;
992
+ }
993
+ // A nested package.json (`node_modules/foo/bar/package.json`) applies unless the root has `exports`.
994
+ let rootPackageInfo;
995
+ let packageInfo = this.getPackageJsonInfo(candidate);
996
+ if (rest !== '' && packageInfo !== undefined) {
997
+ if ((this.features & 4 /* Features.Exports */) !== 0)
998
+ rootPackageInfo = this.getPackageJsonInfo(packageDirectory);
999
+ if (rootPackageInfo === undefined || rootPackageInfo.contents?.exports === undefined) {
1000
+ const fromFile = this.loadModuleFromFile(extensions, candidate);
1001
+ if (fromFile !== undefined)
1002
+ return fromFile;
1003
+ const fromDirectory = this.loadNodeModuleFromDirectoryWorker(extensions, candidate, packageInfo);
1004
+ if (fromDirectory !== undefined) {
1005
+ fromDirectory.packageId = this.getPackageId(fromDirectory.path, packageInfo);
1006
+ return fromDirectory;
1007
+ }
1008
+ }
1009
+ }
1010
+ if (rest !== '')
1011
+ packageInfo = rootPackageInfo ?? this.getPackageJsonInfo(packageDirectory);
1012
+ const contents = packageInfo?.contents;
1013
+ if (packageInfo !== undefined) {
1014
+ this.resolvedPackageDirectory = true;
1015
+ // `exports` takes priority over files, directories and typesVersions, and blocks them.
1016
+ // A top-level `"exports": null` does not block them.
1017
+ if ((this.features & 4 /* Features.Exports */) !== 0 && contents !== undefined && !isFalsyJson(contents.exports)) {
1018
+ return this.loadModuleFromExports(packageInfo, extensions, combinePaths('.', rest));
1019
+ }
1020
+ if (rest !== '' && contents !== undefined) {
1021
+ const versionPaths = contents.getVersionPaths(this.traces);
1022
+ if (versionPaths !== undefined) {
1023
+ if (this.traces !== undefined) {
1024
+ this.trace(1361 /* Diagnostics.X_package_json_has_a_typesVersions_entry_0_that_matches_compiler_version_1_looking_for_a_pattern_to_match_module_name_2 */, versionPaths.version, typeScriptVersion, rest);
1025
+ }
1026
+ const fromPaths = this.tryLoadModuleUsingPaths(extensions, rest, packageDirectory, versionPaths.paths, parsePatterns(versionPaths.paths), { kind: 'package', rest, packageInfo });
1027
+ if (fromPaths !== undefined)
1028
+ return fromPaths;
1029
+ }
1030
+ }
1031
+ }
1032
+ return this.loadFromNodeModulesPackage(extensions, candidate, rest, packageInfo);
1033
+ }
1034
+ /** Loads `candidate` inside a `node_modules` package as a file, then as a directory. */
1035
+ loadFromNodeModulesPackage(extensions, candidate, rest, packageInfo) {
1036
+ if (rest !== '' || !this.esmMode) {
1037
+ const fromFile = this.loadModuleFromFile(extensions, candidate);
1038
+ if (fromFile !== undefined) {
1039
+ fromFile.packageId = this.getPackageId(fromFile.path, packageInfo);
1040
+ return fromFile;
1041
+ }
1042
+ }
1043
+ const fromDirectory = this.loadNodeModuleFromDirectoryWorker(extensions, candidate, packageInfo);
1044
+ if (fromDirectory !== undefined) {
1045
+ fromDirectory.packageId = this.getPackageId(fromDirectory.path, packageInfo);
1046
+ return fromDirectory;
1047
+ }
1048
+ const contents = packageInfo?.contents;
1049
+ if (rest === '' &&
1050
+ contents !== undefined &&
1051
+ (contents.exports === undefined || contents.exports.type === 'null') &&
1052
+ this.esmMode) {
1053
+ // ESM skips index lookups, but a package without `main` or `exports` still defaults to `index.js`.
1054
+ const index = this.loadModuleFromFile(extensions, combinePaths(candidate, 'index.js'));
1055
+ if (index !== undefined) {
1056
+ index.packageId = this.getPackageId(index.path, packageInfo);
1057
+ return index;
1058
+ }
1059
+ }
1060
+ return undefined;
1061
+ }
1062
+ createResolvedModuleHandlingSymlink(resolved) {
1063
+ const isExternalLibraryImport = resolved !== undefined && resolved.path.includes('/node_modules/');
1064
+ if (resolved !== undefined &&
1065
+ this.options.preserveSymlinks !== true &&
1066
+ isExternalLibraryImport &&
1067
+ resolved.originalPath === '' &&
1068
+ !isExternalModuleNameRelative(this.name)) {
1069
+ const real = this.realPathIfDifferent(resolved.path);
1070
+ if (real !== '') {
1071
+ resolved.originalPath = resolved.path;
1072
+ resolved.path = real;
1073
+ }
1074
+ }
1075
+ return this.createResolvedModule(resolved, isExternalLibraryImport);
1076
+ }
1077
+ /** The real path of `path`, or `''` if it is the same path. */
1078
+ realPathIfDifferent(path) {
1079
+ const real = this.realPath(path);
1080
+ // A real path differing only in case keeps the original spelling for forceConsistentCasingInFileNames.
1081
+ const caseSensitive = this.host.useCaseSensitiveFileNames();
1082
+ return comparePaths(path, real, caseSensitive, this.host.getCurrentDirectory()) !== 0 ? real : '';
1083
+ }
1084
+ createResolvedModule(resolved, isExternalLibraryImport) {
1085
+ const diagnostics = this.diagnostics.length === 0 ? NO_DIAGNOSTICS : this.diagnostics;
1086
+ if (resolved === undefined)
1087
+ return unresolvedModule(diagnostics);
1088
+ return {
1089
+ resolvedFileName: resolved.path,
1090
+ originalPath: resolved.originalPath,
1091
+ extension: resolved.extension,
1092
+ resolvedUsingTsExtension: resolved.resolvedUsingTsExtension,
1093
+ packageId: resolved.packageId,
1094
+ isExternalLibraryImport,
1095
+ alternateResult: '',
1096
+ resolutionDiagnostics: diagnostics,
1097
+ };
1098
+ }
1099
+ createResolvedTypeReferenceDirective(resolved, primary) {
1100
+ const result = {
1101
+ resolvedFileName: '',
1102
+ originalPath: '',
1103
+ primary: false,
1104
+ packageId: undefined,
1105
+ isExternalLibraryImport: false,
1106
+ resolutionDiagnostics: this.diagnostics.length === 0 ? NO_DIAGNOSTICS : this.diagnostics,
1107
+ };
1108
+ if (resolved === undefined || resolved.path === '')
1109
+ return result;
1110
+ if (!extensionIsTs(resolved.extension))
1111
+ throw new Error('expected a TypeScript file extension');
1112
+ result.resolvedFileName = resolved.path;
1113
+ result.primary = primary;
1114
+ result.packageId = resolved.packageId;
1115
+ result.isExternalLibraryImport = resolved.path.includes('/node_modules/');
1116
+ if (this.options.preserveSymlinks !== true) {
1117
+ const real = this.realPathIfDifferent(resolved.path);
1118
+ if (real !== '') {
1119
+ result.resolvedFileName = real;
1120
+ result.originalPath = resolved.path;
1121
+ }
1122
+ }
1123
+ return result;
1124
+ }
1125
+ //// paths and rootDirs
1126
+ tryLoadModuleUsingOptionalResolutionSettings() {
1127
+ const fromPaths = this.tryLoadModuleUsingPathsIfEligible();
1128
+ if (fromPaths !== undefined)
1129
+ return fromPaths;
1130
+ // baseUrl lookups were removed; rootDirs only apply to relative names.
1131
+ return isExternalModuleNameRelative(this.name) ? this.tryLoadModuleUsingRootDirs() : undefined;
1132
+ }
1133
+ getPathPatterns() {
1134
+ if (this.options === this.resolver.options)
1135
+ return this.resolver.getPathPatterns();
1136
+ if (this.pathPatterns === undefined)
1137
+ this.pathPatterns = parsePatterns(this.options.paths ?? new Map());
1138
+ return this.pathPatterns;
1139
+ }
1140
+ tryLoadModuleUsingPathsIfEligible() {
1141
+ const paths = this.options.paths;
1142
+ if (paths === undefined || paths.size === 0 || pathIsRelative(this.name))
1143
+ return undefined;
1144
+ if (this.traces !== undefined) {
1145
+ this.trace(1260 /* Diagnostics.X_paths_option_is_specified_looking_for_a_pattern_to_match_module_name_0 */, this.name);
1146
+ }
1147
+ const baseDirectory = this.options.pathsBasePath !== undefined && this.options.pathsBasePath !== ''
1148
+ ? this.options.pathsBasePath
1149
+ : this.host.getCurrentDirectory();
1150
+ return this.tryLoadModuleUsingPaths(this.extensions, this.name, baseDirectory, paths, this.getPathPatterns(), RELATIVE_LOADER);
1151
+ }
1152
+ tryLoadModuleUsingPaths(extensions, moduleName, containingDirectory, paths, patterns, loader) {
1153
+ const pattern = matchPatternOrExact(patterns, moduleName);
1154
+ if (pattern === undefined)
1155
+ return undefined;
1156
+ const star = matchedText(pattern, moduleName);
1157
+ if (this.traces !== undefined)
1158
+ this.trace(1261 /* Diagnostics.Module_name_0_matched_pattern_1 */, moduleName, pattern.text);
1159
+ for (const substitution of paths.get(pattern.text) ?? []) {
1160
+ const path = replaceFirstStar(substitution, star);
1161
+ const candidate = normalizePath(combinePaths(containingDirectory, path));
1162
+ if (this.traces !== undefined) {
1163
+ this.trace(1262 /* Diagnostics.Trying_substitution_0_candidate_module_location_Colon_1 */, substitution, path);
1164
+ }
1165
+ // A substitution may name a file with its extension.
1166
+ const extension = tryGetExtensionFromPath(substitution);
1167
+ if (extension !== '') {
1168
+ const found = this.tryFile(candidate);
1169
+ if (found !== undefined)
1170
+ return resolvedFile(found, extension, false);
1171
+ }
1172
+ const saved = this.candidateEndingIsFromConfig;
1173
+ if (extension !== '')
1174
+ this.candidateEndingIsFromConfig = true;
1175
+ const resolved = this.runLoader(loader, extensions, candidate);
1176
+ this.candidateEndingIsFromConfig = saved;
1177
+ if (resolved !== undefined)
1178
+ return resolved;
1179
+ }
1180
+ return undefined;
1181
+ }
1182
+ runLoader(loader, extensions, candidate) {
1183
+ switch (loader.kind) {
1184
+ case 'relative':
1185
+ return this.nodeLoadModuleByRelativeName(extensions, candidate, true);
1186
+ case 'package':
1187
+ return this.loadFromNodeModulesPackage(extensions, candidate, loader.rest, loader.packageInfo);
1188
+ case 'directory':
1189
+ return this.loadFromPackageJsonEntry(extensions, candidate, loader.packageFile, loader.packageInfo);
1190
+ }
1191
+ }
1192
+ tryLoadModuleUsingRootDirs() {
1193
+ const rootDirs = this.options.rootDirs;
1194
+ if (rootDirs === undefined || rootDirs.length === 0)
1195
+ return undefined;
1196
+ const traces = this.traces;
1197
+ if (traces !== undefined)
1198
+ this.trace(1275 /* Diagnostics.X_rootDirs_option_is_set_using_it_to_resolve_relative_module_name_0 */, this.name);
1199
+ const candidate = normalizePath(combinePaths(this.containingDirectory, this.name));
1200
+ let matchedRootDir = '';
1201
+ let matchedPrefix = '';
1202
+ for (const rootDir of rootDirs) {
1203
+ const normalizedRoot = ensureTrailingDirectorySeparator(normalizePath(rootDir));
1204
+ const isLongest = candidate.startsWith(normalizedRoot) && (matchedPrefix === '' || matchedPrefix.length < normalizedRoot.length);
1205
+ if (traces !== undefined) {
1206
+ this.trace(1272 /* Diagnostics.Checking_if_0_is_the_longest_matching_prefix_for_1_2 */, normalizedRoot, candidate, String(isLongest));
1207
+ }
1208
+ if (isLongest) {
1209
+ matchedPrefix = normalizedRoot;
1210
+ matchedRootDir = rootDir;
1211
+ }
1212
+ }
1213
+ if (matchedPrefix === '')
1214
+ return undefined;
1215
+ if (traces !== undefined)
1216
+ this.trace(1276 /* Diagnostics.Longest_matching_prefix_for_0_is_1 */, candidate, matchedPrefix);
1217
+ const suffix = candidate.slice(matchedPrefix.length);
1218
+ if (traces !== undefined)
1219
+ this.trace(1277 /* Diagnostics.Loading_0_from_the_root_dir_1_candidate_location_2 */, suffix, matchedPrefix, candidate);
1220
+ const initial = this.nodeLoadModuleByRelativeName(this.extensions, candidate, true);
1221
+ if (initial !== undefined)
1222
+ return initial;
1223
+ if (traces !== undefined)
1224
+ this.trace(1278 /* Diagnostics.Trying_other_entries_in_rootDirs */);
1225
+ for (const rootDir of rootDirs) {
1226
+ if (rootDir === matchedRootDir)
1227
+ continue;
1228
+ const other = combinePaths(normalizePath(rootDir), suffix);
1229
+ if (traces !== undefined)
1230
+ this.trace(1277 /* Diagnostics.Loading_0_from_the_root_dir_1_candidate_location_2 */, suffix, rootDir, other);
1231
+ const resolved = this.nodeLoadModuleByRelativeName(this.extensions, other, true);
1232
+ if (resolved !== undefined)
1233
+ return resolved;
1234
+ }
1235
+ if (traces !== undefined)
1236
+ this.trace(1279 /* Diagnostics.Module_resolution_using_rootDirs_has_failed */);
1237
+ return undefined;
1238
+ }
1239
+ //// Files and directories
1240
+ nodeLoadModuleByRelativeName(extensions, candidate, considerPackageJson) {
1241
+ if (this.traces !== undefined) {
1242
+ this.trace(1264 /* Diagnostics.Loading_module_as_file_Slash_folder_candidate_module_location_0_target_file_types_Colon_1 */, candidate, extensionsToString(extensions));
1243
+ }
1244
+ if (!hasTrailingDirectorySeparator(candidate)) {
1245
+ const parent = getDirectoryPath(candidate);
1246
+ if (!this.host.directoryExists(parent)) {
1247
+ if (this.traces !== undefined)
1248
+ this.trace(1311 /* Diagnostics.Directory_0_does_not_exist_skipping_all_lookups_in_it */, parent);
1249
+ return undefined;
1250
+ }
1251
+ const fromFile = this.loadModuleFromFile(extensions, candidate);
1252
+ if (fromFile !== undefined) {
1253
+ if (considerPackageJson)
1254
+ this.setPackageIdFromNodeModulesPath(fromFile);
1255
+ return fromFile;
1256
+ }
1257
+ }
1258
+ if (!this.host.directoryExists(candidate)) {
1259
+ if (this.traces !== undefined)
1260
+ this.trace(1311 /* Diagnostics.Directory_0_does_not_exist_skipping_all_lookups_in_it */, candidate);
1261
+ return undefined;
1262
+ }
1263
+ // ESM relative imports do no directory lookups (neither package.json nor index files).
1264
+ return this.esmMode ? undefined : this.loadNodeModuleFromDirectory(extensions, candidate, considerPackageJson);
1265
+ }
1266
+ loadModuleFromFile(extensions, candidate) {
1267
+ // ./foo.js -> ./foo.ts
1268
+ const replaced = this.loadModuleFromFileNoImplicitExtensions(extensions, candidate);
1269
+ if (replaced !== undefined)
1270
+ return replaced;
1271
+ // ./foo -> ./foo.ts
1272
+ return this.esmMode ? undefined : this.tryAddingExtensions(candidate, extensions, '');
1273
+ }
1274
+ loadModuleFromFileNoImplicitExtensions(extensions, candidate) {
1275
+ // Extensionless files are not supported.
1276
+ if (!getBaseFileName(candidate).includes('.'))
1277
+ return undefined;
1278
+ let extensionless = removeFileExtension(candidate);
1279
+ // Unknown extensions map to declaration files such as `.d.css.ts`.
1280
+ if (extensionless === candidate)
1281
+ extensionless = candidate.slice(0, candidate.lastIndexOf('.'));
1282
+ const extension = candidate.slice(extensionless.length);
1283
+ if (this.traces !== undefined)
1284
+ this.trace(1297 /* Diagnostics.File_name_0_has_a_1_extension_stripping_it */, candidate, extension);
1285
+ return this.tryAddingExtensions(extensionless, extensions, extension);
1286
+ }
1287
+ tryAddingExtensions(extensionless, extensions, originalExtension) {
1288
+ const directory = getDirectoryPath(extensionless);
1289
+ if (directory !== '' && !this.host.directoryExists(directory))
1290
+ return undefined;
1291
+ const ts = (extensions & 1 /* Extensions.TypeScript */) !== 0;
1292
+ const dts = (extensions & 4 /* Extensions.Declaration */) !== 0;
1293
+ const js = (extensions & 2 /* Extensions.JavaScript */) !== 0;
1294
+ switch (originalExtension) {
1295
+ case '.mjs':
1296
+ case '.mts':
1297
+ case '.d.mts': {
1298
+ const usingTs = originalExtension === '.mts' || originalExtension === '.d.mts';
1299
+ return ((ts ? this.tryExtension('.mts', extensionless, usingTs) : undefined) ??
1300
+ (dts ? this.tryExtension('.d.mts', extensionless, usingTs) : undefined) ??
1301
+ (js ? this.tryExtension('.mjs', extensionless, false) : undefined));
1302
+ }
1303
+ case '.cjs':
1304
+ case '.cts':
1305
+ case '.d.cts': {
1306
+ const usingTs = originalExtension === '.cts' || originalExtension === '.d.cts';
1307
+ return ((ts ? this.tryExtension('.cts', extensionless, usingTs) : undefined) ??
1308
+ (dts ? this.tryExtension('.d.cts', extensionless, usingTs) : undefined) ??
1309
+ (js ? this.tryExtension('.cjs', extensionless, false) : undefined));
1310
+ }
1311
+ case '.json':
1312
+ return ((dts ? this.tryExtension('.d.json.ts', extensionless, false) : undefined) ??
1313
+ ((extensions & 8 /* Extensions.Json */) !== 0 ? this.tryExtension('.json', extensionless, false) : undefined));
1314
+ case '.tsx':
1315
+ case '.jsx': {
1316
+ // Prefer an exact .tsx/.jsx match before the .ts/.js file.
1317
+ const usingTs = originalExtension === '.tsx';
1318
+ return ((ts
1319
+ ? (this.tryExtension('.tsx', extensionless, usingTs) ?? this.tryExtension('.ts', extensionless, usingTs))
1320
+ : undefined) ??
1321
+ (dts ? this.tryExtension('.d.ts', extensionless, usingTs) : undefined) ??
1322
+ (js
1323
+ ? (this.tryExtension('.jsx', extensionless, false) ?? this.tryExtension('.js', extensionless, false))
1324
+ : undefined));
1325
+ }
1326
+ case '.ts':
1327
+ case '.d.ts':
1328
+ case '.js':
1329
+ case '': {
1330
+ const usingTs = originalExtension === '.ts' || originalExtension === '.d.ts';
1331
+ return ((ts
1332
+ ? (this.tryExtension('.ts', extensionless, usingTs) ?? this.tryExtension('.tsx', extensionless, usingTs))
1333
+ : undefined) ??
1334
+ (dts ? this.tryExtension('.d.ts', extensionless, usingTs) : undefined) ??
1335
+ (js
1336
+ ? (this.tryExtension('.js', extensionless, false) ?? this.tryExtension('.jsx', extensionless, false))
1337
+ : undefined) ??
1338
+ (this.isConfigLookup ? this.tryExtension('.json', extensionless, false) : undefined));
1339
+ }
1340
+ default:
1341
+ if (dts && !isDeclarationFileName(extensionless + originalExtension)) {
1342
+ return this.tryExtension('.d' + originalExtension + '.ts', extensionless, false);
1343
+ }
1344
+ return undefined;
1345
+ }
1346
+ }
1347
+ tryExtension(extension, extensionless, resolvedUsingTsExtension) {
1348
+ const path = this.tryFile(extensionless + extension);
1349
+ if (path === undefined)
1350
+ return undefined;
1351
+ return resolvedFile(path, extension, !this.candidateEndingIsFromConfig && resolvedUsingTsExtension);
1352
+ }
1353
+ /** The existing file for `fileName`, trying each of `moduleSuffixes`. */
1354
+ tryFile(fileName) {
1355
+ const suffixes = this.options.moduleSuffixes;
1356
+ if (suffixes === undefined || suffixes.length === 0)
1357
+ return this.tryFileLookup(fileName) ? fileName : undefined;
1358
+ const extension = tryGetExtensionFromPath(fileName);
1359
+ const withoutExtension = removeExtension(fileName, extension);
1360
+ for (const suffix of suffixes) {
1361
+ const path = withoutExtension + suffix + extension;
1362
+ if (this.tryFileLookup(path))
1363
+ return path;
1364
+ }
1365
+ return undefined;
1366
+ }
1367
+ tryFileLookup(fileName) {
1368
+ if (this.host.fileExists(fileName)) {
1369
+ if (this.traces !== undefined)
1370
+ this.trace(1266 /* Diagnostics.File_0_exists_use_it_as_a_name_resolution_result */, fileName);
1371
+ return true;
1372
+ }
1373
+ if (this.traces !== undefined)
1374
+ this.trace(1265 /* Diagnostics.File_0_does_not_exist */, fileName);
1375
+ return false;
1376
+ }
1377
+ loadNodeModuleFromDirectory(extensions, candidate, considerPackageJson) {
1378
+ const packageInfo = considerPackageJson ? this.getPackageJsonInfo(candidate) : undefined;
1379
+ return this.loadNodeModuleFromDirectoryWorker(extensions, candidate, packageInfo);
1380
+ }
1381
+ loadNodeModuleFromDirectoryWorker(extensions, candidate, packageInfo) {
1382
+ let packageFile = '';
1383
+ let versionPaths;
1384
+ const contents = packageInfo?.contents;
1385
+ if (packageInfo !== undefined && contents !== undefined) {
1386
+ versionPaths = contents.getVersionPaths(this.traces);
1387
+ if (comparePaths(candidate, packageInfo.packageDirectory, this.host.useCaseSensitiveFileNames()) === 0) {
1388
+ packageFile = this.getPackageFile(extensions, packageInfo);
1389
+ }
1390
+ }
1391
+ const indexPath = combinePaths(candidate, this.isConfigLookup ? 'tsconfig' : 'index');
1392
+ if (versionPaths !== undefined && (packageFile === '' || containsPath(candidate, packageFile, false))) {
1393
+ const moduleName = getRelativePathFromDirectory(candidate, packageFile !== '' ? packageFile : indexPath, false);
1394
+ if (this.traces !== undefined) {
1395
+ this.trace(1361 /* Diagnostics.X_package_json_has_a_typesVersions_entry_0_that_matches_compiler_version_1_looking_for_a_pattern_to_match_module_name_2 */, versionPaths.version, typeScriptVersion, moduleName);
1396
+ }
1397
+ const result = this.tryLoadModuleUsingPaths(extensions, moduleName, candidate, versionPaths.paths, parsePatterns(versionPaths.paths), { kind: 'directory', packageFile, packageInfo });
1398
+ if (result !== undefined)
1399
+ return result;
1400
+ }
1401
+ if (packageFile !== '') {
1402
+ const result = this.loadFromPackageJsonEntry(extensions, packageFile, packageFile, packageInfo);
1403
+ if (result !== undefined)
1404
+ return result;
1405
+ }
1406
+ // ESM resolutions do no index lookups.
1407
+ if (this.esmMode || !this.host.directoryExists(candidate))
1408
+ return undefined;
1409
+ return this.loadModuleFromFile(extensions, indexPath);
1410
+ }
1411
+ /** Loads a `main`/`types` entry (or a typesVersions substitution for it). */
1412
+ loadFromPackageJsonEntry(extensions, candidate, packageFile, packageInfo) {
1413
+ const fromFile = this.loadFileNameFromPackageJsonField(extensions, candidate, packageFile);
1414
+ if (fromFile !== undefined)
1415
+ return fromFile;
1416
+ // `types` may point at a .ts file even for declaration-only lookups.
1417
+ const expanded = extensions === 4 /* Extensions.Declaration */ ? 1 /* Extensions.TypeScript */ | 4 /* Extensions.Declaration */ : extensions;
1418
+ // CommonJS packages may omit extensions in `main`, even from ESM importers.
1419
+ const savedEsmMode = this.esmMode;
1420
+ const savedEnding = this.candidateEndingIsFromConfig;
1421
+ this.candidateEndingIsFromConfig = true;
1422
+ if (packageInfo?.contents !== undefined && packageInfo.contents.type.value !== 'module')
1423
+ this.esmMode = false;
1424
+ const result = this.nodeLoadModuleByRelativeName(expanded, candidate, false);
1425
+ this.esmMode = savedEsmMode;
1426
+ this.candidateEndingIsFromConfig = savedEnding;
1427
+ return result;
1428
+ }
1429
+ /**
1430
+ * Loads a path written in package.json. TS extensions are allowed as is; JS extensions are also tried as their
1431
+ * TS counterparts.
1432
+ */
1433
+ loadFileNameFromPackageJsonField(extensions, candidate, packageJsonValue) {
1434
+ if (((extensions & 1 /* Extensions.TypeScript */) !== 0 && hasImplementationTSFileExtension(candidate)) ||
1435
+ ((extensions & 4 /* Extensions.Declaration */) !== 0 && isDeclarationFileName(candidate))) {
1436
+ const path = this.tryFile(candidate);
1437
+ if (path === undefined)
1438
+ return undefined;
1439
+ const extension = tryExtractTSExtension(path);
1440
+ // True when a trailing `*` matched a TS extension written in the specifier.
1441
+ return resolvedFile(path, extension, packageJsonValue.endsWith('*') && extension !== '');
1442
+ }
1443
+ if (this.isConfigLookup && (extensions & 8 /* Extensions.Json */) !== 0 && fileExtensionIs(candidate, '.json')) {
1444
+ const path = this.tryFile(candidate);
1445
+ if (path !== undefined)
1446
+ return resolvedFile(path, '.json', false);
1447
+ }
1448
+ return this.loadModuleFromFileNoImplicitExtensions(extensions, candidate);
1449
+ }
1450
+ getPackageFile(extensions, packageInfo) {
1451
+ const contents = packageInfo.contents;
1452
+ if (contents === undefined)
1453
+ return '';
1454
+ const directory = packageInfo.packageDirectory;
1455
+ if (this.isConfigLookup)
1456
+ return this.getPackageJsonPathField('tsconfig', contents.tsconfig, directory);
1457
+ if ((extensions & 4 /* Extensions.Declaration */) !== 0) {
1458
+ const typings = this.getPackageJsonPathField('typings', contents.typings, directory);
1459
+ if (typings !== '')
1460
+ return typings;
1461
+ const types = this.getPackageJsonPathField('types', contents.types, directory);
1462
+ if (types !== '')
1463
+ return types;
1464
+ }
1465
+ if ((extensions & (3 /* Extensions.ImplementationFiles */ | 4 /* Extensions.Declaration */)) !== 0) {
1466
+ return this.getPackageJsonPathField('main', contents.main, directory);
1467
+ }
1468
+ return '';
1469
+ }
1470
+ //// package.json
1471
+ getPackageJsonInfo(packageDirectory) {
1472
+ const packageJsonPath = combinePaths(packageDirectory, 'package.json');
1473
+ const cache = this.resolver.packageJsonInfoCache;
1474
+ const existing = cache.get(packageJsonPath);
1475
+ if (existing !== undefined) {
1476
+ if (existing.contents !== undefined) {
1477
+ if (this.traces !== undefined)
1478
+ this.trace(1391 /* Diagnostics.File_0_exists_according_to_earlier_cached_lookups */, packageJsonPath);
1479
+ return withPackageDirectory(existing, packageDirectory);
1480
+ }
1481
+ if (existing.directoryExists && this.traces !== undefined) {
1482
+ this.trace(1392 /* Diagnostics.File_0_does_not_exist_according_to_earlier_cached_lookups */, packageJsonPath);
1483
+ }
1484
+ return undefined;
1485
+ }
1486
+ const directoryExists = this.host.directoryExists(packageDirectory);
1487
+ if (directoryExists && this.host.fileExists(packageJsonPath)) {
1488
+ const contents = parsePackageJson(this.host.readFile(packageJsonPath) ?? '');
1489
+ if (this.traces !== undefined)
1490
+ this.trace(1268 /* Diagnostics.Found_package_json_at_0 */, packageJsonPath);
1491
+ const stored = cache.set(packageJsonPath, { packageDirectory, directoryExists: true, contents });
1492
+ return withPackageDirectory(stored, packageDirectory);
1493
+ }
1494
+ if (directoryExists && this.traces !== undefined)
1495
+ this.trace(1265 /* Diagnostics.File_0_does_not_exist */, packageJsonPath);
1496
+ cache.set(packageJsonPath, { packageDirectory, directoryExists, contents: undefined });
1497
+ return undefined;
1498
+ }
1499
+ getPackageId(resolvedFileName, packageInfo) {
1500
+ const contents = packageInfo?.contents;
1501
+ if (packageInfo === undefined || contents === undefined)
1502
+ return undefined;
1503
+ const name = contents.name.value;
1504
+ const version = contents.version.value;
1505
+ if (name === undefined || version === undefined)
1506
+ return undefined;
1507
+ const directory = packageInfo.packageDirectory;
1508
+ return {
1509
+ name,
1510
+ version,
1511
+ subModuleName: resolvedFileName.length > directory.length ? resolvedFileName.slice(directory.length + 1) : '',
1512
+ peerDependencies: this.readPeerDependencies(packageInfo),
1513
+ };
1514
+ }
1515
+ readPeerDependencies(packageInfo) {
1516
+ const field = packageInfo.contents?.peerDependencies;
1517
+ if (field === undefined || !this.validatePackageJsonField('peerDependencies', field, 'object'))
1518
+ return '';
1519
+ const peers = field.value;
1520
+ if (peers === undefined || peers.size === 0)
1521
+ return '';
1522
+ if (this.traces !== undefined)
1523
+ this.trace(1430 /* Diagnostics.X_package_json_has_a_peerDependencies_field */);
1524
+ const packageDirectory = this.realPath(packageInfo.packageDirectory);
1525
+ const index = packageDirectory.lastIndexOf('/node_modules');
1526
+ if (index === -1)
1527
+ return '';
1528
+ const nodeModules = packageDirectory.slice(0, index + 13) + '/';
1529
+ const names = [...peers.keys()].sort();
1530
+ let result = '';
1531
+ for (const name of names) {
1532
+ const peer = this.getPackageJsonInfo(nodeModules + name);
1533
+ const peerContents = peer?.contents;
1534
+ if (peerContents !== undefined) {
1535
+ const version = peerContents.version.value ?? '';
1536
+ result += '+' + name + '@' + version;
1537
+ if (this.traces !== undefined)
1538
+ this.trace(1431 /* Diagnostics.Found_peerDependency_0_with_1_version */, name, version);
1539
+ }
1540
+ else if (this.traces !== undefined) {
1541
+ this.trace(1432 /* Diagnostics.Failed_to_find_peerDependency_0 */, name);
1542
+ }
1543
+ }
1544
+ return result;
1545
+ }
1546
+ realPath(path) {
1547
+ const real = normalizePath(this.host.realpath(path));
1548
+ if (this.traces !== undefined)
1549
+ this.trace(1295 /* Diagnostics.Resolving_real_path_for_0_result_1 */, path, real);
1550
+ return real;
1551
+ }
1552
+ validatePackageJsonField(fieldName, field, expectedType) {
1553
+ if (field.actualType !== undefined) {
1554
+ if (field.value !== undefined)
1555
+ return true;
1556
+ if (this.traces !== undefined) {
1557
+ this.trace(1273 /* Diagnostics.Expected_type_of_0_field_in_package_json_to_be_1_got_2 */, fieldName, expectedType, field.actualType);
1558
+ }
1559
+ }
1560
+ if (this.traces !== undefined)
1561
+ this.trace(1269 /* Diagnostics.X_package_json_does_not_have_a_0_field */, fieldName);
1562
+ return false;
1563
+ }
1564
+ /** The normalized path a string field points at, or `''`. */
1565
+ getPackageJsonPathField(fieldName, field, directory) {
1566
+ if (!this.validatePackageJsonField(fieldName, field, 'string'))
1567
+ return '';
1568
+ const value = field.value ?? '';
1569
+ if (value === '') {
1570
+ if (this.traces !== undefined)
1571
+ this.trace(1373 /* Diagnostics.X_package_json_had_a_falsy_0_field */, fieldName);
1572
+ return '';
1573
+ }
1574
+ const path = normalizePath(combinePaths(directory, value));
1575
+ if (this.traces !== undefined)
1576
+ this.trace(1270 /* Diagnostics.X_package_json_has_0_field_1_that_references_2 */, fieldName, value, path);
1577
+ return path;
1578
+ }
1579
+ conditionMatches(condition) {
1580
+ if (condition === 'default' || this.conditions.includes(condition))
1581
+ return true;
1582
+ // Versioned types conditions only apply along with `types`.
1583
+ return this.conditions.includes('types') && isApplicableVersionedTypesKey(condition);
1584
+ }
1585
+ }
1586
+ const OUTPUT_EXTENSIONS = ['.mjs', '.cjs', '.js', '.json', '.d.mts', '.d.cts', '.d.ts'];
1587
+ function bundlerFeatures(options) {
1588
+ let features = 31 /* Features.BundlerDefault */;
1589
+ if (options.resolvePackageJsonExports === true)
1590
+ features |= 4 /* Features.Exports */;
1591
+ else if (options.resolvePackageJsonExports === false)
1592
+ features &= ~4 /* Features.Exports */;
1593
+ if (options.resolvePackageJsonImports === true)
1594
+ features |= 1 /* Features.Imports */;
1595
+ else if (options.resolvePackageJsonImports === false)
1596
+ features &= ~1 /* Features.Imports */;
1597
+ return features;
1598
+ }