@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.
Files changed (131) 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 +58 -22
  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/tools.js +5 -9
  8. package/dist/src/component-files.js +3 -2
  9. package/dist/src/conformance-record.js +1 -1
  10. package/dist/src/consumers.js +6 -9
  11. package/dist/src/contextual-uses.js +1 -17
  12. package/dist/src/contract/config.generated.js +4 -1
  13. package/dist/src/contract/report.generated.js +6 -2
  14. package/dist/src/dependencies.js +25 -29
  15. package/dist/src/destructuring.js +1 -19
  16. package/dist/src/element-access.js +179 -164
  17. package/dist/src/entries/build-scripts.js +2 -2
  18. package/dist/src/entries/configuration-files.js +3 -7
  19. package/dist/src/entries/conventions.js +2 -2
  20. package/dist/src/entries/html-entries.js +7 -10
  21. package/dist/src/entries/mdx-entries.js +2 -2
  22. package/dist/src/entries/static-module.js +2 -1
  23. package/dist/src/facts.js +4 -4
  24. package/dist/src/findings/completion.js +40 -4
  25. package/dist/src/{implementations.js → findings/implementations.js} +3 -3
  26. package/dist/src/{in-operands.js → findings/in-operands.js} +2 -2
  27. package/dist/src/framework-lifecycle.js +41 -14
  28. package/dist/src/graph.js +12 -4
  29. package/dist/src/import-bindings.js +73 -28
  30. package/dist/src/index/sites.js +557 -0
  31. package/dist/src/indexed-access.js +523 -478
  32. package/dist/src/interface-satisfaction.js +1 -1
  33. package/dist/src/keyof-comparisons.js +124 -103
  34. package/dist/src/load/expected-module.js +2 -2
  35. package/dist/src/load/specifiers.js +2 -4
  36. package/dist/src/load/synthesize.js +5 -0
  37. package/dist/src/load/workspace-resolution.js +2 -2
  38. package/dist/src/matrix.js +6 -4
  39. package/dist/src/module-declarations.js +70 -85
  40. package/dist/src/overrides.js +134 -112
  41. package/dist/src/paths.js +46 -7
  42. package/dist/src/platform-calls.js +2 -2
  43. package/dist/src/platform-symbols.js +13 -19
  44. package/dist/src/references/read-rule.js +1 -0
  45. package/dist/src/references/read-rules.js +48 -0
  46. package/dist/src/references/sink.js +151 -0
  47. package/dist/src/references/sources.js +450 -0
  48. package/dist/src/references.js +110 -1285
  49. package/dist/src/roots/configured-declarations.js +3 -0
  50. package/dist/src/roots/root-set.js +1 -1
  51. package/dist/src/roots/unseen-loads.js +38 -10
  52. package/dist/src/serialization-contract.js +8 -3
  53. package/dist/src/stores.js +4 -2
  54. package/dist/src/sweep.js +25 -13
  55. package/dist/src/symbol-keys.js +89 -83
  56. package/dist/src/tests/file-class.js +76 -0
  57. package/dist/src/{outside-tests.js → tests/outside.js} +7 -7
  58. package/dist/src/{test-support.js → tests/support.js} +2 -11
  59. package/dist/src/type-parameter-reads.js +178 -139
  60. package/dist/src/unimplemented-callees.js +262 -242
  61. package/dist/src/verbs/analyze.js +3 -3
  62. package/dist/src/verbs/explain.js +50 -28
  63. package/dist/src/verbs/print-retained.js +2 -2
  64. package/jsr.json +1 -1
  65. package/package.json +2 -2
  66. package/src/alias-chain.ts +0 -7
  67. package/src/amd.ts +130 -0
  68. package/src/analysis.ts +86 -23
  69. package/src/augmentations.ts +41 -27
  70. package/src/bindings.ts +460 -0
  71. package/src/calls.ts +25 -7
  72. package/src/commands/tools.ts +5 -11
  73. package/src/component-files.ts +4 -2
  74. package/src/conformance-record.ts +1 -1
  75. package/src/consumers.ts +8 -11
  76. package/src/contextual-uses.ts +2 -22
  77. package/src/contract/config.generated.ts +4 -1
  78. package/src/contract/report.generated.ts +6 -2
  79. package/src/dependencies.ts +27 -28
  80. package/src/destructuring.ts +1 -31
  81. package/src/element-access.ts +188 -182
  82. package/src/entries/build-scripts.ts +2 -2
  83. package/src/entries/configuration-files.ts +11 -8
  84. package/src/entries/conventions.ts +2 -1
  85. package/src/entries/html-entries.ts +15 -14
  86. package/src/entries/mdx-entries.ts +2 -2
  87. package/src/entries/static-module.ts +2 -1
  88. package/src/facts.ts +5 -3
  89. package/src/findings/boundary.ts +2 -0
  90. package/src/findings/completion.ts +43 -4
  91. package/src/findings/emitter.ts +1 -1
  92. package/src/{implementations.ts → findings/implementations.ts} +4 -4
  93. package/src/{in-operands.ts → findings/in-operands.ts} +3 -3
  94. package/src/framework-lifecycle.ts +42 -14
  95. package/src/graph.ts +24 -6
  96. package/src/import-bindings.ts +98 -29
  97. package/src/index/sites.ts +781 -0
  98. package/src/indexed-access.ts +570 -527
  99. package/src/interface-satisfaction.ts +1 -1
  100. package/src/keyof-comparisons.ts +131 -116
  101. package/src/load/expected-module.ts +8 -2
  102. package/src/load/specifiers.ts +8 -5
  103. package/src/load/synthesize.ts +6 -0
  104. package/src/load/workspace-resolution.ts +9 -2
  105. package/src/matrix.ts +6 -3
  106. package/src/module-declarations.ts +74 -98
  107. package/src/overrides.ts +162 -134
  108. package/src/paths.ts +54 -8
  109. package/src/platform-calls.ts +3 -3
  110. package/src/platform-symbols.ts +11 -27
  111. package/src/references/read-rule.ts +60 -0
  112. package/src/references/read-rules.ts +55 -0
  113. package/src/references/sink.ts +213 -0
  114. package/src/references/sources.ts +632 -0
  115. package/src/references.ts +168 -1733
  116. package/src/report.ts +1 -1
  117. package/src/roots/configured-declarations.ts +3 -0
  118. package/src/roots/root-set.ts +1 -1
  119. package/src/roots/unseen-loads.ts +49 -11
  120. package/src/serialization-contract.ts +8 -3
  121. package/src/stores.ts +13 -2
  122. package/src/sweep.ts +37 -14
  123. package/src/symbol-keys.ts +102 -102
  124. package/src/tests/file-class.ts +118 -0
  125. package/src/{outside-tests.ts → tests/outside.ts} +16 -10
  126. package/src/{test-support.ts → tests/support.ts} +9 -20
  127. package/src/type-parameter-reads.ts +187 -158
  128. package/src/unimplemented-callees.ts +297 -280
  129. package/src/verbs/analyze.ts +3 -2
  130. package/src/verbs/explain.ts +74 -31
  131. package/src/verbs/print-retained.ts +2 -2
