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
@@ -17,6 +17,10 @@ let m = /* @__PURE__ */ new Set([
17
17
  "let",
18
18
  "var"
19
19
  ]), h = /* @__PURE__ */ new Set([
20
+ "&&=",
21
+ "??=",
22
+ "||="
23
+ ]), g = /* @__PURE__ */ new Set(["unshift", "push"]), _ = /* @__PURE__ */ new Set([
20
24
  "TaggedTemplateExpression",
21
25
  "AssignmentExpression",
22
26
  "UpdateExpression",
@@ -24,7 +28,7 @@ let m = /* @__PURE__ */ new Set([
24
28
  "YieldExpression",
25
29
  "CallExpression",
26
30
  "NewExpression"
27
- ]), g = {
31
+ ]), v = {
28
32
  boolean: [{
29
33
  text: "true",
30
34
  value: !0
@@ -56,24 +60,24 @@ let m = /* @__PURE__ */ new Set([
56
60
  text: "0",
57
61
  value: 0
58
62
  }]
59
- }, _ = {
63
+ }, y = {
60
64
  create(e) {
61
65
  return {
62
66
  ArrowFunctionExpression(t) {
63
- return t.body.type === "BlockStatement" ? [] : v(t.body, e);
67
+ return t.body.type === "BlockStatement" ? [] : b(t.body, e);
64
68
  },
65
69
  ReturnStatement(t) {
66
- return t.argument ? v(t.argument, e) : [];
70
+ return t.argument ? b(t.argument, e) : [];
67
71
  }
68
72
  };
69
73
  },
70
74
  meta: { description: "Replaces a returned value with an empty default ('', 0, false and true, [] or undefined), or a promise of one." }
71
75
  };
72
- function v(n, a) {
76
+ function b(n, a) {
73
77
  let { syntax: o } = a, s = o.unwrapParentheses(n), c = o.unwrapExpression(s), l = e(s, a);
74
78
  if (l === null || t(c, a)) return [];
75
- let d = typeof l == "object" ? O(l, c, a) : b(l, c);
76
- if (A(c, a)) return d.map((e) => ({
79
+ let d = typeof l == "object" ? F(l, c, a) : S(l, c);
80
+ if (I(c, a)) return d.map((e) => ({
77
81
  skip: {
78
82
  reason: "it only replaces a returned logging call",
79
83
  rule: "logging-call"
@@ -81,7 +85,7 @@ function v(n, a) {
81
85
  text: e.text,
82
86
  node: s
83
87
  }));
84
- if (l === "void" && !E(c) && (!o.getEnclosingFunction(s)?.async || o.isNonThenable(c))) return [{
88
+ if (l === "void" && !N(c) && (!o.getEnclosingFunction(s)?.async || o.isNonThenable(c))) return [{
85
89
  skip: {
86
90
  reason: "the function returns void and the value has no effect to remove",
87
91
  rule: "void-result"
@@ -89,7 +93,7 @@ function v(n, a) {
89
93
  text: "undefined",
90
94
  node: s
91
95
  }];
92
- let f = i(s, a), p = l === "boolean" ? null : [s, ...C(c, a)];
96
+ let f = i(s, a), p = l === "boolean" ? null : [s, ...A(c, a)];
93
97
  return d.map((e) => {
94
98
  let t = p ? {
95
99
  text: e.text,
@@ -99,19 +103,19 @@ function v(n, a) {
99
103
  text: e.text,
100
104
  node: s
101
105
  }, n = f && u(f.owner, e.value) ? r : null;
102
- return !n && l === "boolean" && (n = y(s, e.value === !0, a)), n && (t.skip = n), t;
106
+ return !n && l === "boolean" && (n = x(s, e.value === !0, a)), n && (t.skip = n), t;
103
107
  });
104
108
  }
105
- function y(e, t, n) {
109
+ function x(e, t, n) {
106
110
  let r = o(e, t, n);
107
111
  if (r) return {
108
112
  reason: `it makes the result ${t}, as ${r.mutator} does`,
109
113
  rule: "O19",
110
114
  by: r
111
115
  };
112
- let i = D(e, t, n);
116
+ let i = P(e, t, n);
113
117
  if (i) return i;
114
- let a = [e, ...k(n.syntax.unwrapExpression(e), n)], c = {
118
+ let a = [e, ...E(n.syntax.unwrapExpression(e), n)], c = {
115
119
  mutator: n.id,
116
120
  node: e
117
121
  }, u = s(n);
@@ -129,7 +133,7 @@ function y(e, t, n) {
129
133
  }
130
134
  return null;
131
135
  }
132
- function b(e, t) {
136
+ function S(e, t) {
133
137
  switch (e) {
134
138
  case "boolean": return [{
135
139
  text: "true",
@@ -161,56 +165,84 @@ function b(e, t) {
161
165
  }];
162
166
  }
163
167
  }
164
- function x(e, t, r) {
168
+ function C(e, t, n) {
169
+ let { syntax: r } = n;
170
+ if (!r.isRuntimeNode(e)) return !0;
171
+ let { parent: i, key: a } = r.getContextSlot(e);
172
+ switch (i?.type) {
173
+ case "AssignmentExpression": return a !== "left" || h.has(i.operator) || !r.isResultUnused(i);
174
+ case "MemberExpression": return a !== "object" || !T(i, t, n);
175
+ case "UpdateExpression": return !r.isResultUnused(i);
176
+ default: return !0;
177
+ }
178
+ }
179
+ function w(e, t, r) {
165
180
  return t === void 0 ? e.type === "UnaryExpression" && e.operator === "void" && r.syntax.unwrapExpression(e.argument).type === "Literal" || n(e, "undefined", r) : t === null ? e.type === "Literal" && e.raw === "null" : Array.isArray(t) ? e.type === "ArrayExpression" && e.elements.length === 0 : Object.is(c(e), t);
166
181
  }
167
- function S(e, t) {
182
+ function T(e, t, n) {
183
+ let { syntax: r } = n, { init: i } = t.declaration;
184
+ if (!i || e.computed || t.writes.length > 0 || !g.has(e.property.name) || r.unwrapExpression(i).type !== "ArrayExpression") return !1;
185
+ let a = r.getContextSlot(e);
186
+ return a.key === "callee" && a.parent?.type === "CallExpression" && r.isResultUnused(a.parent);
187
+ }
188
+ function E(e, t) {
189
+ let n = e.type === "Identifier" ? k(e, t) : null;
190
+ if (!n || !M(e, n, t)) return [];
191
+ let { syntax: r } = t, { id: i } = n.declaration;
192
+ return O(e, t).flatMap((e) => e.type === "AssignmentExpression" ? r.isResultUnused(e) ? [e.right] : [] : i === n.identifier ? [e] : []);
193
+ }
194
+ function D(e, t) {
168
195
  if (e.type !== "CallExpression" || e.arguments.length > 1) return !1;
169
196
  let { syntax: n } = t, r = n.unwrapExpression(e.callee);
170
197
  if (r.type !== "MemberExpression" || r.computed || r.property.name !== "resolve") return !1;
171
198
  let i = n.unwrapExpression(r.object);
172
199
  return i.type === "Identifier" && i.name === "Promise";
173
200
  }
174
- function C(e, t) {
175
- let n = w(e, t);
201
+ function O(e, t) {
202
+ let n = k(e, t);
176
203
  if (!n) return [];
177
204
  let { init: r } = n.declaration, { syntax: i } = t, a = i.getEnclosingFunction(e);
178
205
  return [...r ? [r] : [], ...n.writes.filter((e) => i.isRuntimeNode(e) && i.getEnclosingFunction(e) === a)];
179
206
  }
180
- function w(e, t) {
207
+ function k(e, t) {
181
208
  let { sourceCode: n, syntax: r } = t, i = d(e), a = n.getBinding(i);
182
209
  return a && m.has(a.kind) && r.isRuntimeNode(a.declaration) && r.getEnclosingFunction(a.declaration) === r.getEnclosingFunction(e) ? a : null;
183
210
  }
184
- function T(e, t, n) {
185
- if (!S(e, n)) return !1;
211
+ function A(e, t) {
212
+ let n = k(e, t), r = d(e);
213
+ return n && (n.declaration.id !== n.identifier || n.references.some((e) => e !== r && C(e, n, t))) ? [] : O(e, t);
214
+ }
215
+ function j(e, t, n) {
216
+ if (!D(e, n)) return !1;
186
217
  let [r] = e.arguments;
187
- return r ? r.type !== "SpreadElement" && x(n.syntax.unwrapExpression(r), t, n) : t === void 0;
218
+ return r ? r.type !== "SpreadElement" && w(n.syntax.unwrapExpression(r), t, n) : t === void 0;
219
+ }
220
+ function M(e, t, n) {
221
+ let r = new Set(t.writes.flatMap((e) => e.type === "AssignmentExpression" && e.operator === "=" ? [n.syntax.unwrapExpression(e.left)] : []));
222
+ return t.references.every((t) => t === e || r.has(t));
188
223
  }
189
- function E(e) {
224
+ function N(e) {
190
225
  switch (e.type) {
191
- case "SequenceExpression": return e.expressions.some(E);
226
+ case "SequenceExpression": return e.expressions.some(N);
192
227
  case "ChainExpression": return e.expression.type === "CallExpression";
193
228
  case "UnaryExpression": return e.operator === "delete";
194
- default: return h.has(e.type);
229
+ default: return _.has(e.type);
195
230
  }
196
231
  }
197
- function D(e, t, n) {
232
+ function P(e, t, n) {
198
233
  let { negations: r, node: i } = p(e);
199
234
  if (!f(i)) return null;
200
235
  let o = t !== (r % 2 == 1);
201
236
  return a(i, n).skippedConstants.get(o) ?? null;
202
237
  }
203
- function O(e, t, n) {
204
- return g[e.promise].filter((e) => !T(t, e.value, n)).map((e) => ({
238
+ function F(e, t, n) {
239
+ return v[e.promise].filter((e) => !j(t, e.value, n)).map((e) => ({
205
240
  text: `Promise.resolve(${e.text})`,
206
241
  value: {}
207
242
  }));
208
243
  }
209
- function k(e, t) {
210
- return e.type === "Identifier" ? C(e, t).map((e) => e.type === "AssignmentExpression" && e.operator === "=" ? e.right : e) : [];
211
- }
212
- function A(e, t) {
244
+ function I(e, t) {
213
245
  let n = e.type === "ChainExpression" ? e.expression : e;
214
246
  return n.type === "CallExpression" && t.syntax.isLoggingCall(n);
215
247
  }
216
- export { _ as returnValue };
248
+ export { y as returnValue };
@@ -7,13 +7,18 @@ import { RunContext } from './create-run-context.js';
7
7
  * test of its branch pair (catalog 4.5, 4.11, 4.16; 5.2 O19 and 5.3 R5). A
8
8
  * mutant that gives the branch the value (or, for a template with expressions,
9
9
  * the text) of the other branch makes both branches alike, which is the test
10
- * forced to a constant: skipped statically when the test's owner emits that
11
- * constant, otherwise while a mutant that will run moves the test toward it. A
12
- * flipped boolean branch next to a boolean-valued branch (or any branch of a
13
- * pair in a boolean context or a boolean result) is subsumed the same way by a
14
- * mutant that moves the test toward the other branch. In the statement forms
15
- * the boolean result is judged on the other branch, whose kind the literal
16
- * itself cannot decide. A skipped mutant comes with its rule.
10
+ * forced to a constant while the test still runs: skipped statically when the
11
+ * test has no effect and its owner emits that constant, otherwise while a
12
+ * mutant that will run moves the test toward it and keeps every effect of the
13
+ * test (see `getForcedTestJustifier`). A flipped boolean branch next to a
14
+ * boolean-valued branch (or any branch of a pair in a boolean context or a
15
+ * boolean result) is subsumed the same way by a mutant that moves the test
16
+ * toward the other branch, which then runs where the candidate gives the
17
+ * flipped value, so that branch must have no effect; when its only effects are
18
+ * calls of well-known read-only methods (see `isReadOnly`), the skip rests on
19
+ * that guess. In the statement forms the boolean result is judged on the other
20
+ * branch, whose kind the literal itself cannot decide. A skipped mutant comes
21
+ * with its rule.
17
22
  *
18
23
  * @param node - Literal that a literal mutator would replace.
19
24
  * @param replacement - New value of the literal, or new text of a template with
@@ -1,42 +1,41 @@
1
- import { isExpectedBoolean as e } from "./is-expected-boolean.js";
2
- import { getLiteralMutator as t } from "./get-literal-mutator.js";
3
- import { getOwnerConstant as n } from "./get-owner-constant.js";
4
- import { isBooleanResult as r } from "./is-boolean-result.js";
5
- import { isBooleanValued as i } from "./is-boolean-valued.js";
6
- import { getLiteralValue as a } from "./get-literal-value.js";
7
- import { getTowardMutant as o } from "./get-toward-mutant.js";
1
+ import { getForcedTestJustifier as e } from "./get-forced-test-justifier.js";
2
+ import { isEffectFree as t } from "../../syntax/is-effect-free.js";
3
+ import { isExpectedBoolean as n } from "./is-expected-boolean.js";
4
+ import { getLiteralMutator as r } from "./get-literal-mutator.js";
5
+ import { isBooleanResult as i } from "./is-boolean-result.js";
6
+ import { isBooleanValued as a } from "./is-boolean-valued.js";
7
+ import { getLiteralValue as o } from "./get-literal-value.js";
8
8
  import { getBranchPair as s } from "./get-branch-pair.js";
9
- function c(c, l, u) {
10
- let d = s(c, u);
11
- if (!d) return null;
12
- let { forced: f, other: p, test: m } = d, h = {
9
+ import { isReadOnly as c } from "./is-read-only.js";
10
+ function l(l, u, d) {
11
+ let f = s(l, d);
12
+ if (!f) return null;
13
+ let { forced: p, other: m, test: h } = f, g = {
13
14
  candidate: {
14
- mutator: t(c),
15
- node: c
15
+ mutator: r(l),
16
+ node: l
16
17
  },
17
- decision: m,
18
- value: f
19
- }, g = a(p);
20
- if ("value" in l ? g === l.value : u.sourceCode.getText(p) === l.text) {
21
- let e = n(m, f, u);
22
- if (e) return {
23
- reason: `it copies the other branch, which is the test forced to ${f}, as ${e.mutator} does`,
24
- rule: "O19",
25
- by: e
18
+ decision: h,
19
+ value: p
20
+ }, _ = o(m);
21
+ if ("value" in u ? _ === u.value : d.sourceCode.getText(m) === u.text) {
22
+ let t = e(g, d, !0);
23
+ return t && {
24
+ reason: t.owned ? `it copies the other branch, which is the test forced to ${p}, as ${t.by.mutator} does` : `it copies the other branch, which is the test forced to ${p}, as ${t.by.mutator} does on some inputs`,
25
+ ...t.heuristic && { heuristic: !0 },
26
+ rule: t.owned ? "O19" : "R5",
27
+ by: t.by
26
28
  };
27
- let t = o(h, u);
28
- return t ? {
29
- reason: `it copies the other branch, which is the test forced to ${f}, as ${t.mutator} does on some inputs`,
30
- by: t,
31
- rule: "R5"
32
- } : null;
33
29
  }
34
- if (g !== null || typeof a(c) != "boolean") return null;
35
- let { parent: _ } = u.syntax.getContextSlot(c), v = i(p, u) || (_?.type === "ConditionalExpression" ? u.syntax.isBooleanContext(_) || e(_, u) || r(_, u) : r(p, u)) ? o(h, u) : null;
36
- return v ? {
37
- reason: `next to a boolean-valued branch it acts like the test forced to ${f}, as ${v.mutator} does on some inputs`,
38
- by: v,
30
+ if (_ !== null || typeof o(l) != "boolean") return null;
31
+ let { parent: v } = d.syntax.getContextSlot(l);
32
+ if (!(a(m, d) || (v?.type === "ConditionalExpression" ? d.syntax.isBooleanContext(v) || n(v, d) || i(v, d) : i(m, d)))) return null;
33
+ let y = t(m), b = y || c(m, d) ? e(g, d, !1) : null;
34
+ return b && {
35
+ reason: `next to a boolean-valued branch it acts like the test forced to ${p}, as ${b.by.mutator} does on some inputs`,
36
+ ...(b.heuristic || !y) && { heuristic: !0 },
37
+ by: b.by,
39
38
  rule: "R5"
40
- } : null;
39
+ };
41
40
  }
42
- export { c as getBranchCopySkip };
41
+ export { l as getBranchCopySkip };
@@ -0,0 +1,32 @@
1
+ import { Node } from 'oxc-parser';
2
+ import { MutatorContext } from '../../../types/mutator/mutator-context.js';
3
+ /**
4
+ * Default that is the only falsy value of the value it guards.
5
+ */
6
+ export interface CanonicalFalsyDefault {
7
+ /**
8
+ * Why the value is never `NaN` when it is a number, worded as a clause such
9
+ * as "a length is never negative" (see `getValueBound`), or null for a
10
+ * string, BigInt or boolean.
11
+ */
12
+ because: string | null;
13
+ }
14
+ /**
15
+ * Tells whether a default is the only falsy value of the value it guards
16
+ * (catalog 3.3, `canonicalFalsy`), so that `value || fallback` and `value ||=
17
+ * fallback` keep the value, and `value && fallback` and `value &&= fallback`
18
+ * give the default: the type hints make the value a string, BigInt, boolean or
19
+ * number that is never nullish, and the default is `''`, `0n`, `false` or `0`.
20
+ * A number may also be `NaN` or `-0`, which `|| 0` turns into `0`, so it needs
21
+ * a lower bound that is never nullish (see `getValueBound`): such a value is a
22
+ * number of at least the bound, which `NaN` never is, and only a `-0` literal
23
+ * makes it `-0`. A bound that may be nullish is not enough even when an
24
+ * assertion makes the type hints say otherwise.
25
+ *
26
+ * @param value - Left operand or assignment target.
27
+ * @param fallback - Right operand or assigned value.
28
+ * @param context - Mutator context of the file.
29
+ * @returns Why a number is never `NaN` (null for the other types), or null when
30
+ * the default is not the only falsy value of the value.
31
+ */
32
+ export declare function getCanonicalFalsyDefault(value: Node, fallback: Node, context: MutatorContext): CanonicalFalsyDefault | null;
@@ -0,0 +1,11 @@
1
+ import { isCanonicalFalsy as e } from "./is-canonical-falsy.js";
2
+ import { mayBeNullish as t } from "./may-be-nullish.js";
3
+ import { getTypeView as n } from "./get-type-view.js";
4
+ function r(r, i, a) {
5
+ let o = a.hints.getType(r), s = n(o);
6
+ if (t(o) || !e(s.type, i)) return null;
7
+ if (s.type !== "number") return { because: null };
8
+ let c = a.syntax.getValueBound(r);
9
+ return c && !c.nullable ? { because: c.because } : null;
10
+ }
11
+ export { r as getCanonicalFalsyDefault };