tsc-ts 0.0.4 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (584) hide show
  1. package/README.md +34 -2
  2. package/dist/api/compiler/ast-utilities.d.ts +82 -0
  3. package/dist/api/compiler/ast-utilities.js +462 -0
  4. package/dist/api/compiler/ast.d.ts +2351 -0
  5. package/dist/api/compiler/ast.js +11212 -0
  6. package/dist/api/compiler/astnav.d.ts +37 -0
  7. package/dist/api/compiler/astnav.js +767 -0
  8. package/dist/api/compiler/binder-utilities.d.ts +182 -0
  9. package/dist/api/compiler/binder-utilities.js +1241 -0
  10. package/dist/api/compiler/binder.d.ts +33 -0
  11. package/dist/api/compiler/binder.js +2359 -0
  12. package/dist/api/compiler/character-codes.d.ts +161 -0
  13. package/dist/api/compiler/character-codes.js +160 -0
  14. package/dist/api/compiler/checker-calls.d.ts +46 -0
  15. package/dist/api/compiler/checker-calls.js +1641 -0
  16. package/dist/api/compiler/checker-classes.d.ts +30 -0
  17. package/dist/api/compiler/checker-classes.js +582 -0
  18. package/dist/api/compiler/checker-contextual.d.ts +77 -0
  19. package/dist/api/compiler/checker-contextual.js +1136 -0
  20. package/dist/api/compiler/checker-declaration-order.d.ts +12 -0
  21. package/dist/api/compiler/checker-declaration-order.js +357 -0
  22. package/dist/api/compiler/checker-declarations.d.ts +33 -0
  23. package/dist/api/compiler/checker-declarations.js +888 -0
  24. package/dist/api/compiler/checker-declared-types.d.ts +48 -0
  25. package/dist/api/compiler/checker-declared-types.js +788 -0
  26. package/dist/api/compiler/checker-decorators.d.ts +26 -0
  27. package/dist/api/compiler/checker-decorators.js +562 -0
  28. package/dist/api/compiler/checker-deprecation.d.ts +33 -0
  29. package/dist/api/compiler/checker-deprecation.js +314 -0
  30. package/dist/api/compiler/checker-destructuring.d.ts +34 -0
  31. package/dist/api/compiler/checker-destructuring.js +584 -0
  32. package/dist/api/compiler/checker-elaboration.d.ts +15 -0
  33. package/dist/api/compiler/checker-elaboration.js +291 -0
  34. package/dist/api/compiler/checker-emit-helpers.d.ts +58 -0
  35. package/dist/api/compiler/checker-emit-helpers.js +154 -0
  36. package/dist/api/compiler/checker-emit-resolver.d.ts +75 -0
  37. package/dist/api/compiler/checker-emit-resolver.js +580 -0
  38. package/dist/api/compiler/checker-evaluator.d.ts +27 -0
  39. package/dist/api/compiler/checker-evaluator.js +188 -0
  40. package/dist/api/compiler/checker-expressions.d.ts +67 -0
  41. package/dist/api/compiler/checker-expressions.js +1351 -0
  42. package/dist/api/compiler/checker-features.d.ts +6 -0
  43. package/dist/api/compiler/checker-features.js +354 -0
  44. package/dist/api/compiler/checker-flow.d.ts +86 -0
  45. package/dist/api/compiler/checker-flow.js +169 -0
  46. package/dist/api/compiler/checker-functions.d.ts +43 -0
  47. package/dist/api/compiler/checker-functions.js +1002 -0
  48. package/dist/api/compiler/checker-generated-code.d.ts +25 -0
  49. package/dist/api/compiler/checker-generated-code.js +168 -0
  50. package/dist/api/compiler/checker-globals.d.ts +14 -0
  51. package/dist/api/compiler/checker-globals.js +37 -0
  52. package/dist/api/compiler/checker-grammar.d.ts +35 -0
  53. package/dist/api/compiler/checker-grammar.js +2587 -0
  54. package/dist/api/compiler/checker-heritage.d.ts +28 -0
  55. package/dist/api/compiler/checker-heritage.js +901 -0
  56. package/dist/api/compiler/checker-inference.d.ts +179 -0
  57. package/dist/api/compiler/checker-inference.js +2105 -0
  58. package/dist/api/compiler/checker-iteration.d.ts +115 -0
  59. package/dist/api/compiler/checker-iteration.js +857 -0
  60. package/dist/api/compiler/checker-javascript.d.ts +42 -0
  61. package/dist/api/compiler/checker-javascript.js +442 -0
  62. package/dist/api/compiler/checker-jsdoc.d.ts +30 -0
  63. package/dist/api/compiler/checker-jsdoc.js +320 -0
  64. package/dist/api/compiler/checker-jsx.d.ts +94 -0
  65. package/dist/api/compiler/checker-jsx.js +1433 -0
  66. package/dist/api/compiler/checker-literals.d.ts +6 -0
  67. package/dist/api/compiler/checker-literals.js +43 -0
  68. package/dist/api/compiler/checker-members.d.ts +200 -0
  69. package/dist/api/compiler/checker-members.js +2148 -0
  70. package/dist/api/compiler/checker-modules.d.ts +85 -0
  71. package/dist/api/compiler/checker-modules.js +2141 -0
  72. package/dist/api/compiler/checker-narrowing.d.ts +120 -0
  73. package/dist/api/compiler/checker-narrowing.js +2797 -0
  74. package/dist/api/compiler/checker-object-literals.d.ts +14 -0
  75. package/dist/api/compiler/checker-object-literals.js +483 -0
  76. package/dist/api/compiler/checker-operators.d.ts +33 -0
  77. package/dist/api/compiler/checker-operators.js +1040 -0
  78. package/dist/api/compiler/checker-overloads.d.ts +7 -0
  79. package/dist/api/compiler/checker-overloads.js +271 -0
  80. package/dist/api/compiler/checker-property-access.d.ts +34 -0
  81. package/dist/api/compiler/checker-property-access.js +672 -0
  82. package/dist/api/compiler/checker-services.d.ts +49 -0
  83. package/dist/api/compiler/checker-services.js +995 -0
  84. package/dist/api/compiler/checker-signatures.d.ts +55 -0
  85. package/dist/api/compiler/checker-signatures.js +789 -0
  86. package/dist/api/compiler/checker-source-file.d.ts +27 -0
  87. package/dist/api/compiler/checker-source-file.js +619 -0
  88. package/dist/api/compiler/checker-statements.d.ts +18 -0
  89. package/dist/api/compiler/checker-statements.js +226 -0
  90. package/dist/api/compiler/checker-super.d.ts +13 -0
  91. package/dist/api/compiler/checker-super.js +241 -0
  92. package/dist/api/compiler/checker-symbol-types.d.ts +51 -0
  93. package/dist/api/compiler/checker-symbol-types.js +955 -0
  94. package/dist/api/compiler/checker-symbols.d.ts +181 -0
  95. package/dist/api/compiler/checker-symbols.js +1784 -0
  96. package/dist/api/compiler/checker-type-factory.d.ts +142 -0
  97. package/dist/api/compiler/checker-type-factory.js +2542 -0
  98. package/dist/api/compiler/checker-type-nodes.d.ts +26 -0
  99. package/dist/api/compiler/checker-type-nodes.js +828 -0
  100. package/dist/api/compiler/checker-type-operators.d.ts +109 -0
  101. package/dist/api/compiler/checker-type-operators.js +1842 -0
  102. package/dist/api/compiler/checker-types.d.ts +1093 -0
  103. package/dist/api/compiler/checker-types.js +1874 -0
  104. package/dist/api/compiler/checker-unused.d.ts +19 -0
  105. package/dist/api/compiler/checker-unused.js +524 -0
  106. package/dist/api/compiler/checker-utilities.d.ts +33 -0
  107. package/dist/api/compiler/checker-utilities.js +141 -0
  108. package/dist/api/compiler/checker.d.ts +512 -0
  109. package/dist/api/compiler/checker.js +932 -0
  110. package/dist/api/compiler/command-line.d.ts +32 -0
  111. package/dist/api/compiler/command-line.js +383 -0
  112. package/dist/api/compiler/compile-program.d.ts +118 -0
  113. package/dist/api/compiler/compile-program.js +384 -0
  114. package/dist/api/compiler/diagnostic-locales.d.ts +22 -0
  115. package/dist/api/compiler/diagnostic-locales.js +64 -0
  116. package/dist/api/compiler/diagnostic-messages.d.ts +2166 -0
  117. package/dist/api/compiler/diagnostic-messages.js +184 -0
  118. package/dist/api/compiler/diagnostics.d.ts +161 -0
  119. package/dist/api/compiler/diagnostics.js +784 -0
  120. package/dist/api/compiler/emitter.d.ts +71 -0
  121. package/dist/api/compiler/emitter.js +327 -0
  122. package/dist/api/compiler/file-include.d.ts +144 -0
  123. package/dist/api/compiler/file-include.js +599 -0
  124. package/dist/api/compiler/file-loader.d.ts +290 -0
  125. package/dist/api/compiler/file-loader.js +1323 -0
  126. package/dist/api/compiler/file-system.d.ts +51 -0
  127. package/dist/api/compiler/file-system.js +132 -0
  128. package/dist/api/compiler/flow.d.ts +60 -0
  129. package/dist/api/compiler/flow.js +45 -0
  130. package/dist/api/compiler/instantiation.d.ts +74 -0
  131. package/dist/api/compiler/instantiation.js +835 -0
  132. package/dist/api/compiler/jsdoc.d.ts +75 -0
  133. package/dist/api/compiler/jsdoc.js +1229 -0
  134. package/dist/api/compiler/link-tables.d.ts +105 -0
  135. package/dist/api/compiler/link-tables.js +319 -0
  136. package/dist/api/compiler/locale-data.d.ts +24 -0
  137. package/dist/api/compiler/locale-data.js +183 -0
  138. package/dist/api/compiler/locale.d.ts +4 -0
  139. package/dist/api/compiler/locale.js +317 -0
  140. package/dist/api/compiler/locales/cs-CZ.d.ts +2 -0
  141. package/dist/api/compiler/locales/cs-CZ.js +3 -0
  142. package/dist/api/compiler/locales/de-DE.d.ts +2 -0
  143. package/dist/api/compiler/locales/de-DE.js +3 -0
  144. package/dist/api/compiler/locales/es-ES.d.ts +2 -0
  145. package/dist/api/compiler/locales/es-ES.js +3 -0
  146. package/dist/api/compiler/locales/fr-FR.d.ts +2 -0
  147. package/dist/api/compiler/locales/fr-FR.js +3 -0
  148. package/dist/api/compiler/locales/it-IT.d.ts +2 -0
  149. package/dist/api/compiler/locales/it-IT.js +3 -0
  150. package/dist/api/compiler/locales/ja-JP.d.ts +2 -0
  151. package/dist/api/compiler/locales/ja-JP.js +3 -0
  152. package/dist/api/compiler/locales/ko-KR.d.ts +2 -0
  153. package/dist/api/compiler/locales/ko-KR.js +3 -0
  154. package/dist/api/compiler/locales/pl-PL.d.ts +2 -0
  155. package/dist/api/compiler/locales/pl-PL.js +3 -0
  156. package/dist/api/compiler/locales/pt-BR.d.ts +2 -0
  157. package/dist/api/compiler/locales/pt-BR.js +3 -0
  158. package/dist/api/compiler/locales/ru-RU.d.ts +2 -0
  159. package/dist/api/compiler/locales/ru-RU.js +3 -0
  160. package/dist/api/compiler/locales/tr-TR.d.ts +2 -0
  161. package/dist/api/compiler/locales/tr-TR.js +3 -0
  162. package/dist/api/compiler/locales/zh-CN.d.ts +2 -0
  163. package/dist/api/compiler/locales/zh-CN.js +3 -0
  164. package/dist/api/compiler/locales/zh-TW.d.ts +2 -0
  165. package/dist/api/compiler/locales/zh-TW.js +3 -0
  166. package/dist/api/compiler/module-resolution-types.d.ts +83 -0
  167. package/dist/api/compiler/module-resolution-types.js +176 -0
  168. package/dist/api/compiler/module-resolution.d.ts +71 -0
  169. package/dist/api/compiler/module-resolution.js +1598 -0
  170. package/dist/api/compiler/module-specifiers.d.ts +64 -0
  171. package/dist/api/compiler/module-specifiers.js +1101 -0
  172. package/dist/api/compiler/name-resolver.d.ts +43 -0
  173. package/dist/api/compiler/name-resolver.js +509 -0
  174. package/dist/api/compiler/node-builder-names.d.ts +32 -0
  175. package/dist/api/compiler/node-builder-names.js +854 -0
  176. package/dist/api/compiler/node-builder-pseudo.d.ts +36 -0
  177. package/dist/api/compiler/node-builder-pseudo.js +745 -0
  178. package/dist/api/compiler/node-builder-reuse.d.ts +4 -0
  179. package/dist/api/compiler/node-builder-reuse.js +647 -0
  180. package/dist/api/compiler/node-builder.d.ts +270 -0
  181. package/dist/api/compiler/node-builder.js +2645 -0
  182. package/dist/api/compiler/option-declarations.d.ts +90 -0
  183. package/dist/api/compiler/option-declarations.js +1460 -0
  184. package/dist/api/compiler/options.d.ts +289 -0
  185. package/dist/api/compiler/options.js +1197 -0
  186. package/dist/api/compiler/output-paths.d.ts +42 -0
  187. package/dist/api/compiler/output-paths.js +195 -0
  188. package/dist/api/compiler/package-json.d.ts +175 -0
  189. package/dist/api/compiler/package-json.js +1015 -0
  190. package/dist/api/compiler/parallel-parse.d.ts +221 -0
  191. package/dist/api/compiler/parallel-parse.js +541 -0
  192. package/dist/api/compiler/parser.d.ts +604 -0
  193. package/dist/api/compiler/parser.js +6426 -0
  194. package/dist/api/compiler/path.d.ts +91 -0
  195. package/dist/api/compiler/path.js +705 -0
  196. package/dist/api/compiler/printer/async-helpers.d.ts +22 -0
  197. package/dist/api/compiler/printer/async-helpers.js +91 -0
  198. package/dist/api/compiler/printer/auto-generate.d.ts +13 -0
  199. package/dist/api/compiler/printer/auto-generate.js +20 -0
  200. package/dist/api/compiler/printer/decorator-helpers.d.ts +24 -0
  201. package/dist/api/compiler/printer/decorator-helpers.js +118 -0
  202. package/dist/api/compiler/printer/emit-context.d.ts +157 -0
  203. package/dist/api/compiler/printer/emit-context.js +582 -0
  204. package/dist/api/compiler/printer/emit-flags.d.ts +60 -0
  205. package/dist/api/compiler/printer/emit-flags.js +2 -0
  206. package/dist/api/compiler/printer/factory-base.d.ts +171 -0
  207. package/dist/api/compiler/printer/factory-base.js +1505 -0
  208. package/dist/api/compiler/printer/factory.d.ts +147 -0
  209. package/dist/api/compiler/printer/factory.js +542 -0
  210. package/dist/api/compiler/printer/helpers.d.ts +27 -0
  211. package/dist/api/compiler/printer/helpers.js +164 -0
  212. package/dist/api/compiler/printer/name-generator.d.ts +41 -0
  213. package/dist/api/compiler/printer/name-generator.js +283 -0
  214. package/dist/api/compiler/printer/printer.d.ts +411 -0
  215. package/dist/api/compiler/printer/printer.js +4517 -0
  216. package/dist/api/compiler/printer/text-writer.d.ts +46 -0
  217. package/dist/api/compiler/printer/text-writer.js +172 -0
  218. package/dist/api/compiler/printer/utilities.d.ts +82 -0
  219. package/dist/api/compiler/printer/utilities.js +817 -0
  220. package/dist/api/compiler/program-checker.d.ts +156 -0
  221. package/dist/api/compiler/program-checker.js +529 -0
  222. package/dist/api/compiler/program-utilities.d.ts +52 -0
  223. package/dist/api/compiler/program-utilities.js +365 -0
  224. package/dist/api/compiler/program.d.ts +180 -0
  225. package/dist/api/compiler/program.js +1019 -0
  226. package/dist/api/compiler/pseudo-bigint.d.ts +5 -0
  227. package/dist/api/compiler/pseudo-bigint.js +61 -0
  228. package/dist/api/compiler/regexp-checker.d.ts +38 -0
  229. package/dist/api/compiler/regexp-checker.js +942 -0
  230. package/dist/api/compiler/relations.d.ts +263 -0
  231. package/dist/api/compiler/relations.js +4002 -0
  232. package/dist/api/compiler/reparser.d.ts +48 -0
  233. package/dist/api/compiler/reparser.js +1323 -0
  234. package/dist/api/compiler/scanner.d.ts +256 -0
  235. package/dist/api/compiler/scanner.js +2853 -0
  236. package/dist/api/compiler/side-state.d.ts +16 -0
  237. package/dist/api/compiler/side-state.js +89 -0
  238. package/dist/api/compiler/sourcemap.d.ts +55 -0
  239. package/dist/api/compiler/sourcemap.js +340 -0
  240. package/dist/api/compiler/spelling.d.ts +14 -0
  241. package/dist/api/compiler/spelling.js +128 -0
  242. package/dist/api/compiler/symbol-accessibility.d.ts +57 -0
  243. package/dist/api/compiler/symbol-accessibility.js +991 -0
  244. package/dist/api/compiler/symbol.d.ts +282 -0
  245. package/dist/api/compiler/symbol.js +339 -0
  246. package/dist/api/compiler/symlinks.d.ts +32 -0
  247. package/dist/api/compiler/symlinks.js +114 -0
  248. package/dist/api/compiler/syntax-kind.d.ts +389 -0
  249. package/dist/api/compiler/syntax-kind.js +2 -0
  250. package/dist/api/compiler/timeline.d.ts +9 -0
  251. package/dist/api/compiler/timeline.js +54 -0
  252. package/dist/api/compiler/transformers/alias-references.d.ts +39 -0
  253. package/dist/api/compiler/transformers/alias-references.js +677 -0
  254. package/dist/api/compiler/transformers/async-utilities.d.ts +51 -0
  255. package/dist/api/compiler/transformers/async-utilities.js +260 -0
  256. package/dist/api/compiler/transformers/async.d.ts +53 -0
  257. package/dist/api/compiler/transformers/async.js +645 -0
  258. package/dist/api/compiler/transformers/class-fields.d.ts +206 -0
  259. package/dist/api/compiler/transformers/class-fields.js +2418 -0
  260. package/dist/api/compiler/transformers/class-utilities.d.ts +46 -0
  261. package/dist/api/compiler/transformers/class-utilities.js +261 -0
  262. package/dist/api/compiler/transformers/commonjs-module.d.ts +103 -0
  263. package/dist/api/compiler/transformers/commonjs-module.js +1180 -0
  264. package/dist/api/compiler/transformers/const-enum-inliner.d.ts +11 -0
  265. package/dist/api/compiler/transformers/const-enum-inliner.js +36 -0
  266. package/dist/api/compiler/transformers/declarations-diagnostics.d.ts +52 -0
  267. package/dist/api/compiler/transformers/declarations-diagnostics.js +539 -0
  268. package/dist/api/compiler/transformers/declarations-pseudo.d.ts +160 -0
  269. package/dist/api/compiler/transformers/declarations-pseudo.js +799 -0
  270. package/dist/api/compiler/transformers/declarations-resolver.d.ts +152 -0
  271. package/dist/api/compiler/transformers/declarations-resolver.js +35 -0
  272. package/dist/api/compiler/transformers/declarations-syntactic.d.ts +119 -0
  273. package/dist/api/compiler/transformers/declarations-syntactic.js +1582 -0
  274. package/dist/api/compiler/transformers/declarations-tracker.d.ts +46 -0
  275. package/dist/api/compiler/transformers/declarations-tracker.js +198 -0
  276. package/dist/api/compiler/transformers/declarations.d.ts +175 -0
  277. package/dist/api/compiler/transformers/declarations.js +2381 -0
  278. package/dist/api/compiler/transformers/decorator-metadata.d.ts +54 -0
  279. package/dist/api/compiler/transformers/decorator-metadata.js +554 -0
  280. package/dist/api/compiler/transformers/decorator-utilities.d.ts +38 -0
  281. package/dist/api/compiler/transformers/decorator-utilities.js +238 -0
  282. package/dist/api/compiler/transformers/destructuring.d.ts +25 -0
  283. package/dist/api/compiler/transformers/destructuring.js +626 -0
  284. package/dist/api/compiler/transformers/downlevel.d.ts +6 -0
  285. package/dist/api/compiler/transformers/downlevel.js +45 -0
  286. package/dist/api/compiler/transformers/emit-resolver.d.ts +61 -0
  287. package/dist/api/compiler/transformers/emit-resolver.js +197 -0
  288. package/dist/api/compiler/transformers/es-decorators.d.ts +118 -0
  289. package/dist/api/compiler/transformers/es-decorators.js +1901 -0
  290. package/dist/api/compiler/transformers/exponentiation.d.ts +11 -0
  291. package/dist/api/compiler/transformers/exponentiation.js +76 -0
  292. package/dist/api/compiler/transformers/external-module-info.d.ts +35 -0
  293. package/dist/api/compiler/transformers/external-module-info.js +351 -0
  294. package/dist/api/compiler/transformers/for-await.d.ts +43 -0
  295. package/dist/api/compiler/transformers/for-await.js +469 -0
  296. package/dist/api/compiler/transformers/import-elision.d.ts +16 -0
  297. package/dist/api/compiler/transformers/import-elision.js +124 -0
  298. package/dist/api/compiler/transformers/jsx-entities.d.ts +1 -0
  299. package/dist/api/compiler/transformers/jsx-entities.js +256 -0
  300. package/dist/api/compiler/transformers/jsx.d.ts +71 -0
  301. package/dist/api/compiler/transformers/jsx.js +700 -0
  302. package/dist/api/compiler/transformers/legacy-decorators.d.ts +56 -0
  303. package/dist/api/compiler/transformers/legacy-decorators.js +564 -0
  304. package/dist/api/compiler/transformers/logical-assignment.d.ts +14 -0
  305. package/dist/api/compiler/transformers/logical-assignment.js +62 -0
  306. package/dist/api/compiler/transformers/module-utilities.d.ts +9 -0
  307. package/dist/api/compiler/transformers/module-utilities.js +36 -0
  308. package/dist/api/compiler/transformers/module.d.ts +49 -0
  309. package/dist/api/compiler/transformers/module.js +296 -0
  310. package/dist/api/compiler/transformers/named-evaluation.d.ts +26 -0
  311. package/dist/api/compiler/transformers/named-evaluation.js +266 -0
  312. package/dist/api/compiler/transformers/nullish-coalescing.d.ts +9 -0
  313. package/dist/api/compiler/transformers/nullish-coalescing.js +26 -0
  314. package/dist/api/compiler/transformers/object-rest-spread.d.ts +34 -0
  315. package/dist/api/compiler/transformers/object-rest-spread.js +411 -0
  316. package/dist/api/compiler/transformers/optional-catch.d.ts +9 -0
  317. package/dist/api/compiler/transformers/optional-catch.js +20 -0
  318. package/dist/api/compiler/transformers/optional-chain.d.ts +14 -0
  319. package/dist/api/compiler/transformers/optional-chain.js +188 -0
  320. package/dist/api/compiler/transformers/reference-resolver.d.ts +129 -0
  321. package/dist/api/compiler/transformers/reference-resolver.js +1157 -0
  322. package/dist/api/compiler/transformers/runtime-syntax.d.ts +71 -0
  323. package/dist/api/compiler/transformers/runtime-syntax.js +753 -0
  324. package/dist/api/compiler/transformers/subtree-facts.d.ts +10 -0
  325. package/dist/api/compiler/transformers/subtree-facts.js +205 -0
  326. package/dist/api/compiler/transformers/syntax-facts.d.ts +52 -0
  327. package/dist/api/compiler/transformers/syntax-facts.js +258 -0
  328. package/dist/api/compiler/transformers/tagged-template.d.ts +17 -0
  329. package/dist/api/compiler/transformers/tagged-template.js +148 -0
  330. package/dist/api/compiler/transformers/transformer.d.ts +17 -0
  331. package/dist/api/compiler/transformers/transformer.js +54 -0
  332. package/dist/api/compiler/transformers/type-eraser.d.ts +21 -0
  333. package/dist/api/compiler/transformers/type-eraser.js +346 -0
  334. package/dist/api/compiler/transformers/type-serialization.d.ts +20 -0
  335. package/dist/api/compiler/transformers/type-serialization.js +347 -0
  336. package/dist/api/compiler/transformers/using.d.ts +56 -0
  337. package/dist/api/compiler/transformers/using.js +453 -0
  338. package/dist/api/compiler/transformers/utilities.d.ts +50 -0
  339. package/dist/api/compiler/transformers/utilities.js +347 -0
  340. package/dist/api/compiler/transformers/visitor-base.d.ts +6 -0
  341. package/dist/api/compiler/transformers/visitor-base.js +817 -0
  342. package/dist/api/compiler/transformers/visitor-hooks.d.ts +29 -0
  343. package/dist/api/compiler/transformers/visitor-hooks.js +189 -0
  344. package/dist/api/compiler/tsconfig.d.ts +177 -0
  345. package/dist/api/compiler/tsconfig.js +1311 -0
  346. package/dist/api/compiler/type-printer.d.ts +15 -0
  347. package/dist/api/compiler/type-printer.js +74 -0
  348. package/dist/api/compiler/types.d.ts +87 -0
  349. package/dist/api/compiler/types.js +23 -0
  350. package/dist/api/compiler/unicode-identifiers.d.ts +2 -0
  351. package/dist/api/compiler/unicode-identifiers.js +209 -0
  352. package/dist/api/compiler/unicode-properties.d.ts +8 -0
  353. package/dist/api/compiler/unicode-properties.js +531 -0
  354. package/dist/api/compiler/vfs-match.d.ts +24 -0
  355. package/dist/api/compiler/vfs-match.js +587 -0
  356. package/dist/api/library/ast.d.ts +3 -2
  357. package/dist/api/library/ast.generated.d.ts +127 -139
  358. package/dist/api/library/checker.d.ts +51 -0
  359. package/dist/api/library/checker.js +318 -0
  360. package/dist/api/library/diagnostics.d.ts +13 -0
  361. package/dist/api/library/diagnostics.js +50 -0
  362. package/dist/api/library/disk.d.ts +13 -0
  363. package/dist/api/library/disk.js +66 -0
  364. package/dist/api/library/errors.d.ts +13 -0
  365. package/dist/api/library/errors.js +24 -0
  366. package/dist/api/library/host.d.ts +24 -0
  367. package/dist/api/library/host.js +52 -0
  368. package/dist/api/library/index.d.ts +5 -1
  369. package/dist/api/library/index.js +4 -0
  370. package/dist/api/library/nodes.d.ts +51 -0
  371. package/dist/api/library/nodes.js +196 -0
  372. package/dist/api/library/options.d.ts +144 -0
  373. package/dist/api/library/options.js +308 -0
  374. package/dist/api/library/parse.d.ts +19 -0
  375. package/dist/api/library/parse.js +41 -0
  376. package/dist/api/library/program.d.ts +21 -0
  377. package/dist/api/library/program.js +234 -0
  378. package/dist/api/library/types.d.ts +14 -1
  379. package/package.json +12 -8
  380. package/src/compiler/ast-utilities.ts +548 -0
  381. package/src/compiler/ast.ts +12870 -0
  382. package/src/compiler/astnav.ts +799 -0
  383. package/src/compiler/binder-utilities.ts +1392 -0
  384. package/src/compiler/binder.ts +2707 -0
  385. package/src/compiler/build-info.ts +1197 -0
  386. package/src/compiler/character-codes.ts +323 -0
  387. package/src/compiler/checker-calls.ts +2155 -0
  388. package/src/compiler/checker-classes.ts +706 -0
  389. package/src/compiler/checker-contextual.ts +1457 -0
  390. package/src/compiler/checker-declaration-order.ts +438 -0
  391. package/src/compiler/checker-declarations.ts +1201 -0
  392. package/src/compiler/checker-declared-types.ts +919 -0
  393. package/src/compiler/checker-decorators.ts +694 -0
  394. package/src/compiler/checker-deprecation.ts +355 -0
  395. package/src/compiler/checker-destructuring.ts +805 -0
  396. package/src/compiler/checker-elaboration.ts +477 -0
  397. package/src/compiler/checker-emit-helpers.ts +224 -0
  398. package/src/compiler/checker-emit-resolver.ts +769 -0
  399. package/src/compiler/checker-evaluator.ts +243 -0
  400. package/src/compiler/checker-expressions.ts +1831 -0
  401. package/src/compiler/checker-features.ts +361 -0
  402. package/src/compiler/checker-flow.ts +394 -0
  403. package/src/compiler/checker-functions.ts +1296 -0
  404. package/src/compiler/checker-generated-code.ts +227 -0
  405. package/src/compiler/checker-globals.ts +52 -0
  406. package/src/compiler/checker-grammar.ts +3596 -0
  407. package/src/compiler/checker-heritage.ts +1240 -0
  408. package/src/compiler/checker-inference.ts +2584 -0
  409. package/src/compiler/checker-iteration.ts +1206 -0
  410. package/src/compiler/checker-javascript.ts +502 -0
  411. package/src/compiler/checker-jsdoc.ts +360 -0
  412. package/src/compiler/checker-jsx.ts +1928 -0
  413. package/src/compiler/checker-literals.ts +61 -0
  414. package/src/compiler/checker-members.ts +2480 -0
  415. package/src/compiler/checker-modules.ts +2896 -0
  416. package/src/compiler/checker-narrowing.ts +3230 -0
  417. package/src/compiler/checker-object-literals.ts +591 -0
  418. package/src/compiler/checker-operators.ts +1422 -0
  419. package/src/compiler/checker-overloads.ts +328 -0
  420. package/src/compiler/checker-property-access.ts +906 -0
  421. package/src/compiler/checker-services.ts +1149 -0
  422. package/src/compiler/checker-signatures.ts +1032 -0
  423. package/src/compiler/checker-source-file.ts +732 -0
  424. package/src/compiler/checker-statements.ts +292 -0
  425. package/src/compiler/checker-super.ts +261 -0
  426. package/src/compiler/checker-symbol-types.ts +1187 -0
  427. package/src/compiler/checker-symbols.ts +2157 -0
  428. package/src/compiler/checker-type-factory.ts +2616 -0
  429. package/src/compiler/checker-type-nodes.ts +1033 -0
  430. package/src/compiler/checker-type-operators.ts +2510 -0
  431. package/src/compiler/checker-types.ts +2520 -0
  432. package/src/compiler/checker-unused.ts +642 -0
  433. package/src/compiler/checker-utilities.ts +161 -0
  434. package/src/compiler/checker.ts +1138 -0
  435. package/src/compiler/command-line.ts +436 -0
  436. package/src/compiler/compile-program.ts +439 -0
  437. package/src/compiler/decoder.ts +1209 -0
  438. package/src/compiler/diagnostic-locales.ts +86 -0
  439. package/src/compiler/diagnostic-messages.ts +2349 -0
  440. package/src/compiler/diagnostics.ts +858 -0
  441. package/src/compiler/emitter.ts +434 -0
  442. package/src/compiler/encoder.ts +1945 -0
  443. package/src/compiler/file-include.ts +741 -0
  444. package/src/compiler/file-loader.ts +1597 -0
  445. package/src/compiler/file-system.ts +143 -0
  446. package/src/compiler/flow.ts +89 -0
  447. package/src/compiler/help.ts +473 -0
  448. package/src/compiler/incremental.ts +2818 -0
  449. package/src/compiler/init.ts +141 -0
  450. package/src/compiler/instantiation.ts +938 -0
  451. package/src/compiler/jsdoc.ts +1386 -0
  452. package/src/compiler/link-tables.ts +343 -0
  453. package/src/compiler/locale-data.ts +203 -0
  454. package/src/compiler/locale.ts +307 -0
  455. package/src/compiler/locales/cs-CZ.ts +5 -0
  456. package/src/compiler/locales/de-DE.ts +5 -0
  457. package/src/compiler/locales/es-ES.ts +5 -0
  458. package/src/compiler/locales/fr-FR.ts +5 -0
  459. package/src/compiler/locales/it-IT.ts +5 -0
  460. package/src/compiler/locales/ja-JP.ts +5 -0
  461. package/src/compiler/locales/ko-KR.ts +5 -0
  462. package/src/compiler/locales/pl-PL.ts +5 -0
  463. package/src/compiler/locales/pt-BR.ts +5 -0
  464. package/src/compiler/locales/ru-RU.ts +5 -0
  465. package/src/compiler/locales/tr-TR.ts +5 -0
  466. package/src/compiler/locales/zh-CN.ts +5 -0
  467. package/src/compiler/locales/zh-TW.ts +5 -0
  468. package/src/compiler/module-resolution-types.ts +243 -0
  469. package/src/compiler/module-resolution.ts +2072 -0
  470. package/src/compiler/module-specifiers.ts +1491 -0
  471. package/src/compiler/name-resolver.ts +646 -0
  472. package/src/compiler/node-builder-names.ts +1071 -0
  473. package/src/compiler/node-builder-pseudo.ts +892 -0
  474. package/src/compiler/node-builder-reuse.ts +764 -0
  475. package/src/compiler/node-builder.ts +3433 -0
  476. package/src/compiler/option-declarations.ts +1560 -0
  477. package/src/compiler/options.ts +1576 -0
  478. package/src/compiler/output-paths.ts +334 -0
  479. package/src/compiler/package-json.ts +1083 -0
  480. package/src/compiler/parallel-check.ts +1954 -0
  481. package/src/compiler/parallel-parse.ts +595 -0
  482. package/src/compiler/parse-thread.ts +136 -0
  483. package/src/compiler/parser.ts +7766 -0
  484. package/src/compiler/path.ts +717 -0
  485. package/src/compiler/printer/async-helpers.ts +183 -0
  486. package/src/compiler/printer/auto-generate.ts +27 -0
  487. package/src/compiler/printer/decorator-helpers.ts +218 -0
  488. package/src/compiler/printer/emit-context.ts +684 -0
  489. package/src/compiler/printer/emit-flags.ts +64 -0
  490. package/src/compiler/printer/factory-base.ts +2577 -0
  491. package/src/compiler/printer/factory.ts +764 -0
  492. package/src/compiler/printer/helpers.ts +291 -0
  493. package/src/compiler/printer/name-generator.ts +372 -0
  494. package/src/compiler/printer/printer.ts +5072 -0
  495. package/src/compiler/printer/text-writer.ts +183 -0
  496. package/src/compiler/printer/utilities.ts +884 -0
  497. package/src/compiler/program-checker.ts +594 -0
  498. package/src/compiler/program-utilities.ts +435 -0
  499. package/src/compiler/program.ts +1426 -0
  500. package/src/compiler/pseudo-bigint.ts +62 -0
  501. package/src/compiler/regexp-checker.ts +1142 -0
  502. package/src/compiler/relations.ts +5149 -0
  503. package/src/compiler/reparser.ts +1566 -0
  504. package/src/compiler/scanner.ts +2951 -0
  505. package/src/compiler/show-config.ts +239 -0
  506. package/src/compiler/side-state.ts +125 -0
  507. package/src/compiler/sourcemap.ts +366 -0
  508. package/src/compiler/spelling.ts +122 -0
  509. package/src/compiler/symbol-accessibility.ts +1166 -0
  510. package/src/compiler/symbol.ts +557 -0
  511. package/src/compiler/symlinks.ts +137 -0
  512. package/src/compiler/syntax-kind.ts +391 -0
  513. package/src/compiler/thread-entry.ts +191 -0
  514. package/src/compiler/timeline.ts +53 -0
  515. package/src/compiler/transformers/alias-references.ts +757 -0
  516. package/src/compiler/transformers/async-utilities.ts +335 -0
  517. package/src/compiler/transformers/async.ts +838 -0
  518. package/src/compiler/transformers/class-fields.ts +2967 -0
  519. package/src/compiler/transformers/class-utilities.ts +324 -0
  520. package/src/compiler/transformers/commonjs-module.ts +1621 -0
  521. package/src/compiler/transformers/const-enum-inliner.ts +50 -0
  522. package/src/compiler/transformers/declarations-diagnostics.ts +833 -0
  523. package/src/compiler/transformers/declarations-pseudo.ts +969 -0
  524. package/src/compiler/transformers/declarations-resolver.ts +249 -0
  525. package/src/compiler/transformers/declarations-syntactic.ts +1867 -0
  526. package/src/compiler/transformers/declarations-tracker.ts +269 -0
  527. package/src/compiler/transformers/declarations.ts +3120 -0
  528. package/src/compiler/transformers/decorator-metadata.ts +697 -0
  529. package/src/compiler/transformers/decorator-utilities.ts +283 -0
  530. package/src/compiler/transformers/destructuring.ts +708 -0
  531. package/src/compiler/transformers/downlevel.ts +50 -0
  532. package/src/compiler/transformers/emit-resolver.ts +258 -0
  533. package/src/compiler/transformers/es-decorators.ts +2682 -0
  534. package/src/compiler/transformers/exponentiation.ts +80 -0
  535. package/src/compiler/transformers/external-module-info.ts +412 -0
  536. package/src/compiler/transformers/for-await.ts +687 -0
  537. package/src/compiler/transformers/import-elision.ts +152 -0
  538. package/src/compiler/transformers/jsx-entities.ts +256 -0
  539. package/src/compiler/transformers/jsx.ts +824 -0
  540. package/src/compiler/transformers/legacy-decorators.ts +726 -0
  541. package/src/compiler/transformers/logical-assignment.ts +75 -0
  542. package/src/compiler/transformers/module-utilities.ts +42 -0
  543. package/src/compiler/transformers/module.ts +474 -0
  544. package/src/compiler/transformers/named-evaluation.ts +389 -0
  545. package/src/compiler/transformers/nullish-coalescing.ts +35 -0
  546. package/src/compiler/transformers/object-rest-spread.ts +577 -0
  547. package/src/compiler/transformers/optional-catch.ts +29 -0
  548. package/src/compiler/transformers/optional-chain.ts +246 -0
  549. package/src/compiler/transformers/reference-resolver.ts +1213 -0
  550. package/src/compiler/transformers/runtime-syntax.ts +942 -0
  551. package/src/compiler/transformers/subtree-facts.ts +253 -0
  552. package/src/compiler/transformers/syntax-facts.ts +358 -0
  553. package/src/compiler/transformers/tagged-template.ts +167 -0
  554. package/src/compiler/transformers/transformer.ts +56 -0
  555. package/src/compiler/transformers/type-eraser.ts +520 -0
  556. package/src/compiler/transformers/type-serialization.ts +374 -0
  557. package/src/compiler/transformers/using.ts +613 -0
  558. package/src/compiler/transformers/utilities.ts +419 -0
  559. package/src/compiler/transformers/visitor-base.ts +1601 -0
  560. package/src/compiler/transformers/visitor-hooks.ts +252 -0
  561. package/src/compiler/tsc-build.ts +1422 -0
  562. package/src/compiler/tsc-cli.ts +669 -0
  563. package/src/compiler/tsc-compile.ts +446 -0
  564. package/src/compiler/tsc-watch.ts +922 -0
  565. package/src/compiler/tsconfig.ts +1574 -0
  566. package/src/compiler/type-printer.ts +110 -0
  567. package/src/compiler/types.ts +115 -0
  568. package/src/compiler/unicode-identifiers.ts +212 -0
  569. package/src/compiler/unicode-properties.ts +537 -0
  570. package/src/compiler/vfs-match.ts +597 -0
  571. package/src/compiler/xxh3.ts +650 -0
  572. package/src/library/ast.generated.ts +141 -167
  573. package/src/library/ast.ts +4 -1
  574. package/src/library/checker.ts +384 -0
  575. package/src/library/diagnostics.ts +72 -0
  576. package/src/library/disk.ts +73 -0
  577. package/src/library/errors.ts +26 -0
  578. package/src/library/host.ts +63 -0
  579. package/src/library/index.ts +21 -0
  580. package/src/library/nodes.ts +232 -0
  581. package/src/library/options.ts +449 -0
  582. package/src/library/parse.ts +63 -0
  583. package/src/library/program.ts +293 -0
  584. package/src/library/types.ts +14 -1
