@cplieger/deadset-ts 8.0.0-dev.16 → 8.0.0-dev.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/alias-chain.js +0 -5
- package/dist/src/amd.js +81 -0
- package/dist/src/analysis.js +58 -22
- package/dist/src/augmentations.js +23 -24
- package/dist/src/bindings.js +382 -0
- package/dist/src/calls.js +25 -8
- package/dist/src/commands/tools.js +5 -9
- package/dist/src/component-files.js +3 -2
- package/dist/src/conformance-record.js +1 -1
- package/dist/src/consumers.js +6 -9
- package/dist/src/contextual-uses.js +1 -17
- package/dist/src/contract/config.generated.js +4 -1
- package/dist/src/contract/report.generated.js +6 -2
- package/dist/src/dependencies.js +25 -29
- package/dist/src/destructuring.js +1 -19
- package/dist/src/element-access.js +179 -164
- package/dist/src/entries/build-scripts.js +2 -2
- package/dist/src/entries/configuration-files.js +3 -7
- package/dist/src/entries/conventions.js +2 -2
- package/dist/src/entries/html-entries.js +7 -10
- package/dist/src/entries/mdx-entries.js +2 -2
- package/dist/src/entries/static-module.js +2 -1
- package/dist/src/facts.js +4 -4
- package/dist/src/findings/completion.js +40 -4
- package/dist/src/{implementations.js → findings/implementations.js} +3 -3
- package/dist/src/{in-operands.js → findings/in-operands.js} +2 -2
- package/dist/src/framework-lifecycle.js +41 -14
- package/dist/src/graph.js +12 -4
- package/dist/src/import-bindings.js +73 -28
- package/dist/src/index/sites.js +557 -0
- package/dist/src/indexed-access.js +523 -478
- package/dist/src/interface-satisfaction.js +1 -1
- package/dist/src/keyof-comparisons.js +124 -103
- package/dist/src/load/expected-module.js +2 -2
- package/dist/src/load/specifiers.js +2 -4
- package/dist/src/load/synthesize.js +5 -0
- package/dist/src/load/workspace-resolution.js +2 -2
- package/dist/src/matrix.js +6 -4
- package/dist/src/module-declarations.js +70 -85
- package/dist/src/overrides.js +134 -112
- package/dist/src/paths.js +46 -7
- package/dist/src/platform-calls.js +2 -2
- package/dist/src/platform-symbols.js +13 -19
- package/dist/src/references/read-rule.js +1 -0
- package/dist/src/references/read-rules.js +48 -0
- package/dist/src/references/sink.js +151 -0
- package/dist/src/references/sources.js +450 -0
- package/dist/src/references.js +110 -1285
- package/dist/src/roots/configured-declarations.js +3 -0
- package/dist/src/roots/root-set.js +1 -1
- package/dist/src/roots/unseen-loads.js +38 -10
- package/dist/src/serialization-contract.js +8 -3
- package/dist/src/stores.js +4 -2
- package/dist/src/sweep.js +25 -13
- package/dist/src/symbol-keys.js +89 -83
- package/dist/src/tests/file-class.js +76 -0
- package/dist/src/{outside-tests.js → tests/outside.js} +7 -7
- package/dist/src/{test-support.js → tests/support.js} +2 -11
- package/dist/src/type-parameter-reads.js +178 -139
- package/dist/src/unimplemented-callees.js +262 -242
- package/dist/src/verbs/analyze.js +3 -3
- package/dist/src/verbs/explain.js +50 -28
- package/dist/src/verbs/print-retained.js +2 -2
- package/jsr.json +1 -1
- package/package.json +2 -2
- package/src/alias-chain.ts +0 -7
- package/src/amd.ts +130 -0
- package/src/analysis.ts +86 -23
- package/src/augmentations.ts +41 -27
- package/src/bindings.ts +460 -0
- package/src/calls.ts +25 -7
- package/src/commands/tools.ts +5 -11
- package/src/component-files.ts +4 -2
- package/src/conformance-record.ts +1 -1
- package/src/consumers.ts +8 -11
- package/src/contextual-uses.ts +2 -22
- package/src/contract/config.generated.ts +4 -1
- package/src/contract/report.generated.ts +6 -2
- package/src/dependencies.ts +27 -28
- package/src/destructuring.ts +1 -31
- package/src/element-access.ts +188 -182
- package/src/entries/build-scripts.ts +2 -2
- package/src/entries/configuration-files.ts +11 -8
- package/src/entries/conventions.ts +2 -1
- package/src/entries/html-entries.ts +15 -14
- package/src/entries/mdx-entries.ts +2 -2
- package/src/entries/static-module.ts +2 -1
- package/src/facts.ts +5 -3
- package/src/findings/boundary.ts +2 -0
- package/src/findings/completion.ts +43 -4
- package/src/findings/emitter.ts +1 -1
- package/src/{implementations.ts → findings/implementations.ts} +4 -4
- package/src/{in-operands.ts → findings/in-operands.ts} +3 -3
- package/src/framework-lifecycle.ts +42 -14
- package/src/graph.ts +24 -6
- package/src/import-bindings.ts +98 -29
- package/src/index/sites.ts +781 -0
- package/src/indexed-access.ts +570 -527
- package/src/interface-satisfaction.ts +1 -1
- package/src/keyof-comparisons.ts +131 -116
- package/src/load/expected-module.ts +8 -2
- package/src/load/specifiers.ts +8 -5
- package/src/load/synthesize.ts +6 -0
- package/src/load/workspace-resolution.ts +9 -2
- package/src/matrix.ts +6 -3
- package/src/module-declarations.ts +74 -98
- package/src/overrides.ts +162 -134
- package/src/paths.ts +54 -8
- package/src/platform-calls.ts +3 -3
- package/src/platform-symbols.ts +11 -27
- package/src/references/read-rule.ts +60 -0
- package/src/references/read-rules.ts +55 -0
- package/src/references/sink.ts +213 -0
- package/src/references/sources.ts +632 -0
- package/src/references.ts +168 -1733
- package/src/report.ts +1 -1
- package/src/roots/configured-declarations.ts +3 -0
- package/src/roots/root-set.ts +1 -1
- package/src/roots/unseen-loads.ts +49 -11
- package/src/serialization-contract.ts +8 -3
- package/src/stores.ts +13 -2
- package/src/sweep.ts +37 -14
- package/src/symbol-keys.ts +102 -102
- package/src/tests/file-class.ts +118 -0
- package/src/{outside-tests.ts → tests/outside.ts} +16 -10
- package/src/{test-support.ts → tests/support.ts} +9 -20
- package/src/type-parameter-reads.ts +187 -158
- package/src/unimplemented-callees.ts +297 -280
- package/src/verbs/analyze.ts +3 -2
- package/src/verbs/explain.ts +74 -31
- package/src/verbs/print-retained.ts +2 -2
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isBinaryExpression,
|
|
3
|
+
isParenthesizedExpression,
|
|
4
|
+
isPropertyAccessExpression,
|
|
5
|
+
SyntaxKind,
|
|
6
|
+
type Node,
|
|
7
|
+
type SourceFile,
|
|
8
|
+
} from "@typescript/native/ast";
|
|
9
|
+
import { bindingsOf } from "../import-bindings.ts";
|
|
10
|
+
import type { Site } from "../index/sites.ts";
|
|
11
|
+
import { byPosition, renderPosition, type Position } from "../position.ts";
|
|
12
|
+
import type { ConsumerSide, Reference, Resolution, Use } from "../references.ts";
|
|
13
|
+
import { bytewise } from "../text/compare.ts";
|
|
14
|
+
|
|
15
|
+
/** One declaration a use names: `guessed` where only its name answered, `stepped` where an alias chain led to it. */
|
|
16
|
+
export interface Target {
|
|
17
|
+
readonly id: string;
|
|
18
|
+
readonly guessed?: boolean;
|
|
19
|
+
readonly stepped?: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** One write's index among the records, by its file, with the value it stores. */
|
|
23
|
+
interface Valued {
|
|
24
|
+
readonly index: number;
|
|
25
|
+
readonly value: Node;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Where every reference of one pass is made: it renders the position against the side's
|
|
30
|
+
* root, takes the writing file's test class from the file classes, marks a use only a
|
|
31
|
+
* declaration's name answered `guessed` and an alias step's `alias`, tags a consumer's
|
|
32
|
+
* reference with the consumer, and orders the records.
|
|
33
|
+
*/
|
|
34
|
+
export class Sink {
|
|
35
|
+
readonly #root: string;
|
|
36
|
+
readonly #testFile: (file: SourceFile) => boolean;
|
|
37
|
+
readonly #consumer: ConsumerSide | undefined;
|
|
38
|
+
readonly #found: Reference[] = [];
|
|
39
|
+
readonly #valued = new Map<SourceFile, Valued[]>();
|
|
40
|
+
readonly #held = new Set<string>();
|
|
41
|
+
|
|
42
|
+
constructor(
|
|
43
|
+
root: string,
|
|
44
|
+
testFile: (file: SourceFile) => boolean,
|
|
45
|
+
consumer: ConsumerSide | undefined,
|
|
46
|
+
) {
|
|
47
|
+
this.#root = root;
|
|
48
|
+
this.#testFile = testFile;
|
|
49
|
+
this.#consumer = consumer;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Whether a test file wrote one walked file's uses. */
|
|
53
|
+
isTest(file: SourceFile): boolean {
|
|
54
|
+
return this.#testFile(file);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** The position one node of a walked file renders at. */
|
|
58
|
+
position(file: SourceFile, at: Node): Position {
|
|
59
|
+
return renderPosition(file, this.#root, at.getStart());
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Records one use of each target, made by `from` at `at` in `file`. A write that stores
|
|
64
|
+
* `value` is remembered for the import bindings only its values use. A `production` use is
|
|
65
|
+
* production code's whoever writes it.
|
|
66
|
+
*/
|
|
67
|
+
add(
|
|
68
|
+
file: SourceFile,
|
|
69
|
+
at: Node | Position,
|
|
70
|
+
from: string,
|
|
71
|
+
targets: Iterable<Target | string>,
|
|
72
|
+
use: Use,
|
|
73
|
+
via: Resolution,
|
|
74
|
+
value?: Node,
|
|
75
|
+
production = false,
|
|
76
|
+
): void {
|
|
77
|
+
const position = "column" in at ? at : this.position(file, at);
|
|
78
|
+
const test = !production && this.#testFile(file);
|
|
79
|
+
for (const one of targets) {
|
|
80
|
+
const target = typeof one === "string" ? { id: one } : one;
|
|
81
|
+
this.#found.push({
|
|
82
|
+
from,
|
|
83
|
+
to: target.id,
|
|
84
|
+
position,
|
|
85
|
+
use,
|
|
86
|
+
resolution: target.guessed === true ? "by-name" : target.stepped === true ? "alias" : via,
|
|
87
|
+
test,
|
|
88
|
+
...(target.guessed === true ? { guessed: true as const } : {}),
|
|
89
|
+
});
|
|
90
|
+
if (use === "write" && value !== undefined) {
|
|
91
|
+
const valued = this.#valued.get(file) ?? [];
|
|
92
|
+
valued.push({ index: this.#found.length - 1, value });
|
|
93
|
+
this.#valued.set(file, valued);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Holds declarations an unanswered question could have made live, and the one whose read asked it. */
|
|
99
|
+
hold(ids: Iterable<string>): void {
|
|
100
|
+
for (const id of ids) {
|
|
101
|
+
this.#held.add(id);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** The records made so far, before {@link finish} orders them. */
|
|
106
|
+
get made(): readonly Reference[] {
|
|
107
|
+
return this.#found;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Appends records another stage derived from these, rendered already. */
|
|
111
|
+
extend(references: readonly Reference[]): void {
|
|
112
|
+
this.#found.push(...references);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* The records in position order, then the declaration named, the referencing declaration
|
|
117
|
+
* and the use, each write marked with the import bindings only its values use, and the
|
|
118
|
+
* held declarations. `usesOf` gives each walked file's name sites.
|
|
119
|
+
*/
|
|
120
|
+
finish(usesOf: ReadonlyMap<SourceFile, readonly Site[]>): {
|
|
121
|
+
readonly references: readonly Reference[];
|
|
122
|
+
readonly held: readonly string[];
|
|
123
|
+
} {
|
|
124
|
+
const found = this.#found;
|
|
125
|
+
for (const [file, writes] of this.#valued) {
|
|
126
|
+
for (const { index, names } of aloneIn(file, usesOf.get(file) ?? [], writes, found)) {
|
|
127
|
+
const reference = found[index];
|
|
128
|
+
if (reference !== undefined) {
|
|
129
|
+
found[index] = { ...reference, alone: names };
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
found.sort(
|
|
134
|
+
(a, b) =>
|
|
135
|
+
byPosition(a.position, b.position) ||
|
|
136
|
+
bytewise(a.to, b.to) ||
|
|
137
|
+
bytewise(a.from, b.from) ||
|
|
138
|
+
bytewise(a.use, b.use),
|
|
139
|
+
);
|
|
140
|
+
const consumer = this.#consumer;
|
|
141
|
+
return {
|
|
142
|
+
references:
|
|
143
|
+
consumer === undefined
|
|
144
|
+
? found
|
|
145
|
+
: found.map((reference) => ({ ...reference, consumer: consumer.id })),
|
|
146
|
+
held: [...this.#held].sort(bytewise),
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** The value one assignment stores through the name it writes, where it is a plain assignment. */
|
|
152
|
+
export function storedValue(name: Node): Node | undefined {
|
|
153
|
+
let target: Node = name;
|
|
154
|
+
if (isPropertyAccessExpression(name.parent) && name.parent.name === name) {
|
|
155
|
+
target = name.parent;
|
|
156
|
+
}
|
|
157
|
+
while (isParenthesizedExpression(target.parent)) {
|
|
158
|
+
target = target.parent;
|
|
159
|
+
}
|
|
160
|
+
const parent = target.parent;
|
|
161
|
+
return isBinaryExpression(parent) &&
|
|
162
|
+
parent.operatorToken.kind === SyntaxKind.EqualsToken &&
|
|
163
|
+
parent.left === target
|
|
164
|
+
? parent.right
|
|
165
|
+
: undefined;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* The import bindings of one file that only the values written into one declaration
|
|
170
|
+
* use, for each write into it. A binding is named by an identifier that spells its
|
|
171
|
+
* local name and is not the member a property access names.
|
|
172
|
+
*/
|
|
173
|
+
function aloneIn(
|
|
174
|
+
file: SourceFile,
|
|
175
|
+
uses: readonly Site[],
|
|
176
|
+
writes: readonly Valued[],
|
|
177
|
+
found: readonly Reference[],
|
|
178
|
+
): readonly { index: number; names: readonly string[] }[] {
|
|
179
|
+
const bindings = new Set(bindingsOf(file).map((binding) => binding.name.text));
|
|
180
|
+
if (bindings.size === 0) {
|
|
181
|
+
return [];
|
|
182
|
+
}
|
|
183
|
+
const occurrences = new Map<string, Node[]>();
|
|
184
|
+
for (const site of uses) {
|
|
185
|
+
const text = site.node.getText();
|
|
186
|
+
const parent = site.node.parent;
|
|
187
|
+
if (!bindings.has(text) || (isPropertyAccessExpression(parent) && parent.name === site.node)) {
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
if (!occurrences.get(text)?.includes(site.node)) {
|
|
191
|
+
occurrences.set(text, [...(occurrences.get(text) ?? []), site.node]);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
const inside = (node: Node, value: Node): boolean =>
|
|
195
|
+
node.pos >= value.pos && node.end <= value.end;
|
|
196
|
+
const result: { index: number; names: readonly string[] }[] = [];
|
|
197
|
+
for (const write of writes) {
|
|
198
|
+
const to = found[write.index]?.to;
|
|
199
|
+
const sameTarget = writes.filter((one) => found[one.index]?.to === to);
|
|
200
|
+
const names = [...occurrences]
|
|
201
|
+
.filter(
|
|
202
|
+
([, nodes]) =>
|
|
203
|
+
nodes.some((node) => inside(node, write.value)) &&
|
|
204
|
+
nodes.every((node) => sameTarget.some((one) => inside(node, one.value))),
|
|
205
|
+
)
|
|
206
|
+
.map(([name]) => name)
|
|
207
|
+
.sort(bytewise);
|
|
208
|
+
if (names.length > 0) {
|
|
209
|
+
result.push({ index: write.index, names });
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return result;
|
|
213
|
+
}
|