@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
package/src/sweep.ts CHANGED
@@ -7,7 +7,8 @@
7
7
  */
8
8
 
9
9
  import type { TSExemptionClass } from "./exempt-classes.ts";
10
- import { namesACaller, OUTSIDE, type Edge, type Graph } from "./graph.ts";
10
+ import { namesACaller, OUTSIDE, type Counts, type Edge, type Graph } from "./graph.ts";
11
+ import { edgeWithheldBy } from "./tests/file-class.ts";
11
12
  import type { InventorySymbol } from "./inventory.ts";
12
13
  import type { Position } from "./position.ts";
13
14
 
@@ -54,6 +55,32 @@ export interface Mode {
54
55
  * in a test file makes is such a reference, so nothing only a test reaches is live.
55
56
  */
56
57
  readonly production: boolean;
58
+ /**
59
+ * Classes a reference a loaded consumer's test file made as a production one rather than a
60
+ * test one, `analysis.consumer_tests` at `production`: a classification, not a filter, so it
61
+ * decides the split a candidate reports as well as what a production sweep counts.
62
+ */
63
+ readonly consumerTestsProduction?: boolean;
64
+ }
65
+
66
+ /** The references to one declaration the mode counts: under `production` none test code made but those it classes as production. */
67
+ function countedRefs(made: Counts | undefined, mode: Mode): number {
68
+ if (made === undefined) {
69
+ return 0;
70
+ }
71
+ if (!mode.production) {
72
+ return made.production + made.test;
73
+ }
74
+ return made.production + (mode.consumerTestsProduction === true ? made.consumerTest : 0);
75
+ }
76
+
77
+ /** The references to one declaration, split as the mode classes them, whatever it counts. */
78
+ export function splitRefs(
79
+ made: Counts | undefined,
80
+ mode: Mode,
81
+ ): { readonly production: number; readonly test: number } {
82
+ const moved = mode.consumerTestsProduction === true ? (made?.consumerTest ?? 0) : 0;
83
+ return { production: (made?.production ?? 0) + moved, test: (made?.test ?? 0) - moved };
57
84
  }
58
85
 
59
86
  /** What one sweep runs over besides the graph. */
@@ -134,13 +161,7 @@ export function sweep(graph: Graph, input: SweepInput): Liveness {
134
161
  }
135
162
  }
136
163
 
137
- const counted = (at: number): number => {
138
- const made = graph.made[at];
139
- if (made === undefined) {
140
- return 0;
141
- }
142
- return input.mode.production ? made.production : made.production + made.test;
143
- };
164
+ const counted = (at: number): number => countedRefs(graph.made[at], input.mode);
144
165
  const reached = reachable(graph, held, input.mode);
