@whaaaley/crush 0.0.0-stage → 0.2.6
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 +51 -0
- package/dist/judge/task-meta.js +3 -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,375 @@
|
|
|
1
|
+
const variableScopeTypes = new Set([
|
|
2
|
+
'global',
|
|
3
|
+
'module',
|
|
4
|
+
'function',
|
|
5
|
+
'class-field-initializer',
|
|
6
|
+
'class-static-block',
|
|
7
|
+
]);
|
|
8
|
+
const functionTypes = new Set([
|
|
9
|
+
'FunctionDeclaration',
|
|
10
|
+
'FunctionExpression',
|
|
11
|
+
'ArrowFunctionExpression',
|
|
12
|
+
]);
|
|
13
|
+
const patternTypes = new Set([
|
|
14
|
+
'Identifier',
|
|
15
|
+
'ObjectPattern',
|
|
16
|
+
'ArrayPattern',
|
|
17
|
+
'SpreadElement',
|
|
18
|
+
'RestElement',
|
|
19
|
+
'AssignmentPattern',
|
|
20
|
+
]);
|
|
21
|
+
const annotatedPatternTypes = new Set([
|
|
22
|
+
'ArrayPattern',
|
|
23
|
+
'RestElement',
|
|
24
|
+
'AssignmentPattern',
|
|
25
|
+
]);
|
|
26
|
+
const none = { kind: 'none' };
|
|
27
|
+
const reading = { isRead: true, isWrite: false };
|
|
28
|
+
const writing = { isRead: false, isWrite: true };
|
|
29
|
+
const updating = { isRead: true, isWrite: true };
|
|
30
|
+
// What a read stores, and an update such as `i++`, whose value the code never spells out.
|
|
31
|
+
const noValue = null;
|
|
32
|
+
// A function scope's defaults never see a name its body declares, so a default reading one looks outside the function.
|
|
33
|
+
const resolvesIn = (scope, reference, variable) => {
|
|
34
|
+
const { bodyStart } = scope;
|
|
35
|
+
const isHidden = reference.identifier.start < bodyStart && variable.defs.every((definition) => definition.name.start > bodyStart);
|
|
36
|
+
return !isHidden;
|
|
37
|
+
};
|
|
38
|
+
// The variable a reference names, from its own scope outward, as eslint-scope resolves it when each scope closes.
|
|
39
|
+
export const resolvedOf = (reference) => {
|
|
40
|
+
const { name } = reference.identifier;
|
|
41
|
+
for (let scope = reference.from; scope; scope = scope.upper) {
|
|
42
|
+
const variable = scope.set.get(name);
|
|
43
|
+
if (variable && resolvesIn(scope, reference, variable))
|
|
44
|
+
return variable;
|
|
45
|
+
// A plain function's own `arguments` is a variable eslint-scope declares with no definition in the file.
|
|
46
|
+
if (name === 'arguments' && scope.type === 'function' && scope.block.type !== 'ArrowFunctionExpression')
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
return null;
|
|
50
|
+
};
|
|
51
|
+
// eslint-scope 9.1.2's referencer, driven by a walk that visits every node by oxc's child keys, entering and leaving each.
|
|
52
|
+
export const scopeWalker = (program) => {
|
|
53
|
+
const modes = [];
|
|
54
|
+
// The pattern each node opened, whose deferred reads are recorded as the walk leaves it.
|
|
55
|
+
const roots = new Map();
|
|
56
|
+
// A for-in or for-of declaration writes its names from the loop's right side once the declaration is done.
|
|
57
|
+
const forWrites = new Map();
|
|
58
|
+
// The value each declared pattern or name is written, by that pattern.
|
|
59
|
+
const inits = new Map();
|
|
60
|
+
// A block's `var` belongs to the variable scope around it, and any other scope to itself.
|
|
61
|
+
const scopeOf = (type, block, upper, around) => {
|
|
62
|
+
const scope = {
|
|
63
|
+
type,
|
|
64
|
+
upper,
|
|
65
|
+
get variableScope() {
|
|
66
|
+
return around ?? scope;
|
|
67
|
+
},
|
|
68
|
+
block,
|
|
69
|
+
bodyStart: 0,
|
|
70
|
+
set: new Map(),
|
|
71
|
+
references: [],
|
|
72
|
+
};
|
|
73
|
+
return scope;
|
|
74
|
+
};
|
|
75
|
+
// The global scope is open from the start, so every node is inside one.
|
|
76
|
+
let current = scopeOf('global', program, null, null);
|
|
77
|
+
const scopes = [current];
|
|
78
|
+
const nest = (type, block) => {
|
|
79
|
+
current = scopeOf(type, block, current, variableScopeTypes.has(type) ? null : current.variableScope);
|
|
80
|
+
scopes.push(current);
|
|
81
|
+
return current;
|
|
82
|
+
};
|
|
83
|
+
const define = (scope, identifier, type, node, kind) => {
|
|
84
|
+
if (identifier.type !== 'Identifier')
|
|
85
|
+
return;
|
|
86
|
+
const { name } = identifier;
|
|
87
|
+
const definition = { type, name: identifier, node, kind };
|
|
88
|
+
const variable = scope.set.get(name);
|
|
89
|
+
if (variable)
|
|
90
|
+
variable.defs.push(definition);
|
|
91
|
+
else
|
|
92
|
+
scope.set.set(name, { name, scope, defs: [definition] });
|
|
93
|
+
};
|
|
94
|
+
let isRuntime;
|
|
95
|
+
const emit = (buffer, identifier, access, writeExpr, isIdentifierRuntime = isRuntime) => {
|
|
96
|
+
// eslint-scope skips a name spelled `super`, as a key in a type, as it skips `this`.
|
|
97
|
+
if (identifier.type !== 'Identifier' || identifier.name === 'super')
|
|
98
|
+
return;
|
|
99
|
+
const reference = { identifier, from: current, isRead: access.isRead, isWrite: access.isWrite, writeExpr, isRuntime: isIdentifierRuntime };
|
|
100
|
+
if (buffer)
|
|
101
|
+
buffer.push(reference);
|
|
102
|
+
else
|
|
103
|
+
reference.from.references.push(reference);
|
|
104
|
+
};
|
|
105
|
+
const openPattern = (node, outer, bind) => {
|
|
106
|
+
const opened = { bind, deferred: [], outer };
|
|
107
|
+
roots.set(node, opened);
|
|
108
|
+
return { kind: 'pattern', root: opened, assignments: [] };
|
|
109
|
+
};
|
|
110
|
+
const writeDefaults = (outer, identifier, assignments) => {
|
|
111
|
+
for (const assignment of assignments)
|
|
112
|
+
emit(outer, identifier, writing, assignment.right);
|
|
113
|
+
};
|
|
114
|
+
// A pattern's defaults and computed keys are read once the pattern's names are bound, as eslint-scope visits its right-hand nodes last.
|
|
115
|
+
const deferredRead = (opened) => ({ kind: 'read', buffer: opened.deferred });
|
|
116
|
+
// A computed member target's object is read after its key, as eslint-scope queues the key first, so the object's references wait apart until the member is left.
|
|
117
|
+
const heldObjects = new Map();
|
|
118
|
+
const patternChildMode = (parent, key, mode) => {
|
|
119
|
+
// eslint-scope's pattern visitor skips the type annotation of a pattern it has a handler for, where an object pattern's falls to its child walk and binds.
|
|
120
|
+
if (key === 'typeAnnotation' && annotatedPatternTypes.has(parent.type))
|
|
121
|
+
return none;
|
|
122
|
+
switch (parent.type) {
|
|
123
|
+
case 'AssignmentPattern':
|
|
124
|
+
if (key === 'left')
|
|
125
|
+
return { ...mode, assignments: [...mode.assignments, parent] };
|
|
126
|
+
return key === 'right' ? deferredRead(mode.root) : none;
|
|
127
|
+
case 'Property':
|
|
128
|
+
if (key === 'value')
|
|
129
|
+
return mode;
|
|
130
|
+
return parent.computed ? deferredRead(mode.root) : none;
|
|
131
|
+
case 'MemberExpression':
|
|
132
|
+
if (key === 'object') {
|
|
133
|
+
const held = [];
|
|
134
|
+
heldObjects.set(parent, { held, into: mode.root.deferred });
|
|
135
|
+
return { kind: 'read', buffer: held };
|
|
136
|
+
}
|
|
137
|
+
return parent.computed ? deferredRead(mode.root) : none;
|
|
138
|
+
// A call in a pattern, as a parameter property's decorator, reads its arguments before what its callee reads, as eslint-scope queues them first.
|
|
139
|
+
case 'CallExpression': {
|
|
140
|
+
if (key === 'arguments')
|
|
141
|
+
return deferredRead(mode.root);
|
|
142
|
+
if (key !== 'callee')
|
|
143
|
+
return none;
|
|
144
|
+
const held = [];
|
|
145
|
+
heldObjects.set(parent, { held, into: mode.root.deferred });
|
|
146
|
+
return { ...mode, root: { ...mode.root, deferred: held } };
|
|
147
|
+
}
|
|
148
|
+
case 'Identifier':
|
|
149
|
+
return none;
|
|
150
|
+
default:
|
|
151
|
+
return mode;
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
// The mode a child takes under code read as eslint-scope's referencer reads it, opening a pattern where names are bound.
|
|
155
|
+
const readChildMode = (node, parent, key, read) => {
|
|
156
|
+
const { buffer } = read;
|
|
157
|
+
switch (parent.type) {
|
|
158
|
+
case 'AssignmentExpression': {
|
|
159
|
+
if (key === 'right')
|
|
160
|
+
return read;
|
|
161
|
+
if (!patternTypes.has(node.type))
|
|
162
|
+
return read;
|
|
163
|
+
const { right } = parent;
|
|
164
|
+
if (parent.operator !== '=') {
|
|
165
|
+
emit(buffer, node, updating, right);
|
|
166
|
+
return none;
|
|
167
|
+
}
|
|
168
|
+
return openPattern(node, buffer, (identifier, assignments) => {
|
|
169
|
+
writeDefaults(buffer, identifier, assignments);
|
|
170
|
+
emit(buffer, identifier, writing, right);
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
case 'CatchClause':
|
|
174
|
+
if (key === 'body')
|
|
175
|
+
return read;
|
|
176
|
+
return openPattern(node, buffer, (identifier, assignments) => {
|
|
177
|
+
define(current, identifier, 'CatchClause', parent);
|
|
178
|
+
writeDefaults(buffer, identifier, assignments);
|
|
179
|
+
});
|
|
180
|
+
case 'UpdateExpression':
|
|
181
|
+
if (!patternTypes.has(node.type))
|
|
182
|
+
return read;
|
|
183
|
+
emit(buffer, node, updating, noValue);
|
|
184
|
+
return none;
|
|
185
|
+
case 'MemberExpression':
|
|
186
|
+
if (key === 'object')
|
|
187
|
+
return read;
|
|
188
|
+
return parent.computed ? read : none;
|
|
189
|
+
case 'Property':
|
|
190
|
+
case 'MethodDefinition':
|
|
191
|
+
case 'PropertyDefinition':
|
|
192
|
+
if (key === 'value')
|
|
193
|
+
return read;
|
|
194
|
+
return key === 'key' && parent.computed ? read : none;
|
|
195
|
+
case 'LabeledStatement':
|
|
196
|
+
case 'ClassDeclaration':
|
|
197
|
+
case 'ClassExpression':
|
|
198
|
+
return key === 'superClass' || key === 'body' ? read : none;
|
|
199
|
+
case 'VariableDeclaration':
|
|
200
|
+
return { kind: 'declarator', declaration: parent, buffer };
|
|
201
|
+
case 'FunctionDeclaration':
|
|
202
|
+
case 'FunctionExpression':
|
|
203
|
+
case 'ArrowFunctionExpression':
|
|
204
|
+
if (key === 'body') {
|
|
205
|
+
current.bodyStart = node.start;
|
|
206
|
+
return read;
|
|
207
|
+
}
|
|
208
|
+
if (key !== 'params')
|
|
209
|
+
return none;
|
|
210
|
+
return openPattern(node, buffer, (identifier, assignments) => {
|
|
211
|
+
define(current, identifier, 'Parameter', parent);
|
|
212
|
+
writeDefaults(buffer, identifier, assignments);
|
|
213
|
+
});
|
|
214
|
+
case 'ForInStatement':
|
|
215
|
+
case 'ForOfStatement': {
|
|
216
|
+
if (key === 'right' || key === 'body')
|
|
217
|
+
return read;
|
|
218
|
+
if (node.type === 'VariableDeclaration') {
|
|
219
|
+
forWrites.set(node, { identifiers: [], right: parent.right });
|
|
220
|
+
return read;
|
|
221
|
+
}
|
|
222
|
+
const { right } = parent;
|
|
223
|
+
return openPattern(node, buffer, (identifier, assignments) => {
|
|
224
|
+
writeDefaults(buffer, identifier, assignments);
|
|
225
|
+
emit(buffer, identifier, writing, right);
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
case 'ExportNamedDeclaration':
|
|
229
|
+
return parent.source ? none : read;
|
|
230
|
+
case 'JSXOpeningElement':
|
|
231
|
+
return key === 'typeArguments' ? none : read;
|
|
232
|
+
case 'ExportSpecifier':
|
|
233
|
+
return key === 'local' ? read : none;
|
|
234
|
+
case 'Identifier':
|
|
235
|
+
case 'MetaProperty':
|
|
236
|
+
case 'BreakStatement':
|
|
237
|
+
case 'ContinueStatement':
|
|
238
|
+
case 'ImportDeclaration':
|
|
239
|
+
case 'ExportAllDeclaration':
|
|
240
|
+
return none;
|
|
241
|
+
default:
|
|
242
|
+
return read;
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
const declaratorChildMode = (node, parent, key, mode) => {
|
|
246
|
+
if (key === 'init')
|
|
247
|
+
return { kind: 'read', buffer: mode.buffer };
|
|
248
|
+
const { declaration } = mode;
|
|
249
|
+
const { kind } = declaration;
|
|
250
|
+
const init = inits.get(node);
|
|
251
|
+
const writes = forWrites.get(declaration);
|
|
252
|
+
return openPattern(node, mode.buffer, (identifier, assignments) => {
|
|
253
|
+
define(kind === 'var' ? current.variableScope : current, identifier, 'Variable', parent, kind);
|
|
254
|
+
writeDefaults(mode.buffer, identifier, assignments);
|
|
255
|
+
if (init)
|
|
256
|
+
emit(mode.buffer, identifier, writing, init);
|
|
257
|
+
writes?.identifiers.push({ identifier, isRuntime });
|
|
258
|
+
});
|
|
259
|
+
};
|
|
260
|
+
const childMode = (node, parent, key) => {
|
|
261
|
+
const above = modes.at(-1);
|
|
262
|
+
if (!above)
|
|
263
|
+
return { kind: 'read', buffer: null };
|
|
264
|
+
if (above.kind === 'none')
|
|
265
|
+
return none;
|
|
266
|
+
if (above.kind === 'pattern')
|
|
267
|
+
return patternChildMode(parent, key, above);
|
|
268
|
+
if (above.kind === 'declarator')
|
|
269
|
+
return declaratorChildMode(node, parent, key, above);
|
|
270
|
+
return readChildMode(node, parent, key, above);
|
|
271
|
+
};
|
|
272
|
+
// The scopes eslint-scope's handlers open as they reach a node, defining the names a function or class declares.
|
|
273
|
+
const open = (node, parent) => {
|
|
274
|
+
switch (node.type) {
|
|
275
|
+
case 'Program':
|
|
276
|
+
nest('module', node);
|
|
277
|
+
return;
|
|
278
|
+
case 'FunctionDeclaration':
|
|
279
|
+
case 'FunctionExpression':
|
|
280
|
+
case 'ArrowFunctionExpression': {
|
|
281
|
+
const { id } = node;
|
|
282
|
+
if (id && node.type === 'FunctionDeclaration')
|
|
283
|
+
define(current, id, 'FunctionName', node);
|
|
284
|
+
if (id && node.type === 'FunctionExpression')
|
|
285
|
+
define(nest('function-expression-name', node), id, 'FunctionName', node);
|
|
286
|
+
nest('function', node);
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
case 'ClassDeclaration':
|
|
290
|
+
case 'ClassExpression': {
|
|
291
|
+
const { id } = node;
|
|
292
|
+
if (id && node.type === 'ClassDeclaration')
|
|
293
|
+
define(current, id, 'ClassName', node);
|
|
294
|
+
const scope = nest('class', node);
|
|
295
|
+
if (id)
|
|
296
|
+
define(scope, id, 'ClassName', node);
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
case 'VariableDeclaration':
|
|
300
|
+
for (const { id, init } of node.declarations)
|
|
301
|
+
inits.set(id, init);
|
|
302
|
+
return;
|
|
303
|
+
case 'StaticBlock':
|
|
304
|
+
nest('class-static-block', node);
|
|
305
|
+
return;
|
|
306
|
+
case 'CatchClause':
|
|
307
|
+
nest('catch', node);
|
|
308
|
+
return;
|
|
309
|
+
case 'BlockStatement':
|
|
310
|
+
if (!functionTypes.has(parent.type))
|
|
311
|
+
nest('block', node);
|
|
312
|
+
return;
|
|
313
|
+
case 'ForStatement': {
|
|
314
|
+
const { init } = node;
|
|
315
|
+
if (init?.type === 'VariableDeclaration' && init.kind !== 'var')
|
|
316
|
+
nest('for', node);
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
case 'ForInStatement':
|
|
320
|
+
case 'ForOfStatement': {
|
|
321
|
+
if (node.left.type === 'VariableDeclaration' && node.left.kind !== 'var')
|
|
322
|
+
nest('for', node);
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
const enter = (node, parent, key, isNodeRuntime) => {
|
|
328
|
+
isRuntime = isNodeRuntime;
|
|
329
|
+
if (node.type === 'ImportSpecifier' || node.type === 'ImportDefaultSpecifier' || node.type === 'ImportNamespaceSpecifier') {
|
|
330
|
+
define(current, node.local, 'ImportBinding', node);
|
|
331
|
+
}
|
|
332
|
+
const mode = childMode(node, parent, key);
|
|
333
|
+
if (mode.kind === 'read') {
|
|
334
|
+
if (parent.type === 'PropertyDefinition' && key === 'value')
|
|
335
|
+
nest('class-field-initializer', node);
|
|
336
|
+
open(node, parent);
|
|
337
|
+
emit(mode.buffer, node, reading, noValue);
|
|
338
|
+
}
|
|
339
|
+
if (mode.kind === 'pattern')
|
|
340
|
+
mode.root.bind(node, mode.assignments);
|
|
341
|
+
modes.push(mode);
|
|
342
|
+
};
|
|
343
|
+
const exit = (node, parent, key) => {
|
|
344
|
+
modes.pop();
|
|
345
|
+
const holding = heldObjects.get(node);
|
|
346
|
+
if (holding) {
|
|
347
|
+
holding.into.push(...holding.held);
|
|
348
|
+
heldObjects.delete(node);
|
|
349
|
+
}
|
|
350
|
+
const opened = roots.get(node);
|
|
351
|
+
if (opened) {
|
|
352
|
+
for (const reference of opened.deferred) {
|
|
353
|
+
if (opened.outer)
|
|
354
|
+
opened.outer.push(reference);
|
|
355
|
+
else
|
|
356
|
+
reference.from.references.push(reference);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
const writes = forWrites.get(node);
|
|
360
|
+
if (writes) {
|
|
361
|
+
const buffer = null;
|
|
362
|
+
for (const { identifier, isRuntime: isIdentifierRuntime } of writes.identifiers) {
|
|
363
|
+
emit(buffer, identifier, writing, writes.right, isIdentifierRuntime);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
while (current.upper && current.block === node)
|
|
367
|
+
current = current.upper;
|
|
368
|
+
// A switch's cases get a scope of their own, opened once its discriminant is read.
|
|
369
|
+
if (key === 'discriminant')
|
|
370
|
+
nest('switch', parent);
|
|
371
|
+
if (parent.type === 'WithStatement' && key === 'object')
|
|
372
|
+
nest('with', parent);
|
|
373
|
+
};
|
|
374
|
+
return { enter, exit, scopes };
|
|
375
|
+
};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { type Node, type Parsed } from '../../utils/ast.ts';
|
|
2
|
+
import type { Reference } from '../cfg/paths.ts';
|
|
3
|
+
import type { Listener } from '../walk/walk.ts';
|
|
4
|
+
type NodeBase = {
|
|
5
|
+
key: string;
|
|
6
|
+
file: string;
|
|
7
|
+
name: string;
|
|
8
|
+
line: number;
|
|
9
|
+
};
|
|
10
|
+
export type SymbolFileNode = NodeBase & {
|
|
11
|
+
kind: 'file';
|
|
12
|
+
parsed: boolean;
|
|
13
|
+
};
|
|
14
|
+
export type SymbolExportNode = NodeBase & {
|
|
15
|
+
kind: 'export';
|
|
16
|
+
bindings: string[];
|
|
17
|
+
isOwn: boolean;
|
|
18
|
+
};
|
|
19
|
+
export type SymbolBindingNode = NodeBase & {
|
|
20
|
+
kind: 'binding';
|
|
21
|
+
owner: string;
|
|
22
|
+
isPattern: boolean;
|
|
23
|
+
alongside: string[];
|
|
24
|
+
};
|
|
25
|
+
export type SymbolFunctionNode = NodeBase & {
|
|
26
|
+
kind: 'function';
|
|
27
|
+
owner: string;
|
|
28
|
+
};
|
|
29
|
+
export type SymbolNamespaceNode = NodeBase & {
|
|
30
|
+
kind: 'namespace';
|
|
31
|
+
};
|
|
32
|
+
export type SymbolNode = SymbolFileNode | SymbolExportNode | SymbolBindingNode | SymbolFunctionNode | SymbolNamespaceNode;
|
|
33
|
+
export type ImportTarget = {
|
|
34
|
+
specifier: string;
|
|
35
|
+
name: string | null;
|
|
36
|
+
} | {
|
|
37
|
+
specifier: string;
|
|
38
|
+
namespace: true;
|
|
39
|
+
};
|
|
40
|
+
export type Target = {
|
|
41
|
+
key: string;
|
|
42
|
+
} | ImportTarget;
|
|
43
|
+
export type FileSymbols = {
|
|
44
|
+
path: string;
|
|
45
|
+
nodes: SymbolNode[];
|
|
46
|
+
edges: {
|
|
47
|
+
from: string;
|
|
48
|
+
to: Target;
|
|
49
|
+
}[];
|
|
50
|
+
stars: string[];
|
|
51
|
+
globs: {
|
|
52
|
+
from: string;
|
|
53
|
+
patterns: string[];
|
|
54
|
+
}[];
|
|
55
|
+
};
|
|
56
|
+
export type FileSymbolsInput = {
|
|
57
|
+
path: string;
|
|
58
|
+
source: string;
|
|
59
|
+
scan: {
|
|
60
|
+
parsed: Parsed;
|
|
61
|
+
references: Reference[];
|
|
62
|
+
definitions: Map<string, Node>;
|
|
63
|
+
parameters: Set<string>;
|
|
64
|
+
unresolved: Node[];
|
|
65
|
+
walked: Walked;
|
|
66
|
+
} | null;
|
|
67
|
+
};
|
|
68
|
+
export declare const fixedTextOf: (node: Node | null | undefined) => string | null;
|
|
69
|
+
export type Walked = {
|
|
70
|
+
parents: Map<Node, Node>;
|
|
71
|
+
owners: Map<Node, string>;
|
|
72
|
+
declarations: Node[];
|
|
73
|
+
functions: Node[];
|
|
74
|
+
reads: Node[];
|
|
75
|
+
};
|
|
76
|
+
export declare const fileWalkOf: (path: string) => {
|
|
77
|
+
walked: Walked;
|
|
78
|
+
listener: Listener;
|
|
79
|
+
};
|
|
80
|
+
export type FileTree = Walked & {
|
|
81
|
+
program: Parsed['program'];
|
|
82
|
+
references: Reference[];
|
|
83
|
+
bindings: Map<Node, string>;
|
|
84
|
+
names: Map<Node, string[]>;
|
|
85
|
+
definitionOf: Map<Node, Node | undefined>;
|
|
86
|
+
unresolved: Node[];
|
|
87
|
+
};
|
|
88
|
+
export declare const fileTreeOf: (path: string, { parsed, references, definitions, parameters, unresolved, walked }: NonNullable<FileSymbolsInput['scan']>) => FileTree;
|
|
89
|
+
export declare const fileSymbolsOf: (path: string, source: string, tree: FileTree | null) => FileSymbols;
|
|
90
|
+
export {};
|