@whaaaley/crush 0.0.0-stage → 0.2.7
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/LICENSE +32 -0
- package/README.md +185 -2
- package/SKILL.md +187 -0
- package/THIRD_PARTY_NOTICES.md +277 -0
- package/dist/capture/capture.operations.d.ts +23 -0
- package/dist/capture/capture.operations.js +231 -0
- package/dist/capture/capture.schema.d.ts +73 -0
- package/dist/capture/capture.schema.js +28 -0
- package/dist/collapse/collapse.operations.d.ts +2 -0
- package/dist/collapse/collapse.operations.js +82 -0
- package/dist/collapse/collapse.schema.d.ts +40 -0
- package/dist/collapse/collapse.schema.js +35 -0
- package/dist/crush.tables.d.ts +3583 -0
- package/dist/crush.tables.js +456 -0
- package/dist/crushes/callback.crush.d.ts +2 -0
- package/dist/crushes/callback.crush.js +19 -0
- package/dist/crushes/crush.d.ts +36 -0
- package/dist/crushes/crush.js +12 -0
- package/dist/crushes/crush.names.d.ts +1 -0
- package/dist/crushes/crush.names.js +2 -0
- package/dist/crushes/crushes.d.ts +2 -0
- package/dist/crushes/crushes.js +9 -0
- package/dist/crushes/default-value.crush.d.ts +2 -0
- package/dist/crushes/default-value.crush.js +29 -0
- package/dist/crushes/drop-operand.crush.d.ts +2 -0
- package/dist/crushes/drop-operand.crush.js +37 -0
- package/dist/crushes/fold.d.ts +64 -0
- package/dist/crushes/fold.js +366 -0
- package/dist/crushes/force-fork.crush.d.ts +2 -0
- package/dist/crushes/force-fork.crush.js +79 -0
- package/dist/crushes/loop-once.crush.d.ts +2 -0
- package/dist/crushes/loop-once.crush.js +71 -0
- package/dist/crushes/optional-chain.crush.d.ts +2 -0
- package/dist/crushes/optional-chain.crush.js +30 -0
- package/dist/crushes/switch-case.crush.d.ts +2 -0
- package/dist/crushes/switch-case.crush.js +19 -0
- package/dist/decisions/decide.d.ts +61 -0
- package/dist/decisions/decide.js +161 -0
- package/dist/decisions/decisions.d.ts +24 -0
- package/dist/decisions/decisions.js +62 -0
- package/dist/decisions/forks.decision.d.ts +4 -0
- package/dist/decisions/forks.decision.js +32 -0
- package/dist/decisions/kinds.d.ts +101 -0
- package/dist/decisions/kinds.js +38 -0
- package/dist/decisions/loops.decision.d.ts +4 -0
- package/dist/decisions/loops.decision.js +39 -0
- package/dist/decisions/shorts.decision.d.ts +3 -0
- package/dist/decisions/shorts.decision.js +66 -0
- package/dist/decisions/switches.decision.d.ts +3 -0
- package/dist/decisions/switches.decision.js +20 -0
- package/dist/decisions/throws.decision.d.ts +3 -0
- package/dist/decisions/throws.decision.js +35 -0
- package/dist/decisions/values.decision.d.ts +3 -0
- package/dist/decisions/values.decision.js +67 -0
- package/dist/explore/edges/explore.d.ts +60 -0
- package/dist/explore/edges/explore.db.d.ts +22 -0
- package/dist/explore/edges/explore.db.js +55 -0
- package/dist/explore/edges/explore.js +305 -0
- package/dist/explore/edges/random.d.ts +2 -0
- package/dist/explore/edges/random.js +32 -0
- package/dist/explore/explore.operations.d.ts +30 -0
- package/dist/explore/explore.operations.js +117 -0
- package/dist/explore/limits.operations.d.ts +14 -0
- package/dist/explore/limits.operations.js +20 -0
- package/dist/explore/targets.operations.d.ts +36 -0
- package/dist/explore/targets.operations.js +32 -0
- package/dist/explore/utils/draws.d.ts +6 -0
- package/dist/explore/utils/draws.js +2 -0
- package/dist/explore/utils/edits.d.ts +15 -0
- package/dist/explore/utils/edits.js +151 -0
- package/dist/explore/utils/guide.d.ts +23 -0
- package/dist/explore/utils/guide.js +35 -0
- package/dist/explore/utils/keep.d.ts +10 -0
- package/dist/explore/utils/keep.js +61 -0
- package/dist/explore/utils/pools.d.ts +17 -0
- package/dist/explore/utils/pools.js +121 -0
- package/dist/explore/utils/reads.d.ts +19 -0
- package/dist/explore/utils/reads.js +118 -0
- package/dist/explore/utils/twin.d.ts +21 -0
- package/dist/explore/utils/twin.js +55 -0
- package/dist/forks/forks.operations.d.ts +32 -0
- package/dist/forks/forks.operations.js +134 -0
- package/dist/forks/forks.schema.d.ts +20 -0
- package/dist/forks/forks.schema.js +14 -0
- package/dist/graph/cfg/cfg.d.ts +28 -0
- package/dist/graph/cfg/cfg.js +31 -0
- package/dist/graph/cfg/code-paths/analyzer.d.ts +27 -0
- package/dist/graph/cfg/code-paths/analyzer.js +358 -0
- package/dist/graph/cfg/code-paths/segments.d.ts +44 -0
- package/dist/graph/cfg/code-paths/segments.js +105 -0
- package/dist/graph/cfg/code-paths/state.d.ts +121 -0
- package/dist/graph/cfg/code-paths/state.js +611 -0
- package/dist/graph/cfg/entries.d.ts +13 -0
- package/dist/graph/cfg/entries.js +120 -0
- package/dist/graph/cfg/functions.d.ts +6 -0
- package/dist/graph/cfg/functions.js +47 -0
- package/dist/graph/cfg/paths.d.ts +27 -0
- package/dist/graph/cfg/paths.js +91 -0
- package/dist/graph/cfg/scopes/scopes.d.ts +40 -0
- package/dist/graph/cfg/scopes/scopes.js +375 -0
- package/dist/graph/symbols/file.d.ts +90 -0
- package/dist/graph/symbols/file.js +427 -0
- package/dist/graph/symbols/keys.d.ts +13 -0
- package/dist/graph/symbols/keys.js +22 -0
- package/dist/graph/symbols/resolve.operations.d.ts +4 -0
- package/dist/graph/symbols/resolve.operations.js +33 -0
- package/dist/graph/symbols/symbols.d.ts +12 -0
- package/dist/graph/symbols/symbols.js +155 -0
- package/dist/graph/symbols/symbols.schema.d.ts +32 -0
- package/dist/graph/symbols/symbols.schema.js +19 -0
- package/dist/graph/unused/tests.d.ts +7 -0
- package/dist/graph/unused/tests.js +95 -0
- package/dist/graph/unused/unused.d.ts +53 -0
- package/dist/graph/unused/unused.js +319 -0
- package/dist/graph/walk/walk.d.ts +7 -0
- package/dist/graph/walk/walk.js +39 -0
- package/dist/instrument/instrument.operations.d.ts +72 -0
- package/dist/instrument/instrument.operations.js +786 -0
- package/dist/instrument/instrument.schema.d.ts +257 -0
- package/dist/instrument/instrument.schema.js +100 -0
- package/dist/judge/counters.d.ts +86 -0
- package/dist/judge/counters.js +402 -0
- package/dist/judge/edges/api.d.ts +14 -0
- package/dist/judge/edges/api.js +80 -0
- package/dist/judge/edges/completion.reporter.d.ts +9 -0
- package/dist/judge/edges/completion.reporter.js +51 -0
- package/dist/judge/edges/hints.reporter.d.ts +13 -0
- package/dist/judge/edges/hints.reporter.js +29 -0
- package/dist/judge/edges/judge.edges.d.ts +52 -0
- package/dist/judge/edges/judge.edges.js +59 -0
- package/dist/judge/edges/judge.fs.d.ts +8 -0
- package/dist/judge/edges/judge.fs.js +45 -0
- package/dist/judge/edges/merge.d.ts +11 -0
- package/dist/judge/edges/merge.js +60 -0
- package/dist/judge/edges/plugin.d.ts +132 -0
- package/dist/judge/edges/plugin.js +441 -0
- package/dist/judge/edges/reach.d.ts +68 -0
- package/dist/judge/edges/reach.js +132 -0
- package/dist/judge/edges/speed.d.ts +32 -0
- package/dist/judge/edges/speed.js +34 -0
- package/dist/judge/edges/strays.d.ts +1 -0
- package/dist/judge/edges/strays.js +14 -0
- package/dist/judge/edges/vitest.d.ts +20 -0
- package/dist/judge/edges/vitest.js +36 -0
- package/dist/judge/edges/vitest.schema.d.ts +14 -0
- package/dist/judge/edges/vitest.schema.js +16 -0
- package/dist/judge/explore.test.d.ts +1 -0
- package/dist/judge/explore.test.js +101 -0
- package/dist/judge/hints.d.ts +11 -0
- package/dist/judge/hints.js +44 -0
- package/dist/judge/judge.operations.d.ts +218 -0
- package/dist/judge/judge.operations.js +464 -0
- package/dist/judge/judge.schema.d.ts +135 -0
- package/dist/judge/judge.schema.js +129 -0
- package/dist/judge/judge.shard-1.test.d.ts +1 -0
- package/dist/judge/judge.shard-1.test.js +3 -0
- package/dist/judge/judge.shard-2.test.d.ts +1 -0
- package/dist/judge/judge.shard-2.test.js +3 -0
- package/dist/judge/judge.test.d.ts +1 -0
- package/dist/judge/judge.test.js +3 -0
- package/dist/judge/refusals.d.ts +14 -0
- package/dist/judge/refusals.js +10 -0
- package/dist/judge/report.test.d.ts +1 -0
- package/dist/judge/report.test.js +432 -0
- package/dist/judge/runner.d.ts +3 -0
- package/dist/judge/runner.js +1602 -0
- package/dist/judge/stresses.test.d.ts +1 -0
- package/dist/judge/stresses.test.js +12 -0
- package/dist/judge/task-meta.d.ts +14 -0
- package/dist/judge/task-meta.js +1 -0
- package/dist/justify/edges/load.d.ts +7 -0
- package/dist/justify/edges/load.js +40 -0
- package/dist/justify/edges/refresh.fs.d.ts +8 -0
- package/dist/justify/edges/refresh.fs.js +15 -0
- package/dist/justify/justify.operations.d.ts +46 -0
- package/dist/justify/justify.operations.js +80 -0
- package/dist/justify/justify.schema.d.ts +21 -0
- package/dist/justify/justify.schema.js +11 -0
- package/dist/mutators/arithmetic-operator.mutator.d.ts +2 -0
- package/dist/mutators/arithmetic-operator.mutator.js +22 -0
- package/dist/mutators/array-declaration.mutator.d.ts +2 -0
- package/dist/mutators/array-declaration.mutator.js +12 -0
- package/dist/mutators/arrow-function.mutator.d.ts +2 -0
- package/dist/mutators/arrow-function.mutator.js +10 -0
- package/dist/mutators/assignment-operator.mutator.d.ts +2 -0
- package/dist/mutators/assignment-operator.mutator.js +29 -0
- package/dist/mutators/await-expression.mutator.d.ts +2 -0
- package/dist/mutators/await-expression.mutator.js +7 -0
- package/dist/mutators/bitwise-operator.mutator.d.ts +2 -0
- package/dist/mutators/bitwise-operator.mutator.js +19 -0
- package/dist/mutators/block-statement.mutator.d.ts +2 -0
- package/dist/mutators/block-statement.mutator.js +30 -0
- package/dist/mutators/boolean-literal.mutator.d.ts +2 -0
- package/dist/mutators/boolean-literal.mutator.js +5 -0
- package/dist/mutators/coercion.mutator.d.ts +2 -0
- package/dist/mutators/coercion.mutator.js +28 -0
- package/dist/mutators/conditional-expression.mutator.d.ts +2 -0
- package/dist/mutators/conditional-expression.mutator.js +36 -0
- package/dist/mutators/disposal.mutator.d.ts +2 -0
- package/dist/mutators/disposal.mutator.js +13 -0
- package/dist/mutators/empty-destructuring.mutator.d.ts +2 -0
- package/dist/mutators/empty-destructuring.mutator.js +35 -0
- package/dist/mutators/empty-return.mutator.d.ts +2 -0
- package/dist/mutators/empty-return.mutator.js +35 -0
- package/dist/mutators/equality-operator.mutator.d.ts +2 -0
- package/dist/mutators/equality-operator.mutator.js +16 -0
- package/dist/mutators/loop-exit.mutator.d.ts +2 -0
- package/dist/mutators/loop-exit.mutator.js +5 -0
- package/dist/mutators/method-expression.mutator.d.ts +2 -0
- package/dist/mutators/method-expression.mutator.js +59 -0
- package/dist/mutators/missing-lookup.mutator.d.ts +2 -0
- package/dist/mutators/missing-lookup.mutator.js +25 -0
- package/dist/mutators/mutator.d.ts +40 -0
- package/dist/mutators/mutator.js +49 -0
- package/dist/mutators/mutator.names.d.ts +3 -0
- package/dist/mutators/mutator.names.js +43 -0
- package/dist/mutators/mutators.d.ts +8 -0
- package/dist/mutators/mutators.js +84 -0
- package/dist/mutators/nested-condition.mutator.d.ts +2 -0
- package/dist/mutators/nested-condition.mutator.js +16 -0
- package/dist/mutators/number-literal.mutator.d.ts +3 -0
- package/dist/mutators/number-literal.mutator.js +13 -0
- package/dist/mutators/object-literal.mutator.d.ts +2 -0
- package/dist/mutators/object-literal.mutator.js +6 -0
- package/dist/mutators/odd-number.mutator.d.ts +2 -0
- package/dist/mutators/odd-number.mutator.js +15 -0
- package/dist/mutators/operand-deletion.mutator.d.ts +2 -0
- package/dist/mutators/operand-deletion.mutator.js +9 -0
- package/dist/mutators/outcome.mutator.d.ts +3 -0
- package/dist/mutators/outcome.mutator.js +45 -0
- package/dist/mutators/plain-assignment.mutator.d.ts +2 -0
- package/dist/mutators/plain-assignment.mutator.js +7 -0
- package/dist/mutators/power-operator.mutator.d.ts +2 -0
- package/dist/mutators/power-operator.mutator.js +13 -0
- package/dist/mutators/private-brand.mutator.d.ts +2 -0
- package/dist/mutators/private-brand.mutator.js +7 -0
- package/dist/mutators/regex.mutator.d.ts +2 -0
- package/dist/mutators/regex.mutator.js +29 -0
- package/dist/mutators/short-iteration.mutator.d.ts +2 -0
- package/dist/mutators/short-iteration.mutator.js +8 -0
- package/dist/mutators/string-literal.mutator.d.ts +3 -0
- package/dist/mutators/string-literal.mutator.js +149 -0
- package/dist/mutators/switch-default.mutator.d.ts +2 -0
- package/dist/mutators/switch-default.mutator.js +13 -0
- package/dist/mutators/sync-iteration.mutator.d.ts +3 -0
- package/dist/mutators/sync-iteration.mutator.js +9 -0
- package/dist/mutators/thrown-call.mutator.d.ts +2 -0
- package/dist/mutators/thrown-call.mutator.js +7 -0
- package/dist/mutators/unary-operator.mutator.d.ts +2 -0
- package/dist/mutators/unary-operator.mutator.js +18 -0
- package/dist/mutators/unbound-call.mutator.d.ts +2 -0
- package/dist/mutators/unbound-call.mutator.js +14 -0
- package/dist/mutators/update-operator.mutator.d.ts +2 -0
- package/dist/mutators/update-operator.mutator.js +15 -0
- package/dist/mutators/yield-value.mutator.d.ts +2 -0
- package/dist/mutators/yield-value.mutator.js +7 -0
- package/dist/parity/compare.d.ts +27 -0
- package/dist/parity/compare.js +26 -0
- package/dist/parity/corpus.parity.d.ts +1 -0
- package/dist/parity/corpus.parity.js +97 -0
- package/dist/parity/edges/corpus.fs.d.ts +3 -0
- package/dist/parity/edges/corpus.fs.js +30 -0
- package/dist/parity/edges/ports.d.ts +2 -0
- package/dist/parity/edges/ports.js +21 -0
- package/dist/parity/edges/vitest.d.ts +2 -0
- package/dist/parity/edges/vitest.js +3 -0
- package/dist/parity/parity.operations.d.ts +33 -0
- package/dist/parity/parity.operations.js +60 -0
- package/dist/parity/parity.schema.d.ts +5 -0
- package/dist/parity/parity.schema.js +6 -0
- package/dist/parity/stryker/compare.d.ts +14 -0
- package/dist/parity/stryker/compare.js +52 -0
- package/dist/parity/stryker/edges/ports.d.ts +12 -0
- package/dist/parity/stryker/edges/ports.js +28 -0
- package/dist/parity/stryker/equivalence.d.ts +1 -0
- package/dist/parity/stryker/equivalence.js +42 -0
- package/dist/parity/stryker/intended.d.ts +29 -0
- package/dist/parity/stryker/intended.js +152 -0
- package/dist/parity/stryker/normalize.d.ts +27 -0
- package/dist/parity/stryker/normalize.js +181 -0
- package/dist/parity/stryker/rules.d.ts +6 -0
- package/dist/parity/stryker/rules.js +116 -0
- package/dist/parity/stryker/sides.d.ts +46 -0
- package/dist/parity/stryker/sides.js +199 -0
- package/dist/parity/stryker/stryker.parity.d.ts +1 -0
- package/dist/parity/stryker/stryker.parity.js +147 -0
- package/dist/parity/stryker/stryker.schema.d.ts +6 -0
- package/dist/parity/stryker/stryker.schema.js +7 -0
- package/dist/parity/views.d.ts +21 -0
- package/dist/parity/views.js +119 -0
- package/dist/questions/questions.operations.d.ts +110 -0
- package/dist/questions/questions.operations.js +446 -0
- package/dist/questions/questions.schema.d.ts +57 -0
- package/dist/questions/questions.schema.js +28 -0
- package/dist/record/edges/calls.db.d.ts +10 -0
- package/dist/record/edges/calls.db.js +91 -0
- package/dist/record/edges/hits.db.d.ts +3 -0
- package/dist/record/edges/hits.db.js +5 -0
- package/dist/record/edges/holds.db.d.ts +4 -0
- package/dist/record/edges/holds.db.js +31 -0
- package/dist/record/edges/judged-state.db.d.ts +5 -0
- package/dist/record/edges/judged-state.db.js +25 -0
- package/dist/record/edges/markers.db.d.ts +11 -0
- package/dist/record/edges/markers.db.js +55 -0
- package/dist/record/edges/merge.db.d.ts +7 -0
- package/dist/record/edges/merge.db.js +46 -0
- package/dist/record/edges/parts.db.d.ts +42 -0
- package/dist/record/edges/parts.db.js +389 -0
- package/dist/record/edges/parts.edges.d.ts +2 -0
- package/dist/record/edges/parts.edges.js +7 -0
- package/dist/record/edges/parts.fs.d.ts +1 -0
- package/dist/record/edges/parts.fs.js +11 -0
- package/dist/record/edges/parts.writer.d.ts +1 -0
- package/dist/record/edges/parts.writer.js +85 -0
- package/dist/record/edges/passes.db.d.ts +19 -0
- package/dist/record/edges/passes.db.js +31 -0
- package/dist/record/edges/plan.db.d.ts +21 -0
- package/dist/record/edges/plan.db.js +174 -0
- package/dist/record/edges/reach.db.d.ts +6 -0
- package/dist/record/edges/reach.db.js +62 -0
- package/dist/record/edges/record.db.d.ts +22 -0
- package/dist/record/edges/record.db.js +176 -0
- package/dist/record/edges/record.fs.d.ts +3 -0
- package/dist/record/edges/record.fs.js +7 -0
- package/dist/record/edges/site-verdicts.db.d.ts +11 -0
- package/dist/record/edges/site-verdicts.db.js +66 -0
- package/dist/record/edges/verified.db.d.ts +7 -0
- package/dist/record/edges/verified.db.js +71 -0
- package/dist/record/parts.operations.d.ts +26 -0
- package/dist/record/parts.operations.js +31 -0
- package/dist/record/path-checks.operations.d.ts +15 -0
- package/dist/record/path-checks.operations.js +84 -0
- package/dist/record/record.operations.d.ts +36 -0
- package/dist/record/record.operations.js +11 -0
- package/dist/stresses/edges/stresses.record.d.ts +4 -0
- package/dist/stresses/edges/stresses.record.js +37 -0
- package/dist/stresses/stresses.operations.d.ts +28 -0
- package/dist/stresses/stresses.operations.js +22 -0
- package/dist/utils/ast.d.ts +55 -0
- package/dist/utils/ast.js +181 -0
- package/dist/utils/errors.d.ts +8 -0
- package/dist/utils/errors.js +12 -0
- package/dist/utils/faults.d.ts +6 -0
- package/dist/utils/faults.js +10 -0
- package/dist/utils/lookup.d.ts +4 -0
- package/dist/utils/lookup.js +27 -0
- package/dist/utils/order.d.ts +2 -0
- package/dist/utils/order.js +17 -0
- package/dist/utils/retry.d.ts +14 -0
- package/dist/utils/retry.js +15 -0
- package/dist/utils/safe.d.ts +11 -0
- package/dist/utils/safe.js +31 -0
- package/migrations/main/20261129123324_initial/migration.sql +418 -0
- package/migrations/main/20261129123324_initial/snapshot.json +3641 -0
- package/package.json +89 -4
- package/references/consumer-setup.md +92 -0
- package/src/graph/cfg/code-paths/LICENSE +21 -0
- package/src/graph/cfg/scopes/LICENSE +24 -0
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
import { noFaults } from '../../../utils/faults.js';
|
|
2
|
+
import { headOf, idsFrom, isReachable, markUsed, nextId } from './segments.js';
|
|
3
|
+
import * as path from './state.js';
|
|
4
|
+
const breakablePattern = /^(?:(?:Do)?While|For(?:In|Of)?|Switch)Statement$/u;
|
|
5
|
+
// A logical assignment forks as the operator it assigns through, as `a ||= b` forks as `a || b`.
|
|
6
|
+
const assignmentChoices = new Map([
|
|
7
|
+
['&&=', '&&'],
|
|
8
|
+
['||=', '||'],
|
|
9
|
+
['??=', '??'],
|
|
10
|
+
]);
|
|
11
|
+
const isOptional = (node) => 'optional' in node && node.optional === true;
|
|
12
|
+
const labelOf = (parent) => (parent.type === 'LabeledStatement' ? parent.label.name : null);
|
|
13
|
+
const testedTypes = new Set(['ConditionalExpression', 'IfStatement', 'WhileStatement', 'DoWhileStatement', 'ForStatement']);
|
|
14
|
+
// A test whose value decides which way its parent goes, so its own `&&` or `||` hands its sides up rather than joining them.
|
|
15
|
+
const isForkingByTrueOrFalse = (node, parent) => {
|
|
16
|
+
if (parent.type === 'LogicalExpression')
|
|
17
|
+
return true;
|
|
18
|
+
if (parent.type === 'AssignmentExpression')
|
|
19
|
+
return assignmentChoices.has(parent.operator);
|
|
20
|
+
return testedTypes.has(parent.type) && 'test' in parent && parent.test === node;
|
|
21
|
+
};
|
|
22
|
+
// A literal test is a constant ESLint reads as always true or false, as `while (true)`.
|
|
23
|
+
const constantOf = (node) => (node.type === 'Literal' ? Boolean(node.value) : undefined);
|
|
24
|
+
// An identifier that reads a variable, which can throw inside a try, unlike a label, a declared name or a plain key.
|
|
25
|
+
const isIdentifierReference = (node, parent) => {
|
|
26
|
+
switch (parent.type) {
|
|
27
|
+
case 'LabeledStatement':
|
|
28
|
+
case 'BreakStatement':
|
|
29
|
+
case 'ContinueStatement':
|
|
30
|
+
case 'ArrayPattern':
|
|
31
|
+
case 'RestElement':
|
|
32
|
+
case 'CatchClause':
|
|
33
|
+
return false;
|
|
34
|
+
case 'ClassDeclaration':
|
|
35
|
+
case 'ClassExpression':
|
|
36
|
+
case 'VariableDeclarator':
|
|
37
|
+
return !('id' in parent) || parent.id !== node;
|
|
38
|
+
case 'Property':
|
|
39
|
+
case 'PropertyDefinition':
|
|
40
|
+
case 'MethodDefinition':
|
|
41
|
+
return parent.key !== node || ('computed' in parent && parent.computed) || ('shorthand' in parent && parent.shorthand);
|
|
42
|
+
default:
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
// ESLint's code-path analyzer, driven by a walk that enters and leaves every node by oxc's child keys, the root as its own parent.
|
|
47
|
+
export const codePathWalker = (program) => {
|
|
48
|
+
const graphs = [];
|
|
49
|
+
const exits = new Map();
|
|
50
|
+
const faults = noFaults();
|
|
51
|
+
const pathIds = idsFrom('s');
|
|
52
|
+
// Lists a node in every segment open now, the segments it runs in.
|
|
53
|
+
const list = (opened, node) => {
|
|
54
|
+
for (const { listed } of opened.active)
|
|
55
|
+
listed.push(node);
|
|
56
|
+
};
|
|
57
|
+
const startSegment = (opened, segment) => {
|
|
58
|
+
markUsed(segment);
|
|
59
|
+
const listed = [];
|
|
60
|
+
opened.active.push({ segment, listed });
|
|
61
|
+
opened.nodes.set(segment, listed);
|
|
62
|
+
};
|
|
63
|
+
// A finally block's thrown copy ends at its try statement while the normal copy stays open for the code after it, so an end closes only its own segment.
|
|
64
|
+
const endSegment = (opened, segment) => {
|
|
65
|
+
opened.active = opened.active.filter((active) => active.segment !== segment);
|
|
66
|
+
};
|
|
67
|
+
const forwardCurrentToHead = (opened) => {
|
|
68
|
+
const { state } = opened;
|
|
69
|
+
const current = state.current;
|
|
70
|
+
const head = headOf(state.fork);
|
|
71
|
+
if (head === current)
|
|
72
|
+
return;
|
|
73
|
+
for (const [index, segment] of current.entries()) {
|
|
74
|
+
if (segment !== head[index])
|
|
75
|
+
endSegment(opened, segment);
|
|
76
|
+
}
|
|
77
|
+
state.current = head;
|
|
78
|
+
for (const [index, segment] of head.entries()) {
|
|
79
|
+
if (segment !== current[index])
|
|
80
|
+
startSegment(opened, segment);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
// A loop is drawn only between reachable segments, as ESLint reports it.
|
|
84
|
+
const onLooped = (from, to) => {
|
|
85
|
+
if (from.reachable && to.reachable)
|
|
86
|
+
from.loops.push(to.id);
|
|
87
|
+
};
|
|
88
|
+
const openOf = (root, upper) => {
|
|
89
|
+
const id = nextId(pathIds);
|
|
90
|
+
return { upper, id, root, state: path.stateOf(idsFrom(`${id}_`), faults, onLooped), active: [], nodes: new Map() };
|
|
91
|
+
};
|
|
92
|
+
// The module's own path is open from the start, so every node is inside one.
|
|
93
|
+
let opened = openOf(program, null);
|
|
94
|
+
// A function's own path starts before its node is listed, so the node is also listed where it sits in the enclosing path.
|
|
95
|
+
const startCodePath = (root) => {
|
|
96
|
+
forwardCurrentToHead(opened);
|
|
97
|
+
list(opened, root);
|
|
98
|
+
opened = openOf(root, opened);
|
|
99
|
+
};
|
|
100
|
+
const endCodePath = () => {
|
|
101
|
+
const ended = opened;
|
|
102
|
+
const { state, nodes } = ended;
|
|
103
|
+
path.makeFinal(state);
|
|
104
|
+
opened = ended.upper ?? ended;
|
|
105
|
+
// An empty unreachable segment is never started, so every segment reached from the first is gathered here too.
|
|
106
|
+
const seen = new Set();
|
|
107
|
+
const pending = [state.initial];
|
|
108
|
+
for (let raw = pending.pop(); raw; raw = pending.pop()) {
|
|
109
|
+
if (seen.has(raw))
|
|
110
|
+
continue;
|
|
111
|
+
seen.add(raw);
|
|
112
|
+
if (!nodes.has(raw))
|
|
113
|
+
nodes.set(raw, []);
|
|
114
|
+
pending.push(...raw.allNext);
|
|
115
|
+
}
|
|
116
|
+
const idsOf = (segments) => segments.map((segment) => segment.id);
|
|
117
|
+
graphs.push({
|
|
118
|
+
id: ended.id,
|
|
119
|
+
root: ended.root,
|
|
120
|
+
segments: [...nodes].map(([segment, listed]) => ({ id: segment.id, nodes: listed, reachable: segment.reachable, next: idsOf(segment.allNext), loops: segment.loops })),
|
|
121
|
+
initial: state.initial.id,
|
|
122
|
+
final: idsOf(state.final),
|
|
123
|
+
returned: idsOf(state.returned),
|
|
124
|
+
thrown: idsOf(state.thrown),
|
|
125
|
+
});
|
|
126
|
+
};
|
|
127
|
+
const preprocess = (state, node, parent) => {
|
|
128
|
+
switch (parent.type) {
|
|
129
|
+
case 'CallExpression':
|
|
130
|
+
if (isOptional(parent) && parent.arguments[0] === node)
|
|
131
|
+
path.makeLogicalRight(state);
|
|
132
|
+
return;
|
|
133
|
+
case 'MemberExpression':
|
|
134
|
+
if (isOptional(parent) && parent.property === node)
|
|
135
|
+
path.makeLogicalRight(state);
|
|
136
|
+
return;
|
|
137
|
+
case 'LogicalExpression':
|
|
138
|
+
if (parent.right === node)
|
|
139
|
+
path.makeLogicalRight(state);
|
|
140
|
+
return;
|
|
141
|
+
case 'AssignmentExpression':
|
|
142
|
+
if (parent.right === node && assignmentChoices.has(parent.operator))
|
|
143
|
+
path.makeLogicalRight(state);
|
|
144
|
+
return;
|
|
145
|
+
case 'ConditionalExpression':
|
|
146
|
+
case 'IfStatement':
|
|
147
|
+
if (parent.consequent === node)
|
|
148
|
+
path.makeIfConsequent(state);
|
|
149
|
+
else if (parent.alternate === node)
|
|
150
|
+
path.makeIfAlternate(state);
|
|
151
|
+
return;
|
|
152
|
+
case 'SwitchStatement':
|
|
153
|
+
if (parent.discriminant !== node && parent.cases[0] !== node)
|
|
154
|
+
path.forkPath(state);
|
|
155
|
+
return;
|
|
156
|
+
case 'SwitchCase':
|
|
157
|
+
if (parent.consequent[0] === node)
|
|
158
|
+
path.makeSwitchCaseBody(state, { isEmpty: false, isDefault: !parent.test });
|
|
159
|
+
return;
|
|
160
|
+
case 'TryStatement':
|
|
161
|
+
if (parent.handler === node)
|
|
162
|
+
path.makeCatchBlock(state);
|
|
163
|
+
else if (parent.finalizer === node)
|
|
164
|
+
path.makeFinallyBlock(state);
|
|
165
|
+
return;
|
|
166
|
+
case 'WhileStatement':
|
|
167
|
+
if (parent.test === node)
|
|
168
|
+
path.makeWhileTest(state, constantOf(node));
|
|
169
|
+
else
|
|
170
|
+
path.makeWhileBody(state);
|
|
171
|
+
return;
|
|
172
|
+
case 'DoWhileStatement':
|
|
173
|
+
if (parent.body === node)
|
|
174
|
+
path.makeDoWhileBody(state);
|
|
175
|
+
else
|
|
176
|
+
path.makeDoWhileTest(state, constantOf(node));
|
|
177
|
+
return;
|
|
178
|
+
case 'ForStatement':
|
|
179
|
+
if (parent.test === node)
|
|
180
|
+
path.makeForTest(state, constantOf(node));
|
|
181
|
+
else if (parent.update === node)
|
|
182
|
+
path.makeForUpdate(state);
|
|
183
|
+
else if (parent.body === node)
|
|
184
|
+
path.makeForBody(state);
|
|
185
|
+
return;
|
|
186
|
+
case 'ForInStatement':
|
|
187
|
+
case 'ForOfStatement':
|
|
188
|
+
if (parent.left === node)
|
|
189
|
+
path.makeForInOfLeft(state);
|
|
190
|
+
else if (parent.right === node)
|
|
191
|
+
path.makeForInOfRight(state);
|
|
192
|
+
else
|
|
193
|
+
path.makeForInOfBody(state);
|
|
194
|
+
return;
|
|
195
|
+
case 'AssignmentPattern':
|
|
196
|
+
if (parent.right === node) {
|
|
197
|
+
path.pushFork(state);
|
|
198
|
+
path.forkBypassPath(state);
|
|
199
|
+
path.forkPath(state);
|
|
200
|
+
}
|
|
201
|
+
return;
|
|
202
|
+
case 'PropertyDefinition':
|
|
203
|
+
if (parent.value === node)
|
|
204
|
+
startCodePath(node);
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
// The root is its own parent, so only it skips the step its parent takes before it.
|
|
208
|
+
const enterNode = (node, parent) => {
|
|
209
|
+
if (node !== parent)
|
|
210
|
+
preprocess(opened.state, node, parent);
|
|
211
|
+
switch (node.type) {
|
|
212
|
+
case 'FunctionDeclaration':
|
|
213
|
+
case 'FunctionExpression':
|
|
214
|
+
case 'ArrowFunctionExpression':
|
|
215
|
+
case 'StaticBlock':
|
|
216
|
+
startCodePath(node);
|
|
217
|
+
break;
|
|
218
|
+
case 'ChainExpression':
|
|
219
|
+
path.pushChain(opened.state);
|
|
220
|
+
break;
|
|
221
|
+
case 'CallExpression':
|
|
222
|
+
case 'MemberExpression':
|
|
223
|
+
if (isOptional(node))
|
|
224
|
+
path.makeOptionalNode(opened.state);
|
|
225
|
+
break;
|
|
226
|
+
case 'LogicalExpression':
|
|
227
|
+
path.pushChoice(opened.state, { kind: node.operator, isForkingAsResult: isForkingByTrueOrFalse(node, parent) });
|
|
228
|
+
break;
|
|
229
|
+
case 'AssignmentExpression': {
|
|
230
|
+
const kind = assignmentChoices.get(node.operator);
|
|
231
|
+
if (kind)
|
|
232
|
+
path.pushChoice(opened.state, { kind, isForkingAsResult: isForkingByTrueOrFalse(node, parent) });
|
|
233
|
+
break;
|
|
234
|
+
}
|
|
235
|
+
case 'ConditionalExpression':
|
|
236
|
+
case 'IfStatement':
|
|
237
|
+
path.pushChoice(opened.state, { kind: 'test', isForkingAsResult: false });
|
|
238
|
+
break;
|
|
239
|
+
case 'SwitchStatement':
|
|
240
|
+
path.pushSwitch(opened.state, node.cases.some((each) => each.test !== null), labelOf(parent));
|
|
241
|
+
break;
|
|
242
|
+
case 'TryStatement':
|
|
243
|
+
path.pushTry(opened.state, node.finalizer !== null);
|
|
244
|
+
break;
|
|
245
|
+
case 'WhileStatement':
|
|
246
|
+
case 'DoWhileStatement':
|
|
247
|
+
case 'ForStatement':
|
|
248
|
+
case 'ForInStatement':
|
|
249
|
+
case 'ForOfStatement':
|
|
250
|
+
path.pushLoop(opened.state, node.type, labelOf(parent));
|
|
251
|
+
break;
|
|
252
|
+
case 'LabeledStatement':
|
|
253
|
+
if (!breakablePattern.test(node.body.type))
|
|
254
|
+
path.pushBreak(opened.state, { breakable: false, label: node.label.name });
|
|
255
|
+
break;
|
|
256
|
+
}
|
|
257
|
+
forwardCurrentToHead(opened);
|
|
258
|
+
list(opened, node);
|
|
259
|
+
};
|
|
260
|
+
const exitNode = (node, parent) => {
|
|
261
|
+
const { state } = opened;
|
|
262
|
+
let isForwarded = false;
|
|
263
|
+
switch (node.type) {
|
|
264
|
+
case 'ChainExpression':
|
|
265
|
+
path.popChain(state);
|
|
266
|
+
break;
|
|
267
|
+
case 'IfStatement':
|
|
268
|
+
case 'ConditionalExpression':
|
|
269
|
+
case 'LogicalExpression':
|
|
270
|
+
path.popChoice(state);
|
|
271
|
+
break;
|
|
272
|
+
case 'AssignmentExpression':
|
|
273
|
+
if (assignmentChoices.has(node.operator))
|
|
274
|
+
path.popChoice(state);
|
|
275
|
+
break;
|
|
276
|
+
case 'SwitchStatement':
|
|
277
|
+
path.popSwitch(state);
|
|
278
|
+
break;
|
|
279
|
+
case 'SwitchCase':
|
|
280
|
+
if (node.consequent.length === 0)
|
|
281
|
+
path.makeSwitchCaseBody(state, { isEmpty: true, isDefault: !node.test });
|
|
282
|
+
if (isReachable(state.fork))
|
|
283
|
+
isForwarded = true;
|
|
284
|
+
break;
|
|
285
|
+
case 'TryStatement':
|
|
286
|
+
path.popTry(state);
|
|
287
|
+
break;
|
|
288
|
+
case 'BreakStatement':
|
|
289
|
+
forwardCurrentToHead(opened);
|
|
290
|
+
path.makeBreak(state, node.label?.name ?? null);
|
|
291
|
+
isForwarded = true;
|
|
292
|
+
break;
|
|
293
|
+
case 'ContinueStatement':
|
|
294
|
+
forwardCurrentToHead(opened);
|
|
295
|
+
path.makeContinue(state, node.label?.name ?? null);
|
|
296
|
+
isForwarded = true;
|
|
297
|
+
break;
|
|
298
|
+
case 'ReturnStatement':
|
|
299
|
+
forwardCurrentToHead(opened);
|
|
300
|
+
path.makeReturn(state);
|
|
301
|
+
isForwarded = true;
|
|
302
|
+
break;
|
|
303
|
+
case 'ThrowStatement':
|
|
304
|
+
forwardCurrentToHead(opened);
|
|
305
|
+
path.makeThrow(state);
|
|
306
|
+
isForwarded = true;
|
|
307
|
+
break;
|
|
308
|
+
case 'Identifier':
|
|
309
|
+
if (isIdentifierReference(node, parent)) {
|
|
310
|
+
path.makeFirstThrowable(state);
|
|
311
|
+
isForwarded = true;
|
|
312
|
+
}
|
|
313
|
+
break;
|
|
314
|
+
case 'CallExpression':
|
|
315
|
+
case 'ImportExpression':
|
|
316
|
+
case 'MemberExpression':
|
|
317
|
+
case 'NewExpression':
|
|
318
|
+
path.makeFirstThrowable(state);
|
|
319
|
+
break;
|
|
320
|
+
case 'YieldExpression':
|
|
321
|
+
path.makeYield(state);
|
|
322
|
+
break;
|
|
323
|
+
case 'WhileStatement':
|
|
324
|
+
case 'DoWhileStatement':
|
|
325
|
+
case 'ForStatement':
|
|
326
|
+
case 'ForInStatement':
|
|
327
|
+
case 'ForOfStatement':
|
|
328
|
+
path.popLoop(state);
|
|
329
|
+
break;
|
|
330
|
+
case 'AssignmentPattern':
|
|
331
|
+
path.popFork(state);
|
|
332
|
+
break;
|
|
333
|
+
case 'LabeledStatement':
|
|
334
|
+
if (!breakablePattern.test(node.body.type))
|
|
335
|
+
path.popBreak(state);
|
|
336
|
+
break;
|
|
337
|
+
}
|
|
338
|
+
if (!isForwarded)
|
|
339
|
+
forwardCurrentToHead(opened);
|
|
340
|
+
exits.set(node, opened.active.map(({ segment }) => segment.id));
|
|
341
|
+
switch (node.type) {
|
|
342
|
+
case 'Program':
|
|
343
|
+
case 'FunctionDeclaration':
|
|
344
|
+
case 'FunctionExpression':
|
|
345
|
+
case 'ArrowFunctionExpression':
|
|
346
|
+
case 'StaticBlock':
|
|
347
|
+
endCodePath();
|
|
348
|
+
break;
|
|
349
|
+
case 'CallExpression':
|
|
350
|
+
if (isOptional(node) && node.arguments.length === 0)
|
|
351
|
+
path.makeLogicalRight(opened.state);
|
|
352
|
+
break;
|
|
353
|
+
}
|
|
354
|
+
if (parent.type === 'PropertyDefinition' && parent.value === node)
|
|
355
|
+
endCodePath();
|
|
356
|
+
};
|
|
357
|
+
return { enter: enterNode, exit: exitNode, graphs, exits, faults };
|
|
358
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type Faults } from '../../../utils/faults.ts';
|
|
2
|
+
export type PathSegment = {
|
|
3
|
+
id: string;
|
|
4
|
+
allNext: PathSegment[];
|
|
5
|
+
allPrevious: PathSegment[];
|
|
6
|
+
reachable: boolean;
|
|
7
|
+
used: boolean;
|
|
8
|
+
loops: string[];
|
|
9
|
+
};
|
|
10
|
+
export type Ids = {
|
|
11
|
+
prefix: string;
|
|
12
|
+
count: number;
|
|
13
|
+
};
|
|
14
|
+
export type Fork = {
|
|
15
|
+
ids: Ids;
|
|
16
|
+
faults: Faults;
|
|
17
|
+
upper: Fork | null;
|
|
18
|
+
count: number;
|
|
19
|
+
list: PathSegment[][];
|
|
20
|
+
};
|
|
21
|
+
export declare const idsFrom: (prefix: string) => Ids;
|
|
22
|
+
export declare const nextId: (ids: Ids) => string;
|
|
23
|
+
export declare const noSegments: PathSegment[];
|
|
24
|
+
export declare const noFork: Fork;
|
|
25
|
+
export declare const segmentAt: (faults: Faults, segments: PathSegment[], index: number) => PathSegment;
|
|
26
|
+
export declare const flattenUnused: (segments: PathSegment[]) => PathSegment[];
|
|
27
|
+
export declare const markUsed: (segment: PathSegment) => void;
|
|
28
|
+
export declare const someReachable: (segments: PathSegment[]) => boolean;
|
|
29
|
+
export declare const newNext: (id: string, allPrevious: PathSegment[]) => PathSegment;
|
|
30
|
+
export declare const headOf: (fork: Fork) => PathSegment[];
|
|
31
|
+
export declare const isEmpty: (fork: Fork) => boolean;
|
|
32
|
+
export declare const isReachable: (fork: Fork) => boolean;
|
|
33
|
+
export declare const makeNext: (fork: Fork, start: number, end: number) => PathSegment[];
|
|
34
|
+
export declare const makeUnreachable: (fork: Fork, start: number, end: number) => PathSegment[];
|
|
35
|
+
export declare const makeDisconnected: (fork: Fork, start: number, end: number) => PathSegment[];
|
|
36
|
+
export declare const add: (fork: Fork, segments: PathSegment[]) => void;
|
|
37
|
+
export declare const replaceHead: (fork: Fork, segments: PathSegment[]) => void;
|
|
38
|
+
export declare const addAll: (fork: Fork, other: Fork) => void;
|
|
39
|
+
export declare const takeAll: (fork: Fork, other: Fork) => void;
|
|
40
|
+
export declare const clear: (fork: Fork) => void;
|
|
41
|
+
export declare const rootSegment: (ids: Ids) => PathSegment;
|
|
42
|
+
export declare const rootFork: (ids: Ids, faults: Faults, root: PathSegment) => Fork;
|
|
43
|
+
export declare const emptyFork: (parent: Fork) => Fork;
|
|
44
|
+
export declare const leavingFork: (parent: Fork) => Fork;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { heldOr, noFaults } from '../../../utils/faults.js';
|
|
2
|
+
export const idsFrom = (prefix) => ({ prefix, count: 0 });
|
|
3
|
+
export const nextId = (ids) => {
|
|
4
|
+
ids.count += 1;
|
|
5
|
+
return `${ids.prefix}${ids.count}`;
|
|
6
|
+
};
|
|
7
|
+
const segmentOf = (id, allPrevious, reachable) => ({
|
|
8
|
+
id,
|
|
9
|
+
allNext: [],
|
|
10
|
+
allPrevious,
|
|
11
|
+
reachable,
|
|
12
|
+
used: false,
|
|
13
|
+
loops: [],
|
|
14
|
+
});
|
|
15
|
+
const noSegment = { id: '', allNext: [], allPrevious: [], reachable: false, used: false, loops: [] };
|
|
16
|
+
export const noSegments = [];
|
|
17
|
+
export const noFork = { ids: idsFrom(''), faults: noFaults(), upper: null, count: 1, list: [] };
|
|
18
|
+
// The segment of one parallel run, which every step of a fork has one of.
|
|
19
|
+
export const segmentAt = (faults, segments, index) => heldOr(faults, segments[index], noSegment, 'segment of a run');
|
|
20
|
+
// An unused segment stands for the segments before it, so a segment never links to one nothing entered.
|
|
21
|
+
export const flattenUnused = (segments) => {
|
|
22
|
+
const done = new Set();
|
|
23
|
+
for (const segment of segments) {
|
|
24
|
+
if (segment.used)
|
|
25
|
+
done.add(segment);
|
|
26
|
+
else
|
|
27
|
+
for (const previous of segment.allPrevious)
|
|
28
|
+
done.add(previous);
|
|
29
|
+
}
|
|
30
|
+
return [...done];
|
|
31
|
+
};
|
|
32
|
+
export const markUsed = (segment) => {
|
|
33
|
+
if (segment.used)
|
|
34
|
+
return;
|
|
35
|
+
segment.used = true;
|
|
36
|
+
for (const previous of segment.allPrevious) {
|
|
37
|
+
previous.allNext.push(segment);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
export const someReachable = (segments) => segments.some((segment) => segment.reachable);
|
|
41
|
+
export const newNext = (id, allPrevious) => segmentOf(id, flattenUnused(allPrevious), someReachable(allPrevious));
|
|
42
|
+
// The unreachable segment after a `return` is used at once, since `if (a) return a; foo()` must keep it.
|
|
43
|
+
const newUnreachable = (id, allPrevious) => {
|
|
44
|
+
const segment = segmentOf(id, flattenUnused(allPrevious), false);
|
|
45
|
+
markUsed(segment);
|
|
46
|
+
return segment;
|
|
47
|
+
};
|
|
48
|
+
const newDisconnected = (id, allPrevious) => segmentOf(id, [], someReachable(allPrevious));
|
|
49
|
+
// One new segment per parallel run, after that run's segments from step `start` through `end`, a negative step counting from the last.
|
|
50
|
+
const createSegments = (fork, start, end, create) => {
|
|
51
|
+
const { list, faults } = fork;
|
|
52
|
+
const first = start >= 0 ? start : list.length + start;
|
|
53
|
+
const last = end >= 0 ? end : list.length + end;
|
|
54
|
+
const segments = [];
|
|
55
|
+
for (let index = 0; index < fork.count; ++index) {
|
|
56
|
+
const allPrevious = [];
|
|
57
|
+
for (let step = first; step <= last; ++step)
|
|
58
|
+
allPrevious.push(segmentAt(faults, heldOr(faults, list[step], noSegments, 'step of a fork'), index));
|
|
59
|
+
segments.push(create(nextId(fork.ids), allPrevious));
|
|
60
|
+
}
|
|
61
|
+
return segments;
|
|
62
|
+
};
|
|
63
|
+
// A `break` out of a `finally` leaves twice the runs the fork holds, so pairs half the list apart merge until it fits.
|
|
64
|
+
const mergeExtra = (fork, segments) => {
|
|
65
|
+
let current = segments;
|
|
66
|
+
while (current.length > fork.count) {
|
|
67
|
+
const half = Math.floor(current.length / 2);
|
|
68
|
+
const merged = [];
|
|
69
|
+
for (let index = 0; index < half; ++index)
|
|
70
|
+
merged.push(newNext(nextId(fork.ids), [segmentAt(fork.faults, current, index), segmentAt(fork.faults, current, index + half)]));
|
|
71
|
+
current = merged;
|
|
72
|
+
}
|
|
73
|
+
return current;
|
|
74
|
+
};
|
|
75
|
+
export const headOf = (fork) => heldOr(fork.faults, fork.list.at(-1), noSegments, 'head of a fork');
|
|
76
|
+
export const isEmpty = (fork) => fork.list.length === 0;
|
|
77
|
+
export const isReachable = (fork) => someReachable(headOf(fork));
|
|
78
|
+
export const makeNext = (fork, start, end) => createSegments(fork, start, end, newNext);
|
|
79
|
+
export const makeUnreachable = (fork, start, end) => createSegments(fork, start, end, newUnreachable);
|
|
80
|
+
export const makeDisconnected = (fork, start, end) => createSegments(fork, start, end, newDisconnected);
|
|
81
|
+
export const add = (fork, segments) => {
|
|
82
|
+
fork.list.push(mergeExtra(fork, segments));
|
|
83
|
+
};
|
|
84
|
+
export const replaceHead = (fork, segments) => {
|
|
85
|
+
fork.list.splice(-1, 1, mergeExtra(fork, segments));
|
|
86
|
+
};
|
|
87
|
+
export const addAll = (fork, other) => {
|
|
88
|
+
fork.list.push(...other.list);
|
|
89
|
+
};
|
|
90
|
+
// Moves every segment list of the other fork onto this one, leaving the other empty, so a chain of nested choices hands its lists up without copying them at every level.
|
|
91
|
+
export const takeAll = (fork, other) => {
|
|
92
|
+
if (fork.list.length)
|
|
93
|
+
fork.list.push(...other.list);
|
|
94
|
+
else
|
|
95
|
+
fork.list = other.list;
|
|
96
|
+
other.list = [];
|
|
97
|
+
};
|
|
98
|
+
export const clear = (fork) => {
|
|
99
|
+
fork.list = [];
|
|
100
|
+
};
|
|
101
|
+
export const rootSegment = (ids) => segmentOf(nextId(ids), [], true);
|
|
102
|
+
export const rootFork = (ids, faults, root) => ({ ids, faults, upper: null, count: 1, list: [[root]] });
|
|
103
|
+
export const emptyFork = (parent) => ({ ids: parent.ids, faults: parent.faults, upper: parent, count: parent.count, list: [] });
|
|
104
|
+
// Inside a `finally`, the path leaving it forks from the normal one, so the new fork is twice as wide.
|
|
105
|
+
export const leavingFork = (parent) => ({ ids: parent.ids, faults: parent.faults, upper: parent, count: 2 * parent.count, list: [] });
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { type Faults } from '../../../utils/faults.ts';
|
|
2
|
+
import { type Fork, type Ids, type PathSegment } from './segments.ts';
|
|
3
|
+
type Break = {
|
|
4
|
+
upper: Break | null;
|
|
5
|
+
breakable: boolean;
|
|
6
|
+
label: string | null;
|
|
7
|
+
broken: Fork;
|
|
8
|
+
};
|
|
9
|
+
type Chain = {
|
|
10
|
+
upper: Chain | null;
|
|
11
|
+
choices: number;
|
|
12
|
+
};
|
|
13
|
+
export type ChoiceKind = '&&' | '||' | '??' | 'test' | 'loop';
|
|
14
|
+
type Choice = {
|
|
15
|
+
upper: Choice | null;
|
|
16
|
+
kind: ChoiceKind;
|
|
17
|
+
isForkingAsResult: boolean;
|
|
18
|
+
true: Fork;
|
|
19
|
+
false: Fork;
|
|
20
|
+
nullish: Fork;
|
|
21
|
+
processed: boolean;
|
|
22
|
+
};
|
|
23
|
+
export type LoopType = 'WhileStatement' | 'DoWhileStatement' | 'ForStatement' | 'ForInStatement' | 'ForOfStatement';
|
|
24
|
+
type Loop = {
|
|
25
|
+
upper: Loop | null;
|
|
26
|
+
type: LoopType;
|
|
27
|
+
label: string | null;
|
|
28
|
+
broken: Fork;
|
|
29
|
+
test: boolean | undefined;
|
|
30
|
+
continueDestination: PathSegment[] | null;
|
|
31
|
+
continued: Fork;
|
|
32
|
+
entry: PathSegment[] | null;
|
|
33
|
+
endOfInit: PathSegment[] | null;
|
|
34
|
+
testSegments: PathSegment[] | null;
|
|
35
|
+
endOfTest: PathSegment[] | null;
|
|
36
|
+
update: PathSegment[] | null;
|
|
37
|
+
endOfUpdate: PathSegment[] | null;
|
|
38
|
+
previous: PathSegment[] | null;
|
|
39
|
+
left: PathSegment[] | null;
|
|
40
|
+
endOfLeft: PathSegment[] | null;
|
|
41
|
+
};
|
|
42
|
+
type Switch = {
|
|
43
|
+
upper: Switch | null;
|
|
44
|
+
hasCase: boolean;
|
|
45
|
+
defaultSegments: PathSegment[];
|
|
46
|
+
defaultBody: PathSegment[] | null;
|
|
47
|
+
foundEmptyDefault: boolean;
|
|
48
|
+
lastIsDefault: boolean;
|
|
49
|
+
forks: number;
|
|
50
|
+
};
|
|
51
|
+
type Try = {
|
|
52
|
+
upper: Try | null;
|
|
53
|
+
hasFinalizer: boolean;
|
|
54
|
+
position: 'try' | 'catch' | 'finally';
|
|
55
|
+
returned: Fork;
|
|
56
|
+
thrown: Fork;
|
|
57
|
+
lastOfTryIsReachable: boolean;
|
|
58
|
+
lastOfCatchIsReachable: boolean;
|
|
59
|
+
};
|
|
60
|
+
export type State = {
|
|
61
|
+
ids: Ids;
|
|
62
|
+
faults: Faults;
|
|
63
|
+
onLooped: (from: PathSegment, to: PathSegment) => void;
|
|
64
|
+
fork: Fork;
|
|
65
|
+
choice: Choice | null;
|
|
66
|
+
switch: Switch | null;
|
|
67
|
+
try: Try | null;
|
|
68
|
+
loop: Loop | null;
|
|
69
|
+
break: Break | null;
|
|
70
|
+
chain: Chain | null;
|
|
71
|
+
current: PathSegment[];
|
|
72
|
+
initial: PathSegment;
|
|
73
|
+
final: PathSegment[];
|
|
74
|
+
returned: PathSegment[];
|
|
75
|
+
thrown: PathSegment[];
|
|
76
|
+
};
|
|
77
|
+
export declare const stateOf: (ids: Ids, faults: Faults, onLooped: State['onLooped']) => State;
|
|
78
|
+
export declare const pushFork: (state: State) => Fork;
|
|
79
|
+
export declare const popFork: (state: State) => void;
|
|
80
|
+
export declare const forkPath: (state: State) => void;
|
|
81
|
+
export declare const forkBypassPath: (state: State) => void;
|
|
82
|
+
export declare const pushChoice: (state: State, choice: Pick<Choice, 'kind' | 'isForkingAsResult'>) => void;
|
|
83
|
+
export declare const popChoice: (state: State) => void;
|
|
84
|
+
export declare const makeLogicalRight: (state: State) => void;
|
|
85
|
+
export declare const makeIfConsequent: (state: State) => void;
|
|
86
|
+
export declare const makeIfAlternate: (state: State) => void;
|
|
87
|
+
export declare const pushChain: (state: State) => void;
|
|
88
|
+
export declare const popChain: (state: State) => void;
|
|
89
|
+
export declare const makeOptionalNode: (state: State) => void;
|
|
90
|
+
export declare const pushBreak: (state: State, context: Pick<Break, 'breakable' | 'label'>) => Break;
|
|
91
|
+
export declare const popBreak: (state: State) => Break;
|
|
92
|
+
export declare const pushSwitch: (state: State, hasCase: boolean, label: string | null) => void;
|
|
93
|
+
export declare const popSwitch: (state: State) => void;
|
|
94
|
+
export declare const makeSwitchCaseBody: (state: State, body: {
|
|
95
|
+
isEmpty: boolean;
|
|
96
|
+
isDefault: boolean;
|
|
97
|
+
}) => void;
|
|
98
|
+
export declare const pushTry: (state: State, hasFinalizer: boolean) => void;
|
|
99
|
+
export declare const popTry: (state: State) => void;
|
|
100
|
+
export declare const makeCatchBlock: (state: State) => void;
|
|
101
|
+
export declare const makeFinallyBlock: (state: State) => void;
|
|
102
|
+
export declare const makeYield: (state: State) => void;
|
|
103
|
+
export declare const makeFirstThrowable: (state: State) => void;
|
|
104
|
+
export declare const pushLoop: (state: State, type: LoopType, label: string | null) => void;
|
|
105
|
+
export declare const popLoop: (state: State) => void;
|
|
106
|
+
export declare const makeWhileTest: (state: State, test: boolean | undefined) => void;
|
|
107
|
+
export declare const makeWhileBody: (state: State) => void;
|
|
108
|
+
export declare const makeDoWhileBody: (state: State) => void;
|
|
109
|
+
export declare const makeDoWhileTest: (state: State, test: boolean | undefined) => void;
|
|
110
|
+
export declare const makeForTest: (state: State, test: boolean | undefined) => void;
|
|
111
|
+
export declare const makeForUpdate: (state: State) => void;
|
|
112
|
+
export declare const makeForBody: (state: State) => void;
|
|
113
|
+
export declare const makeForInOfLeft: (state: State) => void;
|
|
114
|
+
export declare const makeForInOfRight: (state: State) => void;
|
|
115
|
+
export declare const makeForInOfBody: (state: State) => void;
|
|
116
|
+
export declare const makeBreak: (state: State, label: string | null) => void;
|
|
117
|
+
export declare const makeContinue: (state: State, label: string | null) => void;
|
|
118
|
+
export declare const makeReturn: (state: State) => void;
|
|
119
|
+
export declare const makeThrow: (state: State) => void;
|
|
120
|
+
export declare const makeFinal: (state: State) => void;
|
|
121
|
+
export {};
|