reading-stone 0.0.0-stage → 0.2.1

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 (72) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +11 -0
  3. package/README.md +301 -2
  4. package/dist/analysis.d.ts +341 -0
  5. package/dist/analysis.js +392 -0
  6. package/dist/cognitive.d.ts +163 -0
  7. package/dist/cognitive.js +380 -0
  8. package/dist/complexity.d.ts +102 -0
  9. package/dist/complexity.js +163 -0
  10. package/dist/coverage.d.ts +78 -0
  11. package/dist/coverage.js +635 -0
  12. package/dist/detector.d.ts +41 -0
  13. package/dist/detector.js +2134 -0
  14. package/dist/discovery.d.ts +330 -0
  15. package/dist/discovery.js +930 -0
  16. package/dist/doc-coverage.d.ts +155 -0
  17. package/dist/doc-coverage.js +543 -0
  18. package/dist/extract.d.ts +209 -0
  19. package/dist/extract.js +498 -0
  20. package/dist/index.d.ts +64 -0
  21. package/dist/index.js +63 -0
  22. package/dist/internal.d.ts +75 -0
  23. package/dist/internal.js +63 -0
  24. package/dist/main.d.ts +8 -0
  25. package/dist/main.js +39 -0
  26. package/dist/models.d.ts +185 -0
  27. package/dist/models.js +170 -0
  28. package/dist/program.d.ts +207 -0
  29. package/dist/program.js +662 -0
  30. package/dist/protocol.d.ts +88 -0
  31. package/dist/protocol.js +74 -0
  32. package/dist/quality/assertions.d.ts +81 -0
  33. package/dist/quality/assertions.js +425 -0
  34. package/dist/quality/collect.d.ts +66 -0
  35. package/dist/quality/collect.js +412 -0
  36. package/dist/quality/inference.d.ts +86 -0
  37. package/dist/quality/inference.js +603 -0
  38. package/dist/quality/matchers.d.ts +129 -0
  39. package/dist/quality/matchers.js +220 -0
  40. package/dist/quality/pairing.d.ts +133 -0
  41. package/dist/quality/pairing.js +770 -0
  42. package/dist/quality/pipeline.d.ts +59 -0
  43. package/dist/quality/pipeline.js +202 -0
  44. package/dist/quality/types.d.ts +127 -0
  45. package/dist/quality/types.js +92 -0
  46. package/dist/safeio.d.ts +107 -0
  47. package/dist/safeio.js +314 -0
  48. package/dist/server.d.ts +19 -0
  49. package/dist/server.js +451 -0
  50. package/dist/signals/adapter.d.ts +103 -0
  51. package/dist/signals/adapter.js +323 -0
  52. package/dist/signals/caller-index.d.ts +117 -0
  53. package/dist/signals/caller-index.js +147 -0
  54. package/dist/signals/caller.d.ts +76 -0
  55. package/dist/signals/caller.js +108 -0
  56. package/dist/signals/evidence.d.ts +233 -0
  57. package/dist/signals/evidence.js +578 -0
  58. package/dist/signals/interface.d.ts +68 -0
  59. package/dist/signals/interface.js +87 -0
  60. package/dist/signals/jsdoc.d.ts +27 -0
  61. package/dist/signals/jsdoc.js +233 -0
  62. package/dist/signals/naming.d.ts +26 -0
  63. package/dist/signals/naming.js +160 -0
  64. package/dist/signals/routing.d.ts +163 -0
  65. package/dist/signals/routing.js +416 -0
  66. package/dist/signals/types.d.ts +146 -0
  67. package/dist/signals/types.js +99 -0
  68. package/dist/signals/visibility.d.ts +23 -0
  69. package/dist/signals/visibility.js +82 -0
  70. package/dist/taxonomy.d.ts +89 -0
  71. package/dist/taxonomy.js +217 -0
  72. package/package.json +61 -4