@@ -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, 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
- 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 value that names no
104
- * class of the target, a class of another program included, passes nothing here.
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,
@@ -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 RELATIVE.test(specifier)
75
+ return isPathSpecifier(specifier)
80
76
  ? { path: resolvePath(dir, specifier) }
81
- : SCHEME.test(specifier)
77
+ : hasURLScheme(specifier)
82
78
  ? undefined
83
79
  : { package: specifier };
84
80
  }
85
- if (!RELATIVE.test(specifier) && !SCHEME.test(specifier)) {
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 ((SCHEME.test(specifier) && local === null) || rest.startsWith("//")) {
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 (trimmed === "" || trimmed.startsWith("/") || /^[A-Za-z][A-Za-z0-9+.-]*:/u.test(trimmed)) {
350
+ if (!isPathRelativeURL(trimmed)) {
350
351
  return undefined;
351
352
  }
352
- return trimmed.startsWith("./") || trimmed.startsWith("../") ? trimmed : `./${trimmed}`;
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:d8d2a417c5cb9b3829739424d9cfd3bd7b631231d8f420300656f6df86f5a6d1",
7
+ digest: "sha256:a4ffbc1c2d9dc7903ccbf52af0e1a22094e0b50363f59365f6aa37b9437d3427",
8
8
  },
9
9
  gaps: [],
10
10
  };
@@ -3,22 +3,19 @@ import { inventory } from "./inventory/enumerate.js";
3
3
  import { relativePath } from "./paths.js";
4
4
  import { references } from "./references.js";
5
5
  import { narrowedTo } from "./session.js";
6
+ import { patternTestFile } from "./tests/file-class.js";
6
7
  /**
7
8
  * Every reference one consumer project's own files make to a declaration of the target.
8
9
  * The target's declarations are enumerated over the target's files the consumer's
9
10
  * program holds, against the target root, so each carries the identifier the target's
10
- * own projects give it. A reference from a consumer's test file is a test reference
11
- * unless the configuration counts it as a production one.
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.
12
13
  */
13
14
  export function consumerReferences(project, host, targetRoot, consumer, config, parse) {
14
15
  const held = inventory(narrowedTo(project, (file) => relativePath(targetRoot, file.fileName) !== undefined), host, targetRoot);
15
- const found = references(project, held, targetRoot, {
16
- testFiles: config.ts.test_files,
16
+ return references(project, held, targetRoot, {
17
+ testFile: patternTestFile(config.ts.test_files, consumer.root),
17
18
  consumer,
18
19
  directories: runDirectories(host, consumer.root, parse),
19
- }).references;
20
- if (config.analysis.consumer_tests !== "production") {
21
- return found;
22
- }
23
- return found.map((reference) => (reference.test ? { ...reference, test: false } : reference));
20
+ });
24
21
  }
@@ -63,9 +63,6 @@ export function contextualUses(project, held, chains, literals, flows, cap, prop
63
63
  const privateNames = new Set(held.symbols
64
64
  .filter((symbol) => symbol.visibility === "private-name")
65
65
  .map((symbol) => symbol.id));
66
- let batches = 0;
67
- let lookups = 0;
68
- const batchesOf = (count) => Math.ceil(count / cap);
69
66
  const parts = new Map();
70
67
  /** The object types one type is: itself, or its constituents at any depth. */
71
68
  const partsOf = (type) => {
@@ -75,7 +72,6 @@ export function contextualUses(project, held, chains, literals, flows, cap, prop
75
72
  }
76
73
  let found = [];
77
74
  if (type.isUnionType() || type.isIntersectionType()) {
78
- lookups += 1;
79
75
  const constituents = queries.constituents(type);
80
76
  found = isAnswered(constituents) ? constituents.flatMap(partsOf) : [];
81
77
  }
@@ -94,7 +90,6 @@ export function contextualUses(project, held, chains, literals, flows, cap, prop
94
90
  }
95
91
  const table = new Map();
96
92
  const read = properties.of(type);
97
- lookups += read.asked ? 1 : 0;
98
93
  for (const property of isAnswered(read.properties) ? read.properties : []) {
99
94
  table.set(property.name, {
100
95
  ids: chains
@@ -112,7 +107,6 @@ export function contextualUses(project, held, chains, literals, flows, cap, prop
112
107
  return table;
113
108
  };
114
109
  const writes = [];
115
- batches += batchesOf(literals.length);
116
110
  const contexts = queries.contextualTypes(literals.map((one) => one.literal), cap);
117
111
  // A computed name that is not literal text names the property the literal declares
118
112
  // under the checker's own key, which is how a type declares a member a unique symbol
@@ -123,7 +117,6 @@ export function contextualUses(project, held, chains, literals, flows, cap, prop
123
117
  const name = propertyName(property);
124
118
  return name !== undefined && name.text === undefined ? [name.node] : [];
125
119
  }));
126
- batches += batchesOf(computed.length);
127
120
  const keys = new Map();
128
121
  (computed.length === 0
129
122
  ? []
@@ -152,7 +145,6 @@ export function contextualUses(project, held, chains, literals, flows, cap, prop
152
145
  }
153
146
  });
154
147
  const carried = flows.filter((flow) => !isObjectLiteralExpression(flow.value));
155
- batches += batchesOf(carried.length);
156
148
  const types = queries.typesAt(carried.map((flow) => flow.value), cap);
157
149
  /** The members a position may read structurally: those of object types, not of classes. */
158
150
  const readable = (member) => [
@@ -198,11 +190,9 @@ export function contextualUses(project, held, chains, literals, flows, cap, prop
198
190
  if (elements.has(type.id)) {
199
191
  return elements.get(type.id);
200
192
  }
201
- lookups += 1;
202
193
  const isArray = queries.isArray(type);
203
194
  let element;
204
195
  if (isAnswered(isArray) && isArray) {
205
- lookups += 1;
206
196
  const held = queries.typeArguments(type);
207
197
  element = isAnswered(held) ? held[0] : undefined;
208
198
  }
@@ -216,7 +206,6 @@ export function contextualUses(project, held, chains, literals, flows, cap, prop
216
206
  if (known !== undefined) {
217
207
  return known;
218
208
  }
219
- lookups += type.isTypeReference() ? 1 : 0;
220
209
  const held = queries.typeArguments(type);
221
210
  const found = isAnswered(held) ? held : [];
222
211
  argumentsOf.set(type.id, found);
@@ -232,18 +221,15 @@ export function contextualUses(project, held, chains, literals, flows, cap, prop
232
221
  if (known !== undefined) {
233
222
  return known;
234
223
  }
235
- lookups += 1;
236
224
  let kind = SignatureKind.Call;
237
225
  let signatures = queries.signaturesOf(type, kind);
238
226
  if (isAnswered(signatures) && signatures.length === 0) {
239
- lookups += 1;
240
227
  kind = SignatureKind.Construct;
241
228
  signatures = queries.signaturesOf(type, kind);
242
229
  }
243
230
  const called = (isAnswered(signatures) ? signatures : []).map((signature) => {
244
231
  const parameters = signature.parameters.map((_parameter, index) => queries.parameterType(signature, index));
245
232
  const result = queries.returnTypeOf(signature);
246
- lookups += parameters.length + 1;
247
233
  return {
248
234
  kind,
249
235
  parameters: parameters.map((one) => (isAnswered(one) ? one : undefined)),
@@ -335,7 +321,6 @@ export function contextualUses(project, held, chains, literals, flows, cap, prop
335
321
  const type = types[index];
336
322
  return type === undefined || !isAnswered(type) || !mayCarry(type) ? [] : [{ flow, type }];
337
323
  });
338
- batches += batchesOf(sourced.length);
339
324
  const positions = queries.contextualTypes(sourced.map((one) => one.flow.value), cap);
340
325
  const reads = [];
341
326
  // A literal property writes a position's members once, however many values carry it there.
@@ -408,7 +393,6 @@ export function contextualUses(project, held, chains, literals, flows, cap, prop
408
393
  return known;
409
394
  };
410
395
  const spreads = literals.flatMap(({ literal, from }) => literal.properties.flatMap((property) => isSpreadAssignment(property) ? [{ value: property.expression, from }] : []));
411
- batches += batchesOf(spreads.length);
412
396
  const spreadTypes = queries.typesAt(spreads.map((one) => one.value), cap);
413
397
  spreads.forEach(({ value, from }, index) => {
414
398
  const type = spreadTypes[index];
@@ -426,5 +410,5 @@ export function contextualUses(project, held, chains, literals, flows, cap, prop
426
410
  reads.push({ at: value, from, ids });
427
411
  }
428
412
  });
429
- return { writes, reads, batches, lookups };
413
+ return { writes, reads };
430
414
  }
@@ -483,7 +483,10 @@ export const SETTINGS = [
483
483
  key: "provenance",
484
484
  role: "ignored",
485
485
  read: true,
486
- value: { type: "string", pattern: "^(default|(repository|central|flag): [^\\r\\n]+)$" },
486
+ value: {
487
+ type: "string",
488
+ pattern: "^(default|(repository|central|flag): ([^\\r\\n]|[\\r\\n])+)$",
489
+ },
487
490
  keyPattern: "^[a-z][a-z_]*(\\.[A-Za-z0-9_]+)*$",
488
491
  },
489
492
  ];