@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 @@
1
+ export {};
@@ -0,0 +1,12 @@
1
+ import { inject, it } from 'vite-plus/test';
2
+ import { stressesIn } from '../stresses/edges/stresses.record.js';
3
+ import { recordPathOf, rootProvideKey } from './edges/vitest.js';
4
+ import { phaseRootInput } from './judge.schema.js';
5
+ // How many tests each mutator and the crushes drive, read from the saved record and printed one line per check straight to the terminal, since Vitest shows neither a passing test's annotations nor its console output.
6
+ const root = phaseRootInput.parse(inject(rootProvideKey));
7
+ it('stresses', () => {
8
+ const { data: rows, error } = stressesIn(recordPathOf(root));
9
+ if (error)
10
+ throw error;
11
+ process.stdout.write(rows.map(({ check, cases, caught, mutants }) => `${check}: ${cases} cases, ${caught}/${mutants} caught\n`).join(''));
12
+ });
@@ -0,0 +1,14 @@
1
+ import type { Justification } from '../justify/justify.schema.ts';
2
+ export type CrushTaskMeta = {
3
+ answers?: string | string[];
4
+ justifies?: Justification[];
5
+ keeps?: string;
6
+ steps?: number;
7
+ stepsReason?: string;
8
+ explores?: string;
9
+ twin?: {
10
+ first: string;
11
+ second: string;
12
+ related: string;
13
+ };
14
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ import type { RunnerTestFile } from 'vite-plus/test';
2
+ import type { Safe } from '../../utils/safe.ts';
3
+ import { type LocatedJustification } from '../justify.schema.ts';
4
+ export declare const suiteJustificationsOf: (file: string, tree: RunnerTestFile, isLiteral: (entries: object) => boolean) => Safe<LocatedJustification[]>;
5
+ export declare const readJustifications: (runs: {
6
+ justifications?: LocatedJustification[];
7
+ }[]) => Safe<LocatedJustification[]>;
@@ -0,0 +1,40 @@
1
+ import { failed } from '../../utils/errors.js';
2
+ import { duplicateOf } from '../justify.operations.js';
3
+ import { justificationList } from '../justify.schema.js';
4
+ export const suiteJustificationsOf = (file, tree, isLiteral) => {
5
+ const entries = [];
6
+ const visit = (suite, path, ancestry) => {
7
+ const separator = suite === tree ? '::' : ' > ';
8
+ for (const [suiteIndex, task] of suite.tasks.entries()) {
9
+ if (task.type !== 'suite')
10
+ continue;
11
+ const title = `${path}${separator}${task.name}`;
12
+ const suitePosition = [...ancestry, suiteIndex];
13
+ const declared = task.meta.justifies;
14
+ if (declared !== undefined && declared !== suite.meta.justifies) {
15
+ const parsed = justificationList.safeParse(declared);
16
+ if (!parsed.success)
17
+ return failed(`${title} meta.justifies must list { id, basis, reason }: ${parsed.error.message}`).error;
18
+ if (!isLiteral(declared))
19
+ return failed(`${title} must declare meta.justifies as an inline literal array`).error;
20
+ for (const [index, entry] of parsed.data.entries()) {
21
+ const position = JSON.stringify([file, suitePosition, index]);
22
+ entries.push({ ...entry, path: title, position });
23
+ }
24
+ }
25
+ const error = visit(task, title, suitePosition);
26
+ if (error)
27
+ return error;
28
+ }
29
+ return null;
30
+ };
31
+ const error = visit(tree, file, []);
32
+ return error ? { data: null, error } : { data: entries, error: null };
33
+ };
34
+ export const readJustifications = (runs) => {
35
+ const entries = runs.flatMap(({ justifications }) => justifications ?? []);
36
+ const duplicate = duplicateOf(entries);
37
+ if (duplicate)
38
+ return failed(`${duplicate.paths[0]} and ${duplicate.paths[1]} both justify ${duplicate.id}; keep one entry`);
39
+ return { data: entries, error: null };
40
+ };
@@ -0,0 +1,8 @@
1
+ type RefreshEntryInput = {
2
+ root: string;
3
+ id: string;
4
+ position: string;
5
+ basis: string;
6
+ };
7
+ export declare const refreshEntry: ({ root, id, position, basis }: RefreshEntryInput) => string | null;
8
+ export {};
@@ -0,0 +1,15 @@
1
+ import { readFileSync, writeFileSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { z } from 'zod';
4
+ import { refreshedSourceOf } from '../justify.operations.js';
5
+ const positionInput = z.tuple([z.string()]).rest(z.unknown());
6
+ // Writes the printed basis into the one entry naming the id in its test file, answering why when no entry there names it.
7
+ export const refreshEntry = ({ root, id, position, basis }) => {
8
+ const [file] = positionInput.parse(JSON.parse(position));
9
+ const path = join(root, file);
10
+ const refreshed = refreshedSourceOf({ source: readFileSync(path, 'utf8'), path: file, id, basis });
11
+ if (refreshed === null)
12
+ return `no literal entry in ${file} names it, so set its basis by hand`;
13
+ writeFileSync(path, refreshed);
14
+ return null;
15
+ };
@@ -0,0 +1,46 @@
1
+ import type { Justification, LocatedJustification } from './justify.schema.ts';
2
+ type Justifiable = {
3
+ id: string;
4
+ file: string;
5
+ sites: string[];
6
+ };
7
+ type BasisInput = {
8
+ question: Justifiable;
9
+ sourceHashes: ReadonlyMap<string, string>;
10
+ bases: ReadonlyMap<string, ReadonlySet<string>>;
11
+ position?: string;
12
+ };
13
+ export declare const basisOf: ({ question, sourceHashes, bases, position }: BasisInput) => string;
14
+ type JustifiedInput = Omit<BasisInput, 'question' | 'position'> & {
15
+ entries: (Justification & {
16
+ path?: string;
17
+ position?: string;
18
+ })[];
19
+ questions: Justifiable[];
20
+ };
21
+ export type Judged = Justification & {
22
+ position?: string;
23
+ current: string;
24
+ };
25
+ export type JustifyProblem = {
26
+ id: string;
27
+ problem: string;
28
+ };
29
+ type JustifiedOutput = {
30
+ accepted: Judged[];
31
+ stale: Judged[];
32
+ problems: JustifyProblem[];
33
+ };
34
+ export declare const justifiedOf: ({ entries, questions, sourceHashes, bases }: JustifiedInput) => JustifiedOutput;
35
+ type RefreshInput = {
36
+ source: string;
37
+ path: string;
38
+ id: string;
39
+ basis: string;
40
+ };
41
+ export declare const refreshedSourceOf: ({ source, path, id, basis }: RefreshInput) => string | null;
42
+ export declare const duplicateOf: (entries: LocatedJustification[]) => {
43
+ id: string;
44
+ paths: [string, string];
45
+ } | null;
46
+ export {};
@@ -0,0 +1,80 @@
1
+ import { hashOf } from '../record/record.operations.js';
2
+ import { parse, walk } from '../utils/ast.js';
3
+ import { entryAt } from '../utils/lookup.js';
4
+ // A question's basis covers its source, its verdicts' reads, and the slot of a written justification.
5
+ export const basisOf = ({ question, sourceHashes, bases, position }) => {
6
+ const read = new Set(question.sites.flatMap((site) => [...(bases.get(site) ?? [])]));
7
+ const source = entryAt(sourceHashes, question.file, `the hash of ${question.file}`);
8
+ const digests = [...read].toSorted();
9
+ return hashOf(JSON.stringify(position === undefined ? [source, digests] : [source, digests, position]));
10
+ };
11
+ // Each entry against the run: one naming no question crush asks is a problem, one whose basis is the question's basis now is accepted, and any other is stale and asks again until its basis is set to the one printed.
12
+ // The basis lives in the entry itself, so a fresh record never accepts an entry written against other code.
13
+ export const justifiedOf = ({ entries, questions, sourceHashes, bases }) => {
14
+ const byId = new Map(questions.map((question) => [question.id, question]));
15
+ const output = { accepted: [], stale: [], problems: [] };
16
+ for (const entry of entries) {
17
+ const question = byId.get(entry.id);
18
+ if (!question) {
19
+ output.problems.push({ id: entry.id, problem: 'names no question crush asks, so remove this meta.justifies entry' });
20
+ continue;
21
+ }
22
+ const current = basisOf({ question, sourceHashes, bases, position: entry.position ?? entry.path });
23
+ const judged = { ...entry, current };
24
+ if (entry.basis === current)
25
+ output.accepted.push(judged);
26
+ else
27
+ output.stale.push(judged);
28
+ }
29
+ return output;
30
+ };
31
+ // A string written as a quoted literal or a template with no substitutions, the two forms an entry's id and basis take.
32
+ const textOf = (node) => {
33
+ if (node.type === 'Literal')
34
+ return typeof node.value === 'string' ? node.value : null;
35
+ if (node.type !== 'TemplateLiteral' || node.expressions.length)
36
+ return null;
37
+ const [quasi] = node.quasis;
38
+ return quasi ? quasi.value.cooked : null;
39
+ };
40
+ const keyOf = (node) => (node.type === 'Identifier' ? node.name : textOf(node));
41
+ // The test file's source with the `refresh` basis of the one entry naming the id set to the given one, or null when no such entry names it.
42
+ // The entry is found in the parsed source as an element of a call's `meta.justifies` array, so braces or basis text inside a string, or a fixture shaped like an entry, never move it.
43
+ export const refreshedSourceOf = ({ source, path, id, basis }) => {
44
+ const { data: parsed, error } = parse(source, path);
45
+ if (error)
46
+ return null;
47
+ const spans = [];
48
+ walk(parsed.program, ({ node, parent, ancestors }) => {
49
+ if (node.type !== 'ObjectExpression' || parent.type !== 'ArrayExpression')
50
+ return;
51
+ const holder = ancestors.at(-2);
52
+ const meta = ancestors.at(-4);
53
+ if (holder?.type !== 'Property' || keyOf(holder.key) !== 'justifies')
54
+ return;
55
+ if (meta?.type !== 'Property' || keyOf(meta.key) !== 'meta')
56
+ return;
57
+ if (ancestors.at(-6)?.type !== 'CallExpression')
58
+ return;
59
+ const values = new Map(node.properties.flatMap((property) => (property.type === 'Property' && !property.computed ? [[keyOf(property.key), property.value]] : [])));
60
+ const named = values.get('id');
61
+ const held = values.get('basis');
62
+ if (named && held && textOf(named) === id && textOf(held) === 'refresh')
63
+ spans.push(held);
64
+ });
65
+ // Two entries naming one id leave the one to write unknown, so neither is written.
66
+ const [span, second] = spans;
67
+ if (!span || second)
68
+ return null;
69
+ return source.slice(0, span.start + 1) + basis + source.slice(span.end - 1);
70
+ };
71
+ export const duplicateOf = (entries) => {
72
+ const seen = new Map();
73
+ for (const { id, path } of entries) {
74
+ const first = seen.get(id);
75
+ if (first)
76
+ return { id, paths: [first, path] };
77
+ seen.set(id, path);
78
+ }
79
+ return null;
80
+ };
@@ -0,0 +1,21 @@
1
+ import { z } from 'zod';
2
+ export declare const basisPattern: RegExp;
3
+ export declare const justificationInput: z.ZodObject<{
4
+ id: z.ZodString;
5
+ basis: z.ZodUnion<readonly [z.ZodString, z.ZodLiteral<"refresh">]>;
6
+ reason: z.ZodString;
7
+ }, z.core.$strip>;
8
+ export declare const justificationList: z.ZodArray<z.ZodObject<{
9
+ id: z.ZodString;
10
+ basis: z.ZodUnion<readonly [z.ZodString, z.ZodLiteral<"refresh">]>;
11
+ reason: z.ZodString;
12
+ }, z.core.$strip>>;
13
+ export type Justification = z.infer<typeof justificationInput>;
14
+ export declare const locatedJustificationInput: z.ZodObject<{
15
+ id: z.ZodString;
16
+ basis: z.ZodUnion<readonly [z.ZodString, z.ZodLiteral<"refresh">]>;
17
+ reason: z.ZodString;
18
+ path: z.ZodString;
19
+ position: z.ZodOptional<z.ZodString>;
20
+ }, z.core.$strip>;
21
+ export type LocatedJustification = z.infer<typeof locatedJustificationInput>;
@@ -0,0 +1,11 @@
1
+ import { z } from 'zod';
2
+ import { questionId } from '../questions/questions.schema.js';
3
+ // Matches a basis, a sha-256 hash in hex as the report prints it.
4
+ export const basisPattern = /^[0-9a-f]{64}$/;
5
+ export const justificationInput = z.object({
6
+ id: questionId,
7
+ basis: z.union([z.string().regex(basisPattern), z.literal('refresh')]),
8
+ reason: z.string().trim().min(1).max(1024),
9
+ });
10
+ export const justificationList = z.array(justificationInput);
11
+ export const locatedJustificationInput = justificationInput.extend({ path: z.string(), position: z.string().optional() });
@@ -0,0 +1,2 @@
1
+ import { type Mutator } from './mutator.ts';
2
+ export declare const arithmeticOperator: Mutator;
@@ -0,0 +1,22 @@
1
+ import { holdsText, on, splice } from './mutator.js';
2
+ const arithmetic = new Map([
3
+ ['+', '-'],
4
+ ['-', '+'],
5
+ ['*', '/'],
6
+ ['/', '*'],
7
+ ['%', '*'],
8
+ ]);
9
+ // A chain like `'a' + b + c` checks the operand beside the operator, so the string test reads the left side's right operand.
10
+ export const arithmeticOperator = {
11
+ name: 'ArithmeticOperator',
12
+ source: 'stryker',
13
+ parts: [
14
+ on('BinaryExpression', (node, context) => {
15
+ const swap = arithmetic.get(node.operator);
16
+ const left = node.left.type === 'BinaryExpression' ? node.left.right : node.left;
17
+ if (!swap || holdsText(node.right) || holdsText(left))
18
+ return [];
19
+ return [splice(context, node, node.left.end, node.operator, swap)];
20
+ }),
21
+ ],
22
+ };
@@ -0,0 +1,2 @@
1
+ import { type Mutator } from './mutator.ts';
2
+ export declare const arrayDeclaration: Mutator;
@@ -0,0 +1,12 @@
1
+ import { on, replace, text } from './mutator.js';
2
+ // A call or `new` of Array loses its arguments, and an empty one gains an empty list.
3
+ const construction = (node, context, prefix) => {
4
+ if (text(context.source, node.callee) !== 'Array')
5
+ return [];
6
+ return [replace(context, node, `${prefix}Array(${node.arguments.length ? '' : '[]'})`)];
7
+ };
8
+ const literal = on('ArrayExpression', (node, context) => [replace(context, node, node.elements.length ? '[]' : '["Stryker was here"]')]);
9
+ const call = on('CallExpression', (node, context) => construction(node, context, ''));
10
+ const created = on('NewExpression', (node, context) => construction(node, context, 'new '));
11
+ // An array literal empties and an empty one gains an item.
12
+ export const arrayDeclaration = { name: 'ArrayDeclaration', source: 'stryker', parts: [literal, call, created] };
@@ -0,0 +1,2 @@
1
+ import { type Mutator } from './mutator.ts';
2
+ export declare const arrowFunction: Mutator;
@@ -0,0 +1,10 @@
1
+ import { decidesPerItem } from '../decisions/forks.decision.js';
2
+ import { on, replace } from './mutator.js';
3
+ const isUndefined = (node) => node.type === 'Identifier' && node.name === 'undefined';
4
+ // The body alone becomes `undefined`, so only the cases calling the arrow reach it.
5
+ // A per-item callback is left to the callback crush, which forces its answer each way, and a body already `undefined` has nothing to change.
6
+ export const arrowFunction = {
7
+ name: 'ArrowFunction',
8
+ source: 'stryker',
9
+ parts: [on('ArrowFunctionExpression', (node, context) => (!node.expression || decidesPerItem(context.parent) || isUndefined(node.body) ? [] : [replace({ ...context, chain: null }, node.body, 'undefined')]))],
10
+ };
@@ -0,0 +1,2 @@
1
+ import { type Mutator } from './mutator.ts';
2
+ export declare const assignmentOperator: Mutator;
@@ -0,0 +1,29 @@
1
+ import { holdsText, on, splice } from './mutator.js';
2
+ const assignment = new Map([
3
+ ['+=', '-='],
4
+ ['-=', '+='],
5
+ ['*=', '/='],
6
+ ['/=', '*='],
7
+ ['%=', '*='],
8
+ ['<<=', '>>='],
9
+ ['>>=', '<<='],
10
+ ['&=', '|='],
11
+ ['|=', '&='],
12
+ ['&&=', '||='],
13
+ ['||=', '&&='],
14
+ ['??=', '&&='],
15
+ ]);
16
+ const textAssignments = new Set(['&&=', '||=', '??=']);
17
+ // A string on the right of an arithmetic assignment is concatenation, so only the logical assignments swap there.
18
+ export const assignmentOperator = {
19
+ name: 'AssignmentOperator',
20
+ source: 'stryker',
21
+ parts: [
22
+ on('AssignmentExpression', (node, context) => {
23
+ const swap = assignment.get(node.operator);
24
+ if (!swap || (holdsText(node.right) && !textAssignments.has(node.operator)))
25
+ return [];
26
+ return [splice(context, node, node.left.end, node.operator, swap)];
27
+ }),
28
+ ],
29
+ };
@@ -0,0 +1,2 @@
1
+ import { type Mutator } from './mutator.ts';
2
+ export declare const awaitExpression: Mutator;
@@ -0,0 +1,7 @@
1
+ import { inForkTest, on, replace, text } from './mutator.js';
2
+ // `await value` becomes `value`, except inside a fork test, where forcing the test already decides without the value.
3
+ export const awaitExpression = {
4
+ name: 'AwaitExpression',
5
+ source: 'cfg',
6
+ parts: [on('AwaitExpression', (node, context) => (inForkTest(context) ? [] : [replace(context, node, text(context.source, node.argument))]))],
7
+ };
@@ -0,0 +1,2 @@
1
+ import { type Mutator } from './mutator.ts';
2
+ export declare const bitwiseOperator: Mutator;
@@ -0,0 +1,19 @@
1
+ import { on, splice } from './mutator.js';
2
+ // PIT's MATH swaps for the bitwise and shift operators, which StrykerJS mutates only in their compound assignments.
3
+ const bitwise = new Map([
4
+ ['&', '|'],
5
+ ['|', '&'],
6
+ ['^', '&'],
7
+ ['<<', '>>'],
8
+ ['>>', '<<'],
9
+ ['>>>', '<<'],
10
+ ['^=', '&='],
11
+ ['>>>=', '<<='],
12
+ ]);
13
+ const swapped = (node, context) => {
14
+ const swap = bitwise.get(node.operator);
15
+ return swap ? [splice(context, node, node.left.end, node.operator, swap)] : [];
16
+ };
17
+ const binary = on('BinaryExpression', swapped);
18
+ const assignment = on('AssignmentExpression', swapped);
19
+ export const bitwiseOperator = { name: 'BitwiseOperator', source: 'pit', parts: [binary, assignment] };
@@ -0,0 +1,2 @@
1
+ import { type Mutator } from './mutator.ts';
2
+ export declare const blockStatement: Mutator;
@@ -0,0 +1,30 @@
1
+ import { itemAt, ofType } from '../utils/ast.js';
2
+ import { on, text } from './mutator.js';
3
+ // Matches a `super(...)` call.
4
+ const superCallPattern = /\bsuper\s*\(/;
5
+ const sideParents = new Set(['IfStatement', 'WhileStatement', 'DoWhileStatement', 'ForStatement', 'ForOfStatement', 'ForInStatement']);
6
+ // A block empties, except a fork side's block, which force-fork removes whole, and a constructor whose `super()` must stay first.
7
+ // A block holding only directives, as `'use strict'`, reads as empty, as Babel keeps directives apart from the body Stryker checks.
8
+ // TypeScript emits parameter properties and field initializers right after `super()`, so that call cannot go.
9
+ // Only a constructor's method definition is of the constructor kind, and its class body sits just above it.
10
+ export const blockStatement = {
11
+ name: 'BlockStatement',
12
+ source: 'stryker',
13
+ parts: [
14
+ on('BlockStatement', (node, { parent, ancestors, source }) => {
15
+ const isOnlyDirectives = node.body.every((statement) => statement.type === 'ExpressionStatement' && Boolean(statement.directive));
16
+ if (isOnlyDirectives || sideParents.has(parent.type))
17
+ return [];
18
+ const emptied = [{ start: node.start, end: node.end, replacement: '{}', kind: 'block' }];
19
+ const method = ancestors.at(-2);
20
+ const holder = method ?? node;
21
+ if (!('kind' in holder) || holder.kind !== 'constructor' || !superCallPattern.test(text(source, node)))
22
+ return emptied;
23
+ const { value } = ofType(itemAt(ancestors, ancestors.length - 2), 'MethodDefinition');
24
+ const classBody = ofType(itemAt(ancestors, ancestors.length - 3), 'ClassBody');
25
+ const hasField = classBody.body.some((member) => member.type === 'PropertyDefinition' && member.value !== null);
26
+ const hasParameterProperty = value.params.some((param) => param.type === 'TSParameterProperty');
27
+ return hasField || hasParameterProperty ? [] : emptied;
28
+ }),
29
+ ],
30
+ };
@@ -0,0 +1,2 @@
1
+ import { type Mutator } from './mutator.ts';
2
+ export declare const booleanLiteral: Mutator;
@@ -0,0 +1,5 @@
1
+ import { inForkTest, on, operandOf, replace } from './mutator.js';
2
+ const literal = on('Literal', (node, context) => (typeof node.value === 'boolean' ? [replace(context, node, node.value ? 'false' : 'true')] : []));
3
+ const not = on('UnaryExpression', (node, context) => (node.operator !== '!' || inForkTest(context) ? [] : [replace(context, node, operandOf(context.source, node, '!', true))]));
4
+ // `true` and `false` swap, and `!x` drops its `!`, except inside a fork test, where the fork pass already forces it.
5
+ export const booleanLiteral = { name: 'BooleanLiteral', source: 'stryker', parts: [literal, not] };
@@ -0,0 +1,2 @@
1
+ import { type Mutator } from './mutator.ts';
2
+ export declare const coercion: Mutator;
@@ -0,0 +1,28 @@
1
+ import { present } from '../utils/ast.js';
2
+ import { inForkTest, on, replace, text } from './mutator.js';
3
+ const coercions = new Set(['String', 'Number', 'Boolean']);
4
+ const functionTypes = new Set(['ArrowFunctionExpression', 'FunctionExpression', 'FunctionDeclaration']);
5
+ // A call's own function: the arrow it is the body of, or the function a return of it leaves.
6
+ const ownerOf = (parent, ancestors) => {
7
+ return parent.type === 'ReturnStatement' ? ancestors.findLast((ancestor) => functionTypes.has(ancestor.type)) : parent;
8
+ };
9
+ // `String(x)`, `Number(x)` or `Boolean(x)` becomes `x`, except inside a fork test, where the test reads the value as a boolean either way.
10
+ // A type guard's result must stay a boolean, so `Boolean(x)` it gives has no mutant that compiles.
11
+ export const coercion = {
12
+ name: 'Coercion',
13
+ source: 'cfg',
14
+ parts: [
15
+ on('CallExpression', (node, context) => {
16
+ const { parent, ancestors, source } = context;
17
+ const name = node.callee.type === 'Identifier' ? node.callee.name : '';
18
+ const [only, ...rest] = node.arguments;
19
+ if (!coercions.has(name) || inForkTest(context) || !only || only.type === 'SpreadElement' || rest.length)
20
+ return [];
21
+ const owner = present(ownerOf(parent, ancestors));
22
+ const isGuard = 'returnType' in owner && owner.returnType?.typeAnnotation.type === 'TSTypePredicate';
23
+ if (name === 'Boolean' && isGuard)
24
+ return [];
25
+ return [replace(context, node, text(source, only))];
26
+ }),
27
+ ],
28
+ };
@@ -0,0 +1,2 @@
1
+ import { type Mutator } from './mutator.ts';
2
+ export declare const conditionalExpression: Mutator;
@@ -0,0 +1,36 @@
1
+ import { tokenAt } from '../utils/ast.js';
2
+ import { valueAt } from '../utils/lookup.js';
3
+ import { inForkTest, on, replace } from './mutator.js';
4
+ const booleanOperators = new Set(['!=', '!==', '&&', '<', '<=', '==', '===', '>', '>=', '||']);
5
+ // The other value repeats the whole test's mutant, so a `||` operand only goes false and a `&&` operand only goes true.
6
+ const operandValues = { '||': ['false'], '&&': ['true'], '??': ['true', 'false'] };
7
+ // A boolean expression is forced each way outside fork tests, which the fork pass forces itself.
8
+ const forced = (node, context) => {
9
+ if (!booleanOperators.has(node.operator) || inForkTest(context))
10
+ return [];
11
+ const { parent } = context;
12
+ const values = parent.type === 'LogicalExpression' ? valueAt(operandValues, parent.operator) : ['true', 'false'];
13
+ return values.map((value) => replace(context, node, value));
14
+ };
15
+ // A case's statements are removed from just after its colon, which a test holding a colon of its own sits before.
16
+ const emptied = on('SwitchCase', (node, { source, comments }) => {
17
+ const last = node.consequent.at(-1);
18
+ if (!last)
19
+ return [];
20
+ const start = tokenAt({ source, comments, token: ':', from: node.test ? node.test.end : node.start, to: last.start }) + 1;
21
+ return [{ start, end: last.end, replacement: '', kind: 'statements' }];
22
+ });
23
+ // A `for` with no test gets `false` inserted between its semicolons, after any init holding a semicolon of its own.
24
+ const stopped = on('ForStatement', (node, { source, comments }) => {
25
+ if (node.test)
26
+ return [];
27
+ const at = tokenAt({ source, comments, token: ';', from: node.init ? node.init.end : node.start, to: node.body.start }) + 1;
28
+ return [{ start: at, end: at, replacement: 'false', kind: 'expression' }];
29
+ });
30
+ const binary = on('BinaryExpression', forced);
31
+ const logical = on('LogicalExpression', forced);
32
+ export const conditionalExpression = {
33
+ name: 'ConditionalExpression',
34
+ source: 'stryker',
35
+ parts: [emptied, stopped, binary, logical],
36
+ };
@@ -0,0 +1,2 @@
1
+ import { type Mutator } from './mutator.ts';
2
+ export declare const disposal: Mutator;
@@ -0,0 +1,13 @@
1
+ import { on } from './mutator.js';
2
+ // A `using` declaration becomes `const`, so a case must observe the resource's disposal, except one heading a for...of.
3
+ export const disposal = {
4
+ name: 'Disposal',
5
+ source: 'cfg',
6
+ parts: [
7
+ on('VariableDeclaration', (node, { parent, source }) => {
8
+ if ((node.kind !== 'using' && node.kind !== 'await using') || parent.type === 'ForOfStatement')
9
+ return [];
10
+ return [{ start: node.start, end: node.end, replacement: `const${source.slice(node.start + node.kind.length, node.end)}`, kind: 'disposal' }];
11
+ }),
12
+ ],
13
+ };
@@ -0,0 +1,2 @@
1
+ import { type Mutator } from './mutator.ts';
2
+ export declare const emptyDestructuring: Mutator;
@@ -0,0 +1,35 @@
1
+ import { itemAt, walk } from '../utils/ast.js';
2
+ import { on, replace } from './mutator.js';
3
+ const functionTypes = new Set(['ArrowFunctionExpression', 'FunctionExpression', 'FunctionDeclaration']);
4
+ // The names a pattern binds, its own identifiers outside any key or default value, beside every node the pattern holds.
5
+ const boundBy = (pattern) => {
6
+ const names = new Set();
7
+ const inside = new Set();
8
+ walk(pattern, ({ node, key }) => {
9
+ inside.add(node);
10
+ if (node.type === 'Identifier' && key !== 'key' && key !== 'right')
11
+ names.add(node.name);
12
+ });
13
+ return { names, inside };
14
+ };
15
+ // An object binding's initializer becomes `{}` and an array binding's `[]`, but only where its function reads some bound name, since an unread binding changes nothing.
16
+ export const emptyDestructuring = {
17
+ name: 'EmptyDestructuring',
18
+ source: 'cfg',
19
+ parts: [
20
+ on('VariableDeclarator', (node, context) => {
21
+ const { id, init } = node;
22
+ // A plain name binds no name its own walk visits, so it is never read here.
23
+ if (!init)
24
+ return [];
25
+ const { names, inside } = boundBy(id);
26
+ const scope = context.ancestors.findLast((ancestor) => functionTypes.has(ancestor.type)) ?? itemAt(context.ancestors, 0);
27
+ let isRead = false;
28
+ walk(scope, ({ node: other }) => {
29
+ if (other.type === 'Identifier' && names.has(other.name) && !inside.has(other))
30
+ isRead = true;
31
+ });
32
+ return isRead ? [replace({ ...context, chain: null }, init, id.type === 'ObjectPattern' ? '{}' : '[]')] : [];
33
+ }),
34
+ ],
35
+ };
@@ -0,0 +1,2 @@
1
+ import { type Mutator } from './mutator.ts';
2
+ export declare const emptyReturn: Mutator;
@@ -0,0 +1,35 @@
1
+ import { present } from '../utils/ast.js';
2
+ import { inForkSide, on, replace } from './mutator.js';
3
+ const functionTypes = new Set(['FunctionDeclaration', 'FunctionExpression', 'ArrowFunctionExpression']);
4
+ // PIT picks each empty value from the declared return type, so crush reads only a written annotation, having no checker.
5
+ // A boolean has no empty value, so it takes both, as PIT's TRUE_RETURNS and FALSE_RETURNS do.
6
+ const emptiesOf = (fn) => {
7
+ switch ('returnType' in fn ? fn.returnType?.typeAnnotation.type : undefined) {
8
+ case 'TSNumberKeyword':
9
+ return ['0'];
10
+ case 'TSStringKeyword':
11
+ return ["''"];
12
+ case 'TSBooleanKeyword':
13
+ return ['true', 'false'];
14
+ case 'TSArrayType':
15
+ return ['[]'];
16
+ }
17
+ return [];
18
+ };
19
+ // A return takes its nearest function's annotation.
20
+ const returned = on('ReturnStatement', (node, context) => {
21
+ const { argument } = node;
22
+ if (!argument || inForkSide(context))
23
+ return [];
24
+ const fn = present(context.ancestors.findLast((ancestor) => functionTypes.has(ancestor.type)));
25
+ return emptiesOf(fn).map((empty) => replace({ ...context, chain: null }, argument, empty));
26
+ });
27
+ // An arrow's expression body takes its own arrow's annotation; only an arrow's `expression` flag is ever exactly true.
28
+ const bodied = (context) => {
29
+ const { node, parent, key } = context;
30
+ if (parent.type !== 'ArrowFunctionExpression' || !parent.expression || key !== 'body' || inForkSide(context))
31
+ return [];
32
+ return emptiesOf(parent).map((empty) => replace(context, node, empty));
33
+ };
34
+ // A returned value becomes its type's empty value, except inside a fork side, which force-fork already removes whole.
35
+ export const emptyReturn = { name: 'EmptyReturn', source: 'pit', parts: [returned, { type: null, mutate: bodied }] };
@@ -0,0 +1,2 @@
1
+ import { type Mutator } from './mutator.ts';
2
+ export declare const equalityOperator: Mutator;