tsc-ts 0.0.9 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (373) hide show
  1. package/README.md +2 -2
  2. package/bin/tsc-ts.js +70 -1
  3. package/dist/api/compiler/ast-utilities.d.ts +19 -1
  4. package/dist/api/compiler/ast-utilities.js +180 -95
  5. package/dist/api/compiler/ast.d.ts +22 -15
  6. package/dist/api/compiler/ast.js +1026 -995
  7. package/dist/api/compiler/astnav.js +15 -15
  8. package/dist/api/compiler/binder-utilities.js +186 -186
  9. package/dist/api/compiler/binder.js +290 -263
  10. package/dist/api/compiler/character-codes.js +2 -2
  11. package/dist/api/compiler/checker-calls.js +178 -124
  12. package/dist/api/compiler/checker-classes.d.ts +14 -3
  13. package/dist/api/compiler/checker-classes.js +134 -90
  14. package/dist/api/compiler/checker-contextual.js +64 -61
  15. package/dist/api/compiler/checker-declaration-order.js +79 -79
  16. package/dist/api/compiler/checker-declarations.d.ts +1 -0
  17. package/dist/api/compiler/checker-declarations.js +160 -136
  18. package/dist/api/compiler/checker-declared-types.js +67 -65
  19. package/dist/api/compiler/checker-decorators.js +77 -77
  20. package/dist/api/compiler/checker-deprecation.d.ts +8 -3
  21. package/dist/api/compiler/checker-deprecation.js +76 -55
  22. package/dist/api/compiler/checker-destructuring.js +47 -45
  23. package/dist/api/compiler/checker-elaboration.js +24 -24
  24. package/dist/api/compiler/checker-emit-helpers.js +4 -4
  25. package/dist/api/compiler/checker-emit-resolver.d.ts +4 -2
  26. package/dist/api/compiler/checker-emit-resolver.js +25 -13
  27. package/dist/api/compiler/checker-evaluator.js +9 -9
  28. package/dist/api/compiler/checker-expressions.js +244 -211
  29. package/dist/api/compiler/checker-functions.js +113 -107
  30. package/dist/api/compiler/checker-generated-code.d.ts +0 -11
  31. package/dist/api/compiler/checker-generated-code.js +28 -52
  32. package/dist/api/compiler/checker-grammar.d.ts +1 -0
  33. package/dist/api/compiler/checker-grammar.js +472 -440
  34. package/dist/api/compiler/checker-heritage.js +91 -93
  35. package/dist/api/compiler/checker-inference.d.ts +77 -5
  36. package/dist/api/compiler/checker-inference.js +487 -107
  37. package/dist/api/compiler/checker-iteration.d.ts +0 -10
  38. package/dist/api/compiler/checker-iteration.js +35 -52
  39. package/dist/api/compiler/checker-javascript.js +14 -14
  40. package/dist/api/compiler/checker-jsdoc.d.ts +8 -10
  41. package/dist/api/compiler/checker-jsdoc.js +67 -58
  42. package/dist/api/compiler/checker-jsx.js +105 -88
  43. package/dist/api/compiler/checker-members.d.ts +9 -2
  44. package/dist/api/compiler/checker-members.js +212 -75
  45. package/dist/api/compiler/checker-modules.d.ts +15 -6
  46. package/dist/api/compiler/checker-modules.js +469 -309
  47. package/dist/api/compiler/checker-narrowing.js +273 -189
  48. package/dist/api/compiler/checker-object-literals.js +25 -22
  49. package/dist/api/compiler/checker-operators.js +126 -118
  50. package/dist/api/compiler/checker-overloads.js +27 -27
  51. package/dist/api/compiler/checker-property-access.js +59 -55
  52. package/dist/api/compiler/checker-services.d.ts +1 -0
  53. package/dist/api/compiler/checker-services.js +222 -210
  54. package/dist/api/compiler/checker-signatures.js +65 -49
  55. package/dist/api/compiler/checker-source-file.d.ts +5 -0
  56. package/dist/api/compiler/checker-source-file.js +154 -130
  57. package/dist/api/compiler/checker-statements.js +33 -32
  58. package/dist/api/compiler/checker-super.js +50 -50
  59. package/dist/api/compiler/checker-symbol-types.js +109 -93
  60. package/dist/api/compiler/checker-symbols.d.ts +13 -1
  61. package/dist/api/compiler/checker-symbols.js +264 -149
  62. package/dist/api/compiler/checker-type-factory.d.ts +5 -0
  63. package/dist/api/compiler/checker-type-factory.js +145 -36
  64. package/dist/api/compiler/checker-type-nodes.d.ts +1 -0
  65. package/dist/api/compiler/checker-type-nodes.js +179 -141
  66. package/dist/api/compiler/checker-type-operators.d.ts +2 -0
  67. package/dist/api/compiler/checker-type-operators.js +110 -63
  68. package/dist/api/compiler/checker-types.d.ts +80 -3
  69. package/dist/api/compiler/checker-types.js +121 -2
  70. package/dist/api/compiler/checker-unused.js +114 -118
  71. package/dist/api/compiler/checker-utilities.js +11 -11
  72. package/dist/api/compiler/checker.d.ts +104 -31
  73. package/dist/api/compiler/checker.js +181 -33
  74. package/dist/api/compiler/command-line.d.ts +1 -3
  75. package/dist/api/compiler/command-line.js +47 -44
  76. package/dist/api/compiler/compile-program.d.ts +42 -3
  77. package/dist/api/compiler/compile-program.js +139 -27
  78. package/dist/api/compiler/diagnostic-messages.d.ts +1849 -1774
  79. package/dist/api/compiler/diagnostic-messages.js +128 -122
  80. package/dist/api/compiler/diagnostics.d.ts +22 -0
  81. package/dist/api/compiler/diagnostics.js +93 -11
  82. package/dist/api/compiler/emitter.d.ts +7 -1
  83. package/dist/api/compiler/emitter.js +53 -11
  84. package/dist/api/compiler/file-include.d.ts +2 -1
  85. package/dist/api/compiler/file-include.js +11 -7
  86. package/dist/api/compiler/file-loader.d.ts +21 -1
  87. package/dist/api/compiler/file-loader.js +201 -48
  88. package/dist/api/compiler/instantiation.d.ts +7 -0
  89. package/dist/api/compiler/instantiation.js +101 -49
  90. package/dist/api/compiler/jsdoc.js +23 -23
  91. package/dist/api/compiler/link-tables.d.ts +48 -18
  92. package/dist/api/compiler/link-tables.js +80 -37
  93. package/dist/api/compiler/locales/cs-CZ.d.ts +1 -1
  94. package/dist/api/compiler/locales/cs-CZ.js +1 -1
  95. package/dist/api/compiler/locales/de-DE.d.ts +1 -1
  96. package/dist/api/compiler/locales/de-DE.js +1 -1
  97. package/dist/api/compiler/locales/es-ES.d.ts +1 -1
  98. package/dist/api/compiler/locales/es-ES.js +1 -1
  99. package/dist/api/compiler/locales/fr-FR.d.ts +1 -1
  100. package/dist/api/compiler/locales/fr-FR.js +1 -1
  101. package/dist/api/compiler/locales/it-IT.d.ts +1 -1
  102. package/dist/api/compiler/locales/it-IT.js +1 -1
  103. package/dist/api/compiler/locales/ja-JP.d.ts +1 -1
  104. package/dist/api/compiler/locales/ja-JP.js +1 -1
  105. package/dist/api/compiler/locales/ko-KR.d.ts +1 -1
  106. package/dist/api/compiler/locales/ko-KR.js +1 -1
  107. package/dist/api/compiler/locales/pl-PL.d.ts +1 -1
  108. package/dist/api/compiler/locales/pl-PL.js +1 -1
  109. package/dist/api/compiler/locales/pt-BR.d.ts +1 -1
  110. package/dist/api/compiler/locales/pt-BR.js +1 -1
  111. package/dist/api/compiler/locales/ru-RU.d.ts +1 -1
  112. package/dist/api/compiler/locales/ru-RU.js +1 -1
  113. package/dist/api/compiler/locales/tr-TR.d.ts +1 -1
  114. package/dist/api/compiler/locales/tr-TR.js +1 -1
  115. package/dist/api/compiler/locales/zh-CN.d.ts +1 -1
  116. package/dist/api/compiler/locales/zh-CN.js +1 -1
  117. package/dist/api/compiler/locales/zh-TW.d.ts +1 -1
  118. package/dist/api/compiler/locales/zh-TW.js +1 -1
  119. package/dist/api/compiler/module-resolution-types.js +6 -6
  120. package/dist/api/compiler/module-resolution.d.ts +10 -1
  121. package/dist/api/compiler/module-resolution.js +115 -84
  122. package/dist/api/compiler/module-specifiers.d.ts +15 -0
  123. package/dist/api/compiler/module-specifiers.js +24 -18
  124. package/dist/api/compiler/name-resolver.js +74 -65
  125. package/dist/api/compiler/node-builder-names.d.ts +11 -3
  126. package/dist/api/compiler/node-builder-names.js +210 -90
  127. package/dist/api/compiler/node-builder-pseudo.js +29 -31
  128. package/dist/api/compiler/node-builder-reuse.js +23 -22
  129. package/dist/api/compiler/node-builder.d.ts +18 -1
  130. package/dist/api/compiler/node-builder.js +191 -102
  131. package/dist/api/compiler/option-declarations.d.ts +2 -6
  132. package/dist/api/compiler/option-declarations.js +315 -375
  133. package/dist/api/compiler/options.d.ts +15 -33
  134. package/dist/api/compiler/options.js +21 -54
  135. package/dist/api/compiler/output-paths.d.ts +4 -1
  136. package/dist/api/compiler/output-paths.js +6 -11
  137. package/dist/api/compiler/package-json.d.ts +3 -3
  138. package/dist/api/compiler/package-json.js +11 -10
  139. package/dist/api/compiler/parallel-parse.d.ts +3 -2
  140. package/dist/api/compiler/parallel-parse.js +17 -5
  141. package/dist/api/compiler/parser.d.ts +40 -19
  142. package/dist/api/compiler/parser.js +308 -216
  143. package/dist/api/compiler/path.d.ts +9 -0
  144. package/dist/api/compiler/path.js +20 -3
  145. package/dist/api/compiler/printer/emit-context.d.ts +5 -1
  146. package/dist/api/compiler/printer/emit-context.js +20 -1
  147. package/dist/api/compiler/printer/factory-base.d.ts +2 -2
  148. package/dist/api/compiler/printer/factory-base.js +7 -3
  149. package/dist/api/compiler/printer/factory.js +3 -1
  150. package/dist/api/compiler/printer/helpers.js +10 -1
  151. package/dist/api/compiler/printer/name-generator.d.ts +1 -1
  152. package/dist/api/compiler/printer/name-generator.js +35 -16
  153. package/dist/api/compiler/printer/printer.d.ts +49 -2
  154. package/dist/api/compiler/printer/printer.js +539 -293
  155. package/dist/api/compiler/printer/utilities.js +149 -147
  156. package/dist/api/compiler/program-checker.d.ts +12 -2
  157. package/dist/api/compiler/program-checker.js +88 -34
  158. package/dist/api/compiler/program-utilities.d.ts +3 -1
  159. package/dist/api/compiler/program-utilities.js +28 -15
  160. package/dist/api/compiler/program.d.ts +4 -6
  161. package/dist/api/compiler/program.js +74 -87
  162. package/dist/api/compiler/pseudo-bigint.d.ts +2 -0
  163. package/dist/api/compiler/pseudo-bigint.js +18 -0
  164. package/dist/api/compiler/regexp-checker.d.ts +1 -1
  165. package/dist/api/compiler/regexp-checker.js +93 -76
  166. package/dist/api/compiler/relations.d.ts +27 -4
  167. package/dist/api/compiler/relations.js +347 -180
  168. package/dist/api/compiler/reparser.js +60 -56
  169. package/dist/api/compiler/scanner.d.ts +19 -2
  170. package/dist/api/compiler/scanner.js +123 -108
  171. package/dist/api/compiler/shared-results.d.ts +463 -0
  172. package/dist/api/compiler/shared-results.js +2128 -0
  173. package/dist/api/compiler/sourcemap.js +2 -2
  174. package/dist/api/compiler/symbol-accessibility.js +87 -74
  175. package/dist/api/compiler/symbol.d.ts +23 -14
  176. package/dist/api/compiler/symbol.js +23 -11
  177. package/dist/api/compiler/syntax-kind.d.ts +198 -197
  178. package/dist/api/compiler/transformers/alias-references.js +247 -139
  179. package/dist/api/compiler/transformers/async-utilities.js +25 -25
  180. package/dist/api/compiler/transformers/async.d.ts +0 -1
  181. package/dist/api/compiler/transformers/async.js +64 -77
  182. package/dist/api/compiler/transformers/class-fields.d.ts +1 -0
  183. package/dist/api/compiler/transformers/class-fields.js +81 -78
  184. package/dist/api/compiler/transformers/commonjs-module.js +18 -15
  185. package/dist/api/compiler/transformers/const-enum-inliner.js +1 -1
  186. package/dist/api/compiler/transformers/declarations-diagnostics.js +247 -244
  187. package/dist/api/compiler/transformers/declarations-pseudo.js +100 -100
  188. package/dist/api/compiler/transformers/declarations-resolver.d.ts +0 -3
  189. package/dist/api/compiler/transformers/declarations-syntactic.d.ts +1 -2
  190. package/dist/api/compiler/transformers/declarations-syntactic.js +134 -156
  191. package/dist/api/compiler/transformers/declarations-tracker.js +18 -18
  192. package/dist/api/compiler/transformers/declarations.d.ts +4 -1
  193. package/dist/api/compiler/transformers/declarations.js +305 -238
  194. package/dist/api/compiler/transformers/decorator-metadata.d.ts +1 -1
  195. package/dist/api/compiler/transformers/decorator-metadata.js +53 -45
  196. package/dist/api/compiler/transformers/decorator-utilities.js +24 -24
  197. package/dist/api/compiler/transformers/destructuring.js +19 -18
  198. package/dist/api/compiler/transformers/emit-resolver.js +1 -1
  199. package/dist/api/compiler/transformers/es-decorators.js +55 -55
  200. package/dist/api/compiler/transformers/external-module-info.js +3 -3
  201. package/dist/api/compiler/transformers/for-await.js +25 -25
  202. package/dist/api/compiler/transformers/import-elision.js +14 -14
  203. package/dist/api/compiler/transformers/jsx.js +12 -12
  204. package/dist/api/compiler/transformers/legacy-decorators.js +17 -17
  205. package/dist/api/compiler/transformers/module.js +8 -8
  206. package/dist/api/compiler/transformers/named-evaluation.js +4 -4
  207. package/dist/api/compiler/transformers/object-rest-spread.js +20 -20
  208. package/dist/api/compiler/transformers/optional-chain.js +10 -10
  209. package/dist/api/compiler/transformers/reference-resolver.d.ts +12 -1
  210. package/dist/api/compiler/transformers/reference-resolver.js +131 -69
  211. package/dist/api/compiler/transformers/runtime-syntax.js +35 -31
  212. package/dist/api/compiler/transformers/subtree-facts.js +47 -47
  213. package/dist/api/compiler/transformers/syntax-facts.js +56 -58
  214. package/dist/api/compiler/transformers/type-eraser.js +73 -66
  215. package/dist/api/compiler/transformers/type-serialization.js +24 -24
  216. package/dist/api/compiler/transformers/using.js +12 -12
  217. package/dist/api/compiler/transformers/utilities.js +77 -77
  218. package/dist/api/compiler/transformers/visitor-base.js +172 -172
  219. package/dist/api/compiler/transformers/visitor-hooks.js +6 -2
  220. package/dist/api/compiler/tsconfig.d.ts +10 -2
  221. package/dist/api/compiler/tsconfig.js +136 -48
  222. package/dist/api/compiler/type-printer.js +40 -3
  223. package/dist/api/compiler/types.d.ts +2 -1
  224. package/dist/api/library/ast.generated.d.ts +42 -39
  225. package/dist/api/library/ast.generated.js +1 -1
  226. package/dist/api/library/compiler-options.generated.d.ts +111 -100
  227. package/dist/api/library/compiler-options.generated.js +1 -1
  228. package/dist/api/library/disk.js +12 -1
  229. package/dist/api/library/enums.generated.d.ts +206 -206
  230. package/dist/api/library/enums.generated.js +206 -206
  231. package/dist/api/library/nodes.js +26 -26
  232. package/package.json +9 -9
  233. package/src/compiler/ast-utilities.ts +99 -7
  234. package/src/compiler/ast.ts +58 -26
  235. package/src/compiler/binder.ts +39 -4
  236. package/src/compiler/character-codes.ts +2 -2
  237. package/src/compiler/checker-calls.ts +79 -9
  238. package/src/compiler/checker-classes.ts +78 -24
  239. package/src/compiler/checker-contextual.ts +6 -1
  240. package/src/compiler/checker-declarations.ts +31 -4
  241. package/src/compiler/checker-declared-types.ts +8 -5
  242. package/src/compiler/checker-decorators.ts +1 -1
  243. package/src/compiler/checker-deprecation.ts +29 -8
  244. package/src/compiler/checker-destructuring.ts +10 -3
  245. package/src/compiler/checker-emit-helpers.ts +1 -0
  246. package/src/compiler/checker-emit-resolver.ts +16 -6
  247. package/src/compiler/checker-expressions.ts +79 -46
  248. package/src/compiler/checker-functions.ts +21 -6
  249. package/src/compiler/checker-generated-code.ts +2 -22
  250. package/src/compiler/checker-grammar.ts +136 -62
  251. package/src/compiler/checker-heritage.ts +22 -21
  252. package/src/compiler/checker-inference.ts +514 -82
  253. package/src/compiler/checker-iteration.ts +18 -31
  254. package/src/compiler/checker-javascript.ts +1 -1
  255. package/src/compiler/checker-jsdoc.ts +50 -27
  256. package/src/compiler/checker-jsx.ts +26 -4
  257. package/src/compiler/checker-members.ts +200 -56
  258. package/src/compiler/checker-modules.ts +332 -65
  259. package/src/compiler/checker-narrowing.ts +98 -19
  260. package/src/compiler/checker-object-literals.ts +3 -0
  261. package/src/compiler/checker-operators.ts +11 -4
  262. package/src/compiler/checker-property-access.ts +7 -2
  263. package/src/compiler/checker-services.ts +39 -12
  264. package/src/compiler/checker-signatures.ts +15 -1
  265. package/src/compiler/checker-source-file.ts +39 -13
  266. package/src/compiler/checker-statements.ts +3 -2
  267. package/src/compiler/checker-symbol-types.ts +29 -6
  268. package/src/compiler/checker-symbols.ts +158 -15
  269. package/src/compiler/checker-type-factory.ts +124 -23
  270. package/src/compiler/checker-type-nodes.ts +46 -3
  271. package/src/compiler/checker-type-operators.ts +83 -26
  272. package/src/compiler/checker-types.ts +147 -4
  273. package/src/compiler/checker-unused.ts +9 -14
  274. package/src/compiler/checker.ts +203 -39
  275. package/src/compiler/command-line.ts +28 -28
  276. package/src/compiler/compile-program.ts +167 -27
  277. package/src/compiler/decoder.ts +13 -4
  278. package/src/compiler/diagnostic-messages.ts +1973 -1892
  279. package/src/compiler/diagnostics.ts +84 -3
  280. package/src/compiler/emitter.ts +57 -8
  281. package/src/compiler/encoder.ts +23 -8
  282. package/src/compiler/file-include.ts +9 -3
  283. package/src/compiler/file-loader.ts +197 -38
  284. package/src/compiler/help.ts +10 -14
  285. package/src/compiler/incremental.ts +165 -30
  286. package/src/compiler/init.ts +2 -7
  287. package/src/compiler/instantiation.ts +77 -22
  288. package/src/compiler/jsdoc.ts +3 -1
  289. package/src/compiler/link-tables.ts +82 -37
  290. package/src/compiler/locales/cs-CZ.ts +1 -1
  291. package/src/compiler/locales/de-DE.ts +1 -1
  292. package/src/compiler/locales/es-ES.ts +1 -1
  293. package/src/compiler/locales/fr-FR.ts +1 -1
  294. package/src/compiler/locales/it-IT.ts +1 -1
  295. package/src/compiler/locales/ja-JP.ts +1 -1
  296. package/src/compiler/locales/ko-KR.ts +1 -1
  297. package/src/compiler/locales/pl-PL.ts +1 -1
  298. package/src/compiler/locales/pt-BR.ts +1 -1
  299. package/src/compiler/locales/ru-RU.ts +1 -1
  300. package/src/compiler/locales/tr-TR.ts +1 -1
  301. package/src/compiler/locales/zh-CN.ts +1 -1
  302. package/src/compiler/locales/zh-TW.ts +1 -1
  303. package/src/compiler/module-resolution.ts +44 -8
  304. package/src/compiler/module-specifiers.ts +62 -20
  305. package/src/compiler/name-resolver.ts +9 -1
  306. package/src/compiler/node-builder-names.ts +236 -54
  307. package/src/compiler/node-builder-pseudo.ts +4 -7
  308. package/src/compiler/node-builder-reuse.ts +5 -4
  309. package/src/compiler/node-builder.ts +130 -31
  310. package/src/compiler/option-declarations.ts +33 -103
  311. package/src/compiler/options.ts +23 -62
  312. package/src/compiler/output-paths.ts +5 -18
  313. package/src/compiler/package-entrypoints.ts +345 -0
  314. package/src/compiler/package-json.ts +4 -4
  315. package/src/compiler/parallel-check.ts +326 -52
  316. package/src/compiler/parallel-emit.ts +320 -0
  317. package/src/compiler/parallel-parse.ts +16 -5
  318. package/src/compiler/parse-thread.ts +3 -0
  319. package/src/compiler/parser.ts +156 -39
  320. package/src/compiler/path.ts +22 -2
  321. package/src/compiler/printer/emit-context.ts +21 -0
  322. package/src/compiler/printer/factory-base.ts +10 -3
  323. package/src/compiler/printer/factory.ts +4 -1
  324. package/src/compiler/printer/helpers.ts +10 -1
  325. package/src/compiler/printer/name-generator.ts +24 -2
  326. package/src/compiler/printer/printer.ts +266 -30
  327. package/src/compiler/printer/utilities.ts +8 -2
  328. package/src/compiler/program-checker.ts +57 -5
  329. package/src/compiler/program-utilities.ts +23 -10
  330. package/src/compiler/program.ts +18 -26
  331. package/src/compiler/pseudo-bigint.ts +17 -0
  332. package/src/compiler/regexp-checker.ts +63 -30
  333. package/src/compiler/relations.ts +240 -77
  334. package/src/compiler/reparser.ts +7 -2
  335. package/src/compiler/scanner.ts +109 -79
  336. package/src/compiler/shared-results.ts +2414 -0
  337. package/src/compiler/show-config.ts +18 -1
  338. package/src/compiler/sourcemap.ts +2 -2
  339. package/src/compiler/symbol-accessibility.ts +26 -3
  340. package/src/compiler/symbol.ts +46 -24
  341. package/src/compiler/syntax-kind.ts +188 -187
  342. package/src/compiler/thread-entry.ts +64 -4
  343. package/src/compiler/transformers/alias-references.ts +123 -4
  344. package/src/compiler/transformers/async.ts +2 -17
  345. package/src/compiler/transformers/class-fields.ts +13 -12
  346. package/src/compiler/transformers/commonjs-module.ts +11 -7
  347. package/src/compiler/transformers/declarations-diagnostics.ts +5 -3
  348. package/src/compiler/transformers/declarations-pseudo.ts +2 -4
  349. package/src/compiler/transformers/declarations-resolver.ts +0 -3
  350. package/src/compiler/transformers/declarations-syntactic.ts +1 -21
  351. package/src/compiler/transformers/declarations.ts +134 -48
  352. package/src/compiler/transformers/decorator-metadata.ts +9 -1
  353. package/src/compiler/transformers/destructuring.ts +4 -3
  354. package/src/compiler/transformers/external-module-info.ts +1 -1
  355. package/src/compiler/transformers/jsx.ts +2 -1
  356. package/src/compiler/transformers/reference-resolver.ts +83 -19
  357. package/src/compiler/transformers/runtime-syntax.ts +6 -1
  358. package/src/compiler/transformers/syntax-facts.ts +2 -7
  359. package/src/compiler/transformers/type-eraser.ts +10 -1
  360. package/src/compiler/transformers/type-serialization.ts +3 -2
  361. package/src/compiler/transformers/visitor-base.ts +2 -1
  362. package/src/compiler/transformers/visitor-hooks.ts +9 -4
  363. package/src/compiler/tsc-build.ts +66 -9
  364. package/src/compiler/tsc-cli.ts +7 -0
  365. package/src/compiler/tsc-compile.ts +284 -4
  366. package/src/compiler/tsc-watch.ts +74 -45
  367. package/src/compiler/tsconfig.ts +176 -19
  368. package/src/compiler/type-printer.ts +36 -2
  369. package/src/compiler/types.ts +2 -1
  370. package/src/library/ast.generated.ts +57 -41
  371. package/src/library/compiler-options.generated.ts +117 -103
  372. package/src/library/disk.ts +10 -1
  373. package/src/library/enums.generated.ts +196 -196