145
166
  const liveUnder = graph.symbols.map((_symbol, at): readonly Relation[] => {
146
167
  const relations: Relation[] = [];
@@ -169,10 +190,11 @@ export function sweep(graph: Graph, input: SweepInput): Liveness {
169
190
  if (dead[at] !== true) {
170
191
  return;
171
192
  }
193
+ const split = splitRefs(graph.made[at], input.mode);
172
194
  candidates.push({
173
195
  id: symbol.id,
174
- productionRefs: graph.made[at]?.production ?? 0,
175
- testRefs: graph.made[at]?.test ?? 0,
196
+ productionRefs: split.production,
197
+ testRefs: split.test,
176
198
  relation: counted(at) === 0 ? "reference-counting" : "reachability",
177
199
  testOfDeadCode: testOfDeadCode[at] === true,
178
200
  });
@@ -223,11 +245,12 @@ export function reachedWithTheTests(
223
245
  }
224
246
 
225
247
  /**
226
- * The references a loaded consumer makes that the mode counts. A production mode counts
227
- * none a consumer's test file made, as it counts none of the target's.
248
+ * The references a loaded consumer or an unheld file makes that the mode counts. A
249
+ * production mode counts no test reference, but a loaded consumer's where the mode classes
250
+ * a consumer's tests as production.
228
251
  */
229
252
  function callsOf(graph: Graph, mode: Mode): readonly Edge[] {
230
- return graph.consumed.filter((edge) => !mode.production || !edge.test);
253
+ return graph.consumed.filter((edge) => !edgeWithheldBy(mode, edge));
231
254
  }
232
255
 
233
256
  /** Per declaration of the graph, whether one of the identifiers names it. */
@@ -280,7 +303,7 @@ function reachable(
280
303
  const walk = (holding: boolean): void => {
281
304
  for (let at = queue.pop(); at !== undefined; at = queue.pop()) {
282
305
  for (const edge of graph.out[at] ?? []) {
283
- if (!holding && mode.production && edge.test) {
306
+ if (!holding && edgeWithheldBy(mode, edge)) {
284
307
  continue;
285
308
  }
286
309
  enter(edge.to, namespaces && !edge.evaluation);
@@ -23,10 +23,9 @@ import {
23
23
  import { parenthesesRemoved } from "./unwrap.ts";
24
24
  import type { Symbol as TSSymbol, Type } from "@typescript/native/sync";
25
25
  import type { AliasChains } from "./alias-chain.ts";
26
- import { nodeKey, type Inventory, type InventorySymbol } from "./inventory.ts";
27
- import { renderPosition } from "./position.ts";
28
- import { isAnswered, type PropertyTables } from "./query.ts";
29
- import type { Reference } from "./references.ts";
26
+ import type { InventorySymbol } from "./inventory.ts";
27
+ import { isAnswered, UNANSWERED, type PropertyTables } from "./query.ts";
28
+ import type { Read, ReadRule } from "./references/read-rule.ts";
30
29
  import type { ProjectView } from "./session.ts";
31
30
 
32
31
  /** One element access whose key is a name, and how the access uses the member it selects. */
@@ -193,104 +192,105 @@ function wellKnownName(name: Node | undefined): string | undefined {
193
192
  }
194
193
 
195
194
  /**
196
- * The references the iterations of one project's own files make to the iteration members
197
- * of the values they iterate: a `for…of` statement and a spread element read
198
- * `[Symbol.iterator]`, and a `for await…of` statement reads `[Symbol.asyncIterator]` and,
199
- * which it falls back to, `[Symbol.iterator]`. Each is made by the declaration holding it.
195
+ * The reads the iterations of a side's files make of the iteration members of the values they
196
+ * iterate: a `for…of` statement and a spread element read `[Symbol.iterator]`, and a
197
+ * `for await…of` statement reads `[Symbol.asyncIterator]` and, which it falls back to,
198
+ * `[Symbol.iterator]`. Each is made by the declaration holding it. A value whose type or
199
+ * members the checker leaves unanswered holds the members those names could spell.
200
200
  */
201
- export function iterationReferences<Brand>(
202
- project: ProjectView<Brand>,
203
- held: Inventory,
204
- chains: AliasChains,
205
- root: string,
206
- testFiles: ReadonlySet<string>,
207
- ): readonly Reference[] {
208
- const queries = project.queries;
209
- const ownPaths = project.ownPaths();
210
- const iterated: {
211
- readonly file: SourceFile;
212
- readonly from: string;
213
- readonly operand: Expression;
214
- readonly protocols: readonly Protocol[];
215
- }[] = [];
216
- for (const file of project.ownSourceFiles()) {
217
- const fileId = held.declarations.get(nodeKey(file, file));
218
- if (fileId === undefined) {
219
- continue;
220
- }
221
- const visit = (node: Node, from: string): void => {
222
- const holder = held.declarations.get(nodeKey(file, node)) ?? from;
223
- if (isForOfStatement(node)) {
224
- const protocols: readonly Protocol[] =
225
- node.awaitModifier === undefined ? ["iterator"] : ["asyncIterator", "iterator"];
226
- iterated.push({ file, from: holder, operand: node.expression, protocols });
227
- } else if (isSpreadElement(node)) {
228
- iterated.push({ file, from: holder, operand: node.expression, protocols: ["iterator"] });
229
- }
230
- node.forEachChild((child) => {
231
- visit(child, holder);
232
- });
233
- };
234
- file.forEachChild((child) => {
235
- visit(child, fileId);
236
- });
237
- }
238
- if (iterated.length === 0) {
239
- return [];
240
- }
241
- const types = queries.typesAt(iterated.map((one) => one.operand));
242
- const members = new Map<
243
- number,
244
- readonly { readonly name: string; readonly ids: readonly string[] }[]
245
- >();
246
- const membersOf = (
247
- type: Type,
248
- ): readonly { readonly name: string; readonly ids: readonly string[] }[] => {
249
- const known = members.get(type.id);
250
- if (known !== undefined) {
251
- return known;
252
- }
253
- const keyed: { name: string; ids: readonly string[] }[] = [];
254
- const properties = queries.propertiesOf(type);
255
- for (const property of isAnswered(properties) ? properties : []) {
256
- for (const handle of property.declarations) {
257
- const node = ownPaths.has(handle.path) ? project.declarationAt(handle)?.node : undefined;
258
- const name = wellKnownName((node as { readonly name?: Node } | undefined)?.name);
259
- if (name !== undefined) {
260
- keyed.push({ name, ids: chains.declarationsOf(property) });
261
- break;
262
- }
263
- }
264
- }
265
- members.set(type.id, keyed);
266
- return keyed;
267
- };
268
- const found: Reference[] = [];
269
- iterated.forEach((one, index) => {
270
- const type = types[index];
271
- if (type === undefined || !isAnswered(type)) {
272
- return;
273
- }
274
- const parts =
275
- type.isUnionType() || type.isIntersectionType() ? queries.constituents(type) : [type];
276
- const position = renderPosition(one.file, root, one.operand.getStart());
277
- for (const part of isAnswered(parts) ? parts : []) {
278
- for (const member of membersOf(part)) {
279
- if (!(one.protocols as readonly string[]).includes(member.name)) {
280
- continue;
201
+ export const iteration: ReadRule = {
202
+ start() {
203
+ const iterated: {
204
+ readonly file: SourceFile;
205
+ readonly from: string;
206
+ readonly operand: Expression;
207
+ readonly protocols: readonly Protocol[];
208
+ }[] = [];
209
+ return {
210
+ visit(node, { file, from }) {
211
+ if (isForOfStatement(node)) {
212
+ const protocols: readonly Protocol[] =
213
+ node.awaitModifier === undefined ? ["iterator"] : ["asyncIterator", "iterator"];
214
+ iterated.push({ file, from, operand: node.expression, protocols });
215
+ } else if (isSpreadElement(node)) {
216
+ iterated.push({ file, from, operand: node.expression, protocols: ["iterator"] });
281
217
  }
282
- for (const to of member.ids) {
283
- found.push({
284
- from: one.from,
285
- to,
286
- position,
287
- use: "read",
288
- resolution: "keyed",
289
- test: testFiles.has(position.path),
290
- });
218
+ },
219
+ reads({ project, chains }) {
220
+ const found: Read[] = [];
221
+ if (iterated.length === 0) {
222
+ return found;
291
223
  }
292
- }
293
- }
294
- });
295
- return found;
296
- }
224
+ const queries = project.queries;
225
+ const ownPaths = project.ownPaths();
226
+ const types = queries.typesAt(iterated.map((one) => one.operand));
227
+ const members = new Map<
228
+ number,
229
+ readonly { readonly name: string; readonly ids: readonly string[] }[] | typeof UNANSWERED
230
+ >();
231
+ const membersOf = (type: Type) => {
232
+ const known = members.get(type.id);
233
+ if (known !== undefined) {
234
+ return known;
235
+ }
236
+ const properties = queries.propertiesOf(type);
237
+ const keyed: { name: string; ids: readonly string[] }[] = [];
238
+ for (const property of isAnswered(properties) ? properties : []) {
239
+ for (const handle of property.declarations) {
240
+ const node = ownPaths.has(handle.path)
241
+ ? project.declarationAt(handle)?.node
242
+ : undefined;
243
+ const name = wellKnownName((node as { readonly name?: Node } | undefined)?.name);
244
+ if (name !== undefined) {
245
+ keyed.push({ name, ids: chains.declarationsOf(property) });
246
+ break;
247
+ }
248
+ }
249
+ }
250
+ const result = isAnswered(properties) ? keyed : UNANSWERED;
251
+ members.set(type.id, result);
252
+ return result;
253
+ };
254
+ // A member a well-known symbol keys is named by the symbol's computed name.
255
+ const spelled = (protocols: readonly Protocol[]): readonly string[] =>
256
+ protocols.map((protocol) => `Symbol.${protocol}`);
257
+ iterated.forEach((one, index) => {
258
+ const type = types[index];
259
+ if (type === UNANSWERED) {
260
+ found.push({ kind: "held", from: one.from, names: spelled(one.protocols) });
261
+ return;
262
+ }
263
+ if (type === undefined) {
264
+ return;
265
+ }
266
+ const parts =
267
+ type.isUnionType() || type.isIntersectionType() ? queries.constituents(type) : [type];
268
+ for (const part of isAnswered(parts) ? parts : [type]) {
269
+ const keyed = membersOf(part);
270
+ if (keyed === UNANSWERED) {
271
+ found.push({ kind: "held", from: one.from, names: spelled(one.protocols) });
272
+ continue;
273
+ }
274
+ for (const member of keyed) {
275
+ if (!(one.protocols as readonly string[]).includes(member.name)) {
276
+ continue;
277
+ }
278
+ for (const to of member.ids) {
279
+ found.push({
280
+ kind: "named",
281
+ from: one.from,
282
+ to,
283
+ file: one.file,
284
+ at: one.operand,
285
+ use: "read",
286
+ via: "keyed",
287
+ });
288
+ }
289
+ }
290
+ }
291
+ });
292
+ return found;
293
+ },
294
+ };
295
+ },
296
+ };
@@ -0,0 +1,118 @@
1
+ /**
2
+ * The file classes the run counts references by. A test file is one a `ts.test_files`
3
+ * pattern or a test runner's row names (the test-runner entry source decides which), a test
4
+ * file no project holds, or a consumer's file a pattern names below the consumer's root.
5
+ * A test-support file is test code as well, decided once the references are known
6
+ * (`support.ts`), so a reference carries only whether a test file made it and the counters
7
+ * read the support class beside it.
8
+ */
9
+
10
+ import type { SourceFile } from "@typescript/native/ast";
11
+ import type { Edge } from "../graph.ts";
12
+ import { renderPosition } from "../position.ts";
13
+ import type { Reference } from "../references.ts";
14
+ import type { ProjectView } from "../session.ts";
15
+ import type { Mode } from "../sweep.ts";
16
+ import { bytewise } from "../text/compare.ts";
17
+ import { globExpression } from "../text/glob.ts";
18
+
19
+ /** One rule that classified files as test files, and how many files it matched. */
20
+ export interface TestFileRule {
21
+ /** The rule's name, as a report's own rule list spells one. */
22
+ readonly rule: string;
23
+ readonly matched: number;
24
+ }
25
+
26
+ /** Whether one file of a side is a test file. */
27
+ export type TestFile = (file: SourceFile) => boolean;
28
+
29
+ /** The test files of the target: each file the test-runner source names, by its file name. */
30
+ export function targetTestFile(named: ReadonlySet<string>): TestFile {
31
+ return (file) => named.has(file.fileName);
32
+ }
33
+
34
+ /** The test files a pattern names, each by its path below `root`: a consumer's, below the consumer's root. */
35
+ export function patternTestFile(patterns: readonly string[], root: string): TestFile {
36
+ const expressions = patterns.map(globExpression);
37
+ return (file) => {
38
+ const path = renderPosition(file, root, 0).path;
39
+ return expressions.some((expression) => expression.test(path));
40
+ };
41
+ }
42
+
43
+ /** The own files of a project that are test files, by their path below `root`, ascending. */
44
+ export function testFilePaths<Brand>(
45
+ project: ProjectView<Brand>,
46
+ root: string,
47
+ testFile: TestFile,
48
+ ): readonly string[] {
49
+ return project
50
+ .ownSourceFiles()
51
+ .filter(testFile)
52
+ .map((file) => renderPosition(file, root, 0).path)
53
+ .sort(bytewise);
54
+ }
55
+
56
+ /** Whether test code made one reference: a test file, or a test-support file of the target. */
57
+ export function madeByTestCode(reference: Reference, support: ReadonlySet<string>): boolean {
58
+ return (
59
+ reference.test || (reference.consumer === undefined && support.has(reference.position.path))
60
+ );
61
+ }
62
+
63
+ /** Whether the mode classes a reference test code made as a test one: any but a loaded consumer's it classes as production. */
64
+ export function classedAsTest(test: boolean, consumer: boolean, mode: Mode): boolean {
65
+ return test && !(consumer && mode.consumerTestsProduction === true);
66
+ }
67
+
68
+ /** Whether a production mode counts no reference of this one: test code made it, as the mode classes it. */
69
+ export function withheldBy(
70
+ mode: Mode,
71
+ reference: Reference,
72
+ support: ReadonlySet<string>,
73
+ ): boolean {
74
+ return (
75
+ mode.production &&
76
+ classedAsTest(madeByTestCode(reference, support), reference.consumer !== undefined, mode)
77
+ );
78
+ }
79
+
80
+ /** Whether a production mode follows no edge like this one: {@link withheldBy} for a graph edge. */
81
+ export function edgeWithheldBy(mode: Mode, edge: Edge): boolean {
82
+ return mode.production && classedAsTest(edge.test, edge.consumer, mode);
83
+ }
84
+
85
+ /** The rule a file the analysis classified as test-support code is counted under. */
86
+ const TEST_SUPPORT_RULE = "test-support";
87
+
88
+ /**
89
+ * The name one test-file rule takes. A rule's name is a word list the report's own
90
+ * vocabulary spells, which cannot carry a pattern, so a rule is named by the place of
91
+ * its pattern in the configured list.
92
+ */
93
+ function patternRule(index: number): string {
94
+ return `test-file-pattern-${String(index + 1)}`;
95
+ }
96
+
97
+ /**
98
+ * The rules over the test files of several projects at once, ordered by rule: a file two
99
+ * projects hold is one file, so each rule counts the distinct paths it matches.
100
+ */
101
+ export function testFileRulesOf(
102
+ testFiles: readonly string[],
103
+ paths: readonly string[],
104
+ supportFiles: readonly string[] = [],
105
+ ): readonly TestFileRule[] {
106
+ const distinct = [...new Set(paths)];
107
+ const support = new Set(supportFiles).size;
108
+ return [
109
+ ...testFiles.map((pattern, index) => {
110
+ const expression = globExpression(pattern);
111
+ return {
112
+ rule: patternRule(index),
113
+ matched: distinct.filter((path) => expression.test(path)).length,
114
+ };
115
+ }),
116
+ ...(support === 0 ? [] : [{ rule: TEST_SUPPORT_RULE, matched: support }]),
117
+ ].sort((a, b) => bytewise(a.rule, b.rule));
118
+ }
@@ -19,19 +19,25 @@ import {
19
19
  type Node,
20
20
  type SourceFile,
21
21
  } from "@typescript/native/ast";
22
- import { RESOLVED_EXTENSIONS, type ParseFile } from "./configuration-files.ts";
23
- import { emittedFrom } from "./load/emit-map.ts";
24
- import type { Host } from "./host.ts";
25
- import type { Inventory } from "./inventory.ts";
26
- import { namesImported } from "./module-declarations.ts";
27
- import { dirnamePath, joinPath, normalizePath, queriedModulePath } from "./paths.ts";
28
- import { renderPosition } from "./position.ts";
29
- import { nameComponent } from "./ref.ts";
30
- import type { Reference } from "./references.ts";
22
+ import { RESOLVED_EXTENSIONS, type ParseFile } from "../entries/configuration-files.ts";
23
+ import { emittedFrom } from "../load/emit-map.ts";
24
+ import type { Host } from "../host.ts";
25
+ import type { Inventory } from "../inventory.ts";
26
+ import { namesImported } from "../import-bindings.ts";
27
+ import {
28
+ dirnamePath,
29
+ joinPath,
30
+ normalizePath,
31
+ queriedModulePath,
32
+ startsRelativePath,
33
+ } from "../paths.ts";
34
+ import { renderPosition } from "../position.ts";
35
+ import { nameComponent } from "../ref.ts";
36
+ import type { Reference } from "../references.ts";
31
37
 
32
38
  /** The paths below the target root one relative specifier may name, written path first. */
33
39
  function candidates(dir: string, specifier: string): readonly string[] {
34
- if (!specifier.startsWith("./") && !specifier.startsWith("../")) {
40
+ if (!startsRelativePath(specifier)) {
35
41
  return [];
36
42
  }
37
43
  const path = normalizePath(dir === "" ? specifier : `${dir}/${specifier}`);
@@ -6,11 +6,15 @@
6
6
  * test code.
7
7
  */
8
8
 
9
- import { CONVENTION_ROWS, TEST_LIBRARIES, TEST_LIBRARY_SCOPES } from "./convention-rows.ts";
10
- import { packageOfSpecifier } from "./dependencies.ts";
11
- import type { InventorySymbol } from "./inventory.ts";
12
- import type { Reference } from "./references.ts";
13
- import type { Root } from "./roots.ts";
9
+ import {
10
+ CONVENTION_ROWS,
11
+ TEST_LIBRARIES,
12
+ TEST_LIBRARY_SCOPES,
13
+ } from "../entries/convention-rows.ts";
14
+ import { packageOfSpecifier } from "../dependencies.ts";
15
+ import type { InventorySymbol } from "../inventory.ts";
16
+ import type { Reference } from "../references.ts";
17
+ import type { Root } from "../roots/root-set.ts";
14
18
 
15
19
  /** The root kind that never takes a file out of test-support code: the skip only withholds. */
16
20
  const SKIP_ROOT = "type-error";
@@ -20,7 +24,12 @@ const SKIP_ROOT = "type-error";
20
24
  * convention row reads test files for, and the convention table's test libraries.
21
25
  */
22
26
  const TEST_PACKAGES: ReadonlySet<string> = new Set([
23
- ...CONVENTION_ROWS.filter((row) => row.testFiles !== undefined).map((row) => row.package),
27
+ ...CONVENTION_ROWS.filter(
28
+ (row) =>
29
+ row.testFiles !== undefined ||
30
+ row.testDirectories !== undefined ||
31
+ row.testRunner !== undefined,
32
+ ).map((row) => row.package),
24
33
  ...TEST_LIBRARIES,
25
34
  ]);
26
35
 
@@ -209,18 +218,3 @@ export function testSupportFiles(
209
218
  );
210
219
  return { support, testUsed: new Set([...onlyTests].filter((path) => !support.has(path))) };
211
220
  }
212
-
213
- /** The references with every one a test-support file makes counted as a test reference. */
214
- export function supportReferences(
215
- references: readonly Reference[],
216
- support: ReadonlySet<string>,
217
- ): readonly Reference[] {
218
- if (support.size === 0) {
219
- return references;
220
- }
221
- return references.map((reference) =>
222
- !reference.test && support.has(reference.position.path)
223
- ? { ...reference, test: true }
224
- : reference,
225
- );
226
- }