@whaaaley/crush 0.0.0-stage → 0.2.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 (358) hide show
  1. package/LICENSE +32 -0
  2. package/README.md +185 -2
  3. package/SKILL.md +187 -0
  4. package/THIRD_PARTY_NOTICES.md +277 -0
  5. package/dist/capture/capture.operations.d.ts +23 -0
  6. package/dist/capture/capture.operations.js +231 -0
  7. package/dist/capture/capture.schema.d.ts +73 -0
  8. package/dist/capture/capture.schema.js +28 -0
  9. package/dist/collapse/collapse.operations.d.ts +2 -0
  10. package/dist/collapse/collapse.operations.js +82 -0
  11. package/dist/collapse/collapse.schema.d.ts +40 -0
  12. package/dist/collapse/collapse.schema.js +35 -0
  13. package/dist/crush.tables.d.ts +3583 -0
  14. package/dist/crush.tables.js +456 -0
  15. package/dist/crushes/callback.crush.d.ts +2 -0
  16. package/dist/crushes/callback.crush.js +19 -0
  17. package/dist/crushes/crush.d.ts +36 -0
  18. package/dist/crushes/crush.js +12 -0
  19. package/dist/crushes/crush.names.d.ts +1 -0
  20. package/dist/crushes/crush.names.js +2 -0
  21. package/dist/crushes/crushes.d.ts +2 -0
  22. package/dist/crushes/crushes.js +9 -0
  23. package/dist/crushes/default-value.crush.d.ts +2 -0
  24. package/dist/crushes/default-value.crush.js +29 -0
  25. package/dist/crushes/drop-operand.crush.d.ts +2 -0
  26. package/dist/crushes/drop-operand.crush.js +37 -0
  27. package/dist/crushes/fold.d.ts +64 -0
  28. package/dist/crushes/fold.js +366 -0
  29. package/dist/crushes/force-fork.crush.d.ts +2 -0
  30. package/dist/crushes/force-fork.crush.js +79 -0
  31. package/dist/crushes/loop-once.crush.d.ts +2 -0
  32. package/dist/crushes/loop-once.crush.js +71 -0
  33. package/dist/crushes/optional-chain.crush.d.ts +2 -0
  34. package/dist/crushes/optional-chain.crush.js +30 -0
  35. package/dist/crushes/switch-case.crush.d.ts +2 -0
  36. package/dist/crushes/switch-case.crush.js +19 -0
  37. package/dist/decisions/decide.d.ts +61 -0
  38. package/dist/decisions/decide.js +161 -0
  39. package/dist/decisions/decisions.d.ts +24 -0
  40. package/dist/decisions/decisions.js +62 -0
  41. package/dist/decisions/forks.decision.d.ts +4 -0
  42. package/dist/decisions/forks.decision.js +32 -0
  43. package/dist/decisions/kinds.d.ts +101 -0
  44. package/dist/decisions/kinds.js +38 -0
  45. package/dist/decisions/loops.decision.d.ts +4 -0
  46. package/dist/decisions/loops.decision.js +39 -0
  47. package/dist/decisions/shorts.decision.d.ts +3 -0
  48. package/dist/decisions/shorts.decision.js +66 -0
  49. package/dist/decisions/switches.decision.d.ts +3 -0
  50. package/dist/decisions/switches.decision.js +20 -0
  51. package/dist/decisions/throws.decision.d.ts +3 -0
  52. package/dist/decisions/throws.decision.js +35 -0
  53. package/dist/decisions/values.decision.d.ts +3 -0
  54. package/dist/decisions/values.decision.js +67 -0
  55. package/dist/explore/edges/explore.d.ts +60 -0
  56. package/dist/explore/edges/explore.db.d.ts +22 -0
  57. package/dist/explore/edges/explore.db.js +55 -0
  58. package/dist/explore/edges/explore.js +305 -0
  59. package/dist/explore/edges/random.d.ts +2 -0
  60. package/dist/explore/edges/random.js +32 -0
  61. package/dist/explore/explore.operations.d.ts +30 -0
  62. package/dist/explore/explore.operations.js +117 -0
  63. package/dist/explore/limits.operations.d.ts +14 -0
  64. package/dist/explore/limits.operations.js +20 -0
  65. package/dist/explore/targets.operations.d.ts +36 -0
  66. package/dist/explore/targets.operations.js +32 -0
  67. package/dist/explore/utils/draws.d.ts +6 -0
  68. package/dist/explore/utils/draws.js +2 -0
  69. package/dist/explore/utils/edits.d.ts +15 -0
  70. package/dist/explore/utils/edits.js +151 -0
  71. package/dist/explore/utils/guide.d.ts +23 -0
  72. package/dist/explore/utils/guide.js +35 -0
  73. package/dist/explore/utils/keep.d.ts +10 -0
  74. package/dist/explore/utils/keep.js +61 -0
  75. package/dist/explore/utils/pools.d.ts +17 -0
  76. package/dist/explore/utils/pools.js +121 -0
  77. package/dist/explore/utils/reads.d.ts +19 -0
  78. package/dist/explore/utils/reads.js +118 -0
  79. package/dist/explore/utils/twin.d.ts +21 -0
  80. package/dist/explore/utils/twin.js +55 -0
  81. package/dist/forks/forks.operations.d.ts +32 -0
  82. package/dist/forks/forks.operations.js +134 -0
  83. package/dist/forks/forks.schema.d.ts +20 -0
  84. package/dist/forks/forks.schema.js +14 -0
  85. package/dist/graph/cfg/cfg.d.ts +28 -0
  86. package/dist/graph/cfg/cfg.js +31 -0
  87. package/dist/graph/cfg/code-paths/analyzer.d.ts +27 -0
  88. package/dist/graph/cfg/code-paths/analyzer.js +358 -0
  89. package/dist/graph/cfg/code-paths/segments.d.ts +44 -0
  90. package/dist/graph/cfg/code-paths/segments.js +105 -0
  91. package/dist/graph/cfg/code-paths/state.d.ts +121 -0
  92. package/dist/graph/cfg/code-paths/state.js +611 -0
  93. package/dist/graph/cfg/entries.d.ts +13 -0
  94. package/dist/graph/cfg/entries.js +120 -0
  95. package/dist/graph/cfg/functions.d.ts +6 -0
  96. package/dist/graph/cfg/functions.js +47 -0
  97. package/dist/graph/cfg/paths.d.ts +27 -0
  98. package/dist/graph/cfg/paths.js +91 -0
  99. package/dist/graph/cfg/scopes/scopes.d.ts +40 -0
  100. package/dist/graph/cfg/scopes/scopes.js +375 -0
  101. package/dist/graph/symbols/file.d.ts +90 -0
  102. package/dist/graph/symbols/file.js +427 -0
  103. package/dist/graph/symbols/keys.d.ts +13 -0
  104. package/dist/graph/symbols/keys.js +22 -0
  105. package/dist/graph/symbols/resolve.operations.d.ts +4 -0
  106. package/dist/graph/symbols/resolve.operations.js +33 -0
  107. package/dist/graph/symbols/symbols.d.ts +12 -0
  108. package/dist/graph/symbols/symbols.js +155 -0
  109. package/dist/graph/symbols/symbols.schema.d.ts +32 -0
  110. package/dist/graph/symbols/symbols.schema.js +19 -0
  111. package/dist/graph/unused/tests.d.ts +7 -0
  112. package/dist/graph/unused/tests.js +95 -0
  113. package/dist/graph/unused/unused.d.ts +53 -0
  114. package/dist/graph/unused/unused.js +319 -0
  115. package/dist/graph/walk/walk.d.ts +7 -0
  116. package/dist/graph/walk/walk.js +39 -0
  117. package/dist/instrument/instrument.operations.d.ts +72 -0
  118. package/dist/instrument/instrument.operations.js +786 -0
  119. package/dist/instrument/instrument.schema.d.ts +257 -0
  120. package/dist/instrument/instrument.schema.js +100 -0
  121. package/dist/judge/counters.d.ts +86 -0
  122. package/dist/judge/counters.js +402 -0
  123. package/dist/judge/edges/api.d.ts +14 -0
  124. package/dist/judge/edges/api.js +80 -0
  125. package/dist/judge/edges/completion.reporter.d.ts +9 -0
  126. package/dist/judge/edges/completion.reporter.js +51 -0
  127. package/dist/judge/edges/hints.reporter.d.ts +13 -0
  128. package/dist/judge/edges/hints.reporter.js +29 -0
  129. package/dist/judge/edges/judge.edges.d.ts +52 -0
  130. package/dist/judge/edges/judge.edges.js +59 -0
  131. package/dist/judge/edges/judge.fs.d.ts +8 -0
  132. package/dist/judge/edges/judge.fs.js +45 -0
  133. package/dist/judge/edges/merge.d.ts +11 -0
  134. package/dist/judge/edges/merge.js +60 -0
  135. package/dist/judge/edges/plugin.d.ts +132 -0
  136. package/dist/judge/edges/plugin.js +441 -0
  137. package/dist/judge/edges/reach.d.ts +68 -0
  138. package/dist/judge/edges/reach.js +132 -0
  139. package/dist/judge/edges/speed.d.ts +32 -0
  140. package/dist/judge/edges/speed.js +34 -0
  141. package/dist/judge/edges/strays.d.ts +1 -0
  142. package/dist/judge/edges/strays.js +14 -0
  143. package/dist/judge/edges/vitest.d.ts +20 -0
  144. package/dist/judge/edges/vitest.js +36 -0
  145. package/dist/judge/edges/vitest.schema.d.ts +14 -0
  146. package/dist/judge/edges/vitest.schema.js +16 -0
  147. package/dist/judge/explore.test.d.ts +1 -0
  148. package/dist/judge/explore.test.js +101 -0
  149. package/dist/judge/hints.d.ts +11 -0
  150. package/dist/judge/hints.js +44 -0
  151. package/dist/judge/judge.operations.d.ts +218 -0
  152. package/dist/judge/judge.operations.js +464 -0
  153. package/dist/judge/judge.schema.d.ts +135 -0
  154. package/dist/judge/judge.schema.js +129 -0
  155. package/dist/judge/judge.shard-1.test.d.ts +1 -0
  156. package/dist/judge/judge.shard-1.test.js +3 -0
  157. package/dist/judge/judge.shard-2.test.d.ts +1 -0
  158. package/dist/judge/judge.shard-2.test.js +3 -0
  159. package/dist/judge/judge.test.d.ts +1 -0
  160. package/dist/judge/judge.test.js +3 -0
  161. package/dist/judge/refusals.d.ts +14 -0
  162. package/dist/judge/refusals.js +10 -0
  163. package/dist/judge/report.test.d.ts +1 -0
  164. package/dist/judge/report.test.js +432 -0
  165. package/dist/judge/runner.d.ts +3 -0
  166. package/dist/judge/runner.js +1602 -0
  167. package/dist/judge/stresses.test.d.ts +1 -0
  168. package/dist/judge/stresses.test.js +12 -0
  169. package/dist/judge/task-meta.d.ts +51 -0
  170. package/dist/judge/task-meta.js +3 -0
  171. package/dist/justify/edges/load.d.ts +7 -0
  172. package/dist/justify/edges/load.js +40 -0
  173. package/dist/justify/edges/refresh.fs.d.ts +8 -0
  174. package/dist/justify/edges/refresh.fs.js +15 -0
  175. package/dist/justify/justify.operations.d.ts +46 -0
  176. package/dist/justify/justify.operations.js +80 -0
  177. package/dist/justify/justify.schema.d.ts +21 -0
  178. package/dist/justify/justify.schema.js +11 -0
  179. package/dist/mutators/arithmetic-operator.mutator.d.ts +2 -0
  180. package/dist/mutators/arithmetic-operator.mutator.js +22 -0
  181. package/dist/mutators/array-declaration.mutator.d.ts +2 -0
  182. package/dist/mutators/array-declaration.mutator.js +12 -0
  183. package/dist/mutators/arrow-function.mutator.d.ts +2 -0
  184. package/dist/mutators/arrow-function.mutator.js +10 -0
  185. package/dist/mutators/assignment-operator.mutator.d.ts +2 -0
  186. package/dist/mutators/assignment-operator.mutator.js +29 -0
  187. package/dist/mutators/await-expression.mutator.d.ts +2 -0
  188. package/dist/mutators/await-expression.mutator.js +7 -0
  189. package/dist/mutators/bitwise-operator.mutator.d.ts +2 -0
  190. package/dist/mutators/bitwise-operator.mutator.js +19 -0
  191. package/dist/mutators/block-statement.mutator.d.ts +2 -0
  192. package/dist/mutators/block-statement.mutator.js +30 -0
  193. package/dist/mutators/boolean-literal.mutator.d.ts +2 -0
  194. package/dist/mutators/boolean-literal.mutator.js +5 -0
  195. package/dist/mutators/coercion.mutator.d.ts +2 -0
  196. package/dist/mutators/coercion.mutator.js +28 -0
  197. package/dist/mutators/conditional-expression.mutator.d.ts +2 -0
  198. package/dist/mutators/conditional-expression.mutator.js +36 -0
  199. package/dist/mutators/disposal.mutator.d.ts +2 -0
  200. package/dist/mutators/disposal.mutator.js +13 -0
  201. package/dist/mutators/empty-destructuring.mutator.d.ts +2 -0
  202. package/dist/mutators/empty-destructuring.mutator.js +35 -0
  203. package/dist/mutators/empty-return.mutator.d.ts +2 -0
  204. package/dist/mutators/empty-return.mutator.js +35 -0
  205. package/dist/mutators/equality-operator.mutator.d.ts +2 -0
  206. package/dist/mutators/equality-operator.mutator.js +16 -0
  207. package/dist/mutators/loop-exit.mutator.d.ts +2 -0
  208. package/dist/mutators/loop-exit.mutator.js +5 -0
  209. package/dist/mutators/method-expression.mutator.d.ts +2 -0
  210. package/dist/mutators/method-expression.mutator.js +59 -0
  211. package/dist/mutators/missing-lookup.mutator.d.ts +2 -0
  212. package/dist/mutators/missing-lookup.mutator.js +25 -0
  213. package/dist/mutators/mutator.d.ts +40 -0
  214. package/dist/mutators/mutator.js +49 -0
  215. package/dist/mutators/mutator.names.d.ts +3 -0
  216. package/dist/mutators/mutator.names.js +43 -0
  217. package/dist/mutators/mutators.d.ts +8 -0
  218. package/dist/mutators/mutators.js +84 -0
  219. package/dist/mutators/nested-condition.mutator.d.ts +2 -0
  220. package/dist/mutators/nested-condition.mutator.js +16 -0
  221. package/dist/mutators/number-literal.mutator.d.ts +3 -0
  222. package/dist/mutators/number-literal.mutator.js +13 -0
  223. package/dist/mutators/object-literal.mutator.d.ts +2 -0
  224. package/dist/mutators/object-literal.mutator.js +6 -0
  225. package/dist/mutators/odd-number.mutator.d.ts +2 -0
  226. package/dist/mutators/odd-number.mutator.js +15 -0
  227. package/dist/mutators/operand-deletion.mutator.d.ts +2 -0
  228. package/dist/mutators/operand-deletion.mutator.js +9 -0
  229. package/dist/mutators/outcome.mutator.d.ts +3 -0
  230. package/dist/mutators/outcome.mutator.js +45 -0
  231. package/dist/mutators/plain-assignment.mutator.d.ts +2 -0
  232. package/dist/mutators/plain-assignment.mutator.js +7 -0
  233. package/dist/mutators/power-operator.mutator.d.ts +2 -0
  234. package/dist/mutators/power-operator.mutator.js +13 -0
  235. package/dist/mutators/private-brand.mutator.d.ts +2 -0
  236. package/dist/mutators/private-brand.mutator.js +7 -0
  237. package/dist/mutators/regex.mutator.d.ts +2 -0
  238. package/dist/mutators/regex.mutator.js +29 -0
  239. package/dist/mutators/short-iteration.mutator.d.ts +2 -0
  240. package/dist/mutators/short-iteration.mutator.js +8 -0
  241. package/dist/mutators/string-literal.mutator.d.ts +3 -0
  242. package/dist/mutators/string-literal.mutator.js +149 -0
  243. package/dist/mutators/switch-default.mutator.d.ts +2 -0
  244. package/dist/mutators/switch-default.mutator.js +13 -0
  245. package/dist/mutators/sync-iteration.mutator.d.ts +3 -0
  246. package/dist/mutators/sync-iteration.mutator.js +9 -0
  247. package/dist/mutators/thrown-call.mutator.d.ts +2 -0
  248. package/dist/mutators/thrown-call.mutator.js +7 -0
  249. package/dist/mutators/unary-operator.mutator.d.ts +2 -0
  250. package/dist/mutators/unary-operator.mutator.js +18 -0
  251. package/dist/mutators/unbound-call.mutator.d.ts +2 -0
  252. package/dist/mutators/unbound-call.mutator.js +14 -0
  253. package/dist/mutators/update-operator.mutator.d.ts +2 -0
  254. package/dist/mutators/update-operator.mutator.js +15 -0
  255. package/dist/mutators/yield-value.mutator.d.ts +2 -0
  256. package/dist/mutators/yield-value.mutator.js +7 -0
  257. package/dist/parity/compare.d.ts +27 -0
  258. package/dist/parity/compare.js +26 -0
  259. package/dist/parity/corpus.parity.d.ts +1 -0
  260. package/dist/parity/corpus.parity.js +97 -0
  261. package/dist/parity/edges/corpus.fs.d.ts +3 -0
  262. package/dist/parity/edges/corpus.fs.js +30 -0
  263. package/dist/parity/edges/ports.d.ts +2 -0
  264. package/dist/parity/edges/ports.js +21 -0
  265. package/dist/parity/edges/vitest.d.ts +2 -0
  266. package/dist/parity/edges/vitest.js +3 -0
  267. package/dist/parity/parity.operations.d.ts +33 -0
  268. package/dist/parity/parity.operations.js +60 -0
  269. package/dist/parity/parity.schema.d.ts +5 -0
  270. package/dist/parity/parity.schema.js +6 -0
  271. package/dist/parity/stryker/compare.d.ts +14 -0
  272. package/dist/parity/stryker/compare.js +52 -0
  273. package/dist/parity/stryker/edges/ports.d.ts +12 -0
  274. package/dist/parity/stryker/edges/ports.js +28 -0
  275. package/dist/parity/stryker/equivalence.d.ts +1 -0
  276. package/dist/parity/stryker/equivalence.js +42 -0
  277. package/dist/parity/stryker/intended.d.ts +29 -0
  278. package/dist/parity/stryker/intended.js +152 -0
  279. package/dist/parity/stryker/normalize.d.ts +27 -0
  280. package/dist/parity/stryker/normalize.js +181 -0
  281. package/dist/parity/stryker/rules.d.ts +6 -0
  282. package/dist/parity/stryker/rules.js +116 -0
  283. package/dist/parity/stryker/sides.d.ts +46 -0
  284. package/dist/parity/stryker/sides.js +199 -0
  285. package/dist/parity/stryker/stryker.parity.d.ts +1 -0
  286. package/dist/parity/stryker/stryker.parity.js +147 -0
  287. package/dist/parity/stryker/stryker.schema.d.ts +6 -0
  288. package/dist/parity/stryker/stryker.schema.js +7 -0
  289. package/dist/parity/views.d.ts +21 -0
  290. package/dist/parity/views.js +119 -0
  291. package/dist/questions/questions.operations.d.ts +110 -0
  292. package/dist/questions/questions.operations.js +446 -0
  293. package/dist/questions/questions.schema.d.ts +57 -0
  294. package/dist/questions/questions.schema.js +28 -0
  295. package/dist/record/edges/calls.db.d.ts +10 -0
  296. package/dist/record/edges/calls.db.js +91 -0
  297. package/dist/record/edges/hits.db.d.ts +3 -0
  298. package/dist/record/edges/hits.db.js +5 -0
  299. package/dist/record/edges/holds.db.d.ts +4 -0
  300. package/dist/record/edges/holds.db.js +31 -0
  301. package/dist/record/edges/judged-state.db.d.ts +5 -0
  302. package/dist/record/edges/judged-state.db.js +25 -0
  303. package/dist/record/edges/markers.db.d.ts +11 -0
  304. package/dist/record/edges/markers.db.js +55 -0
  305. package/dist/record/edges/merge.db.d.ts +7 -0
  306. package/dist/record/edges/merge.db.js +46 -0
  307. package/dist/record/edges/parts.db.d.ts +42 -0
  308. package/dist/record/edges/parts.db.js +389 -0
  309. package/dist/record/edges/parts.edges.d.ts +2 -0
  310. package/dist/record/edges/parts.edges.js +7 -0
  311. package/dist/record/edges/parts.fs.d.ts +1 -0
  312. package/dist/record/edges/parts.fs.js +11 -0
  313. package/dist/record/edges/parts.writer.d.ts +1 -0
  314. package/dist/record/edges/parts.writer.js +85 -0
  315. package/dist/record/edges/passes.db.d.ts +19 -0
  316. package/dist/record/edges/passes.db.js +31 -0
  317. package/dist/record/edges/plan.db.d.ts +21 -0
  318. package/dist/record/edges/plan.db.js +174 -0
  319. package/dist/record/edges/reach.db.d.ts +6 -0
  320. package/dist/record/edges/reach.db.js +62 -0
  321. package/dist/record/edges/record.db.d.ts +22 -0
  322. package/dist/record/edges/record.db.js +176 -0
  323. package/dist/record/edges/record.fs.d.ts +3 -0
  324. package/dist/record/edges/record.fs.js +7 -0
  325. package/dist/record/edges/site-verdicts.db.d.ts +11 -0
  326. package/dist/record/edges/site-verdicts.db.js +66 -0
  327. package/dist/record/edges/verified.db.d.ts +7 -0
  328. package/dist/record/edges/verified.db.js +71 -0
  329. package/dist/record/parts.operations.d.ts +26 -0
  330. package/dist/record/parts.operations.js +31 -0
  331. package/dist/record/path-checks.operations.d.ts +15 -0
  332. package/dist/record/path-checks.operations.js +84 -0
  333. package/dist/record/record.operations.d.ts +36 -0
  334. package/dist/record/record.operations.js +11 -0
  335. package/dist/stresses/edges/stresses.record.d.ts +4 -0
  336. package/dist/stresses/edges/stresses.record.js +37 -0
  337. package/dist/stresses/stresses.operations.d.ts +28 -0
  338. package/dist/stresses/stresses.operations.js +22 -0
  339. package/dist/utils/ast.d.ts +55 -0
  340. package/dist/utils/ast.js +181 -0
  341. package/dist/utils/errors.d.ts +8 -0
  342. package/dist/utils/errors.js +12 -0
  343. package/dist/utils/faults.d.ts +6 -0
  344. package/dist/utils/faults.js +10 -0
  345. package/dist/utils/lookup.d.ts +4 -0
  346. package/dist/utils/lookup.js +27 -0
  347. package/dist/utils/order.d.ts +2 -0
  348. package/dist/utils/order.js +17 -0
  349. package/dist/utils/retry.d.ts +14 -0
  350. package/dist/utils/retry.js +15 -0
  351. package/dist/utils/safe.d.ts +11 -0
  352. package/dist/utils/safe.js +31 -0
  353. package/migrations/main/20261129123324_initial/migration.sql +418 -0
  354. package/migrations/main/20261129123324_initial/snapshot.json +3641 -0
  355. package/package.json +89 -4
  356. package/references/consumer-setup.md +92 -0
  357. package/src/graph/cfg/code-paths/LICENSE +21 -0
  358. package/src/graph/cfg/scopes/LICENSE +24 -0
