@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,52 @@
1
+ import { sameCode } from './equivalence.js';
2
+ import { editOf, keyOf } from './normalize.js';
3
+ // The code of a span with a mutant written into it.
4
+ const appliedTo = (source, span, mutant) => `${source.slice(span.start, mutant.start)}${mutant.replacement}${source.slice(mutant.end, span.end)}`;
5
+ // Whether two mutants of one mutator at overlapping spans write the same tree over the span holding both, which Babel's printing alone cannot tell apart.
6
+ const sameTree = (source, a, b) => {
7
+ if (a.mutator !== b.mutator || a.start > b.end || b.start > a.end)
8
+ return false;
9
+ const span = { start: Math.min(a.start, b.start), end: Math.max(a.end, b.end) };
10
+ return sameCode(appliedTo(source, span, a), appliedTo(source, span, b));
11
+ };
12
+ // Pairs the two lists as multisets of edits, so a change both tools make twice must appear twice on each side.
13
+ // What text leaves unpaired is paired again by tree, so only a mutant no tree on the other side matches stays.
14
+ export const compare = ({ source, stryker, crush, fits }) => {
15
+ const waiting = new Map();
16
+ for (const mutant of crush) {
17
+ const edit = editOf(source, mutant);
18
+ const key = keyOf(edit);
19
+ const list = waiting.get(key);
20
+ if (list)
21
+ list.push(edit);
22
+ else
23
+ waiting.set(key, [edit]);
24
+ }
25
+ let matched = 0;
26
+ const textless = [];
27
+ for (const mutant of stryker) {
28
+ const edit = editOf(source, mutant);
29
+ const list = waiting.get(keyOf(edit)) ?? [];
30
+ const at = list.findIndex((other) => fits(mutant, other.mutant));
31
+ if (at === -1)
32
+ textless.push(edit);
33
+ else {
34
+ list.splice(at, 1);
35
+ matched++;
36
+ }
37
+ }
38
+ const leftover = [...waiting.values()].flat();
39
+ const taken = new Set();
40
+ const onlyStryker = [];
41
+ for (const edit of textless) {
42
+ const partner = leftover.find((other) => !taken.has(other) && fits(edit.mutant, other.mutant) && sameTree(source, edit.mutant, other.mutant));
43
+ if (partner) {
44
+ taken.add(partner);
45
+ matched++;
46
+ }
47
+ else
48
+ onlyStryker.push(edit);
49
+ }
50
+ const byPlace = (a, b) => a.at - b.at;
51
+ return { matched, onlyStryker: onlyStryker.sort(byPlace), onlyCrush: leftover.filter((edit) => !taken.has(edit)).sort(byPlace) };
52
+ };
@@ -0,0 +1,12 @@
1
+ import type { bindingsOf } from '../../../graph/cfg/cfg.ts';
2
+ import type { pathsOf } from '../../../graph/cfg/paths.ts';
3
+ import type { Mutator } from '../../../mutators/mutator.ts';
4
+ import type { parse, walk } from '../../../utils/ast.ts';
5
+ export type Ports = {
6
+ mutators: readonly Mutator[];
7
+ parse: typeof parse;
8
+ walk: typeof walk;
9
+ pathsOf: typeof pathsOf;
10
+ bindingsOf: typeof bindingsOf;
11
+ };
12
+ export declare const portsIn: (src: string) => Promise<Ports>;
@@ -0,0 +1,28 @@
1
+ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
2
+ if (typeof path === "string" && /^\.\.?\//.test(path)) {
3
+ return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
4
+ return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
5
+ });
6
+ }
7
+ return path;
8
+ };
9
+ import { join } from 'node:path';
10
+ import { z } from 'zod';
11
+ const isFunction = (value) => typeof value === 'function';
12
+ const mutatorOutput = z.custom((value) => typeof value === 'object' && value !== null && 'name' in value && typeof value.name === 'string' && 'source' in value && typeof value.source === 'string' && 'parts' in value && Array.isArray(value.parts));
13
+ const portsOutput = z.object({
14
+ mutators: z.array(mutatorOutput),
15
+ parse: z.custom(isFunction),
16
+ walk: z.custom(isFunction),
17
+ pathsOf: z.custom(isFunction),
18
+ bindingsOf: z.custom(isFunction),
19
+ });
20
+ // The ports from any crush `src` folder, as the main tree's while a worktree checks against it, so the import path is known only at run time.
21
+ // Only the wired StrykerJS ports run, since LogicalOperator and OptionalChaining are archived for the crushes that cover them.
22
+ export const portsIn = async (src) => {
23
+ const modules = ['mutators/mutators.ts', 'utils/ast.ts', 'graph/cfg/paths.ts', 'graph/cfg/cfg.ts'];
24
+ const loaded = await Promise.all(modules.map((module) => import(__rewriteRelativeImportExtension(join(src, module)))));
25
+ // oxlint-disable-next-line typescript/no-unsafe-argument -- a module imported by a computed path carries no static type
26
+ const { mutators, ...rest } = portsOutput.parse(Object.assign({}, ...loaded));
27
+ return { ...rest, mutators: mutators.filter((mutator) => mutator.source === 'stryker') };
28
+ };
@@ -0,0 +1 @@
1
+ export declare const sameCode: (a: string, b: string) => boolean;
@@ -0,0 +1,42 @@
1
+ import { parseSync } from 'oxc-parser';
2
+ import { safe } from '../../utils/safe.js';
3
+ // Positions, raw text and Babel's own markers say how code was written, never what it is.
4
+ const layoutKeys = new Set(['start', 'end', 'range', 'loc', 'raw', 'extra']);
5
+ const associative = new Set(['&&', '||']);
6
+ // The operands of a chain of one associative operator, flattened, so `a && (b && c)` and `a && b && c` read alike, as Babel prints both the second way.
7
+ const operandsOf = (node, operator) => {
8
+ if (typeof node !== 'object' || node === null || !('type' in node) || node.type !== 'LogicalExpression' || !('operator' in node) || node.operator !== operator)
9
+ return [node];
10
+ return [...operandsOf('left' in node ? node.left : null, operator), ...operandsOf('right' in node ? node.right : null, operator)];
11
+ };
12
+ // A tree written as what it is: layout dropped, logical chains flattened and regex flags in one order.
13
+ const shapeOf = (value) => {
14
+ if (Array.isArray(value))
15
+ return value.map(shapeOf);
16
+ if (typeof value !== 'object' || value === null)
17
+ return value;
18
+ const operator = 'operator' in value && typeof value.operator === 'string' ? value.operator : '';
19
+ if ('type' in value && value.type === 'LogicalExpression' && associative.has(operator))
20
+ return { type: 'LogicalChain', operator, operands: operandsOf(value, operator).map(shapeOf) };
21
+ const shaped = {};
22
+ for (const [key, child] of Object.entries(value)) {
23
+ if (layoutKeys.has(key))
24
+ continue;
25
+ shaped[key] = key === 'flags' && typeof child === 'string' ? child.split('').toSorted().join('') : shapeOf(child);
26
+ }
27
+ return shaped;
28
+ };
29
+ // The tree of a piece of code read as an expression, or failing that as statements, or null where it parses as neither.
30
+ const treeOf = (code) => {
31
+ for (const wrapped of [`(${code}\n)`, code]) {
32
+ const { data: parsed, error } = safe(() => parseSync('code.ts', wrapped, { preserveParens: false, sourceType: 'module' }));
33
+ if (!error && !parsed.errors.length)
34
+ return JSON.stringify(shapeOf(parsed.program.body));
35
+ }
36
+ return null;
37
+ };
38
+ // Whether two pieces of code are the same tree, so a difference only in how a printer wrote it never counts.
39
+ export const sameCode = (a, b) => {
40
+ const tree = treeOf(a);
41
+ return tree !== null && tree === treeOf(b);
42
+ };
@@ -0,0 +1,29 @@
1
+ import type { Context } from '../../mutators/mutator.ts';
2
+ import type { Edit } from './normalize.ts';
3
+ export type Side = 'stryker' | 'crush';
4
+ export type Site = {
5
+ edit: Edit;
6
+ side: Side;
7
+ contexts: Context[];
8
+ };
9
+ export type Intended = {
10
+ name: string;
11
+ side: Side;
12
+ mutators: ReadonlySet<string>;
13
+ reason: string;
14
+ cite: string;
15
+ applies: (context: Context) => boolean;
16
+ };
17
+ type PairInput = {
18
+ stryker: readonly Edit[];
19
+ crush: readonly Edit[];
20
+ arrows: ReadonlyMap<string, string>;
21
+ };
22
+ type PairOutput = {
23
+ paired: number;
24
+ stryker: Edit[];
25
+ crush: Edit[];
26
+ };
27
+ export declare const pairArrowBodies: ({ stryker, crush, arrows }: PairInput) => PairOutput;
28
+ export declare const explain: ({ edit, side, contexts }: Site) => Intended | null;
29
+ export {};
@@ -0,0 +1,152 @@
1
+ import { decidesPerItem, inForkTest, isDiagnostic } from './rules.js';
2
+ import { portNames, spanKey } from './sides.js';
3
+ const strictEqualities = new Set(['===', '!==']);
4
+ const forkSideParents = new Set(['IfStatement', 'WhileStatement', 'DoWhileStatement', 'ForStatement', 'ForOfStatement', 'ForInStatement']);
5
+ // Crush replaces only an arrow's body with `undefined`, keeping its parameters and `async`, where StrykerJS writes `() => undefined` over the whole arrow (arrow-function.mutator.ts).
6
+ // The two count as one intended mutant only when both exist, the arrow's span mapping to its body's, so a mutant either side lacks stays a port bug.
7
+ export const pairArrowBodies = ({ stryker, crush, arrows }) => {
8
+ const bodies = new Map();
9
+ for (const edit of crush) {
10
+ if (edit.mutator !== 'ArrowFunction' || edit.mutant.replacement !== 'undefined')
11
+ continue;
12
+ const key = spanKey(edit.mutant);
13
+ const list = bodies.get(key);
14
+ if (list)
15
+ list.push(edit);
16
+ else
17
+ bodies.set(key, [edit]);
18
+ }
19
+ const taken = new Set();
20
+ const unpaired = [];
21
+ for (const edit of stryker) {
22
+ const body = edit.mutator === 'ArrowFunction' ? arrows.get(spanKey(edit.mutant)) : undefined;
23
+ const partner = body === undefined ? undefined : bodies.get(body)?.find((candidate) => !taken.has(candidate));
24
+ if (partner)
25
+ taken.add(partner);
26
+ else
27
+ unpaired.push(edit);
28
+ }
29
+ return { paired: taken.size, stryker: unpaired, crush: crush.filter((edit) => !taken.has(edit)) };
30
+ };
31
+ const intended = [
32
+ {
33
+ name: 'fork-test',
34
+ side: 'stryker',
35
+ mutators: new Set(['ConditionalExpression']),
36
+ reason: 'An if, loop or ternary test is forced each way by the fork pass, so its boolean expressions are not forced again.',
37
+ cite: 'src/mutators/conditional-expression.mutator.ts inForkTest',
38
+ applies: (context) => inForkTest(context),
39
+ },
40
+ {
41
+ name: 'fork-test-not',
42
+ side: 'stryker',
43
+ mutators: new Set(['BooleanLiteral']),
44
+ reason: 'A `!` inside a fork test is already forced by the fork pass, so it keeps its `!`.',
45
+ cite: 'src/mutators/boolean-literal.mutator.ts inForkTest',
46
+ applies: (context) => context.node.type === 'UnaryExpression' && inForkTest(context),
47
+ },
48
+ {
49
+ name: 'fork-test-strict-string',
50
+ side: 'stryker',
51
+ mutators: new Set(['StringLiteral']),
52
+ reason: 'A string compared with `===` or `!==` inside a fork test is told apart by forcing the test.',
53
+ cite: 'src/mutators/string-literal.mutator.ts strictEqualities and inForkTest',
54
+ applies: (context) => context.parent.type === 'BinaryExpression' && strictEqualities.has(context.parent.operator) && inForkTest(context),
55
+ },
56
+ {
57
+ name: 'fork-side-block',
58
+ side: 'stryker',
59
+ mutators: new Set(['BlockStatement']),
60
+ reason: 'A fork or loop side is removed whole by force-fork and loop-once, so its block is not emptied again.',
61
+ cite: 'src/mutators/block-statement.mutator.ts sideParents',
62
+ applies: ({ parent }) => forkSideParents.has(parent.type),
63
+ },
64
+ {
65
+ name: 'private-field-constructor',
66
+ side: 'stryker',
67
+ mutators: new Set(['BlockStatement']),
68
+ reason: "A derived constructor stays when its class initializes any field, private ones included, which Babel's ClassProperty check misses, since the field code runs right after `super()`.",
69
+ cite: 'src/mutators/block-statement.mutator.ts hasField',
70
+ applies: ({ ancestors }) => {
71
+ const method = ancestors.at(-2);
72
+ const classBody = ancestors.at(-3);
73
+ if (!method || !classBody || !('kind' in method) || method.kind !== 'constructor' || classBody.type !== 'ClassBody')
74
+ return false;
75
+ return classBody.body.some((member) => member.type === 'PropertyDefinition' && member.value !== null);
76
+ },
77
+ },
78
+ {
79
+ name: 'string-key',
80
+ side: 'stryker',
81
+ mutators: new Set(['StringLiteral']),
82
+ reason: "A string key names a slot, a method's included, so renaming it is left alone.",
83
+ cite: "src/mutators/string-literal.mutator.ts key === 'key'",
84
+ applies: ({ key }) => key === 'key',
85
+ },
86
+ {
87
+ name: 'decorator',
88
+ side: 'crush',
89
+ mutators: portNames,
90
+ reason: 'A decorator and its arguments run when the class is defined, so crush mutates them, where StrykerJS skips every decorator whole; nothing checks crush mutants in these spans.',
91
+ cite: 'src/utils/ast.ts walkTree, which visits Decorator children like any runtime node',
92
+ applies: ({ node, ancestors }) => [...ancestors, node].some((above) => above.type === 'Decorator'),
93
+ },
94
+ {
95
+ name: 'for-update',
96
+ side: 'stryker',
97
+ mutators: new Set(['UpdateOperator']),
98
+ reason: "A for loop's own counter is left to loop-once, which already runs the loop at most once.",
99
+ cite: "src/mutators/update-operator.mutator.ts context.key === 'update'",
100
+ applies: ({ key }) => key === 'update',
101
+ },
102
+ {
103
+ name: 'diagnostic-string',
104
+ side: 'stryker',
105
+ mutators: new Set(['StringLiteral']),
106
+ reason: 'A string only a person reads, inside an error or handed to a parameter read only to build one, holds no behavior.',
107
+ cite: 'src/mutators/string-literal.mutator.ts isDiagnostic',
108
+ applies: isDiagnostic,
109
+ },
110
+ {
111
+ name: 'tagged-template',
112
+ side: 'stryker',
113
+ mutators: new Set(['StringLiteral']),
114
+ reason: "A tagged template's text is the tag's input, not a string, so it is left alone.",
115
+ cite: "src/mutators/string-literal.mutator.ts context.key === 'quasi'",
116
+ applies: ({ key }) => key === 'quasi',
117
+ },
118
+ {
119
+ name: 'per-item-callback',
120
+ side: 'stryker',
121
+ mutators: new Set(['ArrowFunction']),
122
+ reason: "A per-item callback's answer is forced each way by the callback crush, so its arrow is not replaced.",
123
+ cite: 'src/mutators/arrow-function.mutator.ts decidesPerItem',
124
+ applies: ({ parent }) => decidesPerItem(parent),
125
+ },
126
+ {
127
+ name: 'logical-operator-crushed',
128
+ side: 'stryker',
129
+ mutators: new Set(['LogicalOperator']),
130
+ reason: 'Crush has no LogicalOperator port: force-fork forces each logical operand each way and drop-operand removes each, which tell apart what swapping the operator would; nothing compares those crushes with these mutants.',
131
+ cite: 'src/crushes/force-fork.crush.ts and src/crushes/drop-operand.crush.ts',
132
+ applies: ({ node }) => node.type === 'LogicalExpression',
133
+ },
134
+ {
135
+ name: 'optional-chaining-crushed',
136
+ side: 'stryker',
137
+ mutators: new Set(['OptionalChaining']),
138
+ reason: 'Crush has no OptionalChaining port: the optional-chain crush forces each optional link present and absent, zero-argument optional calls included; nothing compares that crush with these mutants.',
139
+ cite: 'src/crushes/optional-chain.crush.ts',
140
+ applies: ({ node }) => (node.type === 'MemberExpression' || node.type === 'CallExpression') && node.optional,
141
+ },
142
+ {
143
+ name: 'runtime-type-expression',
144
+ side: 'crush',
145
+ mutators: portNames,
146
+ reason: 'The value under `as` and an enum member run, so crush mutates them, where StrykerJS skips a TSAsExpression or TSEnumDeclaration whole; nothing checks crush mutants in these spans.',
147
+ cite: 'src/utils/ast.ts runtimeTypes',
148
+ applies: ({ node, ancestors }) => [...ancestors, node].some((above) => above.type === 'TSAsExpression' || above.type === 'TSEnumDeclaration'),
149
+ },
150
+ ];
151
+ // The first intended difference explaining a site, or null for a port bug.
152
+ export const explain = ({ edit, side, contexts }) => intended.find((entry) => entry.side === side && entry.mutators.has(edit.mutator) && contexts.some(entry.applies)) ?? null;
@@ -0,0 +1,27 @@
1
+ export type Mutant = {
2
+ mutator: string;
3
+ start: number;
4
+ end: number;
5
+ replacement: string;
6
+ };
7
+ export type Edit = {
8
+ mutator: string;
9
+ at: number;
10
+ removed: string;
11
+ added: string;
12
+ mutant: Mutant;
13
+ };
14
+ type Canonical = {
15
+ text: string;
16
+ offsets: number[];
17
+ };
18
+ export declare const spacePattern: RegExp;
19
+ export declare const closerPattern: RegExp;
20
+ export declare const leadingPipePattern: RegExp;
21
+ export declare const loneParameterPattern: RegExp;
22
+ export declare const regexStartPattern: RegExp;
23
+ export declare const canonical: (code: string, base: number) => Canonical;
24
+ export declare const editOf: (source: string, mutant: Mutant) => Edit;
25
+ export declare const isMinified: (source: string) => boolean;
26
+ export declare const keyOf: ({ mutator, at, removed, added }: Edit) => string;
27
+ export {};
@@ -0,0 +1,181 @@
1
+ import { itemAt } from '../../utils/lookup.js';
2
+ const quotes = new Set(["'", '"']);
3
+ // Matches one whitespace character.
4
+ export const spacePattern = /\s/;
5
+ // Matches one character of a word: a name, a keyword or a number.
6
+ const wordPattern = /[\w$]/;
7
+ // Matches code that closes a bracket next, after any whitespace, which makes a comma before it trailing.
8
+ export const closerPattern = /^\s*[)\]}]/;
9
+ // Matches code ending where a type begins, after `as`, `:`, `<`, `=`, `,` or `(`, where a union's leading `|` Babel leaves out may follow.
10
+ export const leadingPipePattern = /(?:\bas|[:<=,(])\s*$/;
11
+ // Matches a lone arrow parameter in parentheses, as `(x) =>`, which Babel prints bare.
12
+ export const loneParameterPattern = /\(\s*([\w$]+)\s*\)(?=\s*=>)/y;
13
+ // Matches code ending where a value is expected, so a `/` after it opens a regex rather than dividing.
14
+ export const regexStartPattern = /(?:^|[^\w$)\]\s]|(?:^|[^\w$.])(?:return|typeof|case|do|else|in|of|new|delete|void|throw|instanceof|yield|await))\s*$/;
15
+ // Babel ends every statement with a semicolon and drops a trailing comma, so neither tells two mutants apart.
16
+ const dropped = new Set([';']);
17
+ // The index just past the string opened at `from`, skipping escaped characters.
18
+ const closingOf = (code, from) => {
19
+ const quote = code.charAt(from);
20
+ let at = from + 1;
21
+ while (at < code.length && code.charAt(at) !== quote)
22
+ at += code.charAt(at) === '\\' ? 2 : 1;
23
+ return Math.min(at + 1, code.length);
24
+ };
25
+ // The index just past the regex body opened at `from`, or -1 where no closing `/` comes before the line ends.
26
+ const regexEndOf = (code, from) => {
27
+ let isInClass = false;
28
+ for (let at = from + 1; at < code.length; at++) {
29
+ const char = code.charAt(at);
30
+ if (char === '\n')
31
+ return -1;
32
+ if (char === '\\')
33
+ at++;
34
+ else if (char === '[')
35
+ isInClass = true;
36
+ else if (char === ']')
37
+ isInClass = false;
38
+ else if (char === '/' && !isInClass)
39
+ return at + 1;
40
+ }
41
+ return -1;
42
+ };
43
+ // A single-quoted string holding no double quote reads the same in double quotes, the form Babel prints.
44
+ const requoted = (literal) => (literal.startsWith("'") && !literal.includes('"') ? `"${literal.slice(1, -1)}"` : literal);
45
+ // Two words, or two signs that would read as `++` or `--`, need the space between them kept.
46
+ const joins = (before, after) => (wordPattern.test(before) && wordPattern.test(after)) || ((before === '+' || before === '-') && before === after);
47
+ export const canonical = (code, base) => {
48
+ let text = '';
49
+ const offsets = [];
50
+ let isSeparated = false;
51
+ // A kept space takes the offset of the character after it.
52
+ const emit = (chars, offset) => {
53
+ if (isSeparated && text && chars && joins(text.charAt(text.length - 1), chars.charAt(0))) {
54
+ text += ' ';
55
+ offsets.push(base + offset(0));
56
+ }
57
+ isSeparated = false;
58
+ text += chars;
59
+ for (let index = 0; index < chars.length; index++)
60
+ offsets.push(base + offset(index));
61
+ };
62
+ const keep = (from, to) => emit(code.slice(from, to), (index) => from + index);
63
+ // Template text is kept as written up to its close or its next `${`, whose code is read like any other until its matching `}`.
64
+ const depths = [];
65
+ let at = 0;
66
+ const readTemplateText = () => {
67
+ let end = at;
68
+ while (end < code.length && code.charAt(end) !== '`' && code.slice(end, end + 2) !== '${')
69
+ end += code.charAt(end) === '\\' ? 2 : 1;
70
+ const isOpening = code.slice(end, end + 2) === '${';
71
+ const stop = Math.min(end + (isOpening ? 2 : 1), code.length);
72
+ keep(at, stop);
73
+ if (isOpening)
74
+ depths.push(0);
75
+ at = stop;
76
+ };
77
+ while (at < code.length) {
78
+ const char = code.charAt(at);
79
+ const pair = code.slice(at, at + 2);
80
+ const depth = depths.at(-1);
81
+ loneParameterPattern.lastIndex = at;
82
+ const lone = char === '(' ? loneParameterPattern.exec(code) : null;
83
+ const regexEnd = char === '/' && pair !== '//' && pair !== '/*' && regexStartPattern.test(code.slice(Math.max(0, at - 16), at)) ? regexEndOf(code, at) : -1;
84
+ if (char === '`') {
85
+ keep(at, at + 1);
86
+ at++;
87
+ readTemplateText();
88
+ }
89
+ else if (depth !== undefined && (char === '{' || char === '}')) {
90
+ keep(at, at + 1);
91
+ at++;
92
+ if (char === '{')
93
+ depths[depths.length - 1] = depth + 1;
94
+ else if (depth > 0)
95
+ depths[depths.length - 1] = depth - 1;
96
+ else {
97
+ depths.pop();
98
+ readTemplateText();
99
+ }
100
+ }
101
+ else if (quotes.has(char)) {
102
+ const close = closingOf(code, at);
103
+ const start = at;
104
+ emit(requoted(code.slice(at, close)), (index) => start + Math.min(index, close - start - 1));
105
+ at = close;
106
+ }
107
+ else if (lone) {
108
+ const [whole, name = ''] = lone;
109
+ const start = at + whole.indexOf(name);
110
+ emit(name, (index) => start + index);
111
+ at += whole.length;
112
+ isSeparated = true;
113
+ }
114
+ else if (regexEnd !== -1) {
115
+ // A regex is kept whole, its flags in one order, since a regex reads its flags in any order.
116
+ let flagsEnd = regexEnd;
117
+ while (flagsEnd < code.length && wordPattern.test(code.charAt(flagsEnd)))
118
+ flagsEnd++;
119
+ const flags = code.slice(regexEnd, flagsEnd).split('').toSorted().join('');
120
+ const start = at;
121
+ emit(`${code.slice(at, regexEnd)}${flags}`, (index) => start + index);
122
+ at = flagsEnd;
123
+ }
124
+ else if (pair === '//') {
125
+ const newline = code.indexOf('\n', at);
126
+ at = newline === -1 ? code.length : newline;
127
+ isSeparated = true;
128
+ }
129
+ else if (pair === '/*') {
130
+ const close = code.indexOf('*/', at + 2);
131
+ at = close === -1 ? code.length : close + 2;
132
+ isSeparated = true;
133
+ }
134
+ else if (spacePattern.test(char) || dropped.has(char) || (char === ',' && closerPattern.test(code.slice(at + 1))) || (pair === '| ' && leadingPipePattern.test(code.slice(Math.max(0, at - 32), at)))) {
135
+ at++;
136
+ isSeparated = true;
137
+ }
138
+ else {
139
+ keep(at, at + 1);
140
+ at++;
141
+ }
142
+ }
143
+ return { text, offsets };
144
+ };
145
+ // The mutant's change with the text both sides share at either end cut away, placed at the first source offset that differs.
146
+ export const editOf = (source, mutant) => {
147
+ const { mutator, start, end, replacement } = mutant;
148
+ const original = canonical(source.slice(start, end), start);
149
+ const changed = canonical(replacement, 0).text;
150
+ const shorter = Math.min(original.text.length, changed.length);
151
+ let prefix = 0;
152
+ while (prefix < shorter && original.text.charAt(prefix) === changed.charAt(prefix))
153
+ prefix++;
154
+ let suffix = 0;
155
+ while (suffix < shorter - prefix && original.text.charAt(original.text.length - 1 - suffix) === changed.charAt(changed.length - 1 - suffix))
156
+ suffix++;
157
+ // A pure deletion beside repeated text, as `?.filter(f)` before `?.map(g)`, can sit at several places, so it slides to the leftmost one.
158
+ const width = original.text.length - suffix - prefix;
159
+ if (changed.length === prefix + suffix) {
160
+ while (prefix > 0 && original.text.charAt(prefix - 1) === original.text.charAt(prefix - 1 + width)) {
161
+ prefix--;
162
+ suffix++;
163
+ }
164
+ }
165
+ const removed = original.text.slice(prefix, original.text.length - suffix);
166
+ const kept = original.offsets[prefix - 1];
167
+ const at = removed ? itemAt(original.offsets, prefix) : anchorOf(source, kept === undefined ? start : kept + 1);
168
+ return { mutator, at, removed, added: changed.slice(prefix, changed.length - suffix), mutant };
169
+ };
170
+ // A pure insertion sits just past the last source character canonical keeps before it, so `for (;;)` takes `false` at one place whichever semicolon a tool wrote it after.
171
+ const anchorOf = (source, from) => {
172
+ let at = from;
173
+ while (at > 0 && (spacePattern.test(source.charAt(at - 1)) || dropped.has(source.charAt(at - 1))))
174
+ at--;
175
+ return at;
176
+ };
177
+ // Hand-written code averages well under this many characters a line, where a minified bundle runs to thousands.
178
+ const minifiedLineLength = 500;
179
+ // Whether a file reads as a minified bundle, by its average line length.
180
+ export const isMinified = (source) => source.length / source.split('\n').length > minifiedLineLength;
181
+ export const keyOf = ({ mutator, at, removed, added }) => `${mutator}\u0000${at}\u0000${removed}\u0000${added}`;
@@ -0,0 +1,6 @@
1
+ import { type Node } from 'oxc-parser';
2
+ import type { Context } from '../../mutators/mutator.ts';
3
+ export declare const inForkTest: ({ ancestors, node }: Context) => boolean;
4
+ export declare const decidesPerItem: (parent: Node) => boolean;
5
+ export declare const errorClassPattern: RegExp;
6
+ export declare const isDiagnostic: (context: Context) => boolean;
@@ -0,0 +1,116 @@
1
+ import { posix } from 'node:path';
2
+ import { visitorKeys } from 'oxc-parser';
3
+ // The rules behind the intended differences, stated here on their own rather than imported from the crush code they describe.
4
+ // An import would carry a bug planted in that code into its own excuse, so the check would report nothing.
5
+ const forkTypes = new Set(['IfStatement', 'ConditionalExpression', 'WhileStatement', 'DoWhileStatement', 'ForStatement']);
6
+ // Whether a node sits inside the test of an if, ternary, while, do-while or for.
7
+ export const inForkTest = ({ ancestors, node }) => {
8
+ const path = [...ancestors, node];
9
+ return path.some((above, index) => forkTypes.has(above.type) && index + 1 < path.length && 'test' in above && above.test === path[index + 1]);
10
+ };
11
+ const perItemMethods = new Set(['filter', 'some', 'every', 'find', 'findIndex', 'findLast', 'findLastIndex']);
12
+ // Whether a callback is handed to a per-item method named plainly, as `xs.filter(f)`, whose answer decides per item.
13
+ export const decidesPerItem = (parent) => {
14
+ if (parent.type !== 'CallExpression' || parent.callee.type !== 'MemberExpression' || parent.callee.computed)
15
+ return false;
16
+ const { property } = parent.callee;
17
+ return property.type === 'Identifier' && perItemMethods.has(property.name);
18
+ };
19
+ // Matches an error class's name, as `Error` or `RangeError`.
20
+ export const errorClassPattern = /Error$/;
21
+ // Whether a node builds an error: a throw, or a plain-named error class called or constructed.
22
+ const buildsError = (node) => node.type === 'ThrowStatement' || ((node.type === 'NewExpression' || node.type === 'CallExpression') && node.callee.type === 'Identifier' && errorClassPattern.test(node.callee.name));
23
+ const isNode = (value) => typeof value === 'object' && value !== null && 'type' in value && typeof value.type === 'string';
24
+ // Every identifier named `name` under a node, beside whether some node above it, within that subtree, builds an error.
25
+ const readsOf = (root, name) => {
26
+ const found = [];
27
+ const visit = (node, isInError) => {
28
+ const inError = isInError || buildsError(node);
29
+ if (node.type === 'Identifier' && node.name === name)
30
+ found.push(inError);
31
+ for (const key of visitorKeys[node.type] ?? []) {
32
+ const held = Reflect.get(node, key);
33
+ for (const child of [held].flat()) {
34
+ if (isNode(child))
35
+ visit(child, inError);
36
+ }
37
+ }
38
+ };
39
+ visit(root, false);
40
+ return found;
41
+ };
42
+ const isCallable = (node) => node?.type === 'ArrowFunctionExpression' || node?.type === 'FunctionExpression' || node?.type === 'FunctionDeclaration';
43
+ // The function a declaration names `name`, as `function name` or `const name = () => ...`.
44
+ const functionNamed = (node, name) => {
45
+ if (node.type === 'FunctionDeclaration')
46
+ return node.id?.name === name ? node : undefined;
47
+ if (node.type === 'VariableDeclaration')
48
+ return node.declarations.map((declarator) => functionNamed(declarator, name)).find(Boolean);
49
+ if (node.type !== 'VariableDeclarator' || node.id.type !== 'Identifier' || node.id.name !== name)
50
+ return undefined;
51
+ return isCallable(node.init) ? node.init : undefined;
52
+ };
53
+ const exportedName = (node) => (node.type === 'Identifier' ? node.name : node.type === 'Literal' ? String(node.value) : '');
54
+ // The project file a relative specifier names from a file, or null for a package.
55
+ const targetOf = (from, specifier) => (specifier.startsWith('./') || specifier.startsWith('../') ? posix.join(posix.dirname(from), specifier) : null);
56
+ // The function a project file exports as `name`, declared there, re-exported from a local, or re-exported from another file, each file read once.
57
+ const exportedFunction = ({ project, path, name, seen }) => {
58
+ const program = project.get(path);
59
+ if (!program || seen.has(path))
60
+ return undefined;
61
+ const next = new Set([...seen, path]);
62
+ for (const item of program.body) {
63
+ if (item.type !== 'ExportNamedDeclaration')
64
+ continue;
65
+ const declared = item.declaration ? functionNamed(item.declaration, name) : undefined;
66
+ if (declared)
67
+ return declared;
68
+ const specifier = item.specifiers.find((each) => exportedName(each.exported) === name);
69
+ if (!specifier)
70
+ continue;
71
+ const local = exportedName(specifier.local);
72
+ if (item.source) {
73
+ const target = targetOf(path, item.source.value);
74
+ return target === null ? undefined : exportedFunction({ project, path: target, name: local, seen: next });
75
+ }
76
+ return program.body.map((each) => functionNamed(each, local)).find(Boolean) ?? importedFunction({ project, path, local, seen: next });
77
+ }
78
+ return undefined;
79
+ };
80
+ // The function a file's named import of `local` binds, read from the file it imports.
81
+ const importedFunction = ({ project, path, local, seen }) => {
82
+ const program = project.get(path);
83
+ for (const item of program ? program.body : []) {
84
+ if (item.type !== 'ImportDeclaration')
85
+ continue;
86
+ const specifier = item.specifiers.find((each) => each.type === 'ImportSpecifier' && each.local.name === local);
87
+ if (specifier?.type !== 'ImportSpecifier')
88
+ continue;
89
+ const target = targetOf(path, item.source.value);
90
+ return target === null ? undefined : exportedFunction({ project, path: target, name: exportedName(specifier.imported), seen });
91
+ }
92
+ return undefined;
93
+ };
94
+ // The function a plain callee names: the one its binding declares, or the one a named import of it brings in.
95
+ const calleeFunction = ({ bindings, project, path }, callee) => {
96
+ const definition = bindings.get(callee);
97
+ if (!definition)
98
+ return undefined;
99
+ if (definition.type === 'ImportSpecifier')
100
+ return importedFunction({ project, path, local: callee.name, seen: new Set() });
101
+ return functionNamed(definition, callee.name);
102
+ };
103
+ // Whether a string is only a person's to read: inside an error being built, or handed to a parameter its named function reads, and reads only to build an error.
104
+ export const isDiagnostic = (context) => {
105
+ const { node, parent, key, ancestors } = context;
106
+ if (ancestors.some(buildsError))
107
+ return true;
108
+ if (parent.type !== 'CallExpression' || key !== 'arguments' || parent.callee.type !== 'Identifier')
109
+ return false;
110
+ const fn = calleeFunction(context, parent.callee);
111
+ const param = fn?.params[parent.arguments.findIndex((argument) => argument === node)];
112
+ if (!fn || param?.type !== 'Identifier')
113
+ return false;
114
+ const reads = readsOf(fn.body ?? fn, param.name);
115
+ return reads.length > 0 && reads.every(Boolean);
116
+ };