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
|
@@ -1,48 +1,55 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
14
|
+
n.set(e, a);
|
|
13
15
|
break;
|
|
14
16
|
}
|
|
15
17
|
}
|
|
16
18
|
return {
|
|
17
|
-
kept:
|
|
18
|
-
dropped:
|
|
19
|
+
kept: t.filter((e) => !n.has(e)),
|
|
20
|
+
dropped: n
|
|
19
21
|
};
|
|
20
22
|
}
|
|
21
|
-
function
|
|
22
|
-
let { candidates:
|
|
23
|
-
for (let e =
|
|
24
|
-
let
|
|
25
|
-
if (
|
|
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
|
|
30
|
-
|
|
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
|
|
33
|
-
let
|
|
34
|
-
for (;
|
|
35
|
-
let
|
|
36
|
-
e[
|
|
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
|
|
42
|
+
return r;
|
|
39
43
|
}
|
|
40
|
-
function
|
|
41
|
-
return
|
|
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
|
|
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 {
|
|
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
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
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 {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
|
|
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
|
|
18
|
-
let { services:
|
|
19
|
-
function
|
|
20
|
-
if (
|
|
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
|
-
|
|
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
|
-
|
|
31
|
-
|
|
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
|
-
...
|
|
42
|
+
...g(t)
|
|
38
43
|
});
|
|
39
44
|
}
|
|
40
45
|
}
|
|
41
|
-
function
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
|
50
|
-
|
|
51
|
-
if (
|
|
52
|
-
|
|
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
|
|
56
|
-
if (
|
|
57
|
-
|
|
58
|
-
|
|
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:
|
|
64
|
-
if (
|
|
65
|
-
|
|
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:
|
|
123
|
+
reason: k.reason
|
|
68
124
|
});
|
|
69
125
|
return;
|
|
70
126
|
}
|
|
71
|
-
let
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
} :
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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:
|
|
88
|
-
solitary:
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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
|
|
99
|
-
for (let e of
|
|
100
|
-
let t =
|
|
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 } =
|
|
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
|
-
|
|
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)
|
|
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:
|
|
119
|
-
candidates:
|
|
120
|
-
skipped:
|
|
200
|
+
diagnostics: D,
|
|
201
|
+
candidates: O,
|
|
202
|
+
skipped: k
|
|
121
203
|
};
|
|
122
204
|
}
|
|
123
|
-
function
|
|
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(
|
|
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
|
|
149
|
-
let i =
|
|
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:
|
|
236
|
+
file: e.file,
|
|
155
237
|
severity: "error",
|
|
156
238
|
message: r
|
|
157
239
|
};
|
|
158
240
|
}
|
|
159
|
-
function
|
|
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 {
|
|
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;
|
|
@@ -14,10 +14,12 @@ interface DeduplicationOutcome {
|
|
|
14
14
|
kept: MutantCandidate[];
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
|
-
* Keeps the first candidate
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
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
|
-
|
|
2
|
-
|
|
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
|
-
|
|
5
|
-
|
|
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
|
|
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 {
|
|
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 };
|