@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,120 @@
|
|
|
1
|
+
import { locate, walk } from '../../utils/ast.js';
|
|
2
|
+
const functionTypes = new Set(['FunctionDeclaration', 'FunctionExpression', 'ArrowFunctionExpression']);
|
|
3
|
+
// The builder calls that end a tRPC procedure, and the server calls that register an MCP tool.
|
|
4
|
+
const procedureEnds = new Set(['query', 'mutation', 'subscription']);
|
|
5
|
+
const toolRegistrations = new Set(['registerTool', 'tool']);
|
|
6
|
+
// Whether a call names one of the methods on an object, as `query` in `procedure.query(handler)`.
|
|
7
|
+
const callsOneOf = (call, methods) => {
|
|
8
|
+
const { callee } = call;
|
|
9
|
+
if (callee.type !== 'MemberExpression' || callee.computed)
|
|
10
|
+
return false;
|
|
11
|
+
const { property } = callee;
|
|
12
|
+
return property.type === 'Identifier' && methods.has(property.name);
|
|
13
|
+
};
|
|
14
|
+
// The name a property's key spells out in the code, a plain name or a quoted string, and none for a computed key.
|
|
15
|
+
const staticKeyOf = (property) => {
|
|
16
|
+
const { computed, key } = property;
|
|
17
|
+
if (key.type === 'Literal')
|
|
18
|
+
return typeof key.value === 'string' && !computed ? key.value : null;
|
|
19
|
+
return key.type === 'Identifier' && !computed ? key.name : null;
|
|
20
|
+
};
|
|
21
|
+
// The functions a declaration names: its own, or each a `const` or `let` is given, where a default export may leave its function without a name.
|
|
22
|
+
export const declaredFunctionsOf = (declaration) => {
|
|
23
|
+
if (declaration.type === 'FunctionDeclaration')
|
|
24
|
+
return declaration.id ? [{ name: declaration.id.name, node: declaration }] : [];
|
|
25
|
+
if (declaration.type !== 'VariableDeclaration')
|
|
26
|
+
return [];
|
|
27
|
+
return declaration.declarations.flatMap(({ id, init }) => (id.type === 'Identifier' && init && functionTypes.has(init.type) ? [{ name: id.name, node: init }] : []));
|
|
28
|
+
};
|
|
29
|
+
// Every entry a file exports: its named functions, its default, the `fetch` of a default object, and each public method of an exported class.
|
|
30
|
+
export const entriesOf = (source, parsed, paths) => {
|
|
31
|
+
const at = locate(source);
|
|
32
|
+
const keyAt = (offset) => {
|
|
33
|
+
const { line, column } = at(offset);
|
|
34
|
+
return `L${line}C${column}`;
|
|
35
|
+
};
|
|
36
|
+
const references = new Map(paths.references.map((reference) => [reference.identifier, reference]));
|
|
37
|
+
const rewrites = paths.references.filter(({ identifier, definition, isWrite }) => {
|
|
38
|
+
const isInit = definition.type === 'VariableDeclarator' && identifier.start >= definition.id.start && identifier.end <= definition.id.end;
|
|
39
|
+
return isWrite && !isInit;
|
|
40
|
+
});
|
|
41
|
+
const reassigned = new Set(rewrites.map(({ variable }) => variable));
|
|
42
|
+
// A named local handler points at its function, while imported and unresolved names keep their own span.
|
|
43
|
+
const handlerOf = (handler) => {
|
|
44
|
+
const seen = new Set();
|
|
45
|
+
let named = handler;
|
|
46
|
+
for (let reference = references.get(named); reference; reference = references.get(named)) {
|
|
47
|
+
const { variable, definition } = reference;
|
|
48
|
+
if (seen.has(variable) || paths.parameters.has(variable) || reassigned.has(variable))
|
|
49
|
+
return handler;
|
|
50
|
+
if (definition.type === 'FunctionDeclaration')
|
|
51
|
+
return definition;
|
|
52
|
+
if (definition.type !== 'VariableDeclarator')
|
|
53
|
+
return handler;
|
|
54
|
+
const { init } = definition;
|
|
55
|
+
if (!init)
|
|
56
|
+
return handler;
|
|
57
|
+
if (functionTypes.has(init.type))
|
|
58
|
+
return init;
|
|
59
|
+
if (!paths.constants.has(variable))
|
|
60
|
+
return handler;
|
|
61
|
+
seen.add(variable);
|
|
62
|
+
named = init;
|
|
63
|
+
}
|
|
64
|
+
return handler;
|
|
65
|
+
};
|
|
66
|
+
const entries = [];
|
|
67
|
+
// A class's own methods, a constructor and a private member excepted, since only a public method is called from outside.
|
|
68
|
+
const methodsOf = (node) => {
|
|
69
|
+
if (node.type !== 'ClassDeclaration' && node.type !== 'ClassExpression')
|
|
70
|
+
return;
|
|
71
|
+
for (const member of node.body.body) {
|
|
72
|
+
if (member.type === 'MethodDefinition' && member.kind === 'method' && member.key.type === 'Identifier' && member.value.type !== 'TSEmptyBodyFunctionExpression') {
|
|
73
|
+
entries.push({ kind: 'method', name: member.key.name, key: keyAt(member.value.start) });
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
for (const item of parsed.program.body) {
|
|
78
|
+
if (item.type === 'ExportDefaultDeclaration') {
|
|
79
|
+
const declaration = item.declaration;
|
|
80
|
+
if (functionTypes.has(declaration.type)) {
|
|
81
|
+
entries.push({ kind: 'default', name: 'default', key: keyAt(declaration.start) });
|
|
82
|
+
}
|
|
83
|
+
methodsOf(declaration);
|
|
84
|
+
if (declaration.type === 'ObjectExpression') {
|
|
85
|
+
for (const property of declaration.properties) {
|
|
86
|
+
if (property.type === 'Property' && staticKeyOf(property) === 'fetch') {
|
|
87
|
+
entries.push({ kind: 'fetch', name: 'fetch', key: keyAt(handlerOf(property.value).start) });
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (item.type !== 'ExportNamedDeclaration' || !item.declaration)
|
|
93
|
+
continue;
|
|
94
|
+
const { declaration } = item;
|
|
95
|
+
methodsOf(declaration);
|
|
96
|
+
for (const { name, node } of declaredFunctionsOf(declaration)) {
|
|
97
|
+
entries.push({ kind: 'export', name, key: keyAt(node.start) });
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
// A router's property ending in a procedure's builder is a procedure by its key, and a tool's registration a tool by its name, each keyed where its handler starts.
|
|
101
|
+
walk(parsed.program, ({ node }) => {
|
|
102
|
+
if (node.type === 'Property' && node.value.type === 'CallExpression' && callsOneOf(node.value, procedureEnds)) {
|
|
103
|
+
const name = staticKeyOf(node);
|
|
104
|
+
const [handler] = node.value.arguments.toReversed();
|
|
105
|
+
if (name && handler && (functionTypes.has(handler.type) || handler.type === 'Identifier')) {
|
|
106
|
+
entries.push({ kind: 'procedure', name, key: keyAt(handlerOf(handler).start) });
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
if (node.type !== 'CallExpression' || !callsOneOf(node, toolRegistrations))
|
|
110
|
+
return;
|
|
111
|
+
const [name] = node.arguments;
|
|
112
|
+
if (name?.type !== 'Literal' || typeof name.value !== 'string')
|
|
113
|
+
return;
|
|
114
|
+
const handler = node.arguments.reduce((_, argument) => argument, name);
|
|
115
|
+
if (functionTypes.has(handler.type) || handler.type === 'Identifier') {
|
|
116
|
+
entries.push({ kind: 'tool', name: name.value, key: keyAt(handlerOf(handler).start) });
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
return entries;
|
|
120
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { locate, walk } from '../../utils/ast.js';
|
|
2
|
+
import { declaredFunctionsOf, entriesOf } from './entries.js';
|
|
3
|
+
const functionTypes = new Set(['FunctionDeclaration', 'FunctionExpression', 'ArrowFunctionExpression']);
|
|
4
|
+
// Each top-level function and the name it goes by, a declaration's own or the `const` it is written to, exported or not, and each method of a top-level class as `Class.method`.
|
|
5
|
+
const topLevelFunctionsIn = (body) => {
|
|
6
|
+
return body.flatMap((item) => {
|
|
7
|
+
const declaration = item.type === 'ExportNamedDeclaration' || item.type === 'ExportDefaultDeclaration' ? item.declaration : item;
|
|
8
|
+
if (!declaration)
|
|
9
|
+
return [];
|
|
10
|
+
if (declaration.type === 'ClassDeclaration' && declaration.id) {
|
|
11
|
+
const owner = declaration.id.name;
|
|
12
|
+
return declaration.body.body.flatMap((member) => (member.type === 'MethodDefinition' && member.key.type === 'Identifier' && functionTypes.has(member.value.type) ? [{ name: `${owner}.${member.key.name}`, node: member.value }] : []));
|
|
13
|
+
}
|
|
14
|
+
return declaredFunctionsOf(declaration);
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
// Entry handlers join the file's named functions in source order.
|
|
18
|
+
export const namedFunctionsIn = (source, parsed, paths) => {
|
|
19
|
+
const at = locate(source);
|
|
20
|
+
const keyOf = (node) => {
|
|
21
|
+
const { line, column } = at(node.start);
|
|
22
|
+
return `L${line}C${column}`;
|
|
23
|
+
};
|
|
24
|
+
const listed = topLevelFunctionsIn(parsed.program.body);
|
|
25
|
+
const byKey = new Map();
|
|
26
|
+
walk(parsed.program, ({ node }) => {
|
|
27
|
+
if (functionTypes.has(node.type))
|
|
28
|
+
byKey.set(keyOf(node), node);
|
|
29
|
+
});
|
|
30
|
+
const starts = new Set(listed.map(({ node }) => node.start));
|
|
31
|
+
for (const entry of entriesOf(source, parsed, paths)) {
|
|
32
|
+
const node = byKey.get(entry.key);
|
|
33
|
+
if (!node || starts.has(node.start))
|
|
34
|
+
continue;
|
|
35
|
+
const name = entry.kind === 'procedure' || entry.kind === 'tool' ? `${entry.kind}:${entry.name}` : entry.name;
|
|
36
|
+
listed.push({ name, node });
|
|
37
|
+
starts.add(node.start);
|
|
38
|
+
}
|
|
39
|
+
const names = new Set();
|
|
40
|
+
return listed
|
|
41
|
+
.toSorted((a, b) => a.node.start - b.node.start)
|
|
42
|
+
.map(({ name, node }) => {
|
|
43
|
+
const unique = names.has(name) ? `${name} (${keyOf(node)})` : name;
|
|
44
|
+
names.add(unique);
|
|
45
|
+
return { name: unique, node };
|
|
46
|
+
});
|
|
47
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type Node, type Parsed, type Visit } from '../../utils/ast.ts';
|
|
2
|
+
import { type CrushError } from '../../utils/errors.ts';
|
|
3
|
+
import type { Safe } from '../../utils/safe.ts';
|
|
4
|
+
import { type Listener } from '../walk/walk.ts';
|
|
5
|
+
import { type Graph } from './code-paths/analyzer.ts';
|
|
6
|
+
export type { Graph, Segment } from './code-paths/analyzer.ts';
|
|
7
|
+
export type Reference = {
|
|
8
|
+
identifier: Node;
|
|
9
|
+
variable: string;
|
|
10
|
+
definition: Node;
|
|
11
|
+
isRead: boolean;
|
|
12
|
+
isWrite: boolean;
|
|
13
|
+
at: number;
|
|
14
|
+
};
|
|
15
|
+
export type Paths = {
|
|
16
|
+
graphs: Graph[];
|
|
17
|
+
exits: Map<Node, string[]>;
|
|
18
|
+
references: Reference[];
|
|
19
|
+
escaping: Set<string>;
|
|
20
|
+
definitions: Map<string, Node>;
|
|
21
|
+
constants: Set<string>;
|
|
22
|
+
parameters: Set<string>;
|
|
23
|
+
unresolved: Node[];
|
|
24
|
+
};
|
|
25
|
+
export declare const visitListenerOf: (program: Node, onVisit: (visit: Visit) => void) => Listener;
|
|
26
|
+
export declare const pathsOf: (parsed: Parsed, listeners?: readonly Listener[]) => Safe<Paths, CrushError>;
|
|
27
|
+
export declare const referencesOf: (parsed: Parsed, listeners?: readonly Listener[]) => Safe<Pick<Paths, 'references' | 'definitions' | 'parameters' | 'unresolved'>, CrushError>;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { visitorOf } from '../../utils/ast.js';
|
|
2
|
+
import { failed } from '../../utils/errors.js';
|
|
3
|
+
import { noFaults } from '../../utils/faults.js';
|
|
4
|
+
import { walkFile } from '../walk/walk.js';
|
|
5
|
+
import { codePathWalker } from './code-paths/analyzer.js';
|
|
6
|
+
import { resolvedOf, scopeWalker } from './scopes/scopes.js';
|
|
7
|
+
// The walk's runtime nodes, the root left out, are what crush's own walk visits.
|
|
8
|
+
export const visitListenerOf = (program, onVisit) => {
|
|
9
|
+
const visitor = visitorOf(program, onVisit);
|
|
10
|
+
const isVisited = (node, parent, isRuntime) => isRuntime && node !== parent;
|
|
11
|
+
return {
|
|
12
|
+
enter: (node, parent, key, isRuntime) => {
|
|
13
|
+
if (isVisited(node, parent, isRuntime))
|
|
14
|
+
visitor.enter(node, parent, key);
|
|
15
|
+
},
|
|
16
|
+
exit: (node, parent, _key, isRuntime) => {
|
|
17
|
+
if (isVisited(node, parent, isRuntime))
|
|
18
|
+
visitor.exit();
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
// One walk drives the scopes and every listener a caller adds, as the code paths, a visitor or a graph's own collector.
|
|
23
|
+
const scopeFactsOf = (parsed, faults, listeners) => {
|
|
24
|
+
const scopes = scopeWalker(parsed.program);
|
|
25
|
+
walkFile(parsed.program, faults, [scopes, ...listeners]);
|
|
26
|
+
const references = [];
|
|
27
|
+
const escaping = new Set();
|
|
28
|
+
// The node defining each variable, as its import specifier, its declarator or its function declaration, which a call graph resolves a callee by.
|
|
29
|
+
const definitions = new Map();
|
|
30
|
+
// The variables a `const` declares, which hold their first value for good.
|
|
31
|
+
const constants = new Set();
|
|
32
|
+
const parameters = new Set();
|
|
33
|
+
const unresolved = [];
|
|
34
|
+
// Two variables sharing a name in one file, as a `let x` in each of two blocks, are told apart by a count after the first.
|
|
35
|
+
const ids = new Map();
|
|
36
|
+
const counts = new Map();
|
|
37
|
+
const idOf = (variable) => {
|
|
38
|
+
const kept = ids.get(variable);
|
|
39
|
+
if (kept)
|
|
40
|
+
return kept;
|
|
41
|
+
const count = (counts.get(variable.name) ?? 0) + 1;
|
|
42
|
+
counts.set(variable.name, count);
|
|
43
|
+
const id = count === 1 ? variable.name : `${variable.name}:${count}`;
|
|
44
|
+
ids.set(variable, id);
|
|
45
|
+
return id;
|
|
46
|
+
};
|
|
47
|
+
for (const scope of scopes.scopes) {
|
|
48
|
+
for (const reference of scope.references) {
|
|
49
|
+
const resolved = resolvedOf(reference);
|
|
50
|
+
const { identifier } = reference;
|
|
51
|
+
// A built-in global, as `Number` or `undefined`, resolves to no variable the file declares.
|
|
52
|
+
// The walk also reaches types, where a key of `{ url: string }` names a variable it is not, which crush's runtime walk never visits.
|
|
53
|
+
if (!reference.isRuntime)
|
|
54
|
+
continue;
|
|
55
|
+
if (!resolved) {
|
|
56
|
+
if (reference.isRead)
|
|
57
|
+
unresolved.push(identifier);
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
const variable = idOf(resolved);
|
|
61
|
+
const [definition] = resolved.defs;
|
|
62
|
+
definitions.set(variable, definition.node);
|
|
63
|
+
if (definition.type === 'Parameter')
|
|
64
|
+
parameters.add(variable);
|
|
65
|
+
if (definition.kind === 'const')
|
|
66
|
+
constants.add(variable);
|
|
67
|
+
const at = reference.writeExpr ? reference.writeExpr.end : identifier.start;
|
|
68
|
+
references.push({ identifier, variable, definition: definition.node, isRead: reference.isRead, isWrite: reference.isWrite, at });
|
|
69
|
+
if (reference.isWrite && reference.from.variableScope !== resolved.scope.variableScope)
|
|
70
|
+
escaping.add(variable);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return { references, escaping, definitions, constants, parameters, unresolved };
|
|
74
|
+
};
|
|
75
|
+
// The walk also tells each listener of every node, so a caller finds decisions, sites or a graph's nodes without walking the file again.
|
|
76
|
+
export const pathsOf = (parsed, listeners = []) => {
|
|
77
|
+
const paths = codePathWalker(parsed.program);
|
|
78
|
+
const { graphs, exits, faults } = paths;
|
|
79
|
+
const facts = scopeFactsOf(parsed, faults, [paths, ...listeners]);
|
|
80
|
+
if (faults.error)
|
|
81
|
+
return failed(`${parsed.path}: ${faults.error.message}`);
|
|
82
|
+
return { data: { graphs, exits, ...facts }, error: null };
|
|
83
|
+
};
|
|
84
|
+
// The project map keeps this for every file, so the facts it never reads are left out.
|
|
85
|
+
export const referencesOf = (parsed, listeners = []) => {
|
|
86
|
+
const faults = noFaults();
|
|
87
|
+
const { references, definitions, parameters, unresolved } = scopeFactsOf(parsed, faults, listeners);
|
|
88
|
+
if (faults.error)
|
|
89
|
+
return failed(`${parsed.path}: ${faults.error.message}`);
|
|
90
|
+
return { data: { references, definitions, parameters, unresolved }, error: null };
|
|
91
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { Node, Program } from 'oxc-parser';
|
|
2
|
+
import type { NodeOf } from '../../../utils/ast.ts';
|
|
3
|
+
export type ScopeType = 'global' | 'module' | 'function' | 'function-expression-name' | 'class' | 'class-field-initializer' | 'class-static-block' | 'catch' | 'block' | 'for' | 'switch' | 'with';
|
|
4
|
+
export type DefinitionType = 'Variable' | 'Parameter' | 'FunctionName' | 'ClassName' | 'ImportBinding' | 'CatchClause';
|
|
5
|
+
export type Definition = {
|
|
6
|
+
type: DefinitionType;
|
|
7
|
+
name: Node;
|
|
8
|
+
node: Node;
|
|
9
|
+
kind: string | undefined;
|
|
10
|
+
};
|
|
11
|
+
export type Variable = {
|
|
12
|
+
name: string;
|
|
13
|
+
scope: Scope;
|
|
14
|
+
defs: [Definition, ...Definition[]];
|
|
15
|
+
};
|
|
16
|
+
export type Reference = {
|
|
17
|
+
identifier: NodeOf<'Identifier'>;
|
|
18
|
+
from: Scope;
|
|
19
|
+
isRead: boolean;
|
|
20
|
+
isWrite: boolean;
|
|
21
|
+
writeExpr: Node | null;
|
|
22
|
+
isRuntime: boolean;
|
|
23
|
+
};
|
|
24
|
+
export type Scope = {
|
|
25
|
+
type: ScopeType;
|
|
26
|
+
upper: Scope | null;
|
|
27
|
+
variableScope: Scope;
|
|
28
|
+
block: Node;
|
|
29
|
+
bodyStart: number;
|
|
30
|
+
set: Map<string, Variable>;
|
|
31
|
+
references: Reference[];
|
|
32
|
+
};
|
|
33
|
+
export declare const resolvedOf: (reference: Reference) => Variable | null;
|
|
34
|
+
type ScopeWalker = {
|
|
35
|
+
enter: (node: Node, parent: Node, key: string, isRuntime: boolean) => void;
|
|
36
|
+
exit: (node: Node, parent: Node, key: string) => void;
|
|
37
|
+
scopes: Scope[];
|
|
38
|
+
};
|
|
39
|
+
export declare const scopeWalker: (program: Program) => ScopeWalker;
|
|
40
|
+
export {};
|