@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,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;
@@ -0,0 +1,16 @@
1
+ import { on, splice } from './mutator.js';
2
+ const equality = new Map([
3
+ ['<', ['<=', '>=']],
4
+ ['<=', ['<', '>']],
5
+ ['>', ['>=', '<=']],
6
+ ['>=', ['>', '<']],
7
+ ['==', ['!=']],
8
+ ['!=', ['==']],
9
+ ['===', ['!==']],
10
+ ['!==', ['===']],
11
+ ]);
12
+ export const equalityOperator = {
13
+ name: 'EqualityOperator',
14
+ source: 'stryker',
15
+ parts: [on('BinaryExpression', (node, context) => (equality.get(node.operator) ?? []).map((swap) => splice(context, node, node.left.end, node.operator, swap)))],
16
+ };
@@ -0,0 +1,2 @@
1
+ import { type Mutator } from './mutator.ts';
2
+ export declare const loopExit: Mutator;
@@ -0,0 +1,5 @@
1
+ import { on, statement, text } from './mutator.js';
2
+ const broken = on('BreakStatement', (node, { source }) => [statement(node, text(source, node).endsWith(';') ? 'return;' : 'return')]);
3
+ const continued = on('ContinueStatement', (node, { source }) => [statement(node, text(source, node).replace('continue', 'break'))]);
4
+ // mutmut's loop exit mutants: `break` leaves the whole function as `return`, and `continue` ends the loop as `break`, keeping its label.
5
+ export const loopExit = { name: 'LoopExit', source: 'mutmut', parts: [broken, continued] };
@@ -0,0 +1,2 @@
1
+ import { type Mutator } from './mutator.ts';
2
+ export declare const methodExpression: Mutator;
@@ -0,0 +1,59 @@
1
+ import { propertyNameOf } from '../decisions/decide.js';
2
+ import { ofType } from '../utils/ast.js';
3
+ import { on, replace, text } from './mutator.js';
4
+ // Stryker's table after its reverse loop, which maps each swap back except `setUTCDate`, so `setTime` stays `setDate`; a null swap drops the call.
5
+ const replacements = new Map([
6
+ ['charAt', null],
7
+ ['endsWith', 'startsWith'],
8
+ ['every', 'some'],
9
+ ['filter', null],
10
+ ['reverse', null],
11
+ ['slice', null],
12
+ ['sort', null],
13
+ ['substr', null],
14
+ ['substring', null],
15
+ ['toLocaleLowerCase', 'toLocaleUpperCase'],
16
+ ['toLowerCase', 'toUpperCase'],
17
+ ['trim', null],
18
+ ['trimEnd', 'trimStart'],
19
+ ['min', 'max'],
20
+ ['setDate', 'setTime'],
21
+ ['setFullYear', 'setMonth'],
22
+ ['setHours', 'setMinutes'],
23
+ ['setSeconds', 'setMilliseconds'],
24
+ ['setUTCDate', 'setTime'],
25
+ ['setUTCFullYear', 'setUTCMonth'],
26
+ ['setUTCHours', 'setUTCMinutes'],
27
+ ['setUTCSeconds', 'setUTCMilliseconds'],
28
+ ['startsWith', 'endsWith'],
29
+ ['some', 'every'],
30
+ ['toLocaleUpperCase', 'toLocaleLowerCase'],
31
+ ['toUpperCase', 'toLowerCase'],
32
+ ['trimStart', 'trimEnd'],
33
+ ['max', 'min'],
34
+ ['setTime', 'setDate'],
35
+ ['setMonth', 'setFullYear'],
36
+ ['setMinutes', 'setHours'],
37
+ ['setMilliseconds', 'setSeconds'],
38
+ ['setUTCMonth', 'setUTCFullYear'],
39
+ ['setUTCMinutes', 'setUTCHours'],
40
+ ['setUTCMilliseconds', 'setUTCSeconds'],
41
+ ]);
42
+ // A named method's name reads as empty otherwise, which no swap holds.
43
+ export const methodExpression = {
44
+ name: 'MethodExpression',
45
+ source: 'stryker',
46
+ parts: [
47
+ on('CallExpression', (node, context) => {
48
+ const name = propertyNameOf(node.callee);
49
+ if (!replacements.has(name))
50
+ return [];
51
+ const callee = ofType(node.callee, 'MemberExpression');
52
+ const swap = replacements.get(name);
53
+ if (!swap)
54
+ return [replace(context, node, text(context.source, callee.object))];
55
+ const raw = text(context.source, node);
56
+ return [replace(context, node, `${raw.slice(0, callee.property.start - node.start)}${swap}${raw.slice(callee.property.end - node.start)}`)];
57
+ }),
58
+ ],
59
+ };
@@ -0,0 +1,2 @@
1
+ import { type Mutator } from './mutator.ts';
2
+ export declare const missingLookup: Mutator;
@@ -0,0 +1,25 @@
1
+ import { propertyNameOf } from '../decisions/decide.js';
2
+ import { on, replace } from './mutator.js';
3
+ const absentLookups = new Map([
4
+ ['get', 'undefined'],
5
+ ['find', 'undefined'],
6
+ ['findLast', 'undefined'],
7
+ ['at', 'undefined'],
8
+ ['indexOf', '-1'],
9
+ ['lastIndexOf', '-1'],
10
+ ['findIndex', '-1'],
11
+ ['findLastIndex', '-1'],
12
+ ]);
13
+ // A lookup answers as if it found nothing, except one feeding `??`, whose fork already takes the absent side; only `??` carries that operator.
14
+ export const missingLookup = {
15
+ name: 'MissingLookup',
16
+ source: 'cfg',
17
+ parts: [
18
+ on('CallExpression', (node, context) => {
19
+ const absent = absentLookups.get(propertyNameOf(node.callee));
20
+ if (!absent || (context.parent.type === 'LogicalExpression' && context.parent.operator === '??' && context.key === 'left'))
21
+ return [];
22
+ return [replace(context, node, absent)];
23
+ }),
24
+ ],
25
+ };
@@ -0,0 +1,40 @@
1
+ import { type Node, type NodeOf, type Parsed, type Visit } from '../utils/ast.ts';
2
+ export type Kind = 'expression' | 'block' | 'statements' | 'disposal';
3
+ export type Mutation = {
4
+ start: number;
5
+ end: number;
6
+ replacement: string;
7
+ kind: Kind;
8
+ };
9
+ export declare const groupedOf: (replacement: string) => string;
10
+ export declare const groupedBooleanReplacements: ReadonlySet<string>;
11
+ export type Project = ReadonlyMap<string, Parsed['program']>;
12
+ export type Context = Visit & {
13
+ source: string;
14
+ comments: Parsed['comments'];
15
+ path: string;
16
+ project: Project;
17
+ bindings: ReadonlyMap<Node, Node>;
18
+ };
19
+ type Source = 'stryker' | 'cfg' | 'pit' | 'mutmut' | 'laurent' | 'crush';
20
+ export type Part = {
21
+ type: Node['type'] | null;
22
+ mutate: (context: Context) => Mutation[];
23
+ };
24
+ export type Mutator = {
25
+ name: string;
26
+ source: Source;
27
+ parts: Part[];
28
+ };
29
+ export declare const on: <T extends Node['type']>(type: T, mutate: (node: NodeOf<T>, context: Context) => Mutation[]) => Part;
30
+ export declare const mutationsOf: (mutator: Mutator, context: Context) => Mutation[];
31
+ export declare const text: (source: string, node: Node) => string;
32
+ export declare const joined: (before: string, after: string) => string;
33
+ export declare const replace: (context: Context, node: Node, replacement: string) => Mutation;
34
+ export declare const splice: (context: Context, node: Node, from: number, token: string, swap: string) => Mutation;
35
+ export declare const operandOf: (source: string, node: Node, operator: string, isPrefix: boolean) => string;
36
+ export declare const statement: (node: Node, replacement: string) => Mutation;
37
+ export declare const holdsText: (node: Node) => boolean;
38
+ export declare const inForkTest: (context: Context) => boolean;
39
+ export declare const inForkSide: (context: Context) => boolean;
40
+ export {};
@@ -0,0 +1,49 @@
1
+ import { ofType, itemAt, tokenAt } from '../utils/ast.js';
2
+ // Groups an expression for the switch and the report.
3
+ export const groupedOf = (replacement) => `(${replacement})`;
4
+ export const groupedBooleanReplacements = new Set(['true', 'false'].map(groupedOf));
5
+ // A rule for one node type, handed the node already narrowed, so no mutator tests a type itself.
6
+ export const on = (type, mutate) => ({ type, mutate: (context) => mutate(ofType(context.node, type), context) });
7
+ // The mutants one mutator makes at one visit, for a caller that holds no index of the rules by node type.
8
+ export const mutationsOf = (mutator, context) => mutator.parts.filter(({ type }) => type === null || type === context.node.type).flatMap(({ mutate }) => mutate(context));
9
+ export const text = (source, node) => source.slice(node.start, node.end);
10
+ // Whether two characters written side by side read as one token, as `-` and `-` make `--` and `/` before `/` or `*` opens a comment.
11
+ const fuses = (before, after) => ((before === '+' || before === '-') && before === after) || (before === '/' && (after === '/' || after === '*'));
12
+ // Two pieces of code joined, with a space between where their touching characters would otherwise read as one token.
13
+ export const joined = (before, after) => `${before}${fuses(before.charAt(before.length - 1), after.charAt(0)) ? ' ' : ''}${after}`;
14
+ // A wrap inside an optional chain would break its short circuit, so a site on the chain's spine covers the whole chain.
15
+ // The replacement is spaced from the source on either side of its span where it would otherwise fuse with it, as `-` before a new `-a`.
16
+ export const replace = (context, node, replacement) => {
17
+ const { source, chain } = context;
18
+ const outer = chain ?? node;
19
+ const written = `${source.slice(outer.start, node.start)}${replacement}${source.slice(node.end, outer.end)}`;
20
+ const before = fuses(source.charAt(outer.start - 1), written.charAt(0)) ? ' ' : '';
21
+ const after = fuses(written.charAt(written.length - 1), source.charAt(outer.end)) ? ' ' : '';
22
+ return { start: outer.start, end: outer.end, replacement: `${before}${written}${after}`, kind: 'expression' };
23
+ };
24
+ // Replaces the first `token` at or after `from` inside the node's text that no comment holds, never fusing the swap with a neighbor.
25
+ export const splice = (context, node, from, token, swap) => {
26
+ const { source, comments } = context;
27
+ const raw = text(source, node);
28
+ const at = tokenAt({ source, comments, token, from, to: node.end }) - node.start;
29
+ return replace(context, node, joined(joined(raw.slice(0, at), swap), raw.slice(at + token.length)));
30
+ };
31
+ // An operand's full text, its parentheses included, which the parser leaves outside the operand's own span.
32
+ // A prefix operand runs from after the operator to the node's end, a postfix one from the node's start to before the operator.
33
+ export const operandOf = (source, node, operator, isPrefix) => (isPrefix ? source.slice(node.start + operator.length, node.end) : source.slice(node.start, node.end - operator.length));
34
+ // A run of statements replaced whole, which no chain widens.
35
+ export const statement = (node, replacement) => ({ start: node.start, end: node.end, replacement, kind: 'statements' });
36
+ // Only a template or a string Literal holds text, and only a Literal carries a string `value`.
37
+ export const holdsText = (node) => node.type === 'TemplateLiteral' || (node.type === 'Literal' && typeof node.value === 'string');
38
+ const forkTypes = new Set(['IfStatement', 'ConditionalExpression', 'WhileStatement', 'DoWhileStatement', 'ForStatement']);
39
+ // The path from the root down to the visited node, each step beside the one under it.
40
+ const stepsOf = ({ ancestors, node }) => {
41
+ const path = [...ancestors, node];
42
+ return path.slice(1).map((child, index) => [itemAt(path, index), child]);
43
+ };
44
+ // Whether the node sits inside a fork's test, where the fork pass already forces every value the test reads.
45
+ export const inForkTest = (context) => stepsOf(context).some(([above, below]) => forkTypes.has(above.type) && 'test' in above && above.test === below);
46
+ // Whether the step below is one side of the step above, its consequent, alternate or body.
47
+ const holdsOnASide = (above, below) => ('consequent' in above && above.consequent === below) || ('alternate' in above && above.alternate === below) || ('body' in above && above.body === below);
48
+ // Whether the node sits inside one side of a fork or loop, which force-fork and loop-once already remove whole.
49
+ export const inForkSide = (context) => stepsOf(context).some(([above, below]) => (forkTypes.has(above.type) || above.type === 'ForOfStatement' || above.type === 'ForInStatement') && holdsOnASide(above, below));
@@ -0,0 +1,3 @@
1
+ export declare const outcomeMutatorName = "Outcome";
2
+ export declare const mutatorNames: readonly ['ArithmeticOperator', 'ArrayDeclaration', 'ArrowFunction', 'AssignmentOperator', 'BlockStatement', 'BooleanLiteral', 'ConditionalExpression', 'EqualityOperator', 'MethodExpression', 'ObjectLiteral', 'Regex', 'StringLiteral', 'UnaryOperator', 'UpdateOperator', 'AwaitExpression', 'Coercion', 'Disposal', 'EmptyDestructuring', 'MissingLookup', 'OddNumber', 'PrivateBrand', 'ShortIteration', 'SwitchDefault', 'ThrownCall', 'UnboundCall', 'YieldValue', 'NumberLiteral', 'BitwiseOperator', 'EmptyReturn', 'PlainAssignment', 'PowerOperator', 'LoopExit', 'NestedCondition', "Outcome", 'SyncIteration', 'OperandDeletion'];
3
+ export declare const pluginMutatorName = "Plugin";
@@ -0,0 +1,43 @@
1
+ // The outcome mutator's name, which questions read without loading the mutator.
2
+ export const outcomeMutatorName = 'Outcome';
3
+ // Every wired mutator's name in the order `mutators` lists them, apart from the registry so the record's check reads it without loading a mutator.
4
+ export const mutatorNames = [
5
+ 'ArithmeticOperator',
6
+ 'ArrayDeclaration',
7
+ 'ArrowFunction',
8
+ 'AssignmentOperator',
9
+ 'BlockStatement',
10
+ 'BooleanLiteral',
11
+ 'ConditionalExpression',
12
+ 'EqualityOperator',
13
+ 'MethodExpression',
14
+ 'ObjectLiteral',
15
+ 'Regex',
16
+ 'StringLiteral',
17
+ 'UnaryOperator',
18
+ 'UpdateOperator',
19
+ 'AwaitExpression',
20
+ 'Coercion',
21
+ 'Disposal',
22
+ 'EmptyDestructuring',
23
+ 'MissingLookup',
24
+ 'OddNumber',
25
+ 'PrivateBrand',
26
+ 'ShortIteration',
27
+ 'SwitchDefault',
28
+ 'ThrownCall',
29
+ 'UnboundCall',
30
+ 'YieldValue',
31
+ 'NumberLiteral',
32
+ 'BitwiseOperator',
33
+ 'EmptyReturn',
34
+ 'PlainAssignment',
35
+ 'PowerOperator',
36
+ 'LoopExit',
37
+ 'NestedCondition',
38
+ outcomeMutatorName,
39
+ 'SyncIteration',
40
+ 'OperandDeletion',
41
+ ];
42
+ // The name every fork plugin's site is planned under, beside the wired mutators.
43
+ export const pluginMutatorName = 'Plugin';
@@ -0,0 +1,8 @@
1
+ import type { Mutator, Part } from './mutator.ts';
2
+ export declare const mutators: readonly Mutator[];
3
+ export declare const strykerMutatorNames: ReadonlySet<string>;
4
+ type NamedPart = Part & {
5
+ name: string;
6
+ };
7
+ export declare const partsAt: (type: string) => NamedPart[];
8
+ export {};
@@ -0,0 +1,84 @@
1
+ import { arithmeticOperator } from './arithmetic-operator.mutator.js';
2
+ import { arrayDeclaration } from './array-declaration.mutator.js';
3
+ import { arrowFunction } from './arrow-function.mutator.js';
4
+ import { assignmentOperator } from './assignment-operator.mutator.js';
5
+ import { awaitExpression } from './await-expression.mutator.js';
6
+ import { bitwiseOperator } from './bitwise-operator.mutator.js';
7
+ import { blockStatement } from './block-statement.mutator.js';
8
+ import { booleanLiteral } from './boolean-literal.mutator.js';
9
+ import { coercion } from './coercion.mutator.js';
10
+ import { conditionalExpression } from './conditional-expression.mutator.js';
11
+ import { disposal } from './disposal.mutator.js';
12
+ import { emptyDestructuring } from './empty-destructuring.mutator.js';
13
+ import { emptyReturn } from './empty-return.mutator.js';
14
+ import { equalityOperator } from './equality-operator.mutator.js';
15
+ import { loopExit } from './loop-exit.mutator.js';
16
+ import { methodExpression } from './method-expression.mutator.js';
17
+ import { missingLookup } from './missing-lookup.mutator.js';
18
+ import { nestedCondition } from './nested-condition.mutator.js';
19
+ import { numberLiteral } from './number-literal.mutator.js';
20
+ import { objectLiteral } from './object-literal.mutator.js';
21
+ import { oddNumber } from './odd-number.mutator.js';
22
+ import { operandDeletion } from './operand-deletion.mutator.js';
23
+ import { outcome } from './outcome.mutator.js';
24
+ import { plainAssignment } from './plain-assignment.mutator.js';
25
+ import { powerOperator } from './power-operator.mutator.js';
26
+ import { privateBrand } from './private-brand.mutator.js';
27
+ import { regex } from './regex.mutator.js';
28
+ import { shortIteration } from './short-iteration.mutator.js';
29
+ import { stringLiteral } from './string-literal.mutator.js';
30
+ import { switchDefault } from './switch-default.mutator.js';
31
+ import { syncIteration } from './sync-iteration.mutator.js';
32
+ import { thrownCall } from './thrown-call.mutator.js';
33
+ import { unaryOperator } from './unary-operator.mutator.js';
34
+ import { unboundCall } from './unbound-call.mutator.js';
35
+ import { updateOperator } from './update-operator.mutator.js';
36
+ import { yieldValue } from './yield-value.mutator.js';
37
+ // Every wired mutator, StrykerJS's in its alphabetical order first, then the CFG's, PIT's and mutmut's; the not-wired files stay out.
38
+ export const mutators = [
39
+ arithmeticOperator,
40
+ arrayDeclaration,
41
+ arrowFunction,
42
+ assignmentOperator,
43
+ blockStatement,
44
+ booleanLiteral,
45
+ conditionalExpression,
46
+ equalityOperator,
47
+ methodExpression,
48
+ objectLiteral,
49
+ regex,
50
+ stringLiteral,
51
+ unaryOperator,
52
+ updateOperator,
53
+ awaitExpression,
54
+ coercion,
55
+ disposal,
56
+ emptyDestructuring,
57
+ missingLookup,
58
+ oddNumber,
59
+ privateBrand,
60
+ shortIteration,
61
+ switchDefault,
62
+ thrownCall,
63
+ unboundCall,
64
+ yieldValue,
65
+ numberLiteral,
66
+ bitwiseOperator,
67
+ emptyReturn,
68
+ plainAssignment,
69
+ powerOperator,
70
+ loopExit,
71
+ nestedCondition,
72
+ outcome,
73
+ syncIteration,
74
+ operandDeletion,
75
+ ];
76
+ // StrykerJS's mutators, whose edits stand over the same edit from one of crush's own.
77
+ export const strykerMutatorNames = new Set(mutators.filter(({ source }) => source === 'stryker').map(({ name }) => name));
78
+ const named = mutators.flatMap(({ name, parts }) => parts.map((part) => ({ ...part, name })));
79
+ // The rules for every type, which alone run at a type no rule names.
80
+ const everyType = named.filter(({ type }) => type === null);
81
+ // Each node type's rules, with the rules for every type among them, in the order the mutators and their rules are listed.
82
+ const partsByType = new Map([...new Set(named.map(({ type }) => type).filter((type) => type !== null))].map((type) => [type, named.filter((part) => part.type === null || part.type === type)]));
83
+ // The rules a visit of a node of this type runs, so a visit tries no rule for another type.
84
+ export const partsAt = (type) => partsByType.get(type) ?? everyType;
@@ -0,0 +1,2 @@
1
+ import { type Mutator } from './mutator.ts';
2
+ export declare const nestedCondition: Mutator;
@@ -0,0 +1,16 @@
1
+ import { itemAt } from '../utils/ast.js';
2
+ import { on, statement, text } from './mutator.js';
3
+ // A swap for an `if` holding only another `if`, neither with an `else`, which runs its body as `&&` over both tests would: one `if` over both joined by `||`, so nesting a condition never drops the swap a written `&&` gets.
4
+ export const nestedCondition = {
5
+ name: 'NestedCondition',
6
+ source: 'crush',
7
+ parts: [
8
+ on('IfStatement', (node, { source }) => {
9
+ const { consequent } = node;
10
+ const only = consequent.type === 'BlockStatement' && consequent.body.length === 1 ? itemAt(consequent.body, 0) : consequent;
11
+ if (node.alternate || only.type !== 'IfStatement' || only.alternate)
12
+ return [];
13
+ return [statement(node, `if ((${text(source, node.test)}) || (${text(source, only.test)})) ${text(source, only.consequent)}`)];
14
+ }),
15
+ ],
16
+ };
@@ -0,0 +1,3 @@
1
+ import { type Mutator } from './mutator.ts';
2
+ export declare const replacementOf: (value: number) => string;
3
+ export declare const numberLiteral: Mutator;
@@ -0,0 +1,13 @@
1
+ import { on, replace } from './mutator.js';
2
+ // PIT's inline constant rule: an integer one becomes zero, any other integer grows by one, and a fraction becomes one.
3
+ export const replacementOf = (value) => {
4
+ if (!Number.isInteger(value))
5
+ return '1';
6
+ return value === 1 ? '0' : String(value + 1);
7
+ };
8
+ // A number under `key` names a member, as `{ 1: a }`, rather than a value a case could tell apart.
9
+ export const numberLiteral = {
10
+ name: 'NumberLiteral',
11
+ source: 'pit',
12
+ parts: [on('Literal', (node, context) => (typeof node.value !== 'number' || context.key === 'key' ? [] : [replace(context, node, replacementOf(node.value))]))],
13
+ };
@@ -0,0 +1,2 @@
1
+ import { type Mutator } from './mutator.ts';
2
+ export declare const objectLiteral: Mutator;
@@ -0,0 +1,6 @@
1
+ import { on, replace } from './mutator.js';
2
+ export const objectLiteral = {
3
+ name: 'ObjectLiteral',
4
+ source: 'stryker',
5
+ parts: [on('ObjectExpression', (node, context) => (node.properties.length ? [replace(context, node, '{}')] : []))],
6
+ };
@@ -0,0 +1,2 @@
1
+ import { type Mutator } from './mutator.ts';
2
+ export declare const oddNumber: Mutator;
@@ -0,0 +1,15 @@
1
+ import { objectNameOf } from '../decisions/decide.js';
2
+ import { inForkTest, on, replace } from './mutator.js';
3
+ const numberCalls = new Set(['Number', 'parseInt', 'parseFloat']);
4
+ // A number parse or a Math method answers NaN, except inside a fork test, where forcing the test already covers the odd answer.
5
+ export const oddNumber = {
6
+ name: 'OddNumber',
7
+ source: 'cfg',
8
+ parts: [
9
+ on('CallExpression', (node, context) => {
10
+ const isParse = node.callee.type === 'Identifier' && numberCalls.has(node.callee.name);
11
+ const isMath = objectNameOf(node.callee) === 'Math' && node.callee.type === 'MemberExpression' && !node.callee.computed;
12
+ return (isParse || isMath) && !inForkTest(context) ? [replace(context, node, 'NaN')] : [];
13
+ }),
14
+ ],
15
+ };
@@ -0,0 +1,2 @@
1
+ import { type Mutator } from './mutator.ts';
2
+ export declare const operandDeletion: Mutator;
@@ -0,0 +1,9 @@
1
+ import { on, replace, text } from './mutator.js';
2
+ // The operators whose result is built from both operands, so either operand alone is a different value of the same kind.
3
+ const deletable = new Set(['+', '-', '*', '/', '%', '**', '&', '|', '^', '<<', '>>', '>>>']);
4
+ // Laurent et al.'s arithmetic operator deletion, each operand alone in place of the operation, which ArithmeticOperator's swap covers for neither a string concatenation nor a product.
5
+ export const operandDeletion = {
6
+ name: 'OperandDeletion',
7
+ source: 'laurent',
8
+ parts: [on('BinaryExpression', (node, context) => (deletable.has(node.operator) ? [replace(context, node, text(context.source, node.left)), replace(context, node, text(context.source, node.right))] : []))],
9
+ };
@@ -0,0 +1,3 @@
1
+ import { type Mutator } from './mutator.ts';
2
+ export declare const falsyPattern: RegExp;
3
+ export declare const outcome: Mutator;
@@ -0,0 +1,45 @@
1
+ import { present } from '../utils/ast.js';
2
+ import { replace, statement, text } from './mutator.js';
3
+ import { outcomeMutatorName } from './mutator.names.js';
4
+ // Each arm of a ternary is an outcome of its own, so a result splits a ternary into its arms.
5
+ const leavesOf = (node) => (node.type === 'ConditionalExpression' ? [...leavesOf(node.consequent), ...leavesOf(node.alternate)] : [node]);
6
+ // What a function gives back: a return's argument, or an arrow's expression body, which sits under the arrow rather than inside a return.
7
+ const resultOf = ({ node, parent, key }) => {
8
+ if (node.type === 'ReturnStatement')
9
+ return node.argument;
10
+ return parent.type === 'ArrowFunctionExpression' && parent.expression && key === 'body' ? node : null;
11
+ };
12
+ // Matches a falsy literal: false, null, undefined, 0, or an empty string or template.
13
+ export const falsyPattern = /^(false|null|undefined|0|''|""|``)$/;
14
+ // `undefined` reads as falsy to every caller testing the result, so a falsy result's mutant gives `true`.
15
+ const isFalsy = (source, leaf) => {
16
+ switch (leaf.type) {
17
+ case 'UnaryExpression':
18
+ return leaf.operator === 'void' || falsyPattern.test(text(source, leaf));
19
+ case 'SequenceExpression':
20
+ return isFalsy(source, present(leaf.expressions.at(-1)));
21
+ case 'TSAsExpression':
22
+ case 'TSSatisfiesExpression':
23
+ case 'TSNonNullExpression':
24
+ case 'TSTypeAssertion':
25
+ return isFalsy(source, leaf.expression);
26
+ default:
27
+ return falsyPattern.test(text(source, leaf));
28
+ }
29
+ };
30
+ // Outcome mutants: what a function gives back becomes a wrong result, and a throw is dropped, so a test must check what the function does.
31
+ export const outcome = {
32
+ name: outcomeMutatorName,
33
+ source: 'crush',
34
+ parts: [
35
+ {
36
+ type: null,
37
+ mutate: (context) => {
38
+ if (context.node.type === 'ThrowStatement')
39
+ return [statement(context.node, '')];
40
+ const result = resultOf(context);
41
+ return result ? leavesOf(result).map((leaf) => replace(context, leaf, isFalsy(context.source, leaf) ? 'true' : 'undefined')) : [];
42
+ },
43
+ },
44
+ ],
45
+ };
@@ -0,0 +1,2 @@
1
+ import { type Mutator } from './mutator.ts';
2
+ export declare const plainAssignment: Mutator;
@@ -0,0 +1,7 @@
1
+ import { on, replace, text } from './mutator.js';
2
+ // mutmut's augmented assignment mutant: `a += b` becomes `a = b`, so an accumulator no case checks survives.
3
+ export const plainAssignment = {
4
+ name: 'PlainAssignment',
5
+ source: 'mutmut',
6
+ parts: [on('AssignmentExpression', (node, context) => (node.operator === '=' ? [] : [replace(context, node, `${text(context.source, node.left)} = ${text(context.source, node.right)}`)]))],
7
+ };
@@ -0,0 +1,2 @@
1
+ import { type Mutator } from './mutator.ts';
2
+ export declare const powerOperator: Mutator;
@@ -0,0 +1,13 @@
1
+ import { on, splice } from './mutator.js';
2
+ // mutmut's power swap, `a ** b` to `a * b` and `a **= b` to `a *= b`, which StrykerJS leaves out.
3
+ const power = new Map([
4
+ ['**', '*'],
5
+ ['**=', '*='],
6
+ ]);
7
+ const swapped = (node, context) => {
8
+ const swap = power.get(node.operator);
9
+ return swap ? [splice(context, node, node.left.end, node.operator, swap)] : [];
10
+ };
11
+ const binary = on('BinaryExpression', swapped);
12
+ const assignment = on('AssignmentExpression', swapped);
13
+ export const powerOperator = { name: 'PowerOperator', source: 'mutmut', parts: [binary, assignment] };
@@ -0,0 +1,2 @@
1
+ import { type Mutator } from './mutator.ts';
2
+ export declare const privateBrand: Mutator;
@@ -0,0 +1,7 @@
1
+ import { inForkTest, on, replace } from './mutator.js';
2
+ // A `#x in o` check answers true, except inside a fork test, where the fork pass already forces it; only `in` takes a private name on its left.
3
+ export const privateBrand = {
4
+ name: 'PrivateBrand',
5
+ source: 'cfg',
6
+ parts: [on('BinaryExpression', (node, context) => (node.left.type !== 'PrivateIdentifier' || inForkTest(context) ? [] : [replace(context, node, 'true')]))],
7
+ };
@@ -0,0 +1,2 @@
1
+ import { type Mutator } from './mutator.ts';
2
+ export declare const regex: Mutator;
@@ -0,0 +1,29 @@
1
+ import * as weaponRegex from 'weapon-regex';
2
+ import { safe } from '../utils/safe.js';
3
+ import { on, replace, text } from './mutator.js';
4
+ // weapon-regex refuses a pattern it cannot parse, which then has no mutants.
5
+ const patternsOf = (pattern, flags) => {
6
+ const { data: mutants, error } = safe(() => weaponRegex.mutate(pattern, flags, { mutationLevels: [1] }));
7
+ if (error)
8
+ return [];
9
+ return mutants.map((mutant) => mutant.pattern);
10
+ };
11
+ const literal = on('Literal', (node, context) => {
12
+ if (!('regex' in node))
13
+ return [];
14
+ const { pattern, flags } = node.regex;
15
+ return patternsOf(pattern, flags).map((mutant) => replace(context, node, `/${mutant}/${flags}`));
16
+ });
17
+ // The pattern argument is replaced on its own, so a chain around the constructor never widens the site.
18
+ // Its mutants read the pattern alone, since the call keeps its flags as they are, and weapon-regex refuses a pattern that is no written string.
19
+ const constructed = on('NewExpression', (node, context) => {
20
+ if (text(context.source, node.callee) !== 'RegExp')
21
+ return [];
22
+ const [first = node] = node.arguments;
23
+ const pattern = first.type === 'Literal' ? first.value : null;
24
+ if (typeof pattern !== 'string')
25
+ return [];
26
+ return patternsOf(pattern, '').map((mutant) => replace({ ...context, chain: null }, first, JSON.stringify(mutant)));
27
+ });
28
+ // Each level 1 mutant of a regex literal, or of the pattern string handed to `new RegExp`.
29
+ export const regex = { name: 'Regex', source: 'stryker', parts: [literal, constructed] };
@@ -0,0 +1,2 @@
1
+ import { type Mutator } from './mutator.ts';
2
+ export declare const shortIteration: Mutator;