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.
- package/dist/adapters/jest/build-dry-file.d.ts +12 -12
- package/dist/adapters/jest/collect-jest-dependencies.d.ts +8 -7
- package/dist/adapters/jest/runner.d.ts +1 -1
- package/dist/adapters/jest/runner.js +1 -1
- package/dist/adapters/jest/types/jest-record.d.ts +4 -4
- package/dist/adapters/jest/types/unit-worker.d.ts +16 -8
- package/dist/adapters/jest/types/worker-session.d.ts +6 -7
- package/dist/adapters/jest/worker/boot-worker.d.ts +4 -3
- package/dist/adapters/jest/worker/run-unit.d.ts +20 -18
- package/dist/adapters/jest/worker/vm-setup.js +1 -1
- package/dist/adapters/jest/worker/worker.js +1 -1
- package/dist/adapters/jest/write-worker-session.d.ts +1 -2
- package/dist/adapters/jest/write-worker-session.js +2 -2
- package/dist/adapters/node-test/collect-node-dependencies.d.ts +5 -5
- package/dist/adapters/node-test/preload/preload.js +4 -1
- package/dist/adapters/node-test/run-test-file.js +1 -0
- package/dist/adapters/node-test/types/node-test-record.d.ts +3 -3
- package/dist/adapters/node-test/types/node-test-unit.d.ts +6 -1
- package/dist/adapters/shared/create-input-filter.d.ts +26 -0
- package/dist/adapters/shared/create-input-filter.js +32 -0
- package/dist/adapters/shared/track-file-inputs.d.ts +7 -3
- package/dist/adapters/shared/track-file-inputs.js +16 -7
- package/dist/adapters/shared/track-file-reads.d.ts +12 -8
- package/dist/adapters/shared/track-file-reads.js +110 -57
- package/dist/adapters/shared/track-inputs.d.ts +13 -6
- package/dist/adapters/shared/track-inputs.js +7 -7
- package/dist/adapters/shared/types/file-input-tracking.d.ts +6 -0
- package/dist/adapters/shared/types/input-tracking.d.ts +3 -3
- package/dist/adapters/vitest/collect-dependencies.d.ts +4 -3
- package/dist/adapters/vitest/collect-dependencies.js +25 -24
- package/dist/adapters/vitest/get-cache-inputs.js +3 -1
- package/dist/adapters/vitest/is-virtual-module.d.ts +11 -0
- package/dist/adapters/vitest/is-virtual-module.js +8 -0
- package/dist/adapters/vitest/read-out-files.d.ts +7 -2
- package/dist/adapters/vitest/read-out-files.js +5 -5
- package/dist/adapters/vitest/read-out-records.d.ts +17 -0
- package/dist/adapters/vitest/read-out-records.js +27 -0
- package/dist/adapters/vitest/read-strays.d.ts +20 -0
- package/dist/adapters/vitest/read-strays.js +53 -0
- package/dist/adapters/vitest/read-unit-inputs.d.ts +7 -1
- package/dist/adapters/vitest/read-unit-inputs.js +1 -1
- package/dist/adapters/vitest/run-dry.js +16 -16
- package/dist/adapters/vitest/run-plan.d.ts +3 -1
- package/dist/adapters/vitest/run-plan.js +15 -15
- package/dist/adapters/vitest/run-specifications.d.ts +3 -2
- package/dist/adapters/vitest/runner.d.ts +38 -23
- package/dist/adapters/vitest/runner.js +84 -85
- package/dist/adapters/vitest/types/stray-decisions.d.ts +8 -0
- package/dist/adapters/vitest/types/unit-outcome.d.ts +2 -1
- package/dist/adapters/vitest/types/vitest-worker.d.ts +83 -12
- package/dist/adapters/vitest/worker/encode-stray.d.ts +16 -0
- package/dist/adapters/vitest/worker/encode-stray.js +16 -0
- package/dist/adapters/vitest/worker/intercept-strays.d.ts +26 -0
- package/dist/adapters/vitest/worker/intercept-strays.js +13 -0
- package/dist/adapters/vitest/worker/read-try-facts.d.ts +5 -4
- package/dist/adapters/vitest/worker/write-out-record.d.ts +2 -2
- package/dist/cli/html/build-html-report.js +1 -1
- package/dist/cli/html/client/main.js +1 -1
- package/dist/cli/html/client/render-change.d.ts +3 -2
- package/dist/cli/html/client/render-code.d.ts +1 -1
- package/dist/cli/html/pack-replacement.d.ts +1 -1
- package/dist/cli/parse-arguments.js +1 -1
- package/dist/cli/report/build-list-report.js +1 -1
- package/dist/cli/report/build-run-report.js +1 -1
- package/dist/cli/report/format-file-groups.d.ts +1 -1
- package/dist/cli/run-mutation.js +31 -31
- package/dist/cli/terminal/create-spinner.d.ts +1 -1
- package/dist/cli/terminal/get-text-style.js +4 -4
- package/dist/core/cache/get-environment-key.js +2 -2
- package/dist/core/cache/hash-files.d.ts +7 -3
- package/dist/core/cache/hash-files.js +16 -17
- package/dist/core/cache/prepare-run-cache.d.ts +29 -7
- package/dist/core/cache/prepare-run-cache.js +96 -62
- package/dist/core/cache/save-run-cache.d.ts +8 -7
- package/dist/core/cache/save-run-cache.js +2 -1
- package/dist/core/cache/unknown-hash.d.ts +7 -0
- package/dist/core/cache/unknown-hash.js +2 -0
- package/dist/core/files/select-changed-mutants.d.ts +11 -6
- package/dist/core/files/select-changed-mutants.js +38 -13
- package/dist/core/generate/apply-solitary-rule.d.ts +8 -5
- package/dist/core/generate/apply-solitary-rule.js +36 -29
- package/dist/core/generate/collect-candidates.d.ts +18 -4
- package/dist/core/generate/collect-candidates.js +168 -86
- package/dist/core/generate/compare-targets.d.ts +14 -0
- package/dist/core/generate/compare-targets.js +6 -0
- package/dist/core/generate/deduplicate-candidates.d.ts +6 -4
- package/dist/core/generate/deduplicate-candidates.js +11 -9
- package/dist/core/generate/find-list-removal.d.ts +20 -0
- package/dist/core/generate/find-list-removal.js +26 -0
- package/dist/core/generate/generate-file-mutants.js +47 -46
- package/dist/core/generate/get-mutant-site.d.ts +18 -0
- package/dist/core/generate/get-mutant-site.js +4 -0
- package/dist/core/generate/get-target.d.ts +14 -0
- package/dist/core/generate/get-target.js +4 -0
- package/dist/core/generate/pick-host.d.ts +10 -0
- package/dist/core/generate/pick-host.js +16 -0
- package/dist/core/generate/validate-replacement.d.ts +15 -4
- package/dist/core/generate/validate-replacement.js +28 -13
- package/dist/core/ignore/find-ignore-rule.d.ts +8 -7
- package/dist/core/instrument/find-attribute-values.d.ts +12 -0
- package/dist/core/instrument/find-attribute-values.js +13 -0
- package/dist/core/instrument/get-site-syntax.d.ts +14 -0
- package/dist/core/instrument/get-site-syntax.js +12 -0
- package/dist/core/instrument/group-mutant-ranges.d.ts +7 -3
- package/dist/core/instrument/group-mutant-ranges.js +25 -19
- package/dist/core/instrument/instrument-file.d.ts +5 -3
- package/dist/core/instrument/instrument-file.js +10 -9
- package/dist/core/instrument/instrumenter-version.d.ts +1 -1
- package/dist/core/instrument/render-branch.d.ts +17 -0
- package/dist/core/instrument/render-branch.js +81 -0
- package/dist/core/instrument/render-mutant-range.d.ts +17 -6
- package/dist/core/instrument/render-mutant-range.js +39 -13
- package/dist/core/list-mutants.d.ts +7 -5
- package/dist/core/list-mutants.js +2 -2
- package/dist/core/mutators/array-element.d.ts +7 -6
- package/dist/core/mutators/array-element.js +13 -13
- package/dist/core/mutators/assignment-operator.js +34 -33
- package/dist/core/mutators/boolean-literal.d.ts +3 -2
- package/dist/core/mutators/number-literal.d.ts +1 -1
- package/dist/core/mutators/object-property.d.ts +4 -3
- package/dist/core/mutators/object-property.js +7 -8
- package/dist/core/mutators/return-value.js +65 -33
- package/dist/core/mutators/shared/get-branch-copy-skip.d.ts +12 -7
- package/dist/core/mutators/shared/get-branch-copy-skip.js +34 -35
- package/dist/core/mutators/shared/get-canonical-falsy-default.d.ts +32 -0
- package/dist/core/mutators/shared/get-canonical-falsy-default.js +11 -0
- package/dist/core/mutators/shared/get-comparison-plan.js +86 -85
- package/dist/core/mutators/shared/get-condition-constants.d.ts +8 -8
- package/dist/core/mutators/shared/get-condition-constants.js +3 -3
- package/dist/core/mutators/shared/get-endless-value.d.ts +20 -0
- package/dist/core/mutators/shared/get-endless-value.js +25 -0
- package/dist/core/mutators/shared/get-forced-test-justifier.d.ts +44 -0
- package/dist/core/mutators/shared/get-forced-test-justifier.js +25 -0
- package/dist/core/mutators/shared/get-group-constant.d.ts +4 -4
- package/dist/core/mutators/shared/get-group-constant.js +2 -2
- package/dist/core/mutators/shared/get-literal-skip.d.ts +6 -6
- package/dist/core/mutators/shared/get-literal-skip.js +2 -2
- package/dist/core/mutators/shared/get-logical-drops.d.ts +8 -8
- package/dist/core/mutators/shared/get-logical-drops.js +80 -82
- package/dist/core/mutators/shared/get-owner-constant.d.ts +3 -1
- package/dist/core/mutators/shared/get-running-value.d.ts +5 -4
- package/dist/core/mutators/shared/get-toward-mutant.d.ts +10 -2
- package/dist/core/mutators/shared/get-toward-mutant.js +45 -40
- package/dist/core/mutators/shared/has-other-exit.js +16 -36
- package/dist/core/mutators/shared/is-loop-exit.d.ts +20 -0
- package/dist/core/mutators/shared/is-loop-exit.js +32 -0
- package/dist/core/mutators/shared/is-read-only.d.ts +26 -0
- package/dist/core/mutators/shared/is-read-only.js +53 -0
- package/dist/core/mutators/statement-removal.d.ts +4 -3
- package/dist/core/mutators/statement-removal.js +69 -73
- package/dist/core/mutators/string-literal.d.ts +15 -5
- package/dist/core/mutators/string-literal.js +79 -50
- package/dist/core/presets/recommended.d.ts +2 -2
- package/dist/core/presets/strict.d.ts +4 -2
- package/dist/core/run/apply-batch-result.d.ts +23 -22
- package/dist/core/run/apply-batch-result.js +5 -5
- package/dist/core/run/apply-isolated-result.d.ts +18 -17
- package/dist/core/run/apply-isolated-result.js +1 -0
- package/dist/core/run/classify-try.d.ts +9 -8
- package/dist/core/run/get-test-file-limits.d.ts +13 -0
- package/dist/core/run/get-test-file-limits.js +13 -0
- package/dist/core/run/get-unit-evidence.d.ts +6 -3
- package/dist/core/run/get-unit-evidence.js +1 -1
- package/dist/core/run/plan-batch.d.ts +6 -3
- package/dist/core/run/plan-batch.js +36 -31
- package/dist/core/run/plan-isolated.d.ts +3 -1
- package/dist/core/run/plan-isolated.js +8 -14
- package/dist/core/run/read-isolated-unit.d.ts +4 -4
- package/dist/core/run/run-batch-phases.d.ts +4 -3
- package/dist/core/run/run-dry-phase.d.ts +35 -19
- package/dist/core/run/run-dry-phase.js +127 -77
- package/dist/core/run/run-isolated-rounds.d.ts +6 -5
- package/dist/core/run/run-isolated-rounds.js +1 -0
- package/dist/core/run-mutants.d.ts +26 -21
- package/dist/core/run-mutants.js +72 -64
- package/dist/core/runtime/create-hit-limit-error.d.ts +5 -3
- package/dist/core/runtime/create-hit-limit-error.js +1 -1
- package/dist/core/runtime/install-mutant-runtime.js +23 -6
- package/dist/core/runtime/runtime-version.d.ts +4 -4
- package/dist/core/skips/skip-rules.d.ts +4 -0
- package/dist/core/skips/skip-rules.js +4 -0
- package/dist/core/syntax/is-brace-sensitive-attribute.d.ts +18 -0
- package/dist/core/syntax/is-brace-sensitive-attribute.js +28 -0
- package/dist/core/syntax/is-spread-safe-member.d.ts +18 -0
- package/dist/core/syntax/is-spread-safe-member.js +18 -0
- package/dist/core/syntax/is-value-position.d.ts +3 -1
- package/dist/core/text/get-list-removal-range.d.ts +22 -0
- package/dist/core/text/get-list-removal-range.js +46 -0
- package/dist/core/text/is-plain-attribute-string.d.ts +10 -0
- package/dist/core/text/is-plain-attribute-string.js +5 -0
- package/dist/core/text/parse-expression.d.ts +8 -4
- package/dist/core/text/parse-expression.js +1 -0
- package/dist/core/text/remove-list-element.d.ts +2 -4
- package/dist/core/text/remove-list-element.js +4 -45
- package/dist/docs/styles/colors.js +1 -1
- package/dist/package.js +1 -1
- package/dist/types/adapter/dry-file.d.ts +2 -1
- package/dist/types/adapter/dry-run-request.d.ts +5 -4
- package/dist/types/adapter/mutant-runtime.d.ts +30 -1
- package/dist/types/cli/text-style.d.ts +1 -1
- package/dist/types/config/preset-settings.d.ts +2 -2
- package/dist/types/config/run-config.d.ts +12 -4
- package/dist/types/html/indexed-mutant.d.ts +4 -2
- package/dist/types/html/shown-change.d.ts +4 -3
- package/dist/types/mutant/list-removal.d.ts +37 -0
- package/dist/types/mutant/mutant-candidate.d.ts +11 -17
- package/dist/types/mutant/mutant-host.d.ts +49 -0
- package/dist/types/mutant/mutant-kind.d.ts +18 -0
- package/dist/types/mutant/mutant-range.d.ts +15 -8
- package/dist/types/mutant/mutant.d.ts +9 -15
- package/dist/types/mutant/site-syntax.d.ts +14 -0
- package/dist/types/mutant/skip-justifier.d.ts +3 -1
- package/dist/types/mutant/skipped-candidate.d.ts +13 -10
- package/dist/types/mutant/skipped-mutant.d.ts +9 -6
- package/dist/types/mutator/replacement.d.ts +14 -3
- package/dist/types/report/html-report.d.ts +10 -7
- package/dist/types/report/list-report-focus.d.ts +3 -2
- package/dist/types/report/list-report-justifier.d.ts +4 -2
- package/dist/types/report/list-report-mutant.d.ts +15 -9
- package/dist/types/report/list-report-skipped.d.ts +3 -2
- package/dist/types/report/list-report.d.ts +1 -1
- package/dist/types/report/run-report.d.ts +2 -2
- package/dist/types/report/slim-list-report.d.ts +6 -3
- package/dist/types/report/slim-run-report.d.ts +1 -1
- package/dist/types/run/isolated-reason.d.ts +4 -3
- package/dist/types/run/mutant-state.d.ts +1 -1
- package/dist/types/run/run-event.d.ts +1 -1
- package/dist/types/run/run-kind.d.ts +3 -2
- package/dist/types/run/run-result.d.ts +6 -3
- package/dist/types/run/run-state.d.ts +9 -1
- package/dist/types/run/run-status.d.ts +2 -2
- package/dist/types/run/try-cause.d.ts +8 -6
- package/dist/types/syntax/syntax-helpers.d.ts +5 -3
- package/package.json +5 -5
- package/skills/mootant/SKILL.md +14 -12
- package/skills/mootant/references/mutators.md +3 -1
- package/dist/core/instrument/get-site-check.d.ts +0 -9
- package/dist/core/instrument/get-site-check.js +0 -5
- package/dist/core/instrument/get-template-site-check.d.ts +0 -12
- package/dist/core/instrument/get-template-site-check.js +0 -5
- /package/dist/cli/{built-in-adapters.d.ts → get-built-in-adapters.d.ts} +0 -0
- /package/dist/cli/{built-in-adapters.js → get-built-in-adapters.js} +0 -0
- /package/dist/cli/terminal/{colors.d.ts → create-colors.d.ts} +0 -0
- /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
|
-
]),
|
|
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" ? [] :
|
|
67
|
+
return t.body.type === "BlockStatement" ? [] : b(t.body, e);
|
|
64
68
|
},
|
|
65
69
|
ReturnStatement(t) {
|
|
66
|
-
return t.argument ?
|
|
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
|
|
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" ?
|
|
76
|
-
if (
|
|
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" && !
|
|
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, ...
|
|
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 =
|
|
106
|
+
return !n && l === "boolean" && (n = x(s, e.value === !0, a)), n && (t.skip = n), t;
|
|
103
107
|
});
|
|
104
108
|
}
|
|
105
|
-
function
|
|
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 =
|
|
116
|
+
let i = P(e, t, n);
|
|
113
117
|
if (i) return i;
|
|
114
|
-
let a = [e, ...
|
|
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
|
|
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
|
|
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
|
|
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
|
|
175
|
-
let n =
|
|
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
|
|
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
|
|
185
|
-
|
|
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" &&
|
|
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
|
|
224
|
+
function N(e) {
|
|
190
225
|
switch (e.type) {
|
|
191
|
-
case "SequenceExpression": return e.expressions.some(
|
|
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
|
|
229
|
+
default: return _.has(e.type);
|
|
195
230
|
}
|
|
196
231
|
}
|
|
197
|
-
function
|
|
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
|
|
204
|
-
return
|
|
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
|
|
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 {
|
|
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
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
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 {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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:
|
|
15
|
-
node:
|
|
15
|
+
mutator: r(l),
|
|
16
|
+
node: l
|
|
16
17
|
},
|
|
17
|
-
decision:
|
|
18
|
-
value:
|
|
19
|
-
},
|
|
20
|
-
if ("value" in
|
|
21
|
-
let
|
|
22
|
-
|
|
23
|
-
reason: `it copies the other branch, which is the test forced to ${
|
|
24
|
-
|
|
25
|
-
|
|
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 (
|
|
35
|
-
let { parent:
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
}
|
|
39
|
+
};
|
|
41
40
|
}
|
|
42
|
-
export {
|
|
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 };
|