@@ -56,6 +56,7 @@ import {
56
56
  import type { EmitResolver } from './emit-resolver.js';
57
57
  import { ConstantKind, type Evaluation } from './reference-resolver.js';
58
58
  import { type TypeScriptFacts } from './subtree-facts.js';
59
+ import { nodeIsDecorated } from './decorator-utilities.js';
59
60
  import { Transformer } from './transformer.js';
60
61
  import {
61
62
  getInnermostModuleDeclaration,
@@ -65,6 +66,7 @@ import {
65
66
  isInstantiatedModule,
66
67
  isParameterPropertyDeclaration,
67
68
  isSameNode,
69
+ modifierFlagsOf,
68
70
  } from './utilities.js';
69
71
 
70
72
  const typeScriptModifiers =
@@ -577,7 +579,10 @@ export class RuntimeSyntax extends Transformer {
577
579
  let name = visitedName instanceof Identifier ? (visitedName as Identifier) : undefined;
578
580
  if (
579
581
  name === undefined &&
580
- (exported || childIsDecorated(this.options.experimentalDecorators === true, node.members))
582
+ (exported ||
583
+ childIsDecorated(this.options.experimentalDecorators === true, node.members) ||
584
+ ((modifierFlagsOf(node) & exportDefault) !== exportDefault &&
585
+ nodeIsDecorated(this.options.experimentalDecorators === true, node, undefined, undefined)))
581
586
  )
582
587
  name = this.factory.createGeneratedNameForNode(node, 0, '', '');
583
588
  const updated: Node = this.factory.updateClassDeclaration(
@@ -4,7 +4,6 @@ import {
4
4
  BinaryExpression,
5
5
  BindingElement,
6
6
  BindingPattern,
7
- CallExpression,
8
7
  CatchClause,
9
8
  ForInOrOfStatement,
10
9
  FunctionDeclaration,
@@ -29,6 +28,7 @@ import {
29
28
  import { ClusteredIntLinkTable } from '../link-tables.js';
30
29
  import { isTypeNodeKind } from '../printer/utilities.js';
31
30
  import { SyntaxKind } from '../syntax-kind.js';
31
+ import { isImportCall } from '../ast-utilities.js';
32
32
  import { TokenFlags } from '../types.js';
33
33
  import { getElementsOfBindingOrAssignmentPattern, getTargetOfBindingOrAssignmentElement } from './destructuring.js';
34
34
 
@@ -267,12 +267,7 @@ export class SyntaxFacts extends NodeVisitor {
267
267
  : SubtreeFacts.None)
268
268
  );
269
269
  case SyntaxKind.CallExpression:
270
- return (
271
- this.children(node) |
272
- (node instanceof CallExpression && node.expression.kind === SyntaxKind.ImportKeyword
273
- ? SubtreeFacts.ContainsDynamicImport
274
- : SubtreeFacts.None)
275
- );
270
+ return this.children(node) | (isImportCall(node) ? SubtreeFacts.ContainsDynamicImport : SubtreeFacts.None);
276
271
  case SyntaxKind.MetaProperty:
277
272
  return node instanceof MetaProperty ? this.propagate(node.name) & ~SubtreeFacts.ContainsIdentifier : 0;
278
273
  case SyntaxKind.SpreadElement:
@@ -398,7 +398,16 @@ export class TypeEraser extends Transformer {
398
398
  case SyntaxKind.ImportClause:
399
399
  if (node instanceof ImportClause) {
400
400
  if (node.phaseModifier === SyntaxKind.TypeKeyword) return undefined;
401
- const bindings = this.visitNode(node.namedBindings);
401
+ let bindings = this.visitNode(node.namedBindings);
402
+ // With a default import, `{}` left by erasing type-only specifiers goes; a `{}` written in the source stays.
403
+ if (
404
+ node.name !== undefined &&
405
+ bindings instanceof NamedImports &&
406
+ bindings.elements.nodes.length === 0 &&
407
+ node.namedBindings instanceof NamedImports &&
408
+ node.namedBindings.elements.nodes.length !== 0
409
+ )
410
+ bindings = undefined;
402
411
  if (node.name === undefined && bindings === undefined) return undefined;
403
412
  return factory.updateImportClause(node, node.phaseModifier, node.name, bindings);
404
413
  }
@@ -22,6 +22,7 @@ import {
22
22
  UnionTypeNode,
23
23
  VariableDeclaration,
24
24
  getIsTypeOnly,
25
+ getText,
25
26
  } from '../ast.js';
26
27
  import { getStrictOptionValue } from '../options.js';
27
28
  import { SyntaxKind } from '../syntax-kind.js';
@@ -119,10 +120,10 @@ function resolveEntityName(
119
120
  const namespace = resolveEntityName(resolver, name.left, SymbolFlags.Namespace, false, location);
120
121
  if (namespace === undefined) return undefined;
121
122
  if (namespace === unknownSymbol) return namespace;
122
- let member = resolver.getExportOfSymbol(namespace, name.right.text);
123
+ let member = resolver.getExportOfSymbol(namespace, getText(name.right));
123
124
  if (member === undefined && (namespace.flags & SymbolFlags.Alias) !== 0) {
124
125
  const target = resolver.resolveAlias(namespace);
125
- if (target !== undefined) member = resolver.getExportOfSymbol(target, name.right.text);
126
+ if (target !== undefined) member = resolver.getExportOfSymbol(target, getText(name.right));
126
127
  }
127
128
  if (member === undefined || (member.flags & (meaning | SymbolFlags.Alias)) === 0) return undefined;
128
129
  symbol = member;
@@ -1186,6 +1186,7 @@ export abstract class VisitorBase extends VisitorHooks {
1186
1186
  this.visitModifiers(node.modifiers),
1187
1187
  node.keyword,
1188
1188
  required(this.visitNode(node.name), node.name),
1189
+ this.visitNode(node.attributes) as TypeLiteralNode | undefined,
1189
1190
  this.visitNode(node.body),
1190
1191
  );
1191
1192
  break;
@@ -1340,7 +1341,7 @@ export abstract class VisitorBase extends VisitorHooks {
1340
1341
  return this.factory.updateQualifiedName(
1341
1342
  node,
1342
1343
  required(this.visitNode(node.left), node.left),
1343
- asIdentifier(this.visitNode(node.right), node.right),
1344
+ required(this.visitNode(node.right), node.right),
1344
1345
  );
1345
1346
  break;
1346
1347
  case SyntaxKind.RestType:
@@ -144,11 +144,16 @@ export abstract class VisitorHooks {
144
144
  if (declarations.length === 0) return updated;
145
145
  const factory = this.factory;
146
146
  if (updated === undefined) return factory.createBlock(declarations, true);
147
- if (!(updated instanceof Block))
148
- return factory.createBlock(
149
- this.context.mergeEnvironment([factory.createReturnStatement(updated)], declarations),
150
- false,
147
+ if (!(updated instanceof Block)) {
148
+ // The return statement takes the expression's range, so its comments are emitted once, before `return`.
149
+ this.context.addEmitFlags(updated, EmitFlags.NoComments);
150
+ const block = this.context.convertToFunctionBlock(updated, false);
151
+ return factory.updateBlock(
152
+ block,
153
+ this.context.mergeEnvironmentList(block.statements, declarations),
154
+ block.multiLine,
151
155
  );
156
+ }
152
157
  return factory.updateBlock(
153
158
  updated,
154
159
  this.context.mergeEnvironmentList(updated.statements, declarations),
@@ -55,15 +55,20 @@ import {
55
55
  SystemFileSystem,
56
56
  } from './tsc-cli.js';
57
57
  import {
58
+ checkWhileThreadsEmit,
58
59
  emitFilesAndReportErrors,
60
+ emitKindsOf,
61
+ emitsOnThreads,
59
62
  exitStatusOf,
60
63
  rechecksOnThreads,
64
+ reportEmitAndErrors,
61
65
  Statistics,
62
66
  statisticsOf,
63
67
  SystemTimeStamps,
64
68
  } from './tsc-compile.js';
65
69
  import { sharesPublishedGraphs } from '@scriptc/threads';
66
70
  import { checkerThreads, parseThreads, shareWithCheckers, startParallelCheck } from './parallel-check.js';
71
+ import { emitThreads } from './parallel-emit.js';
67
72
  import { LoadKind, ParseSession, clearPreparedFiles, parallelParse, reportPreparedFiles } from './parallel-parse.js';
68
73
  import { assignSymbolIdsAtCreation } from './symbol.js';
69
74
 
@@ -772,6 +777,9 @@ export class Orchestrator {
772
777
  times.parseTime = performance.now() - parseStart;
773
778
  const bindStart = performance.now();
774
779
  const checked = new CheckedProgram(program);
780
+ // The project's incremental program, made after checking, keeps the globals found checking a file
781
+ // with the file.
782
+ checked.globalsInFileDiagnostics = true;
775
783
  times.bindTime = performance.now() - bindStart;
776
784
  const options = program.options;
777
785
  const count = mayUseThreads ? checkerThreads(options.checkers, options.singleThreaded, program) : 1;
@@ -792,10 +800,58 @@ export class Orchestrator {
792
800
  });
793
801
  return true;
794
802
  }
803
+ if (mayUseThreads && this.emitsOnThreads(checked, oldSnapshot))
804
+ return this.checkWhileThreadsEmit(task, checked, times, oldSnapshot, then);
795
805
  this.emitAndReport(task, checked, times, oldSnapshot, undefined);
796
806
  return false;
797
807
  }
798
808
 
809
+ /**
810
+ * Whether `checkWhileThreadsEmit` builds the project of `checked`: one whose emit threads apply
811
+ * (`emitsOnThreads`), that emits every file (one without old build info, or one that is not incremental)
812
+ * and that emits enough for the threads (`emitThreads`).
813
+ */
814
+ private emitsOnThreads(checked: CheckedProgram, oldSnapshot: Snapshot | undefined): boolean {
815
+ const options = checked.program.options;
816
+ return (
817
+ emitsOnThreads(options) &&
818
+ (oldSnapshot === undefined || !isIncremental(options)) &&
819
+ emitThreads(checked.program, options.singleThreaded) > 0
820
+ );
821
+ }
822
+
823
+ /**
824
+ * The rest of `checkAndEmit` with one checker for a project that `emitsOnThreads` accepts, as `tsc -p` compiles
825
+ * (`compileWithEmitThreads`, tsc-compile.ts): this thread checks the program while emit threads emit its
826
+ * JavaScript, and the declaration thread its declarations where that pays (parallel-emit.ts). Where its pending
827
+ * emit leaves too little JavaScript for the threads (`emitDeclarationOnly`), this thread checks and emits it.
828
+ * Returns whether the threads emit, and then calls `then` once the project is emitted.
829
+ */
830
+ private checkWhileThreadsEmit(
831
+ task: BuildTask,
832
+ checked: CheckedProgram,
833
+ times: CompileTimes,
834
+ oldSnapshot: Snapshot | undefined,
835
+ then: () => void,
836
+ ): boolean {
837
+ const program = checked.program;
838
+ const options = program.options;
839
+ // The program is shared before its checker does more than merge the globals.
840
+ shareWithCheckers(checked);
841
+ const incrementalProgram = this.incrementalProgramOf(task, checked, times, oldSnapshot);
842
+ const emitKinds = emitKindsOf(incrementalProgram);
843
+ const threads = emitThreads(program, options.singleThreaded, emitKinds);
844
+ if (threads === 0) {
845
+ this.emitAndReport(task, checked, times, oldSnapshot, undefined, incrementalProgram);
846
+ return false;
847
+ }
848
+ checkWhileThreadsEmit(incrementalProgram, threads, emitKinds, (diagnostics) => {
849
+ this.emitAndReport(task, checked, times, oldSnapshot, undefined, incrementalProgram, diagnostics);
850
+ then();
851
+ });
852
+ return true;
853
+ }
854
+
799
855
  /**
800
856
  * The rest of `checkAndEmit` for a project with old build info on checker threads, as `tsc -p` rebuilds
801
857
  * (`recheckInParallel`, tsc-compile.ts): the program is shared with the threads first, then the
@@ -869,22 +925,23 @@ export class Orchestrator {
869
925
  oldSnapshot: Snapshot | undefined,
870
926
  /** The wall time of checker threads that checked the program, as reported. */
871
927
  parallelCheckTime: number | undefined,
872
- /** The incremental program, where `recheckOnThreads` made it. */
928
+ /** The incremental program, where `recheckOnThreads` or `checkWhileThreadsEmit` made it. */
873
929
  made?: IncrementalProgram,
930
+ /** The program's diagnostics, where `checkWhileThreadsEmit` collected them. */
931
+ diagnostics?: Diagnostic[],
874
932
  ): void {
875
933
  const resolved = task.resolved!;
876
934
  const sys = this.sys;
877
935
  const program = checked.program;
878
936
  const incrementalProgram = made ?? this.incrementalProgramOf(task, checked, times, oldSnapshot);
879
937
 
880
- const result = emitFilesAndReportErrors(
881
- sys,
882
- incrementalProgram,
883
- new TaskDiagnosticReporter(task, this.reporter, sys, this.locale),
884
- new QuietSummary(sys, {}, this.locale),
885
- new TaskWriter(this, task),
886
- this.locale,
887
- );
938
+ const reporter = new TaskDiagnosticReporter(task, this.reporter, sys, this.locale);
939
+ const summary = new QuietSummary(sys, {}, this.locale);
940
+ const writer = new TaskWriter(this, task);
941
+ const result =
942
+ diagnostics === undefined
943
+ ? emitFilesAndReportErrors(sys, incrementalProgram, reporter, summary, writer, this.locale)
944
+ : reportEmitAndErrors(sys, incrementalProgram, diagnostics, reporter, summary, writer, this.locale);
888
945
  task.exitStatus = exitStatusOf(result);
889
946
  if (parallelCheckTime !== undefined) times.checkTime = parallelCheckTime;
890
947
  const options = program.options;
@@ -64,6 +64,8 @@ export abstract class System extends CommandLineHost {
64
64
 
65
65
  /** Returns `''` for unset variables. */
66
66
  abstract getEnvironmentVariable(name: string): string;
67
+ /** Whether the variable is set, perhaps to `''`. */
68
+ abstract hasEnvironmentVariable(name: string): boolean;
67
69
  abstract write(text: string): void;
68
70
  abstract fileExists(path: string): boolean;
69
71
  abstract directoryExists(path: string): boolean;
@@ -199,6 +201,11 @@ export class DiagnosticReporter {
199
201
  else this.sys.write(formatDiagnostic(diagnostic, this.format));
200
202
  }
201
203
 
204
+ /** The format `reportAll` writes diagnostics in, where it writes them plainly; undefined otherwise. */
205
+ plainFormat(): DiagnosticFormatOptions | undefined {
206
+ return this.quiet || this.pretty ? undefined : this.format;
207
+ }
208
+
202
209
  /** Writes the diagnostics at once: a write for each costs more than formatting it. */
203
210
  reportAll(diagnostics: readonly Diagnostic[]): void {
204
211
  if (this.quiet || diagnostics.length === 0) return;
@@ -8,12 +8,15 @@ import {
8
8
  CheckedProgram,
9
9
  CompilerProgram,
10
10
  CompileTimes,
11
+ declarationDiagnosticsDue,
11
12
  getDiagnosticsOfProgram,
12
13
  OutputWriter,
13
14
  PlainProgram,
15
+ recordMetadataKinds,
14
16
  } from './compile-program.js';
15
- import type { Diagnostic, Locale } from './diagnostics.js';
16
- import { EmitResult } from './emitter.js';
17
+ import { type Diagnostic, formattedReports, type Locale } from './diagnostics.js';
18
+ import { EmitOnly, EmitResult } from './emitter.js';
19
+ import { type CompilerOptions, getEmitDeclarations } from './options.js';
17
20
  import {
18
21
  FileBuildInfoReader,
19
22
  IncrementalProgram,
@@ -21,7 +24,21 @@ import {
21
24
  type Snapshot,
22
25
  TimeStampHost,
23
26
  } from './incremental.js';
24
- import { checkerThreads, shareWithCheckers, startParallelCheck, traceSingleChecker } from './parallel-check.js';
27
+ import {
28
+ checkerThreads,
29
+ parallelCheck,
30
+ shareWithCheckers,
31
+ startParallelCheck,
32
+ traceSingleChecker,
33
+ } from './parallel-check.js';
34
+ import {
35
+ declarationThreadPays,
36
+ emitThreads,
37
+ startDeclarationErrorThread,
38
+ startDeclarationThread,
39
+ startMetadataEmit,
40
+ startParallelEmit,
41
+ } from './parallel-emit.js';
25
42
  import { sharesPublishedGraphs } from '@scriptc/threads';
26
43
  import { getNormalizedAbsolutePath } from './path.js';
27
44
  import { sortAndDeduplicateDiagnostics } from './program.js';
@@ -122,6 +139,215 @@ export function compileThreads(_sys: System, work: CompileWork): number {
122
139
  return checkerThreads(options.checkers, options.singleThreaded, work.program);
123
140
  }
124
141
 
142
+ /** The number of threads to emit JavaScript on while this thread checks (`compileWithEmitThreads`), or 0. */
143
+ export function compileEmitThreads(work: CompileWork): number {
144
+ return emitThreads(work.program, work.program.options.singleThreaded);
145
+ }
146
+
147
+ /**
148
+ * Like `compile`, with this thread checking the program while `threads` threads emit its JavaScript
149
+ * (parallel-emit.ts); calls `done` with the exit status once it is emitted and reported. Returns
150
+ * false, and `compile` runs instead, where emit threads don't apply (`emitsOnThreads`) and for an
151
+ * incremental program with build info, whose rebuild emits what changed. An incremental program
152
+ * without build info emits every file, as its pending emit holds (`emitKindsOf`).
153
+ */
154
+ export function compileWithEmitThreads(
155
+ sys: System,
156
+ work: CompileWork,
157
+ threads: number,
158
+ done: (status: ExitStatus) => void,
159
+ ): boolean {
160
+ const program = work.program;
161
+ if (!emitsOnThreads(program.options)) return false;
162
+ if (work.incremental && !checksIncrementalOnThreads(sys, program.commandLine.buildInfoFileName())) return false;
163
+ const times = new CompileTimes();
164
+ times.configTime = work.configTime;
165
+ times.parseTime = work.parseTime;
166
+ const bindStart = performance.now();
167
+ const checked = new CheckedProgram(program);
168
+ times.bindTime = performance.now() - bindStart;
169
+ // The program is shared before its checker does more than merge the globals.
170
+ shareWithCheckers(checked);
171
+ let compilerProgram: CompilerProgram;
172
+ if (work.incremental) {
173
+ const old = oldSnapshotOf(sys, work, times);
174
+ const changesStart = performance.now();
175
+ compilerProgram = new IncrementalProgram(checked, times, old, new SystemTimeStamps(sys));
176
+ times.changesComputeTime = performance.now() - changesStart;
177
+ } else compilerProgram = new PlainProgram(checked, times);
178
+ const report = (diagnostics: Diagnostic[]): void => {
179
+ const result = reportEmitAndErrors(
180
+ sys,
181
+ compilerProgram,
182
+ diagnostics,
183
+ work.reporter,
184
+ work.errorSummary,
185
+ new SystemWriter(sys),
186
+ outputLocale(program.options),
187
+ );
188
+ traceSingleChecker(checked);
189
+ done(emitStatusAndReportStatistics(sys, compilerProgram, result));
190
+ };
191
+ const emitKinds = emitKindsOf(compilerProgram);
192
+ if (emitKinds !== undefined) threads = emitThreads(program, program.options.singleThreaded, emitKinds);
193
+ if (threads > 0) checkWhileThreadsEmit(compilerProgram, threads, emitKinds, report);
194
+ else {
195
+ const diagnostics = getDiagnosticsOfProgram(compilerProgram, false);
196
+ mark('diagnostics collected');
197
+ report(diagnostics);
198
+ }
199
+ return true;
200
+ }
201
+
202
+ /**
203
+ * Whether emit threads (parallel-emit.ts) can emit a program with `options` while this thread checks it:
204
+ * not one that emits nothing or waits for its errors to emit (`noEmitOnError`), nor one that emits a
205
+ * single `outFile` from the whole program.
206
+ */
207
+ export function emitsOnThreads(options: CompilerOptions): boolean {
208
+ return (
209
+ options.noEmit !== true &&
210
+ options.noEmitOnError !== true &&
211
+ options.listFilesOnly !== true &&
212
+ (options.outFile ?? '') === ''
213
+ );
214
+ }
215
+
216
+ /**
217
+ * What emit threads emit of each file of `program`, by file index (`emitsJavaScript`, parallel-emit.ts):
218
+ * for an incremental program that keeps incremental state, the emit pending before checking
219
+ * (`IncrementalProgram.emitKindsOnCheckers`), which checking only adds to and the program's emit
220
+ * completes; `undefined` where every file is emitted in full.
221
+ */
222
+ export function emitKindsOf(program: CompilerProgram): number[] | undefined {
223
+ if (!(program instanceof IncrementalProgram) || !program.snapshot.canUseIncrementalState()) return undefined;
224
+ return program.emitKindsOnCheckers(program.program.getSourceFiles());
225
+ }
226
+
227
+ /**
228
+ * Checks `compilerProgram` on this thread while `threads` emit threads emit the JavaScript of its files that
229
+ * `emitKinds` selects, and the declaration thread their declarations where that pays; then calls `report`
230
+ * with the program's diagnostics, once the outputs of every thread arrived for the program's emit to complete
231
+ * (`PlainProgram.emit`, `IncrementalProgram.emit`). The program must be shared (`shareWithCheckers`).
232
+ */
233
+ export function checkWhileThreadsEmit(
234
+ compilerProgram: CompilerProgram,
235
+ threads: number,
236
+ emitKinds: readonly number[] | undefined,
237
+ report: (diagnostics: Diagnostic[]) => void,
238
+ ): void {
239
+ const checked = compilerProgram.checked;
240
+ const program = checked.program;
241
+ let diagnostics: Diagnostic[] | undefined = undefined;
242
+ // The first wave of emit threads, and the declaration thread or the second wave.
243
+ let emitting = 2;
244
+ let declarations: (EmitResult | undefined)[] | undefined = undefined;
245
+ const reportOnce = (): void => {
246
+ if (diagnostics === undefined || emitting > 0) return;
247
+ if (declarations !== undefined) {
248
+ // The declaration thread emitted all of each decorator metadata file: its result is the file's emit.
249
+ for (const i of metadata) {
250
+ const result = declarations[i];
251
+ if (result === undefined) continue;
252
+ checked.emittedInParallel![i] = result;
253
+ declarations[i] = new EmitResult();
254
+ }
255
+ checked.declarationsEmittedAhead = declarations;
256
+ }
257
+ report(diagnostics);
258
+ };
259
+ const emitted = (): void => {
260
+ emitting--;
261
+ reportOnce();
262
+ };
263
+ const metadata = startParallelEmit(checked, threads, emitted, emitKinds);
264
+ // With declarations, the declaration thread also emits the files with decorator metadata.
265
+ if (getEmitDeclarations(program.options) && declarationThreadPays(1))
266
+ declarations = startDeclarationThread(checked, metadata, emitted, emitKinds);
267
+ const found = getDiagnosticsOfProgram(compilerProgram, false);
268
+ mark('diagnostics collected');
269
+ // Else they are emitted with the kinds this thread's checker gives, now that it checked.
270
+ if (declarations === undefined) {
271
+ if (metadata.length > 0) {
272
+ const files = program.getSourceFiles();
273
+ const kinds = recordMetadataKinds(
274
+ checked,
275
+ metadata.map((i) => files[i]!),
276
+ );
277
+ mark('metadata kinds recorded');
278
+ startMetadataEmit(checked, threads, metadata, kinds, emitted);
279
+ } else emitting--;
280
+ }
281
+ diagnostics = found;
282
+ reportOnce();
283
+ }
284
+
285
+ /**
286
+ * Like `compile` for a `noEmit` program with declarations, which reports the errors of declaration emit:
287
+ * this thread checks the program while the declaration thread (`startDeclarationErrorThread`) finds the
288
+ * declaration errors of every file, then reports both; calls `done` with the exit status. Returns false
289
+ * where the declaration thread doesn't apply, and `compile` runs instead: an incremental program, one
290
+ * that waits for its errors (`noEmitOnError`), a program that isn't shared with threads, or one where a
291
+ * declaration thread doesn't pay (`declarationThreadPays`).
292
+ */
293
+ export function compileWithDeclarationThread(
294
+ sys: System,
295
+ work: CompileWork,
296
+ done: (status: ExitStatus) => void,
297
+ ): boolean {
298
+ const program = work.program;
299
+ const options = program.options;
300
+ if (
301
+ work.incremental ||
302
+ options.noEmit !== true ||
303
+ options.noEmitOnError === true ||
304
+ options.listFilesOnly === true ||
305
+ options.singleThreaded === true ||
306
+ !getEmitDeclarations(options) ||
307
+ parallelCheck.spawn === undefined ||
308
+ !sharesPublishedGraphs ||
309
+ !declarationThreadPays(1)
310
+ )
311
+ return false;
312
+ const times = new CompileTimes();
313
+ times.configTime = work.configTime;
314
+ times.parseTime = work.parseTime;
315
+ const bindStart = performance.now();
316
+ const checked = new CheckedProgram(program);
317
+ times.bindTime = performance.now() - bindStart;
318
+ shareWithCheckers(checked);
319
+ const compilerProgram = new PlainProgram(checked, times);
320
+ let diagnostics: Diagnostic[] | undefined = undefined;
321
+ let declaring = true;
322
+ const report = (): void => {
323
+ if (diagnostics === undefined || declaring) return;
324
+ if (declarationDiagnosticsDue(compilerProgram, diagnostics, false))
325
+ for (const d of compilerProgram.getDeclarationDiagnostics()) diagnostics.push(d);
326
+ const result = reportEmitAndErrors(
327
+ sys,
328
+ compilerProgram,
329
+ diagnostics,
330
+ work.reporter,
331
+ work.errorSummary,
332
+ new SystemWriter(sys),
333
+ outputLocale(options),
334
+ );
335
+ traceSingleChecker(checked);
336
+ done(emitStatusAndReportStatistics(sys, compilerProgram, result));
337
+ };
338
+ startDeclarationErrorThread(checked, (declarations) => {
339
+ // `PlainProgram.getDeclarationDiagnostics` reads them.
340
+ checked.declarationsInParallel = declarations;
341
+ declaring = false;
342
+ report();
343
+ });
344
+ // `report` adds the declaration errors once the thread has found them, when they are due.
345
+ diagnostics = getDiagnosticsOfProgram(compilerProgram, false, true);
346
+ mark('diagnostics collected');
347
+ report();
348
+ return true;
349
+ }
350
+
125
351
  /**
126
352
  * Like `compile`, with `threads` checker threads (parallel-check.ts): calls `done` with the exit
127
353
  * status once the threads have checked the program and it is emitted and reported.
@@ -137,8 +363,12 @@ export function compileInParallel(
137
363
  times.configTime = work.configTime;
138
364
  times.parseTime = work.parseTime;
139
365
  const bindStart = performance.now();
366
+ // The checker threads format their diagnostics in the format the reporter writes them in.
367
+ formattedReports.format = work.reporter.plainFormat();
140
368
  mark(`${threads} checkers`);
141
369
  const checked = new CheckedProgram(program);
370
+ // The incremental program made after checking keeps the globals found checking a file with the file.
371
+ if (work.incremental) checked.globalsInFileDiagnostics = true;
142
372
  times.bindTime = performance.now() - bindStart;
143
373
  mark('checker created');
144
374
  if (work.incremental && !checksIncrementalOnThreads(sys, program.commandLine.buildInfoFileName())) {
@@ -176,6 +406,43 @@ export function compileInParallel(
176
406
  };
177
407
  const options = program.options;
178
408
  if (!checking && (options.noEmit === true || options.noEmitOnError === true)) return finish(0);
409
+ if (
410
+ sharesPublishedGraphs &&
411
+ checking &&
412
+ !work.incremental &&
413
+ getEmitDeclarations(options) &&
414
+ options.noEmit !== true &&
415
+ options.noEmitOnError !== true &&
416
+ options.composite !== true &&
417
+ (options.outFile ?? '') === '' &&
418
+ declarationThreadPays(threads)
419
+ ) {
420
+ // The checker threads emit JavaScript and the declaration thread declarations (parallel-emit.ts).
421
+ const kinds: number[] = [];
422
+ for (let i = 0; i < program.getSourceFiles().length; i++) kinds.push(EmitOnly.Js);
423
+ let pending = 2;
424
+ let checkTime = 0;
425
+ let declarations: (EmitResult | undefined)[] = [];
426
+ const joined = (): void => {
427
+ if (--pending > 0) return;
428
+ checked.javaScriptEmittedOnThreads = true;
429
+ checked.declarationsEmittedAhead = declarations;
430
+ finish(checkTime);
431
+ };
432
+ declarations = startDeclarationThread(checked, [], joined);
433
+ startParallelCheck(
434
+ checked,
435
+ threads,
436
+ (time) => {
437
+ checkTime = time;
438
+ joined();
439
+ },
440
+ true,
441
+ kinds,
442
+ checking,
443
+ );
444
+ return;
445
+ }
179
446
  startParallelCheck(checked, threads, finish, true, undefined, checking);
180
447
  }
181
448
 
@@ -285,12 +552,25 @@ export function emitFilesAndReportErrors(
285
552
  ): CompileResult {
286
553
  const diagnostics = getDiagnosticsOfProgram(program, false);
287
554
  mark('diagnostics collected');
555
+ return reportEmitAndErrors(sys, program, diagnostics, reporter, errorSummary, writer, locale);
556
+ }
557
+
558
+ /** The rest of `emitFilesAndReportErrors`, with the program's `diagnostics` collected. */
559
+ export function reportEmitAndErrors(
560
+ sys: System,
561
+ program: CompilerProgram,
562
+ diagnostics: Diagnostic[],
563
+ reporter: DiagnosticReporter,
564
+ errorSummary: ErrorSummaryReporter,
565
+ writer: OutputWriter,
566
+ locale: Locale,
567
+ ): CompileResult {
288
568
  let emitResult = new EmitResult();
289
569
  emitResult.emitSkipped = true;
290
570
  if (program.options.listFilesOnly !== true) {
291
571
  const emitStart = performance.now();
292
572
  emitResult = program.emit(writer);
293
- program.times.emitTime = performance.now() - emitStart;
573
+ program.times.emitTime += performance.now() - emitStart;
294
574
  }
295
575
  for (const diagnostic of emitResult.diagnostics) diagnostics.push(diagnostic);
296
576
  const all = sortAndDeduplicateDiagnostics(diagnostics);