@@ -0,0 +1,427 @@
1
+ import { locate } from '../../utils/ast.js';
2
+ import { entryAt } from '../../utils/lookup.js';
3
+ import { bindingKey, exportKey, fileKey, functionKey } from './keys.js';
4
+ const functionTypes = new Set(['FunctionDeclaration', 'FunctionExpression', 'ArrowFunctionExpression']);
5
+ const bindingTypes = new Set(['FunctionDeclaration', 'ClassDeclaration', 'TSEnumDeclaration', 'TSModuleDeclaration', 'VariableDeclarator']);
6
+ // A pattern slot holds a node or nothing.
7
+ const isNode = (value) => Boolean(value);
8
+ // The names a declaration binds, in source order: its own name, or every name a declarator's pattern holds at any depth, walked on a stack of its own.
9
+ // An ambient module's string name binds nothing a read can spell.
10
+ const namesOf = (node) => {
11
+ const names = [];
12
+ const pending = 'id' in node && node.id ? [node.id] : [];
13
+ for (let next = pending.pop(); next; next = pending.pop()) {
14
+ const inner = [];
15
+ if (next.type === 'Identifier')
16
+ names.push(next.name);
17
+ if (next.type === 'ArrayPattern')
18
+ inner.push(...next.elements);
19
+ if (next.type === 'ObjectPattern')
20
+ inner.push(...next.properties.map((property) => (property.type === 'RestElement' ? property.argument : property.value)));
21
+ if (next.type === 'RestElement')
22
+ inner.push(next.argument);
23
+ if (next.type === 'AssignmentPattern')
24
+ inner.push(next.left);
25
+ // A dotted namespace, as `A.B`, is read by its leftmost name.
26
+ if (next.type === 'TSQualifiedName')
27
+ inner.push(next.left);
28
+ pending.push(...inner.filter(isNode).toReversed());
29
+ }
30
+ return names;
31
+ };
32
+ // The name an import or export specifier spells, a plain name or a quoted string.
33
+ const nameOf = (node) => (node.type === 'Identifier' ? node.name : node.type === 'Literal' ? String(node.value) : '');
34
+ // The text a specifier spells, as a string literal or a template literal with nothing substituted, or none for one computed at run time.
35
+ export const fixedTextOf = (node) => {
36
+ if (!node)
37
+ return null;
38
+ if (node.type === 'Literal' && typeof node.value === 'string')
39
+ return node.value;
40
+ // Only a tagged template keeps an escape it cannot cook, so a plain one always has its cooked text.
41
+ return node.type === 'TemplateLiteral' && !node.expressions.length ? node.quasis.map((quasi) => quasi.value.cooked ?? quasi.value.raw).join('') : null;
42
+ };
43
+ // Whether a node is `import.meta`, or a member of it such as `import.meta.url`.
44
+ const isImportMeta = (node, property) => {
45
+ if (!property)
46
+ return node.type === 'MetaProperty' && node.meta.name === 'import';
47
+ return node.type === 'MemberExpression' && !node.computed && node.property.name === property && isImportMeta(node.object, null);
48
+ };
49
+ // Whether a declarator's value is a regular expression, a literal or a `new RegExp`.
50
+ const holdsPattern = (init) => {
51
+ if (!init)
52
+ return false;
53
+ if (init.type === 'Literal')
54
+ return 'regex' in init;
55
+ return init.type === 'NewExpression' && init.callee.type === 'Identifier' && init.callee.name === 'RegExp';
56
+ };
57
+ // The kinds of node a file's reads in types, loads and globs come from.
58
+ const readTypes = new Set(['TSTypeQuery', 'TSTypeReference', 'TSImportType', 'ImportExpression', 'NewExpression', 'CallExpression']);
59
+ // A walk of the file tells this each node before its children, in order, so a node's parent and its owner are known when it is entered.
60
+ // A declaration marked `declare`, or inside one, only describes a value made elsewhere, so it is no declaration a pass reads.
61
+ export const fileWalkOf = (path) => {
62
+ const walked = { parents: new Map(), owners: new Map(), declarations: [], functions: [], reads: [] };
63
+ const ambient = new Set();
64
+ // The root is its own parent, and runs with the module.
65
+ const ownerOf = (node, parent) => {
66
+ if (node === parent)
67
+ return fileKey(path);
68
+ return functionTypes.has(parent.type) ? functionKey(path, parent.start) : entryAt(walked.owners, parent, 'the owner of a walked node');
69
+ };
70
+ const enter = (node, parent) => {
71
+ if (node !== parent)
72
+ walked.parents.set(node, parent);
73
+ walked.owners.set(node, ownerOf(node, parent));
74
+ if (('declare' in node && node.declare === true) || ambient.has(parent))
75
+ ambient.add(node);
76
+ if (bindingTypes.has(node.type) && !ambient.has(node))
77
+ walked.declarations.push(node);
78
+ if (functionTypes.has(node.type))
79
+ walked.functions.push(node);
80
+ if (readTypes.has(node.type))
81
+ walked.reads.push(node);
82
+ };
83
+ return { walked, listener: { enter, exit: () => { } } };
84
+ };
85
+ const disposingKinds = new Set(['using', 'await using']);
86
+ // The binding key of every named declaration, leaving out a loop head's item, which the loop needs declared even when its body never reads it, and a `using` binding, which its scope disposes on exit.
87
+ const bindingsOf = (path, { parents, declarations }) => {
88
+ const bindings = new Map();
89
+ const names = new Map();
90
+ for (const node of declarations) {
91
+ const bound = namesOf(node);
92
+ if (!bound.length)
93
+ continue;
94
+ const declaration = entryAt(parents, node, 'the parent of a declaration');
95
+ if (declaration.type === 'VariableDeclaration' && disposingKinds.has(declaration.kind))
96
+ continue;
97
+ const head = parents.get(declaration);
98
+ if (head?.type === 'ForInStatement' || head?.type === 'ForOfStatement')
99
+ continue;
100
+ bindings.set(node, bindingKey(path, node.start));
101
+ names.set(node, bound);
102
+ }
103
+ return { bindings, names };
104
+ };
105
+ const definitionsOf = ({ references, definitions, parameters, parents }) => {
106
+ const declaredBy = new Map();
107
+ for (const { identifier, variable } of references) {
108
+ const parent = entryAt(parents, identifier, 'the parent of a read');
109
+ if ('id' in parent && parent.id === identifier)
110
+ declaredBy.set(variable, parent);
111
+ }
112
+ const definitionOf = (variable) => declaredBy.get(variable) ?? (parameters.has(variable) ? undefined : definitions.get(variable));
113
+ return new Map(references.map(({ identifier, variable }) => [identifier, definitionOf(variable)]));
114
+ };
115
+ export const fileTreeOf = (path, { parsed, references, definitions, parameters, unresolved, walked }) => {
116
+ const { bindings, names } = bindingsOf(path, walked);
117
+ const definitionOf = definitionsOf({ references, definitions, parameters, parents: walked.parents });
118
+ return { ...walked, program: parsed.program, references, bindings, names, definitionOf, unresolved };
119
+ };
120
+ // One file's nodes and edges: its loads, its reads of bindings and imports, `typeof` reads included, and what it exports.
121
+ // Any read of a function, a call or a hand-off alike, reaches it, so a function passed to another is reached wherever the code passing it runs.
122
+ // A function bound to no name, as a callback written inline, runs with the code holding it.
123
+ export const fileSymbolsOf = (path, source, tree) => {
124
+ const at = locate(source);
125
+ const lineOf = (offset) => at(offset).line;
126
+ const fileNode = { key: fileKey(path), file: path, kind: 'file', name: path, line: 1, parsed: tree !== null };
127
+ const symbols = { path, nodes: [fileNode], edges: [], stars: [], globs: [] };
128
+ if (!tree)
129
+ return symbols;
130
+ const edge = (from, to) => {
131
+ if ('key' in to && to.key === from)
132
+ return;
133
+ symbols.edges.push({ from, to });
134
+ };
135
+ // TypeScript merges declarations of one name, as a class and a namespace, so each name has one export node leading to every binding declared under it.
136
+ const exports = new Map();
137
+ const exportOf = (name, line) => {
138
+ const kept = exports.get(name);
139
+ if (kept)
140
+ return kept;
141
+ const made = { key: exportKey(path, name), file: path, kind: 'export', name, line, bindings: [], isOwn: true };
142
+ exports.set(name, made);
143
+ symbols.nodes.push(made);
144
+ return made;
145
+ };
146
+ const { program, references, parents, owners, bindings, names, definitionOf, unresolved } = tree;
147
+ const namesAt = (node) => names.get(node) ?? [];
148
+ const ownerOf = (node) => entryAt(owners, node, 'the owner of a graph node');
149
+ // Every named declaration is a binding, a function's binding leading to the function it holds.
150
+ const bindingNodes = new Map();
151
+ for (const [node, key] of bindings) {
152
+ const held = node.type === 'VariableDeclarator' ? node.init : node;
153
+ const made = { key, file: path, kind: 'binding', name: namesAt(node).join(', '), line: lineOf(node.start), owner: ownerOf(node), isPattern: holdsPattern(held), alongside: [] };
154
+ bindingNodes.set(node, made);
155
+ symbols.nodes.push(made);
156
+ if (held && functionTypes.has(held.type))
157
+ edge(key, { key: functionKey(path, held.start) });
158
+ }
159
+ // A namespace reaches every declaration in its body, as reading a namespace import reaches every export.
160
+ for (const [node, key] of bindings) {
161
+ for (let above = parents.get(node); above && !functionTypes.has(above.type); above = parents.get(above)) {
162
+ const namespace = above.type === 'TSModuleDeclaration' ? bindings.get(above) : undefined;
163
+ if (!namespace)
164
+ continue;
165
+ edge(namespace, { key });
166
+ break;
167
+ }
168
+ }
169
+ for (const node of tree.functions) {
170
+ const owner = ownerOf(node);
171
+ const key = functionKey(path, node.start);
172
+ symbols.nodes.push({ key, file: path, kind: 'function', name: '', line: lineOf(node.start), owner });
173
+ const parent = parents.get(node);
174
+ // A declaration with no name is only ever a default export, which the export reaches.
175
+ const isBound = node.type === 'FunctionDeclaration' || (parent?.type === 'VariableDeclarator' && parent.id.type === 'Identifier');
176
+ if (!isBound && parent?.type !== 'ExportDefaultDeclaration')
177
+ edge(owner, { key });
178
+ }
179
+ // Each import specifier's module and the export it names.
180
+ const imports = new Map();
181
+ for (const item of program.body) {
182
+ if (item.type !== 'ImportDeclaration')
183
+ continue;
184
+ for (const specifier of item.specifiers) {
185
+ const from = item.source.value;
186
+ const name = specifier.type === 'ImportSpecifier' ? nameOf(specifier.imported) : 'default';
187
+ imports.set(specifier, specifier.type === 'ImportNamespaceSpecifier' ? { specifier: from, namespace: true } : { specifier: from, name });
188
+ }
189
+ }
190
+ // What reading a declaration reaches: its binding, or the export it imports, a namespace read for one static member reaching that export alone.
191
+ const targetOf = (definition, read) => {
192
+ if (!definition)
193
+ return undefined;
194
+ const binding = bindings.get(definition);
195
+ if (binding)
196
+ return { key: binding };
197
+ const imported = imports.get(definition);
198
+ if (!imported || !('namespace' in imported))
199
+ return imported;
200
+ const parent = parents.get(read);
201
+ if (parent?.type === 'MemberExpression' && parent.object === read && !parent.computed)
202
+ return { specifier: imported.specifier, name: nameOf(parent.property) };
203
+ if (parent?.type === 'TSQualifiedName' && parent.left === read)
204
+ return { specifier: imported.specifier, name: nameOf(parent.right) };
205
+ return imported;
206
+ };
207
+ // Where each import is read, in code or in a type, so a removal can name the imports it leaves unread.
208
+ const importReads = new Map();
209
+ const noteRead = (definition, offset) => {
210
+ if (definition && imports.has(definition))
211
+ importReads.set(definition, [...(importReads.get(definition) ?? []), offset]);
212
+ };
213
+ // The binding whose value a read helps work out, in the same function: its initializer's, as `const L = live()` holds `live`, or an assignment's, as a `beforeEach` setting `x = live()`.
214
+ const valueHolderOf = (identifier) => {
215
+ for (let above = parents.get(identifier); above && !functionTypes.has(above.type); above = parents.get(above)) {
216
+ const binding = bindings.get(above);
217
+ if (binding)
218
+ return binding;
219
+ if (above.type !== 'AssignmentExpression')
220
+ continue;
221
+ const assigned = definitionOf.get(above.left);
222
+ const target = assigned ? bindings.get(assigned) : undefined;
223
+ if (target)
224
+ return target;
225
+ }
226
+ return null;
227
+ };
228
+ // Names the scopes leave out, a `typeof` in a type or a value read of a namespace, which the scopes declare no variable for, resolve against the module's own declarations and imports.
229
+ const moduleNames = new Map();
230
+ for (const item of program.body) {
231
+ if (item.type === 'ImportDeclaration')
232
+ for (const specifier of item.specifiers)
233
+ moduleNames.set(specifier.local.name, specifier);
234
+ const declaration = item.type === 'ExportNamedDeclaration' || item.type === 'ExportDefaultDeclaration' ? item.declaration : item;
235
+ if (!declaration)
236
+ continue;
237
+ const declared = declaration.type === 'VariableDeclaration' ? declaration.declarations : [declaration];
238
+ for (const node of declared)
239
+ for (const name of namesAt(node))
240
+ moduleNames.set(name, node);
241
+ }
242
+ for (const { identifier, isRead } of references) {
243
+ if (!isRead)
244
+ continue;
245
+ const definition = definitionOf.get(identifier);
246
+ noteRead(definition, identifier.start);
247
+ const parent = parents.get(identifier);
248
+ // Naming a binding in an export reaches it only through that export, and a declaration's own name, as a namespace merged with a class, reads nothing.
249
+ if (parent?.type === 'ExportSpecifier' || parent?.type === 'ExportDefaultDeclaration')
250
+ continue;
251
+ if (parent && 'id' in parent && parent.id === identifier)
252
+ continue;
253
+ const target = targetOf(definition, identifier);
254
+ if (!target)
255
+ continue;
256
+ edge(ownerOf(identifier), target);
257
+ // A module-level value is worked out by its initializer, so whatever reads the value reaches what the initializer read.
258
+ const holder = valueHolderOf(identifier);
259
+ if (holder)
260
+ edge(holder, target);
261
+ }
262
+ // The scopes declare no variable for a namespace or an enum, so a read of one is unresolved, and it reaches the one its name spells in scope, as a read would.
263
+ // A namespace's own name is reported too, which names it rather than reading it.
264
+ // A namespace or enum may be declared in any block or switch case, so a read reaches the nearest one in scope, found in the statements of each around it.
265
+ // Most files declare no namespace or enum, so a read of any other name, as of a built-in global, is settled without a walk.
266
+ const scopedNames = new Set([...bindingNodes].filter(([node]) => node.type === 'TSEnumDeclaration' || node.type === 'TSModuleDeclaration').map(([, made]) => made.name));
267
+ const scopedDeclarationOf = (identifier) => {
268
+ const name = nameOf(identifier);
269
+ if (!scopedNames.has(name))
270
+ return undefined;
271
+ for (let above = parents.get(identifier); above; above = parents.get(above)) {
272
+ const statements = above.type === 'SwitchCase' ? above.consequent : above.type === 'Program' || above.type === 'BlockStatement' || above.type === 'TSModuleBlock' ? above.body : [];
273
+ for (const statement of statements) {
274
+ const declaration = statement.type === 'ExportNamedDeclaration' ? statement.declaration : statement;
275
+ if (declaration && (declaration.type === 'TSEnumDeclaration' || declaration.type === 'TSModuleDeclaration') && namesAt(declaration).includes(name))
276
+ return declaration;
277
+ }
278
+ }
279
+ return undefined;
280
+ };
281
+ for (const identifier of unresolved) {
282
+ const parent = entryAt(parents, identifier, 'the parent of a read');
283
+ if ('id' in parent && parent.id === identifier)
284
+ continue;
285
+ const definition = scopedDeclarationOf(identifier);
286
+ const target = targetOf(definition, identifier);
287
+ if (!target)
288
+ continue;
289
+ edge(ownerOf(identifier), target);
290
+ const holder = valueHolderOf(identifier);
291
+ if (holder)
292
+ edge(holder, target);
293
+ }
294
+ const readByName = (identifier) => {
295
+ const definition = moduleNames.get(nameOf(identifier));
296
+ noteRead(definition, identifier.start);
297
+ const target = targetOf(definition, identifier);
298
+ if (target)
299
+ edge(fileNode.key, target);
300
+ };
301
+ for (const node of tree.reads) {
302
+ const owner = ownerOf(node);
303
+ // A value read in a type is needed to compile, so the module reaches it.
304
+ // A class or enum named as a type is read the same way, as an annotation or a qualified enum member.
305
+ const typeName = node.type === 'TSTypeQuery' ? node.exprName : node.type === 'TSTypeReference' ? node.typeName : null;
306
+ const name = typeName?.type === 'TSQualifiedName' ? typeName.left : typeName;
307
+ if (name?.type === 'Identifier')
308
+ readByName(name);
309
+ // An import type names a module's export by its first name, as `import('./m').X.Y` names `X`, and naming none stands for the whole module, as a namespace does.
310
+ if (node.type === 'TSImportType') {
311
+ const specifier = fixedTextOf(node.source);
312
+ let first = node.qualifier;
313
+ while (first?.type === 'TSQualifiedName')
314
+ first = first.left;
315
+ if (specifier) {
316
+ edge(fileNode.key, { specifier, name: null });
317
+ edge(fileNode.key, first?.type === 'Identifier' ? { specifier, name: first.name } : { specifier, namespace: true });
318
+ }
319
+ }
320
+ // A dynamic import of a fixed specifier loads its file and reaches every export, from the code that imports it.
321
+ if (node.type === 'ImportExpression') {
322
+ const specifier = fixedTextOf(node.source);
323
+ if (!specifier)
324
+ continue;
325
+ edge(owner, { specifier, name: null });
326
+ edge(owner, { specifier, namespace: true });
327
+ }
328
+ // `new URL('./worker.ts', import.meta.url)` names a file a worker or a loader runs.
329
+ if (node.type === 'NewExpression' && node.callee.type === 'Identifier' && node.callee.name === 'URL') {
330
+ const [first, second] = node.arguments;
331
+ const specifier = fixedTextOf(first);
332
+ if (!specifier || !second || !isImportMeta(second, 'url'))
333
+ continue;
334
+ edge(owner, { specifier, name: null });
335
+ edge(owner, { specifier, namespace: true });
336
+ }
337
+ if (node.type === 'CallExpression' && isImportMeta(node.callee, 'glob')) {
338
+ const [first] = node.arguments;
339
+ const patterns = first?.type === 'ArrayExpression' ? first.elements.map((element) => fixedTextOf(element)) : [fixedTextOf(first)];
340
+ symbols.globs.push({ from: owner, patterns: patterns.filter((pattern) => pattern !== null) });
341
+ }
342
+ }
343
+ for (const item of program.body) {
344
+ // A module or value imported for its type is needed to compile, so the importing module reaches it.
345
+ if (item.type === 'ImportDeclaration') {
346
+ edge(fileNode.key, { specifier: item.source.value, name: null });
347
+ for (const specifier of item.specifiers) {
348
+ const imported = imports.get(specifier);
349
+ if (imported && (item.importKind === 'type' || (specifier.type === 'ImportSpecifier' && specifier.importKind === 'type')))
350
+ edge(fileNode.key, imported);
351
+ }
352
+ }
353
+ if (item.type === 'ExportAllDeclaration') {
354
+ edge(fileNode.key, { specifier: item.source.value, name: null });
355
+ if (item.exported)
356
+ edge(exportOf(nameOf(item.exported), lineOf(item.start)).key, { specifier: item.source.value, namespace: true });
357
+ else
358
+ symbols.stars.push(item.source.value);
359
+ }
360
+ if (item.type === 'ExportDefaultDeclaration') {
361
+ const { declaration } = item;
362
+ const exported = exportOf('default', lineOf(item.start));
363
+ const binding = bindings.get(declaration);
364
+ if (binding) {
365
+ edge(exported.key, { key: binding });
366
+ exported.bindings.push(binding);
367
+ }
368
+ if (functionTypes.has(declaration.type) && !binding)
369
+ edge(exported.key, { key: functionKey(path, declaration.start) });
370
+ const target = targetOf(definitionOf.get(declaration), declaration);
371
+ if (target)
372
+ edge(exported.key, target);
373
+ if (target && 'key' in target)
374
+ exported.bindings.push(target.key);
375
+ }
376
+ if (item.type !== 'ExportNamedDeclaration' || item.exportKind === 'type')
377
+ continue;
378
+ const { declaration, specifiers, source } = item;
379
+ if (source)
380
+ edge(fileNode.key, { specifier: source.value, name: null });
381
+ const declared = declaration?.type === 'VariableDeclaration' ? declaration.declarations : declaration ? [declaration] : [];
382
+ for (const node of declared) {
383
+ const held = bindingNodes.get(node);
384
+ if (!held)
385
+ continue;
386
+ for (const name of namesAt(node)) {
387
+ const exported = exportOf(name, lineOf(node.start));
388
+ edge(exported.key, { key: held.key });
389
+ exported.bindings.push(held.key);
390
+ }
391
+ }
392
+ for (const specifier of specifiers) {
393
+ if (specifier.exportKind === 'type')
394
+ continue;
395
+ const exported = exportOf(nameOf(specifier.exported), lineOf(specifier.start));
396
+ if (source) {
397
+ edge(exported.key, { specifier: source.value, name: nameOf(specifier.local) });
398
+ continue;
399
+ }
400
+ const target = targetOf(definitionOf.get(specifier.local), specifier.local);
401
+ if (!target)
402
+ continue;
403
+ edge(exported.key, target);
404
+ if ('key' in target)
405
+ exported.bindings.push(target.key);
406
+ }
407
+ }
408
+ // An import every read of which sits inside the declarations of one module-level name goes unread once that name is removed.
409
+ // TypeScript merges declarations of one name, as a class and a namespace, so they hold an import together.
410
+ // A binding standing at the top level, or exported there, is a class, function, enum or namespace, since a declarator's parent is its statement.
411
+ // Those are the kinds TypeScript merges, so only they share a name, and any other binding, as one in a block, holds imports alone.
412
+ const isMerged = (node) => {
413
+ const parent = parents.get(node);
414
+ return parent === program || (parent?.type === 'ExportNamedDeclaration' && parents.get(parent) === program);
415
+ };
416
+ const moduleBindings = [...bindingNodes].filter(([, made]) => made.owner === fileNode.key);
417
+ const byName = [...Map.groupBy(moduleBindings, ([node, made]) => (isMerged(node) ? made.name : made.key)).values()];
418
+ for (const [specifier, offsets] of importReads) {
419
+ const holders = byName.find((group) => offsets.every((offset) => group.some(([node]) => offset >= node.start && offset < node.end)));
420
+ if (!('local' in specifier))
421
+ continue;
422
+ const { local } = specifier;
423
+ for (const [, made] of holders ?? [])
424
+ made.alongside.push(nameOf(local));
425
+ }
426
+ return symbols;
427
+ };
@@ -0,0 +1,13 @@
1
+ import { z } from 'zod';
2
+ export declare const reachFile: z.ZodString;
3
+ export declare const reachName: z.ZodString;
4
+ declare const reachKey: z.ZodUnion<readonly [z.ZodTuple<[z.ZodLiteral<"file">, z.ZodString], null>, z.ZodTuple<[z.ZodLiteral<"namespace">, z.ZodString], null>, z.ZodTuple<[z.ZodLiteral<"export">, z.ZodString, z.ZodString], null>, z.ZodTuple<[z.ZodLiteral<"binding">, z.ZodString, z.ZodNumber], null>, z.ZodTuple<[z.ZodLiteral<"function">, z.ZodString, z.ZodNumber], null>]>;
5
+ export type ReachKey = z.infer<typeof reachKey>;
6
+ export declare const encodeReachKey: (key: ReachKey) => string;
7
+ export declare const decodeReachKey: (encoded: string) => ReachKey | null;
8
+ export declare const fileKey: (path: string) => string;
9
+ export declare const namespaceKey: (path: string) => string;
10
+ export declare const exportKey: (path: string, name: string) => string;
11
+ export declare const bindingKey: (path: string, start: number) => string;
12
+ export declare const functionKey: (path: string, start: number) => string;
13
+ export {};
@@ -0,0 +1,22 @@
1
+ import { z } from 'zod';
2
+ import { safe } from '../../utils/safe.js';
3
+ export const reachFile = z.string().min(1).max(2048);
4
+ export const reachName = z.string().max(2048);
5
+ const reachKey = z.union([
6
+ z.tuple([z.literal('file'), reachFile]),
7
+ z.tuple([z.literal('namespace'), reachFile]),
8
+ z.tuple([z.literal('export'), reachFile, reachName]),
9
+ z.tuple([z.literal('binding'), reachFile, z.number().int().nonnegative()]),
10
+ z.tuple([z.literal('function'), reachFile, z.number().int().nonnegative()]),
11
+ ]);
12
+ export const encodeReachKey = (key) => JSON.stringify(key);
13
+ export const decodeReachKey = (encoded) => {
14
+ // Text that is no JSON parses to nothing, which the schema refuses like any other wrong shape.
15
+ const { data: decoded } = safe(() => reachKey.safeParse(JSON.parse(encoded)));
16
+ return decoded?.success ? decoded.data : null;
17
+ };
18
+ export const fileKey = (path) => encodeReachKey(['file', path]);
19
+ export const namespaceKey = (path) => encodeReachKey(['namespace', path]);
20
+ export const exportKey = (path, name) => encodeReachKey(['export', path, name]);
21
+ export const bindingKey = (path, start) => encodeReachKey(['binding', path, start]);
22
+ export const functionKey = (path, start) => encodeReachKey(['function', path, start]);
@@ -0,0 +1,4 @@
1
+ export declare const scriptExtensionPattern: RegExp;
2
+ export declare const querySuffixPattern: RegExp;
3
+ export declare const normalized: (path: string) => string | null;
4
+ export declare const resolverOf: (files: ReadonlySet<string>) => ((from: string, specifier: string) => string | null);
@@ -0,0 +1,33 @@
1
+ // Endings the Stryker corpus tries after a relative specifier.
2
+ const suffixes = ['', '.ts', '.tsx', '.mts', '.cts', '.js', '/index.ts', '/index.tsx', '/index.js'];
3
+ // Matches a JavaScript extension a TypeScript source is imported by, as `.js` for `.ts` or `.mjs` for `.mts`.
4
+ export const scriptExtensionPattern = /\.([cm]?)js(x?)$/;
5
+ // Matches a query or hash a specifier carries after its path, as `?raw`, never the `#` opening a package import.
6
+ export const querySuffixPattern = /(?!^)[?#].*$/;
7
+ // A path with its `.` and `..` folders worked out, relative to the project root, or none when it climbs out of the root.
8
+ export const normalized = (path) => {
9
+ const parts = [];
10
+ for (const part of path.split('/')) {
11
+ if (part === '..' && !parts.length)
12
+ return null;
13
+ if (part === '..')
14
+ parts.pop();
15
+ else if (part !== '.' && part)
16
+ parts.push(part);
17
+ }
18
+ return parts.join('/');
19
+ };
20
+ // Looks up a relative import among the files in the Stryker corpus manifest.
21
+ export const resolverOf = (files) => {
22
+ return (from, written) => {
23
+ if (!written.startsWith('.'))
24
+ return null;
25
+ const specifier = written.replace(querySuffixPattern, '');
26
+ const folder = from.slice(0, from.lastIndexOf('/') + 1);
27
+ const base = normalized(folder + specifier);
28
+ if (base === null)
29
+ return null;
30
+ const candidates = [...suffixes.map((suffix) => base + suffix), base.replace(scriptExtensionPattern, (_, kind, jsx) => `.${kind}ts${jsx}`)];
31
+ return candidates.find((candidate) => files.has(candidate)) ?? null;
32
+ };
33
+ };
@@ -0,0 +1,12 @@
1
+ import type { SymbolNode, FileSymbols } from './file.ts';
2
+ export type SymbolGraph = {
3
+ nodes: ReadonlyMap<string, SymbolNode>;
4
+ edges: ReadonlyMap<string, ReadonlySet<string>>;
5
+ };
6
+ export type SymbolGraphInput = {
7
+ files: FileSymbols[];
8
+ roots: ReadonlyMap<string, 'entry' | 'test'>;
9
+ resolve: (from: string, specifier: string) => string | null;
10
+ };
11
+ export declare const reachedFrom: (edges: ReadonlyMap<string, Iterable<string>>, starts: string[], canEnter?: (key: string) => boolean) => Set<string>;
12
+ export declare const symbolGraphOf: ({ files, roots, resolve }: SymbolGraphInput) => SymbolGraph;