@@ -0,0 +1,578 @@
1
+ import { escapeLeadingUnderscores, getJSDocTags, getTextOfJSDocComment, isBinaryExpression, isClassDeclaration, isClassLikeDeclaration, isExportAssignment, isExpressionStatement, isFunctionDeclaration, isFunctionLikeDeclaration, isIdentifier, isJSDoc, isObjectLiteralExpression, isPropertyAccessExpression, isPropertyAssignment, isPropertyDeclaration, isReturnStatement, isSatisfiesExpression, isTypeReferenceNode, isVariableDeclaration, isVariableDeclarationList, isVariableStatement, ModifierFlags, SyntaxKind, } from "typescript/unstable/ast";
2
+ import { SymbolFlags, } from "typescript/unstable/sync";
3
+ import { buildCallerIndex } from "./caller-index.js";
4
+ /**
5
+ * Builds the per-record evidence snapshot over one prepared analysis
6
+ * (research R12's seam).
7
+ *
8
+ * Both halves compute here, each once per record: the mode-independent
9
+ * components (both exportedness components and both documentation fields)
10
+ * from the parsed AST, and the checker-resolved components
11
+ * (`exportedReturnType`, `interfaceMember`) through the live program-mode
12
+ * checker. The caller index is `buildCallerIndex` (T009) run once per
13
+ * build, over the same records and in-scope set — its count lands on the
14
+ * snapshot verbatim, never recomputed per record. In parse-only mode there
15
+ * is no checker: the checker-resolved components carry their degradation
16
+ * values (false/0) and the caller index is empty, so degradation reduces
17
+ * precision, never availability.
18
+ *
19
+ * Every value is computed once per record, and the result is a pure
20
+ * function of the live inputs: repeated calls over the same context,
21
+ * records, and in-scope set produce equal snapshots. An empty record list
22
+ * yields the empty map.
23
+ *
24
+ * @param context The bootstrapped analysis context — the program-mode arm
25
+ * must still be live (every checker query and the caller index's
26
+ * `getSignatureUsage` traffic round-trip to the native compiler server);
27
+ * the parse-only arm owns nothing to keep alive.
28
+ * @param records The extracted function-likes, as `prepareAnalysis`
29
+ * returned them — the same instances the caller will look up by.
30
+ * @param inScopePaths The pattern-filtered, test-excluded source list from
31
+ * `PreparedAnalysis.inScopePaths` — the identical file set the caller index
32
+ * filters call sites by (US3-7's parity).
33
+ * @param rootPath The realpath-resolved analysis root from
34
+ * `PreparedAnalysis.rootPath` — the base the caller index relativizes
35
+ * call-site file names against.
36
+ * @returns Every record mapped to its evidence snapshot, keyed by the
37
+ * record reference.
38
+ */
39
+ export function buildRecordEvidence(context, records, inScopePaths, rootPath) {
40
+ // The caller index is built once per snapshot while the context is live
41
+ // (research R7's lifetime rule) — before any record loop that might
42
+ // hand its results to a consumer that disposes. Parse-only yields the
43
+ // empty index inside.
44
+ const callerIndex = buildCallerIndex(context, records, inScopePaths, rootPath);
45
+ // The checker-resolved components' gate: null in parse-only mode, where
46
+ // each carries its degradation value (false/0) below.
47
+ const checker = context.mode === "program" ? context.checker : null;
48
+ // Per-build memo of each file's CJS exported names — scanned at most once
49
+ // per file, only when the fallback route is actually consulted.
50
+ const cjsNamesByFile = new Map();
51
+ const evidence = new Map();
52
+ for (const record of records) {
53
+ // The component split turns on shape alone: a record with an enclosing
54
+ // class is judged through the class (receiver component), every other
55
+ // record through itself (function component). The two components are
56
+ // disjoint by construction — no record takes both.
57
+ const enclosingClass = enclosingClassOf(record.node);
58
+ evidence.set(record, {
59
+ record,
60
+ exportedFunction: enclosingClass === null && isExportedValue(record.node, cjsNamesByFile),
61
+ exportedReturnType: checker !== null && hasExportedReturnType(checker, record.node),
62
+ exportedReceiver: enclosingClass !== null && isExportedValue(enclosingClass, cjsNamesByFile),
63
+ docText: docTextOf(record.node),
64
+ docTags: docTagsOf(record.node),
65
+ interfaceMember: checker !== null &&
66
+ enclosingClass !== null &&
67
+ isDeclaredInterfaceMember(checker, enclosingClass, record.name),
68
+ // Total in program mode (one entry per record, 0 for the uncalled);
69
+ // the empty parse-only index leaves every record at the degraded 0.
70
+ callerModuleCount: callerIndex.get(record) ?? 0,
71
+ });
72
+ }
73
+ return evidence;
74
+ }
75
+ /**
76
+ * The closed exported-value rule (research R5; data-model.md Section 5.1):
77
+ * whether `node`'s value is reachable from module scope. Three routes,
78
+ * checked in order — the own export modifier, the value-position chain, and
79
+ * the same-file CJS fallback, which only a walk that ended at module scope
80
+ * may consult. See the module header for the full contract; the
81
+ * load-bearing details live with the steps below.
82
+ *
83
+ * @param node The declaration or expression to judge.
84
+ * @param cjsNamesByFile The per-build memo of scanned CJS exported names.
85
+ * @returns Whether the node's value is reachable from module scope.
86
+ */
87
+ function isExportedValue(node, cjsNamesByFile) {
88
+ if (hasExportModifier(node)) {
89
+ return true;
90
+ }
91
+ // The walk-start spelling for the CJS fallback: a named declaration
92
+ // carries its own binding name (a module-scope `function f` is targeted
93
+ // by `module.exports.f = f`); expressions contribute nothing here — the
94
+ // binding they initialize is captured at the variable step instead.
95
+ let bindingName = declaredName(node);
96
+ let current = node;
97
+ // The CJS fallback's gate: whether the walk ended with the record rooted
98
+ // at module scope. The assignment's right-hand side resolves in the
99
+ // module frame, so only a module-scope binding — or an object-literal
100
+ // member whose value-position chain roots at one — can be the binding an
101
+ // assignment targets; a function-local namesake shares the spelling but
102
+ // not the binding (Principle II: the name-based match is the
103
+ // approximation, the scope gate is its boundary).
104
+ let rootedAtModuleScope = false;
105
+ while (current !== undefined) {
106
+ // Annotated to break the inference cycle the `current = parent`
107
+ // reassignments would otherwise create (TS7022): the walk's parent is
108
+ // always the compiler-set AST parent, plain Node.
109
+ const parent = current.parent;
110
+ // The export-assignment route fires for both spellings — `export
111
+ // default <expr>` and `export = <expr>` — and only in the expression
112
+ // position: the assignment's clause is not the exported value.
113
+ if (isExportAssignment(parent) && parent.expression === current) {
114
+ return true;
115
+ }
116
+ if (isVariableDeclaration(parent) && parent.initializer === current) {
117
+ // The innermost variable binding on the chain is the name callers
118
+ // invoke (outer bindings of nested object literals are never the
119
+ // invokable name); a destructuring pattern names nothing.
120
+ if (bindingName === null && isIdentifier(parent.name)) {
121
+ bindingName = parent.name.text;
122
+ }
123
+ current = parent;
124
+ continue;
125
+ }
126
+ if (isVariableDeclarationList(parent) &&
127
+ parent.declarations.some((declaration) => declaration === current)) {
128
+ current = parent;
129
+ continue;
130
+ }
131
+ if (isVariableStatement(parent)) {
132
+ // The root statement is the last stop of the variable chain: its
133
+ // export modifier is the statement form of ESM exportedness, and no
134
+ // route above a statement can export the initializer. An un-exported
135
+ // statement only ends the ESM walk — the captured binding name still
136
+ // reaches the CJS fallback (the rooted-object rule) when the
137
+ // statement itself sits at module scope.
138
+ if ((parent.modifierFlags & ModifierFlags.Export) !== 0) {
139
+ return true;
140
+ }
141
+ rootedAtModuleScope = parent.parent.kind === SyntaxKind.SourceFile;
142
+ break;
143
+ }
144
+ if (isPropertyAssignment(parent) && parent.initializer === current) {
145
+ current = parent;
146
+ continue;
147
+ }
148
+ if (isObjectLiteralExpression(parent)) {
149
+ // Object-literal passthrough (R5's rooted-object rule): a member of
150
+ // a literal rooted at an exported binding is exported with it.
151
+ current = parent;
152
+ continue;
153
+ }
154
+ // Every other parent — class bodies, blocks, call arguments, source
155
+ // files — ends the walk; nothing above them exports the node. The
156
+ // ending parent also settles the CJS gate: the source file itself
157
+ // roots the record at module scope, anything else (a block, a class
158
+ // body) does not.
159
+ rootedAtModuleScope = parent.kind === SyntaxKind.SourceFile;
160
+ break;
161
+ }
162
+ if (bindingName === null || !rootedAtModuleScope) {
163
+ return false;
164
+ }
165
+ const sourceFile = node.getSourceFile();
166
+ let names = cjsNamesByFile.get(sourceFile);
167
+ if (names === undefined) {
168
+ names = scanCjsExportedNames(sourceFile);
169
+ cjsNamesByFile.set(sourceFile, names);
170
+ }
171
+ return names.has(bindingName);
172
+ }
173
+ /**
174
+ * Whether `node` is a declaration carrying the export modifier itself — the
175
+ * direct ESM form. `export default` declarations qualify through their
176
+ * modifier flags: ExportDefault is a composite that includes the Export
177
+ * bit, so one mask covers both spellings. Only declarations that can carry
178
+ * the modifier are tested (functions, classes, variable statements);
179
+ * expressions cannot, and class expressions are reached through their root
180
+ * binding instead.
181
+ *
182
+ * @param node The node to test.
183
+ * @returns Whether the node's own modifier flags include Export.
184
+ */
185
+ function hasExportModifier(node) {
186
+ return ((isFunctionDeclaration(node) ||
187
+ isClassDeclaration(node) ||
188
+ isVariableStatement(node)) &&
189
+ (node.modifierFlags & ModifierFlags.Export) !== 0);
190
+ }
191
+ /**
192
+ * The declared name of a named function or class declaration — the
193
+ * walk-start spelling of the CJS binding match. Only declarations count: a
194
+ * function EXPRESSION's internal name is invisible to callers (the binding
195
+ * it initializes is the invokable name, captured at the variable step), so
196
+ * expressions contribute nothing.
197
+ *
198
+ * @param node The node to read a declared name from.
199
+ * @returns The declaration's name, or null when the node is not a named
200
+ * declaration.
201
+ */
202
+ function declaredName(node) {
203
+ if (isFunctionDeclaration(node) || isClassDeclaration(node)) {
204
+ return node.name !== undefined ? node.name.text : null;
205
+ }
206
+ return null;
207
+ }
208
+ /**
209
+ * The class-like a record is a direct member of, when it is one: any
210
+ * function-like whose parent is a class-like (methods, constructors,
211
+ * accessors — extraction's member forms), or the initializer of a class
212
+ * property under a class-like (the arrow/function-expression member form).
213
+ * Object-literal members and every module-scope form return null — the
214
+ * receiver/function component split turns on exactly this shape, and the
215
+ * interface-heritage component reads the returned class's heritage
216
+ * clauses.
217
+ *
218
+ * @param node The record's node.
219
+ * @returns The enclosing class-like, or null when the record is not a
220
+ * direct class member.
221
+ */
222
+ function enclosingClassOf(node) {
223
+ const parent = node.parent;
224
+ if (isClassLikeDeclaration(parent)) {
225
+ return parent;
226
+ }
227
+ if (isPropertyDeclaration(parent) &&
228
+ parent.initializer === node &&
229
+ isClassLikeDeclaration(parent.parent)) {
230
+ return parent.parent;
231
+ }
232
+ return null;
233
+ }
234
+ /**
235
+ * Resolves a checker-returned symbol to the symbol its references name:
236
+ * an import alias is followed to its target, every other symbol passes
237
+ * through unchanged. Constitution Principle III's price on the unstable
238
+ * surface — `getAliasedSymbol` is the checker's own alias machinery —
239
+ * comes with a hard precondition the module header records: the native
240
+ * server PANICS on a non-alias argument ("Should only get alias here",
241
+ * verified against 7.0.2), so the Alias-flag gate below is a safety
242
+ * requirement, not a stylistic choice.
243
+ *
244
+ * Principle II at the unresolved boundary: an alias whose target cannot
245
+ * be resolved (a name imported from a missing module) yields the
246
+ * checker's unknown symbol, which identifies nothing — absence of
247
+ * evidence, returned as null, never an error and never a phantom target.
248
+ *
249
+ * @param checker The live program-mode type checker.
250
+ * @param symbol The symbol a reference resolved to, or undefined when the
251
+ * reference resolved nowhere.
252
+ * @returns The referenced symbol with aliases followed, or null when
253
+ * nothing resolvable backs the reference.
254
+ */
255
+ function resolveThroughAliases(checker, symbol) {
256
+ if (symbol === undefined) {
257
+ return null;
258
+ }
259
+ if ((symbol.flags & SymbolFlags.Alias) === 0) {
260
+ return symbol;
261
+ }
262
+ const target = checker.getAliasedSymbol(symbol);
263
+ return checker.isUnknownSymbol(target) ? null : target;
264
+ }
265
+ /**
266
+ * The interface-heritage component (research R6; data-model.md Section
267
+ * 5.1): whether an interface in the enclosing class's heritage DECLARES a
268
+ * member carrying the record's name.
269
+ *
270
+ * The route, each step verified against 7.0.2: `checker.getSymbolAtLocation`
271
+ * on each heritage clause type's EXPRESSION (the clause-type node itself
272
+ * resolves nothing), aliases followed to the base symbol, the base counted
273
+ * only when one of its declarations is an `InterfaceDeclaration` — the
274
+ * declaration-kind gate that keeps a resolvable CLASS base from firing
275
+ * through either heritage token, `extends Base` and `implements Base`
276
+ * alike — and membership read from the base symbol's `getMembers()`
277
+ * DECLARED-member table, keyed by the record's escaped name.
278
+ *
279
+ * The declared table is load-bearing (research R6's pinned hazard): an
280
+ * apparent-member lookup would find `Object`-prototype members on every
281
+ * interface and manufacture +30 signals on every `toString`-alike method.
282
+ * The escaped-name key is the compiler's own `escapeLeadingUnderscores`
283
+ * spelling — names beginning with `__` carry one extra underscore in the
284
+ * table (Principle III: the compiler's util, never a reimplementation).
285
+ * An invalid `extends`-an-interface clause resolves through no checker
286
+ * route (the symbol is undefined) and contributes nothing — Principle II,
287
+ * undeterminable is absence of evidence, never an error.
288
+ *
289
+ * @param checker The live program-mode type checker.
290
+ * @param enclosingClass The class-like the record is a direct member of.
291
+ * @param name The record's member name.
292
+ * @returns Whether a heritage interface declares a member with that name.
293
+ */
294
+ function isDeclaredInterfaceMember(checker, enclosingClass, name) {
295
+ const escapedName = escapeLeadingUnderscores(name);
296
+ for (const clause of enclosingClass.heritageClauses ?? []) {
297
+ for (const base of clause.types) {
298
+ const baseSymbol = resolveThroughAliases(checker, checker.getSymbolAtLocation(base.expression));
299
+ if (baseSymbol === null) {
300
+ continue;
301
+ }
302
+ // The declaration-kind gate: only an interface base counts. A class
303
+ // base resolves to the same member-bearing symbol shape — the kind
304
+ // is the only discriminator (research R6's cheap-check-first shape).
305
+ if (!baseSymbol.declarations.some((declaration) => declaration.kind === SyntaxKind.InterfaceDeclaration)) {
306
+ continue;
307
+ }
308
+ if (baseSymbol.getMembers().has(escapedName)) {
309
+ return true;
310
+ }
311
+ }
312
+ }
313
+ return false;
314
+ }
315
+ /**
316
+ * The exported-return-type component (research R5; data-model.md Section
317
+ * 5.1): whether the record's own explicit return-type annotation contains
318
+ * at least one type reference resolving through the checker to an exported
319
+ * or ambient symbol. See the module header's return-type contract for the
320
+ * full rule.
321
+ *
322
+ * @param checker The live program-mode type checker.
323
+ * @param node The record's function-like node.
324
+ * @returns Whether an exported or ambient type reference appears in the
325
+ * annotation.
326
+ */
327
+ function hasExportedReturnType(checker, node) {
328
+ const annotation = returnTypeAnnotationOf(node);
329
+ if (annotation === null) {
330
+ return false;
331
+ }
332
+ for (const reference of typeReferencesIn(annotation)) {
333
+ const symbol = resolveThroughAliases(checker, checker.getSymbolAtLocation(reference.typeName));
334
+ if (symbol === null) {
335
+ continue;
336
+ }
337
+ if (symbol.declarations.some(isExportedOrAmbientDeclaration)) {
338
+ return true;
339
+ }
340
+ }
341
+ return false;
342
+ }
343
+ /**
344
+ * The record node's explicit return-type annotation — the `type` field of
345
+ * the function-like itself, present for every record form that annotates a
346
+ * return (the declaration forms and the assigned expression forms alike
347
+ * carry it on the function-like node the record wraps). Constructors and
348
+ * setters cannot annotate a return; unannotated functions do not.
349
+ *
350
+ * @param node The record's node.
351
+ * @returns The annotation's type-node subtree, or null when absent.
352
+ */
353
+ function returnTypeAnnotationOf(node) {
354
+ return isFunctionLikeDeclaration(node) && node.type !== undefined ? node.type : null;
355
+ }
356
+ /**
357
+ * Collects every identifier-based type reference in an annotation subtree,
358
+ * outer references and nested type arguments alike (`Result | null`,
359
+ * `Array<Result>`): a keyword (`string`), a literal type (`"ok"`), and an
360
+ * object-literal type (`{ n: number }`) are not type references and never
361
+ * appear. The walk revisits only nodes of a file extraction already
362
+ * admitted under its depth budget — the detector's per-record walk
363
+ * discipline, no second budget.
364
+ *
365
+ * @param annotation The annotation's root type node.
366
+ * @returns The type-reference nodes within, in source order.
367
+ */
368
+ function typeReferencesIn(annotation) {
369
+ const references = [];
370
+ const collect = (node) => {
371
+ if (isTypeReferenceNode(node)) {
372
+ references.push(node);
373
+ }
374
+ node.forEachChild((child) => {
375
+ collect(child);
376
+ return undefined;
377
+ });
378
+ };
379
+ collect(annotation);
380
+ return references;
381
+ }
382
+ /**
383
+ * Whether one declaration of a resolved type symbol is exported or ambient
384
+ * (research R5): exported is the export modifier on the declaration itself
385
+ * — the same ESM signal as the exported-value rule's modifier route — and
386
+ * ambient is a `.d.ts` source file (the platform libraries; their members
387
+ * carry no export modifier, verified). A handle the producing project
388
+ * cannot resolve identifies nothing.
389
+ *
390
+ * The cast is scoped to the modifier read: every declaration shape a
391
+ * resolved type reference reaches (interface, class, alias, enum, module)
392
+ * is modifier-bearing, and the `?? None` fallback covers the shapes the
393
+ * cast cannot promise (a type parameter declaration), where no export
394
+ * modifier exists — the bit test reads as no-export, never crashes.
395
+ *
396
+ * @param declaration The declaration handle to judge.
397
+ * @returns Whether the declaration is exported or ambient.
398
+ */
399
+ function isExportedOrAmbientDeclaration(declaration) {
400
+ const node = declaration.resolve();
401
+ if (node === undefined) {
402
+ return false;
403
+ }
404
+ const modifierFlags = node.modifierFlags ?? ModifierFlags.None;
405
+ if ((modifierFlags & ModifierFlags.Export) !== 0) {
406
+ return true;
407
+ }
408
+ return node.getSourceFile().fileName.endsWith(".d.ts");
409
+ }
410
+ /**
411
+ * Scans one source file's top-level statements for CommonJS export
412
+ * assignments (spec edge case 5): `module.exports.<p> = X`,
413
+ * `module.exports = X`, and `exports.<p> = X`, each with a plain `=`
414
+ * operator and an identifier right-hand side. The right-hand identifier is
415
+ * the targeted binding's NAME — the value the assignment exports —
416
+ * collected into the per-file set the exported-value rule matches against.
417
+ *
418
+ * Deliberate approximations, both Principle II (ambiguity over omission):
419
+ * the match is name-based within the file (scope-precise resolution needs
420
+ * the checker), and only top-level statements are scanned (a CJS export
421
+ * inside a function body is not a module export). Compound operators
422
+ * (`+=`), non-identifier targets (`module.exports.f = obj.g`), and deeper
423
+ * member forms (`module.exports.f.g = X`) contribute nothing.
424
+ *
425
+ * @param sourceFile The file to scan.
426
+ * @returns The names targeted by the file's CJS export assignments.
427
+ */
428
+ function scanCjsExportedNames(sourceFile) {
429
+ const names = new Set();
430
+ for (const statement of sourceFile.statements) {
431
+ if (!isExpressionStatement(statement)) {
432
+ continue;
433
+ }
434
+ const assignment = statement.expression;
435
+ if (!isBinaryExpression(assignment) ||
436
+ assignment.operatorToken.kind !== SyntaxKind.EqualsToken ||
437
+ !isPropertyAccessExpression(assignment.left) ||
438
+ !isIdentifier(assignment.right)) {
439
+ continue;
440
+ }
441
+ const receiver = assignment.left;
442
+ // The three receiver shapes: `module.exports` itself, a property on it,
443
+ // and a property on the `exports` alias.
444
+ if (isModuleExportsAccess(receiver) ||
445
+ isExportsAliasAccess(receiver) ||
446
+ (isPropertyAccessExpression(receiver.expression) &&
447
+ isModuleExportsAccess(receiver.expression))) {
448
+ names.add(assignment.right.text);
449
+ }
450
+ }
451
+ return names;
452
+ }
453
+ /**
454
+ * Whether `node` spells the whole-module CJS receiver `module.exports`.
455
+ *
456
+ * @param node The node to test.
457
+ * @returns Whether the node is a property access reading `module.exports`.
458
+ */
459
+ function isModuleExportsAccess(node) {
460
+ return (isPropertyAccessExpression(node) &&
461
+ isIdentifier(node.expression) &&
462
+ node.expression.text === "module" &&
463
+ node.name.text === "exports");
464
+ }
465
+ /**
466
+ * Whether `node` is a property access on the `exports` alias — the
467
+ * per-property CJS receiver (`exports.<name>`).
468
+ *
469
+ * @param node The node to test.
470
+ * @returns Whether the node reads a property of `exports`.
471
+ */
472
+ function isExportsAliasAccess(node) {
473
+ return (isPropertyAccessExpression(node) &&
474
+ isIdentifier(node.expression) &&
475
+ node.expression.text === "exports");
476
+ }
477
+ /**
478
+ * The record's JSDoc tags (data-model.md Section 5.1): the compiler's own
479
+ * `getJSDocTags` list — bare tag names in document order, with the
480
+ * compiler's parent-node inheritance included (variable-declaration
481
+ * unification: a statement's tags document the function its initializer
482
+ * names). Constitution Principle III: never a custom doc parser.
483
+ *
484
+ * @param node The record's node.
485
+ * @returns The tag list — tag name and comment text — in document order.
486
+ */
487
+ function docTagsOf(node) {
488
+ return getJSDocTags(node).map((tag) => ({
489
+ tag: tag.tagName.text,
490
+ text: getTextOfJSDocComment(tag.comment) ?? "",
491
+ }));
492
+ }
493
+ /**
494
+ * The record's flattened JSDoc text: the description and each tag's comment
495
+ * text, single-space joined, non-empty parts only — each part rendered by
496
+ * the compiler's own `getTextOfJSDocComment` (Constitution Principle III).
497
+ *
498
+ * The JSDoc nodes come from mirroring the compiler's hosting walk
499
+ * (`nextJSDocHost`): the record's own JSDoc first, then the comments
500
+ * attached to the hosting parents above it — innermost first, so a node's
501
+ * own comment precedes a hosting statement's. The walk stops where the
502
+ * compiler's does: object literals and class bodies are not hosting
503
+ * parents, so a documented statement does not document its object-literal
504
+ * members, and a documented class does not document its methods.
505
+ *
506
+ * @param node The record's node.
507
+ * @returns The joined doc text — the empty string when undocumented.
508
+ */
509
+ function docTextOf(node) {
510
+ const parts = [];
511
+ let current = node;
512
+ while (current !== undefined) {
513
+ for (const attached of current.jsDoc ?? []) {
514
+ if (isJSDoc(attached)) {
515
+ appendDocParts(attached, parts);
516
+ }
517
+ }
518
+ current = nextJSDocHost(current);
519
+ }
520
+ return parts.join(" ");
521
+ }
522
+ /**
523
+ * Flattens one JSDoc node into `parts`: its description, then each tag's
524
+ * comment in document order — empty renderings skipped, the rest joined by
525
+ * the caller.
526
+ *
527
+ * @param doc The JSDoc node to flatten.
528
+ * @param parts The accumulator of non-empty rendered parts.
529
+ */
530
+ function appendDocParts(doc, parts) {
531
+ const description = getTextOfJSDocComment(doc.comment);
532
+ if (description !== undefined && description.length > 0) {
533
+ parts.push(description);
534
+ }
535
+ for (const tag of doc.tags ?? []) {
536
+ const text = getTextOfJSDocComment(tag.comment);
537
+ if (text !== undefined && text.length > 0) {
538
+ parts.push(text);
539
+ }
540
+ }
541
+ }
542
+ /**
543
+ * The next node up whose attached JSDoc the compiler considers hosted by
544
+ * `node` — a faithful mirror of the compiler's own
545
+ * `getNextJSDocCommentLocation` (typescript/dist/ast/jsdoc.js): the
546
+ * comment-bearing owners are property assignments, export assignments,
547
+ * property declarations, variable declarations, satisfies expressions,
548
+ * return statements, variable statements, and expression statements, plus a
549
+ * variable declaration list only when `node` is its first declaration.
550
+ * Every other parent — object literals, class bodies, source files — ends
551
+ * the walk.
552
+ *
553
+ * Exported for doc-coverage's symbol walk — a pure widening, the
554
+ * collectSources precedent: both pipelines read JSDoc attachment through
555
+ * this one hosting surface, so their semantics cannot drift.
556
+ *
557
+ * @param node The node whose hosting parent to find.
558
+ * @returns The parent that hosts JSDoc for `node`, or undefined when the
559
+ * walk ends.
560
+ */
561
+ export function nextJSDocHost(node) {
562
+ const parent = node.parent;
563
+ if (isPropertyAssignment(parent) ||
564
+ isExportAssignment(parent) ||
565
+ isPropertyDeclaration(parent) ||
566
+ isVariableDeclaration(parent) ||
567
+ isSatisfiesExpression(parent) ||
568
+ isReturnStatement(parent) ||
569
+ isVariableStatement(parent) ||
570
+ isExpressionStatement(parent)) {
571
+ return parent;
572
+ }
573
+ if (isVariableDeclarationList(parent) && parent.declarations[0] === node) {
574
+ return parent;
575
+ }
576
+ return undefined;
577
+ }
578
+ //# sourceMappingURL=evidence.js.map
@@ -0,0 +1,68 @@
1
+ import type { SideEffectType } from "../taxonomy.js";
2
+ import type { RecordEvidence } from "./evidence.js";
3
+ import type { Signal } from "./types.js";
4
+ /**
5
+ * The interface-satisfaction extractor (FR-002; research R6; data-model.md
6
+ * Section 7) — the pure half of US1's `interface` signal, and one of the
7
+ * five extractors the adapter fans out per (function record, canonical
8
+ * effect type) pair (FR-008).
9
+ *
10
+ * The rule is one row of pinned weight arithmetic, not tuning: a
11
+ * class-member record whose enclosing class's heritage declares an
12
+ * interface member carrying the record's name emits exactly one +30
13
+ * `interface` signal; every other record emits nothing. A weight that
14
+ * drifts from data-model.md Section 7 is a bug — the same posture as the
15
+ * caller bucket table (caller.ts) and the confidence formula (FR-009).
16
+ *
17
+ * Evidence seam (research R12): the rule is a pure function of the snapshot
18
+ * and the pair's effect type — no compiler interaction, no I/O, no
19
+ * `ProgramContext`. Every compiler-shaped decision — heritage resolution
20
+ * through the checker, the InterfaceDeclaration-kind gate, the
21
+ * declared-member table keyed by the compiler's escaped-name spelling, the
22
+ * `toString` apparent-member hazard — lives entirely in evidence.ts's
23
+ * `RecordEvidence.interfaceMember` (T019), pinned over program-mode fixture
24
+ * trees by tests/signals/evidence.test.ts (T011); the one runtime import
25
+ * here is `derivePackage`, the pure string helper that renders the record's
26
+ * dotted module path. The seam is what makes the rule exhaustively
27
+ * table-testable with hand-built snapshots (tests/signals/interface.test.ts,
28
+ * T012) — no tree, no tsconfig, no checker for the weights, exactly like
29
+ * the sibling pure rules (visibility, caller, naming, jsdoc).
30
+ *
31
+ * Effect-type blindness: interface evidence agrees with every effect type
32
+ * equally — a declared interface contract obligates the method as a whole,
33
+ * not one effect category — so unlike naming and documentation evidence
34
+ * (FR-005/FR-006) there is no routing gate, and `effectType` rides along as
35
+ * identity only.
36
+ *
37
+ * Parse-only degradation (FR-002; spec assumption 10): without a checker
38
+ * the seam answers `interfaceMember: false` for every record, so no
39
+ * interface signal exists at all — undeterminable is absence of evidence,
40
+ * never an error (Constitution Principle II), and degradation reduces
41
+ * precision, never availability.
42
+ *
43
+ * Determinism (Constitution Principle I; research R1): the emitted
44
+ * `reasoning` is a fixed template naming the matched member and the rule —
45
+ * a pure function of the matched rule and its token, stable per analyzer
46
+ * version and pinned by the test suite exactly like effect `description`
47
+ * strings.
48
+ */
49
+ /**
50
+ * Maps one (function record, canonical effect type) pair's evidence snapshot
51
+ * to FR-002's `interface` signal.
52
+ *
53
+ * The identity fields pass through verbatim — `function` is the record's
54
+ * unqualified name and `package` its `derivePackage` value — and the rule
55
+ * is effect-type-blind (see the module header): the same snapshot yields
56
+ * the same source, weight, and reasoning for any canonical effect type.
57
+ *
58
+ * @param evidence The record's evidence snapshot; the rule reads only
59
+ * `interfaceMember` and the record's identity fields, never the live
60
+ * compiler views.
61
+ * @param effectType The pair's canonical effect type — the signal's
62
+ * `side_effect_type` identity field.
63
+ * @returns The +30 `interface` signal when `evidence.interfaceMember` is
64
+ * true — a class-member record a heritage interface declares — or
65
+ * `undefined` otherwise, including every parse-only snapshot: neutral
66
+ * absence, never an error (Constitution Principle II).
67
+ */
68
+ export declare function interfaceSignal(evidence: RecordEvidence, effectType: SideEffectType): Signal | undefined;