@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.
Files changed (207) hide show
  1. package/dist/src/alias-chain.js +0 -5
  2. package/dist/src/amd.js +81 -0
  3. package/dist/src/analysis.js +94 -54
  4. package/dist/src/augmentations.js +23 -24
  5. package/dist/src/bindings.js +382 -0
  6. package/dist/src/calls.js +25 -8
  7. package/dist/src/commands/read.js +6 -7
  8. package/dist/src/commands/tools.js +5 -9
  9. package/dist/src/component-files.js +3 -2
  10. package/dist/src/conformance-record.js +1 -1
  11. package/dist/src/consumers.js +9 -10
  12. package/dist/src/contextual-uses.js +1 -17
  13. package/dist/src/contract/config.generated.js +5 -2
  14. package/dist/src/contract/contract.generated.js +119 -2
  15. package/dist/src/contract/report.generated.js +6 -2
  16. package/dist/src/dependencies.js +98 -71
  17. package/dist/src/destructuring.js +1 -19
  18. package/dist/src/element-access.js +179 -164
  19. package/dist/src/entries/build-scripts.js +222 -0
  20. package/dist/src/{configuration-files.js → entries/configuration-files.js} +22 -64
  21. package/dist/src/{convention-rows.js → entries/convention-rows.js} +120 -27
  22. package/dist/src/entries/conventions.js +739 -0
  23. package/dist/src/{html-entries.js → entries/html-entries.js} +9 -12
  24. package/dist/src/{mdx-entries.js → entries/mdx-entries.js} +3 -3
  25. package/dist/src/entries/run-directories.js +77 -0
  26. package/dist/src/entries/sources.js +144 -0
  27. package/dist/src/entries/static-module.js +670 -0
  28. package/dist/src/entries/test-runners.js +684 -0
  29. package/dist/src/{workflow-steps.js → entries/workflow-steps.js} +18 -8
  30. package/dist/src/extensions.js +37 -0
  31. package/dist/src/facts.js +38 -0
  32. package/dist/src/findings/completion.js +40 -4
  33. package/dist/src/findings/emitters.js +5 -8
  34. package/dist/src/{implementations.js → findings/implementations.js} +3 -3
  35. package/dist/src/{in-operands.js → findings/in-operands.js} +2 -2
  36. package/dist/src/findings/self-check.js +36 -20
  37. package/dist/src/findings-pass.js +5 -6
  38. package/dist/src/framework-lifecycle.js +42 -15
  39. package/dist/src/fs/manifest.js +15 -20
  40. package/dist/src/generated-file.js +172 -29
  41. package/dist/src/graph.js +14 -8
  42. package/dist/src/import-bindings.js +73 -28
  43. package/dist/src/index/sites.js +557 -0
  44. package/dist/src/index.js +1 -1
  45. package/dist/src/indexed-access.js +523 -478
  46. package/dist/src/injection-container.js +1 -1
  47. package/dist/src/interface-satisfaction.js +1 -1
  48. package/dist/src/inventory/commonjs.js +62 -17
  49. package/dist/src/inventory/enumerate.js +2 -1
  50. package/dist/src/javascript-file.js +26 -11
  51. package/dist/src/keyof-comparisons.js +124 -103
  52. package/dist/src/load/classify.js +28 -9
  53. package/dist/src/load/diagnostics.js +8 -1
  54. package/dist/src/load/discover.js +15 -7
  55. package/dist/src/load/expected-module.js +2 -2
  56. package/dist/src/load/plan.js +2 -2
  57. package/dist/src/load/specifiers.js +2 -4
  58. package/dist/src/load/synthesize.js +10 -5
  59. package/dist/src/load/workspace-manifests.js +1 -1
  60. package/dist/src/load/workspace-resolution.js +2 -2
  61. package/dist/src/matrix.js +12 -17
  62. package/dist/src/module-declarations.js +70 -85
  63. package/dist/src/overrides.js +134 -112
  64. package/dist/src/paths.js +56 -1
  65. package/dist/src/platform-calls.js +78 -0
  66. package/dist/src/platform-symbols.js +134 -0
  67. package/dist/src/references/read-rule.js +1 -0
  68. package/dist/src/references/read-rules.js +48 -0
  69. package/dist/src/references/sink.js +151 -0
  70. package/dist/src/references/sources.js +450 -0
  71. package/dist/src/references.js +111 -1116
  72. package/dist/src/resolve.js +1 -1
  73. package/dist/src/{configured-declarations.js → roots/configured-declarations.js} +7 -4
  74. package/dist/src/{entry-point-gaps.js → roots/entry-point-gaps.js} +5 -8
  75. package/dist/src/{manifest.js → roots/manifest.js} +4 -4
  76. package/dist/src/roots/published-reach.js +412 -0
  77. package/dist/src/roots/root-set.js +489 -0
  78. package/dist/src/roots/unseen-loads.js +236 -0
  79. package/dist/src/serialization-contract.js +9 -4
  80. package/dist/src/source-files.js +5 -9
  81. package/dist/src/stores.js +4 -2
  82. package/dist/src/suppress.js +30 -32
  83. package/dist/src/sweep.js +25 -13
  84. package/dist/src/symbol-keys.js +89 -83
  85. package/dist/src/tests/file-class.js +76 -0
  86. package/dist/src/{outside-tests.js → tests/outside.js} +7 -7
  87. package/dist/src/{test-support.js → tests/support.js} +5 -12
  88. package/dist/src/type-parameter-reads.js +178 -139
  89. package/dist/src/unimplemented-callees.js +262 -242
  90. package/dist/src/verbs/analyze.js +15 -3
  91. package/dist/src/verbs/describe.js +5 -3
  92. package/dist/src/verbs/explain.js +50 -28
  93. package/dist/src/verbs/print-retained.js +2 -2
  94. package/jsr.json +1 -1
  95. package/package.json +3 -3
  96. package/src/alias-chain.ts +0 -7
  97. package/src/amd.ts +130 -0
  98. package/src/analysis.ts +156 -70
  99. package/src/augmentations.ts +41 -27
  100. package/src/automatic-types.ts +1 -1
  101. package/src/bindings.ts +460 -0
  102. package/src/calls.ts +25 -7
  103. package/src/commands/read.ts +6 -8
  104. package/src/commands/tools.ts +5 -11
  105. package/src/component-files.ts +4 -2
  106. package/src/conformance-record.ts +1 -1
  107. package/src/consumers.ts +12 -11
  108. package/src/contextual-uses.ts +2 -22
  109. package/src/contract/config.generated.ts +5 -2
  110. package/src/contract/contract.generated.ts +138 -2
  111. package/src/contract/report.generated.ts +6 -2
  112. package/src/dependencies.ts +117 -71
  113. package/src/destructuring.ts +1 -31
  114. package/src/element-access.ts +188 -182
  115. package/src/entries/build-scripts.ts +292 -0
  116. package/src/{configuration-files.ts → entries/configuration-files.ts} +33 -82
  117. package/src/{convention-rows.ts → entries/convention-rows.ts} +167 -28
  118. package/src/{conventions.ts → entries/conventions.ts} +349 -523
  119. package/src/{html-entries.ts → entries/html-entries.ts} +19 -18
  120. package/src/{mdx-entries.ts → entries/mdx-entries.ts} +5 -5
  121. package/src/entries/run-directories.ts +108 -0
  122. package/src/entries/sources.ts +266 -0
  123. package/src/entries/static-module.ts +858 -0
  124. package/src/entries/test-runners.ts +868 -0
  125. package/src/{workflow-steps.ts → entries/workflow-steps.ts} +29 -11
  126. package/src/exempt.ts +3 -2
  127. package/src/extensions.ts +45 -0
  128. package/src/facts.ts +46 -0
  129. package/src/file-facts.ts +1 -1
  130. package/src/findings/boundary.ts +2 -0
  131. package/src/findings/completion.ts +43 -4
  132. package/src/findings/emitter.ts +1 -1
  133. package/src/findings/emitters.ts +14 -10
  134. package/src/{implementations.ts → findings/implementations.ts} +4 -4
  135. package/src/{in-operands.ts → findings/in-operands.ts} +3 -3
  136. package/src/findings/self-check.ts +41 -22
  137. package/src/findings/visibility-narrowing.ts +1 -1
  138. package/src/findings-pass.ts +5 -12
  139. package/src/framework-lifecycle.ts +43 -15
  140. package/src/fs/manifest.ts +25 -21
  141. package/src/generated-file.ts +240 -36
  142. package/src/graph.ts +27 -11
  143. package/src/import-bindings.ts +98 -29
  144. package/src/index/sites.ts +781 -0
  145. package/src/index.ts +1 -1
  146. package/src/indexed-access.ts +570 -527
  147. package/src/injection-container.ts +1 -1
  148. package/src/interface-satisfaction.ts +1 -1
  149. package/src/inventory/commonjs.ts +102 -17
  150. package/src/inventory/enumerate.ts +2 -1
  151. package/src/javascript-file.ts +29 -12
  152. package/src/keyof-comparisons.ts +131 -116
  153. package/src/load/classify.ts +49 -13
  154. package/src/load/diagnostics.ts +11 -1
  155. package/src/load/discover.ts +27 -11
  156. package/src/load/expected-module.ts +8 -2
  157. package/src/load/plan.ts +11 -2
  158. package/src/load/specifiers.ts +8 -5
  159. package/src/load/synthesize.ts +12 -6
  160. package/src/load/test-globals.ts +1 -1
  161. package/src/load/workspace-manifests.ts +1 -1
  162. package/src/load/workspace-resolution.ts +9 -2
  163. package/src/load/workspace-run.ts +1 -1
  164. package/src/matrix.ts +13 -17
  165. package/src/module-declarations.ts +74 -98
  166. package/src/overrides.ts +162 -134
  167. package/src/paths.ts +65 -1
  168. package/src/platform-calls.ts +119 -0
  169. package/src/platform-symbols.ts +189 -0
  170. package/src/references/read-rule.ts +60 -0
  171. package/src/references/read-rules.ts +55 -0
  172. package/src/references/sink.ts +213 -0
  173. package/src/references/sources.ts +632 -0
  174. package/src/references.ts +174 -1492
  175. package/src/report.ts +2 -2
  176. package/src/resolve.ts +1 -1
  177. package/src/{configured-declarations.ts → roots/configured-declarations.ts} +10 -7
  178. package/src/{entry-point-gaps.ts → roots/entry-point-gaps.ts} +5 -8
  179. package/src/{manifest.ts → roots/manifest.ts} +5 -5
  180. package/src/roots/published-reach.ts +481 -0
  181. package/src/{roots.ts → roots/root-set.ts} +203 -630
  182. package/src/roots/unseen-loads.ts +345 -0
  183. package/src/serialization-contract.ts +9 -4
  184. package/src/source-files.ts +5 -10
  185. package/src/stores.ts +13 -2
  186. package/src/suppress.ts +48 -33
  187. package/src/sweep.ts +37 -14
  188. package/src/symbol-keys.ts +102 -102
  189. package/src/tests/file-class.ts +118 -0
  190. package/src/{outside-tests.ts → tests/outside.ts} +16 -10
  191. package/src/{test-support.ts → tests/support.ts} +15 -21
  192. package/src/type-parameter-reads.ts +187 -158
  193. package/src/unimplemented-callees.ts +297 -280
  194. package/src/verbs/analyze.ts +19 -5
  195. package/src/verbs/describe.ts +5 -2
  196. package/src/verbs/explain.ts +75 -32
  197. package/src/verbs/print-retained.ts +2 -2
  198. package/dist/src/build-scripts.js +0 -418
  199. package/dist/src/conventions.js +0 -907
  200. package/dist/src/entry-points.js +0 -444
  201. package/dist/src/own-body.js +0 -28
  202. package/dist/src/roots.js +0 -865
  203. package/dist/src/unseen-loads.js +0 -189
  204. package/src/build-scripts.ts +0 -536
  205. package/src/entry-points.ts +0 -584
  206. package/src/own-body.ts +0 -42
  207. package/src/unseen-loads.ts +0 -282
