@cplieger/deadset-ts 8.0.0-dev.15 → 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 +94 -54
- 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/read.js +6 -7
- 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 +9 -10
- package/dist/src/contextual-uses.js +1 -17
- package/dist/src/contract/config.generated.js +5 -2
- package/dist/src/contract/contract.generated.js +119 -2
- package/dist/src/contract/report.generated.js +6 -2
- package/dist/src/dependencies.js +98 -71
- package/dist/src/destructuring.js +1 -19
- package/dist/src/element-access.js +179 -164
- package/dist/src/entries/build-scripts.js +222 -0
- package/dist/src/{configuration-files.js → entries/configuration-files.js} +22 -64
- package/dist/src/{convention-rows.js → entries/convention-rows.js} +120 -27
- package/dist/src/entries/conventions.js +739 -0
- package/dist/src/{html-entries.js → entries/html-entries.js} +9 -12
- package/dist/src/{mdx-entries.js → entries/mdx-entries.js} +3 -3
- package/dist/src/entries/run-directories.js +77 -0
- package/dist/src/entries/sources.js +144 -0
- package/dist/src/entries/static-module.js +670 -0
- package/dist/src/entries/test-runners.js +684 -0
- package/dist/src/{workflow-steps.js → entries/workflow-steps.js} +18 -8
- package/dist/src/extensions.js +37 -0
- package/dist/src/facts.js +38 -0
- package/dist/src/findings/completion.js +40 -4
- package/dist/src/findings/emitters.js +5 -8
- 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/findings/self-check.js +36 -20
- package/dist/src/findings-pass.js +5 -6
- package/dist/src/framework-lifecycle.js +42 -15
- package/dist/src/fs/manifest.js +15 -20
- package/dist/src/generated-file.js +172 -29
- package/dist/src/graph.js +14 -8
- package/dist/src/import-bindings.js +73 -28
- package/dist/src/index/sites.js +557 -0
- package/dist/src/index.js +1 -1
- package/dist/src/indexed-access.js +523 -478
- package/dist/src/injection-container.js +1 -1
- package/dist/src/interface-satisfaction.js +1 -1
- package/dist/src/inventory/commonjs.js +62 -17
- package/dist/src/inventory/enumerate.js +2 -1
- package/dist/src/javascript-file.js +26 -11
- package/dist/src/keyof-comparisons.js +124 -103
- package/dist/src/load/classify.js +28 -9
- package/dist/src/load/diagnostics.js +8 -1
- package/dist/src/load/discover.js +15 -7
- package/dist/src/load/expected-module.js +2 -2
- package/dist/src/load/plan.js +2 -2
- package/dist/src/load/specifiers.js +2 -4
- package/dist/src/load/synthesize.js +10 -5
- package/dist/src/load/workspace-manifests.js +1 -1
- package/dist/src/load/workspace-resolution.js +2 -2
- package/dist/src/matrix.js +12 -17
- package/dist/src/module-declarations.js +70 -85
- package/dist/src/overrides.js +134 -112
- package/dist/src/paths.js +56 -1
- package/dist/src/platform-calls.js +78 -0
- package/dist/src/platform-symbols.js +134 -0
- 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 +111 -1116
- package/dist/src/resolve.js +1 -1
- package/dist/src/{configured-declarations.js → roots/configured-declarations.js} +7 -4
- package/dist/src/{entry-point-gaps.js → roots/entry-point-gaps.js} +5 -8
- package/dist/src/{manifest.js → roots/manifest.js} +4 -4
- package/dist/src/roots/published-reach.js +412 -0
- package/dist/src/roots/root-set.js +489 -0
- package/dist/src/roots/unseen-loads.js +236 -0
- package/dist/src/serialization-contract.js +9 -4
- package/dist/src/source-files.js +5 -9
- package/dist/src/stores.js +4 -2
- package/dist/src/suppress.js +30 -32
- 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} +5 -12
- package/dist/src/type-parameter-reads.js +178 -139
- package/dist/src/unimplemented-callees.js +262 -242
- package/dist/src/verbs/analyze.js +15 -3
- package/dist/src/verbs/describe.js +5 -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 +3 -3
- package/src/alias-chain.ts +0 -7
- package/src/amd.ts +130 -0
- package/src/analysis.ts +156 -70
- package/src/augmentations.ts +41 -27
- package/src/automatic-types.ts +1 -1
- package/src/bindings.ts +460 -0
- package/src/calls.ts +25 -7
- package/src/commands/read.ts +6 -8
- 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 +12 -11
- package/src/contextual-uses.ts +2 -22
- package/src/contract/config.generated.ts +5 -2
- package/src/contract/contract.generated.ts +138 -2
- package/src/contract/report.generated.ts +6 -2
- package/src/dependencies.ts +117 -71
- package/src/destructuring.ts +1 -31
- package/src/element-access.ts +188 -182
- package/src/entries/build-scripts.ts +292 -0
- package/src/{configuration-files.ts → entries/configuration-files.ts} +33 -82
- package/src/{convention-rows.ts → entries/convention-rows.ts} +167 -28
- package/src/{conventions.ts → entries/conventions.ts} +349 -523
- package/src/{html-entries.ts → entries/html-entries.ts} +19 -18
- package/src/{mdx-entries.ts → entries/mdx-entries.ts} +5 -5
- package/src/entries/run-directories.ts +108 -0
- package/src/entries/sources.ts +266 -0
- package/src/entries/static-module.ts +858 -0
- package/src/entries/test-runners.ts +868 -0
- package/src/{workflow-steps.ts → entries/workflow-steps.ts} +29 -11
- package/src/exempt.ts +3 -2
- package/src/extensions.ts +45 -0
- package/src/facts.ts +46 -0
- package/src/file-facts.ts +1 -1
- package/src/findings/boundary.ts +2 -0
- package/src/findings/completion.ts +43 -4
- package/src/findings/emitter.ts +1 -1
- package/src/findings/emitters.ts +14 -10
- package/src/{implementations.ts → findings/implementations.ts} +4 -4
- package/src/{in-operands.ts → findings/in-operands.ts} +3 -3
- package/src/findings/self-check.ts +41 -22
- package/src/findings/visibility-narrowing.ts +1 -1
- package/src/findings-pass.ts +5 -12
- package/src/framework-lifecycle.ts +43 -15
- package/src/fs/manifest.ts +25 -21
- package/src/generated-file.ts +240 -36
- package/src/graph.ts +27 -11
- package/src/import-bindings.ts +98 -29
- package/src/index/sites.ts +781 -0
- package/src/index.ts +1 -1
- package/src/indexed-access.ts +570 -527
- package/src/injection-container.ts +1 -1
- package/src/interface-satisfaction.ts +1 -1
- package/src/inventory/commonjs.ts +102 -17
- package/src/inventory/enumerate.ts +2 -1
- package/src/javascript-file.ts +29 -12
- package/src/keyof-comparisons.ts +131 -116
- package/src/load/classify.ts +49 -13
- package/src/load/diagnostics.ts +11 -1
- package/src/load/discover.ts +27 -11
- package/src/load/expected-module.ts +8 -2
- package/src/load/plan.ts +11 -2
- package/src/load/specifiers.ts +8 -5
- package/src/load/synthesize.ts +12 -6
- package/src/load/test-globals.ts +1 -1
- package/src/load/workspace-manifests.ts +1 -1
- package/src/load/workspace-resolution.ts +9 -2
- package/src/load/workspace-run.ts +1 -1
- package/src/matrix.ts +13 -17
- package/src/module-declarations.ts +74 -98
- package/src/overrides.ts +162 -134
- package/src/paths.ts +65 -1
- package/src/platform-calls.ts +119 -0
- package/src/platform-symbols.ts +189 -0
- 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 +174 -1492
- package/src/report.ts +2 -2
- package/src/resolve.ts +1 -1
- package/src/{configured-declarations.ts → roots/configured-declarations.ts} +10 -7
- package/src/{entry-point-gaps.ts → roots/entry-point-gaps.ts} +5 -8
- package/src/{manifest.ts → roots/manifest.ts} +5 -5
- package/src/roots/published-reach.ts +481 -0
- package/src/{roots.ts → roots/root-set.ts} +203 -630
- package/src/roots/unseen-loads.ts +345 -0
- package/src/serialization-contract.ts +9 -4
- package/src/source-files.ts +5 -10
- package/src/stores.ts +13 -2
- package/src/suppress.ts +48 -33
- 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} +15 -21
- package/src/type-parameter-reads.ts +187 -158
- package/src/unimplemented-callees.ts +297 -280
- package/src/verbs/analyze.ts +19 -5
- package/src/verbs/describe.ts +5 -2
- package/src/verbs/explain.ts +75 -32
- package/src/verbs/print-retained.ts +2 -2
- package/dist/src/build-scripts.js +0 -418
- package/dist/src/conventions.js +0 -907
- package/dist/src/entry-points.js +0 -444
- package/dist/src/own-body.js +0 -28
- package/dist/src/roots.js +0 -865
- package/dist/src/unseen-loads.js +0 -189
- package/src/build-scripts.ts +0 -536
- package/src/entry-points.ts +0 -584
- package/src/own-body.ts +0 -42
- package/src/unseen-loads.ts +0 -282
|
@@ -0,0 +1,382 @@
|
|
|
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
|
+
import { isAsExpression, isEnumDeclaration, isIdentifier, isInterfaceDeclaration, isIntersectionTypeNode, isJSDocText, isLiteralTypeNode, isMethodSignatureDeclaration, isObjectLiteralExpression, isParenthesizedTypeNode, isPropertyAssignment, isPropertySignatureDeclaration, isSatisfiesExpression, isStringLiteralLikeNode, isTypeAliasDeclaration, isTypeLiteralNode, isTypeReferenceNode, isUnionTypeNode, isVariableStatement, } from "@typescript/native/ast";
|
|
8
|
+
import { GENERATORS } from "./contract/contract.generated.js";
|
|
9
|
+
import { componentOf, nameNodeOf } from "./inventory.js";
|
|
10
|
+
import { nameComponent, spell } from "./ref.js";
|
|
11
|
+
import { bytewise } from "./text/compare.js";
|
|
12
|
+
/** The `@generated from <kind> <rest>` tags of one node's own documentation, in order. */
|
|
13
|
+
function generatedTags(node) {
|
|
14
|
+
const docs = node.jsDoc ?? [];
|
|
15
|
+
return docs.flatMap((doc) => (doc.tags ?? []).flatMap((tag) => {
|
|
16
|
+
const { tagName, comment } = tag;
|
|
17
|
+
if (tagName === undefined || !isIdentifier(tagName) || tagName.text !== "generated") {
|
|
18
|
+
return [];
|
|
19
|
+
}
|
|
20
|
+
const text = (comment ?? [])
|
|
21
|
+
.map((part) => (isJSDocText(part) ? part.text : ""))
|
|
22
|
+
.join("")
|
|
23
|
+
.trim();
|
|
24
|
+
const found = /^from (\w+(?: value)?):? (.+)$/u.exec(text);
|
|
25
|
+
return found === null ? [] : [{ kind: found[1] ?? "", rest: (found[2] ?? "").trim() }];
|
|
26
|
+
}));
|
|
27
|
+
}
|
|
28
|
+
/** The tag of one kind a node carries, its text after the kind. */
|
|
29
|
+
function tagged(node, kind) {
|
|
30
|
+
return generatedTags(node).find((one) => one.kind === kind)?.rest;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The name a field or an enum value tag declares: the word before ` = <number>`, read
|
|
34
|
+
* before an optional bracketed option list (`= 7 [json_name = "sync"];`).
|
|
35
|
+
*/
|
|
36
|
+
function declaredName(rest) {
|
|
37
|
+
return /(\w+) = \d+(?: \[.*\])?;$/u.exec(rest)?.[1];
|
|
38
|
+
}
|
|
39
|
+
/** The spelled component of one declaration's name, or undefined for a name the grammar cannot spell. */
|
|
40
|
+
function spelledName(node) {
|
|
41
|
+
const component = componentOf(nameNodeOf(node));
|
|
42
|
+
return component === undefined ? undefined : spell(component);
|
|
43
|
+
}
|
|
44
|
+
/** The object type literals one type is or holds as a direct constituent of a union or an intersection. */
|
|
45
|
+
function literalsOf(type) {
|
|
46
|
+
if (type === undefined) {
|
|
47
|
+
return [];
|
|
48
|
+
}
|
|
49
|
+
if (isParenthesizedTypeNode(type)) {
|
|
50
|
+
return literalsOf(type.type);
|
|
51
|
+
}
|
|
52
|
+
if (isUnionTypeNode(type) || isIntersectionTypeNode(type)) {
|
|
53
|
+
return type.types.flatMap((one) => literalsOf(one));
|
|
54
|
+
}
|
|
55
|
+
return isTypeLiteralNode(type) ? [type] : [];
|
|
56
|
+
}
|
|
57
|
+
/** The string literal type one type literal declares for its `case` property, the oneof discriminant. */
|
|
58
|
+
function caseOf(literal) {
|
|
59
|
+
if (!isTypeLiteralNode(literal)) {
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
for (const member of literal.members) {
|
|
63
|
+
if (isPropertySignatureDeclaration(member) &&
|
|
64
|
+
spelledName(member) === "case" &&
|
|
65
|
+
isLiteralTypeNode(member.type) &&
|
|
66
|
+
isStringLiteralLikeNode(member.type.literal)) {
|
|
67
|
+
return member.type.literal.text;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
/** The fields, enum values and oneof constituents of one tagged message or enum, below its fragment. */
|
|
73
|
+
function membersOf(members, fragment, name) {
|
|
74
|
+
return members.flatMap((member) => {
|
|
75
|
+
const spelled = spelledName(member);
|
|
76
|
+
if (spelled === undefined) {
|
|
77
|
+
return [];
|
|
78
|
+
}
|
|
79
|
+
const at = `${fragment}.${spelled}`;
|
|
80
|
+
const field = tagged(member, "field") ?? tagged(member, "enum value");
|
|
81
|
+
const declared = field === undefined ? undefined : declaredName(field);
|
|
82
|
+
if (declared !== undefined) {
|
|
83
|
+
return [{ fragment: at, name: `${name}.${declared}` }];
|
|
84
|
+
}
|
|
85
|
+
if (tagged(member, "oneof") === undefined || !isPropertySignatureDeclaration(member)) {
|
|
86
|
+
return [];
|
|
87
|
+
}
|
|
88
|
+
return literalsOf(member.type).flatMap((constituent) => {
|
|
89
|
+
const discriminant = caseOf(constituent);
|
|
90
|
+
return discriminant === undefined
|
|
91
|
+
? []
|
|
92
|
+
: [
|
|
93
|
+
{
|
|
94
|
+
fragment: `${at}.'${discriminant.replaceAll("\\", "\\\\").replaceAll("'", "\\'")}':case`,
|
|
95
|
+
name: `${name}.${discriminant}`,
|
|
96
|
+
},
|
|
97
|
+
];
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
/** The full name `@generated from <kind> <pkg.Name>` gives, without a trailing comment. */
|
|
102
|
+
function fullName(rest) {
|
|
103
|
+
return rest.split(/\s/u)[0] ?? rest;
|
|
104
|
+
}
|
|
105
|
+
/** The consumers a protoc-gen-es file of row `protoc-gen-es-2` names, as `references-ts.28` reads them. */
|
|
106
|
+
function protobufEsConsumers(file) {
|
|
107
|
+
const found = [];
|
|
108
|
+
const typed = new Map();
|
|
109
|
+
const constants = [];
|
|
110
|
+
for (const statement of file.statements) {
|
|
111
|
+
if (isTypeAliasDeclaration(statement) || isInterfaceDeclaration(statement)) {
|
|
112
|
+
const fragment = spelledName(statement);
|
|
113
|
+
const message = tagged(statement, "message");
|
|
114
|
+
if (fragment === undefined || message === undefined) {
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
const name = fullName(message);
|
|
118
|
+
typed.set(statement.name.text, name);
|
|
119
|
+
found.push({ fragment, name });
|
|
120
|
+
const members = isInterfaceDeclaration(statement)
|
|
121
|
+
? statement.members
|
|
122
|
+
: literalsOf(statement.type).flatMap((one) => (isTypeLiteralNode(one) ? one.members : []));
|
|
123
|
+
found.push(...membersOf(members, fragment, name));
|
|
124
|
+
}
|
|
125
|
+
else if (isEnumDeclaration(statement)) {
|
|
126
|
+
const fragment = spelledName(statement);
|
|
127
|
+
const enumName = tagged(statement, "enum");
|
|
128
|
+
if (fragment === undefined || enumName === undefined) {
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
const name = fullName(enumName);
|
|
132
|
+
typed.set(statement.name.text, name);
|
|
133
|
+
found.push({ fragment, name }, ...membersOf(statement.members, fragment, name));
|
|
134
|
+
}
|
|
135
|
+
else if (isVariableStatement(statement)) {
|
|
136
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
137
|
+
const fragment = spelledName(declaration);
|
|
138
|
+
if (fragment === undefined) {
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
const tags = [...generatedTags(statement), ...generatedTags(declaration)];
|
|
142
|
+
const enumName = tags.find((one) => one.kind === "enum")?.rest;
|
|
143
|
+
const service = tags.find((one) => one.kind === "service")?.rest;
|
|
144
|
+
const initializer = declaration.initializer;
|
|
145
|
+
const object = initializer === undefined ? undefined : asConst(initializer);
|
|
146
|
+
if (enumName !== undefined && object !== undefined && isObjectLiteralExpression(object)) {
|
|
147
|
+
const name = fullName(enumName);
|
|
148
|
+
typed.set(fragment, name);
|
|
149
|
+
found.push({ fragment, name }, ...membersOf(object.properties, fragment, name));
|
|
150
|
+
}
|
|
151
|
+
else if (service !== undefined) {
|
|
152
|
+
found.push({ fragment, name: fullName(service) });
|
|
153
|
+
const [methods] = typeArguments(declaration.type);
|
|
154
|
+
for (const literal of literalsOf(methods)) {
|
|
155
|
+
for (const member of isTypeLiteralNode(literal) ? literal.members : []) {
|
|
156
|
+
const spelled = spelledName(member);
|
|
157
|
+
const rpc = tagged(member, "rpc");
|
|
158
|
+
if (spelled !== undefined && rpc !== undefined) {
|
|
159
|
+
found.push({ fragment: `${fragment}.${spelled}`, name: fullName(rpc) });
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
else if (declaration.type !== undefined) {
|
|
165
|
+
constants.push({ fragment, type: declaration.type, node: declaration });
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
for (const constant of constants) {
|
|
171
|
+
const type = constant.type;
|
|
172
|
+
if (!isTypeReferenceNode(type) || !isIdentifier(type.typeName)) {
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
if (type.typeName.text !== "GenMessage" && type.typeName.text !== "GenEnum") {
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
const [argument] = typeArguments(type);
|
|
179
|
+
const named = argument !== undefined && isTypeReferenceNode(argument) && isIdentifier(argument.typeName)
|
|
180
|
+
? typed.get(argument.typeName.text)
|
|
181
|
+
: undefined;
|
|
182
|
+
if (named !== undefined) {
|
|
183
|
+
found.push({ fragment: constant.fragment, name: named });
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return found;
|
|
187
|
+
}
|
|
188
|
+
/** The expression an `as const` or `satisfies` clause holds, or the expression itself. */
|
|
189
|
+
function asConst(node) {
|
|
190
|
+
return isAsExpression(node) || isSatisfiesExpression(node) ? asConst(node.expression) : node;
|
|
191
|
+
}
|
|
192
|
+
/** The type arguments one type reference writes. */
|
|
193
|
+
function typeArguments(type) {
|
|
194
|
+
return type !== undefined && isTypeReferenceNode(type) ? (type.typeArguments ?? []) : [];
|
|
195
|
+
}
|
|
196
|
+
/** A ts-proto service path literal, split into its service and its method. */
|
|
197
|
+
const SERVICE_PATH = /^\/((?:\w+\.)*\w+)\/(\w+)$/u;
|
|
198
|
+
/**
|
|
199
|
+
* The service and RPC consumers a ts-proto file of row `ts-proto-2` names, as
|
|
200
|
+
* `references-ts.31` reads them: the methods of the interface a `<Svc>ServiceName`
|
|
201
|
+
* constant names, and a definition object whose members write a service `path`, with each
|
|
202
|
+
* member the consumer of its RPC and the object, and the `<Svc>Client` that the same
|
|
203
|
+
* file declares beside it, consumers of the service.
|
|
204
|
+
*/
|
|
205
|
+
function tsProtoConsumers(file) {
|
|
206
|
+
const found = [];
|
|
207
|
+
const interfaces = new Map();
|
|
208
|
+
const clients = new Set();
|
|
209
|
+
for (const statement of file.statements) {
|
|
210
|
+
if (isInterfaceDeclaration(statement)) {
|
|
211
|
+
interfaces.set(statement.name.text, statement.members);
|
|
212
|
+
}
|
|
213
|
+
if (isVariableStatement(statement)) {
|
|
214
|
+
for (const one of statement.declarationList.declarations) {
|
|
215
|
+
if (isIdentifier(one.name)) {
|
|
216
|
+
clients.add(one.name.text);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
for (const statement of file.statements) {
|
|
222
|
+
if (!isVariableStatement(statement)) {
|
|
223
|
+
continue;
|
|
224
|
+
}
|
|
225
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
226
|
+
const { name, initializer } = declaration;
|
|
227
|
+
if (!isIdentifier(name) || initializer === undefined) {
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
230
|
+
if (name.text.endsWith("ServiceName") && isStringLiteralLikeNode(initializer)) {
|
|
231
|
+
const service = name.text.slice(0, -"ServiceName".length);
|
|
232
|
+
for (const member of interfaces.get(service) ?? []) {
|
|
233
|
+
const spelled = spelledName(member);
|
|
234
|
+
if (spelled !== undefined && isMethodSignatureDeclaration(member)) {
|
|
235
|
+
found.push({
|
|
236
|
+
fragment: `${nameComponent(service)}.${spelled}`,
|
|
237
|
+
name: `${initializer.text}.${spelled}`,
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
continue;
|
|
242
|
+
}
|
|
243
|
+
const object = asConst(initializer);
|
|
244
|
+
if (!isObjectLiteralExpression(object)) {
|
|
245
|
+
continue;
|
|
246
|
+
}
|
|
247
|
+
let service;
|
|
248
|
+
for (const property of object.properties) {
|
|
249
|
+
const spelled = spelledName(property);
|
|
250
|
+
const value = isPropertyAssignment(property) ? asConst(property.initializer) : undefined;
|
|
251
|
+
const path = value !== undefined && isObjectLiteralExpression(value)
|
|
252
|
+
? value.properties.find((one) => isPropertyAssignment(one) &&
|
|
253
|
+
spelledName(one) === "path" &&
|
|
254
|
+
isStringLiteralLikeNode(one.initializer))
|
|
255
|
+
: undefined;
|
|
256
|
+
const matched = path !== undefined &&
|
|
257
|
+
isPropertyAssignment(path) &&
|
|
258
|
+
isStringLiteralLikeNode(path.initializer)
|
|
259
|
+
? SERVICE_PATH.exec(path.initializer.text)
|
|
260
|
+
: null;
|
|
261
|
+
if (spelled === undefined || matched === null) {
|
|
262
|
+
continue;
|
|
263
|
+
}
|
|
264
|
+
service = matched[1];
|
|
265
|
+
const rpc = `${matched[1] ?? ""}.${matched[2] ?? ""}`;
|
|
266
|
+
found.push({ fragment: `${nameComponent(name.text)}.${spelled}`, name: rpc });
|
|
267
|
+
const client = `${name.text.replace(/Service$/u, "")}Client`;
|
|
268
|
+
if (interfaces.get(client)?.some((member) => spelledName(member) === spelled) === true) {
|
|
269
|
+
found.push({ fragment: `${nameComponent(client)}.${spelled}`, name: rpc });
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
if (service !== undefined) {
|
|
273
|
+
found.push({ fragment: nameComponent(name.text), name: service });
|
|
274
|
+
const client = `${name.text.replace(/Service$/u, "")}Client`;
|
|
275
|
+
if (interfaces.has(client) || clients.has(client)) {
|
|
276
|
+
found.push({ fragment: nameComponent(client), name: service });
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
return found;
|
|
282
|
+
}
|
|
283
|
+
/** The package `// @generated from file <path> (package <pkg>, ...)` or `protobufPackage` names, `.` for none. */
|
|
284
|
+
function packageOf(file) {
|
|
285
|
+
const header = /^\/\/ @generated from file \S+ \(package ([\w.]+)/mu.exec(file.text)?.[1];
|
|
286
|
+
if (header !== undefined) {
|
|
287
|
+
return header;
|
|
288
|
+
}
|
|
289
|
+
for (const statement of file.statements) {
|
|
290
|
+
if (!isVariableStatement(statement)) {
|
|
291
|
+
continue;
|
|
292
|
+
}
|
|
293
|
+
for (const one of statement.declarationList.declarations) {
|
|
294
|
+
if (isIdentifier(one.name) &&
|
|
295
|
+
one.name.text === "protobufPackage" &&
|
|
296
|
+
one.initializer !== undefined &&
|
|
297
|
+
isStringLiteralLikeNode(one.initializer) &&
|
|
298
|
+
one.initializer.text !== "") {
|
|
299
|
+
return one.initializer.text;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
return ".";
|
|
304
|
+
}
|
|
305
|
+
/** The `proto://` reference of a schema declaration a full name written in package `pkg` names. */
|
|
306
|
+
function schemaRef(pkg, name) {
|
|
307
|
+
const local = pkg !== "." && name.startsWith(`${pkg}.`) ? name.slice(pkg.length + 1) : name;
|
|
308
|
+
return `proto://${pkg}#${local}`;
|
|
309
|
+
}
|
|
310
|
+
/** The consumer reader of each row whose output the analyzer decodes. */
|
|
311
|
+
const CONSUMERS = {
|
|
312
|
+
"protoc-gen-es-2": protobufEsConsumers,
|
|
313
|
+
"ts-proto-2": tsProtoConsumers,
|
|
314
|
+
};
|
|
315
|
+
/** The scope of the fallback record each fallback cell publishes. */
|
|
316
|
+
const FALLBACK_SCOPE = {
|
|
317
|
+
fallback: "all",
|
|
318
|
+
"rpc-types-fallback": "types",
|
|
319
|
+
};
|
|
320
|
+
/**
|
|
321
|
+
* The binding records one project's generated files publish, each file read once:
|
|
322
|
+
* `files` by path below the target root, `moduleRefs` each file's own reference.
|
|
323
|
+
*/
|
|
324
|
+
export function bindingsOf(files, generated, moduleRefs) {
|
|
325
|
+
const records = [];
|
|
326
|
+
for (const [path, fact] of generated) {
|
|
327
|
+
const file = files.get(path);
|
|
328
|
+
const moduleRef = moduleRefs.get(path);
|
|
329
|
+
const generator = fact.generator;
|
|
330
|
+
if (file === undefined || moduleRef === undefined || generator === undefined) {
|
|
331
|
+
continue;
|
|
332
|
+
}
|
|
333
|
+
const [schemaFile] = generator.schemaFiles;
|
|
334
|
+
const cell = GENERATORS.find((row) => row.id === generator.row)?.cell;
|
|
335
|
+
const scope = cell === undefined ? undefined : FALLBACK_SCOPE[cell];
|
|
336
|
+
if (scope !== undefined) {
|
|
337
|
+
for (const one of generator.schemaFiles) {
|
|
338
|
+
records.push({
|
|
339
|
+
role: "fallback",
|
|
340
|
+
symbol: moduleRef,
|
|
341
|
+
schema_file: one,
|
|
342
|
+
generated_file: path,
|
|
343
|
+
scope,
|
|
344
|
+
state: "live",
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
const read = CONSUMERS[generator.row];
|
|
349
|
+
if (read === undefined || schemaFile === undefined) {
|
|
350
|
+
continue;
|
|
351
|
+
}
|
|
352
|
+
const pkg = packageOf(file);
|
|
353
|
+
const seen = new Set();
|
|
354
|
+
for (const named of read(file)) {
|
|
355
|
+
const symbol = `${moduleRef}${named.fragment}`;
|
|
356
|
+
if (seen.has(symbol)) {
|
|
357
|
+
continue;
|
|
358
|
+
}
|
|
359
|
+
seen.add(symbol);
|
|
360
|
+
records.push({
|
|
361
|
+
role: "consumer",
|
|
362
|
+
symbol,
|
|
363
|
+
schema_file: schemaFile,
|
|
364
|
+
schema: schemaRef(pkg, named.name),
|
|
365
|
+
generated_file: path,
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
return records;
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* The records of a run's projects, each once, in the order the facts schema states: by
|
|
373
|
+
* schema file, schema, role and symbol. A generated file two projects hold publishes its
|
|
374
|
+
* records in each.
|
|
375
|
+
*/
|
|
376
|
+
export function distinctBindings(records) {
|
|
377
|
+
const byKey = new Map(records.map((one) => [JSON.stringify(one), one]));
|
|
378
|
+
return [...byKey.values()].sort((a, b) => bytewise(a.schema_file, b.schema_file) ||
|
|
379
|
+
bytewise(a.schema ?? "", b.schema ?? "") ||
|
|
380
|
+
bytewise(a.role, b.role) ||
|
|
381
|
+
bytewise(a.symbol, b.symbol));
|
|
382
|
+
}
|
package/dist/src/calls.js
CHANGED
|
@@ -2,13 +2,14 @@
|
|
|
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
|
-
import { isArrayLiteralExpression, isCallExpression, isClassDeclaration, isDecorator, isIdentifier, isObjectLiteralExpression, isParenthesizedExpression, isPropertyAccessExpression, isPropertyAssignment, isShorthandPropertyAssignment, isSpreadElement, } from "@typescript/native/ast";
|
|
8
|
+
import { isArrayLiteralExpression, isCallExpression, isClassDeclaration, isDecorator, isIdentifier, isObjectLiteralExpression, isParenthesizedExpression, isPropertyAccessExpression, isPropertyAssignment, isShorthandPropertyAssignment, isSpreadElement, isVariableDeclaration, } from "@typescript/native/ast";
|
|
9
9
|
import { SymbolFlags } from "@typescript/native/sync";
|
|
10
10
|
import { nodeKey } from "./inventory.js";
|
|
11
11
|
import { must } from "./query.js";
|
|
12
|
+
import { unwrapped } from "./unwrap.js";
|
|
12
13
|
/** The name node a callee or a decorator expression resolves through, where it has one. */
|
|
13
14
|
export function calleeName(expression) {
|
|
14
15
|
if (isParenthesizedExpression(expression)) {
|
|
@@ -100,21 +101,37 @@ export function valuesPassed(argument) {
|
|
|
100
101
|
return found;
|
|
101
102
|
}
|
|
102
103
|
/**
|
|
103
|
-
* The classes of the target each call passes, by the call. A
|
|
104
|
-
*
|
|
104
|
+
* The classes of the target each call passes, by the call. A name that is no class is
|
|
105
|
+
* followed through the initializer of each variable it declares, so a class bound to a
|
|
106
|
+
* variable first is passed. A value that names no class of the target, a class of
|
|
107
|
+
* another program included, passes nothing here.
|
|
105
108
|
*/
|
|
106
109
|
export function classesPassed(project, held, chains, calls) {
|
|
107
110
|
const passed = new Map(calls.map((call) => [call, call.arguments.flatMap((argument) => valuesPassed(argument))]));
|
|
108
111
|
const all = [...passed.values()].flat();
|
|
109
112
|
const targets = resolvedTargets(project, all.filter((value) => !value.shorthand).map((value) => value.name));
|
|
110
113
|
const classes = new Set(held.symbols.filter((symbol) => symbol.kind === "class").map((symbol) => symbol.id));
|
|
114
|
+
const reached = (symbol, seen) => {
|
|
115
|
+
const ids = chains.declarationsOf(symbol).filter((id) => classes.has(id));
|
|
116
|
+
if (ids.length > 0 || seen.has(symbol.id)) {
|
|
117
|
+
return ids;
|
|
118
|
+
}
|
|
119
|
+
seen.add(symbol.id);
|
|
120
|
+
return symbol.declarations.flatMap((handle) => {
|
|
121
|
+
const node = project.declarationAt(handle)?.node;
|
|
122
|
+
if (node === undefined || !isVariableDeclaration(node) || node.initializer === undefined) {
|
|
123
|
+
return [];
|
|
124
|
+
}
|
|
125
|
+
const name = calleeName(unwrapped(node.initializer));
|
|
126
|
+
const next = name === undefined ? undefined : resolvedTargets(project, [name]).get(name);
|
|
127
|
+
return next === undefined ? [] : reached(next, seen);
|
|
128
|
+
});
|
|
129
|
+
};
|
|
111
130
|
const classesOf = (value) => {
|
|
112
131
|
const symbol = value.shorthand
|
|
113
132
|
? must(project.shorthandValueAt(project.handle(value.name)))
|
|
114
133
|
: targets.get(value.name);
|
|
115
|
-
return symbol === undefined
|
|
116
|
-
? []
|
|
117
|
-
: chains.declarationsOf(symbol).filter((id) => classes.has(id));
|
|
134
|
+
return symbol === undefined ? [] : reached(symbol, new Set());
|
|
118
135
|
};
|
|
119
136
|
return new Map([...passed].map(([call, values]) => [
|
|
120
137
|
call,
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The one reader of every command string the analysis reads. Layer 3, the holding rule
|
|
3
|
-
* `roots.ts` applies through `text/named-files.ts`, reads all of the string's text
|
|
4
|
-
* the other two layers make of it; layer 1 parses the string and layer 2 reads each
|
|
5
|
-
* command a tool's reader understands, and they only add the files and modules it runs.
|
|
3
|
+
* `roots/root-set.ts` applies through `text/named-files.ts`, reads all of the string's text
|
|
4
|
+
* whatever the other two layers make of it; layer 1 parses the string and layer 2 reads each
|
|
5
|
+
* simple command a tool's reader understands, and they only add the files and modules it runs.
|
|
6
6
|
*/
|
|
7
7
|
import { joinPath, resolvePath } from "../paths.js";
|
|
8
8
|
import { shellLine } from "./shell.js";
|
|
9
9
|
import { configurationsOf, preloadTarget, readBuiltin, readTool, } from "./tools.js";
|
|
10
|
+
import { APPENDED_EXTENSIONS } from "../extensions.js";
|
|
10
11
|
/**
|
|
11
12
|
* The outcomes of one pipeline run in `dir`: those of the builtin that is its one member, as
|
|
12
13
|
* `readBuiltin` gives them, a directory the analysis does not know after a part layer 1 does
|
|
@@ -104,8 +105,6 @@ export function readCommands(text, dir) {
|
|
|
104
105
|
held: text,
|
|
105
106
|
};
|
|
106
107
|
}
|
|
107
|
-
/** The extensions a runtime or a loader tries after a path written without one. */
|
|
108
|
-
const TRIED_EXTENSIONS = [".ts", ".tsx", ".mts", ".cts", ".js", ".jsx", ".mjs", ".cjs"];
|
|
109
108
|
/**
|
|
110
109
|
* The files `run` loads: its entry, and each preload written as a path. Each may be at its
|
|
111
110
|
* path, with each extension tried, and as a directory's `index` file.
|
|
@@ -126,8 +125,8 @@ export function loadsOf(run) {
|
|
|
126
125
|
written: one,
|
|
127
126
|
paths: [
|
|
128
127
|
path,
|
|
129
|
-
...
|
|
130
|
-
...
|
|
128
|
+
...APPENDED_EXTENSIONS.map((extension) => `${path}${extension}`),
|
|
129
|
+
...APPENDED_EXTENSIONS.map((extension) => joinPath(path, `index${extension}`)),
|
|
131
130
|
],
|
|
132
131
|
}));
|
|
133
132
|
}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* never guesses: an option it does not handle, or a dynamic word where it needs a value, leaves
|
|
6
6
|
* the command unread.
|
|
7
7
|
*/
|
|
8
|
-
import { resolvePath } from "../paths.js";
|
|
8
|
+
import { hasURLScheme, isPathSpecifier, resolvePath } from "../paths.js";
|
|
9
9
|
/** The options `words` start with, or `undefined` where one is unhandled or a needed word is dynamic. */
|
|
10
10
|
function optionsOf(words, options) {
|
|
11
11
|
const values = new Map();
|
|
@@ -46,10 +46,6 @@ function optionsOf(words, options) {
|
|
|
46
46
|
}
|
|
47
47
|
return { values, at: words.length, ended: false };
|
|
48
48
|
}
|
|
49
|
-
/** A specifier that starts with a URL scheme, `file:` and `node:` among them. */
|
|
50
|
-
const SCHEME = /^[a-z][a-z\d+.-]*:/iu;
|
|
51
|
-
/** A specifier written as a path: `.`, `..`, or one starting `./`, `../` or `/`. */
|
|
52
|
-
const RELATIVE = /^(?:\.{1,2}(?:\/|$)|\/)/u;
|
|
53
49
|
/**
|
|
54
50
|
* The path a URL's path text names, percent-decoded as Node's `fileURLToPath` does, with a
|
|
55
51
|
* backslash read as the URL parser reads it, or `undefined` where it does not decode or
|
|
@@ -76,19 +72,19 @@ function urlPath(text) {
|
|
|
76
72
|
export function preloadTarget(preload, dir) {
|
|
77
73
|
const { specifier, resolution } = preload;
|
|
78
74
|
if (resolution === "require") {
|
|
79
|
-
return
|
|
75
|
+
return isPathSpecifier(specifier)
|
|
80
76
|
? { path: resolvePath(dir, specifier) }
|
|
81
|
-
:
|
|
77
|
+
: hasURLScheme(specifier)
|
|
82
78
|
? undefined
|
|
83
79
|
: { package: specifier };
|
|
84
80
|
}
|
|
85
|
-
if (!
|
|
81
|
+
if (!isPathSpecifier(specifier) && !hasURLScheme(specifier)) {
|
|
86
82
|
return { package: specifier };
|
|
87
83
|
}
|
|
88
84
|
const local = /^file:(?:\/\/(?=\/))?/iu.exec(specifier);
|
|
89
85
|
const rest = specifier.slice(local?.[0].length ?? 0);
|
|
90
86
|
// `file://host/…` names a file on another host.
|
|
91
|
-
if ((
|
|
87
|
+
if ((hasURLScheme(specifier) && local === null) || rest.startsWith("//")) {
|
|
92
88
|
return undefined;
|
|
93
89
|
}
|
|
94
90
|
const path = urlPath(rest);
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* of the module is the same position of the file. A default export and the imports a `src`
|
|
6
6
|
* attribute names are appended past the file's end.
|
|
7
7
|
*/
|
|
8
|
+
import { isPathRelativeURL, startsRelativePath } from "./paths.js";
|
|
8
9
|
const LANGUAGES = new Map([
|
|
9
10
|
["ts", "ts"],
|
|
10
11
|
["tsx", "tsx"],
|
|
@@ -346,10 +347,10 @@ function actionOf(text) {
|
|
|
346
347
|
/** Whether a `src` value names a file: no scheme, no root-relative path, not empty. */
|
|
347
348
|
function specifierOf(value) {
|
|
348
349
|
const trimmed = value.trim();
|
|
349
|
-
if (
|
|
350
|
+
if (!isPathRelativeURL(trimmed)) {
|
|
350
351
|
return undefined;
|
|
351
352
|
}
|
|
352
|
-
return
|
|
353
|
+
return startsRelativePath(trimmed) ? trimmed : `./${trimmed}`;
|
|
353
354
|
}
|
|
354
355
|
/** The line-start `<script` tags one block's content holds. */
|
|
355
356
|
function scriptsInside(text, from, to) {
|
|
@@ -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
|
};
|
package/dist/src/consumers.js
CHANGED
|
@@ -1,22 +1,21 @@
|
|
|
1
|
+
import { runDirectories } from "./entries/run-directories.js";
|
|
1
2
|
import { inventory } from "./inventory/enumerate.js";
|
|
2
3
|
import { relativePath } from "./paths.js";
|
|
3
4
|
import { references } from "./references.js";
|
|
4
5
|
import { narrowedTo } from "./session.js";
|
|
6
|
+
import { patternTestFile } from "./tests/file-class.js";
|
|
5
7
|
/**
|
|
6
8
|
* Every reference one consumer project's own files make to a declaration of the target.
|
|
7
9
|
* The target's declarations are enumerated over the target's files the consumer's
|
|
8
10
|
* program holds, against the target root, so each carries the identifier the target's
|
|
9
|
-
* own projects give it. A reference from a consumer's test file is a test reference
|
|
10
|
-
*
|
|
11
|
+
* own projects give it. A reference from a consumer's test file is a test reference;
|
|
12
|
+
* whether the run counts it as a production one is the sweep's mode.
|
|
11
13
|
*/
|
|
12
|
-
export function consumerReferences(project, host, targetRoot, consumer, config) {
|
|
14
|
+
export function consumerReferences(project, host, targetRoot, consumer, config, parse) {
|
|
13
15
|
const held = inventory(narrowedTo(project, (file) => relativePath(targetRoot, file.fileName) !== undefined), host, targetRoot);
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
return references(project, held, targetRoot, {
|
|
17
|
+
testFile: patternTestFile(config.ts.test_files, consumer.root),
|
|
16
18
|
consumer,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return found;
|
|
20
|
-
}
|
|
21
|
-
return found.map((reference) => (reference.test ? { ...reference, test: false } : reference));
|
|
19
|
+
directories: runDirectories(host, consumer.root, parse),
|
|
20
|
+
});
|
|
22
21
|
}
|