@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,181 @@
|
|
|
1
|
+
import { parseSync, visitorKeys } from 'oxc-parser';
|
|
2
|
+
import { failed } from './errors.js';
|
|
3
|
+
import { itemAt, valueAt } from './lookup.js';
|
|
4
|
+
export { entryAt, itemAt, present } from './lookup.js';
|
|
5
|
+
const runtimeTypes = new Set([
|
|
6
|
+
'TSAsExpression',
|
|
7
|
+
'TSSatisfiesExpression',
|
|
8
|
+
'TSNonNullExpression',
|
|
9
|
+
'TSTypeAssertion',
|
|
10
|
+
'TSInstantiationExpression',
|
|
11
|
+
'TSParameterProperty',
|
|
12
|
+
'TSEnumDeclaration',
|
|
13
|
+
'TSEnumBody',
|
|
14
|
+
'TSEnumMember',
|
|
15
|
+
'TSModuleDeclaration',
|
|
16
|
+
'TSModuleBlock',
|
|
17
|
+
]);
|
|
18
|
+
const chainKeys = new Set(['object', 'callee', 'expression']);
|
|
19
|
+
const functionTypes = new Set(['FunctionDeclaration', 'FunctionExpression', 'ArrowFunctionExpression']);
|
|
20
|
+
// visitorKeys name only child slots, and each holds a node, an array of nodes, or nothing.
|
|
21
|
+
const isNode = (value) => Boolean(value);
|
|
22
|
+
// Type-only TS nodes hold no runtime code, so they are skipped whole, type annotations under runtime code included.
|
|
23
|
+
export const holdsRuntime = (node) => !('declare' in node && node.declare === true) && (!node.type.startsWith('TS') || runtimeTypes.has(node.type));
|
|
24
|
+
export const parse = (source, path) => {
|
|
25
|
+
// ESLint's code paths chain `a || (b || c)` as one fork only with no ParenthesizedExpression between, as standard ESTree has none.
|
|
26
|
+
// Oxc guesses a script for a file with no import or export, so every file is read as the module ESLint 10 reads it as.
|
|
27
|
+
const { program, comments, errors } = parseSync(path, source, { preserveParens: false, sourceType: 'module' });
|
|
28
|
+
const [error] = errors;
|
|
29
|
+
if (error)
|
|
30
|
+
return failed(`${path}: ${error.message}`);
|
|
31
|
+
return { data: { program, comments, path }, error: null };
|
|
32
|
+
};
|
|
33
|
+
const isType = (node, type) => node.type === type;
|
|
34
|
+
// A node narrowed to the type its caller knows it holds, as a decision's kind fixes its node, refusing any other.
|
|
35
|
+
export const ofType = (node, type) => {
|
|
36
|
+
if (!isType(node, type))
|
|
37
|
+
throw new Error(`${node.type} where ${type} was expected`);
|
|
38
|
+
return node;
|
|
39
|
+
};
|
|
40
|
+
// The visits of a node's children in order, each with the parent, key, chain and inFunction the walk gives it.
|
|
41
|
+
const childVisitsOf = (visit) => {
|
|
42
|
+
const { node, ancestors } = visit;
|
|
43
|
+
const depth = ancestors.length;
|
|
44
|
+
const inFunction = visit.inFunction || functionTypes.has(node.type);
|
|
45
|
+
// A ChainExpression's one key is a chain key, so a chain passes only down the keys that continue it.
|
|
46
|
+
const ownChain = node.type === 'ChainExpression' ? node : visit.chain;
|
|
47
|
+
const visits = [];
|
|
48
|
+
for (const key of valueAt(visitorKeys, node.type)) {
|
|
49
|
+
const chain = chainKeys.has(key) ? ownChain : null;
|
|
50
|
+
const value = Reflect.get(node, key);
|
|
51
|
+
for (const child of Array.isArray(value) ? value : [value]) {
|
|
52
|
+
if (isNode(child))
|
|
53
|
+
visits.push({ visit: { node: child, parent: node, ancestors, key, chain, inFunction }, depth });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return visits;
|
|
57
|
+
};
|
|
58
|
+
// The ancestors array is shared and changes as the walk moves, so a visitor reads it only during its own call.
|
|
59
|
+
// The walk keeps its own stack so a tree deeper than the call stack is walked whole.
|
|
60
|
+
const walkTree = (root, onNode) => {
|
|
61
|
+
const ancestors = [root];
|
|
62
|
+
// The root itself is never visited, so every visited node has a parent.
|
|
63
|
+
const pending = childVisitsOf({ node: root, parent: root, ancestors, key: root.type, chain: null, inFunction: false }).toReversed();
|
|
64
|
+
for (let step = pending.pop(); step; step = pending.pop()) {
|
|
65
|
+
const { visit, depth } = step;
|
|
66
|
+
ancestors.length = depth;
|
|
67
|
+
if (!holdsRuntime(visit.node))
|
|
68
|
+
continue;
|
|
69
|
+
onNode(visit);
|
|
70
|
+
ancestors.push(visit.node);
|
|
71
|
+
for (const child of childVisitsOf(visit).toReversed())
|
|
72
|
+
pending.push(child);
|
|
73
|
+
}
|
|
74
|
+
ancestors.length = 1;
|
|
75
|
+
};
|
|
76
|
+
// The visits a walk driven from outside makes, as the CFG's one walk enters and leaves each node: only runtime nodes are visited, each with the same parent, ancestors, chain and inFunction `walk` gives it.
|
|
77
|
+
export const visitorOf = (root, onNode) => {
|
|
78
|
+
const ancestors = [root];
|
|
79
|
+
const open = [];
|
|
80
|
+
let above = { node: root, parent: root, ancestors, key: root.type, chain: null, inFunction: false };
|
|
81
|
+
const enter = (node, parent, key) => {
|
|
82
|
+
const ownChain = parent.type === 'ChainExpression' ? parent : above.chain;
|
|
83
|
+
const visit = { node, parent, ancestors, key, chain: chainKeys.has(key) ? ownChain : null, inFunction: above.inFunction || functionTypes.has(parent.type) };
|
|
84
|
+
onNode(visit);
|
|
85
|
+
ancestors.push(node);
|
|
86
|
+
open.push(above);
|
|
87
|
+
above = visit;
|
|
88
|
+
};
|
|
89
|
+
const exit = () => {
|
|
90
|
+
ancestors.pop();
|
|
91
|
+
above = open.pop() ?? above;
|
|
92
|
+
};
|
|
93
|
+
return { enter, exit };
|
|
94
|
+
};
|
|
95
|
+
const replays = new WeakMap();
|
|
96
|
+
const replayOf = (program) => {
|
|
97
|
+
const kept = replays.get(program);
|
|
98
|
+
if (kept)
|
|
99
|
+
return kept;
|
|
100
|
+
const ancestors = [program];
|
|
101
|
+
const steps = [];
|
|
102
|
+
walkTree(program, (visit) => steps.push({ visit: { ...visit, ancestors }, depth: visit.ancestors.length }));
|
|
103
|
+
const replay = { steps, ancestors, isReplaying: false };
|
|
104
|
+
replays.set(program, replay);
|
|
105
|
+
return replay;
|
|
106
|
+
};
|
|
107
|
+
export const walk = (root, onNode) => {
|
|
108
|
+
const replay = root.type === 'Program' ? replayOf(root) : null;
|
|
109
|
+
if (!replay)
|
|
110
|
+
return walkTree(root, onNode);
|
|
111
|
+
if (replay.isReplaying)
|
|
112
|
+
return walkTree(root, onNode);
|
|
113
|
+
const { steps, ancestors } = replay;
|
|
114
|
+
replay.isReplaying = true;
|
|
115
|
+
for (const { visit, depth } of steps) {
|
|
116
|
+
ancestors.length = depth;
|
|
117
|
+
onNode(visit);
|
|
118
|
+
ancestors.push(visit.node);
|
|
119
|
+
}
|
|
120
|
+
ancestors.length = 1;
|
|
121
|
+
replay.isReplaying = false;
|
|
122
|
+
};
|
|
123
|
+
// A member's property and an object's key name a slot, not a variable, unless written in brackets.
|
|
124
|
+
// The slot that holds a property name under each node kind that has one, a member's property or a key in an object or class.
|
|
125
|
+
const propertySlots = new Map([
|
|
126
|
+
['MemberExpression', 'property'],
|
|
127
|
+
['Property', 'key'],
|
|
128
|
+
['MethodDefinition', 'key'],
|
|
129
|
+
['PropertyDefinition', 'key'],
|
|
130
|
+
]);
|
|
131
|
+
export const namesProperty = (parent, key) => propertySlots.get(parent.type) === key && !('computed' in parent && parent.computed);
|
|
132
|
+
// Whether an offset sits inside one of a file's comments, which the parser lists in source order.
|
|
133
|
+
export const isInComment = (comments, at) => {
|
|
134
|
+
let low = 0;
|
|
135
|
+
let high = comments.length;
|
|
136
|
+
while (low < high) {
|
|
137
|
+
const middle = (low + high) >> 1;
|
|
138
|
+
if (itemAt(comments, middle).end <= at)
|
|
139
|
+
low = middle + 1;
|
|
140
|
+
else
|
|
141
|
+
high = middle;
|
|
142
|
+
}
|
|
143
|
+
const comment = comments.at(low);
|
|
144
|
+
return comment !== undefined && comment.start <= at;
|
|
145
|
+
};
|
|
146
|
+
// Where the first `token` between two offsets starts that no comment holds, as an operator between its operands.
|
|
147
|
+
export const tokenAt = ({ source, comments, token, from, to }) => {
|
|
148
|
+
for (let at = source.indexOf(token, from); at !== -1 && at + token.length <= to; at = source.indexOf(token, at + 1)) {
|
|
149
|
+
if (!isInComment(comments, at))
|
|
150
|
+
return at;
|
|
151
|
+
}
|
|
152
|
+
throw new Error(`no ${token} outside a comment between ${from} and ${to}`);
|
|
153
|
+
};
|
|
154
|
+
// Matches each line terminator JavaScript reads, a carriage return and line feed as one.
|
|
155
|
+
export const lineBreakPattern = /\r\n|[\n\r\u2028\u2029]/g;
|
|
156
|
+
// The offsets where a source's lines start, the first included.
|
|
157
|
+
export const lineStartsOf = (source) => [0, ...Array.from(source.matchAll(lineBreakPattern), (match) => match.index + match[0].length)];
|
|
158
|
+
const lineBreaks = new Set(['\n', '\r', '\u2028', '\u2029']);
|
|
159
|
+
// Where the line holding an offset starts, just past the nearest line terminator before it.
|
|
160
|
+
export const lineStartOf = (source, offset) => {
|
|
161
|
+
let at = offset;
|
|
162
|
+
while (at > 0 && !lineBreaks.has(source.charAt(at - 1)))
|
|
163
|
+
at--;
|
|
164
|
+
return at;
|
|
165
|
+
};
|
|
166
|
+
export const locate = (source) => {
|
|
167
|
+
const starts = lineStartsOf(source);
|
|
168
|
+
// A scan looks up every fork and site, so the last line start at or before the offset is found by halving.
|
|
169
|
+
return (offset) => {
|
|
170
|
+
let low = 0;
|
|
171
|
+
let high = starts.length - 1;
|
|
172
|
+
while (low < high) {
|
|
173
|
+
const middle = Math.ceil((low + high) / 2);
|
|
174
|
+
if (itemAt(starts, middle) <= offset)
|
|
175
|
+
low = middle;
|
|
176
|
+
else
|
|
177
|
+
high = middle - 1;
|
|
178
|
+
}
|
|
179
|
+
return { line: low + 1, column: offset - itemAt(starts, low) };
|
|
180
|
+
};
|
|
181
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export class CrushError extends Error {
|
|
2
|
+
constructor(message) {
|
|
3
|
+
super(message);
|
|
4
|
+
this.name = this.constructor.name;
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
export const failed = (message) => ({ data: null, error: new CrushError(message) });
|
|
8
|
+
// Hands a failure to Vitest, which learns that a runner module or hook failed only from a throw, so this is the one place crush throws one.
|
|
9
|
+
// The binding names its type, so TypeScript narrows past a call to it as it does past a throw.
|
|
10
|
+
export const thrownToVitest = (error) => {
|
|
11
|
+
throw error;
|
|
12
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { CrushError } from './errors.ts';
|
|
2
|
+
export type Faults = {
|
|
3
|
+
error: CrushError | null;
|
|
4
|
+
};
|
|
5
|
+
export declare const noFaults: () => Faults;
|
|
6
|
+
export declare const heldOr: <T extends object>(faults: Faults, value: T | null | undefined, standIn: T, what: string) => T;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CrushError } from './errors.js';
|
|
2
|
+
export const noFaults = () => ({ error: null });
|
|
3
|
+
// A value the code around it always holds, as a fork its own walk opened.
|
|
4
|
+
// A bug in crush that leaves it missing is kept as the walk's first error, so the walk runs to its end on a copy of a stand-in and returns that error rather than a wrong answer.
|
|
5
|
+
export const heldOr = (faults, value, standIn, what) => {
|
|
6
|
+
if (value)
|
|
7
|
+
return value;
|
|
8
|
+
faults.error ??= new CrushError(`no ${what}`);
|
|
9
|
+
return structuredClone(standIn);
|
|
10
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const itemAt: <T>(list: readonly T[], index: number) => T;
|
|
2
|
+
export declare const entryAt: <K, V>(map: ReadonlyMap<K, V>, key: K, name: string) => V;
|
|
3
|
+
export declare const valueAt: <T>(record: Readonly<Record<string, T>>, key: string) => T;
|
|
4
|
+
export declare const present: <T>(value: T | null | undefined) => T;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// The item at an index a list always holds, as a position its own code numbered.
|
|
2
|
+
export const itemAt = (list, index) => {
|
|
3
|
+
const item = list[index];
|
|
4
|
+
if (item === undefined)
|
|
5
|
+
throw new Error(`no item at ${index} of ${list.length}`);
|
|
6
|
+
return item;
|
|
7
|
+
};
|
|
8
|
+
// The value under a key a map always holds, as a node or id its own code indexed, named in the refusal by what the key stands for.
|
|
9
|
+
export const entryAt = (map, key, name) => {
|
|
10
|
+
const value = map.get(key);
|
|
11
|
+
if (value === undefined)
|
|
12
|
+
throw new Error(`no entry for ${name}`);
|
|
13
|
+
return value;
|
|
14
|
+
};
|
|
15
|
+
// The value under a key a record always holds, as an id its own code wrote.
|
|
16
|
+
export const valueAt = (record, key) => {
|
|
17
|
+
const value = Object.hasOwn(record, key) ? record[key] : undefined;
|
|
18
|
+
if (value === undefined)
|
|
19
|
+
throw new Error(`no value under ${key}`);
|
|
20
|
+
return value;
|
|
21
|
+
};
|
|
22
|
+
// A value a caller knows is set, as a loop's test a decision was made from.
|
|
23
|
+
export const present = (value) => {
|
|
24
|
+
if (value === null || value === undefined)
|
|
25
|
+
throw new Error('no value where one was known to be set');
|
|
26
|
+
return value;
|
|
27
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// The first answer work gives that is not null, each item's work starting only once the one before it ends, since such work shares state no two runs may touch at once.
|
|
2
|
+
export const firstInOrder = async (items, work) => {
|
|
3
|
+
for (const item of items) {
|
|
4
|
+
// oxlint-disable-next-line no-await-in-loop -- each item's work must end before the next starts, and an answer stops the rest
|
|
5
|
+
const answer = await work(item);
|
|
6
|
+
if (answer !== null)
|
|
7
|
+
return answer;
|
|
8
|
+
}
|
|
9
|
+
return null;
|
|
10
|
+
};
|
|
11
|
+
// Runs each item's work once the one before it ends, as firstInOrder does with work that never answers.
|
|
12
|
+
export const eachInOrder = async (items, work) => {
|
|
13
|
+
await firstInOrder(items, async (item) => {
|
|
14
|
+
await work(item);
|
|
15
|
+
return null;
|
|
16
|
+
});
|
|
17
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type Clock = {
|
|
2
|
+
now: () => number;
|
|
3
|
+
sleep: (ms: number) => Promise<void>;
|
|
4
|
+
};
|
|
5
|
+
export declare const systemClock: Clock;
|
|
6
|
+
type RetriedInput = {
|
|
7
|
+
run: () => Error | null;
|
|
8
|
+
isRetried: (error: Error) => boolean;
|
|
9
|
+
waitMs: number;
|
|
10
|
+
intervalMs: number;
|
|
11
|
+
clock: Clock;
|
|
12
|
+
};
|
|
13
|
+
export declare const retried: ({ run, isRetried, waitMs, intervalMs, clock }: RetriedInput) => Promise<Error | null>;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export const systemClock = {
|
|
2
|
+
now: () => Temporal.Now.instant().epochMilliseconds,
|
|
3
|
+
sleep: (ms) => new Promise((resolve) => setTimeout(resolve, ms)),
|
|
4
|
+
};
|
|
5
|
+
// Tries `run` until it answers no failure, waiting the interval between tries, answering a failure it never retries or the last once the wait has passed.
|
|
6
|
+
export const retried = async ({ run, isRetried, waitMs, intervalMs, clock }) => {
|
|
7
|
+
const started = clock.now();
|
|
8
|
+
for (;;) {
|
|
9
|
+
const error = run();
|
|
10
|
+
if (!error || !isRetried(error) || clock.now() - started > waitMs)
|
|
11
|
+
return error;
|
|
12
|
+
// oxlint-disable-next-line no-await-in-loop -- each try waits out the interval after the one before it
|
|
13
|
+
await clock.sleep(intervalMs);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type Safe<T, E extends Error = Error> = {
|
|
2
|
+
data: T;
|
|
3
|
+
error: null;
|
|
4
|
+
} | {
|
|
5
|
+
data: null;
|
|
6
|
+
error: E;
|
|
7
|
+
};
|
|
8
|
+
export declare class ThrownValue extends Error {
|
|
9
|
+
}
|
|
10
|
+
export declare const safe: <T>(fn: () => T) => Safe<T>;
|
|
11
|
+
export declare const safeAsync: <T>(fn: () => Promise<T> | T) => Promise<Safe<T>>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// A thrown value that is no Error, wrapped as one, which a caller tells apart from a real Error, since its stack is the wrap's rather than the throw's.
|
|
2
|
+
export class ThrownValue extends Error {
|
|
3
|
+
}
|
|
4
|
+
// A thrown value as text, which a value with no string conversion, as `Object.create(null)`, cannot give, so the wrap never throws in place of the throw it wraps.
|
|
5
|
+
const textOf = (thrown) => {
|
|
6
|
+
try {
|
|
7
|
+
return String(thrown);
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
return 'a thrown value with no text';
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
// Anything can be thrown, so a non-Error is wrapped to give every caller a message and a stack.
|
|
14
|
+
// `Error.isError` reads no prototype, so a revoked proxy, whose prototype cannot be read, is told apart without throwing.
|
|
15
|
+
const toError = (thrown) => (Error.isError(thrown) ? thrown : new ThrownValue(textOf(thrown), { cause: thrown }));
|
|
16
|
+
export const safe = (fn) => {
|
|
17
|
+
try {
|
|
18
|
+
return { data: fn(), error: null };
|
|
19
|
+
}
|
|
20
|
+
catch (thrown) {
|
|
21
|
+
return { data: null, error: toError(thrown) };
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
export const safeAsync = async (fn) => {
|
|
25
|
+
try {
|
|
26
|
+
return { data: await fn(), error: null };
|
|
27
|
+
}
|
|
28
|
+
catch (thrown) {
|
|
29
|
+
return { data: null, error: toError(thrown) };
|
|
30
|
+
}
|
|
31
|
+
};
|