tsc-ts 0.0.10 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (367) hide show
  1. package/README.md +1 -1
  2. package/bin/tsc-ts.js +70 -1
  3. package/dist/api/compiler/ast-utilities.d.ts +19 -1
  4. package/dist/api/compiler/ast-utilities.js +180 -95
  5. package/dist/api/compiler/ast.d.ts +20 -15
  6. package/dist/api/compiler/ast.js +1023 -995
  7. package/dist/api/compiler/astnav.js +15 -15
  8. package/dist/api/compiler/binder-utilities.js +186 -186
  9. package/dist/api/compiler/binder.js +290 -263
  10. package/dist/api/compiler/character-codes.js +2 -2
  11. package/dist/api/compiler/checker-calls.js +173 -123
  12. package/dist/api/compiler/checker-classes.d.ts +14 -3
  13. package/dist/api/compiler/checker-classes.js +134 -90
  14. package/dist/api/compiler/checker-contextual.js +64 -61
  15. package/dist/api/compiler/checker-declaration-order.js +79 -79
  16. package/dist/api/compiler/checker-declarations.d.ts +1 -0
  17. package/dist/api/compiler/checker-declarations.js +160 -136
  18. package/dist/api/compiler/checker-declared-types.js +67 -65
  19. package/dist/api/compiler/checker-decorators.js +77 -77
  20. package/dist/api/compiler/checker-deprecation.d.ts +8 -3
  21. package/dist/api/compiler/checker-deprecation.js +76 -55
  22. package/dist/api/compiler/checker-destructuring.js +47 -45
  23. package/dist/api/compiler/checker-elaboration.js +24 -24
  24. package/dist/api/compiler/checker-emit-helpers.js +4 -4
  25. package/dist/api/compiler/checker-emit-resolver.d.ts +4 -2
  26. package/dist/api/compiler/checker-emit-resolver.js +25 -13
  27. package/dist/api/compiler/checker-evaluator.js +9 -9
  28. package/dist/api/compiler/checker-expressions.js +244 -211
  29. package/dist/api/compiler/checker-functions.js +113 -107
  30. package/dist/api/compiler/checker-generated-code.d.ts +0 -11
  31. package/dist/api/compiler/checker-generated-code.js +28 -52
  32. package/dist/api/compiler/checker-grammar.d.ts +1 -0
  33. package/dist/api/compiler/checker-grammar.js +469 -438
  34. package/dist/api/compiler/checker-heritage.js +91 -93
  35. package/dist/api/compiler/checker-inference.d.ts +77 -5
  36. package/dist/api/compiler/checker-inference.js +487 -113
  37. package/dist/api/compiler/checker-iteration.d.ts +0 -10
  38. package/dist/api/compiler/checker-iteration.js +35 -52
  39. package/dist/api/compiler/checker-javascript.js +14 -14
  40. package/dist/api/compiler/checker-jsdoc.d.ts +8 -10
  41. package/dist/api/compiler/checker-jsdoc.js +67 -58
  42. package/dist/api/compiler/checker-jsx.js +105 -88
  43. package/dist/api/compiler/checker-members.d.ts +9 -2
  44. package/dist/api/compiler/checker-members.js +210 -74
  45. package/dist/api/compiler/checker-modules.d.ts +15 -6
  46. package/dist/api/compiler/checker-modules.js +469 -309
  47. package/dist/api/compiler/checker-narrowing.js +273 -189
  48. package/dist/api/compiler/checker-object-literals.js +25 -22
  49. package/dist/api/compiler/checker-operators.js +126 -118
  50. package/dist/api/compiler/checker-overloads.js +27 -27
  51. package/dist/api/compiler/checker-property-access.js +59 -55
  52. package/dist/api/compiler/checker-services.d.ts +1 -0
  53. package/dist/api/compiler/checker-services.js +222 -210
  54. package/dist/api/compiler/checker-signatures.js +65 -49
  55. package/dist/api/compiler/checker-source-file.d.ts +5 -0
  56. package/dist/api/compiler/checker-source-file.js +154 -130
  57. package/dist/api/compiler/checker-statements.js +33 -32
  58. package/dist/api/compiler/checker-super.js +50 -50
  59. package/dist/api/compiler/checker-symbol-types.js +109 -93
  60. package/dist/api/compiler/checker-symbols.d.ts +13 -1
  61. package/dist/api/compiler/checker-symbols.js +264 -149
  62. package/dist/api/compiler/checker-type-factory.d.ts +5 -0
  63. package/dist/api/compiler/checker-type-factory.js +137 -34
  64. package/dist/api/compiler/checker-type-nodes.d.ts +1 -0
  65. package/dist/api/compiler/checker-type-nodes.js +179 -141
  66. package/dist/api/compiler/checker-type-operators.d.ts +2 -0
  67. package/dist/api/compiler/checker-type-operators.js +110 -63
  68. package/dist/api/compiler/checker-types.d.ts +80 -3
  69. package/dist/api/compiler/checker-types.js +121 -2
  70. package/dist/api/compiler/checker-unused.js +114 -118
  71. package/dist/api/compiler/checker-utilities.js +11 -11
  72. package/dist/api/compiler/checker.d.ts +93 -31
  73. package/dist/api/compiler/checker.js +143 -35
  74. package/dist/api/compiler/command-line.d.ts +1 -3
  75. package/dist/api/compiler/command-line.js +47 -44
  76. package/dist/api/compiler/compile-program.d.ts +19 -4
  77. package/dist/api/compiler/compile-program.js +45 -26
  78. package/dist/api/compiler/diagnostic-messages.d.ts +1849 -1774
  79. package/dist/api/compiler/diagnostic-messages.js +128 -122
  80. package/dist/api/compiler/diagnostics.js +7 -7
  81. package/dist/api/compiler/emitter.d.ts +7 -1
  82. package/dist/api/compiler/emitter.js +53 -11
  83. package/dist/api/compiler/file-include.d.ts +2 -1
  84. package/dist/api/compiler/file-include.js +11 -7
  85. package/dist/api/compiler/file-loader.d.ts +10 -0
  86. package/dist/api/compiler/file-loader.js +138 -41
  87. package/dist/api/compiler/instantiation.d.ts +7 -0
  88. package/dist/api/compiler/instantiation.js +101 -49
  89. package/dist/api/compiler/jsdoc.js +23 -23
  90. package/dist/api/compiler/link-tables.d.ts +48 -18
  91. package/dist/api/compiler/link-tables.js +80 -37
  92. package/dist/api/compiler/locales/cs-CZ.d.ts +1 -1
  93. package/dist/api/compiler/locales/cs-CZ.js +1 -1
  94. package/dist/api/compiler/locales/de-DE.d.ts +1 -1
  95. package/dist/api/compiler/locales/de-DE.js +1 -1
  96. package/dist/api/compiler/locales/es-ES.d.ts +1 -1
  97. package/dist/api/compiler/locales/es-ES.js +1 -1
  98. package/dist/api/compiler/locales/fr-FR.d.ts +1 -1
  99. package/dist/api/compiler/locales/fr-FR.js +1 -1
  100. package/dist/api/compiler/locales/it-IT.d.ts +1 -1
  101. package/dist/api/compiler/locales/it-IT.js +1 -1
  102. package/dist/api/compiler/locales/ja-JP.d.ts +1 -1
  103. package/dist/api/compiler/locales/ja-JP.js +1 -1
  104. package/dist/api/compiler/locales/ko-KR.d.ts +1 -1
  105. package/dist/api/compiler/locales/ko-KR.js +1 -1
  106. package/dist/api/compiler/locales/pl-PL.d.ts +1 -1
  107. package/dist/api/compiler/locales/pl-PL.js +1 -1
  108. package/dist/api/compiler/locales/pt-BR.d.ts +1 -1
  109. package/dist/api/compiler/locales/pt-BR.js +1 -1
  110. package/dist/api/compiler/locales/ru-RU.d.ts +1 -1
  111. package/dist/api/compiler/locales/ru-RU.js +1 -1
  112. package/dist/api/compiler/locales/tr-TR.d.ts +1 -1
  113. package/dist/api/compiler/locales/tr-TR.js +1 -1
  114. package/dist/api/compiler/locales/zh-CN.d.ts +1 -1
  115. package/dist/api/compiler/locales/zh-CN.js +1 -1
  116. package/dist/api/compiler/locales/zh-TW.d.ts +1 -1
  117. package/dist/api/compiler/locales/zh-TW.js +1 -1
  118. package/dist/api/compiler/module-resolution-types.js +6 -6
  119. package/dist/api/compiler/module-resolution.d.ts +10 -1
  120. package/dist/api/compiler/module-resolution.js +115 -84
  121. package/dist/api/compiler/module-specifiers.d.ts +15 -0
  122. package/dist/api/compiler/module-specifiers.js +24 -18
  123. package/dist/api/compiler/name-resolver.js +74 -65
  124. package/dist/api/compiler/node-builder-names.d.ts +11 -3
  125. package/dist/api/compiler/node-builder-names.js +210 -90
  126. package/dist/api/compiler/node-builder-pseudo.js +29 -31
  127. package/dist/api/compiler/node-builder-reuse.js +23 -22
  128. package/dist/api/compiler/node-builder.d.ts +18 -1
  129. package/dist/api/compiler/node-builder.js +191 -102
  130. package/dist/api/compiler/option-declarations.d.ts +2 -6
  131. package/dist/api/compiler/option-declarations.js +315 -375
  132. package/dist/api/compiler/options.d.ts +15 -33
  133. package/dist/api/compiler/options.js +21 -54
  134. package/dist/api/compiler/output-paths.d.ts +4 -1
  135. package/dist/api/compiler/output-paths.js +6 -11
  136. package/dist/api/compiler/package-json.d.ts +3 -3
  137. package/dist/api/compiler/package-json.js +11 -10
  138. package/dist/api/compiler/parser.d.ts +40 -19
  139. package/dist/api/compiler/parser.js +308 -216
  140. package/dist/api/compiler/path.d.ts +9 -0
  141. package/dist/api/compiler/path.js +20 -3
  142. package/dist/api/compiler/printer/emit-context.d.ts +3 -1
  143. package/dist/api/compiler/printer/emit-context.js +16 -1
  144. package/dist/api/compiler/printer/factory-base.d.ts +2 -2
  145. package/dist/api/compiler/printer/factory-base.js +7 -3
  146. package/dist/api/compiler/printer/factory.js +3 -1
  147. package/dist/api/compiler/printer/helpers.js +10 -1
  148. package/dist/api/compiler/printer/name-generator.d.ts +1 -1
  149. package/dist/api/compiler/printer/name-generator.js +35 -16
  150. package/dist/api/compiler/printer/printer.d.ts +1 -0
  151. package/dist/api/compiler/printer/printer.js +303 -281
  152. package/dist/api/compiler/printer/utilities.js +149 -147
  153. package/dist/api/compiler/program-checker.d.ts +8 -2
  154. package/dist/api/compiler/program-checker.js +84 -34
  155. package/dist/api/compiler/program-utilities.d.ts +3 -1
  156. package/dist/api/compiler/program-utilities.js +28 -15
  157. package/dist/api/compiler/program.d.ts +2 -0
  158. package/dist/api/compiler/program.js +69 -57
  159. package/dist/api/compiler/pseudo-bigint.d.ts +2 -0
  160. package/dist/api/compiler/pseudo-bigint.js +18 -0
  161. package/dist/api/compiler/regexp-checker.d.ts +1 -1
  162. package/dist/api/compiler/regexp-checker.js +93 -76
  163. package/dist/api/compiler/relations.d.ts +27 -4
  164. package/dist/api/compiler/relations.js +337 -180
  165. package/dist/api/compiler/reparser.js +60 -56
  166. package/dist/api/compiler/scanner.d.ts +19 -2
  167. package/dist/api/compiler/scanner.js +123 -108
  168. package/dist/api/compiler/shared-results.d.ts +463 -0
  169. package/dist/api/compiler/shared-results.js +2128 -0
  170. package/dist/api/compiler/sourcemap.js +2 -2
  171. package/dist/api/compiler/symbol-accessibility.js +87 -74
  172. package/dist/api/compiler/symbol.d.ts +22 -13
  173. package/dist/api/compiler/symbol.js +15 -1
  174. package/dist/api/compiler/syntax-kind.d.ts +198 -197
  175. package/dist/api/compiler/transformers/alias-references.js +247 -139
  176. package/dist/api/compiler/transformers/async-utilities.js +25 -25
  177. package/dist/api/compiler/transformers/async.d.ts +0 -1
  178. package/dist/api/compiler/transformers/async.js +64 -77
  179. package/dist/api/compiler/transformers/class-fields.d.ts +1 -0
  180. package/dist/api/compiler/transformers/class-fields.js +81 -78
  181. package/dist/api/compiler/transformers/commonjs-module.js +18 -15
  182. package/dist/api/compiler/transformers/const-enum-inliner.js +1 -1
  183. package/dist/api/compiler/transformers/declarations-diagnostics.js +247 -244
  184. package/dist/api/compiler/transformers/declarations-pseudo.js +100 -100
  185. package/dist/api/compiler/transformers/declarations-resolver.d.ts +0 -3
  186. package/dist/api/compiler/transformers/declarations-syntactic.d.ts +1 -2
  187. package/dist/api/compiler/transformers/declarations-syntactic.js +134 -156
  188. package/dist/api/compiler/transformers/declarations-tracker.js +18 -18
  189. package/dist/api/compiler/transformers/declarations.d.ts +4 -1
  190. package/dist/api/compiler/transformers/declarations.js +305 -238
  191. package/dist/api/compiler/transformers/decorator-metadata.d.ts +1 -1
  192. package/dist/api/compiler/transformers/decorator-metadata.js +53 -45
  193. package/dist/api/compiler/transformers/decorator-utilities.js +24 -24
  194. package/dist/api/compiler/transformers/destructuring.js +19 -18
  195. package/dist/api/compiler/transformers/emit-resolver.js +1 -1
  196. package/dist/api/compiler/transformers/es-decorators.js +55 -55
  197. package/dist/api/compiler/transformers/external-module-info.js +3 -3
  198. package/dist/api/compiler/transformers/for-await.js +25 -25
  199. package/dist/api/compiler/transformers/import-elision.js +14 -14
  200. package/dist/api/compiler/transformers/jsx.js +12 -12
  201. package/dist/api/compiler/transformers/legacy-decorators.js +17 -17
  202. package/dist/api/compiler/transformers/module.js +8 -8
  203. package/dist/api/compiler/transformers/named-evaluation.js +4 -4
  204. package/dist/api/compiler/transformers/object-rest-spread.js +20 -20
  205. package/dist/api/compiler/transformers/optional-chain.js +10 -10
  206. package/dist/api/compiler/transformers/reference-resolver.d.ts +12 -1
  207. package/dist/api/compiler/transformers/reference-resolver.js +131 -69
  208. package/dist/api/compiler/transformers/runtime-syntax.js +35 -31
  209. package/dist/api/compiler/transformers/subtree-facts.js +47 -47
  210. package/dist/api/compiler/transformers/syntax-facts.js +56 -58
  211. package/dist/api/compiler/transformers/type-eraser.js +73 -66
  212. package/dist/api/compiler/transformers/type-serialization.js +24 -24
  213. package/dist/api/compiler/transformers/using.js +12 -12
  214. package/dist/api/compiler/transformers/utilities.js +77 -77
  215. package/dist/api/compiler/transformers/visitor-base.js +172 -172
  216. package/dist/api/compiler/transformers/visitor-hooks.js +6 -2
  217. package/dist/api/compiler/tsconfig.d.ts +10 -2
  218. package/dist/api/compiler/tsconfig.js +136 -48
  219. package/dist/api/compiler/type-printer.js +40 -3
  220. package/dist/api/compiler/types.d.ts +2 -1
  221. package/dist/api/library/ast.generated.d.ts +42 -39
  222. package/dist/api/library/ast.generated.js +1 -1
  223. package/dist/api/library/compiler-options.generated.d.ts +111 -100
  224. package/dist/api/library/compiler-options.generated.js +1 -1
  225. package/dist/api/library/disk.js +12 -1
  226. package/dist/api/library/enums.generated.d.ts +206 -206
  227. package/dist/api/library/enums.generated.js +206 -206
  228. package/dist/api/library/nodes.js +26 -26
  229. package/package.json +9 -9
  230. package/src/compiler/ast-utilities.ts +99 -7
  231. package/src/compiler/ast.ts +55 -26
  232. package/src/compiler/binder.ts +39 -4
  233. package/src/compiler/character-codes.ts +2 -2
  234. package/src/compiler/checker-calls.ts +76 -8
  235. package/src/compiler/checker-classes.ts +78 -24
  236. package/src/compiler/checker-contextual.ts +6 -1
  237. package/src/compiler/checker-declarations.ts +31 -4
  238. package/src/compiler/checker-declared-types.ts +8 -5
  239. package/src/compiler/checker-decorators.ts +1 -1
  240. package/src/compiler/checker-deprecation.ts +29 -8
  241. package/src/compiler/checker-destructuring.ts +10 -3
  242. package/src/compiler/checker-emit-helpers.ts +1 -0
  243. package/src/compiler/checker-emit-resolver.ts +16 -6
  244. package/src/compiler/checker-expressions.ts +79 -46
  245. package/src/compiler/checker-functions.ts +21 -6
  246. package/src/compiler/checker-generated-code.ts +2 -22
  247. package/src/compiler/checker-grammar.ts +133 -60
  248. package/src/compiler/checker-heritage.ts +22 -21
  249. package/src/compiler/checker-inference.ts +514 -87
  250. package/src/compiler/checker-iteration.ts +18 -31
  251. package/src/compiler/checker-javascript.ts +1 -1
  252. package/src/compiler/checker-jsdoc.ts +50 -27
  253. package/src/compiler/checker-jsx.ts +26 -4
  254. package/src/compiler/checker-members.ts +197 -55
  255. package/src/compiler/checker-modules.ts +332 -65
  256. package/src/compiler/checker-narrowing.ts +98 -19
  257. package/src/compiler/checker-object-literals.ts +3 -0
  258. package/src/compiler/checker-operators.ts +11 -4
  259. package/src/compiler/checker-property-access.ts +7 -2
  260. package/src/compiler/checker-services.ts +39 -12
  261. package/src/compiler/checker-signatures.ts +15 -1
  262. package/src/compiler/checker-source-file.ts +39 -13
  263. package/src/compiler/checker-statements.ts +3 -2
  264. package/src/compiler/checker-symbol-types.ts +29 -6
  265. package/src/compiler/checker-symbols.ts +158 -15
  266. package/src/compiler/checker-type-factory.ts +120 -21
  267. package/src/compiler/checker-type-nodes.ts +46 -3
  268. package/src/compiler/checker-type-operators.ts +83 -26
  269. package/src/compiler/checker-types.ts +147 -4
  270. package/src/compiler/checker-unused.ts +9 -14
  271. package/src/compiler/checker.ts +168 -41
  272. package/src/compiler/command-line.ts +28 -28
  273. package/src/compiler/compile-program.ts +51 -25
  274. package/src/compiler/decoder.ts +13 -4
  275. package/src/compiler/diagnostic-messages.ts +1973 -1892
  276. package/src/compiler/emitter.ts +57 -8
  277. package/src/compiler/encoder.ts +23 -8
  278. package/src/compiler/file-include.ts +9 -3
  279. package/src/compiler/file-loader.ts +139 -32
  280. package/src/compiler/help.ts +10 -14
  281. package/src/compiler/incremental.ts +86 -18
  282. package/src/compiler/init.ts +2 -7
  283. package/src/compiler/instantiation.ts +77 -22
  284. package/src/compiler/jsdoc.ts +3 -1
  285. package/src/compiler/link-tables.ts +82 -37
  286. package/src/compiler/locales/cs-CZ.ts +1 -1
  287. package/src/compiler/locales/de-DE.ts +1 -1
  288. package/src/compiler/locales/es-ES.ts +1 -1
  289. package/src/compiler/locales/fr-FR.ts +1 -1
  290. package/src/compiler/locales/it-IT.ts +1 -1
  291. package/src/compiler/locales/ja-JP.ts +1 -1
  292. package/src/compiler/locales/ko-KR.ts +1 -1
  293. package/src/compiler/locales/pl-PL.ts +1 -1
  294. package/src/compiler/locales/pt-BR.ts +1 -1
  295. package/src/compiler/locales/ru-RU.ts +1 -1
  296. package/src/compiler/locales/tr-TR.ts +1 -1
  297. package/src/compiler/locales/zh-CN.ts +1 -1
  298. package/src/compiler/locales/zh-TW.ts +1 -1
  299. package/src/compiler/module-resolution.ts +44 -8
  300. package/src/compiler/module-specifiers.ts +62 -20
  301. package/src/compiler/name-resolver.ts +9 -1
  302. package/src/compiler/node-builder-names.ts +236 -54
  303. package/src/compiler/node-builder-pseudo.ts +4 -7
  304. package/src/compiler/node-builder-reuse.ts +5 -4
  305. package/src/compiler/node-builder.ts +130 -31
  306. package/src/compiler/option-declarations.ts +33 -103
  307. package/src/compiler/options.ts +23 -62
  308. package/src/compiler/output-paths.ts +5 -18
  309. package/src/compiler/package-entrypoints.ts +345 -0
  310. package/src/compiler/package-json.ts +4 -4
  311. package/src/compiler/parallel-check.ts +197 -8
  312. package/src/compiler/parallel-emit.ts +1 -1
  313. package/src/compiler/parser.ts +156 -39
  314. package/src/compiler/path.ts +22 -2
  315. package/src/compiler/printer/emit-context.ts +16 -0
  316. package/src/compiler/printer/factory-base.ts +10 -3
  317. package/src/compiler/printer/factory.ts +4 -1
  318. package/src/compiler/printer/helpers.ts +10 -1
  319. package/src/compiler/printer/name-generator.ts +24 -2
  320. package/src/compiler/printer/printer.ts +35 -14
  321. package/src/compiler/printer/utilities.ts +8 -2
  322. package/src/compiler/program-checker.ts +53 -5
  323. package/src/compiler/program-utilities.ts +23 -10
  324. package/src/compiler/program.ts +13 -1
  325. package/src/compiler/pseudo-bigint.ts +17 -0
  326. package/src/compiler/regexp-checker.ts +63 -30
  327. package/src/compiler/relations.ts +233 -77
  328. package/src/compiler/reparser.ts +7 -2
  329. package/src/compiler/scanner.ts +109 -79
  330. package/src/compiler/shared-results.ts +2414 -0
  331. package/src/compiler/show-config.ts +18 -1
  332. package/src/compiler/sourcemap.ts +2 -2
  333. package/src/compiler/symbol-accessibility.ts +26 -3
  334. package/src/compiler/symbol.ts +31 -14
  335. package/src/compiler/syntax-kind.ts +188 -187
  336. package/src/compiler/thread-entry.ts +19 -2
  337. package/src/compiler/transformers/alias-references.ts +123 -4
  338. package/src/compiler/transformers/async.ts +2 -17
  339. package/src/compiler/transformers/class-fields.ts +13 -12
  340. package/src/compiler/transformers/commonjs-module.ts +11 -7
  341. package/src/compiler/transformers/declarations-diagnostics.ts +5 -3
  342. package/src/compiler/transformers/declarations-pseudo.ts +2 -4
  343. package/src/compiler/transformers/declarations-resolver.ts +0 -3
  344. package/src/compiler/transformers/declarations-syntactic.ts +1 -21
  345. package/src/compiler/transformers/declarations.ts +134 -48
  346. package/src/compiler/transformers/decorator-metadata.ts +9 -1
  347. package/src/compiler/transformers/destructuring.ts +4 -3
  348. package/src/compiler/transformers/external-module-info.ts +1 -1
  349. package/src/compiler/transformers/jsx.ts +2 -1
  350. package/src/compiler/transformers/reference-resolver.ts +83 -19
  351. package/src/compiler/transformers/runtime-syntax.ts +6 -1
  352. package/src/compiler/transformers/syntax-facts.ts +2 -7
  353. package/src/compiler/transformers/type-eraser.ts +10 -1
  354. package/src/compiler/transformers/type-serialization.ts +3 -2
  355. package/src/compiler/transformers/visitor-base.ts +2 -1
  356. package/src/compiler/transformers/visitor-hooks.ts +9 -4
  357. package/src/compiler/tsc-build.ts +3 -0
  358. package/src/compiler/tsc-cli.ts +2 -0
  359. package/src/compiler/tsc-compile.ts +7 -2
  360. package/src/compiler/tsc-watch.ts +74 -45
  361. package/src/compiler/tsconfig.ts +176 -19
  362. package/src/compiler/type-printer.ts +36 -2
  363. package/src/compiler/types.ts +2 -1
  364. package/src/library/ast.generated.ts +57 -41
  365. package/src/library/compiler-options.generated.ts +117 -103
  366. package/src/library/disk.ts +10 -1
  367. package/src/library/enums.generated.ts +196 -196
