mootant 0.1.0 → 0.2.0

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 (244) hide show
  1. package/dist/adapters/jest/build-dry-file.d.ts +12 -12
  2. package/dist/adapters/jest/collect-jest-dependencies.d.ts +8 -7
  3. package/dist/adapters/jest/runner.d.ts +1 -1
  4. package/dist/adapters/jest/runner.js +1 -1
  5. package/dist/adapters/jest/types/jest-record.d.ts +4 -4
  6. package/dist/adapters/jest/types/unit-worker.d.ts +16 -8
  7. package/dist/adapters/jest/types/worker-session.d.ts +6 -7
  8. package/dist/adapters/jest/worker/boot-worker.d.ts +4 -3
  9. package/dist/adapters/jest/worker/run-unit.d.ts +20 -18
  10. package/dist/adapters/jest/worker/vm-setup.js +1 -1
  11. package/dist/adapters/jest/worker/worker.js +1 -1
  12. package/dist/adapters/jest/write-worker-session.d.ts +1 -2
  13. package/dist/adapters/jest/write-worker-session.js +2 -2
  14. package/dist/adapters/node-test/collect-node-dependencies.d.ts +5 -5
  15. package/dist/adapters/node-test/preload/preload.js +4 -1
  16. package/dist/adapters/node-test/run-test-file.js +1 -0
  17. package/dist/adapters/node-test/types/node-test-record.d.ts +3 -3
  18. package/dist/adapters/node-test/types/node-test-unit.d.ts +6 -1
  19. package/dist/adapters/shared/create-input-filter.d.ts +26 -0
  20. package/dist/adapters/shared/create-input-filter.js +32 -0
  21. package/dist/adapters/shared/track-file-inputs.d.ts +7 -3
  22. package/dist/adapters/shared/track-file-inputs.js +16 -7
  23. package/dist/adapters/shared/track-file-reads.d.ts +12 -8
  24. package/dist/adapters/shared/track-file-reads.js +110 -57
  25. package/dist/adapters/shared/track-inputs.d.ts +13 -6
  26. package/dist/adapters/shared/track-inputs.js +7 -7
  27. package/dist/adapters/shared/types/file-input-tracking.d.ts +6 -0
  28. package/dist/adapters/shared/types/input-tracking.d.ts +3 -3
  29. package/dist/adapters/vitest/collect-dependencies.d.ts +4 -3
  30. package/dist/adapters/vitest/collect-dependencies.js +25 -24
  31. package/dist/adapters/vitest/get-cache-inputs.js +3 -1
  32. package/dist/adapters/vitest/is-virtual-module.d.ts +11 -0
  33. package/dist/adapters/vitest/is-virtual-module.js +8 -0
  34. package/dist/adapters/vitest/read-out-files.d.ts +7 -2
  35. package/dist/adapters/vitest/read-out-files.js +5 -5
  36. package/dist/adapters/vitest/read-out-records.d.ts +17 -0
  37. package/dist/adapters/vitest/read-out-records.js +27 -0
  38. package/dist/adapters/vitest/read-strays.d.ts +20 -0
  39. package/dist/adapters/vitest/read-strays.js +53 -0
  40. package/dist/adapters/vitest/read-unit-inputs.d.ts +7 -1
  41. package/dist/adapters/vitest/read-unit-inputs.js +1 -1
  42. package/dist/adapters/vitest/run-dry.js +16 -16
  43. package/dist/adapters/vitest/run-plan.d.ts +3 -1
  44. package/dist/adapters/vitest/run-plan.js +15 -15
  45. package/dist/adapters/vitest/run-specifications.d.ts +3 -2
  46. package/dist/adapters/vitest/runner.d.ts +38 -23
  47. package/dist/adapters/vitest/runner.js +84 -85
  48. package/dist/adapters/vitest/types/stray-decisions.d.ts +8 -0
  49. package/dist/adapters/vitest/types/unit-outcome.d.ts +2 -1
  50. package/dist/adapters/vitest/types/vitest-worker.d.ts +83 -12
  51. package/dist/adapters/vitest/worker/encode-stray.d.ts +16 -0
  52. package/dist/adapters/vitest/worker/encode-stray.js +16 -0
  53. package/dist/adapters/vitest/worker/intercept-strays.d.ts +26 -0
  54. package/dist/adapters/vitest/worker/intercept-strays.js +13 -0
  55. package/dist/adapters/vitest/worker/read-try-facts.d.ts +5 -4
  56. package/dist/adapters/vitest/worker/write-out-record.d.ts +2 -2
  57. package/dist/cli/html/build-html-report.js +1 -1
  58. package/dist/cli/html/client/main.js +1 -1
  59. package/dist/cli/html/client/render-change.d.ts +3 -2
  60. package/dist/cli/html/client/render-code.d.ts +1 -1
  61. package/dist/cli/html/pack-replacement.d.ts +1 -1
  62. package/dist/cli/parse-arguments.js +1 -1
  63. package/dist/cli/report/build-list-report.js +1 -1
  64. package/dist/cli/report/build-run-report.js +1 -1
  65. package/dist/cli/report/format-file-groups.d.ts +1 -1
  66. package/dist/cli/run-mutation.js +31 -31
  67. package/dist/cli/terminal/create-spinner.d.ts +1 -1
  68. package/dist/cli/terminal/get-text-style.js +4 -4
  69. package/dist/core/cache/get-environment-key.js +2 -2
  70. package/dist/core/cache/hash-files.d.ts +7 -3
  71. package/dist/core/cache/hash-files.js +16 -17
  72. package/dist/core/cache/prepare-run-cache.d.ts +29 -7
  73. package/dist/core/cache/prepare-run-cache.js +96 -62
  74. package/dist/core/cache/save-run-cache.d.ts +8 -7
  75. package/dist/core/cache/save-run-cache.js +2 -1
  76. package/dist/core/cache/unknown-hash.d.ts +7 -0
  77. package/dist/core/cache/unknown-hash.js +2 -0
  78. package/dist/core/files/select-changed-mutants.d.ts +11 -6
  79. package/dist/core/files/select-changed-mutants.js +38 -13
  80. package/dist/core/generate/apply-solitary-rule.d.ts +8 -5
  81. package/dist/core/generate/apply-solitary-rule.js +36 -29
  82. package/dist/core/generate/collect-candidates.d.ts +18 -4
  83. package/dist/core/generate/collect-candidates.js +168 -86
  84. package/dist/core/generate/compare-targets.d.ts +14 -0
  85. package/dist/core/generate/compare-targets.js +6 -0
  86. package/dist/core/generate/deduplicate-candidates.d.ts +6 -4
  87. package/dist/core/generate/deduplicate-candidates.js +11 -9
  88. package/dist/core/generate/find-list-removal.d.ts +20 -0
  89. package/dist/core/generate/find-list-removal.js +26 -0
  90. package/dist/core/generate/generate-file-mutants.js +47 -46
  91. package/dist/core/generate/get-mutant-site.d.ts +18 -0
  92. package/dist/core/generate/get-mutant-site.js +4 -0
  93. package/dist/core/generate/get-target.d.ts +14 -0
  94. package/dist/core/generate/get-target.js +4 -0
  95. package/dist/core/generate/pick-host.d.ts +10 -0
  96. package/dist/core/generate/pick-host.js +16 -0
  97. package/dist/core/generate/validate-replacement.d.ts +15 -4
  98. package/dist/core/generate/validate-replacement.js +28 -13
  99. package/dist/core/ignore/find-ignore-rule.d.ts +8 -7
  100. package/dist/core/instrument/find-attribute-values.d.ts +12 -0
  101. package/dist/core/instrument/find-attribute-values.js +13 -0
  102. package/dist/core/instrument/get-site-syntax.d.ts +14 -0
  103. package/dist/core/instrument/get-site-syntax.js +12 -0
  104. package/dist/core/instrument/group-mutant-ranges.d.ts +7 -3
  105. package/dist/core/instrument/group-mutant-ranges.js +25 -19
  106. package/dist/core/instrument/instrument-file.d.ts +5 -3
  107. package/dist/core/instrument/instrument-file.js +10 -9
  108. package/dist/core/instrument/instrumenter-version.d.ts +1 -1
  109. package/dist/core/instrument/render-branch.d.ts +17 -0
  110. package/dist/core/instrument/render-branch.js +81 -0
  111. package/dist/core/instrument/render-mutant-range.d.ts +17 -6
  112. package/dist/core/instrument/render-mutant-range.js +39 -13
  113. package/dist/core/list-mutants.d.ts +7 -5
  114. package/dist/core/list-mutants.js +2 -2
  115. package/dist/core/mutators/array-element.d.ts +7 -6
  116. package/dist/core/mutators/array-element.js +13 -13
  117. package/dist/core/mutators/assignment-operator.js +34 -33
  118. package/dist/core/mutators/boolean-literal.d.ts +3 -2
  119. package/dist/core/mutators/number-literal.d.ts +1 -1
  120. package/dist/core/mutators/object-property.d.ts +4 -3
  121. package/dist/core/mutators/object-property.js +7 -8
  122. package/dist/core/mutators/return-value.js +65 -33
  123. package/dist/core/mutators/shared/get-branch-copy-skip.d.ts +12 -7
  124. package/dist/core/mutators/shared/get-branch-copy-skip.js +34 -35
  125. package/dist/core/mutators/shared/get-canonical-falsy-default.d.ts +32 -0
  126. package/dist/core/mutators/shared/get-canonical-falsy-default.js +11 -0
  127. package/dist/core/mutators/shared/get-comparison-plan.js +86 -85
  128. package/dist/core/mutators/shared/get-condition-constants.d.ts +8 -8
  129. package/dist/core/mutators/shared/get-condition-constants.js +3 -3
  130. package/dist/core/mutators/shared/get-endless-value.d.ts +20 -0
  131. package/dist/core/mutators/shared/get-endless-value.js +25 -0
  132. package/dist/core/mutators/shared/get-forced-test-justifier.d.ts +44 -0
  133. package/dist/core/mutators/shared/get-forced-test-justifier.js +25 -0
  134. package/dist/core/mutators/shared/get-group-constant.d.ts +4 -4
  135. package/dist/core/mutators/shared/get-group-constant.js +2 -2
  136. package/dist/core/mutators/shared/get-literal-skip.d.ts +6 -6
  137. package/dist/core/mutators/shared/get-literal-skip.js +2 -2
  138. package/dist/core/mutators/shared/get-logical-drops.d.ts +8 -8
  139. package/dist/core/mutators/shared/get-logical-drops.js +80 -82
  140. package/dist/core/mutators/shared/get-owner-constant.d.ts +3 -1
  141. package/dist/core/mutators/shared/get-running-value.d.ts +5 -4
  142. package/dist/core/mutators/shared/get-toward-mutant.d.ts +10 -2
  143. package/dist/core/mutators/shared/get-toward-mutant.js +45 -40
  144. package/dist/core/mutators/shared/has-other-exit.js +16 -36
  145. package/dist/core/mutators/shared/is-loop-exit.d.ts +20 -0
  146. package/dist/core/mutators/shared/is-loop-exit.js +32 -0
  147. package/dist/core/mutators/shared/is-read-only.d.ts +26 -0
  148. package/dist/core/mutators/shared/is-read-only.js +53 -0
  149. package/dist/core/mutators/statement-removal.d.ts +4 -3
  150. package/dist/core/mutators/statement-removal.js +69 -73
  151. package/dist/core/mutators/string-literal.d.ts +15 -5
  152. package/dist/core/mutators/string-literal.js +79 -50
  153. package/dist/core/presets/recommended.d.ts +2 -2
  154. package/dist/core/presets/strict.d.ts +4 -2
  155. package/dist/core/run/apply-batch-result.d.ts +23 -22
  156. package/dist/core/run/apply-batch-result.js +5 -5
  157. package/dist/core/run/apply-isolated-result.d.ts +18 -17
  158. package/dist/core/run/apply-isolated-result.js +1 -0
  159. package/dist/core/run/classify-try.d.ts +9 -8
  160. package/dist/core/run/get-test-file-limits.d.ts +13 -0
  161. package/dist/core/run/get-test-file-limits.js +13 -0
  162. package/dist/core/run/get-unit-evidence.d.ts +6 -3
  163. package/dist/core/run/get-unit-evidence.js +1 -1
  164. package/dist/core/run/plan-batch.d.ts +6 -3
  165. package/dist/core/run/plan-batch.js +36 -31
  166. package/dist/core/run/plan-isolated.d.ts +3 -1
  167. package/dist/core/run/plan-isolated.js +8 -14
  168. package/dist/core/run/read-isolated-unit.d.ts +4 -4
  169. package/dist/core/run/run-batch-phases.d.ts +4 -3
  170. package/dist/core/run/run-dry-phase.d.ts +35 -19
  171. package/dist/core/run/run-dry-phase.js +127 -77
  172. package/dist/core/run/run-isolated-rounds.d.ts +6 -5
  173. package/dist/core/run/run-isolated-rounds.js +1 -0
  174. package/dist/core/run-mutants.d.ts +26 -21
  175. package/dist/core/run-mutants.js +72 -64
  176. package/dist/core/runtime/create-hit-limit-error.d.ts +5 -3
  177. package/dist/core/runtime/create-hit-limit-error.js +1 -1
  178. package/dist/core/runtime/install-mutant-runtime.js +23 -6
  179. package/dist/core/runtime/runtime-version.d.ts +4 -4
  180. package/dist/core/skips/skip-rules.d.ts +4 -0
  181. package/dist/core/skips/skip-rules.js +4 -0
  182. package/dist/core/syntax/is-brace-sensitive-attribute.d.ts +18 -0
  183. package/dist/core/syntax/is-brace-sensitive-attribute.js +28 -0
  184. package/dist/core/syntax/is-spread-safe-member.d.ts +18 -0
  185. package/dist/core/syntax/is-spread-safe-member.js +18 -0
  186. package/dist/core/syntax/is-value-position.d.ts +3 -1
  187. package/dist/core/text/get-list-removal-range.d.ts +22 -0
  188. package/dist/core/text/get-list-removal-range.js +46 -0
  189. package/dist/core/text/is-plain-attribute-string.d.ts +10 -0
  190. package/dist/core/text/is-plain-attribute-string.js +5 -0
  191. package/dist/core/text/parse-expression.d.ts +8 -4
  192. package/dist/core/text/parse-expression.js +1 -0
  193. package/dist/core/text/remove-list-element.d.ts +2 -4
  194. package/dist/core/text/remove-list-element.js +4 -45
  195. package/dist/docs/styles/colors.js +1 -1
  196. package/dist/package.js +1 -1
  197. package/dist/types/adapter/dry-file.d.ts +2 -1
  198. package/dist/types/adapter/dry-run-request.d.ts +5 -4
  199. package/dist/types/adapter/mutant-runtime.d.ts +30 -1
  200. package/dist/types/cli/text-style.d.ts +1 -1
  201. package/dist/types/config/preset-settings.d.ts +2 -2
  202. package/dist/types/config/run-config.d.ts +12 -4
  203. package/dist/types/html/indexed-mutant.d.ts +4 -2
  204. package/dist/types/html/shown-change.d.ts +4 -3
  205. package/dist/types/mutant/list-removal.d.ts +37 -0
  206. package/dist/types/mutant/mutant-candidate.d.ts +11 -17
  207. package/dist/types/mutant/mutant-host.d.ts +49 -0
  208. package/dist/types/mutant/mutant-kind.d.ts +18 -0
  209. package/dist/types/mutant/mutant-range.d.ts +15 -8
  210. package/dist/types/mutant/mutant.d.ts +9 -15
  211. package/dist/types/mutant/site-syntax.d.ts +14 -0
  212. package/dist/types/mutant/skip-justifier.d.ts +3 -1
  213. package/dist/types/mutant/skipped-candidate.d.ts +13 -10
  214. package/dist/types/mutant/skipped-mutant.d.ts +9 -6
  215. package/dist/types/mutator/replacement.d.ts +14 -3
  216. package/dist/types/report/html-report.d.ts +10 -7
  217. package/dist/types/report/list-report-focus.d.ts +3 -2
  218. package/dist/types/report/list-report-justifier.d.ts +4 -2
  219. package/dist/types/report/list-report-mutant.d.ts +15 -9
  220. package/dist/types/report/list-report-skipped.d.ts +3 -2
  221. package/dist/types/report/list-report.d.ts +1 -1
  222. package/dist/types/report/run-report.d.ts +2 -2
  223. package/dist/types/report/slim-list-report.d.ts +6 -3
  224. package/dist/types/report/slim-run-report.d.ts +1 -1
  225. package/dist/types/run/isolated-reason.d.ts +4 -3
  226. package/dist/types/run/mutant-state.d.ts +1 -1
  227. package/dist/types/run/run-event.d.ts +1 -1
  228. package/dist/types/run/run-kind.d.ts +3 -2
  229. package/dist/types/run/run-result.d.ts +6 -3
  230. package/dist/types/run/run-state.d.ts +9 -1
  231. package/dist/types/run/run-status.d.ts +2 -2
  232. package/dist/types/run/try-cause.d.ts +8 -6
  233. package/dist/types/syntax/syntax-helpers.d.ts +5 -3
  234. package/package.json +5 -5
  235. package/skills/mootant/SKILL.md +14 -12
  236. package/skills/mootant/references/mutators.md +3 -1
  237. package/dist/core/instrument/get-site-check.d.ts +0 -9
  238. package/dist/core/instrument/get-site-check.js +0 -5
  239. package/dist/core/instrument/get-template-site-check.d.ts +0 -12
  240. package/dist/core/instrument/get-template-site-check.js +0 -5
  241. /package/dist/cli/{built-in-adapters.d.ts → get-built-in-adapters.d.ts} +0 -0
  242. /package/dist/cli/{built-in-adapters.js → get-built-in-adapters.js} +0 -0
  243. /package/dist/cli/terminal/{colors.d.ts → create-colors.d.ts} +0 -0
  244. /package/dist/cli/terminal/{colors.js → create-colors.js} +0 -0