@@ -0,0 +1,1945 @@
1
+ // Encodes a source file in TypeScript 7's binary AST format (protocol version 5), the
2
+ // `getSourceFile` payload of the API.
3
+ //
4
+ // Layout: a 44-byte header, string offsets (UTF-8 start/end pairs), string data (the
5
+ // UTF-8 file text, then strings that aren't slices of it), extended node data,
6
+ // msgpack structured data, and 28-byte node records in visit order. Node positions are
7
+ // UTF-16 offsets.
8
+ import {
9
+ ArrayLiteralExpression,
10
+ ArrayTypeNode,
11
+ ArrowFunction,
12
+ AsExpression,
13
+ AwaitExpression,
14
+ BinaryExpression,
15
+ BindingElement,
16
+ BindingPattern,
17
+ Block,
18
+ BreakStatement,
19
+ CallExpression,
20
+ CallSignatureDeclaration,
21
+ CaseBlock,
22
+ CaseOrDefaultClause,
23
+ CatchClause,
24
+ ClassDeclaration,
25
+ ClassExpression,
26
+ ClassStaticBlockDeclaration,
27
+ ComputedPropertyName,
28
+ ConditionalExpression,
29
+ ConditionalTypeNode,
30
+ ConstructSignatureDeclaration,
31
+ ConstructorDeclaration,
32
+ ConstructorTypeNode,
33
+ ContinueStatement,
34
+ Decorator,
35
+ DeleteExpression,
36
+ DoStatement,
37
+ ElementAccessExpression,
38
+ EnumDeclaration,
39
+ EnumMember,
40
+ ExportAssignment,
41
+ ExportDeclaration,
42
+ ExportSpecifier,
43
+ ExpressionStatement,
44
+ ExpressionWithTypeArguments,
45
+ ExternalModuleReference,
46
+ type FileReference,
47
+ ForInOrOfStatement,
48
+ ForStatement,
49
+ FunctionDeclaration,
50
+ FunctionExpression,
51
+ FunctionTypeNode,
52
+ GetAccessorDeclaration,
53
+ HeritageClause,
54
+ IfStatement,
55
+ ImportAttribute,
56
+ ImportAttributes,
57
+ ImportClause,
58
+ ImportDeclaration,
59
+ ImportEqualsDeclaration,
60
+ ImportSpecifier,
61
+ ImportTypeNode,
62
+ IndexSignatureDeclaration,
63
+ IndexedAccessTypeNode,
64
+ InferTypeNode,
65
+ InterfaceDeclaration,
66
+ IntersectionTypeNode,
67
+ JSDoc,
68
+ JSDocAugmentsTag,
69
+ JSDocCallbackTag,
70
+ JSDocDeprecatedTag,
71
+ JSDocImplementsTag,
72
+ JSDocImportTag,
73
+ JSDocLink,
74
+ JSDocLinkCode,
75
+ JSDocLinkPlain,
76
+ JSDocNameReference,
77
+ JSDocNonNullableType,
78
+ JSDocNullableType,
79
+ JSDocOptionalType,
80
+ JSDocOverloadTag,
81
+ JSDocOverrideTag,
82
+ JSDocParameterOrPropertyTag,
83
+ JSDocPrivateTag,
84
+ JSDocProtectedTag,
85
+ JSDocPublicTag,
86
+ JSDocReadonlyTag,
87
+ JSDocReturnTag,
88
+ JSDocSatisfiesTag,
89
+ JSDocSeeTag,
90
+ JSDocSignature,
91
+ JSDocTemplateTag,
92
+ JSDocText,
93
+ JSDocThisTag,
94
+ JSDocThrowsTag,
95
+ JSDocTypeExpression,
96
+ JSDocTypeLiteral,
97
+ JSDocTypeTag,
98
+ JSDocTypedefTag,
99
+ JSDocUnknownTag,
100
+ JSDocVariadicType,
101
+ JsxAttribute,
102
+ JsxAttributes,
103
+ JsxClosingElement,
104
+ JsxElement,
105
+ JsxExpression,
106
+ JsxFragment,
107
+ JsxNamespacedName,
108
+ JsxOpeningElement,
109
+ JsxSelfClosingElement,
110
+ JsxSpreadAttribute,
111
+ JsxText,
112
+ LabeledStatement,
113
+ LiteralTypeNode,
114
+ MappedTypeNode,
115
+ MetaProperty,
116
+ MethodDeclaration,
117
+ MethodSignatureDeclaration,
118
+ MissingDeclaration,
119
+ type ModifierList,
120
+ ModuleBlock,
121
+ ModuleDeclaration,
122
+ NamedExports,
123
+ NamedImports,
124
+ NamedTupleMember,
125
+ NamespaceExport,
126
+ NamespaceExportDeclaration,
127
+ NamespaceImport,
128
+ NewExpression,
129
+ type Node,
130
+ type NodeList,
131
+ NodeVisitor,
132
+ NoSubstitutionTemplateLiteral,
133
+ NonNullExpression,
134
+ NumericLiteral,
135
+ ObjectLiteralExpression,
136
+ OptionalTypeNode,
137
+ ParameterDeclaration,
138
+ ParenthesizedExpression,
139
+ ParenthesizedTypeNode,
140
+ PostfixUnaryExpression,
141
+ PrefixUnaryExpression,
142
+ PrivateIdentifier,
143
+ PropertyAccessExpression,
144
+ PropertyAssignment,
145
+ PropertyDeclaration,
146
+ PropertySignatureDeclaration,
147
+ QualifiedName,
148
+ RegularExpressionLiteral,
149
+ RestTypeNode,
150
+ ReturnStatement,
151
+ SatisfiesExpression,
152
+ SetAccessorDeclaration,
153
+ ShorthandPropertyAssignment,
154
+ SourceFile,
155
+ SpreadAssignment,
156
+ SpreadElement,
157
+ StringLiteral,
158
+ SwitchStatement,
159
+ TaggedTemplateExpression,
160
+ TemplateExpression,
161
+ TemplateHead,
162
+ TemplateLiteralTypeNode,
163
+ TemplateLiteralTypeSpan,
164
+ TemplateMiddle,
165
+ TemplateSpan,
166
+ TemplateTail,
167
+ ThrowStatement,
168
+ TryStatement,
169
+ TupleTypeNode,
170
+ TypeAliasDeclaration,
171
+ TypeAssertion,
172
+ TypeLiteralNode,
173
+ TypeOfExpression,
174
+ TypeOperatorNode,
175
+ TypeParameterDeclaration,
176
+ TypePredicateNode,
177
+ TypeQueryNode,
178
+ TypeReferenceNode,
179
+ UnionTypeNode,
180
+ VariableDeclaration,
181
+ VariableDeclarationList,
182
+ VariableStatement,
183
+ VoidExpression,
184
+ WhileStatement,
185
+ WithStatement,
186
+ YieldExpression,
187
+ BigIntLiteral,
188
+ Identifier,
189
+ } from './ast.js';
190
+ import { getJSDoc } from './parser.js';
191
+ import { SyntaxKind } from './syntax-kind.js';
192
+ import { hash128 } from './xxh3.js';
193
+ import { utf8Offsets } from './character-codes.js';
194
+
195
+ export const protocolVersion = 5;
196
+
197
+ const nodeSize = 28;
198
+ const headerSize = 44;
199
+ const nodeListKind = 0xffffffff;
200
+ const noStructuredData = 0xffffffff;
201
+
202
+ const dataTypeChildren = 0;
203
+ const dataTypeString = 1 << 30;
204
+ const dataTypeExtended = 2 << 30;
205
+
206
+ const utf8Encoder = new TextEncoder();
207
+
208
+ /** A growable little-endian byte buffer. */
209
+ class ByteWriter {
210
+ bytes: Uint8Array;
211
+ length: number;
212
+
213
+ constructor(capacity: number) {
214
+ this.bytes = new Uint8Array(capacity < 16 ? 16 : capacity);
215
+ this.length = 0;
216
+ }
217
+
218
+ /** Makes room for `count` more bytes and returns the offset to write them at. */
219
+ reserve(count: number): number {
220
+ const at = this.length;
221
+ const needed = at + count;
222
+ if (needed > this.bytes.length) {
223
+ let size = this.bytes.length * 2;
224
+ while (size < needed) size *= 2;
225
+ const grown = new Uint8Array(size);
226
+ grown.set(this.bytes.subarray(0, at));
227
+ this.bytes = grown;
228
+ }
229
+ this.length = needed;
230
+ return at;
231
+ }
232
+
233
+ u8(value: number): void {
234
+ const at = this.reserve(1);
235
+ this.bytes[at] = value & 0xff;
236
+ }
237
+
238
+ u32(value: number): void {
239
+ this.setU32(this.reserve(4), value);
240
+ }
241
+
242
+ setU32(at: number, value: number): void {
243
+ const bytes = this.bytes;
244
+ bytes[at] = value & 0xff;
245
+ bytes[at + 1] = (value >>> 8) & 0xff;
246
+ bytes[at + 2] = (value >>> 16) & 0xff;
247
+ bytes[at + 3] = (value >>> 24) & 0xff;
248
+ }
249
+
250
+ /** Big-endian, for msgpack. */
251
+ be(value: number, size: number): void {
252
+ const at = this.reserve(size);
253
+ for (let i = 0; i < size; i++) this.bytes[at + i] = (value >>> ((size - 1 - i) * 8)) & 0xff;
254
+ }
255
+
256
+ append(data: Uint8Array): void {
257
+ const at = this.reserve(data.length);
258
+ this.bytes.set(data, at);
259
+ }
260
+
261
+ view(): Uint8Array {
262
+ return this.bytes.subarray(0, this.length);
263
+ }
264
+ }
265
+
266
+ /** Whether typed arrays store numbers little-endian, as the encoding does. */
267
+ const littleEndian = new Uint8Array(new Uint32Array([1]).buffer)[0] === 1;
268
+
269
+ /** Node records: seven 32-bit fields each (`nodeSize` bytes), written a field at a time. */
270
+ class NodeRecords {
271
+ private words: Uint32Array;
272
+ count = 0;
273
+
274
+ constructor(capacity: number) {
275
+ this.words = new Uint32Array((capacity < 2 ? 2 : capacity) * 7);
276
+ }
277
+
278
+ /** The records' size in bytes. */
279
+ get length(): number {
280
+ return this.count * nodeSize;
281
+ }
282
+
283
+ push(kind: number, pos: number, end: number, parent: number, data: number, flags: number): void {
284
+ const at = this.count * 7;
285
+ if (at + 7 > this.words.length) {
286
+ const grown = new Uint32Array(this.words.length * 2);
287
+ grown.set(this.words);
288
+ this.words = grown;
289
+ }
290
+ const words = this.words;
291
+ words[at] = kind;
292
+ words[at + 1] = pos;
293
+ words[at + 2] = end;
294
+ words[at + 3] = 0;
295
+ words[at + 4] = parent;
296
+ words[at + 5] = data;
297
+ words[at + 6] = flags;
298
+ this.count++;
299
+ }
300
+
301
+ /** Sets the `next` field of record `index`. */
302
+ setNext(index: number, next: number): void {
303
+ this.words[index * 7 + 3] = next;
304
+ }
305
+
306
+ /** The records as little-endian bytes. */
307
+ view(): Uint8Array {
308
+ if (littleEndian) return new Uint8Array(this.words.buffer, 0, this.length);
309
+ const bytes = new Uint8Array(this.length);
310
+ for (let i = 0; i < this.count * 7; i++) {
311
+ const value = this.words[i];
312
+ bytes[i * 4] = value & 0xff;
313
+ bytes[i * 4 + 1] = (value >>> 8) & 0xff;
314
+ bytes[i * 4 + 2] = (value >>> 16) & 0xff;
315
+ bytes[i * 4 + 3] = (value >>> 24) & 0xff;
316
+ }
317
+ return bytes;
318
+ }
319
+ }
320
+
321
+ function utf8Length(text: string): number {
322
+ let length = 0;
323
+ for (let i = 0; i < text.length; i++) {
324
+ const ch = text.charCodeAt(i);
325
+ if (ch < 0x80) length += 1;
326
+ else if (ch < 0x800) length += 2;
327
+ else if (ch >= 0xd800 && ch <= 0xdbff && i + 1 < text.length) {
328
+ const low = text.charCodeAt(i + 1);
329
+ if (low >= 0xdc00 && low <= 0xdfff) {
330
+ length += 4;
331
+ i++;
332
+ } else length += 3;
333
+ } else length += 3;
334
+ }
335
+ return length;
336
+ }
337
+
338
+ /** UTF-8 bytes of `text`, with lone surrogates as WTF-8 like tsgo's strings. */
339
+ function encodeUTF8(text: string): Uint8Array {
340
+ const bytes = new Uint8Array(utf8Length(text));
341
+ let at = 0;
342
+ for (let i = 0; i < text.length; i++) {
343
+ let ch = text.charCodeAt(i);
344
+ if (ch < 0x80) {
345
+ bytes[at++] = ch;
346
+ continue;
347
+ }
348
+ if (ch < 0x800) {
349
+ bytes[at++] = 0xc0 | (ch >> 6);
350
+ bytes[at++] = 0x80 | (ch & 0x3f);
351
+ continue;
352
+ }
353
+ if (ch >= 0xd800 && ch <= 0xdbff && i + 1 < text.length) {
354
+ const low = text.charCodeAt(i + 1);
355
+ if (low >= 0xdc00 && low <= 0xdfff) {
356
+ ch = (ch - 0xd800) * 0x400 + (low - 0xdc00) + 0x10000;
357
+ i++;
358
+ bytes[at++] = 0xf0 | (ch >> 18);
359
+ bytes[at++] = 0x80 | ((ch >> 12) & 0x3f);
360
+ bytes[at++] = 0x80 | ((ch >> 6) & 0x3f);
361
+ bytes[at++] = 0x80 | (ch & 0x3f);
362
+ continue;
363
+ }
364
+ }
365
+ bytes[at++] = 0xe0 | (ch >> 12);
366
+ bytes[at++] = 0x80 | ((ch >> 6) & 0x3f);
367
+ bytes[at++] = 0x80 | (ch & 0x3f);
368
+ }
369
+ return bytes;
370
+ }
371
+
372
+ function hasLoneSurrogate(text: string): boolean {
373
+ for (let i = 0; i < text.length; i++) {
374
+ const ch = text.charCodeAt(i);
375
+ if (ch < 0xd800 || ch > 0xdfff) continue;
376
+ if (ch <= 0xdbff && i + 1 < text.length) {
377
+ const low = text.charCodeAt(i + 1);
378
+ if (low >= 0xdc00 && low <= 0xdfff) {
379
+ i++;
380
+ continue;
381
+ }
382
+ }
383
+ return true;
384
+ }
385
+ return false;
386
+ }
387
+
388
+ function isASCII(text: string): boolean {
389
+ for (let i = 0; i < text.length; i++) if (text.charCodeAt(i) >= 0x80) return false;
390
+ return true;
391
+ }
392
+
393
+ /**
394
+ * Strings referenced by nodes. A string that equals the file text just before the node's
395
+ * end (less a closing quote) is stored as that slice; others are appended after the text.
396
+ */
397
+ class StringTable {
398
+ readonly fileText: Uint8Array;
399
+ readonly asciiFile: boolean;
400
+ readonly offsets8: Int32Array | undefined;
401
+ readonly offsets: ByteWriter;
402
+ readonly others: ByteWriter;
403
+ count: number;
404
+
405
+ constructor(
406
+ private readonly text: string,
407
+ fileText: Uint8Array,
408
+ ) {
409
+ this.fileText = fileText;
410
+ this.asciiFile = fileText.length === text.length;
411
+ this.offsets8 = this.asciiFile ? undefined : utf8Offsets(text);
412
+ this.offsets = new ByteWriter(1024);
413
+ this.others = new ByteWriter(64);
414
+ this.count = 0;
415
+ }
416
+
417
+ /** The UTF-8 offset of UTF-16 offset `pos`. */
418
+ utf8(pos: number): number {
419
+ const offsets = this.offsets8;
420
+ if (offsets === undefined || pos < 0 || pos >= offsets.length) return pos;
421
+ return offsets[pos];
422
+ }
423
+
424
+ private push(start: number, end: number): number {
425
+ const index = this.count;
426
+ this.offsets.u32(start);
427
+ this.offsets.u32(end);
428
+ this.count += 2;
429
+ return index;
430
+ }
431
+
432
+ /** Records the whole file text. */
433
+ addFileText(pos: number, end: number): number {
434
+ return this.push(this.utf8(pos), this.utf8(end));
435
+ }
436
+
437
+ add(text: string, kind: SyntaxKind, pos: number, end: number): number {
438
+ const fileText = this.fileText;
439
+ const pos8 = this.utf8(pos);
440
+ let end8 = this.utf8(end);
441
+ if (end8 - pos8 > 0 && end8 <= fileText.length) {
442
+ // A closing quote takes one byte and one UTF-16 unit.
443
+ let end16 = end;
444
+ if (
445
+ kind === SyntaxKind.StringLiteral ||
446
+ kind === SyntaxKind.TemplateTail ||
447
+ kind === SyntaxKind.NoSubstitutionTemplateLiteral
448
+ ) {
449
+ end8 -= 1;
450
+ end16 -= 1;
451
+ }
452
+ // Where the text is the file text before `end16`, its UTF-8 bytes are those of that slice, unless it
453
+ // has lone surrogates: `encodeUTF8` writes them as WTF-8, and the file's UTF-8 has none.
454
+ const start16 = end16 - text.length;
455
+ if (
456
+ start16 >= 0 &&
457
+ end16 <= this.text.length &&
458
+ this.text.startsWith(text, start16) &&
459
+ (this.asciiFile || !hasLoneSurrogate(text))
460
+ )
461
+ return this.push(this.utf8(start16), end8);
462
+ }
463
+ const ascii = isASCII(text);
464
+ const length = ascii ? text.length : utf8Length(text);
465
+ if (end8 - pos8 > 0 && end8 <= fileText.length) {
466
+ const start8 = end8 - length;
467
+ if (start8 >= 0 && this.matches(text, ascii, start8, end8)) return this.push(start8, end8);
468
+ }
469
+ const offset = fileText.length + this.others.length;
470
+ if (ascii) {
471
+ const at = this.others.reserve(length);
472
+ const bytes = this.others.bytes;
473
+ for (let i = 0; i < length; i++) bytes[at + i] = text.charCodeAt(i);
474
+ } else this.others.append(encodeUTF8(text));
475
+ return this.push(offset, offset + length);
476
+ }
477
+
478
+ private matches(text: string, ascii: boolean, start8: number, end8: number): boolean {
479
+ const fileText = this.fileText;
480
+ if (ascii) {
481
+ for (let i = 0; i < text.length; i++) if (fileText[start8 + i] !== text.charCodeAt(i)) return false;
482
+ return true;
483
+ }
484
+ const encoded = encodeUTF8(text);
485
+ if (encoded.length !== end8 - start8) return false;
486
+ for (let i = 0; i < encoded.length; i++) if (fileText[start8 + i] !== encoded[i]) return false;
487
+ return true;
488
+ }
489
+ }
490
+
491
+ function hasModifiers(modifiers: ModifierList | undefined): boolean {
492
+ return modifiers !== undefined && modifiers.nodes.length > 0;
493
+ }
494
+
495
+ /** Which of a node's child properties are present, one bit per property in visit order. */
496
+ function hasElements(nodes: readonly Node[] | undefined): boolean {
497
+ return nodes !== undefined && nodes.length > 0;
498
+ }
499
+
500
+ function childrenPropertyMask(node: Node): number {
501
+ switch (node.kind) {
502
+ case SyntaxKind.QualifiedName:
503
+ return node instanceof QualifiedName
504
+ ? ((node as QualifiedName).left !== undefined ? 1 : 0) | ((node as QualifiedName).right !== undefined ? 2 : 0)
505
+ : 0;
506
+ case SyntaxKind.ComputedPropertyName:
507
+ return node instanceof ComputedPropertyName
508
+ ? (node as ComputedPropertyName).expression !== undefined
509
+ ? 1
510
+ : 0
511
+ : 0;
512
+ case SyntaxKind.Decorator:
513
+ return node instanceof Decorator ? ((node as Decorator).expression !== undefined ? 1 : 0) : 0;
514
+ case SyntaxKind.IfStatement:
515
+ return node instanceof IfStatement
516
+ ? ((node as IfStatement).expression !== undefined ? 1 : 0) |
517
+ ((node as IfStatement).thenStatement !== undefined ? 2 : 0) |
518
+ ((node as IfStatement).elseStatement !== undefined ? 4 : 0)
519
+ : 0;
520
+ case SyntaxKind.DoStatement:
521
+ return node instanceof DoStatement
522
+ ? ((node as DoStatement).statement !== undefined ? 1 : 0) |
523
+ ((node as DoStatement).expression !== undefined ? 2 : 0)
524
+ : 0;
525
+ case SyntaxKind.WhileStatement:
526
+ return node instanceof WhileStatement
527
+ ? ((node as WhileStatement).expression !== undefined ? 1 : 0) |
528
+ ((node as WhileStatement).statement !== undefined ? 2 : 0)
529
+ : 0;
530
+ case SyntaxKind.ForStatement:
531
+ return node instanceof ForStatement
532
+ ? ((node as ForStatement).initializer !== undefined ? 1 : 0) |
533
+ ((node as ForStatement).condition !== undefined ? 2 : 0) |
534
+ ((node as ForStatement).incrementor !== undefined ? 4 : 0) |
535
+ ((node as ForStatement).statement !== undefined ? 8 : 0)
536
+ : 0;
537
+ case SyntaxKind.ForInStatement:
538
+ case SyntaxKind.ForOfStatement:
539
+ return node instanceof ForInOrOfStatement
540
+ ? ((node as ForInOrOfStatement).awaitModifier !== undefined ? 1 : 0) |
541
+ ((node as ForInOrOfStatement).initializer !== undefined ? 2 : 0) |
542
+ ((node as ForInOrOfStatement).expression !== undefined ? 4 : 0) |
543
+ ((node as ForInOrOfStatement).statement !== undefined ? 8 : 0)
544
+ : 0;
545
+ case SyntaxKind.BreakStatement:
546
+ return node instanceof BreakStatement ? ((node as BreakStatement).label !== undefined ? 1 : 0) : 0;
547
+ case SyntaxKind.ContinueStatement:
548
+ return node instanceof ContinueStatement ? ((node as ContinueStatement).label !== undefined ? 1 : 0) : 0;
549
+ case SyntaxKind.ReturnStatement:
550
+ return node instanceof ReturnStatement ? ((node as ReturnStatement).expression !== undefined ? 1 : 0) : 0;
551
+ case SyntaxKind.WithStatement:
552
+ return node instanceof WithStatement
553
+ ? ((node as WithStatement).expression !== undefined ? 1 : 0) |
554
+ ((node as WithStatement).statement !== undefined ? 2 : 0)
555
+ : 0;
556
+ case SyntaxKind.SwitchStatement:
557
+ return node instanceof SwitchStatement
558
+ ? ((node as SwitchStatement).expression !== undefined ? 1 : 0) |
559
+ ((node as SwitchStatement).caseBlock !== undefined ? 2 : 0)
560
+ : 0;
561
+ case SyntaxKind.CaseBlock:
562
+ return node instanceof CaseBlock ? ((node as CaseBlock).clauses !== undefined ? 1 : 0) : 0;
563
+ case SyntaxKind.CaseClause:
564
+ case SyntaxKind.DefaultClause:
565
+ return node instanceof CaseOrDefaultClause
566
+ ? ((node as CaseOrDefaultClause).expression !== undefined ? 1 : 0) |
567
+ ((node as CaseOrDefaultClause).statements !== undefined ? 2 : 0)
568
+ : 0;
569
+ case SyntaxKind.ThrowStatement:
570
+ return node instanceof ThrowStatement ? ((node as ThrowStatement).expression !== undefined ? 1 : 0) : 0;
571
+ case SyntaxKind.TryStatement:
572
+ return node instanceof TryStatement
573
+ ? ((node as TryStatement).tryBlock !== undefined ? 1 : 0) |
574
+ ((node as TryStatement).catchClause !== undefined ? 2 : 0) |
575
+ ((node as TryStatement).finallyBlock !== undefined ? 4 : 0)
576
+ : 0;
577
+ case SyntaxKind.CatchClause:
578
+ return node instanceof CatchClause
579
+ ? ((node as CatchClause).variableDeclaration !== undefined ? 1 : 0) |
580
+ ((node as CatchClause).block !== undefined ? 2 : 0)
581
+ : 0;
582
+ case SyntaxKind.LabeledStatement:
583
+ return node instanceof LabeledStatement
584
+ ? ((node as LabeledStatement).label !== undefined ? 1 : 0) |
585
+ ((node as LabeledStatement).statement !== undefined ? 2 : 0)
586
+ : 0;
587
+ case SyntaxKind.ExpressionStatement:
588
+ return node instanceof ExpressionStatement ? ((node as ExpressionStatement).expression !== undefined ? 1 : 0) : 0;
589
+ case SyntaxKind.Block:
590
+ return node instanceof Block ? ((node as Block).statements !== undefined ? 1 : 0) : 0;
591
+ case SyntaxKind.VariableStatement:
592
+ return node instanceof VariableStatement
593
+ ? (hasModifiers((node as VariableStatement).modifiers) ? 1 : 0) |
594
+ ((node as VariableStatement).declarationList !== undefined ? 2 : 0)
595
+ : 0;
596
+ case SyntaxKind.VariableDeclaration:
597
+ return node instanceof VariableDeclaration
598
+ ? ((node as VariableDeclaration).name !== undefined ? 1 : 0) |
599
+ ((node as VariableDeclaration).exclamationToken !== undefined ? 2 : 0) |
600
+ ((node as VariableDeclaration).type !== undefined ? 4 : 0) |
601
+ ((node as VariableDeclaration).initializer !== undefined ? 8 : 0)
602
+ : 0;
603
+ case SyntaxKind.VariableDeclarationList:
604
+ return node instanceof VariableDeclarationList
605
+ ? (node as VariableDeclarationList).declarations !== undefined
606
+ ? 1
607
+ : 0
608
+ : 0;
609
+ case SyntaxKind.ObjectBindingPattern:
610
+ case SyntaxKind.ArrayBindingPattern:
611
+ return node instanceof BindingPattern ? ((node as BindingPattern).elements !== undefined ? 1 : 0) : 0;
612
+ case SyntaxKind.Parameter:
613
+ return node instanceof ParameterDeclaration
614
+ ? (hasModifiers((node as ParameterDeclaration).modifiers) ? 1 : 0) |
615
+ ((node as ParameterDeclaration).dotDotDotToken !== undefined ? 2 : 0) |
616
+ ((node as ParameterDeclaration).name !== undefined ? 4 : 0) |
617
+ ((node as ParameterDeclaration).questionToken !== undefined ? 8 : 0) |
618
+ ((node as ParameterDeclaration).type !== undefined ? 16 : 0) |
619
+ ((node as ParameterDeclaration).initializer !== undefined ? 32 : 0)
620
+ : 0;
621
+ case SyntaxKind.BindingElement:
622
+ return node instanceof BindingElement
623
+ ? ((node as BindingElement).dotDotDotToken !== undefined ? 1 : 0) |
624
+ ((node as BindingElement).propertyName !== undefined ? 2 : 0) |
625
+ ((node as BindingElement).name !== undefined ? 4 : 0) |
626
+ ((node as BindingElement).initializer !== undefined ? 8 : 0)
627
+ : 0;
628
+ case SyntaxKind.MissingDeclaration:
629
+ return node instanceof MissingDeclaration ? (hasModifiers((node as MissingDeclaration).modifiers) ? 1 : 0) : 0;
630
+ case SyntaxKind.FunctionDeclaration:
631
+ return node instanceof FunctionDeclaration
632
+ ? (hasModifiers((node as FunctionDeclaration).modifiers) ? 1 : 0) |
633
+ ((node as FunctionDeclaration).asteriskToken !== undefined ? 2 : 0) |
634
+ ((node as FunctionDeclaration).name !== undefined ? 4 : 0) |
635
+ ((node as FunctionDeclaration).typeParameters !== undefined ? 8 : 0) |
636
+ ((node as FunctionDeclaration).parameters !== undefined ? 16 : 0) |
637
+ ((node as FunctionDeclaration).type !== undefined ? 32 : 0) |
638
+ ((node as FunctionDeclaration).body !== undefined ? 64 : 0)
639
+ : 0;
640
+ case SyntaxKind.ClassDeclaration:
641
+ return node instanceof ClassDeclaration
642
+ ? (hasModifiers((node as ClassDeclaration).modifiers) ? 1 : 0) |
643
+ ((node as ClassDeclaration).name !== undefined ? 2 : 0) |
644
+ ((node as ClassDeclaration).typeParameters !== undefined ? 4 : 0) |
645
+ ((node as ClassDeclaration).heritageClauses !== undefined ? 8 : 0) |
646
+ ((node as ClassDeclaration).members !== undefined ? 16 : 0)
647
+ : 0;
648
+ case SyntaxKind.ClassExpression:
649
+ return node instanceof ClassExpression
650
+ ? (hasModifiers((node as ClassExpression).modifiers) ? 1 : 0) |
651
+ ((node as ClassExpression).name !== undefined ? 2 : 0) |
652
+ ((node as ClassExpression).typeParameters !== undefined ? 4 : 0) |
653
+ ((node as ClassExpression).heritageClauses !== undefined ? 8 : 0) |
654
+ ((node as ClassExpression).members !== undefined ? 16 : 0)
655
+ : 0;
656
+ case SyntaxKind.HeritageClause:
657
+ return node instanceof HeritageClause ? ((node as HeritageClause).types !== undefined ? 1 : 0) : 0;
658
+ case SyntaxKind.InterfaceDeclaration:
659
+ return node instanceof InterfaceDeclaration
660
+ ? (hasModifiers((node as InterfaceDeclaration).modifiers) ? 1 : 0) |
661
+ ((node as InterfaceDeclaration).name !== undefined ? 2 : 0) |
662
+ ((node as InterfaceDeclaration).typeParameters !== undefined ? 4 : 0) |
663
+ ((node as InterfaceDeclaration).heritageClauses !== undefined ? 8 : 0) |
664
+ ((node as InterfaceDeclaration).members !== undefined ? 16 : 0)
665
+ : 0;
666
+ case SyntaxKind.TypeAliasDeclaration:
667
+ case SyntaxKind.JSTypeAliasDeclaration:
668
+ return node instanceof TypeAliasDeclaration
669
+ ? (hasModifiers((node as TypeAliasDeclaration).modifiers) ? 1 : 0) |
670
+ ((node as TypeAliasDeclaration).name !== undefined ? 2 : 0) |
671
+ ((node as TypeAliasDeclaration).typeParameters !== undefined ? 4 : 0) |
672
+ ((node as TypeAliasDeclaration).type !== undefined ? 8 : 0)
673
+ : 0;
674
+ case SyntaxKind.EnumMember:
675
+ return node instanceof EnumMember
676
+ ? ((node as EnumMember).name !== undefined ? 1 : 0) | ((node as EnumMember).initializer !== undefined ? 2 : 0)
677
+ : 0;
678
+ case SyntaxKind.EnumDeclaration:
679
+ return node instanceof EnumDeclaration
680
+ ? (hasModifiers((node as EnumDeclaration).modifiers) ? 1 : 0) |
681
+ ((node as EnumDeclaration).name !== undefined ? 2 : 0) |
682
+ ((node as EnumDeclaration).members !== undefined ? 4 : 0)
683
+ : 0;
684
+ case SyntaxKind.ModuleBlock:
685
+ return node instanceof ModuleBlock ? ((node as ModuleBlock).statements !== undefined ? 1 : 0) : 0;
686
+ case SyntaxKind.ImportDeclaration:
687
+ case SyntaxKind.JSImportDeclaration:
688
+ return node instanceof ImportDeclaration
689
+ ? (hasModifiers((node as ImportDeclaration).modifiers) ? 1 : 0) |
690
+ ((node as ImportDeclaration).importClause !== undefined ? 2 : 0) |
691
+ ((node as ImportDeclaration).moduleSpecifier !== undefined ? 4 : 0) |
692
+ ((node as ImportDeclaration).attributes !== undefined ? 8 : 0)
693
+ : 0;
694
+ case SyntaxKind.ExternalModuleReference:
695
+ return node instanceof ExternalModuleReference
696
+ ? (node as ExternalModuleReference).expression !== undefined
697
+ ? 1
698
+ : 0
699
+ : 0;
700
+ case SyntaxKind.NamespaceImport:
701
+ return node instanceof NamespaceImport ? ((node as NamespaceImport).name !== undefined ? 1 : 0) : 0;
702
+ case SyntaxKind.NamedImports:
703
+ return node instanceof NamedImports ? ((node as NamedImports).elements !== undefined ? 1 : 0) : 0;
704
+ case SyntaxKind.ExportAssignment:
705
+ return node instanceof ExportAssignment
706
+ ? (hasModifiers((node as ExportAssignment).modifiers) ? 1 : 0) |
707
+ ((node as ExportAssignment).type !== undefined ? 2 : 0) |
708
+ ((node as ExportAssignment).expression !== undefined ? 4 : 0)
709
+ : 0;
710
+ case SyntaxKind.NamespaceExportDeclaration:
711
+ return node instanceof NamespaceExportDeclaration
712
+ ? (hasModifiers((node as NamespaceExportDeclaration).modifiers) ? 1 : 0) |
713
+ ((node as NamespaceExportDeclaration).name !== undefined ? 2 : 0)
714
+ : 0;
715
+ case SyntaxKind.NamespaceExport:
716
+ return node instanceof NamespaceExport ? ((node as NamespaceExport).name !== undefined ? 1 : 0) : 0;
717
+ case SyntaxKind.NamedExports:
718
+ return node instanceof NamedExports ? ((node as NamedExports).elements !== undefined ? 1 : 0) : 0;
719
+ case SyntaxKind.ExportSpecifier:
720
+ return node instanceof ExportSpecifier
721
+ ? ((node as ExportSpecifier).propertyName !== undefined ? 1 : 0) |
722
+ ((node as ExportSpecifier).name !== undefined ? 2 : 0)
723
+ : 0;
724
+ case SyntaxKind.CallSignature:
725
+ return node instanceof CallSignatureDeclaration
726
+ ? ((node as CallSignatureDeclaration).typeParameters !== undefined ? 1 : 0) |
727
+ ((node as CallSignatureDeclaration).parameters !== undefined ? 2 : 0) |
728
+ ((node as CallSignatureDeclaration).type !== undefined ? 4 : 0)
729
+ : 0;
730
+ case SyntaxKind.ConstructSignature:
731
+ return node instanceof ConstructSignatureDeclaration
732
+ ? ((node as ConstructSignatureDeclaration).typeParameters !== undefined ? 1 : 0) |
733
+ ((node as ConstructSignatureDeclaration).parameters !== undefined ? 2 : 0) |
734
+ ((node as ConstructSignatureDeclaration).type !== undefined ? 4 : 0)
735
+ : 0;
736
+ case SyntaxKind.Constructor:
737
+ return node instanceof ConstructorDeclaration
738
+ ? (hasModifiers((node as ConstructorDeclaration).modifiers) ? 1 : 0) |
739
+ ((node as ConstructorDeclaration).typeParameters !== undefined ? 2 : 0) |
740
+ ((node as ConstructorDeclaration).parameters !== undefined ? 4 : 0) |
741
+ ((node as ConstructorDeclaration).type !== undefined ? 8 : 0) |
742
+ ((node as ConstructorDeclaration).body !== undefined ? 16 : 0)
743
+ : 0;
744
+ case SyntaxKind.GetAccessor:
745
+ return node instanceof GetAccessorDeclaration
746
+ ? (hasModifiers((node as GetAccessorDeclaration).modifiers) ? 1 : 0) |
747
+ ((node as GetAccessorDeclaration).name !== undefined ? 2 : 0) |
748
+ ((node as GetAccessorDeclaration).typeParameters !== undefined ? 4 : 0) |
749
+ ((node as GetAccessorDeclaration).parameters !== undefined ? 8 : 0) |
750
+ ((node as GetAccessorDeclaration).type !== undefined ? 16 : 0) |
751
+ ((node as GetAccessorDeclaration).body !== undefined ? 32 : 0)
752
+ : 0;
753
+ case SyntaxKind.SetAccessor:
754
+ return node instanceof SetAccessorDeclaration
755
+ ? (hasModifiers((node as SetAccessorDeclaration).modifiers) ? 1 : 0) |
756
+ ((node as SetAccessorDeclaration).name !== undefined ? 2 : 0) |
757
+ ((node as SetAccessorDeclaration).typeParameters !== undefined ? 4 : 0) |
758
+ ((node as SetAccessorDeclaration).parameters !== undefined ? 8 : 0) |
759
+ ((node as SetAccessorDeclaration).type !== undefined ? 16 : 0) |
760
+ ((node as SetAccessorDeclaration).body !== undefined ? 32 : 0)
761
+ : 0;
762
+ case SyntaxKind.IndexSignature:
763
+ return node instanceof IndexSignatureDeclaration
764
+ ? (hasModifiers((node as IndexSignatureDeclaration).modifiers) ? 1 : 0) |
765
+ ((node as IndexSignatureDeclaration).parameters !== undefined ? 2 : 0) |
766
+ ((node as IndexSignatureDeclaration).type !== undefined ? 4 : 0)
767
+ : 0;
768
+ case SyntaxKind.MethodSignature:
769
+ return node instanceof MethodSignatureDeclaration
770
+ ? (hasModifiers((node as MethodSignatureDeclaration).modifiers) ? 1 : 0) |
771
+ ((node as MethodSignatureDeclaration).name !== undefined ? 2 : 0) |
772
+ ((node as MethodSignatureDeclaration).postfixToken !== undefined ? 4 : 0) |
773
+ ((node as MethodSignatureDeclaration).typeParameters !== undefined ? 8 : 0) |
774
+ ((node as MethodSignatureDeclaration).parameters !== undefined ? 16 : 0) |
775
+ ((node as MethodSignatureDeclaration).type !== undefined ? 32 : 0)
776
+ : 0;
777
+ case SyntaxKind.MethodDeclaration:
778
+ return node instanceof MethodDeclaration
779
+ ? (hasModifiers((node as MethodDeclaration).modifiers) ? 1 : 0) |
780
+ ((node as MethodDeclaration).asteriskToken !== undefined ? 2 : 0) |
781
+ ((node as MethodDeclaration).name !== undefined ? 4 : 0) |
782
+ ((node as MethodDeclaration).postfixToken !== undefined ? 8 : 0) |
783
+ ((node as MethodDeclaration).typeParameters !== undefined ? 16 : 0) |
784
+ ((node as MethodDeclaration).parameters !== undefined ? 32 : 0) |
785
+ ((node as MethodDeclaration).type !== undefined ? 64 : 0) |
786
+ ((node as MethodDeclaration).body !== undefined ? 128 : 0)
787
+ : 0;
788
+ case SyntaxKind.PropertySignature:
789
+ return node instanceof PropertySignatureDeclaration
790
+ ? (hasModifiers((node as PropertySignatureDeclaration).modifiers) ? 1 : 0) |
791
+ ((node as PropertySignatureDeclaration).name !== undefined ? 2 : 0) |
792
+ ((node as PropertySignatureDeclaration).postfixToken !== undefined ? 4 : 0) |
793
+ ((node as PropertySignatureDeclaration).type !== undefined ? 8 : 0) |
794
+ ((node as PropertySignatureDeclaration).initializer !== undefined ? 16 : 0)
795
+ : 0;
796
+ case SyntaxKind.PropertyDeclaration:
797
+ return node instanceof PropertyDeclaration
798
+ ? (hasModifiers((node as PropertyDeclaration).modifiers) ? 1 : 0) |
799
+ ((node as PropertyDeclaration).name !== undefined ? 2 : 0) |
800
+ ((node as PropertyDeclaration).postfixToken !== undefined ? 4 : 0) |
801
+ ((node as PropertyDeclaration).type !== undefined ? 8 : 0) |
802
+ ((node as PropertyDeclaration).initializer !== undefined ? 16 : 0)
803
+ : 0;
804
+ case SyntaxKind.ClassStaticBlockDeclaration:
805
+ return node instanceof ClassStaticBlockDeclaration
806
+ ? (hasModifiers((node as ClassStaticBlockDeclaration).modifiers) ? 1 : 0) |
807
+ ((node as ClassStaticBlockDeclaration).body !== undefined ? 2 : 0)
808
+ : 0;
809
+ case SyntaxKind.BinaryExpression:
810
+ return node instanceof BinaryExpression
811
+ ? (hasModifiers((node as BinaryExpression).modifiers) ? 1 : 0) |
812
+ ((node as BinaryExpression).left !== undefined ? 2 : 0) |
813
+ ((node as BinaryExpression).type !== undefined ? 4 : 0) |
814
+ ((node as BinaryExpression).operatorToken !== undefined ? 8 : 0) |
815
+ ((node as BinaryExpression).right !== undefined ? 16 : 0)
816
+ : 0;
817
+ case SyntaxKind.PrefixUnaryExpression:
818
+ return node instanceof PrefixUnaryExpression
819
+ ? (node as PrefixUnaryExpression).operand !== undefined
820
+ ? 1
821
+ : 0
822
+ : 0;
823
+ case SyntaxKind.PostfixUnaryExpression:
824
+ return node instanceof PostfixUnaryExpression
825
+ ? (node as PostfixUnaryExpression).operand !== undefined
826
+ ? 1
827
+ : 0
828
+ : 0;
829
+ case SyntaxKind.YieldExpression:
830
+ return node instanceof YieldExpression
831
+ ? ((node as YieldExpression).asteriskToken !== undefined ? 1 : 0) |
832
+ ((node as YieldExpression).expression !== undefined ? 2 : 0)
833
+ : 0;
834
+ case SyntaxKind.ArrowFunction:
835
+ return node instanceof ArrowFunction
836
+ ? (hasModifiers((node as ArrowFunction).modifiers) ? 1 : 0) |
837
+ ((node as ArrowFunction).typeParameters !== undefined ? 2 : 0) |
838
+ ((node as ArrowFunction).parameters !== undefined ? 4 : 0) |
839
+ ((node as ArrowFunction).type !== undefined ? 8 : 0) |
840
+ ((node as ArrowFunction).equalsGreaterThanToken !== undefined ? 16 : 0) |
841
+ ((node as ArrowFunction).body !== undefined ? 32 : 0)
842
+ : 0;
843
+ case SyntaxKind.FunctionExpression:
844
+ return node instanceof FunctionExpression
845
+ ? (hasModifiers((node as FunctionExpression).modifiers) ? 1 : 0) |
846
+ ((node as FunctionExpression).asteriskToken !== undefined ? 2 : 0) |
847
+ ((node as FunctionExpression).name !== undefined ? 4 : 0) |
848
+ ((node as FunctionExpression).typeParameters !== undefined ? 8 : 0) |
849
+ ((node as FunctionExpression).parameters !== undefined ? 16 : 0) |
850
+ ((node as FunctionExpression).type !== undefined ? 32 : 0) |
851
+ ((node as FunctionExpression).body !== undefined ? 64 : 0)
852
+ : 0;
853
+ case SyntaxKind.AsExpression:
854
+ return node instanceof AsExpression
855
+ ? ((node as AsExpression).expression !== undefined ? 1 : 0) |
856
+ ((node as AsExpression).type !== undefined ? 2 : 0)
857
+ : 0;
858
+ case SyntaxKind.SatisfiesExpression:
859
+ return node instanceof SatisfiesExpression
860
+ ? ((node as SatisfiesExpression).expression !== undefined ? 1 : 0) |
861
+ ((node as SatisfiesExpression).type !== undefined ? 2 : 0)
862
+ : 0;
863
+ case SyntaxKind.ConditionalExpression:
864
+ return node instanceof ConditionalExpression
865
+ ? ((node as ConditionalExpression).condition !== undefined ? 1 : 0) |
866
+ ((node as ConditionalExpression).questionToken !== undefined ? 2 : 0) |
867
+ ((node as ConditionalExpression).whenTrue !== undefined ? 4 : 0) |
868
+ ((node as ConditionalExpression).colonToken !== undefined ? 8 : 0) |
869
+ ((node as ConditionalExpression).whenFalse !== undefined ? 16 : 0)
870
+ : 0;
871
+ case SyntaxKind.PropertyAccessExpression:
872
+ return node instanceof PropertyAccessExpression
873
+ ? ((node as PropertyAccessExpression).expression !== undefined ? 1 : 0) |
874
+ ((node as PropertyAccessExpression).questionDotToken !== undefined ? 2 : 0) |
875
+ ((node as PropertyAccessExpression).name !== undefined ? 4 : 0)
876
+ : 0;
877
+ case SyntaxKind.ElementAccessExpression:
878
+ return node instanceof ElementAccessExpression
879
+ ? ((node as ElementAccessExpression).expression !== undefined ? 1 : 0) |
880
+ ((node as ElementAccessExpression).questionDotToken !== undefined ? 2 : 0) |
881
+ ((node as ElementAccessExpression).argumentExpression !== undefined ? 4 : 0)
882
+ : 0;
883
+ case SyntaxKind.CallExpression:
884
+ return node instanceof CallExpression
885
+ ? ((node as CallExpression).expression !== undefined ? 1 : 0) |
886
+ ((node as CallExpression).questionDotToken !== undefined ? 2 : 0) |
887
+ ((node as CallExpression).typeArguments !== undefined ? 4 : 0) |
888
+ ((node as CallExpression).arguments !== undefined ? 8 : 0)
889
+ : 0;
890
+ case SyntaxKind.NewExpression:
891
+ return node instanceof NewExpression
892
+ ? ((node as NewExpression).expression !== undefined ? 1 : 0) |
893
+ ((node as NewExpression).typeArguments !== undefined ? 2 : 0) |
894
+ ((node as NewExpression).arguments !== undefined ? 4 : 0)
895
+ : 0;
896
+ case SyntaxKind.MetaProperty:
897
+ return node instanceof MetaProperty ? ((node as MetaProperty).name !== undefined ? 1 : 0) : 0;
898
+ case SyntaxKind.NonNullExpression:
899
+ return node instanceof NonNullExpression ? ((node as NonNullExpression).expression !== undefined ? 1 : 0) : 0;
900
+ case SyntaxKind.SpreadElement:
901
+ return node instanceof SpreadElement ? ((node as SpreadElement).expression !== undefined ? 1 : 0) : 0;
902
+ case SyntaxKind.TemplateExpression:
903
+ return node instanceof TemplateExpression
904
+ ? ((node as TemplateExpression).head !== undefined ? 1 : 0) |
905
+ ((node as TemplateExpression).templateSpans !== undefined ? 2 : 0)
906
+ : 0;
907
+ case SyntaxKind.TemplateSpan:
908
+ return node instanceof TemplateSpan
909
+ ? ((node as TemplateSpan).expression !== undefined ? 1 : 0) |
910
+ ((node as TemplateSpan).literal !== undefined ? 2 : 0)
911
+ : 0;
912
+ case SyntaxKind.TaggedTemplateExpression:
913
+ return node instanceof TaggedTemplateExpression
914
+ ? ((node as TaggedTemplateExpression).tag !== undefined ? 1 : 0) |
915
+ ((node as TaggedTemplateExpression).questionDotToken !== undefined ? 2 : 0) |
916
+ ((node as TaggedTemplateExpression).typeArguments !== undefined ? 4 : 0) |
917
+ ((node as TaggedTemplateExpression).template !== undefined ? 8 : 0)
918
+ : 0;
919
+ case SyntaxKind.ParenthesizedExpression:
920
+ return node instanceof ParenthesizedExpression
921
+ ? (node as ParenthesizedExpression).expression !== undefined
922
+ ? 1
923
+ : 0
924
+ : 0;
925
+ case SyntaxKind.ArrayLiteralExpression:
926
+ return node instanceof ArrayLiteralExpression
927
+ ? (node as ArrayLiteralExpression).elements !== undefined
928
+ ? 1
929
+ : 0
930
+ : 0;
931
+ case SyntaxKind.ObjectLiteralExpression:
932
+ return node instanceof ObjectLiteralExpression
933
+ ? (node as ObjectLiteralExpression).properties !== undefined
934
+ ? 1
935
+ : 0
936
+ : 0;
937
+ case SyntaxKind.SpreadAssignment:
938
+ return node instanceof SpreadAssignment ? ((node as SpreadAssignment).expression !== undefined ? 1 : 0) : 0;
939
+ case SyntaxKind.PropertyAssignment:
940
+ return node instanceof PropertyAssignment
941
+ ? (hasModifiers((node as PropertyAssignment).modifiers) ? 1 : 0) |
942
+ ((node as PropertyAssignment).name !== undefined ? 2 : 0) |
943
+ ((node as PropertyAssignment).postfixToken !== undefined ? 4 : 0) |
944
+ ((node as PropertyAssignment).type !== undefined ? 8 : 0) |
945
+ ((node as PropertyAssignment).initializer !== undefined ? 16 : 0)
946
+ : 0;
947
+ case SyntaxKind.ShorthandPropertyAssignment:
948
+ return node instanceof ShorthandPropertyAssignment
949
+ ? (hasModifiers((node as ShorthandPropertyAssignment).modifiers) ? 1 : 0) |
950
+ ((node as ShorthandPropertyAssignment).name !== undefined ? 2 : 0) |
951
+ ((node as ShorthandPropertyAssignment).postfixToken !== undefined ? 4 : 0) |
952
+ ((node as ShorthandPropertyAssignment).type !== undefined ? 8 : 0) |
953
+ ((node as ShorthandPropertyAssignment).equalsToken !== undefined ? 16 : 0) |
954
+ ((node as ShorthandPropertyAssignment).objectAssignmentInitializer !== undefined ? 32 : 0)
955
+ : 0;
956
+ case SyntaxKind.DeleteExpression:
957
+ return node instanceof DeleteExpression ? ((node as DeleteExpression).expression !== undefined ? 1 : 0) : 0;
958
+ case SyntaxKind.TypeOfExpression:
959
+ return node instanceof TypeOfExpression ? ((node as TypeOfExpression).expression !== undefined ? 1 : 0) : 0;
960
+ case SyntaxKind.VoidExpression:
961
+ return node instanceof VoidExpression ? ((node as VoidExpression).expression !== undefined ? 1 : 0) : 0;
962
+ case SyntaxKind.AwaitExpression:
963
+ return node instanceof AwaitExpression ? ((node as AwaitExpression).expression !== undefined ? 1 : 0) : 0;
964
+ case SyntaxKind.TypeAssertionExpression:
965
+ return node instanceof TypeAssertion
966
+ ? ((node as TypeAssertion).type !== undefined ? 1 : 0) |
967
+ ((node as TypeAssertion).expression !== undefined ? 2 : 0)
968
+ : 0;
969
+ case SyntaxKind.UnionType:
970
+ return node instanceof UnionTypeNode ? ((node as UnionTypeNode).types !== undefined ? 1 : 0) : 0;
971
+ case SyntaxKind.IntersectionType:
972
+ return node instanceof IntersectionTypeNode ? ((node as IntersectionTypeNode).types !== undefined ? 1 : 0) : 0;
973
+ case SyntaxKind.ConditionalType:
974
+ return node instanceof ConditionalTypeNode
975
+ ? ((node as ConditionalTypeNode).checkType !== undefined ? 1 : 0) |
976
+ ((node as ConditionalTypeNode).extendsType !== undefined ? 2 : 0) |
977
+ ((node as ConditionalTypeNode).trueType !== undefined ? 4 : 0) |
978
+ ((node as ConditionalTypeNode).falseType !== undefined ? 8 : 0)
979
+ : 0;
980
+ case SyntaxKind.TypeOperator:
981
+ return node instanceof TypeOperatorNode ? ((node as TypeOperatorNode).type !== undefined ? 1 : 0) : 0;
982
+ case SyntaxKind.InferType:
983
+ return node instanceof InferTypeNode ? ((node as InferTypeNode).typeParameter !== undefined ? 1 : 0) : 0;
984
+ case SyntaxKind.ArrayType:
985
+ return node instanceof ArrayTypeNode ? ((node as ArrayTypeNode).elementType !== undefined ? 1 : 0) : 0;
986
+ case SyntaxKind.IndexedAccessType:
987
+ return node instanceof IndexedAccessTypeNode
988
+ ? ((node as IndexedAccessTypeNode).objectType !== undefined ? 1 : 0) |
989
+ ((node as IndexedAccessTypeNode).indexType !== undefined ? 2 : 0)
990
+ : 0;
991
+ case SyntaxKind.TypeReference:
992
+ return node instanceof TypeReferenceNode
993
+ ? ((node as TypeReferenceNode).typeName !== undefined ? 1 : 0) |
994
+ ((node as TypeReferenceNode).typeArguments !== undefined ? 2 : 0)
995
+ : 0;
996
+ case SyntaxKind.ExpressionWithTypeArguments:
997
+ return node instanceof ExpressionWithTypeArguments
998
+ ? ((node as ExpressionWithTypeArguments).expression !== undefined ? 1 : 0) |
999
+ ((node as ExpressionWithTypeArguments).typeArguments !== undefined ? 2 : 0)
1000
+ : 0;
1001
+ case SyntaxKind.LiteralType:
1002
+ return node instanceof LiteralTypeNode ? ((node as LiteralTypeNode).literal !== undefined ? 1 : 0) : 0;
1003
+ case SyntaxKind.TypePredicate:
1004
+ return node instanceof TypePredicateNode
1005
+ ? ((node as TypePredicateNode).assertsModifier !== undefined ? 1 : 0) |
1006
+ ((node as TypePredicateNode).parameterName !== undefined ? 2 : 0) |
1007
+ ((node as TypePredicateNode).type !== undefined ? 4 : 0)
1008
+ : 0;
1009
+ case SyntaxKind.ImportAttribute:
1010
+ return node instanceof ImportAttribute
1011
+ ? ((node as ImportAttribute).name !== undefined ? 1 : 0) |
1012
+ ((node as ImportAttribute).value !== undefined ? 2 : 0)
1013
+ : 0;
1014
+ case SyntaxKind.ImportAttributes:
1015
+ return node instanceof ImportAttributes ? ((node as ImportAttributes).attributes !== undefined ? 1 : 0) : 0;
1016
+ case SyntaxKind.TypeQuery:
1017
+ return node instanceof TypeQueryNode
1018
+ ? ((node as TypeQueryNode).exprName !== undefined ? 1 : 0) |
1019
+ ((node as TypeQueryNode).typeArguments !== undefined ? 2 : 0)
1020
+ : 0;
1021
+ case SyntaxKind.MappedType:
1022
+ return node instanceof MappedTypeNode
1023
+ ? ((node as MappedTypeNode).readonlyToken !== undefined ? 1 : 0) |
1024
+ ((node as MappedTypeNode).typeParameter !== undefined ? 2 : 0) |
1025
+ ((node as MappedTypeNode).nameType !== undefined ? 4 : 0) |
1026
+ ((node as MappedTypeNode).questionToken !== undefined ? 8 : 0) |
1027
+ ((node as MappedTypeNode).type !== undefined ? 16 : 0) |
1028
+ ((node as MappedTypeNode).members !== undefined ? 32 : 0)
1029
+ : 0;
1030
+ case SyntaxKind.TypeLiteral:
1031
+ return node instanceof TypeLiteralNode ? ((node as TypeLiteralNode).members !== undefined ? 1 : 0) : 0;
1032
+ case SyntaxKind.TupleType:
1033
+ return node instanceof TupleTypeNode ? ((node as TupleTypeNode).elements !== undefined ? 1 : 0) : 0;
1034
+ case SyntaxKind.NamedTupleMember:
1035
+ return node instanceof NamedTupleMember
1036
+ ? ((node as NamedTupleMember).dotDotDotToken !== undefined ? 1 : 0) |
1037
+ ((node as NamedTupleMember).name !== undefined ? 2 : 0) |
1038
+ ((node as NamedTupleMember).questionToken !== undefined ? 4 : 0) |
1039
+ ((node as NamedTupleMember).type !== undefined ? 8 : 0)
1040
+ : 0;
1041
+ case SyntaxKind.OptionalType:
1042
+ return node instanceof OptionalTypeNode ? ((node as OptionalTypeNode).type !== undefined ? 1 : 0) : 0;
1043
+ case SyntaxKind.RestType:
1044
+ return node instanceof RestTypeNode ? ((node as RestTypeNode).type !== undefined ? 1 : 0) : 0;
1045
+ case SyntaxKind.ParenthesizedType:
1046
+ return node instanceof ParenthesizedTypeNode ? ((node as ParenthesizedTypeNode).type !== undefined ? 1 : 0) : 0;
1047
+ case SyntaxKind.FunctionType:
1048
+ return node instanceof FunctionTypeNode
1049
+ ? ((node as FunctionTypeNode).typeParameters !== undefined ? 1 : 0) |
1050
+ ((node as FunctionTypeNode).parameters !== undefined ? 2 : 0) |
1051
+ ((node as FunctionTypeNode).type !== undefined ? 4 : 0)
1052
+ : 0;
1053
+ case SyntaxKind.ConstructorType:
1054
+ return node instanceof ConstructorTypeNode
1055
+ ? (hasModifiers((node as ConstructorTypeNode).modifiers) ? 1 : 0) |
1056
+ ((node as ConstructorTypeNode).typeParameters !== undefined ? 2 : 0) |
1057
+ ((node as ConstructorTypeNode).parameters !== undefined ? 4 : 0) |
1058
+ ((node as ConstructorTypeNode).type !== undefined ? 8 : 0)
1059
+ : 0;
1060
+ case SyntaxKind.TemplateLiteralType:
1061
+ return node instanceof TemplateLiteralTypeNode
1062
+ ? ((node as TemplateLiteralTypeNode).head !== undefined ? 1 : 0) |
1063
+ ((node as TemplateLiteralTypeNode).templateSpans !== undefined ? 2 : 0)
1064
+ : 0;
1065
+ case SyntaxKind.TemplateLiteralTypeSpan:
1066
+ return node instanceof TemplateLiteralTypeSpan
1067
+ ? ((node as TemplateLiteralTypeSpan).type !== undefined ? 1 : 0) |
1068
+ ((node as TemplateLiteralTypeSpan).literal !== undefined ? 2 : 0)
1069
+ : 0;
1070
+ case SyntaxKind.JsxElement:
1071
+ return node instanceof JsxElement
1072
+ ? ((node as JsxElement).openingElement !== undefined ? 1 : 0) |
1073
+ ((node as JsxElement).children !== undefined ? 2 : 0) |
1074
+ ((node as JsxElement).closingElement !== undefined ? 4 : 0)
1075
+ : 0;
1076
+ case SyntaxKind.JsxAttributes:
1077
+ return node instanceof JsxAttributes ? ((node as JsxAttributes).properties !== undefined ? 1 : 0) : 0;
1078
+ case SyntaxKind.JsxNamespacedName:
1079
+ return node instanceof JsxNamespacedName
1080
+ ? ((node as JsxNamespacedName).namespace !== undefined ? 1 : 0) |
1081
+ ((node as JsxNamespacedName).name !== undefined ? 2 : 0)
1082
+ : 0;
1083
+ case SyntaxKind.JsxOpeningElement:
1084
+ return node instanceof JsxOpeningElement
1085
+ ? ((node as JsxOpeningElement).tagName !== undefined ? 1 : 0) |
1086
+ ((node as JsxOpeningElement).typeArguments !== undefined ? 2 : 0) |
1087
+ ((node as JsxOpeningElement).attributes !== undefined ? 4 : 0)
1088
+ : 0;
1089
+ case SyntaxKind.JsxSelfClosingElement:
1090
+ return node instanceof JsxSelfClosingElement
1091
+ ? ((node as JsxSelfClosingElement).tagName !== undefined ? 1 : 0) |
1092
+ ((node as JsxSelfClosingElement).typeArguments !== undefined ? 2 : 0) |
1093
+ ((node as JsxSelfClosingElement).attributes !== undefined ? 4 : 0)
1094
+ : 0;
1095
+ case SyntaxKind.JsxFragment:
1096
+ return node instanceof JsxFragment
1097
+ ? ((node as JsxFragment).openingFragment !== undefined ? 1 : 0) |
1098
+ ((node as JsxFragment).children !== undefined ? 2 : 0) |
1099
+ ((node as JsxFragment).closingFragment !== undefined ? 4 : 0)
1100
+ : 0;
1101
+ case SyntaxKind.JsxAttribute:
1102
+ return node instanceof JsxAttribute
1103
+ ? ((node as JsxAttribute).name !== undefined ? 1 : 0) |
1104
+ ((node as JsxAttribute).initializer !== undefined ? 2 : 0)
1105
+ : 0;
1106
+ case SyntaxKind.JsxSpreadAttribute:
1107
+ return node instanceof JsxSpreadAttribute ? ((node as JsxSpreadAttribute).expression !== undefined ? 1 : 0) : 0;
1108
+ case SyntaxKind.JsxClosingElement:
1109
+ return node instanceof JsxClosingElement ? ((node as JsxClosingElement).tagName !== undefined ? 1 : 0) : 0;
1110
+ case SyntaxKind.JsxExpression:
1111
+ return node instanceof JsxExpression
1112
+ ? ((node as JsxExpression).dotDotDotToken !== undefined ? 1 : 0) |
1113
+ ((node as JsxExpression).expression !== undefined ? 2 : 0)
1114
+ : 0;
1115
+ case SyntaxKind.JSDoc:
1116
+ return node instanceof JSDoc
1117
+ ? ((node as JSDoc).comment !== undefined ? 1 : 0) | ((node as JSDoc).tags !== undefined ? 2 : 0)
1118
+ : 0;
1119
+ case SyntaxKind.JSDocTypeExpression:
1120
+ return node instanceof JSDocTypeExpression ? ((node as JSDocTypeExpression).type !== undefined ? 1 : 0) : 0;
1121
+ case SyntaxKind.JSDocNonNullableType:
1122
+ return node instanceof JSDocNonNullableType ? ((node as JSDocNonNullableType).type !== undefined ? 1 : 0) : 0;
1123
+ case SyntaxKind.JSDocNullableType:
1124
+ return node instanceof JSDocNullableType ? ((node as JSDocNullableType).type !== undefined ? 1 : 0) : 0;
1125
+ case SyntaxKind.JSDocVariadicType:
1126
+ return node instanceof JSDocVariadicType ? ((node as JSDocVariadicType).type !== undefined ? 1 : 0) : 0;
1127
+ case SyntaxKind.JSDocOptionalType:
1128
+ return node instanceof JSDocOptionalType ? ((node as JSDocOptionalType).type !== undefined ? 1 : 0) : 0;
1129
+ case SyntaxKind.JSDocTypeTag:
1130
+ return node instanceof JSDocTypeTag
1131
+ ? ((node as JSDocTypeTag).tagName !== undefined ? 1 : 0) |
1132
+ ((node as JSDocTypeTag).typeExpression !== undefined ? 2 : 0) |
1133
+ ((node as JSDocTypeTag).comment !== undefined ? 4 : 0)
1134
+ : 0;
1135
+ case SyntaxKind.JSDocUnknownTag:
1136
+ return node instanceof JSDocUnknownTag
1137
+ ? ((node as JSDocUnknownTag).tagName !== undefined ? 1 : 0) |
1138
+ ((node as JSDocUnknownTag).comment !== undefined ? 2 : 0)
1139
+ : 0;
1140
+ case SyntaxKind.JSDocTemplateTag:
1141
+ return node instanceof JSDocTemplateTag
1142
+ ? ((node as JSDocTemplateTag).tagName !== undefined ? 1 : 0) |
1143
+ ((node as JSDocTemplateTag).constraint !== undefined ? 2 : 0) |
1144
+ ((node as JSDocTemplateTag).typeParameters !== undefined ? 4 : 0) |
1145
+ ((node as JSDocTemplateTag).comment !== undefined ? 8 : 0)
1146
+ : 0;
1147
+ case SyntaxKind.JSDocReturnTag:
1148
+ return node instanceof JSDocReturnTag
1149
+ ? ((node as JSDocReturnTag).tagName !== undefined ? 1 : 0) |
1150
+ ((node as JSDocReturnTag).typeExpression !== undefined ? 2 : 0) |
1151
+ ((node as JSDocReturnTag).comment !== undefined ? 4 : 0)
1152
+ : 0;
1153
+ case SyntaxKind.JSDocPublicTag:
1154
+ return node instanceof JSDocPublicTag
1155
+ ? ((node as JSDocPublicTag).tagName !== undefined ? 1 : 0) |
1156
+ ((node as JSDocPublicTag).comment !== undefined ? 2 : 0)
1157
+ : 0;
1158
+ case SyntaxKind.JSDocPrivateTag:
1159
+ return node instanceof JSDocPrivateTag
1160
+ ? ((node as JSDocPrivateTag).tagName !== undefined ? 1 : 0) |
1161
+ ((node as JSDocPrivateTag).comment !== undefined ? 2 : 0)
1162
+ : 0;
1163
+ case SyntaxKind.JSDocProtectedTag:
1164
+ return node instanceof JSDocProtectedTag
1165
+ ? ((node as JSDocProtectedTag).tagName !== undefined ? 1 : 0) |
1166
+ ((node as JSDocProtectedTag).comment !== undefined ? 2 : 0)
1167
+ : 0;
1168
+ case SyntaxKind.JSDocReadonlyTag:
1169
+ return node instanceof JSDocReadonlyTag
1170
+ ? ((node as JSDocReadonlyTag).tagName !== undefined ? 1 : 0) |
1171
+ ((node as JSDocReadonlyTag).comment !== undefined ? 2 : 0)
1172
+ : 0;
1173
+ case SyntaxKind.JSDocOverrideTag:
1174
+ return node instanceof JSDocOverrideTag
1175
+ ? ((node as JSDocOverrideTag).tagName !== undefined ? 1 : 0) |
1176
+ ((node as JSDocOverrideTag).comment !== undefined ? 2 : 0)
1177
+ : 0;
1178
+ case SyntaxKind.JSDocDeprecatedTag:
1179
+ return node instanceof JSDocDeprecatedTag
1180
+ ? ((node as JSDocDeprecatedTag).tagName !== undefined ? 1 : 0) |
1181
+ ((node as JSDocDeprecatedTag).comment !== undefined ? 2 : 0)
1182
+ : 0;
1183
+ case SyntaxKind.JSDocSeeTag:
1184
+ return node instanceof JSDocSeeTag
1185
+ ? ((node as JSDocSeeTag).tagName !== undefined ? 1 : 0) |
1186
+ ((node as JSDocSeeTag).nameExpression !== undefined ? 2 : 0) |
1187
+ ((node as JSDocSeeTag).comment !== undefined ? 4 : 0)
1188
+ : 0;
1189
+ case SyntaxKind.JSDocImplementsTag:
1190
+ return node instanceof JSDocImplementsTag
1191
+ ? ((node as JSDocImplementsTag).tagName !== undefined ? 1 : 0) |
1192
+ ((node as JSDocImplementsTag).className !== undefined ? 2 : 0) |
1193
+ ((node as JSDocImplementsTag).comment !== undefined ? 4 : 0)
1194
+ : 0;
1195
+ case SyntaxKind.JSDocAugmentsTag:
1196
+ return node instanceof JSDocAugmentsTag
1197
+ ? ((node as JSDocAugmentsTag).tagName !== undefined ? 1 : 0) |
1198
+ ((node as JSDocAugmentsTag).className !== undefined ? 2 : 0) |
1199
+ ((node as JSDocAugmentsTag).comment !== undefined ? 4 : 0)
1200
+ : 0;
1201
+ case SyntaxKind.JSDocSatisfiesTag:
1202
+ return node instanceof JSDocSatisfiesTag
1203
+ ? ((node as JSDocSatisfiesTag).tagName !== undefined ? 1 : 0) |
1204
+ ((node as JSDocSatisfiesTag).typeExpression !== undefined ? 2 : 0) |
1205
+ ((node as JSDocSatisfiesTag).comment !== undefined ? 4 : 0)
1206
+ : 0;
1207
+ case SyntaxKind.JSDocThrowsTag:
1208
+ return node instanceof JSDocThrowsTag
1209
+ ? ((node as JSDocThrowsTag).tagName !== undefined ? 1 : 0) |
1210
+ ((node as JSDocThrowsTag).typeExpression !== undefined ? 2 : 0) |
1211
+ ((node as JSDocThrowsTag).comment !== undefined ? 4 : 0)
1212
+ : 0;
1213
+ case SyntaxKind.JSDocThisTag:
1214
+ return node instanceof JSDocThisTag
1215
+ ? ((node as JSDocThisTag).tagName !== undefined ? 1 : 0) |
1216
+ ((node as JSDocThisTag).typeExpression !== undefined ? 2 : 0) |
1217
+ ((node as JSDocThisTag).comment !== undefined ? 4 : 0)
1218
+ : 0;
1219
+ case SyntaxKind.JSDocImportTag:
1220
+ return node instanceof JSDocImportTag
1221
+ ? ((node as JSDocImportTag).tagName !== undefined ? 1 : 0) |
1222
+ ((node as JSDocImportTag).importClause !== undefined ? 2 : 0) |
1223
+ ((node as JSDocImportTag).moduleSpecifier !== undefined ? 4 : 0) |
1224
+ ((node as JSDocImportTag).attributes !== undefined ? 8 : 0) |
1225
+ ((node as JSDocImportTag).comment !== undefined ? 16 : 0)
1226
+ : 0;
1227
+ case SyntaxKind.JSDocCallbackTag:
1228
+ return node instanceof JSDocCallbackTag
1229
+ ? ((node as JSDocCallbackTag).tagName !== undefined ? 1 : 0) |
1230
+ ((node as JSDocCallbackTag).typeExpression !== undefined ? 2 : 0) |
1231
+ ((node as JSDocCallbackTag).name !== undefined ? 4 : 0) |
1232
+ ((node as JSDocCallbackTag).comment !== undefined ? 8 : 0)
1233
+ : 0;
1234
+ case SyntaxKind.JSDocOverloadTag:
1235
+ return node instanceof JSDocOverloadTag
1236
+ ? ((node as JSDocOverloadTag).tagName !== undefined ? 1 : 0) |
1237
+ ((node as JSDocOverloadTag).typeExpression !== undefined ? 2 : 0) |
1238
+ ((node as JSDocOverloadTag).comment !== undefined ? 4 : 0)
1239
+ : 0;
1240
+ case SyntaxKind.JSDocTypedefTag:
1241
+ return node instanceof JSDocTypedefTag
1242
+ ? ((node as JSDocTypedefTag).tagName !== undefined ? 1 : 0) |
1243
+ ((node as JSDocTypedefTag).typeExpression !== undefined ? 2 : 0) |
1244
+ ((node as JSDocTypedefTag).name !== undefined ? 4 : 0) |
1245
+ ((node as JSDocTypedefTag).comment !== undefined ? 8 : 0)
1246
+ : 0;
1247
+ case SyntaxKind.JSDocSignature:
1248
+ return node instanceof JSDocSignature
1249
+ ? ((node as JSDocSignature).typeParameters !== undefined ? 1 : 0) |
1250
+ ((node as JSDocSignature).parameters !== undefined ? 2 : 0) |
1251
+ ((node as JSDocSignature).type !== undefined ? 4 : 0)
1252
+ : 0;
1253
+ case SyntaxKind.JSDocNameReference:
1254
+ return node instanceof JSDocNameReference ? ((node as JSDocNameReference).name !== undefined ? 1 : 0) : 0;
1255
+ case SyntaxKind.ModuleDeclaration:
1256
+ return node instanceof ModuleDeclaration
1257
+ ? (hasModifiers((node as ModuleDeclaration).modifiers) ? 1 : 0) |
1258
+ ((node as ModuleDeclaration).name !== undefined ? 2 : 0) |
1259
+ ((node as ModuleDeclaration).body !== undefined ? 4 : 0)
1260
+ : 0;
1261
+ case SyntaxKind.ImportEqualsDeclaration:
1262
+ return node instanceof ImportEqualsDeclaration
1263
+ ? (hasModifiers((node as ImportEqualsDeclaration).modifiers) ? 1 : 0) |
1264
+ ((node as ImportEqualsDeclaration).name !== undefined ? 2 : 0) |
1265
+ ((node as ImportEqualsDeclaration).moduleReference !== undefined ? 4 : 0)
1266
+ : 0;
1267
+ case SyntaxKind.ExportDeclaration:
1268
+ return node instanceof ExportDeclaration
1269
+ ? (hasModifiers((node as ExportDeclaration).modifiers) ? 1 : 0) |
1270
+ ((node as ExportDeclaration).exportClause !== undefined ? 2 : 0) |
1271
+ ((node as ExportDeclaration).moduleSpecifier !== undefined ? 4 : 0) |
1272
+ ((node as ExportDeclaration).attributes !== undefined ? 8 : 0)
1273
+ : 0;
1274
+ case SyntaxKind.ImportType:
1275
+ return node instanceof ImportTypeNode
1276
+ ? ((node as ImportTypeNode).argument !== undefined ? 1 : 0) |
1277
+ ((node as ImportTypeNode).attributes !== undefined ? 2 : 0) |
1278
+ ((node as ImportTypeNode).qualifier !== undefined ? 4 : 0) |
1279
+ ((node as ImportTypeNode).typeArguments !== undefined ? 8 : 0)
1280
+ : 0;
1281
+ case SyntaxKind.ImportClause:
1282
+ return node instanceof ImportClause
1283
+ ? ((node as ImportClause).name !== undefined ? 1 : 0) |
1284
+ ((node as ImportClause).namedBindings !== undefined ? 2 : 0)
1285
+ : 0;
1286
+ case SyntaxKind.ImportSpecifier:
1287
+ return node instanceof ImportSpecifier
1288
+ ? ((node as ImportSpecifier).propertyName !== undefined ? 1 : 0) |
1289
+ ((node as ImportSpecifier).name !== undefined ? 2 : 0)
1290
+ : 0;
1291
+ case SyntaxKind.JSDocLink:
1292
+ return node instanceof JSDocLink ? ((node as JSDocLink).name !== undefined ? 1 : 0) : 0;
1293
+ case SyntaxKind.JSDocLinkPlain:
1294
+ return node instanceof JSDocLinkPlain ? ((node as JSDocLinkPlain).name !== undefined ? 1 : 0) : 0;
1295
+ case SyntaxKind.JSDocLinkCode:
1296
+ return node instanceof JSDocLinkCode ? ((node as JSDocLinkCode).name !== undefined ? 1 : 0) : 0;
1297
+ case SyntaxKind.TypeParameter:
1298
+ return node instanceof TypeParameterDeclaration
1299
+ ? (hasModifiers((node as TypeParameterDeclaration).modifiers) ? 1 : 0) |
1300
+ ((node as TypeParameterDeclaration).name !== undefined ? 2 : 0) |
1301
+ ((node as TypeParameterDeclaration).constraint !== undefined ? 4 : 0) |
1302
+ ((node as TypeParameterDeclaration).expression !== undefined ? 8 : 0) |
1303
+ ((node as TypeParameterDeclaration).defaultType !== undefined ? 16 : 0)
1304
+ : 0;
1305
+ case SyntaxKind.JSDocTypeLiteral:
1306
+ return node instanceof JSDocTypeLiteral ? (hasElements((node as JSDocTypeLiteral).jsdocPropertyTags) ? 1 : 0) : 0;
1307
+ case SyntaxKind.JSDocParameterTag:
1308
+ case SyntaxKind.JSDocPropertyTag:
1309
+ return node instanceof JSDocParameterOrPropertyTag
1310
+ ? ((node as JSDocParameterOrPropertyTag).tagName !== undefined ? 1 : 0) |
1311
+ ((node as JSDocParameterOrPropertyTag).name !== undefined ? 2 : 0) |
1312
+ ((node as JSDocParameterOrPropertyTag).typeExpression !== undefined ? 4 : 0) |
1313
+ ((node as JSDocParameterOrPropertyTag).comment !== undefined ? 8 : 0)
1314
+ : 0;
1315
+ default:
1316
+ return 0;
1317
+ }
1318
+ }
1319
+
1320
+ function bit(value: boolean): number {
1321
+ return value ? 1 : 0;
1322
+ }
1323
+
1324
+ /** Small per-kind values in bits 24-29 of the data word. */
1325
+ function commonData(node: Node): number {
1326
+ switch (node.kind) {
1327
+ case SyntaxKind.Block:
1328
+ return node instanceof Block ? bit((node as Block).multiLine) << 24 : 0;
1329
+ case SyntaxKind.HeritageClause:
1330
+ return node instanceof HeritageClause
1331
+ ? bit((node as HeritageClause).token === SyntaxKind.ImplementsKeyword) << 24
1332
+ : 0;
1333
+ case SyntaxKind.ExportAssignment:
1334
+ return node instanceof ExportAssignment ? bit((node as ExportAssignment).isExportEquals) << 24 : 0;
1335
+ case SyntaxKind.ExportSpecifier:
1336
+ return node instanceof ExportSpecifier ? bit((node as ExportSpecifier).isTypeOnly) << 24 : 0;
1337
+ case SyntaxKind.PrefixUnaryExpression:
1338
+ return node instanceof PrefixUnaryExpression
1339
+ ? prefixOperatorIndex((node as PrefixUnaryExpression).operator) << 24
1340
+ : 0;
1341
+ case SyntaxKind.PostfixUnaryExpression:
1342
+ return node instanceof PostfixUnaryExpression
1343
+ ? bit((node as PostfixUnaryExpression).operator === SyntaxKind.MinusMinusToken) << 24
1344
+ : 0;
1345
+ case SyntaxKind.MetaProperty:
1346
+ return node instanceof MetaProperty
1347
+ ? bit((node as MetaProperty).keywordToken === SyntaxKind.NewKeyword) << 24
1348
+ : 0;
1349
+ case SyntaxKind.ArrayLiteralExpression:
1350
+ return node instanceof ArrayLiteralExpression ? bit((node as ArrayLiteralExpression).multiLine) << 24 : 0;
1351
+ case SyntaxKind.ObjectLiteralExpression:
1352
+ return node instanceof ObjectLiteralExpression ? bit((node as ObjectLiteralExpression).multiLine) << 24 : 0;
1353
+ case SyntaxKind.TypeOperator:
1354
+ if (!(node instanceof TypeOperatorNode)) return 0;
1355
+ if ((node as TypeOperatorNode).operator === SyntaxKind.ReadonlyKeyword) return 1 << 24;
1356
+ if ((node as TypeOperatorNode).operator === SyntaxKind.UniqueKeyword) return 2 << 24;
1357
+ return 0;
1358
+ case SyntaxKind.ImportAttributes:
1359
+ return node instanceof ImportAttributes
1360
+ ? (bit((node as ImportAttributes).multiLine) << 24) |
1361
+ (bit((node as ImportAttributes).token === SyntaxKind.AssertKeyword) << 25)
1362
+ : 0;
1363
+ case SyntaxKind.JsxText:
1364
+ return node instanceof JsxText ? bit((node as JsxText).containsOnlyTriviaWhiteSpaces) << 24 : 0;
1365
+ case SyntaxKind.ModuleDeclaration:
1366
+ return node instanceof ModuleDeclaration
1367
+ ? bit((node as ModuleDeclaration).keyword === SyntaxKind.NamespaceKeyword) << 24
1368
+ : 0;
1369
+ case SyntaxKind.ImportEqualsDeclaration:
1370
+ return node instanceof ImportEqualsDeclaration ? bit((node as ImportEqualsDeclaration).isTypeOnly) << 24 : 0;
1371
+ case SyntaxKind.ExportDeclaration:
1372
+ return node instanceof ExportDeclaration ? bit((node as ExportDeclaration).isTypeOnly) << 24 : 0;
1373
+ case SyntaxKind.ImportType:
1374
+ return node instanceof ImportTypeNode ? bit((node as ImportTypeNode).isTypeOf) << 24 : 0;
1375
+ case SyntaxKind.ImportClause:
1376
+ if (!(node instanceof ImportClause)) return 0;
1377
+ if ((node as ImportClause).phaseModifier === SyntaxKind.TypeKeyword) return 1 << 24;
1378
+ if ((node as ImportClause).phaseModifier === SyntaxKind.DeferKeyword) return 2 << 24;
1379
+ return 0;
1380
+ case SyntaxKind.ImportSpecifier:
1381
+ return node instanceof ImportSpecifier ? bit((node as ImportSpecifier).isTypeOnly) << 24 : 0;
1382
+ case SyntaxKind.JSDocTypeLiteral:
1383
+ return node instanceof JSDocTypeLiteral ? bit((node as JSDocTypeLiteral).isArrayType) << 24 : 0;
1384
+ case SyntaxKind.JSDocParameterTag:
1385
+ case SyntaxKind.JSDocPropertyTag:
1386
+ return node instanceof JSDocParameterOrPropertyTag
1387
+ ? (bit((node as JSDocParameterOrPropertyTag).isBracketed) << 24) |
1388
+ (bit((node as JSDocParameterOrPropertyTag).isNameFirst) << 25)
1389
+ : 0;
1390
+ }
1391
+ return 0;
1392
+ }
1393
+
1394
+ function prefixOperatorIndex(operator: SyntaxKind): number {
1395
+ switch (operator) {
1396
+ case SyntaxKind.MinusToken:
1397
+ return 1;
1398
+ case SyntaxKind.TildeToken:
1399
+ return 2;
1400
+ case SyntaxKind.ExclamationToken:
1401
+ return 3;
1402
+ case SyntaxKind.PlusPlusToken:
1403
+ return 4;
1404
+ case SyntaxKind.MinusMinusToken:
1405
+ return 5;
1406
+ }
1407
+ return 0;
1408
+ }
1409
+
1410
+ function dataType(kind: SyntaxKind): number {
1411
+ switch (kind) {
1412
+ case SyntaxKind.Identifier:
1413
+ case SyntaxKind.PrivateIdentifier:
1414
+ case SyntaxKind.JsxText:
1415
+ case SyntaxKind.JSDocText:
1416
+ case SyntaxKind.JSDocLink:
1417
+ case SyntaxKind.JSDocLinkPlain:
1418
+ case SyntaxKind.JSDocLinkCode:
1419
+ return dataTypeString;
1420
+ case SyntaxKind.StringLiteral:
1421
+ case SyntaxKind.NumericLiteral:
1422
+ case SyntaxKind.BigIntLiteral:
1423
+ case SyntaxKind.RegularExpressionLiteral:
1424
+ case SyntaxKind.NoSubstitutionTemplateLiteral:
1425
+ case SyntaxKind.TemplateHead:
1426
+ case SyntaxKind.TemplateMiddle:
1427
+ case SyntaxKind.TemplateTail:
1428
+ case SyntaxKind.SourceFile:
1429
+ return dataTypeExtended;
1430
+ }
1431
+ return dataTypeChildren;
1432
+ }
1433
+
1434
+ /** The text of a node encoded as a string. */
1435
+ function nodeText(node: Node): string {
1436
+ if (node instanceof Identifier) return (node as Identifier).text;
1437
+ if (node instanceof PrivateIdentifier) return (node as PrivateIdentifier).text;
1438
+ if (node instanceof JsxText) return (node as JsxText).text;
1439
+ if (node instanceof JSDocText) return (node as JSDocText).text;
1440
+ if (node instanceof JSDocLink) return (node as JSDocLink).text;
1441
+ if (node instanceof JSDocLinkPlain) return (node as JSDocLinkPlain).text;
1442
+ if (node instanceof JSDocLinkCode) return (node as JSDocLinkCode).text;
1443
+ return '';
1444
+ }
1445
+
1446
+ function writeArrayHeader(out: ByteWriter, length: number): void {
1447
+ if (length <= 0x0f) out.u8(0x90 | length);
1448
+ else if (length <= 0xffff) {
1449
+ out.u8(0xdc);
1450
+ out.be(length, 2);
1451
+ } else {
1452
+ out.u8(0xdd);
1453
+ out.be(length, 4);
1454
+ }
1455
+ }
1456
+
1457
+ function writeUint(out: ByteWriter, value: number): void {
1458
+ if (value <= 0x7f) out.u8(value);
1459
+ else if (value <= 0xff) {
1460
+ out.u8(0xcc);
1461
+ out.u8(value);
1462
+ } else if (value <= 0xffff) {
1463
+ out.u8(0xcd);
1464
+ out.be(value, 2);
1465
+ } else {
1466
+ out.u8(0xce);
1467
+ out.be(value, 4);
1468
+ }
1469
+ }
1470
+
1471
+ function writeString(out: ByteWriter, text: string): void {
1472
+ const bytes = encodeUTF8(text);
1473
+ const n = bytes.length;
1474
+ if (n <= 0x1f) out.u8(0xa0 | n);
1475
+ else if (n <= 0xff) {
1476
+ out.u8(0xd9);
1477
+ out.u8(n);
1478
+ } else if (n <= 0xffff) {
1479
+ out.u8(0xda);
1480
+ out.be(n, 2);
1481
+ } else {
1482
+ out.u8(0xdb);
1483
+ out.be(n, 4);
1484
+ }
1485
+ out.append(bytes);
1486
+ }
1487
+
1488
+ function writeFileReferences(out: ByteWriter, refs: readonly FileReference[]): number {
1489
+ if (refs.length === 0) return noStructuredData;
1490
+ const offset = out.length;
1491
+ writeArrayHeader(out, refs.length);
1492
+ for (const ref of refs) {
1493
+ writeArrayHeader(out, 5);
1494
+ writeUint(out, ref.pos);
1495
+ writeUint(out, ref.end);
1496
+ writeString(out, ref.fileName);
1497
+ writeUint(out, ref.resolutionMode);
1498
+ out.u8(ref.preserve ? 0xc3 : 0xc2);
1499
+ }
1500
+ return offset;
1501
+ }
1502
+
1503
+ /** Walks the tree in the API's order and writes node records. */
1504
+ class Encoder extends NodeVisitor {
1505
+ /** The file whose JSDoc comments are encoded, if any. */
1506
+ readonly file: SourceFile | undefined;
1507
+ readonly strings: StringTable;
1508
+ readonly nodes: NodeRecords;
1509
+ readonly extended: ByteWriter;
1510
+ readonly structured: ByteWriter;
1511
+ /** Node indices of imports, module augmentations and the external module indicator. */
1512
+ readonly tracked: Map<Node, number>;
1513
+ /** Whether a node of each kind is tracked (`track`), so that other nodes need no lookup. */
1514
+ private readonly trackedKinds = new Uint8Array(512);
1515
+ nodeCount: number;
1516
+ parentIndex: number;
1517
+ prevIndex: number;
1518
+ /** For a node outside a parsed file whose positions are in another file's text, that text's UTF-8 offsets. */
1519
+ positions: Utf8Positions | undefined = undefined;
1520
+
1521
+ constructor(file: SourceFile | undefined, text: string, fileText: Uint8Array, nodeCount: number) {
1522
+ super();
1523
+ this.file = file;
1524
+ this.strings = new StringTable(text, fileText);
1525
+ this.nodes = new NodeRecords(nodeCount + 2);
1526
+ this.extended = new ByteWriter(256);
1527
+ this.structured = new ByteWriter(64);
1528
+ this.tracked = new Map<Node, number>();
1529
+ this.nodeCount = 0;
1530
+ this.parentIndex = 0;
1531
+ this.prevIndex = 0;
1532
+ }
1533
+
1534
+ /** Records the index `node` gets (`tracked`). */
1535
+ track(node: Node): void {
1536
+ this.tracked.set(node, 0);
1537
+ this.trackedKinds[node.kind] = 1;
1538
+ }
1539
+
1540
+ /** Points the previous sibling's `next` at the record about to be written. */
1541
+ private linkSibling(index: number): void {
1542
+ if (this.prevIndex !== 0) this.nodes.setNext(this.prevIndex, index);
1543
+ }
1544
+
1545
+ visitNode(node: Node): boolean {
1546
+ const index = ++this.nodeCount;
1547
+ this.linkSibling(index);
1548
+ const positions = this.positions;
1549
+ if (positions === undefined)
1550
+ this.nodes.push(node.kind, node.pos, node.end, this.parentIndex, this.nodeData(node), node.flags);
1551
+ else
1552
+ this.nodes.push(
1553
+ node.kind,
1554
+ positions.of(node.pos),
1555
+ positions.of(node.end),
1556
+ this.parentIndex,
1557
+ this.nodeData(node),
1558
+ node.flags,
1559
+ );
1560
+ if (this.trackedKinds[node.kind] === 1 && this.tracked.has(node)) this.tracked.set(node, index);
1561
+ const saveParent = this.parentIndex;
1562
+ this.prevIndex = 0;
1563
+ this.parentIndex = index;
1564
+ this.visitChildren(node);
1565
+ this.prevIndex = index;
1566
+ this.parentIndex = saveParent;
1567
+ return false;
1568
+ }
1569
+
1570
+ visitList(list: NodeList): boolean {
1571
+ const index = ++this.nodeCount;
1572
+ this.linkSibling(index);
1573
+ const positions = this.positions;
1574
+ if (positions === undefined)
1575
+ this.nodes.push(nodeListKind, list.pos, list.end, this.parentIndex, list.nodes.length, 0);
1576
+ else
1577
+ this.nodes.push(
1578
+ nodeListKind,
1579
+ positions.of(list.pos),
1580
+ positions.of(list.end),
1581
+ this.parentIndex,
1582
+ list.nodes.length,
1583
+ 0,
1584
+ );
1585
+ const saveParent = this.parentIndex;
1586
+ this.prevIndex = 0;
1587
+ this.parentIndex = index;
1588
+ const nodes = list.nodes;
1589
+ for (let i = 0; i < nodes.length; i++) this.visitNode(nodes[i]!);
1590
+ this.prevIndex = index;
1591
+ this.parentIndex = saveParent;
1592
+ return false;
1593
+ }
1594
+
1595
+ visitModifiers(list: ModifierList): boolean {
1596
+ if (list.nodes.length > 0) this.visitList(list);
1597
+ return false;
1598
+ }
1599
+
1600
+ /** The children in the API's order, then the node's JSDoc comments. */
1601
+ visitChildren(node: Node): boolean {
1602
+ if (node instanceof JSDocParameterOrPropertyTag) {
1603
+ const tag = node as JSDocParameterOrPropertyTag;
1604
+ this.visitNode(tag.tagName);
1605
+ this.visitNode(tag.name);
1606
+ if (tag.typeExpression !== undefined) this.visitNode(tag.typeExpression);
1607
+ if (tag.comment !== undefined) this.visitList(tag.comment);
1608
+ } else node.forEachChild(this);
1609
+ const file = this.file;
1610
+ if (file !== undefined) {
1611
+ const jsDoc = getJSDoc(file, node);
1612
+ for (let i = 0; i < jsDoc.length; i++) this.visitNode(jsDoc[i]!);
1613
+ }
1614
+ return false;
1615
+ }
1616
+
1617
+ /** Writes the nil record and the root, then the root's descendants. */
1618
+ encodeRoot(root: Node): void {
1619
+ const nodes = this.nodes;
1620
+ nodes.push(0, 0, 0, 0, 0, 0);
1621
+ this.nodeCount = 1;
1622
+ this.parentIndex = 1;
1623
+ const positions = this.positions;
1624
+ nodes.push(
1625
+ root.kind,
1626
+ positions === undefined ? root.pos : positions.of(root.pos),
1627
+ positions === undefined ? root.end : positions.of(root.end),
1628
+ 0,
1629
+ this.nodeData(root),
1630
+ root.flags,
1631
+ );
1632
+ this.visitChildren(root);
1633
+ }
1634
+
1635
+ /** The encoding: header, string table, extended and structured data, then node records. */
1636
+ finish(fileText: Uint8Array, hash: Uint8Array | undefined, parseOptions: number): Uint8Array {
1637
+ const strings = this.strings;
1638
+ const extended = this.extended;
1639
+ const structured = this.structured;
1640
+ const nodes = this.nodes;
1641
+ const offsetStringOffsets = headerSize;
1642
+ const offsetStringData = offsetStringOffsets + strings.offsets.length;
1643
+ const offsetExtended = offsetStringData + fileText.length + strings.others.length;
1644
+ const offsetStructured = offsetExtended + extended.length;
1645
+ const offsetNodes = offsetStructured + structured.length;
1646
+
1647
+ const out = new ByteWriter(offsetNodes + nodes.length);
1648
+ out.u32((protocolVersion << 24) >>> 0);
1649
+ if (hash !== undefined) out.append(hash);
1650
+ else for (let i = 0; i < 4; i++) out.u32(0);
1651
+ out.u32(parseOptions);
1652
+ out.u32(offsetStringOffsets);
1653
+ out.u32(offsetStringData);
1654
+ out.u32(offsetExtended);
1655
+ out.u32(offsetStructured);
1656
+ out.u32(offsetNodes);
1657
+ out.append(strings.offsets.view());
1658
+ out.append(fileText);
1659
+ out.append(strings.others.view());
1660
+ out.append(extended.view());
1661
+ out.append(structured.view());
1662
+ out.append(nodes.view());
1663
+ return out.view();
1664
+ }
1665
+
1666
+ nodeData(node: Node): number {
1667
+ const type = dataType(node.kind);
1668
+ const common = commonData(node);
1669
+ if (type === dataTypeChildren) return (type | common | childrenPropertyMask(node)) >>> 0;
1670
+ if (type === dataTypeString)
1671
+ return (type | common | this.strings.add(nodeText(node), node.kind, node.pos, node.end)) >>> 0;
1672
+ return (type | common | this.extendedData(node)) >>> 0;
1673
+ }
1674
+
1675
+ /** Writes the node's extended data and returns its offset. */
1676
+ extendedData(node: Node): number {
1677
+ const out = this.extended;
1678
+ const offset = out.length;
1679
+ const strings = this.strings;
1680
+ if (node instanceof StringLiteral) {
1681
+ out.u32(
1682
+ strings.add(
1683
+ (node as StringLiteral).text,
1684
+ (node as StringLiteral).kind,
1685
+ (node as StringLiteral).pos,
1686
+ (node as StringLiteral).end,
1687
+ ),
1688
+ );
1689
+ out.u32((node as StringLiteral).tokenFlags);
1690
+ } else if (node instanceof NumericLiteral) {
1691
+ out.u32(
1692
+ strings.add(
1693
+ (node as NumericLiteral).text,
1694
+ (node as NumericLiteral).kind,
1695
+ (node as NumericLiteral).pos,
1696
+ (node as NumericLiteral).end,
1697
+ ),
1698
+ );
1699
+ out.u32((node as NumericLiteral).tokenFlags);
1700
+ } else if (node instanceof BigIntLiteral) {
1701
+ out.u32(
1702
+ strings.add(
1703
+ (node as BigIntLiteral).text,
1704
+ (node as BigIntLiteral).kind,
1705
+ (node as BigIntLiteral).pos,
1706
+ (node as BigIntLiteral).end,
1707
+ ),
1708
+ );
1709
+ out.u32((node as BigIntLiteral).tokenFlags);
1710
+ } else if (node instanceof RegularExpressionLiteral) {
1711
+ out.u32(
1712
+ strings.add(
1713
+ (node as RegularExpressionLiteral).text,
1714
+ (node as RegularExpressionLiteral).kind,
1715
+ (node as RegularExpressionLiteral).pos,
1716
+ (node as RegularExpressionLiteral).end,
1717
+ ),
1718
+ );
1719
+ out.u32((node as RegularExpressionLiteral).tokenFlags);
1720
+ } else if (node instanceof NoSubstitutionTemplateLiteral) {
1721
+ out.u32(
1722
+ strings.add(
1723
+ (node as NoSubstitutionTemplateLiteral).text,
1724
+ (node as NoSubstitutionTemplateLiteral).kind,
1725
+ (node as NoSubstitutionTemplateLiteral).pos,
1726
+ (node as NoSubstitutionTemplateLiteral).end,
1727
+ ),
1728
+ );
1729
+ out.u32((node as NoSubstitutionTemplateLiteral).templateFlags);
1730
+ } else if (node instanceof TemplateHead) {
1731
+ out.u32(
1732
+ strings.add(
1733
+ (node as TemplateHead).text,
1734
+ (node as TemplateHead).kind,
1735
+ (node as TemplateHead).pos,
1736
+ (node as TemplateHead).end,
1737
+ ),
1738
+ );
1739
+ out.u32(
1740
+ strings.add(
1741
+ (node as TemplateHead).rawText,
1742
+ (node as TemplateHead).kind,
1743
+ (node as TemplateHead).pos,
1744
+ (node as TemplateHead).end,
1745
+ ),
1746
+ );
1747
+ out.u32((node as TemplateHead).templateFlags);
1748
+ } else if (node instanceof TemplateMiddle) {
1749
+ out.u32(
1750
+ strings.add(
1751
+ (node as TemplateMiddle).text,
1752
+ (node as TemplateMiddle).kind,
1753
+ (node as TemplateMiddle).pos,
1754
+ (node as TemplateMiddle).end,
1755
+ ),
1756
+ );
1757
+ out.u32(
1758
+ strings.add(
1759
+ (node as TemplateMiddle).rawText,
1760
+ (node as TemplateMiddle).kind,
1761
+ (node as TemplateMiddle).pos,
1762
+ (node as TemplateMiddle).end,
1763
+ ),
1764
+ );
1765
+ out.u32((node as TemplateMiddle).templateFlags);
1766
+ } else if (node instanceof TemplateTail) {
1767
+ out.u32(
1768
+ strings.add(
1769
+ (node as TemplateTail).text,
1770
+ (node as TemplateTail).kind,
1771
+ (node as TemplateTail).pos,
1772
+ (node as TemplateTail).end,
1773
+ ),
1774
+ );
1775
+ out.u32(
1776
+ strings.add(
1777
+ (node as TemplateTail).rawText,
1778
+ (node as TemplateTail).kind,
1779
+ (node as TemplateTail).pos,
1780
+ (node as TemplateTail).end,
1781
+ ),
1782
+ );
1783
+ out.u32((node as TemplateTail).templateFlags);
1784
+ } else if (node instanceof SourceFile) {
1785
+ out.u32(strings.addFileText((node as SourceFile).pos, (node as SourceFile).end));
1786
+ out.u32(strings.add((node as SourceFile).fileName, SyntaxKind.Unknown, 0, 0));
1787
+ out.u32(strings.add((node as SourceFile).path, SyntaxKind.Unknown, 0, 0));
1788
+ out.u32((node as SourceFile).languageVariant);
1789
+ out.u32((node as SourceFile).scriptKind);
1790
+ out.u32(writeFileReferences(this.structured, (node as SourceFile).referencedFiles));
1791
+ out.u32(writeFileReferences(this.structured, (node as SourceFile).typeReferenceDirectives));
1792
+ out.u32(writeFileReferences(this.structured, (node as SourceFile).libReferenceDirectives));
1793
+ // Imports, module augmentations, ambient module names and the external module
1794
+ // indicator are patched in after the walk.
1795
+ out.u32(noStructuredData);
1796
+ out.u32(noStructuredData);
1797
+ out.u32(noStructuredData);
1798
+ out.u32(0);
1799
+ } else throw new Error(`no extended data for kind ${node.kind}`);
1800
+ return offset;
1801
+ }
1802
+
1803
+ writeNodeIndices(nodes: readonly Node[]): number {
1804
+ if (nodes.length === 0) return noStructuredData;
1805
+ const out = this.structured;
1806
+ const offset = out.length;
1807
+ writeArrayHeader(out, nodes.length);
1808
+ for (const node of nodes) {
1809
+ const index = this.tracked.get(node);
1810
+ writeUint(out, index === undefined ? 0 : index);
1811
+ }
1812
+ return offset;
1813
+ }
1814
+
1815
+ writeStrings(strings: readonly string[]): number {
1816
+ if (strings.length === 0) return noStructuredData;
1817
+ const out = this.structured;
1818
+ const offset = out.length;
1819
+ writeArrayHeader(out, strings.length);
1820
+ for (const text of strings) writeString(out, text);
1821
+ return offset;
1822
+ }
1823
+ }
1824
+
1825
+ /** The UTF-8 offsets of a text's UTF-16 offsets, computed when first needed. */
1826
+ class Utf8Positions {
1827
+ private offsets: Int32Array | undefined = undefined;
1828
+ private ascii = false;
1829
+
1830
+ constructor(private readonly text: string) {}
1831
+
1832
+ /** The UTF-8 offset of UTF-16 offset `pos`; a negative position is unchanged. */
1833
+ of(pos: number): number {
1834
+ if (pos < 0 || this.ascii) return pos;
1835
+ let offsets = this.offsets;
1836
+ if (offsets === undefined) {
1837
+ if (!/[\u0080-\uffff]/.test(this.text)) {
1838
+ this.ascii = true;
1839
+ return pos;
1840
+ }
1841
+ offsets = this.offsets = utf8Offsets(this.text);
1842
+ }
1843
+ return pos >= offsets.length ? pos : offsets[pos]!;
1844
+ }
1845
+ }
1846
+
1847
+ /** The API's binary encoding of `file`. */
1848
+ export function encodeSourceFile(file: SourceFile): Uint8Array {
1849
+ const fileText = utf8Encoder.encode(file.text);
1850
+ const encoder = new Encoder(file, file.text, fileText, file.nodeCount);
1851
+ const tracked = encoder.tracked;
1852
+ for (const node of file.imports) encoder.track(node);
1853
+ for (const node of file.moduleAugmentations) encoder.track(node);
1854
+ const indicator = file.externalModuleIndicator;
1855
+ if (indicator !== undefined && indicator !== file) encoder.track(indicator);
1856
+
1857
+ // The root's extended data starts its section.
1858
+ encoder.encodeRoot(file);
1859
+
1860
+ const extended = encoder.extended;
1861
+ extended.setU32(32, encoder.writeNodeIndices(file.imports));
1862
+ extended.setU32(36, encoder.writeNodeIndices(file.moduleAugmentations));
1863
+ extended.setU32(40, encoder.writeStrings(file.ambientModuleNames));
1864
+ let indicatorIndex = 0;
1865
+ if (indicator === file) indicatorIndex = 1;
1866
+ else if (indicator !== undefined) {
1867
+ const index = tracked.get(indicator);
1868
+ if (index !== undefined) indicatorIndex = index;
1869
+ }
1870
+ extended.setU32(44, indicatorIndex);
1871
+
1872
+ const options = file.externalModuleIndicatorOptions;
1873
+ return encoder.finish(fileText, hash128(fileText), (options.jsx ? 1 : 0) | (options.force ? 2 : 0));
1874
+ }
1875
+
1876
+ /**
1877
+ * The nodes of a source file by their index in its encoding, which node handles name. Node lists
1878
+ * take an index but have no entry.
1879
+ */
1880
+ export class NodeIndexTable extends NodeVisitor {
1881
+ /** Index 0 is the nil node and index 1 the file. */
1882
+ readonly nodes: (Node | undefined)[];
1883
+ private readonly indices = new Map<Node, number>();
1884
+
1885
+ constructor(readonly file: SourceFile) {
1886
+ super();
1887
+ this.nodes = [undefined];
1888
+ this.add(file);
1889
+ this.visitChildren(file);
1890
+ }
1891
+
1892
+ /** The index of `node`, or 0 if it isn't in the file. */
1893
+ indexOf(node: Node): number {
1894
+ return this.indices.get(node) ?? 0;
1895
+ }
1896
+
1897
+ private add(node: Node): void {
1898
+ this.indices.set(node, this.nodes.length);
1899
+ this.nodes.push(node);
1900
+ }
1901
+
1902
+ visitNode(node: Node): boolean {
1903
+ this.add(node);
1904
+ this.visitChildren(node);
1905
+ return false;
1906
+ }
1907
+
1908
+ visitList(list: NodeList): boolean {
1909
+ this.nodes.push(undefined);
1910
+ const nodes = list.nodes;
1911
+ for (let i = 0; i < nodes.length; i++) this.visitNode(nodes[i]!);
1912
+ return false;
1913
+ }
1914
+
1915
+ visitModifiers(list: ModifierList): boolean {
1916
+ if (list.nodes.length > 0) this.visitList(list);
1917
+ return false;
1918
+ }
1919
+
1920
+ /** The same order as the encoder's. */
1921
+ private visitChildren(node: Node): void {
1922
+ if (node instanceof JSDocParameterOrPropertyTag) {
1923
+ const tag = node as JSDocParameterOrPropertyTag;
1924
+ this.visitNode(tag.tagName);
1925
+ this.visitNode(tag.name);
1926
+ if (tag.typeExpression !== undefined) this.visitNode(tag.typeExpression);
1927
+ if (tag.comment !== undefined) this.visitList(tag.comment);
1928
+ } else node.forEachChild(this);
1929
+ const jsDoc = getJSDoc(this.file, node);
1930
+ for (let i = 0; i < jsDoc.length; i++) this.visitNode(jsDoc[i]!);
1931
+ }
1932
+ }
1933
+
1934
+ /**
1935
+ * The encoding of a node that isn't part of a parsed file, such as one the node builder created:
1936
+ * no hash, parse options or JSDoc, and every string appended to the string data. The positions its
1937
+ * nodes have are in `positionsFile`, if given; as in tsgo, they are encoded as UTF-8 offsets in its text.
1938
+ */
1939
+ export function encodeNode(node: Node, positionsFile?: SourceFile): Uint8Array {
1940
+ const fileText = new Uint8Array(0);
1941
+ const encoder = new Encoder(undefined, '', fileText, 64);
1942
+ if (positionsFile !== undefined) encoder.positions = new Utf8Positions(positionsFile.text);
1943
+ encoder.encodeRoot(node);
1944
+ return encoder.finish(fileText, undefined, 0);
1945
+ }