@whaaaley/crush 0.0.0-stage → 0.2.7

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 +14 -0
  170. package/dist/judge/task-meta.js +1 -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,121 @@
1
+ import { fieldOf, holderKeyOf, isHolder, isIndex, keysOf } from './reads.js';
2
+ import { entryAt } from '../../utils/lookup.js';
3
+ // The most items one pool keeps under one key, a sample once more arrive.
4
+ export const poolLimit = 256;
5
+ // Of nine number draws, how many take a number known under the field's key, one a step from the current value, and the rest a small number.
6
+ const keyedDraws = 3;
7
+ const fieldKeyOf = (holderKey, key) => JSON.stringify([holderKey, key]);
8
+ export const holderShapeOf = (holder) => JSON.stringify(Object.keys(Object(holder)).toSorted());
9
+ export const poolsOf = (r) => {
10
+ const stringsAt = new Map();
11
+ const numbersAt = new Map();
12
+ const donorsAt = new Map();
13
+ const elementsAt = new Map();
14
+ const remember = (pool, key, item) => {
15
+ const known = pool.get(key);
16
+ if (!known)
17
+ pool.set(key, [item]);
18
+ else if (known.length < poolLimit)
19
+ known.push(item);
20
+ else
21
+ known[r.int(0, poolLimit - 1)] = item;
22
+ };
23
+ const shapesAt = new Map();
24
+ const tags = new Set();
25
+ const noteShape = (id, value, holder) => {
26
+ const known = shapesAt.get(id) ?? { byShape: new Map(), exclusive: new Map() };
27
+ shapesAt.set(id, known);
28
+ const shape = holderShapeOf(holder);
29
+ const had = known.byShape.get(shape);
30
+ if (had === undefined) {
31
+ known.byShape.set(shape, value);
32
+ known.exclusive.set(value, (known.exclusive.get(value) ?? 0) + 1);
33
+ }
34
+ else if (had !== null && had !== value) {
35
+ known.byShape.set(shape, null);
36
+ const remaining = entryAt(known.exclusive, had, 'a label with an exclusive shape') - 1;
37
+ if (remaining)
38
+ known.exclusive.set(had, remaining);
39
+ else
40
+ known.exclusive.delete(had);
41
+ }
42
+ if (known.exclusive.size > 1)
43
+ tags.add(id);
44
+ else
45
+ tags.delete(id);
46
+ };
47
+ const isTag = (holderKey, key) => tags.has(fieldKeyOf(holderKey, key));
48
+ const learn = (value, holderKey, parent) => {
49
+ const isArray = Array.isArray(value);
50
+ for (const [key, inner] of Object.entries(Object(value))) {
51
+ if (typeof inner === 'string') {
52
+ const fieldKey = fieldKeyOf(holderKey, key);
53
+ const known = stringsAt.get(fieldKey) ?? [];
54
+ if (!known.includes(inner))
55
+ known.push(inner);
56
+ stringsAt.set(fieldKey, known);
57
+ if (isArray)
58
+ continue;
59
+ noteShape(fieldKey, inner, Object(value));
60
+ if (parent && tags.has(fieldKey))
61
+ remember(donorsAt, fieldKeyOf(holderShapeOf(parent.container), parent.key), { container: parent.container, value });
62
+ }
63
+ else if (typeof inner === 'number') {
64
+ remember(numbersAt, key, inner);
65
+ }
66
+ else if (isHolder(inner)) {
67
+ if (Array.isArray(inner)) {
68
+ const elementKey = fieldKeyOf(holderShapeOf(value), key);
69
+ for (const element of inner)
70
+ if (isHolder(element))
71
+ remember(elementsAt, elementKey, element);
72
+ }
73
+ // An array's elements take the array's own place as their container, so a tagged element is swapped only for one from the same field of a matching holder.
74
+ const container = isArray && parent ? parent : { container: value, key };
75
+ learn(inner, isArray || (holderKey !== '' && isIndex(key)) ? holderKey : key, container);
76
+ }
77
+ }
78
+ };
79
+ // The seeds are learned twice, since which fields are tags is known only once every seed has been seen, so every pool but the strings starts again.
80
+ const forget = () => {
81
+ for (const pool of [donorsAt, elementsAt, numbersAt])
82
+ pool.clear();
83
+ };
84
+ const drawNumber = (key, current) => {
85
+ const roll = r.int(0, 8);
86
+ const known = numbersAt.get(key);
87
+ if (roll < keyedDraws && known)
88
+ return r.pick(known);
89
+ return roll === 8 ? current + r.int(-1, 1) : r.int(-8, 8);
90
+ };
91
+ const drawString = (key, current, holderKey = '') => r.pick(stringsAt.get(fieldKeyOf(holderKey, key)) ?? [current]);
92
+ // An input's own fields sit under the root key, the one `holderKeyOf` gives the empty path, so a tag on its top level is known by the same key edits look it up under.
93
+ const learnInput = (input) => learn(input, holderKeyOf([]));
94
+ // An array is a tuple when the seeds hold it at one length at least twice, counting each element of a list at one place, so `[language, ranked]` entries keep their length.
95
+ const lengthsAt = new Map();
96
+ const placeOf = (path) => JSON.stringify(path.map((key) => (isIndex(key) ? '*' : key)));
97
+ const learnLengths = (value, path = []) => {
98
+ if (Array.isArray(value)) {
99
+ const place = placeOf(path);
100
+ const known = lengthsAt.get(place) ?? { lengths: new Set(), count: 0 };
101
+ known.lengths.add(value.length);
102
+ known.count++;
103
+ lengthsAt.set(place, known);
104
+ }
105
+ for (const [key, inner] of Object.entries(value))
106
+ if (isHolder(inner))
107
+ learnLengths(inner, path.concat(key));
108
+ };
109
+ const isTuple = (path) => {
110
+ const known = lengthsAt.get(placeOf(path));
111
+ return known !== undefined && known.count > 1 && known.lengths.size === 1;
112
+ };
113
+ const elementsOf = (holder, key) => elementsAt.get(fieldKeyOf(holderShapeOf(holder), key));
114
+ const donorsOf = (container, containerKey, key) => {
115
+ const candidates = donorsAt.get(fieldKeyOf(holderShapeOf(container), key)) ?? [];
116
+ // Labels can change as the search learns new shapes, so compare them at draw time.
117
+ const labels = keysOf(container).filter((field) => isTag(containerKey, field));
118
+ return candidates.filter((donor) => labels.every((field) => fieldOf(container, field) === fieldOf(donor.container, field))).map((donor) => donor.value);
119
+ };
120
+ return { donorsOf, elementsOf, isTag, learn, learnInput, learnLengths, isTuple, forget, drawNumber, drawString };
121
+ };
@@ -0,0 +1,19 @@
1
+ export type Holder = Record<string, unknown> | unknown[];
2
+ export declare const isHolder: (value: unknown) => value is Holder;
3
+ export declare const fieldOf: (holder: unknown, key: string) => unknown;
4
+ export type ReadNode = {
5
+ keys: Set<string>;
6
+ children: Map<string, ReadNode>;
7
+ proxy: unknown;
8
+ };
9
+ export declare const readsOf: (value: object, run: (proxied: object) => unknown) => ReadNode;
10
+ export declare const merged: (a: ReadNode | undefined, b: ReadNode | undefined) => ReadNode | undefined;
11
+ export type Path = string[];
12
+ export declare const leafPathsOf: (value: unknown, node: ReadNode, path: Path, found: Path[]) => Path[];
13
+ export declare const valueAtPath: (value: unknown, path: Path) => unknown;
14
+ export declare const copyOf: (value: unknown) => Holder;
15
+ export declare const withAt: (value: unknown, path: Path, depth: number, change: (holder: unknown, key: string) => unknown) => Holder;
16
+ export declare const isIndex: (key: string) => boolean;
17
+ export declare const holderKeyOf: (path: Path) => string;
18
+ export declare const sizeOf: (value: unknown) => number;
19
+ export declare const keysOf: (value: unknown) => string[];
@@ -0,0 +1,118 @@
1
+ // oxlint-disable typescript/no-unsafe-argument, typescript/no-unsafe-assignment, typescript/no-unsafe-return -- this file handles values the code under test makes, passes or throws, which no static type names
2
+ import { itemAt, present } from '../../utils/lookup.js';
3
+ // Only an array or a plain object holds fields an edit walks into; a Set, Map, Date or class instance is one value, so an edit never turns it into a plain object no typed caller could pass.
4
+ export const isHolder = (value) => {
5
+ if (Array.isArray(value))
6
+ return true;
7
+ if (typeof value !== 'object' || value === null)
8
+ return false;
9
+ const prototype = Object.getPrototypeOf(value);
10
+ return prototype === Object.prototype || prototype === null;
11
+ };
12
+ export const fieldOf = (holder, key) => {
13
+ if (!isHolder(holder))
14
+ return undefined;
15
+ const field = Reflect.get(holder, key);
16
+ return field;
17
+ };
18
+ export const readsOf = (value, run) => {
19
+ const wrap = (target) => {
20
+ const node = { keys: new Set(), children: new Map(), proxy: undefined };
21
+ node.proxy = new Proxy(target, {
22
+ get: (object, key) => {
23
+ const inner = Reflect.get(object, key);
24
+ if (typeof key !== 'string')
25
+ return inner;
26
+ node.keys.add(key);
27
+ if (!isHolder(inner))
28
+ return inner;
29
+ let child = node.children.get(key);
30
+ if (!child) {
31
+ child = wrap(inner);
32
+ node.children.set(key, child);
33
+ }
34
+ return child.proxy;
35
+ },
36
+ });
37
+ return node;
38
+ };
39
+ const root = wrap(value);
40
+ run(Object(root.proxy));
41
+ return root;
42
+ };
43
+ // The reads of two runs over one shape, as one tree.
44
+ export const merged = (a, b) => {
45
+ if (!a || !b)
46
+ return a ?? b;
47
+ const node = { keys: new Set([...a.keys, ...b.keys]), children: new Map(), proxy: undefined };
48
+ // A key both trees reached merges once per tree, which gives the same child again.
49
+ for (const key of [...a.children.keys(), ...b.children.keys()])
50
+ node.children.set(key, present(merged(a.children.get(key), b.children.get(key))));
51
+ return node;
52
+ };
53
+ // The path to every number and string a run read.
54
+ export const leafPathsOf = (value, node, path, found) => {
55
+ for (const key of node.keys) {
56
+ const inner = fieldOf(value, key);
57
+ if (typeof inner === 'number' || typeof inner === 'string') {
58
+ if (key !== 'length')
59
+ found.push([...path, key]);
60
+ }
61
+ else {
62
+ // A run that read a holder entered it, so only a holder has a child.
63
+ const child = node.children.get(key);
64
+ if (child)
65
+ leafPathsOf(inner, child, [...path, key], found);
66
+ }
67
+ }
68
+ return found;
69
+ };
70
+ export const valueAtPath = (value, path) => {
71
+ let at = value;
72
+ for (const key of path)
73
+ at = fieldOf(at, key);
74
+ return at;
75
+ };
76
+ export const copyOf = (value) => (Array.isArray(value) ? value.slice() : { ...Object(value) });
77
+ // A value with the field at a path replaced, copying only the objects along the path.
78
+ export const withAt = (value, path, depth, change) => {
79
+ const key = itemAt(path, depth);
80
+ const copy = copyOf(value);
81
+ Reflect.set(copy, key, depth === path.length - 1 ? change(value, key) : withAt(fieldOf(value, key), path, depth + 1, change));
82
+ return copy;
83
+ };
84
+ export const isIndex = (key) => !Number.isNaN(Number(key));
85
+ // The nearest named holder, with a top-level argument index as the fallback for a positional seed.
86
+ export const holderKeyOf = (path) => {
87
+ let holderKey = path[0] ?? '';
88
+ for (const each of path)
89
+ if (!isIndex(each))
90
+ holderKey = each;
91
+ return holderKey;
92
+ };
93
+ export const sizeOf = (value) => {
94
+ const root = Object(value);
95
+ const stack = [{ value: root, fields: Object.values(root).values() }];
96
+ const ancestors = new Set([root]);
97
+ let size = 1;
98
+ while (stack.length) {
99
+ const frame = itemAt(stack, stack.length - 1);
100
+ const field = frame.fields.next();
101
+ if (field.done) {
102
+ ancestors.delete(frame.value);
103
+ stack.pop();
104
+ continue;
105
+ }
106
+ size++;
107
+ const inner = field.value;
108
+ if (!isHolder(inner))
109
+ continue;
110
+ // Only ancestors form a cycle. A shared field still counts at each place it occurs.
111
+ if (ancestors.has(inner))
112
+ return Infinity;
113
+ ancestors.add(inner);
114
+ stack.push({ value: inner, fields: Object.values(inner).values() });
115
+ }
116
+ return size;
117
+ };
118
+ export const keysOf = (value) => Object.keys(Object(value));
@@ -0,0 +1,21 @@
1
+ import type { Pools } from './pools.ts';
2
+ import type { Random } from './draws.ts';
3
+ import { type Path, type ReadNode } from './reads.ts';
4
+ export type Plan = {
5
+ numbers: [string, number][];
6
+ strings: string[];
7
+ children: [string, Plan][];
8
+ resizes: string | undefined;
9
+ free: number;
10
+ };
11
+ type TwinInput = {
12
+ r: Random;
13
+ pools: Pools;
14
+ resized: (array: unknown[], key: string, holder?: unknown) => unknown[];
15
+ };
16
+ export type Twin = {
17
+ planOf: (value: unknown, node: ReadNode | undefined, key: string, path: Path) => Plan | undefined;
18
+ vary: (value: unknown, plan: Plan, holderKey?: string, holder?: unknown) => unknown;
19
+ };
20
+ export declare const twinOf: ({ r, pools, resized }: TwinInput) => Twin;
21
+ export {};
@@ -0,0 +1,55 @@
1
+ import { copyOf, fieldOf, isIndex, keysOf } from './reads.js';
2
+ // The chance in a thousand each free field of the second side is redrawn.
3
+ const varyChance = 500;
4
+ // The chance in a hundred a free array of the second side changes length.
5
+ const growChance = 25;
6
+ export const twinOf = ({ r, pools, resized }) => {
7
+ // The path is where the value sits in the input, so its last step names the field a resize keys on.
8
+ const planOf = (value, node, key, path) => {
9
+ const field = path.at(-1) ?? key;
10
+ const isResizable = Array.isArray(value) && !node?.keys.has('length') && !pools.isTuple(path);
11
+ const plan = { numbers: [], strings: [], children: [], resizes: isResizable ? field : undefined, free: 0 };
12
+ for (const each of keysOf(value)) {
13
+ const inner = fieldOf(value, each);
14
+ if (typeof inner === 'number') {
15
+ if (!node?.keys.has(each))
16
+ plan.numbers.push([each, inner]);
17
+ }
18
+ else if (typeof inner === 'string') {
19
+ if (!pools.isTag(key, each) && !node?.keys.has(each))
20
+ plan.strings.push(each);
21
+ }
22
+ else {
23
+ // Only a holder has fields to free, so a boolean or null plans nothing.
24
+ const child = planOf(inner, node?.children.get(each), isIndex(each) ? key : each, path.concat(each));
25
+ if (child) {
26
+ plan.children.push([each, child]);
27
+ plan.free += child.free;
28
+ }
29
+ }
30
+ }
31
+ plan.free += plan.numbers.length + plan.strings.length + (plan.resizes === undefined ? 0 : 1);
32
+ return plan.free ? plan : undefined;
33
+ };
34
+ const vary = (value, plan, holderKey = '', holder) => {
35
+ let copy;
36
+ const set = (key, next) => {
37
+ copy ??= copyOf(value);
38
+ Reflect.set(copy, key, next);
39
+ };
40
+ for (const [key, current] of plan.numbers)
41
+ if (r.int(0, 999) < varyChance)
42
+ set(key, pools.drawNumber(key, current));
43
+ for (const key of plan.strings)
44
+ if (r.int(0, 999) < varyChance)
45
+ set(key, pools.drawString(key, fieldOf(value, key), holderKey));
46
+ for (const [key, child] of plan.children) {
47
+ set(key, vary(fieldOf(value, key), child, isIndex(key) ? holderKey : key, value));
48
+ }
49
+ const varied = copy ?? value;
50
+ if (plan.resizes !== undefined && Array.isArray(varied) && r.int(0, 99) < growChance)
51
+ return resized(varied, plan.resizes, holder);
52
+ return varied;
53
+ };
54
+ return { planOf, vary };
55
+ };
@@ -0,0 +1,32 @@
1
+ import type { Mutation, Project } from '../mutators/mutator.ts';
2
+ import { type Node, type Parsed } from '../utils/ast.ts';
3
+ import { type CrushError } from '../utils/errors.ts';
4
+ import type { Safe } from '../utils/safe.ts';
5
+ import type { ForkPlugin } from './forks.schema.ts';
6
+ type Resolve = (from: string, specifier: string) => string | null;
7
+ export type Forks = {
8
+ plugins: readonly ForkPlugin[];
9
+ resolve: Resolve;
10
+ };
11
+ export declare const placeholderPattern: RegExp;
12
+ export declare const awaitPattern: RegExp;
13
+ export declare const argumentsPattern: RegExp;
14
+ type RemovalInput = {
15
+ removal: string;
16
+ receiver: string | null;
17
+ args: readonly string[];
18
+ };
19
+ export declare const removalOf: ({ removal, receiver, args }: RemovalInput) => Safe<string, CrushError>;
20
+ type PluginSitesInput = {
21
+ path: string;
22
+ source: string;
23
+ parsed: Parsed;
24
+ project: Project;
25
+ bindings: ReadonlyMap<Node, Node>;
26
+ forks: Forks;
27
+ };
28
+ export type PluginSite = Mutation & {
29
+ shown: string;
30
+ };
31
+ export declare const pluginSitesOf: ({ path, source, parsed, project, bindings, forks }: PluginSitesInput) => Safe<PluginSite[], CrushError>;
32
+ export {};
@@ -0,0 +1,134 @@
1
+ import { groupedOf, replace } from '../mutators/mutator.js';
2
+ import { parseSync } from 'oxc-parser';
3
+ import { locate, walk } from '../utils/ast.js';
4
+ import { failed } from '../utils/errors.js';
5
+ // Matches a removal's placeholder: an argument by its position, or a method call's receiver.
6
+ export const placeholderPattern = /(?<![\w$])\$(?:this\b|\d+)/g;
7
+ // Matches an `await` in a removal's text.
8
+ export const awaitPattern = /\bawait\b/;
9
+ // Matches a read of `arguments` in a removal's text.
10
+ export const argumentsPattern = /\barguments\b/;
11
+ // A removal's text in place of one call, each argument evaluated exactly once and in its written order: placed where the removal names it when it names each once, in order, after every one it leaves out, which run first; otherwise bound to a temporary.
12
+ // Every argument and the whole removal sit in parentheses, so no operator in the removal binds across them.
13
+ export const removalOf = ({ removal, receiver, args }) => {
14
+ const given = [...(receiver === null ? [] : [{ name: '$this', text: receiver }]), ...args.map((text, index) => ({ name: `$${index}`, text }))];
15
+ const used = [...removal.matchAll(placeholderPattern)].map(([name]) => name);
16
+ for (const name of used) {
17
+ if (name === '$this' && receiver === null)
18
+ return failed('names $this, but the call has no receiver');
19
+ if (!given.some((each) => each.name === name))
20
+ return failed(`names ${name}, but the call passes ${args.length} argument${args.length === 1 ? '' : 's'}`);
21
+ }
22
+ const tail = given.slice(given.length - used.length).map(({ name }) => name);
23
+ const isInPlace = used.every((name, index) => name === tail[index]);
24
+ if (isInPlace) {
25
+ const placed = removal.replace(placeholderPattern, (name) => `(${given.find((each) => each.name === name)?.text ?? ''})`);
26
+ const unused = given.filter(({ name }) => !used.includes(name)).map(({ text }) => `(${text}), `);
27
+ return { data: `(${unused.join('')}${placed})`, error: null };
28
+ }
29
+ const temporaryOf = (name) => (name === '$this' ? '__this' : `__a${name.slice(1)}`);
30
+ const body = removal.replace(placeholderPattern, (name) => `(${temporaryOf(name)})`);
31
+ const parameters = given.map(({ name }) => temporaryOf(name)).join(', ');
32
+ const values = given.map(({ text }) => text).join(', ');
33
+ // A removal that awaits needs an async temporary, whose promise the call then awaits.
34
+ if (awaitPattern.test(removal))
35
+ return { data: `(await (async (${parameters}) => (${body}))(${values}))`, error: null };
36
+ return { data: `((${parameters}) => (${body}))(${values})`, error: null };
37
+ };
38
+ const nameOf = (node) => (node.type === 'Identifier' ? node.name : node.value);
39
+ // Every module and name an imported binding reaches, following a module that passes the export on, each file asked once.
40
+ const originsOf = ({ project, resolve, path, definition, program }) => {
41
+ const declaration = program.body.find((item) => item.type === 'ImportDeclaration' && item.specifiers.some((specifier) => specifier === definition));
42
+ if (declaration?.type !== 'ImportDeclaration' || definition.type !== 'ImportSpecifier')
43
+ return [];
44
+ const origins = [];
45
+ const seen = new Set();
46
+ const follow = (from, specifier, name) => {
47
+ const module = resolve(from, specifier) ?? specifier;
48
+ if (seen.has(`${module}\0${name}`))
49
+ return;
50
+ seen.add(`${module}\0${name}`);
51
+ origins.push({ module, name });
52
+ for (const item of project.get(module)?.body ?? []) {
53
+ if (item.type !== 'ExportNamedDeclaration' || !item.source)
54
+ continue;
55
+ for (const each of item.specifiers)
56
+ if (nameOf(each.exported) === name)
57
+ follow(module, item.source.value, nameOf(each.local));
58
+ }
59
+ };
60
+ follow(path, declaration.source.value, nameOf(definition.imported));
61
+ return origins;
62
+ };
63
+ // How many syntax and semantic errors oxc finds in a file, the semantic ones catching an `await`, `yield` or `super` where its function cannot hold one.
64
+ const errorsIn = (source, path) => parseSync(path, source, { sourceType: 'module', showSemanticErrors: true }).errors.length;
65
+ const functionTypes = new Set(['FunctionDeclaration', 'FunctionExpression']);
66
+ // Each removal of each plugin a call inside a function reaches, when the call passes the plugin's count of arguments, as a mutation site.
67
+ // A removal is parsed in place, in the whole file, so one that awaits, yields or reads `super` or `new.target` where the call's function cannot refuses the plugin naming the call.
68
+ export const pluginSitesOf = ({ path, source, parsed, project, bindings, forks }) => {
69
+ const { plugins, resolve } = forks;
70
+ if (!plugins.length)
71
+ return { data: [], error: null };
72
+ const at = locate(source);
73
+ const text = (node) => source.slice(node.start, node.end);
74
+ const sites = [];
75
+ // A removal is weighed against the errors the file already has, so only one it brings refuses the plugin.
76
+ const ownErrors = errorsIn(source, path);
77
+ // The plugins a call's callee reaches, with the receiver a method's removal names.
78
+ const matchesOf = (call) => {
79
+ const { callee } = call;
80
+ const named = callee.type === 'MemberExpression' && !callee.computed && callee.object.type === 'Identifier' && callee.property.type === 'Identifier' ? { binding: callee.object, method: callee.property.name } : null;
81
+ const binding = callee.type === 'Identifier' ? callee : named?.binding;
82
+ const definition = binding ? bindings.get(binding) : undefined;
83
+ if (!binding || !definition)
84
+ return [];
85
+ const suffix = named ? `.${named.method}` : '';
86
+ const origins = originsOf({ project, resolve, path, definition, program: parsed.program }).map(({ module, name }) => ({ module, name: `${name}${suffix}` }));
87
+ const isOwn = (plugin) => plugin.arity === call.arguments.length && origins.some(({ module, name }) => module === plugin.export.module && name === plugin.export.name);
88
+ const receiver = named ? text(named.binding) : null;
89
+ return plugins.filter(isOwn).map((plugin) => ({ plugin, receiver }));
90
+ };
91
+ // One plugin's removals at one call, or the refusal naming the first that cannot stand there.
92
+ const removalSitesOf = (visit, node, { plugin, receiver }) => {
93
+ const call = `${path}:${at(node.start).line} \`${text(node)}\``;
94
+ if (node.arguments.some(({ type }) => type === 'SpreadElement'))
95
+ return failed(`fork plugin ${plugin.name} cannot place a spread argument at ${call}`);
96
+ const found = [];
97
+ const args = node.arguments.map(text);
98
+ // An arrow reads `arguments` from the function around it, so one with no other function around it reads none.
99
+ const isInArrowsOnly = !visit.ancestors.some(({ type }) => functionTypes.has(type));
100
+ for (const removal of plugin.removals) {
101
+ const { data: rendered, error: refused } = removalOf({ removal, receiver, args });
102
+ if (refused)
103
+ return failed(`fork plugin ${plugin.name}'s removal \`${removal}\` ${refused.message} at ${call}`);
104
+ const site = replace({ ...visit, source, comments: parsed.comments, path, project, bindings }, node, rendered);
105
+ const applied = `${source.slice(0, site.start)}${site.replacement}${source.slice(site.end)}`;
106
+ if (errorsIn(applied, path) > ownErrors)
107
+ return failed(`fork plugin ${plugin.name}'s removal \`${removal}\` does not parse where it is applied at ${call}`);
108
+ if (argumentsPattern.test(removal) && isInArrowsOnly)
109
+ return failed(`fork plugin ${plugin.name}'s removal \`${removal}\` reads arguments outside a function at ${call}`);
110
+ const shown = removal.replace(placeholderPattern, (name) => groupedOf(name === '$this' ? (receiver ?? '') : text(node.arguments[Number(name.slice(1))] ?? node)));
111
+ found.push({ ...site, shown });
112
+ }
113
+ return { data: found, error: null };
114
+ };
115
+ // The walk cannot return early, so it keeps the first refusal and collects nothing after it.
116
+ const refusals = [];
117
+ walk(parsed.program, (visit) => {
118
+ const { node } = visit;
119
+ if (refusals.length || !visit.inFunction || node.type !== 'CallExpression')
120
+ return;
121
+ for (const match of matchesOf(node)) {
122
+ const { data: found, error } = removalSitesOf(visit, node, match);
123
+ if (error) {
124
+ refusals.push(error);
125
+ return;
126
+ }
127
+ sites.push(...found);
128
+ }
129
+ });
130
+ const [refusal] = refusals;
131
+ if (refusal)
132
+ return { data: null, error: refusal };
133
+ return { data: sites, error: null };
134
+ };
@@ -0,0 +1,20 @@
1
+ import { z } from 'zod';
2
+ export declare const forkPluginInput: z.ZodObject<{
3
+ name: z.ZodString;
4
+ export: z.ZodObject<{
5
+ module: z.ZodString;
6
+ name: z.ZodString;
7
+ }, z.core.$strip>;
8
+ arity: z.ZodNumber;
9
+ removals: z.ZodArray<z.ZodString>;
10
+ }, z.core.$strip>;
11
+ export declare const forkPluginsInput: z.ZodArray<z.ZodObject<{
12
+ name: z.ZodString;
13
+ export: z.ZodObject<{
14
+ module: z.ZodString;
15
+ name: z.ZodString;
16
+ }, z.core.$strip>;
17
+ arity: z.ZodNumber;
18
+ removals: z.ZodArray<z.ZodString>;
19
+ }, z.core.$strip>>;
20
+ export type ForkPlugin = z.infer<typeof forkPluginInput>;
@@ -0,0 +1,14 @@
1
+ import { z } from 'zod';
2
+ // One fork plugin, as a project passes it to the command project: the export whose calls it removes, the count of arguments those calls pass, and each text a removal leaves in place of a call.
3
+ // A helper called in two forms, as data first and data last, gets one plugin per count, so a removal never reads one form's arguments as the other's.
4
+ // A removal names the call's arguments as `$0`, `$1` and so on, and a method call's receiver as `$this`.
5
+ export const forkPluginInput = z.object({
6
+ name: z.string().min(1).max(64),
7
+ export: z.object({
8
+ module: z.string().min(1).max(512),
9
+ name: z.string().min(1).max(256),
10
+ }),
11
+ arity: z.number().int().nonnegative().max(64),
12
+ removals: z.array(z.string().min(1).max(2048)).min(1),
13
+ });
14
+ export const forkPluginsInput = z.array(forkPluginInput);
@@ -0,0 +1,28 @@
1
+ import { type Node, type Parsed } from '../../utils/ast.ts';
2
+ import type { CrushError } from '../../utils/errors.ts';
3
+ import type { Safe } from '../../utils/safe.ts';
4
+ import { type Decision } from '../../decisions/decisions.ts';
5
+ import type { Mutation, Project } from '../../mutators/mutator.ts';
6
+ import type { Listener } from '../walk/walk.ts';
7
+ import { type Paths } from './paths.ts';
8
+ export type { Decision, DecisionKind, Sides } from '../../decisions/decisions.ts';
9
+ export type { Graph, Segment } from './paths.ts';
10
+ export type Site = Mutation & {
11
+ mutator: string;
12
+ owner: string;
13
+ };
14
+ export type Cfg = {
15
+ decisions: Decision[];
16
+ sites: Site[];
17
+ paths: Paths;
18
+ bindings: Map<Node, Node>;
19
+ ownerOf: (start: number) => string;
20
+ };
21
+ export declare const bindingsOf: ({ references, parameters }: Pick<Paths, 'references' | 'parameters'>) => Map<Node, Node>;
22
+ type CfgInput = {
23
+ source: string;
24
+ parsed: Parsed;
25
+ project: Project;
26
+ listeners?: readonly Listener[];
27
+ };
28
+ export declare const cfgOf: ({ source, parsed, project, listeners }: CfgInput) => Safe<Cfg, CrushError>;
@@ -0,0 +1,31 @@
1
+ import { walk } from '../../utils/ast.js';
2
+ import { decisionCollector, ownerAt } from '../../decisions/decisions.js';
3
+ import { partsAt } from '../../mutators/mutators.js';
4
+ import { pathsOf, visitListenerOf } from './paths.js';
5
+ // The node defining the variable each identifier reads or writes, as an import specifier, a declarator or a function declaration.
6
+ // A parameter's definition is the function taking it, never a declaration of its own value, so a parameter binds nothing.
7
+ export const bindingsOf = ({ references, parameters }) => {
8
+ const bound = references.filter(({ variable }) => !parameters.has(variable));
9
+ return new Map(bound.map(({ identifier, definition }) => [identifier, definition]));
10
+ };
11
+ // One walk of the file builds its code paths and scopes and finds its decisions, then a second finds its mutation sites with every identifier bound.
12
+ export const cfgOf = ({ source, parsed, project, listeners = [] }) => {
13
+ const collector = decisionCollector(source, parsed.comments);
14
+ const found = [];
15
+ const { data: paths, error } = pathsOf(parsed, [visitListenerOf(parsed.program, (visit) => collector.visit(visit)), ...listeners]);
16
+ if (error)
17
+ return { data: null, error };
18
+ const bindings = bindingsOf(paths);
19
+ walk(parsed.program, (visit) => {
20
+ if (!visit.inFunction)
21
+ return;
22
+ const context = { ...visit, source, comments: parsed.comments, path: parsed.path, project, bindings };
23
+ for (const { name, mutate } of partsAt(visit.node.type)) {
24
+ for (const mutation of mutate(context))
25
+ found.push({ ...mutation, mutator: name });
26
+ }
27
+ });
28
+ const { decisions, owners } = collector.finish(paths);
29
+ const sites = found.map((site) => Object.assign(site, { owner: ownerAt(owners, site.start) }));
30
+ return { data: { decisions, sites, paths, bindings, ownerOf: (start) => ownerAt(owners, start) }, error: null };
31
+ };
@@ -0,0 +1,27 @@
1
+ import type { Node, Program } from 'oxc-parser';
2
+ import { type Faults } from '../../../utils/faults.ts';
3
+ export type Segment = {
4
+ id: string;
5
+ nodes: Node[];
6
+ reachable: boolean;
7
+ next: string[];
8
+ loops: string[];
9
+ };
10
+ export type Graph = {
11
+ id: string;
12
+ root: Node;
13
+ segments: Segment[];
14
+ initial: string;
15
+ final: string[];
16
+ returned: string[];
17
+ thrown: string[];
18
+ };
19
+ export type CodePaths = {
20
+ graphs: Graph[];
21
+ exits: Map<Node, string[]>;
22
+ };
23
+ export declare const codePathWalker: (program: Program) => CodePaths & {
24
+ faults: Faults;
25
+ enter: (node: Node, parent: Node) => void;
26
+ exit: (node: Node, parent: Node) => void;
27
+ };