@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
package/src/bindings.ts
ADDED
|
@@ -0,0 +1,460 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The binding identities of the facts document, `bindings.6` and `bindings.7`: the consumer
|
|
3
|
+
* records a generator row's output names, read from the syntax its plugin writes, and the
|
|
4
|
+
* fallback records of the rows that bind a file only as a whole. The run publishes no state,
|
|
5
|
+
* so every record is an identity (`bindings.10`).
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
isAsExpression,
|
|
10
|
+
isEnumDeclaration,
|
|
11
|
+
isIdentifier,
|
|
12
|
+
isInterfaceDeclaration,
|
|
13
|
+
isIntersectionTypeNode,
|
|
14
|
+
isJSDocText,
|
|
15
|
+
isLiteralTypeNode,
|
|
16
|
+
isMethodSignatureDeclaration,
|
|
17
|
+
isObjectLiteralExpression,
|
|
18
|
+
isParenthesizedTypeNode,
|
|
19
|
+
isPropertyAssignment,
|
|
20
|
+
isPropertySignatureDeclaration,
|
|
21
|
+
isSatisfiesExpression,
|
|
22
|
+
isStringLiteralLikeNode,
|
|
23
|
+
isTypeAliasDeclaration,
|
|
24
|
+
isTypeLiteralNode,
|
|
25
|
+
isTypeReferenceNode,
|
|
26
|
+
isUnionTypeNode,
|
|
27
|
+
isVariableStatement,
|
|
28
|
+
type Node,
|
|
29
|
+
type SourceFile,
|
|
30
|
+
} from "@typescript/native/ast";
|
|
31
|
+
import { GENERATORS } from "./contract/contract.generated.ts";
|
|
32
|
+
import type { GeneratedFact } from "./generated-file.ts";
|
|
33
|
+
import { componentOf, nameNodeOf } from "./inventory.ts";
|
|
34
|
+
import { nameComponent, spell } from "./ref.ts";
|
|
35
|
+
import { bytewise } from "./text/compare.ts";
|
|
36
|
+
|
|
37
|
+
/** One binding record of the facts document, as `facts.schema.json` spells it. */
|
|
38
|
+
export interface BindingRecord {
|
|
39
|
+
readonly role: "consumer" | "fallback";
|
|
40
|
+
readonly symbol: string;
|
|
41
|
+
readonly schema_file: string;
|
|
42
|
+
readonly schema?: string;
|
|
43
|
+
readonly generated_file: string;
|
|
44
|
+
readonly scope?: "all" | "types";
|
|
45
|
+
readonly state?: "live";
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** A consumer one output names: the generated declaration's fragment and the schema declaration's dotted name. */
|
|
49
|
+
interface Named {
|
|
50
|
+
readonly fragment: string;
|
|
51
|
+
readonly name: string;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** The `@generated from <kind> <rest>` tags of one node's own documentation, in order. */
|
|
55
|
+
function generatedTags(node: Node): readonly { readonly kind: string; readonly rest: string }[] {
|
|
56
|
+
const docs = (node as { readonly jsDoc?: readonly Node[] }).jsDoc ?? [];
|
|
57
|
+
return docs.flatMap((doc) =>
|
|
58
|
+
((doc as { readonly tags?: readonly Node[] }).tags ?? []).flatMap((tag) => {
|
|
59
|
+
const { tagName, comment } = tag as {
|
|
60
|
+
readonly tagName?: Node;
|
|
61
|
+
readonly comment?: readonly Node[];
|
|
62
|
+
};
|
|
63
|
+
if (tagName === undefined || !isIdentifier(tagName) || tagName.text !== "generated") {
|
|
64
|
+
return [];
|
|
65
|
+
}
|
|
66
|
+
const text = (comment ?? [])
|
|
67
|
+
.map((part) => (isJSDocText(part) ? part.text : ""))
|
|
68
|
+
.join("")
|
|
69
|
+
.trim();
|
|
70
|
+
const found = /^from (\w+(?: value)?):? (.+)$/u.exec(text);
|
|
71
|
+
return found === null ? [] : [{ kind: found[1] ?? "", rest: (found[2] ?? "").trim() }];
|
|
72
|
+
}),
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** The tag of one kind a node carries, its text after the kind. */
|
|
77
|
+
function tagged(node: Node, kind: string): string | undefined {
|
|
78
|
+
return generatedTags(node).find((one) => one.kind === kind)?.rest;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* The name a field or an enum value tag declares: the word before ` = <number>`, read
|
|
83
|
+
* before an optional bracketed option list (`= 7 [json_name = "sync"];`).
|
|
84
|
+
*/
|
|
85
|
+
function declaredName(rest: string): string | undefined {
|
|
86
|
+
return /(\w+) = \d+(?: \[.*\])?;$/u.exec(rest)?.[1];
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** The spelled component of one declaration's name, or undefined for a name the grammar cannot spell. */
|
|
90
|
+
function spelledName(node: Node): string | undefined {
|
|
91
|
+
const component = componentOf(nameNodeOf(node));
|
|
92
|
+
return component === undefined ? undefined : spell(component);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** The object type literals one type is or holds as a direct constituent of a union or an intersection. */
|
|
96
|
+
function literalsOf(type: Node | undefined): readonly Node[] {
|
|
97
|
+
if (type === undefined) {
|
|
98
|
+
return [];
|
|
99
|
+
}
|
|
100
|
+
if (isParenthesizedTypeNode(type)) {
|
|
101
|
+
return literalsOf(type.type);
|
|
102
|
+
}
|
|
103
|
+
if (isUnionTypeNode(type) || isIntersectionTypeNode(type)) {
|
|
104
|
+
return type.types.flatMap((one) => literalsOf(one));
|
|
105
|
+
}
|
|
106
|
+
return isTypeLiteralNode(type) ? [type] : [];
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** The string literal type one type literal declares for its `case` property, the oneof discriminant. */
|
|
110
|
+
function caseOf(literal: Node): string | undefined {
|
|
111
|
+
if (!isTypeLiteralNode(literal)) {
|
|
112
|
+
return undefined;
|
|
113
|
+
}
|
|
114
|
+
for (const member of literal.members) {
|
|
115
|
+
if (
|
|
116
|
+
isPropertySignatureDeclaration(member) &&
|
|
117
|
+
spelledName(member) === "case" &&
|
|
118
|
+
isLiteralTypeNode(member.type) &&
|
|
119
|
+
isStringLiteralLikeNode(member.type.literal)
|
|
120
|
+
) {
|
|
121
|
+
return member.type.literal.text;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return undefined;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** The fields, enum values and oneof constituents of one tagged message or enum, below its fragment. */
|
|
128
|
+
function membersOf(members: readonly Node[], fragment: string, name: string): readonly Named[] {
|
|
129
|
+
return members.flatMap((member): Named[] => {
|
|
130
|
+
const spelled = spelledName(member);
|
|
131
|
+
if (spelled === undefined) {
|
|
132
|
+
return [];
|
|
133
|
+
}
|
|
134
|
+
const at = `${fragment}.${spelled}`;
|
|
135
|
+
const field = tagged(member, "field") ?? tagged(member, "enum value");
|
|
136
|
+
const declared = field === undefined ? undefined : declaredName(field);
|
|
137
|
+
if (declared !== undefined) {
|
|
138
|
+
return [{ fragment: at, name: `${name}.${declared}` }];
|
|
139
|
+
}
|
|
140
|
+
if (tagged(member, "oneof") === undefined || !isPropertySignatureDeclaration(member)) {
|
|
141
|
+
return [];
|
|
142
|
+
}
|
|
143
|
+
return literalsOf(member.type).flatMap((constituent): Named[] => {
|
|
144
|
+
const discriminant = caseOf(constituent);
|
|
145
|
+
return discriminant === undefined
|
|
146
|
+
? []
|
|
147
|
+
: [
|
|
148
|
+
{
|
|
149
|
+
fragment: `${at}.'${discriminant.replaceAll("\\", "\\\\").replaceAll("'", "\\'")}':case`,
|
|
150
|
+
name: `${name}.${discriminant}`,
|
|
151
|
+
},
|
|
152
|
+
];
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** The full name `@generated from <kind> <pkg.Name>` gives, without a trailing comment. */
|
|
158
|
+
function fullName(rest: string): string {
|
|
159
|
+
return rest.split(/\s/u)[0] ?? rest;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** The consumers a protoc-gen-es file of row `protoc-gen-es-2` names, as `references-ts.28` reads them. */
|
|
163
|
+
function protobufEsConsumers(file: SourceFile): readonly Named[] {
|
|
164
|
+
const found: Named[] = [];
|
|
165
|
+
const typed = new Map<string, string>();
|
|
166
|
+
const constants: { readonly fragment: string; readonly type: Node; readonly node: Node }[] = [];
|
|
167
|
+
for (const statement of file.statements) {
|
|
168
|
+
if (isTypeAliasDeclaration(statement) || isInterfaceDeclaration(statement)) {
|
|
169
|
+
const fragment = spelledName(statement);
|
|
170
|
+
const message = tagged(statement, "message");
|
|
171
|
+
if (fragment === undefined || message === undefined) {
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
const name = fullName(message);
|
|
175
|
+
typed.set(statement.name.text, name);
|
|
176
|
+
found.push({ fragment, name });
|
|
177
|
+
const members = isInterfaceDeclaration(statement)
|
|
178
|
+
? statement.members
|
|
179
|
+
: literalsOf(statement.type).flatMap((one) => (isTypeLiteralNode(one) ? one.members : []));
|
|
180
|
+
found.push(...membersOf(members, fragment, name));
|
|
181
|
+
} else if (isEnumDeclaration(statement)) {
|
|
182
|
+
const fragment = spelledName(statement);
|
|
183
|
+
const enumName = tagged(statement, "enum");
|
|
184
|
+
if (fragment === undefined || enumName === undefined) {
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
const name = fullName(enumName);
|
|
188
|
+
typed.set(statement.name.text, name);
|
|
189
|
+
found.push({ fragment, name }, ...membersOf(statement.members, fragment, name));
|
|
190
|
+
} else if (isVariableStatement(statement)) {
|
|
191
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
192
|
+
const fragment = spelledName(declaration);
|
|
193
|
+
if (fragment === undefined) {
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
const tags = [...generatedTags(statement), ...generatedTags(declaration)];
|
|
197
|
+
const enumName = tags.find((one) => one.kind === "enum")?.rest;
|
|
198
|
+
const service = tags.find((one) => one.kind === "service")?.rest;
|
|
199
|
+
const initializer = declaration.initializer;
|
|
200
|
+
const object = initializer === undefined ? undefined : asConst(initializer);
|
|
201
|
+
if (enumName !== undefined && object !== undefined && isObjectLiteralExpression(object)) {
|
|
202
|
+
const name = fullName(enumName);
|
|
203
|
+
typed.set(fragment, name);
|
|
204
|
+
found.push({ fragment, name }, ...membersOf(object.properties, fragment, name));
|
|
205
|
+
} else if (service !== undefined) {
|
|
206
|
+
found.push({ fragment, name: fullName(service) });
|
|
207
|
+
const [methods] = typeArguments(declaration.type);
|
|
208
|
+
for (const literal of literalsOf(methods)) {
|
|
209
|
+
for (const member of isTypeLiteralNode(literal) ? literal.members : []) {
|
|
210
|
+
const spelled = spelledName(member);
|
|
211
|
+
const rpc = tagged(member, "rpc");
|
|
212
|
+
if (spelled !== undefined && rpc !== undefined) {
|
|
213
|
+
found.push({ fragment: `${fragment}.${spelled}`, name: fullName(rpc) });
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
} else if (declaration.type !== undefined) {
|
|
218
|
+
constants.push({ fragment, type: declaration.type, node: declaration });
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
for (const constant of constants) {
|
|
224
|
+
const type = constant.type;
|
|
225
|
+
if (!isTypeReferenceNode(type) || !isIdentifier(type.typeName)) {
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
if (type.typeName.text !== "GenMessage" && type.typeName.text !== "GenEnum") {
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
const [argument] = typeArguments(type);
|
|
232
|
+
const named =
|
|
233
|
+
argument !== undefined && isTypeReferenceNode(argument) && isIdentifier(argument.typeName)
|
|
234
|
+
? typed.get(argument.typeName.text)
|
|
235
|
+
: undefined;
|
|
236
|
+
if (named !== undefined) {
|
|
237
|
+
found.push({ fragment: constant.fragment, name: named });
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
return found;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/** The expression an `as const` or `satisfies` clause holds, or the expression itself. */
|
|
244
|
+
function asConst(node: Node): Node {
|
|
245
|
+
return isAsExpression(node) || isSatisfiesExpression(node) ? asConst(node.expression) : node;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/** The type arguments one type reference writes. */
|
|
249
|
+
function typeArguments(type: Node | undefined): readonly Node[] {
|
|
250
|
+
return type !== undefined && isTypeReferenceNode(type) ? (type.typeArguments ?? []) : [];
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/** A ts-proto service path literal, split into its service and its method. */
|
|
254
|
+
const SERVICE_PATH = /^\/((?:\w+\.)*\w+)\/(\w+)$/u;
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* The service and RPC consumers a ts-proto file of row `ts-proto-2` names, as
|
|
258
|
+
* `references-ts.31` reads them: the methods of the interface a `<Svc>ServiceName`
|
|
259
|
+
* constant names, and a definition object whose members write a service `path`, with each
|
|
260
|
+
* member the consumer of its RPC and the object, and the `<Svc>Client` that the same
|
|
261
|
+
* file declares beside it, consumers of the service.
|
|
262
|
+
*/
|
|
263
|
+
function tsProtoConsumers(file: SourceFile): readonly Named[] {
|
|
264
|
+
const found: Named[] = [];
|
|
265
|
+
const interfaces = new Map<string, readonly Node[]>();
|
|
266
|
+
const clients = new Set<string>();
|
|
267
|
+
for (const statement of file.statements) {
|
|
268
|
+
if (isInterfaceDeclaration(statement)) {
|
|
269
|
+
interfaces.set(statement.name.text, statement.members);
|
|
270
|
+
}
|
|
271
|
+
if (isVariableStatement(statement)) {
|
|
272
|
+
for (const one of statement.declarationList.declarations) {
|
|
273
|
+
if (isIdentifier(one.name)) {
|
|
274
|
+
clients.add(one.name.text);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
for (const statement of file.statements) {
|
|
280
|
+
if (!isVariableStatement(statement)) {
|
|
281
|
+
continue;
|
|
282
|
+
}
|
|
283
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
284
|
+
const { name, initializer } = declaration;
|
|
285
|
+
if (!isIdentifier(name) || initializer === undefined) {
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
288
|
+
if (name.text.endsWith("ServiceName") && isStringLiteralLikeNode(initializer)) {
|
|
289
|
+
const service = name.text.slice(0, -"ServiceName".length);
|
|
290
|
+
for (const member of interfaces.get(service) ?? []) {
|
|
291
|
+
const spelled = spelledName(member);
|
|
292
|
+
if (spelled !== undefined && isMethodSignatureDeclaration(member)) {
|
|
293
|
+
found.push({
|
|
294
|
+
fragment: `${nameComponent(service)}.${spelled}`,
|
|
295
|
+
name: `${initializer.text}.${spelled}`,
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
continue;
|
|
300
|
+
}
|
|
301
|
+
const object = asConst(initializer);
|
|
302
|
+
if (!isObjectLiteralExpression(object)) {
|
|
303
|
+
continue;
|
|
304
|
+
}
|
|
305
|
+
let service: string | undefined;
|
|
306
|
+
for (const property of object.properties) {
|
|
307
|
+
const spelled = spelledName(property);
|
|
308
|
+
const value = isPropertyAssignment(property) ? asConst(property.initializer) : undefined;
|
|
309
|
+
const path =
|
|
310
|
+
value !== undefined && isObjectLiteralExpression(value)
|
|
311
|
+
? value.properties.find(
|
|
312
|
+
(one) =>
|
|
313
|
+
isPropertyAssignment(one) &&
|
|
314
|
+
spelledName(one) === "path" &&
|
|
315
|
+
isStringLiteralLikeNode(one.initializer),
|
|
316
|
+
)
|
|
317
|
+
: undefined;
|
|
318
|
+
const matched =
|
|
319
|
+
path !== undefined &&
|
|
320
|
+
isPropertyAssignment(path) &&
|
|
321
|
+
isStringLiteralLikeNode(path.initializer)
|
|
322
|
+
? SERVICE_PATH.exec(path.initializer.text)
|
|
323
|
+
: null;
|
|
324
|
+
if (spelled === undefined || matched === null) {
|
|
325
|
+
continue;
|
|
326
|
+
}
|
|
327
|
+
service = matched[1];
|
|
328
|
+
const rpc = `${matched[1] ?? ""}.${matched[2] ?? ""}`;
|
|
329
|
+
found.push({ fragment: `${nameComponent(name.text)}.${spelled}`, name: rpc });
|
|
330
|
+
const client = `${name.text.replace(/Service$/u, "")}Client`;
|
|
331
|
+
if (interfaces.get(client)?.some((member) => spelledName(member) === spelled) === true) {
|
|
332
|
+
found.push({ fragment: `${nameComponent(client)}.${spelled}`, name: rpc });
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
if (service !== undefined) {
|
|
336
|
+
found.push({ fragment: nameComponent(name.text), name: service });
|
|
337
|
+
const client = `${name.text.replace(/Service$/u, "")}Client`;
|
|
338
|
+
if (interfaces.has(client) || clients.has(client)) {
|
|
339
|
+
found.push({ fragment: nameComponent(client), name: service });
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
return found;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/** The package `// @generated from file <path> (package <pkg>, ...)` or `protobufPackage` names, `.` for none. */
|
|
348
|
+
function packageOf(file: SourceFile): string {
|
|
349
|
+
const header = /^\/\/ @generated from file \S+ \(package ([\w.]+)/mu.exec(file.text)?.[1];
|
|
350
|
+
if (header !== undefined) {
|
|
351
|
+
return header;
|
|
352
|
+
}
|
|
353
|
+
for (const statement of file.statements) {
|
|
354
|
+
if (!isVariableStatement(statement)) {
|
|
355
|
+
continue;
|
|
356
|
+
}
|
|
357
|
+
for (const one of statement.declarationList.declarations) {
|
|
358
|
+
if (
|
|
359
|
+
isIdentifier(one.name) &&
|
|
360
|
+
one.name.text === "protobufPackage" &&
|
|
361
|
+
one.initializer !== undefined &&
|
|
362
|
+
isStringLiteralLikeNode(one.initializer) &&
|
|
363
|
+
one.initializer.text !== ""
|
|
364
|
+
) {
|
|
365
|
+
return one.initializer.text;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
return ".";
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/** The `proto://` reference of a schema declaration a full name written in package `pkg` names. */
|
|
373
|
+
function schemaRef(pkg: string, name: string): string {
|
|
374
|
+
const local = pkg !== "." && name.startsWith(`${pkg}.`) ? name.slice(pkg.length + 1) : name;
|
|
375
|
+
return `proto://${pkg}#${local}`;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/** The consumer reader of each row whose output the analyzer decodes. */
|
|
379
|
+
const CONSUMERS: Readonly<Record<string, (file: SourceFile) => readonly Named[]>> = {
|
|
380
|
+
"protoc-gen-es-2": protobufEsConsumers,
|
|
381
|
+
"ts-proto-2": tsProtoConsumers,
|
|
382
|
+
};
|
|
383
|
+
|
|
384
|
+
/** The scope of the fallback record each fallback cell publishes. */
|
|
385
|
+
const FALLBACK_SCOPE: Readonly<Record<string, "all" | "types">> = {
|
|
386
|
+
fallback: "all",
|
|
387
|
+
"rpc-types-fallback": "types",
|
|
388
|
+
};
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* The binding records one project's generated files publish, each file read once:
|
|
392
|
+
* `files` by path below the target root, `moduleRefs` each file's own reference.
|
|
393
|
+
*/
|
|
394
|
+
export function bindingsOf(
|
|
395
|
+
files: ReadonlyMap<string, SourceFile>,
|
|
396
|
+
generated: ReadonlyMap<string, GeneratedFact>,
|
|
397
|
+
moduleRefs: ReadonlyMap<string, string>,
|
|
398
|
+
): readonly BindingRecord[] {
|
|
399
|
+
const records: BindingRecord[] = [];
|
|
400
|
+
for (const [path, fact] of generated) {
|
|
401
|
+
const file = files.get(path);
|
|
402
|
+
const moduleRef = moduleRefs.get(path);
|
|
403
|
+
const generator = fact.generator;
|
|
404
|
+
if (file === undefined || moduleRef === undefined || generator === undefined) {
|
|
405
|
+
continue;
|
|
406
|
+
}
|
|
407
|
+
const [schemaFile] = generator.schemaFiles;
|
|
408
|
+
const cell = GENERATORS.find((row) => row.id === generator.row)?.cell;
|
|
409
|
+
const scope = cell === undefined ? undefined : FALLBACK_SCOPE[cell];
|
|
410
|
+
if (scope !== undefined) {
|
|
411
|
+
for (const one of generator.schemaFiles) {
|
|
412
|
+
records.push({
|
|
413
|
+
role: "fallback",
|
|
414
|
+
symbol: moduleRef,
|
|
415
|
+
schema_file: one,
|
|
416
|
+
generated_file: path,
|
|
417
|
+
scope,
|
|
418
|
+
state: "live",
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
const read = CONSUMERS[generator.row];
|
|
423
|
+
if (read === undefined || schemaFile === undefined) {
|
|
424
|
+
continue;
|
|
425
|
+
}
|
|
426
|
+
const pkg = packageOf(file);
|
|
427
|
+
const seen = new Set<string>();
|
|
428
|
+
for (const named of read(file)) {
|
|
429
|
+
const symbol = `${moduleRef}${named.fragment}`;
|
|
430
|
+
if (seen.has(symbol)) {
|
|
431
|
+
continue;
|
|
432
|
+
}
|
|
433
|
+
seen.add(symbol);
|
|
434
|
+
records.push({
|
|
435
|
+
role: "consumer",
|
|
436
|
+
symbol,
|
|
437
|
+
schema_file: schemaFile,
|
|
438
|
+
schema: schemaRef(pkg, named.name),
|
|
439
|
+
generated_file: path,
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
return records;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
/**
|
|
447
|
+
* The records of a run's projects, each once, in the order the facts schema states: by
|
|
448
|
+
* schema file, schema, role and symbol. A generated file two projects hold publishes its
|
|
449
|
+
* records in each.
|
|
450
|
+
*/
|
|
451
|
+
export function distinctBindings(records: readonly BindingRecord[]): readonly BindingRecord[] {
|
|
452
|
+
const byKey = new Map(records.map((one) => [JSON.stringify(one), one]));
|
|
453
|
+
return [...byKey.values()].sort(
|
|
454
|
+
(a, b) =>
|
|
455
|
+
bytewise(a.schema_file, b.schema_file) ||
|
|
456
|
+
bytewise(a.schema ?? "", b.schema ?? "") ||
|
|
457
|
+
bytewise(a.role, b.role) ||
|
|
458
|
+
bytewise(a.symbol, b.symbol),
|
|
459
|
+
);
|
|
460
|
+
}
|
package/src/calls.ts
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* The calls and decorators of one project that the configured classes read: what each
|
|
3
3
|
* callee resolves to, and which of the target's classes a call passes or a decorator
|
|
4
4
|
* is attached to. A class is passed as an argument, or as an element of an array
|
|
5
|
-
* literal or a property value of an object literal written as one, at any depth,
|
|
6
|
-
* decorator written as a call is a call.
|
|
5
|
+
* literal or a property value of an object literal written as one, at any depth, named
|
|
6
|
+
* directly or through variables, and a decorator written as a call is a call.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import {
|
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
isPropertyAssignment,
|
|
19
19
|
isShorthandPropertyAssignment,
|
|
20
20
|
isSpreadElement,
|
|
21
|
+
isVariableDeclaration,
|
|
21
22
|
type CallExpression,
|
|
22
23
|
type Decorator,
|
|
23
24
|
type Expression,
|
|
@@ -28,6 +29,7 @@ import type { AliasChains } from "./alias-chain.ts";
|
|
|
28
29
|
import { nodeKey, type Inventory } from "./inventory.ts";
|
|
29
30
|
import { must } from "./query.ts";
|
|
30
31
|
import type { ProjectView } from "./session.ts";
|
|
32
|
+
import { unwrapped } from "./unwrap.ts";
|
|
31
33
|
|
|
32
34
|
/** One value written where a call passes it, and the node its declaration is resolved from. */
|
|
33
35
|
interface PassedValue {
|
|
@@ -145,8 +147,10 @@ export function valuesPassed(argument: Expression): readonly PassedValue[] {
|
|
|
145
147
|
}
|
|
146
148
|
|
|
147
149
|
/**
|
|
148
|
-
* The classes of the target each call passes, by the call. A
|
|
149
|
-
*
|
|
150
|
+
* The classes of the target each call passes, by the call. A name that is no class is
|
|
151
|
+
* followed through the initializer of each variable it declares, so a class bound to a
|
|
152
|
+
* variable first is passed. A value that names no class of the target, a class of
|
|
153
|
+
* another program included, passes nothing here.
|
|
150
154
|
*/
|
|
151
155
|
export function classesPassed<Brand>(
|
|
152
156
|
project: ProjectView<Brand>,
|
|
@@ -165,13 +169,27 @@ export function classesPassed<Brand>(
|
|
|
165
169
|
const classes = new Set(
|
|
166
170
|
held.symbols.filter((symbol) => symbol.kind === "class").map((symbol) => symbol.id),
|
|
167
171
|
);
|
|
172
|
+
const reached = (symbol: TSSymbol, seen: Set<number>): readonly string[] => {
|
|
173
|
+
const ids = chains.declarationsOf(symbol).filter((id) => classes.has(id));
|
|
174
|
+
if (ids.length > 0 || seen.has(symbol.id)) {
|
|
175
|
+
return ids;
|
|
176
|
+
}
|
|
177
|
+
seen.add(symbol.id);
|
|
178
|
+
return symbol.declarations.flatMap((handle) => {
|
|
179
|
+
const node = project.declarationAt(handle)?.node;
|
|
180
|
+
if (node === undefined || !isVariableDeclaration(node) || node.initializer === undefined) {
|
|
181
|
+
return [];
|
|
182
|
+
}
|
|
183
|
+
const name = calleeName(unwrapped(node.initializer));
|
|
184
|
+
const next = name === undefined ? undefined : resolvedTargets(project, [name]).get(name);
|
|
185
|
+
return next === undefined ? [] : reached(next, seen);
|
|
186
|
+
});
|
|
187
|
+
};
|
|
168
188
|
const classesOf = (value: PassedValue): readonly string[] => {
|
|
169
189
|
const symbol = value.shorthand
|
|
170
190
|
? must(project.shorthandValueAt(project.handle(value.name)))
|
|
171
191
|
: targets.get(value.name);
|
|
172
|
-
return symbol === undefined
|
|
173
|
-
? []
|
|
174
|
-
: chains.declarationsOf(symbol).filter((id) => classes.has(id));
|
|
192
|
+
return symbol === undefined ? [] : reached(symbol, new Set());
|
|
175
193
|
};
|
|
176
194
|
return new Map(
|
|
177
195
|
[...passed].map(([call, values]) => [
|
package/src/commands/tools.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* the command unread.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { resolvePath } from "../paths.ts";
|
|
9
|
+
import { hasURLScheme, isPathSpecifier, resolvePath } from "../paths.ts";
|
|
10
10
|
import type { Word } from "./shell.ts";
|
|
11
11
|
|
|
12
12
|
/** One module a runtime loads before its entry, and the resolution its option names it by. */
|
|
@@ -92,12 +92,6 @@ function optionsOf(words: readonly Word[], options: Options): Read | undefined {
|
|
|
92
92
|
return { values, at: words.length, ended: false };
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
/** A specifier that starts with a URL scheme, `file:` and `node:` among them. */
|
|
96
|
-
const SCHEME = /^[a-z][a-z\d+.-]*:/iu;
|
|
97
|
-
|
|
98
|
-
/** A specifier written as a path: `.`, `..`, or one starting `./`, `../` or `/`. */
|
|
99
|
-
const RELATIVE = /^(?:\.{1,2}(?:\/|$)|\/)/u;
|
|
100
|
-
|
|
101
95
|
/**
|
|
102
96
|
* The path a URL's path text names, percent-decoded as Node's `fileURLToPath` does, with a
|
|
103
97
|
* backslash read as the URL parser reads it, or `undefined` where it does not decode or
|
|
@@ -127,19 +121,19 @@ export function preloadTarget(
|
|
|
127
121
|
): { readonly path: string } | { readonly package: string } | undefined {
|
|
128
122
|
const { specifier, resolution } = preload;
|
|
129
123
|
if (resolution === "require") {
|
|
130
|
-
return
|
|
124
|
+
return isPathSpecifier(specifier)
|
|
131
125
|
? { path: resolvePath(dir, specifier) }
|
|
132
|
-
:
|
|
126
|
+
: hasURLScheme(specifier)
|
|
133
127
|
? undefined
|
|
134
128
|
: { package: specifier };
|
|
135
129
|
}
|
|
136
|
-
if (!
|
|
130
|
+
if (!isPathSpecifier(specifier) && !hasURLScheme(specifier)) {
|
|
137
131
|
return { package: specifier };
|
|
138
132
|
}
|
|
139
133
|
const local = /^file:(?:\/\/(?=\/))?/iu.exec(specifier);
|
|
140
134
|
const rest = specifier.slice(local?.[0].length ?? 0);
|
|
141
135
|
// `file://host/…` names a file on another host.
|
|
142
|
-
if ((
|
|
136
|
+
if ((hasURLScheme(specifier) && local === null) || rest.startsWith("//")) {
|
|
143
137
|
return undefined;
|
|
144
138
|
}
|
|
145
139
|
const path = urlPath(rest);
|
package/src/component-files.ts
CHANGED
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
* attribute names are appended past the file's end.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
+
import { isPathRelativeURL, startsRelativePath } from "./paths.ts";
|
|
10
|
+
|
|
9
11
|
/** The language one block is written in, as the module's virtual extension spells it. */
|
|
10
12
|
type BlockLanguage = "ts" | "tsx" | "js" | "jsx";
|
|
11
13
|
|
|
@@ -465,10 +467,10 @@ function actionOf(text: string): string {
|
|
|
465
467
|
/** Whether a `src` value names a file: no scheme, no root-relative path, not empty. */
|
|
466
468
|
function specifierOf(value: string): string | undefined {
|
|
467
469
|
const trimmed = value.trim();
|
|
468
|
-
if (
|
|
470
|
+
if (!isPathRelativeURL(trimmed)) {
|
|
469
471
|
return undefined;
|
|
470
472
|
}
|
|
471
|
-
return
|
|
473
|
+
return startsRelativePath(trimmed) ? trimmed : `./${trimmed}`;
|
|
472
474
|
}
|
|
473
475
|
|
|
474
476
|
/** The line-start `<script` tags one block's content holds. */
|
|
@@ -4,7 +4,7 @@ export const RECORD = {
|
|
|
4
4
|
conformance: {
|
|
5
5
|
corpusVersion: "6.0.0",
|
|
6
6
|
result: "pass",
|
|
7
|
-
digest: "sha256:
|
|
7
|
+
digest: "sha256:a4ffbc1c2d9dc7903ccbf52af0e1a22094e0b50363f59365f6aa37b9437d3427",
|
|
8
8
|
},
|
|
9
9
|
gaps: [],
|
|
10
10
|
} as const;
|
package/src/consumers.ts
CHANGED
|
@@ -4,15 +4,16 @@ import { runDirectories } from "./entries/run-directories.ts";
|
|
|
4
4
|
import type { Host } from "./host.ts";
|
|
5
5
|
import { inventory } from "./inventory/enumerate.ts";
|
|
6
6
|
import { relativePath } from "./paths.ts";
|
|
7
|
-
import { references, type ConsumerSide, type
|
|
7
|
+
import { references, type ConsumerSide, type References } from "./references.ts";
|
|
8
8
|
import { narrowedTo, type ProjectView } from "./session.ts";
|
|
9
|
+
import { patternTestFile } from "./tests/file-class.ts";
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* Every reference one consumer project's own files make to a declaration of the target.
|
|
12
13
|
* The target's declarations are enumerated over the target's files the consumer's
|
|
13
14
|
* program holds, against the target root, so each carries the identifier the target's
|
|
14
|
-
* own projects give it. A reference from a consumer's test file is a test reference
|
|
15
|
-
*
|
|
15
|
+
* own projects give it. A reference from a consumer's test file is a test reference;
|
|
16
|
+
* whether the run counts it as a production one is the sweep's mode.
|
|
16
17
|
*/
|
|
17
18
|
export function consumerReferences<Brand>(
|
|
18
19
|
project: ProjectView<Brand>,
|
|
@@ -21,19 +22,15 @@ export function consumerReferences<Brand>(
|
|
|
21
22
|
consumer: ConsumerSide,
|
|
22
23
|
config: PartialConfig,
|
|
23
24
|
parse: ParseFile,
|
|
24
|
-
):
|
|
25
|
+
): References {
|
|
25
26
|
const held = inventory(
|
|
26
27
|
narrowedTo(project, (file) => relativePath(targetRoot, file.fileName) !== undefined),
|
|
27
28
|
host,
|
|
28
29
|
targetRoot,
|
|
29
30
|
);
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
return references(project, held, targetRoot, {
|
|
32
|
+
testFile: patternTestFile(config.ts.test_files, consumer.root),
|
|
32
33
|
consumer,
|
|
33
34
|
directories: runDirectories(host, consumer.root, parse),
|
|
34
|
-
})
|
|
35
|
-
if (config.analysis.consumer_tests !== "production") {
|
|
36
|
-
return found;
|
|
37
|
-
}
|
|
38
|
-
return found.map((reference) => (reference.test ? { ...reference, test: false } : reference));
|
|
35
|
+
});
|
|
39
36
|
}
|