@@ -1,48 +1,55 @@
1
- import { compareCandidates as e } from "./compare-candidates.js";
2
- function t(e) {
3
- let t = /* @__PURE__ */ new Map(), r = e.filter((e) => e.solitary !== null).toSorted(a);
4
- for (let i of r) for (let r of i.solitary) {
5
- let a = n({
6
- candidates: e,
7
- candidate: i,
8
- dropped: t,
9
- range: r
1
+ import { compareTargets as e } from "./compare-targets.js";
2
+ import { getTarget as t } from "./get-target.js";
3
+ const n = /^(?:''|""|``)$/u;
4
+ function r(t) {
5
+ let n = /* @__PURE__ */ new Map(), r = t.toSorted(e), a = r.filter((e) => e.solitary !== null).toSorted(c);
6
+ for (let e of a) for (let t of e.solitary) {
7
+ let a = i({
8
+ candidates: r,
9
+ candidate: e,
10
+ dropped: n,
11
+ range: t
10
12
  });
11
13
  if (a !== null) {
12
- t.set(i, a);
14
+ n.set(e, a);
13
15
  break;
14
16
  }
15
17
  }
16
18
  return {
17
- kept: e.filter((e) => !t.has(e)),
18
- dropped: t
19
+ kept: t.filter((e) => !n.has(e)),
20
+ dropped: n
19
21
  };
20
22
  }
21
- function n(e) {
22
- let { candidates: t, candidate: n, dropped: a, range: o } = e;
23
- for (let e = i(t, o.start); e < t.length && t[e].start < o.end; e++) {
24
- let i = t[e];
25
- if (i !== n && i.end <= o.end && !a.has(i) && r(i, n)) return i;
23
+ function i(e) {
24
+ let { candidates: n, candidate: r, dropped: i, range: c } = e;
25
+ for (let e = o(n, c.start); e < n.length && t(n[e]).start < c.end; e++) {
26
+ let o = n[e];
27
+ if (o !== r && t(o).end <= c.end && !i.has(o) && !s(o, r, c) && a(o, r)) return o;
26
28
  }
27
29
  return null;
28
30
  }
29
- function r(e, t) {
30
- return e.registered.mutator.meta.countsForSolitary === !1 || e.registered === t.registered && e.start === t.start && e.end === t.end ? !1 : t.ignoreRule !== null || e.ignoreRule === null;
31
+ function a(e, n) {
32
+ if (e.registered.mutator.meta.countsForSolitary === !1) return !1;
33
+ let r = t(e), i = t(n);
34
+ return e.registered === n.registered && r.start === i.start && r.end === i.end ? !1 : n.ignoreRule !== null || e.ignoreRule === null;
31
35
  }
32
- function i(e, t) {
33
- let n = 0, r = e.length;
34
- for (; n < r;) {
35
- let i = Math.floor((n + r) / 2);
36
- e[i].start < t ? n = i + 1 : r = i;
36
+ function o(e, n) {
37
+ let r = 0, i = e.length;
38
+ for (; r < i;) {
39
+ let a = Math.floor((r + i) / 2);
40
+ t(e[a]).start < n ? r = a + 1 : i = a;
37
41
  }
38
- return n;
42
+ return r;
39
43
  }
40
- function a(t, n) {
41
- return o(t) - o(n) || t.solitary[0].start - n.solitary[0].start || e(t, n);
44
+ function s(e, t, r) {
45
+ return t.registered.id === "array-element" && e.registered.id === "string-literal" && n.test(e.text) && e.start === r.start && e.end === r.end;
42
46
  }
43
- function o(e) {
47
+ function c(t, n) {
48
+ return l(t) - l(n) || t.solitary[0].start - n.solitary[0].start || e(t, n);
49
+ }
50
+ function l(e) {
44
51
  let t = 0;
45
52
  for (let n of e.solitary) t += n.end - n.start;
46
53
  return t;
47
54
  }
48
- export { t as applySolitaryRule };
55
+ export { r as applySolitaryRule };
@@ -105,10 +105,11 @@ interface CandidateCollection {
105
105
  * creates its visitors once, in rank order; then every dispatched node is
106
106
  * passed, in pre-order, to the visitors registered for its type. Each returned
107
107
  * replacement is validated and becomes a candidate with its kind, scope path,
108
- * solitary ranges and ignore rule. A throwing `create` or visitor and an
109
- * invalid replacement become mutator errors and cost only that mutator, visit
110
- * or replacement. A replacement that would move code its framework compiler
111
- * reads where it stands, such as a Svelte rune call or a Vue compiler macro, is
108
+ * solitary ranges and ignore rule, which ignore directives decide where it is
109
+ * placed (see `getMutantSite`). A throwing `create` or visitor and an invalid
110
+ * replacement become mutator errors and cost only that mutator, visit or
111
+ * replacement. A replacement that would move code its framework compiler reads
112
+ * where it stands, such as a Svelte rune call or a Vue compiler macro, is
112
113
  * dropped. A replacement that only changes a literal in the delay of a known
113
114
  * timer call, such as `1000` turned into `1001`, is skipped as noise, even when
114
115
  * its visitor skipped it for another rule; a replacement there that touches a
@@ -125,6 +126,19 @@ interface CandidateCollection {
125
126
  * template is fitted into the attribute value or the interpolation around it,
126
127
  * or skipped when it cannot be.
127
128
  *
129
+ * A replacement with an empty text for an element of an array literal or a
130
+ * member of an object literal removes that element (see `findListRemoval`). Its
131
+ * candidate replaces only the element with the comma next to it (see
132
+ * `getListRemovalRange`), with the element as its focus, and is hosted with the
133
+ * other removals of its literal. A removal that is not narrowed replaces the
134
+ * whole literal instead, which takes a copy of the literal per removal; when a
135
+ * literal has more than eight such removals, none of them becomes a candidate,
136
+ * and each is skipped in the narrowed shape, without a copy. Every check that
137
+ * looks at the replaced node, such as the template filter, compiler pins and
138
+ * loop advances, looks at the literal of a removal, as it does for the whole
139
+ * literal. In a Vue template, a removal that would join the text around it into
140
+ * the delimiter of the template code is skipped.
141
+ *
128
142
  * @param input - Mutators, parsed file, runtime tree, ignore rules and shared
129
143
  * context services.
130
144
  * @returns Candidates in emission order, mutator errors and skipped
@@ -1,126 +1,208 @@
1
- import { getSourcePosition as e } from "../text/get-source-position.js";
2
- import { findCompilerPins as t } from "../syntax/find-compiler-pins.js";
3
- import { readLiteralType as n } from "../syntax/read-literal-type.js";
4
- import { validateReplacement as r } from "./validate-replacement.js";
5
- import { findIgnoreRule as i } from "../ignore/find-ignore-rule.js";
6
- import { getReplacementKind as a } from "./get-replacement-kind.js";
7
- import { parseExpression as o } from "../text/parse-expression.js";
8
- import { getScopePath as s } from "../identity/get-scope-path.js";
9
- import { groupReplacement as c } from "./group-replacement.js";
10
- import { fitTemplateText as l } from "./fit-template-text.js";
11
- import { getSlot as u } from "../tree/get-slot.js";
12
- import { pickFocus as d } from "./pick-focus.js";
13
- const f = {
1
+ import { getComponentFramework as e } from "../parser/get-component-framework.js";
2
+ import { getListRemovalRange as t } from "../text/get-list-removal-range.js";
3
+ import { getSourcePosition as n } from "../text/get-source-position.js";
4
+ import { findCompilerPins as r } from "../syntax/find-compiler-pins.js";
5
+ import { removeListElement as i } from "../text/remove-list-element.js";
6
+ import { readLiteralType as a } from "../syntax/read-literal-type.js";
7
+ import { validateReplacement as o } from "./validate-replacement.js";
8
+ import { findIgnoreRule as s } from "../ignore/find-ignore-rule.js";
9
+ import { getReplacementKind as c } from "./get-replacement-kind.js";
10
+ import { parseExpression as l } from "../text/parse-expression.js";
11
+ import { getScopePath as u } from "../identity/get-scope-path.js";
12
+ import { groupReplacement as d } from "./group-replacement.js";
13
+ import { fitTemplateText as f } from "./fit-template-text.js";
14
+ import { findListRemoval as p } from "./find-list-removal.js";
15
+ import { getMutantSite as m } from "./get-mutant-site.js";
16
+ import { getSlot as h } from "../tree/get-slot.js";
17
+ import { pickFocus as g } from "./pick-focus.js";
18
+ const _ = {
14
19
  reason: "it only changes a timer delay",
15
20
  rule: "timer-delay"
16
21
  };
17
- function p(p) {
18
- let { services: _, parsed: v, rules: y, tree: b } = p, x = v.language === "typescript" ? "ts" : "js", S = [], C = [], w = [];
19
- function T(e, t, n) {
20
- if (p.skipped) {
22
+ function v(v) {
23
+ let { services: S, parsed: C, rules: w, tree: T } = v, E = C.language === "typescript" ? "ts" : "js", D = [], O = [], k = [];
24
+ function A(e, t, n) {
25
+ if (v.skipped) {
21
26
  let { by: r } = n;
22
- w.push({
27
+ k.push({
23
28
  by: r ? {
24
29
  start: r.node.start,
25
30
  mutator: r.mutator,
26
31
  id: null
27
32
  } : null,
28
- kind: a(t.node),
29
33
  heuristic: n.heuristic === !0,
30
- start: t.node.start,
31
- end: t.node.end,
32
- emission: w.length,
33
- text: t.text,
34
+ emission: k.length,
35
+ start: t.start,
34
36
  reason: n.reason,
37
+ kind: t.kind,
38
+ text: t.text,
39
+ end: t.end,
35
40
  rule: n.rule,
36
41
  registered: e,
37
- ...d(t)
42
+ ...g(t)
38
43
  });
39
44
  }
40
45
  }
41
- function E(e) {
42
- let { syntax: t } = _, { node: r, text: i } = e;
43
- if (!t.isRuntimeNode(r) || !t.isTimerDelay(r)) return !1;
44
- let a = n(r);
45
- if (a === null) return !1;
46
- let s = o(i, x);
47
- return s !== null && n(s) === a;
46
+ function j(e, n, r) {
47
+ if (r?.narrow) {
48
+ let { start: e, end: i } = n.node;
49
+ return {
50
+ ...t(C, r.list, r.index),
51
+ list: {
52
+ start: r.list.start,
53
+ end: r.list.end
54
+ },
55
+ focus: {
56
+ text: "",
57
+ start: e,
58
+ end: i
59
+ },
60
+ kind: r.kind,
61
+ text: ""
62
+ };
63
+ }
64
+ let a = r === null ? n : {
65
+ text: i(C, r.list, r.index),
66
+ node: r.list
67
+ }, { node: o, text: s } = d(a, {
68
+ parsed: C,
69
+ tree: T
70
+ }, e.id.includes("/"));
71
+ return {
72
+ kind: c(o),
73
+ start: o.start,
74
+ end: o.end,
75
+ text: s,
76
+ ...g(a)
77
+ };
78
+ }
79
+ function M(e, t) {
80
+ let { syntax: n } = S;
81
+ if (!n.isRuntimeNode(e) || !n.isTimerDelay(e)) return !1;
82
+ let r = a(e);
83
+ if (r === null) return !1;
84
+ let i = l(t, E);
85
+ return i !== null && a(i) === r;
86
+ }
87
+ function N(e, t) {
88
+ if (e.kind !== "element" && e.kind !== "property") return f(e.text, t, E);
89
+ let n = C.text.slice(e.start - 1, e.start) + C.text.slice(e.end, e.end + 1), r = f(n, t, E);
90
+ return r.kind === "fit" ? {
91
+ text: e.text,
92
+ kind: "fit"
93
+ } : r;
48
94
  }
49
- function D(t, n, o) {
50
- if (k !== null && (k.has(o.node) || a(o.node) !== "expression")) return;
51
- if (o.skip) {
52
- T(t, o, E(o) ? f : o.skip);
95
+ function P(e, t, r) {
96
+ let i = p(T, r, L), a = i?.list ?? r.node;
97
+ if (I !== null && (I.has(a) || c(a) !== "expression")) return;
98
+ let l = i !== null && !i.narrow && i.copies > 8;
99
+ l && i !== null && (i = {
100
+ ...i,
101
+ narrow: !0
102
+ });
103
+ let d = j(e, r, i);
104
+ if (r.skip) {
105
+ A(e, d, M(a, d.text) ? _ : r.skip);
53
106
  return;
54
107
  }
55
- let c = r(b, o.node, o.focus);
56
- if (c !== null) {
57
- S.push(h(v, n, `Mutator "${t.id}" ${c}`)), T(t, o, {
58
- reason: `the mutator ${c.slice(0, -1)}`,
108
+ let f = i === null && r.text === "" && d.kind === "expression", h = f ? `returned an empty text for a ${a.type} node; only an element of an array literal or a member of an object literal is removed with an empty text.` : o(T, a, d);
109
+ if (h !== null) {
110
+ D.push(b(C, t, `Mutator "${e.id}" ${h}`)), A(e, f ? {
111
+ ...d,
112
+ text: ""
113
+ } : d, {
114
+ reason: `the mutator ${h.slice(0, -1)}`,
59
115
  rule: "invalid-target"
60
116
  });
61
117
  return;
62
118
  }
63
- let { start: u, end: m } = o.node, w = O.find((e) => u <= e.start && e.end <= m && e.region.start <= u && m <= e.region.end);
64
- if (w) {
65
- T(t, o, {
119
+ let { start: y, end: E } = a, k = F.find((e) => y <= e.start && e.end <= E && e.region.start <= y && E <= e.region.end);
120
+ if (k) {
121
+ A(e, d, {
66
122
  rule: "compiler-macro",
67
- reason: w.reason
123
+ reason: k.reason
68
124
  });
69
125
  return;
70
126
  }
71
- let D = p.expressions?.findLast((e) => e.start <= u)?.delimiter, A = D === void 0 ? {
72
- text: o.text,
73
- kind: "fit"
74
- } : l(o.text, D, x);
75
- A.kind === "unfit" ? T(t, o, {
76
- rule: "template-text",
77
- reason: A.reason
78
- }) : E(o) ? T(t, o, f) : !_.settings.timeouts && t.id !== "optional-chaining" && _.syntax.isLoopAdvanceValue(o.node) ? T(t, o, {
79
- reason: "it changes the value that advances a loop, so it may keep the loop running forever",
80
- rule: "loop-advance"
81
- }) : C.push({
82
- ignoreRule: i(y, {
83
- line: e(v.lineStarts, u).line,
84
- mutator: t.id,
85
- start: u
127
+ let P = v.expressions?.findLast((e) => e.start <= y)?.delimiter, R = P === void 0 ? {
128
+ kind: "fit",
129
+ text: d.text
130
+ } : N(d, P);
131
+ if (R.kind === "unfit") {
132
+ A(e, d, {
133
+ rule: "template-text",
134
+ reason: R.reason
135
+ });
136
+ return;
137
+ }
138
+ if (M(a, d.text)) {
139
+ A(e, d, _);
140
+ return;
141
+ }
142
+ if (!S.settings.timeouts && e.id !== "optional-chaining" && S.syntax.isLoopAdvanceValue(a)) {
143
+ A(e, d, {
144
+ reason: "it changes the value that advances a loop, so it may keep the loop running forever",
145
+ rule: "loop-advance"
146
+ });
147
+ return;
148
+ }
149
+ if (l) {
150
+ A(e, d, {
151
+ reason: `removing it takes a copy of the whole literal, which Mootant does not make for a literal with more than 8 such ${d.kind === "element" ? "elements" : "members"}`,
152
+ rule: "literal-copies"
153
+ });
154
+ return;
155
+ }
156
+ let z = d.kind === "element" || d.kind === "property" ? {
157
+ focus: d.focus,
158
+ kind: d.kind,
159
+ list: d.list
160
+ } : {
161
+ kind: d.kind,
162
+ ...g(d)
163
+ }, B = m({
164
+ ...z,
165
+ start: d.start
166
+ });
167
+ O.push({
168
+ ignoreRule: s(w, {
169
+ line: n(C.lineStarts, B).line,
170
+ mutator: e.id,
171
+ start: B
86
172
  }),
87
- scope: k === null ? s(b, o.node) : "<template>",
88
- solitary: g(o.solitary),
89
- kind: a(o.node),
90
- emission: C.length,
91
- text: A.text,
92
- registered: t,
93
- start: u,
94
- end: m,
95
- ...d(o)
173
+ scope: I === null ? u(T, a) : "<template>",
174
+ solitary: x(r.solitary),
175
+ emission: O.length,
176
+ start: d.start,
177
+ end: d.end,
178
+ text: R.text,
179
+ registered: e,
180
+ ...z
96
181
  });
97
182
  }
98
- let O = t(b, v.file), k = p.hosts ?? null, A = m(p, S);
99
- for (let e of b.order) {
100
- let t = A.get(e.type);
183
+ let F = r(T, C.file), I = v.hosts ?? null, L = I !== null && e(C.file) === "svelte", R = y(v, D);
184
+ for (let e of T.order) {
185
+ let t = R.get(e.type);
101
186
  if (!t) continue;
102
- let { parent: n } = u(b, e);
187
+ let { parent: n } = h(T, e);
103
188
  for (let { registered: r, visit: i } of t) {
104
189
  let t;
105
190
  try {
106
191
  t = i(e, n);
107
192
  } catch (t) {
108
- S.push(h(v, e, `Mutator "${r.id}" failed on ${e.type}: ${t.message}`));
193
+ D.push(b(C, e, `Mutator "${r.id}" failed on ${e.type}: ${t.message}`));
109
194
  continue;
110
195
  }
111
- for (let n of t) D(r, e, c(n, {
112
- parsed: v,
113
- tree: b
114
- }, r.id.includes("/")));
196
+ for (let n of t) P(r, e, n);
115
197
  }
116
198
  }
117
199
  return {
118
- diagnostics: S,
119
- candidates: C,
120
- skipped: w
200
+ diagnostics: D,
201
+ candidates: O,
202
+ skipped: k
121
203
  };
122
204
  }
123
- function m(e, t) {
205
+ function y(e, t) {
124
206
  let { services: n, mutators: r, parsed: i } = e, a = /* @__PURE__ */ new Map();
125
207
  for (let e of r) {
126
208
  let r;
@@ -132,7 +214,7 @@ function m(e, t) {
132
214
  file: i.file
133
215
  });
134
216
  } catch (n) {
135
- t.push(h(i, null, `Mutator "${e.id}" failed while preparing the file: ${n.message}`));
217
+ t.push(b(i, null, `Mutator "${e.id}" failed while preparing the file: ${n.message}`));
136
218
  continue;
137
219
  }
138
220
  for (let [t, n] of Object.entries(r)) {
@@ -145,21 +227,21 @@ function m(e, t) {
145
227
  }
146
228
  return a;
147
229
  }
148
- function h(t, n, r) {
149
- let i = n === null ? null : e(t.lineStarts, n.start);
230
+ function b(e, t, r) {
231
+ let i = t === null ? null : n(e.lineStarts, t.start);
150
232
  return {
151
233
  column: i?.column ?? null,
152
234
  line: i?.line ?? null,
153
235
  code: "mutator-error",
154
- file: t.file,
236
+ file: e.file,
155
237
  severity: "error",
156
238
  message: r
157
239
  };
158
240
  }
159
- function g(e) {
241
+ function x(e) {
160
242
  return !e || e.length === 0 ? null : e.map(({ start: e, end: t }) => ({
161
243
  start: e,
162
244
  end: t
163
245
  }));
164
246
  }
165
- export { p as collectCandidates };
247
+ export { v as collectCandidates };
@@ -0,0 +1,14 @@
1
+ import { MutantCandidate } from '../../types/mutant/mutant-candidate.js';
2
+ /**
3
+ * Compares two candidates of one file in canonical order (see
4
+ * `compareCandidates`), but by their targets instead of the ranges they write
5
+ * over (see `getTarget`): by target start ascending, then by target end
6
+ * descending, then by mutator rank, then by the order in which visitors
7
+ * returned them. So the removal of an element comes where its literal does.
8
+ *
9
+ * @param left - First candidate.
10
+ * @param right - Second candidate.
11
+ * @returns A negative number when the left candidate comes first, a positive
12
+ * number when the right one does, and 0 for the same candidate.
13
+ */
14
+ export declare function compareTargets(left: MutantCandidate, right: MutantCandidate): number;
@@ -0,0 +1,6 @@
1
+ import { getTarget as e } from "./get-target.js";
2
+ function t(t, n) {
3
+ let r = e(t), i = e(n);
4
+ return r.start - i.start || i.end - r.end || t.registered.rank - n.registered.rank || t.emission - n.emission;
5
+ }
6
+ export { t as compareTargets };
@@ -14,10 +14,12 @@ interface DeduplicationOutcome {
14
14
  kept: MutantCandidate[];
15
15
  }
16
16
  /**
17
- * Keeps the first candidate, in canonical order, of every group of candidates
18
- * that produce the same mutated file. Two candidates are compared by the
19
- * smallest edit that turns the original text into their mutated text, so a
20
- * nested duplicate, such as dropping either `!` of `!!a`, is found as well as
17
+ * Keeps the first candidate of every group of candidates that produce the same
18
+ * mutated file, in canonical order but by the node each replacement names (see
19
+ * `getTarget`), so the removal of an element competes from the start of its
20
+ * literal, as the whole literal it amounts to does. Two candidates are compared
21
+ * by the smallest edit that turns the original text into their mutated text, so
22
+ * a nested duplicate, such as dropping either `!` of `!!a`, is found as well as
21
23
  * the same replacement from two mutators. Statuses do not matter: the first
22
24
  * candidate wins even when it is ignored.
23
25
  *
@@ -1,14 +1,16 @@
1
- function e(e, n) {
2
- let r = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map();
1
+ import { compareTargets as e } from "./compare-targets.js";
2
+ function t(t, r) {
3
+ let i = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map();
4
+ for (let o of t.toSorted(e)) {
5
+ let e = n(r, o), t = i.get(e);
6
+ t ? a.set(o, t) : i.set(e, o);
7
+ }
3
8
  return {
4
- duplicates: i,
5
- kept: e.filter((e) => {
6
- let a = t(n, e), o = r.get(a);
7
- return o ? (i.set(e, o), !1) : (r.set(a, e), !0);
8
- })
9
+ kept: t.filter((e) => !a.has(e)),
10
+ duplicates: a
9
11
  };
10
12
  }
11
- function t(e, t) {
13
+ function n(e, t) {
12
14
  let { start: n, end: r } = t, i = t.text, a = e.length - (r - n) + i.length, o = Math.min(e.length, a);
13
15
  function s(t) {
14
16
  let a = t - n;
@@ -22,4 +24,4 @@ function t(e, t) {
22
24
  for (let e = c; e < a - l; e++) u += s(e);
23
25
  return `${c}:${e.length - l}:${u}`;
24
26
  }
25
- export { e as deduplicateCandidates };
27
+ export { t as deduplicateCandidates };
@@ -0,0 +1,20 @@
1
+ import { ListRemoval } from '../../types/mutant/list-removal.js';
2
+ import { Replacement } from '../../types/mutator/replacement.js';
3
+ import { TreeIndex } from '../../types/syntax/tree-index.js';
4
+ /**
5
+ * Tells whether a replacement removes one element of an array literal or one
6
+ * member of an object literal: its text is empty and its node is an element or
7
+ * member of a literal in the runtime tree. The removal is narrowed to the
8
+ * element unless the copy of the literal that leaves an element out could not
9
+ * be built around it: in an array with a hole, which the copy would read and
10
+ * fill, or for a member that a spread would change (see `isSpreadSafeMember`).
11
+ * In a Svelte template no removal is narrowed, since the compiler reads class
12
+ * values as written.
13
+ *
14
+ * @param tree - Runtime tree of the file.
15
+ * @param replacement - Replacement a mutator returned.
16
+ * @param template - Whether the tree is the code of a Svelte template.
17
+ * @returns The literal, the position, whether the removal is narrowed and how
18
+ * many removals of the literal are not, or null for any other replacement.
19
+ */
20
+ export declare function findListRemoval(tree: TreeIndex, replacement: Replacement, template: boolean): ListRemoval | null;
@@ -0,0 +1,26 @@
1
+ import { isSpreadSafeMember as e } from "../syntax/is-spread-safe-member.js";
2
+ let t = /* @__PURE__ */ new WeakMap();
3
+ function n(e, n, i) {
4
+ let a = e.slots.get(n.node);
5
+ if (!a || n.text !== "") return null;
6
+ let { parent: o, index: s } = a;
7
+ if (s === null || o?.type !== "ArrayExpression" && o?.type !== "ObjectExpression") return null;
8
+ let c = t.get(o);
9
+ return c === void 0 && (c = r(o, i), t.set(o, c)), {
10
+ kind: o.type === "ArrayExpression" ? "element" : "property",
11
+ narrow: !c.has(s),
12
+ copies: c.size,
13
+ list: o,
14
+ index: s
15
+ };
16
+ }
17
+ function r(t, n) {
18
+ let r = /* @__PURE__ */ new Set();
19
+ if (t.type === "ArrayExpression") {
20
+ if (n || t.elements.includes(null)) for (let [e, n] of t.elements.entries()) n !== null && r.add(e);
21
+ return r;
22
+ }
23
+ for (let [i, a] of t.properties.entries()) (n || !e(a)) && r.add(i);
24
+ return r;
25
+ }
26
+ export { n as findListRemoval };