@@ -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, and a
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 value that names no
149
- * class of the target, a class of another program included, passes nothing here.
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]) => [
@@ -1,8 +1,8 @@
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 whatever
4
- * the other two layers make of it; layer 1 parses the string and layer 2 reads each simple
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
 
8
8
  import { joinPath, resolvePath } from "../paths.ts";
@@ -16,6 +16,7 @@ import {
16
16
  type Preload,
17
17
  type Reading,
18
18
  } from "./tools.ts";
19
+ import { APPENDED_EXTENSIONS } from "../extensions.ts";
19
20
 
20
21
  /** One program a read command runs. */
21
22
  interface Run {
@@ -159,9 +160,6 @@ export function readCommands(text: string, dir: string | undefined): CommandRead
159
160
  };
160
161
  }
161
162
 
162
- /** The extensions a runtime or a loader tries after a path written without one. */
163
- const TRIED_EXTENSIONS = [".ts", ".tsx", ".mts", ".cts", ".js", ".jsx", ".mjs", ".cjs"] as const;
164
-
165
163
  /** One file a run loads, as written, and every absolute path it may be at. */
166
164
  interface Load {
167
165
  readonly written: string;
@@ -188,8 +186,8 @@ export function loadsOf(run: Run): readonly Load[] {
188
186
  written: one,
189
187
  paths: [
190
188
  path,
191
- ...TRIED_EXTENSIONS.map((extension) => `${path}${extension}`),
192
- ...TRIED_EXTENSIONS.map((extension) => joinPath(path, `index${extension}`)),
189
+ ...APPENDED_EXTENSIONS.map((extension) => `${path}${extension}`),
190
+ ...APPENDED_EXTENSIONS.map((extension) => joinPath(path, `index${extension}`)),
193
191
  ],
194
192
  }));