@@ -375,6 +375,8 @@ const enum ListItem {
375
375
  ImportSpecifier,
376
376
  ExportSpecifier,
377
377
  ExpressionWithTypeArguments,
378
+ /** An `ExpressionWithTypeArguments` or a type reference in a heritage clause. */
379
+ HeritageClauseElement,
378
380
  JsxChild,
379
381
  JsxAttributeLike,
380
382
  }
@@ -606,7 +608,8 @@ export class Printer extends NameGeneratorHost {
606
608
 
607
609
  isFileLevelUniqueName(name: string): boolean {
608
610
  const file = this.currentSourceFile;
609
- return file === undefined || isFileLevelUniqueName(file, name);
611
+ // The names of the source file as parsed, not as transformed.
612
+ return file === undefined || isFileLevelUniqueName(this.context.mostOriginal(file) as SourceFile, name);
610
613
  }
611
614
 
612
615
  private getLiteralTextOfNode(node: Node, sourceFile: SourceFile | undefined, flags: LiteralTextFlags): string {
@@ -1217,7 +1220,8 @@ export class Printer extends NameGeneratorHost {
1217
1220
  const state = this.enterNode(node);
1218
1221
  this.emitEntityName(node.left);
1219
1222
  this.write1('.');
1220
- this.emitIdentifierName(node.right);
1223
+ if (node.right instanceof PrivateIdentifier) this.emitPrivateIdentifier(node.right);
1224
+ else this.emitIdentifierName(node.right as Identifier);
1221
1225
  this.exitNode(node, state);
1222
1226
  return true;
1223
1227
  }
@@ -1914,10 +1918,11 @@ export class Printer extends NameGeneratorHost {
1914
1918
  this.emitOptionalToken(questionToken);
1915
1919
  if (questionToken.kind !== SyntaxKind.QuestionToken) this.write1('?');
1916
1920
  }
1917
- this.write1(': ');
1918
- // tsgo's printer fails on a mapped type without a type, too.
1919
- if (node.type === undefined) throw new Error('Mapped type without a type');
1920
- this.emitTypeNodeOutsideExtends(node.type);
1921
+ // A mapped type written without a type, `{ [K in keyof T] }`, prints without one.
1922
+ if (node.type !== undefined) {
1923
+ this.write1(': ');
1924
+ this.emitTypeNodeOutsideExtends(node.type);
1925
+ }
1921
1926
  this.write1(';');
1922
1927
  if (node.members !== undefined && node.members.nodes.length > 0) {
1923
1928
  if (singleLine) this.space();
@@ -2948,8 +2953,8 @@ export class Printer extends NameGeneratorHost {
2948
2953
  case SyntaxKind.MetaProperty:
2949
2954
  if (node instanceof MetaProperty) {
2950
2955
  const state = this.enterNode(node);
2951
- this.emitToken(node.keywordToken, node.pos, node);
2952
- this.write1('.');
2956
+ const pos = this.emitToken(node.keywordToken, node.pos, node);
2957
+ this.emitToken(SyntaxKind.DotToken, pos, node);
2953
2958
  this.emitIdentifierName(node.name);
2954
2959
  this.exitNode(node, state);
2955
2960
  return true;
@@ -3311,6 +3316,10 @@ export class Printer extends NameGeneratorHost {
3311
3316
  this.emitIdentifierOrString(body.name, false);
3312
3317
  body = body.body;
3313
3318
  }
3319
+ if (node.attributes !== undefined) {
3320
+ this.write1(' with ');
3321
+ this.emitTypeNode(node.attributes, TypePrecedence.NonArray);
3322
+ }
3314
3323
  if (body === undefined) this.write1(';');
3315
3324
  else if (body instanceof ModuleBlock) {
3316
3325
  this.space();
@@ -3419,16 +3428,21 @@ export class Printer extends NameGeneratorHost {
3419
3428
  this.emitBindingIdentifier(bindings.name);
3420
3429
  this.exitNode(bindings, bindingsState);
3421
3430
  } else if (bindings instanceof NamedImports) {
3422
- const bindingsState = this.enterNode(bindings);
3423
- this.write1('{');
3424
- this.emitList(ListItem.ImportSpecifier, bindings, bindings.elements, ListFormat.NamedImportsOrExportsElements);
3425
- this.write1('}');
3426
- this.exitNode(bindings, bindingsState);
3431
+ this.emitNamedImports(bindings);
3427
3432
  }
3428
3433
  this.exitNode(node, state);
3429
3434
  return true;
3430
3435
  }
3431
3436
 
3437
+ private emitNamedImports(node: NamedImports): boolean {
3438
+ const state = this.enterNode(node);
3439
+ this.write1('{');
3440
+ this.emitList(ListItem.ImportSpecifier, node, node.elements, ListFormat.NamedImportsOrExportsElements);
3441
+ this.write1('}');
3442
+ this.exitNode(node, state);
3443
+ return true;
3444
+ }
3445
+
3432
3446
  /** Import and export specifiers. */
3433
3447
  private emitSpecifier(
3434
3448
  node: Node,
@@ -3871,7 +3885,7 @@ export class Printer extends NameGeneratorHost {
3871
3885
  this.space();
3872
3886
  this.emitToken(node.token, node.pos, node);
3873
3887
  this.space();
3874
- this.emitList(ListItem.ExpressionWithTypeArguments, node, node.types, ListFormat.HeritageClauseTypes);
3888
+ this.emitList(ListItem.HeritageClauseElement, node, node.types, ListFormat.HeritageClauseTypes);
3875
3889
  this.exitNode(node, state);
3876
3890
  return true;
3877
3891
  }
@@ -4092,6 +4106,10 @@ export class Printer extends NameGeneratorHost {
4092
4106
  case ListItem.ExpressionWithTypeArguments:
4093
4107
  if (node instanceof ExpressionWithTypeArguments) return this.emitExpressionWithTypeArguments(node);
4094
4108
  break;
4109
+ case ListItem.HeritageClauseElement:
4110
+ if (node instanceof ExpressionWithTypeArguments) return this.emitExpressionWithTypeArguments(node);
4111
+ if (node.kind === SyntaxKind.TypeReference) return this.emitTypeNodeWorker(node);
4112
+ break;
4095
4113
  case ListItem.JsxChild:
4096
4114
  return this.emitJsxChild(node);
4097
4115
  case ListItem.JsxAttributeLike:
@@ -4391,6 +4409,9 @@ export class Printer extends NameGeneratorHost {
4391
4409
  case SyntaxKind.ImportClause:
4392
4410
  if (node instanceof ImportClause) return this.emitImportClause(node);
4393
4411
  break;
4412
+ case SyntaxKind.NamedImports:
4413
+ if (node instanceof NamedImports) return this.emitNamedImports(node);
4414
+ break;
4394
4415
  case SyntaxKind.ImportSpecifier:
4395
4416
  return this.emitListItem(ListItem.ImportSpecifier, node);
4396
4417
  case SyntaxKind.ExportSpecifier:
@@ -31,7 +31,12 @@ import {
31
31
  PrivateIdentifier,
32
32
  getExpression,
33
33
  } from '../ast.js';
34
- import { OperatorPrecedence, getBinaryOperatorPrecedence } from '../ast-utilities.js';
34
+ import {
35
+ OperatorPrecedence,
36
+ getBinaryOperatorPrecedence,
37
+ isJSDocTypeExpressionOrChild,
38
+ normalizeJSDocTypeSourceText,
39
+ } from '../ast-utilities.js';
35
40
  import {
36
41
  CharacterCodes,
37
42
  isDigit,
@@ -687,7 +692,8 @@ export function getLiteralText(node: Node, sourceText: string | undefined, flags
687
692
  /** The source text of a node without leading trivia, as tsgo's GetSourceTextOfNodeFromSourceFile. */
688
693
  export function getSourceTextOfNode(sourceText: string, node: Node): string {
689
694
  if (node.pos === node.end && node.pos >= 0 && node.kind !== SyntaxKind.EndOfFile) return '';
690
- const text = sourceText.substring(skipTrivia(sourceText, node.pos), node.end);
695
+ let text = sourceText.substring(skipTrivia(sourceText, node.pos), node.end);
696
+ if (isJSDocTypeExpressionOrChild(node)) text = normalizeJSDocTypeSourceText(text);
691
697
  if ((node.flags & NodeFlags.ReparserTransformedLiteral) !== 0) {
692
698
  if (node instanceof StringLiteral)
693
699
  return (node.tokenFlags & TokenFlags.SingleQuote) !== 0 ? "'" + text + "'" : '"' + text + '"';
@@ -9,7 +9,14 @@
9
9
  */
10
10
  import { type Node, ScriptKind, type SourceFile } from './ast.js';
11
11
  import { Checker, CheckerHost, disposeChecker } from './checker.js';
12
- import { createDiagnostic, Diagnostic, type DiagnosticMessage, Diagnostics, messageCode } from './diagnostics.js';
12
+ import {
13
+ compareDiagnostics,
14
+ createDiagnostic,
15
+ Diagnostic,
16
+ type DiagnosticMessage,
17
+ Diagnostics,
18
+ messageCode,
19
+ } from './diagnostics.js';
13
20
  import type { EmitResult } from './emitter.js';
14
21
  import type { CompilerOptions, ModuleKind } from './options.js';
15
22
  import type { ResolvedModule } from './module-resolution-types.js';
@@ -265,6 +272,12 @@ export class CheckedProgram {
265
272
  */
266
273
  referenceThreads = 1;
267
274
  readonly parallelGlobalDiagnostics: Diagnostic[] = [];
275
+ /**
276
+ * Whether the semantic diagnostics of a file include the global diagnostics its checker found while
277
+ * checking it, as an incremental program caches them (IncrementalProgram). Such a program doesn't report
278
+ * the global diagnostics found by checking otherwise (`reportsGlobalDiagnosticsOfChecking`, compile-program.ts).
279
+ */
280
+ globalsInFileDiagnostics = false;
268
281
  /**
269
282
  * The declaration diagnostics checker threads computed under `noEmit` (PlainProgram,
270
283
  * IncrementalProgram), by file index; `undefined` for files they did not. Set once every file is
@@ -403,11 +416,11 @@ export class CheckedProgram {
403
416
  return sortAndDeduplicateDiagnostics([...own, ...parallel]);
404
417
  }
405
418
 
406
- /** Whether `file`'s bind and check diagnostics are reported. */
407
- skipTypeChecking(file: SourceFile): boolean {
419
+ /** Whether `file`'s bind and check diagnostics are skipped; `ignoreNoCheck` leaves `noCheck` out. */
420
+ skipTypeChecking(file: SourceFile, ignoreNoCheck = false): boolean {
408
421
  const options = this.program.options;
409
422
  return (
410
- options.noCheck === true ||
423
+ (!ignoreNoCheck && options.noCheck === true) ||
411
424
  (options.skipLibCheck === true && file.isDeclarationFile) ||
412
425
  (options.skipDefaultLibCheck === true && this.program.isSourceFileDefaultLibrary(file.path)) ||
413
426
  this.program.getProjectReferenceFromSource(file.path) !== undefined ||
@@ -436,7 +449,15 @@ export class CheckedProgram {
436
449
  private getBindAndCheckDiagnostics(file: SourceFile, checks?: readonly Diagnostic[]): Diagnostic[] {
437
450
  const options = this.program.options;
438
451
  const diagnostics = file.bindDiagnostics.slice();
439
- for (const d of checks ?? this.checker.getDiagnostics(file)) diagnostics.push(d);
452
+ if (checks !== undefined) for (const d of checks) diagnostics.push(d);
453
+ else if (this.globalsInFileDiagnostics) {
454
+ const checker = this.checker;
455
+ const before = checker.getGlobalDiagnostics();
456
+ for (const d of checker.getDiagnostics(file)) diagnostics.push(d);
457
+ const after = checker.getGlobalDiagnostics();
458
+ if (after.length > before.length)
459
+ for (const d of after) if (!containsSortedDiagnostic(before, d)) diagnostics.push(d);
460
+ } else for (const d of this.checker.getDiagnostics(file)) diagnostics.push(d);
440
461
  if (isPlainJSFile(file, options)) {
441
462
  const result: Diagnostic[] = [];
442
463
  for (const d of diagnostics) if (plainJSErrors.has(d.code)) result.push(d);
@@ -467,6 +488,20 @@ export class CheckedProgram {
467
488
  }
468
489
  }
469
490
 
491
+ /** Whether `sorted`, in `compareDiagnostics` order, has a diagnostic equal to `diagnostic`. */
492
+ function containsSortedDiagnostic(sorted: readonly Diagnostic[], diagnostic: Diagnostic): boolean {
493
+ let low = 0;
494
+ let high = sorted.length - 1;
495
+ while (low <= high) {
496
+ const middle = (low + high) >>> 1;
497
+ const c = compareDiagnostics(sorted[middle]!, diagnostic);
498
+ if (c === 0) return true;
499
+ if (c < 0) low = middle + 1;
500
+ else high = middle - 1;
501
+ }
502
+ return false;
503
+ }
504
+
470
505
  /** The `@ts-ignore` and `@ts-expect-error` comments of a file, by line. */
471
506
  class Directives {
472
507
  private readonly byLine = new Map<number, { pos: number; end: number; kind: CommentDirectiveKind }>();
@@ -488,6 +523,11 @@ class Directives {
488
523
  const lineStarts = this.file.diagnosticFile().getLineStarts();
489
524
  const result: Diagnostic[] = [];
490
525
  for (const diagnostic of diagnostics) {
526
+ // A global diagnostic, or one of another file, has no line here.
527
+ if (diagnostic.file === undefined || diagnostic.file.fileName !== this.file.fileName) {
528
+ result.push(diagnostic);
529
+ continue;
530
+ }
491
531
  let ignored = false;
492
532
  for (let line = computeLineOfPosition(lineStarts, diagnostic.pos) - 1; line >= 0; line--) {
493
533
  const directive = this.byLine.get(line);
@@ -564,6 +604,7 @@ const plainJSErrors = codesOf([
564
604
  Diagnostics.A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement,
565
605
  Diagnostics.A_default_clause_cannot_appear_more_than_once_in_a_switch_statement,
566
606
  Diagnostics.A_default_export_must_be_at_the_top_level_of_a_file_or_module_declaration,
607
+ Diagnostics.A_deferred_import_must_specify_a_namespace_binding,
567
608
  Diagnostics.A_definite_assignment_assertion_is_not_permitted_in_this_context,
568
609
  Diagnostics.A_destructuring_declaration_must_have_an_initializer,
569
610
  Diagnostics.A_get_accessor_cannot_have_parameters,
@@ -632,6 +673,13 @@ const plainJSErrors = codesOf([
632
673
  Diagnostics.X_await_using_statements_are_only_allowed_within_async_functions_and_at_the_top_levels_of_modules,
633
674
  Diagnostics.Private_field_0_must_be_declared_in_an_enclosing_class,
634
675
  Diagnostics.This_condition_will_always_return_0_since_JavaScript_compares_objects_by_reference_not_value,
676
+ Diagnostics.A_deferred_import_must_specify_a_namespace_binding,
677
+ Diagnostics.A_source_phase_import_must_specify_a_local_binding,
678
+ Diagnostics.Named_and_namespace_imports_are_not_allowed_in_a_source_phase_import,
679
+ Diagnostics.Optional_chaining_cannot_be_used_with_import_source,
680
+ Diagnostics.Source_phase_imports_are_not_allowed_on_statements_that_compile_to_CommonJS_require_calls,
681
+ Diagnostics.Source_phase_imports_are_only_supported_when_the_module_option_is_set_to_esnext_nodenext_or_preserve,
682
+ Diagnostics.X_0_is_not_a_valid_meta_property_for_keyword_import_Did_you_mean_meta_defer_or_source,
635
683
  ]);
636
684
 
637
685
  function codesOf(messages: readonly DiagnosticMessage[]): Set<number> {
@@ -4,6 +4,7 @@
4
4
  import {
5
5
  ExportDeclaration,
6
6
  ExternalModuleIndicatorOptions,
7
+ Identifier,
7
8
  ImportAttribute,
8
9
  ImportAttributes,
9
10
  ImportClause,
@@ -19,7 +20,7 @@ import {
19
20
  type Node,
20
21
  type SourceFile,
21
22
  } from './ast.js';
22
- import { isImportCall, isRequireCall } from './ast-utilities.js';
23
+ import { isImportCall, isRequireCall, isSourcePhaseImportCall } from './ast-utilities.js';
23
24
  import { libMap } from './option-declarations.js';
24
25
  import {
25
26
  getEmitModuleDetectionKind,
@@ -59,6 +60,8 @@ export function getDefaultLibFileName(options: CompilerOptions): string {
59
60
  switch (getEmitScriptTarget(options)) {
60
61
  case ScriptTarget.ESNext:
61
62
  return 'lib.esnext.full.d.ts';
63
+ case ScriptTarget.ES2026:
64
+ return 'lib.es2026.full.d.ts';
62
65
  case ScriptTarget.ES2025:
63
66
  return 'lib.es2025.full.d.ts';
64
67
  case ScriptTarget.ES2024:
@@ -115,6 +118,8 @@ export function scriptTargetName(target: ScriptTarget): string {
115
118
  return 'ES2024';
116
119
  case ScriptTarget.ES2025:
117
120
  return 'ES2025';
121
+ case ScriptTarget.ES2026:
122
+ return 'ES2026';
118
123
  case ScriptTarget.ESNext:
119
124
  return 'ESNext';
120
125
  case ScriptTarget.JSON:
@@ -316,21 +321,27 @@ function literalText(node: Node): string {
316
321
 
317
322
  /** The `resolution-mode` of `import type` attributes, or `None`. */
318
323
  export function getResolutionModeOverride(attributes: ImportAttributes | undefined): ModuleKind {
319
- if (attributes === undefined) return ModuleKind.None;
320
- const elements = attributes.attributes.nodes;
321
- if (elements.length !== 1) return ModuleKind.None;
322
- const attribute = elements[0]!;
323
- if (!(attribute instanceof ImportAttribute)) return ModuleKind.None;
324
- const name = attribute.name;
325
- if (name === undefined || !isStringLiteralLike(name) || literalText(name) !== 'resolution-mode')
326
- return ModuleKind.None;
327
- if (!isStringLiteralLike(attribute.value)) return ModuleKind.None;
324
+ const attribute = resolutionModeAttribute(attributes);
325
+ if (attribute === undefined || !isStringLiteralLike(attribute.value)) return ModuleKind.None;
328
326
  const text = literalText(attribute.value);
329
327
  if (text === 'import') return ModuleKind.ESNext;
330
328
  if (text === 'require') return ModuleKind.CommonJS;
331
329
  return ModuleKind.None;
332
330
  }
333
331
 
332
+ /** The `resolution-mode` attribute among import attributes, as tsgo's `GetResolutionModeOverride` finds it. */
333
+ export function resolutionModeAttribute(attributes: ImportAttributes | undefined): ImportAttribute | undefined {
334
+ if (attributes === undefined) return undefined;
335
+ for (const attribute of attributes.attributes.nodes) {
336
+ if (!(attribute instanceof ImportAttribute)) continue;
337
+ const name = attribute.name;
338
+ if (name === undefined) continue;
339
+ const text = name instanceof Identifier ? name.text : literalText(name);
340
+ if (text === 'resolution-mode') return attribute;
341
+ }
342
+ return undefined;
343
+ }
344
+
334
345
  /** The attributes of an import or export declaration or a JSDoc `@import`, if any. */
335
346
  function importOrExportAttributes(node: Node | undefined): ImportAttributes | undefined {
336
347
  if (node instanceof ImportDeclaration) return node.attributes;
@@ -404,6 +415,8 @@ export function getEmitSyntaxForUsageLocation(
404
415
  const fileEmitMode = getEmitModuleFormatOfFile(fileName, options, metadata);
405
416
  const call = walkUpParenthesizedExpressions(parent);
406
417
  if (call !== undefined && isImportCall(call)) {
418
+ // `import.source()` is never transformed to `require`.
419
+ if (isSourcePhaseImportCall(call)) return ModuleKind.ESNext;
407
420
  return shouldTransformImportCall(options, fileEmitMode) ? ModuleKind.CommonJS : ModuleKind.ESNext;
408
421
  }
409
422
  if (fileEmitMode === ModuleKind.CommonJS) return ModuleKind.CommonJS;
@@ -85,6 +85,7 @@ import {
85
85
  pathIsRelative,
86
86
  toFileNameLowerCase,
87
87
  toPath,
88
+ isNetworkPathValue,
88
89
  } from './path.js';
89
90
  import {
90
91
  getDefaultResolutionModeForFile,
@@ -106,6 +107,7 @@ import {
106
107
  type SourceOutputAndProjectReference,
107
108
  } from './tsconfig.js';
108
109
  import { SyntaxKind } from './syntax-kind.js';
110
+ import { isSourcePhaseImport } from './ast-utilities.js';
109
111
  import { KnownSymlinks } from './symlinks.js';
110
112
  import { mark } from './timeline.js';
111
113
  import { LanguageVariant } from './types.js';
@@ -294,6 +296,11 @@ export class Program implements OutputPathsHost {
294
296
  return this.processed.redirectTargets.get(path) ?? [];
295
297
  }
296
298
 
299
+ /** The nearest `package.json` lookup at or above `directory`. */
300
+ getPackageScopeForPath(directory: string): PackageJsonInfo | undefined {
301
+ return this.processed.resolver.getPackageScopeForPath(directory);
302
+ }
303
+
297
304
  /** The directory of the nearest `package.json` at or above `directory`, or `''`. */
298
305
  getNearestAncestorDirectoryWithPackageJson(directory: string): string {
299
306
  const scope = this.processed.resolver.getPackageScopeForPath(directory);
@@ -362,7 +369,8 @@ export class Program implements OutputPathsHost {
362
369
  )
363
370
  continue;
364
371
  const resolved = resolver.resolvePackageDirectory(dependency, packageJsonName, ModuleKind.CommonJS);
365
- if (resolved !== undefined && resolved.resolvedFileName !== '')
372
+ // A dependency installed in place has no original path to map from.
373
+ if (resolved !== undefined && resolved.resolvedFileName !== '' && resolved.originalPath !== '')
366
374
  symlinks.processResolution(
367
375
  combinePaths(resolved.originalPath, 'package.json'),
368
376
  combinePaths(resolved.resolvedFileName, 'package.json'),
@@ -467,6 +475,8 @@ export class Program implements OutputPathsHost {
467
475
  }
468
476
 
469
477
  getResolvedModuleFromModuleSpecifier(file: SourceFile, specifier: Node): ResolvedModule | undefined {
478
+ // A source phase import loads no module declarations.
479
+ if (specifier.parent !== undefined && isSourcePhaseImport(specifier.parent)) return undefined;
470
480
  const text = specifierText(specifier);
471
481
  return this.getResolvedModule(file, text, this.getModeForUsageLocation(file, specifier));
472
482
  }
@@ -915,6 +925,8 @@ export class Program implements OutputPathsHost {
915
925
  Diagnostics.Non_relative_paths_are_not_allowed_Did_you_forget_a_leading_Slash,
916
926
  [],
917
927
  );
928
+ } else if (isNetworkPathValue(substitution, options.pathsBasePath ?? this.currentDirectory)) {
929
+ this.pathsValueDiagnostic(key, i, Diagnostics.Network_path_0_is_not_supported, [substitution]);
918
930
  }
919
931
  }
920
932
  }
@@ -60,3 +60,20 @@ export function parsePseudoBigInt(literal: string): string {
60
60
  }
61
61
  return result;
62
62
  }
63
+
64
+ /** Compares two bigint values in decimal, each optionally prefixed with `-`, by numeric value. */
65
+ export function comparePseudoBigInts(a: string, b: string): number {
66
+ const negative = a.charCodeAt(0) === CharacterCodes.minus;
67
+ const r = pseudoBigIntSign(a) - pseudoBigIntSign(b);
68
+ if (r !== 0) return r;
69
+ const digitsA = negative ? a.substring(1) : a;
70
+ const digitsB = negative ? b.substring(1) : b;
71
+ let magnitude = digitsA.length - digitsB.length;
72
+ if (magnitude === 0) magnitude = digitsA < digitsB ? -1 : digitsA > digitsB ? 1 : 0;
73
+ return negative ? -magnitude : magnitude;
74
+ }
75
+
76
+ function pseudoBigIntSign(value: string): number {
77
+ if (value.charCodeAt(0) === CharacterCodes.minus) return -1;
78
+ return value === '0' ? 0 : 1;
79
+ }
@@ -9,7 +9,7 @@ import {
9
9
  } from './character-codes.js';
10
10
  import { Diagnostics } from './diagnostic-messages.js';
11
11
  import type { DiagnosticMessage } from './diagnostics.js';
12
- import type { Scanner } from './scanner.js';
12
+ import { IdentifierVariant, type Scanner } from './scanner.js';
13
13
  import { getSpellingSuggestion } from './spelling.js';
14
14
  import { ScriptTarget } from './types.js';
15
15
  import {
@@ -243,13 +243,24 @@ class RegularExpressionChecker {
243
243
 
244
244
  // Disjunction ::= Alternative ('|' Alternative)*
245
245
  private scanDisjunction(isInGroup: boolean): void {
246
+ // The names any alternative defines. One alternative matches, so in a group they join the
247
+ // enclosing alternative's scope: `(?:(?<a>x))(?<a>z)` defines `a` twice.
248
+ let disjunctionNames: Set<string> | undefined;
246
249
  for (;;) {
247
250
  this.namedCapturingGroups.push(new Set<string>());
248
251
  this.scanAlternative(isInGroup);
249
- this.namedCapturingGroups.pop();
250
- if (this.char() !== CharacterCodes.bar) return;
252
+ const alternativeNames = this.namedCapturingGroups.pop()!;
253
+ if (alternativeNames.size > 0) {
254
+ if (disjunctionNames === undefined) disjunctionNames = new Set<string>();
255
+ for (const name of alternativeNames) disjunctionNames.add(name);
256
+ }
257
+ if (this.char() !== CharacterCodes.bar) break;
251
258
  this.scanner.pos = (this.scanner.pos + 1) | 0;
252
259
  }
260
+ if (isInGroup && disjunctionNames !== undefined && this.namedCapturingGroups.length > 0) {
261
+ const parentScope = this.namedCapturingGroups[this.namedCapturingGroups.length - 1]!;
262
+ for (const name of disjunctionNames) parentScope.add(name);
263
+ }
253
264
  }
254
265
 
255
266
  // Alternative ::= Term*
@@ -317,6 +328,14 @@ class RegularExpressionChecker {
317
328
  noArgs,
318
329
  );
319
330
  }
331
+ // Modifier characters make this `(?flags:` rather than a plain `(?:` group.
332
+ if (this.scanner.pos !== flagsStart && this.scanner.languageVersion() < ScriptTarget.ES2025)
333
+ this.error(
334
+ Diagnostics.Regular_expression_pattern_modifiers_are_only_available_when_targeting_0_or_later,
335
+ flagsStart,
336
+ this.scanner.pos - flagsStart,
337
+ ['es2025'],
338
+ );
320
339
  this.scanExpectedChar(CharacterCodes.colon);
321
340
  isPreviousTermQuantifiable = true;
322
341
  }
@@ -443,10 +462,8 @@ class RegularExpressionChecker {
443
462
  size,
444
463
  noArgs,
445
464
  );
446
- else {
447
- currentFlags |= flag;
448
- this.scanner.checkRegularExpressionFlagAvailability(flag, this.scanner.pos, size);
449
- }
465
+ // Modifiers need ES2025, later than any flag they can toggle, and the group reports that.
466
+ else currentFlags |= flag;
450
467
  this.scanner.pos = (this.scanner.pos + size) | 0;
451
468
  }
452
469
  return currentFlags;
@@ -545,9 +562,8 @@ class RegularExpressionChecker {
545
562
  private scanGroupName(isReference: boolean): void {
546
563
  const scanner = this.scanner;
547
564
  scanner.tokenStart = this.scanner.pos | 0;
548
- scanner.scanIdentifier(0);
549
565
  const start = scanner.tokenStart;
550
- if (this.scanner.pos === start) {
566
+ if (!scanner.scanIdentifier(0, IdentifierVariant.RegExpGroupName)) {
551
567
  this.error(Diagnostics.Expected_a_capturing_group_name, this.scanner.pos, 0, noArgs);
552
568
  return;
553
569
  }
@@ -562,6 +578,20 @@ class RegularExpressionChecker {
562
578
  noArgs,
563
579
  );
564
580
  } else {
581
+ // An earlier definition is in a mutually exclusive alternative. Below ES2018 the group is
582
+ // reported already.
583
+ const languageVersion = this.scanner.languageVersion();
584
+ if (
585
+ this.groupSpecifiers.has(name) &&
586
+ languageVersion >= ScriptTarget.ES2018 &&
587
+ languageVersion < ScriptTarget.ES2025
588
+ )
589
+ this.error(
590
+ Diagnostics.Duplicate_named_capturing_groups_are_only_available_when_targeting_0_or_later,
591
+ start,
592
+ this.scanner.pos - start,
593
+ ['es2025'],
594
+ );
565
595
  if (this.namedCapturingGroups.length > 0)
566
596
  this.namedCapturingGroups[this.namedCapturingGroups.length - 1]!.add(name);
567
597
  this.groupSpecifiers.add(name);
@@ -667,9 +697,6 @@ class RegularExpressionChecker {
667
697
  this.mayContainStrings = !isCharacterComplement && expressionMayContainStrings;
668
698
  return this.mayContainStrings;
669
699
  }
670
- this.error(Diagnostics.Unexpected_0_Did_you_mean_to_escape_it_with_backslash, this.scanner.pos, 1, [
671
- String.fromCharCode(ch),
672
- ]);
673
700
  break;
674
701
  default:
675
702
  if (isCharacterComplement && this.mayContainStrings)
@@ -730,29 +757,26 @@ class RegularExpressionChecker {
730
757
  } else if (operand >= 0 && secondOperand >= 0 && operand > secondOperand) {
731
758
  this.error(Diagnostics.Range_out_of_order_in_character_class, start, this.scanner.pos - start, noArgs);
732
759
  }
733
- } else if (ch === CharacterCodes.ampersand) {
760
+ } else if (
761
+ ch === CharacterCodes.ampersand &&
762
+ this.scanner.pos + 1 < this.end &&
763
+ this.charAt(this.scanner.pos + 1) === CharacterCodes.ampersand
764
+ ) {
734
765
  start = this.scanner.pos;
735
- this.scanner.pos = (this.scanner.pos + 1) | 0;
766
+ this.scanner.pos = (this.scanner.pos + 2) | 0;
767
+ this.error(
768
+ Diagnostics.Operators_must_not_be_mixed_within_a_character_class_Wrap_it_in_a_nested_class_instead,
769
+ this.scanner.pos - 2,
770
+ 2,
771
+ noArgs,
772
+ );
736
773
  if (this.char() === CharacterCodes.ampersand) {
737
- this.scanner.pos = (this.scanner.pos + 1) | 0;
738
- this.error(
739
- Diagnostics.Operators_must_not_be_mixed_within_a_character_class_Wrap_it_in_a_nested_class_instead,
740
- this.scanner.pos - 2,
741
- 2,
742
- noArgs,
743
- );
744
- if (this.char() === CharacterCodes.ampersand) {
745
- this.error(Diagnostics.Unexpected_0_Did_you_mean_to_escape_it_with_backslash, this.scanner.pos, 1, [
746
- String.fromCharCode(ch),
747
- ]);
748
- this.scanner.pos = (this.scanner.pos + 1) | 0;
749
- }
750
- } else {
751
- this.error(Diagnostics.Unexpected_0_Did_you_mean_to_escape_it_with_backslash, this.scanner.pos - 1, 1, [
774
+ this.error(Diagnostics.Unexpected_0_Did_you_mean_to_escape_it_with_backslash, this.scanner.pos, 1, [
752
775
  String.fromCharCode(ch),
753
776
  ]);
777
+ this.scanner.pos = (this.scanner.pos + 1) | 0;
754
778
  }
755
- operand = this.scanner.pos - start === 1 ? CharacterCodes.ampersand : ClassValue.String;
779
+ operand = ClassValue.String;
756
780
  continue;
757
781
  }
758
782
  if (this.isClassContentExit(this.char())) break;
@@ -768,6 +792,15 @@ class RegularExpressionChecker {
768
792
  operand = ClassValue.String;
769
793
  } else {
770
794
  operand = this.scanClassSetOperand();
795
+ // Each operand of a negated union must match single characters.
796
+ if (isCharacterComplement && this.mayContainStrings)
797
+ this.error(
798
+ Diagnostics.Anything_that_would_possibly_match_more_than_a_single_character_is_invalid_inside_a_negated_character_class,
799
+ start,
800
+ this.scanner.pos - start,
801
+ noArgs,
802
+ );
803
+ expressionMayContainStrings = expressionMayContainStrings || this.mayContainStrings;
771
804
  }
772
805
  }
773
806
  this.mayContainStrings = !isCharacterComplement && expressionMayContainStrings;