195
193
  }
@@ -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 RELATIVE.test(specifier)
124
+ return isPathSpecifier(specifier)
131
125
  ? { path: resolvePath(dir, specifier) }
132
- : SCHEME.test(specifier)
126
+ : hasURLScheme(specifier)
133
127
  ? undefined
134
128
  : { package: specifier };
135
129
  }
136
- if (!RELATIVE.test(specifier) && !SCHEME.test(specifier)) {
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 ((SCHEME.test(specifier) && local === null) || rest.startsWith("//")) {
136
+ if ((hasURLScheme(specifier) && local === null) || rest.startsWith("//")) {
143
137
  return undefined;
144
138
  }
145
139
  const path = urlPath(rest);
@@ -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 (trimmed === "" || trimmed.startsWith("/") || /^[A-Za-z][A-Za-z0-9+.-]*:/u.test(trimmed)) {
470
+ if (!isPathRelativeURL(trimmed)) {
469
471
  return undefined;
470
472
  }
471
- return trimmed.startsWith("./") || trimmed.startsWith("../") ? trimmed : `./${trimmed}`;
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:4a66f7f01b0f1a23cf843b77ef48d762f2dcf486153e665560f107f10b0ea838",
7
+ digest: "sha256:a4ffbc1c2d9dc7903ccbf52af0e1a22094e0b50363f59365f6aa37b9437d3427",
8
8
  },
9
9
  gaps: [],
10
10
  } as const;