reading-stone 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/NOTICE +11 -0
- package/README.md +274 -2
- package/dist/analysis.d.ts +341 -0
- package/dist/analysis.js +392 -0
- package/dist/cognitive.d.ts +163 -0
- package/dist/cognitive.js +380 -0
- package/dist/complexity.d.ts +102 -0
- package/dist/complexity.js +163 -0
- package/dist/coverage.d.ts +78 -0
- package/dist/coverage.js +635 -0
- package/dist/detector.d.ts +41 -0
- package/dist/detector.js +2134 -0
- package/dist/discovery.d.ts +330 -0
- package/dist/discovery.js +930 -0
- package/dist/doc-coverage.d.ts +155 -0
- package/dist/doc-coverage.js +543 -0
- package/dist/extract.d.ts +209 -0
- package/dist/extract.js +498 -0
- package/dist/index.d.ts +64 -0
- package/dist/index.js +54 -0
- package/dist/internal.d.ts +75 -0
- package/dist/internal.js +63 -0
- package/dist/main.d.ts +8 -0
- package/dist/main.js +39 -0
- package/dist/models.d.ts +185 -0
- package/dist/models.js +170 -0
- package/dist/program.d.ts +207 -0
- package/dist/program.js +662 -0
- package/dist/protocol.d.ts +88 -0
- package/dist/protocol.js +74 -0
- package/dist/quality/assertions.d.ts +81 -0
- package/dist/quality/assertions.js +425 -0
- package/dist/quality/collect.d.ts +66 -0
- package/dist/quality/collect.js +412 -0
- package/dist/quality/inference.d.ts +86 -0
- package/dist/quality/inference.js +603 -0
- package/dist/quality/matchers.d.ts +129 -0
- package/dist/quality/matchers.js +220 -0
- package/dist/quality/pairing.d.ts +133 -0
- package/dist/quality/pairing.js +770 -0
- package/dist/quality/pipeline.d.ts +59 -0
- package/dist/quality/pipeline.js +202 -0
- package/dist/quality/types.d.ts +127 -0
- package/dist/quality/types.js +92 -0
- package/dist/safeio.d.ts +107 -0
- package/dist/safeio.js +314 -0
- package/dist/server.d.ts +19 -0
- package/dist/server.js +451 -0
- package/dist/signals/adapter.d.ts +103 -0
- package/dist/signals/adapter.js +323 -0
- package/dist/signals/caller-index.d.ts +117 -0
- package/dist/signals/caller-index.js +147 -0
- package/dist/signals/caller.d.ts +76 -0
- package/dist/signals/caller.js +108 -0
- package/dist/signals/evidence.d.ts +233 -0
- package/dist/signals/evidence.js +578 -0
- package/dist/signals/interface.d.ts +68 -0
- package/dist/signals/interface.js +87 -0
- package/dist/signals/jsdoc.d.ts +27 -0
- package/dist/signals/jsdoc.js +233 -0
- package/dist/signals/naming.d.ts +26 -0
- package/dist/signals/naming.js +160 -0
- package/dist/signals/routing.d.ts +163 -0
- package/dist/signals/routing.js +416 -0
- package/dist/signals/types.d.ts +146 -0
- package/dist/signals/types.js +99 -0
- package/dist/signals/visibility.d.ts +23 -0
- package/dist/signals/visibility.js +82 -0
- package/dist/taxonomy.d.ts +89 -0
- package/dist/taxonomy.js +217 -0
- package/package.json +61 -4
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import type { Writable } from "node:stream";
|
|
2
|
+
import { type ArrowFunction, type BindingName, type Block, type CallExpression, type ConstructorDeclaration, type FunctionDeclaration, type FunctionExpression, type GetAccessorDeclaration, type MethodDeclaration, type Node, type PropertyName, type SetAccessorDeclaration, type SourceFile } from "typescript/unstable/ast";
|
|
3
|
+
import type { ProgramContext } from "./program.js";
|
|
4
|
+
/**
|
|
5
|
+
* The table-driven function extractor (FR-007 through FR-009; research R4,
|
|
6
|
+
* R5, R15; data-model.md ExtractionRecord; Constitution Principles I, III,
|
|
7
|
+
* IV, and V). `extractFunctions` walks each in-scope source file exactly
|
|
8
|
+
* once and returns the extracted function-likes as deterministically
|
|
9
|
+
* ordered `ExtractionRecord`s — the record set the detector (FR-009
|
|
10
|
+
* attribution) and the complexity engine (FR-022 parity) both consume.
|
|
11
|
+
*
|
|
12
|
+
* The R4 form table, as a dispatch over the node kinds the compiler
|
|
13
|
+
* produces:
|
|
14
|
+
*
|
|
15
|
+
* 1. **Function declarations** with a body, under the declared name; an
|
|
16
|
+
* anonymous body-bearing declaration is grammatically an
|
|
17
|
+
* `export default function`, named `"default"`.
|
|
18
|
+
* 2. **Methods** — class members and object-literal members alike, one node
|
|
19
|
+
* kind — with a body, under the method name; constructors under the
|
|
20
|
+
* literal name `"constructor"`; getter and setter accessors with a body
|
|
21
|
+
* under the property name (one record per accessor of a pair).
|
|
22
|
+
* 3. **Assigned function expressions** — arrow functions and function
|
|
23
|
+
* expressions — under the name of the variable, object-literal property,
|
|
24
|
+
* or class property whose initializer they are, or `"default"` when they
|
|
25
|
+
* are the expression of an `export default`.
|
|
26
|
+
* 4. **Nested function-likes** inside another record's body, each its own
|
|
27
|
+
* record (extraction is not limited to module scope).
|
|
28
|
+
*
|
|
29
|
+
* Never extracted: body-less declarations (overload signatures, ambient
|
|
30
|
+
* `declare function`s, abstract class methods, interface method
|
|
31
|
+
* signatures) and unassigned function expressions (IIFE callees,
|
|
32
|
+
* call-argument callbacks). Per FR-009 those anonymous bodies scan into the
|
|
33
|
+
* innermost enclosing extracted record at detection time; their absence
|
|
34
|
+
* from the record set is this module's pinned half of that contract.
|
|
35
|
+
*
|
|
36
|
+
* Both `ProgramContext` modes extract identically (research R5: the form
|
|
37
|
+
* table and scope tracker are purely lexical): parse-only sources arrive
|
|
38
|
+
* keyed by root-relative path, program-mode source names are absolute and
|
|
39
|
+
* relativized against `realRoot`, and the default libraries the configured
|
|
40
|
+
* program pulls in live outside the analysis root and are filtered by
|
|
41
|
+
* containment.
|
|
42
|
+
*
|
|
43
|
+
* Determinism (FR-008, research R8): records are emitted in source order
|
|
44
|
+
* and finally sorted by `(relPath, line, name)` with the platform-default
|
|
45
|
+
* stable sort, so full-key ties — a getter/setter pair on one line —
|
|
46
|
+
* resolve by AST position. Line is the 1-based line of the record's own
|
|
47
|
+
* node start (`sourceFile.getLineAndCharacterOfPosition(node.getStart(
|
|
48
|
+
* sourceFile))`, R4).
|
|
49
|
+
*
|
|
50
|
+
* Resource bounds (research R15, Constitution V): the walk tracks AST depth
|
|
51
|
+
* against a fixed budget and aborts on exceed; because each traversal level
|
|
52
|
+
* costs several native frames in the compiler client's lazy node
|
|
53
|
+
* materialization, a `RangeError` from the native stack is the same depth
|
|
54
|
+
* condition surfacing through the environment's stack size and is caught
|
|
55
|
+
* the same way. Either abort discards the file's already-emitted records,
|
|
56
|
+
* writes exactly one `reading-stone: skipping <relPath>: ast depth exceeds
|
|
57
|
+
* budget` diagnostic to the injected stderr, and continues with the next
|
|
58
|
+
* file — diagnosed degradation, never a silent truncation and never a
|
|
59
|
+
* crash. stdout is never touched (it is reserved for JSON-RPC responses).
|
|
60
|
+
*/
|
|
61
|
+
/**
|
|
62
|
+
* One extracted function-like (data-model.md ExtractionRecord; internal —
|
|
63
|
+
* not protocol-visible). The serializable identity fields (`name`,
|
|
64
|
+
* `relPath`, `line`) and `deferred` are computed during extraction — never
|
|
65
|
+
* lazily — so consumers may drop the `ProgramContext` (disposing a
|
|
66
|
+
* program-mode compiler) once `extractFunctions` returns; `node` and
|
|
67
|
+
* `scopeChain` are live compiler views for the detector's same-lifetime
|
|
68
|
+
* walk.
|
|
69
|
+
*/
|
|
70
|
+
export type ExtractionRecord = {
|
|
71
|
+
/** Identity per the R4 table: declared, variable, or property name, `"constructor"`, or `"default"`. */
|
|
72
|
+
readonly name: string;
|
|
73
|
+
/** Root-relative POSIX path of the declaring file. */
|
|
74
|
+
readonly relPath: string;
|
|
75
|
+
/** 1-based line of the record's declaration. */
|
|
76
|
+
readonly line: number;
|
|
77
|
+
/** The body-owning function-like node; the detector's walk stops at nested extracted function-likes. */
|
|
78
|
+
readonly node: Node;
|
|
79
|
+
/** Lexical scope chain, outermost-first (module frame first, the record's own scope last). */
|
|
80
|
+
readonly scopeChain: readonly ScopeFrame[];
|
|
81
|
+
/** Whether the walk entered this record inside a scheduling callback (research R6). */
|
|
82
|
+
readonly deferred: boolean;
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* One frame of the lexical scope tracker (research R5): the declaration
|
|
86
|
+
* kind of the scope and the binding names declared into it. Module frames
|
|
87
|
+
* carry `SourceFile`-level declarations (variables, functions, classes,
|
|
88
|
+
* imports); function frames carry parameters and locals. Write
|
|
89
|
+
* classification resolves a written identifier against the chain from the
|
|
90
|
+
* innermost frame outward — own scope, enclosing function scopes, then
|
|
91
|
+
* module scope.
|
|
92
|
+
*/
|
|
93
|
+
export type ScopeFrame = {
|
|
94
|
+
readonly kind: "module" | "function";
|
|
95
|
+
readonly names: ReadonlySet<string>;
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* The bare timer globals of the closed scheduling set (research R6):
|
|
99
|
+
* matched as whole callee identifiers, receiver-blind. Exported because
|
|
100
|
+
* `detector.ts`'s FR-016 spawn forms match the same globals — the two
|
|
101
|
+
* modules share the one set and can never disagree on it.
|
|
102
|
+
*/
|
|
103
|
+
export declare const TIMER_GLOBAL_NAMES: ReadonlySet<string>;
|
|
104
|
+
/**
|
|
105
|
+
* Extracts every R4-form function-like from the context's in-scope sources
|
|
106
|
+
* (FR-007, FR-008; research R4, R12).
|
|
107
|
+
*
|
|
108
|
+
* @param realRoot Realpath-resolved absolute analysis root (discovery's
|
|
109
|
+
* `resolveRoot` output); program-mode source names relativize against it.
|
|
110
|
+
* @param context The bootstrapped `ProgramContext` in either mode; the
|
|
111
|
+
* context is only read during the call.
|
|
112
|
+
* @param stderr Injected diagnostic sink for per-file depth-budget skips;
|
|
113
|
+
* stdout is never touched.
|
|
114
|
+
* @returns The extraction records, sorted by `(relPath, line, name)` with
|
|
115
|
+
* full-key ties resolved by source order through sort stability.
|
|
116
|
+
*/
|
|
117
|
+
export declare function extractFunctions(realRoot: string, context: ProgramContext, stderr: Writable): ExtractionRecord[];
|
|
118
|
+
/**
|
|
119
|
+
* The walk set: parse-only sources arrive keyed by root-relative path;
|
|
120
|
+
* program-mode names are the compiler's absolute file names, filtered to
|
|
121
|
+
* the in-scope files that relativize strictly beneath `realRoot`. The
|
|
122
|
+
* configured program's default libraries live outside the analysis root
|
|
123
|
+
* and cannot pass the containment test, so exactly the analyzed tree's
|
|
124
|
+
* sources are walked. Exported as a pure widening (spec 005 T003,
|
|
125
|
+
* FR-011; research R2) for the doc-coverage consumer
|
|
126
|
+
* (src/doc-coverage.ts): its symbol-surface walk iterates this one walk
|
|
127
|
+
* set instead of re-deriving the in-scope sources, so FR-004's
|
|
128
|
+
* file-set parity with `analyze` stays structural.
|
|
129
|
+
*
|
|
130
|
+
* @param realRoot Realpath-resolved absolute analysis root.
|
|
131
|
+
* @param context The bootstrapped context in either mode.
|
|
132
|
+
* @returns `(relPath, SourceFile)` pairs in context order.
|
|
133
|
+
*/
|
|
134
|
+
export declare function collectSources(realRoot: string, context: ProgramContext): Array<[string, SourceFile]>;
|
|
135
|
+
/**
|
|
136
|
+
* The record name for a property-name position (methods, accessors,
|
|
137
|
+
* object-literal and class properties): the node's source spelling —
|
|
138
|
+
* getStart through getEnd, no trivia — which is the identifier's text for
|
|
139
|
+
* identifier names and the literal's source text for string and numeric
|
|
140
|
+
* literal names, computed names, and private names. Deterministic for the
|
|
141
|
+
* same tree, never fabricated. Exported because doc-coverage's class-member
|
|
142
|
+
* rows carry the same source-spelling identity — the collectBindingNames
|
|
143
|
+
* widening precedent.
|
|
144
|
+
*
|
|
145
|
+
* @param name The property-name node.
|
|
146
|
+
* @param sourceFile The declaring source, for the text slice.
|
|
147
|
+
* @returns The name's text.
|
|
148
|
+
*/
|
|
149
|
+
export declare function propertyNameText(name: PropertyName, sourceFile: SourceFile): string;
|
|
150
|
+
/**
|
|
151
|
+
* Collects a binding name into a scope frame, recursing through
|
|
152
|
+
* destructuring patterns (`const { a, b: c } = ...`, `const [x, y] = ...`)
|
|
153
|
+
* so every bound spelling is tracked; pattern holes bind nothing. Exported
|
|
154
|
+
* because the detector's scope machinery resolves the same parameter and
|
|
155
|
+
* variable spellings — the one collector, never a mirrored copy.
|
|
156
|
+
*
|
|
157
|
+
* @param name The binding-name node.
|
|
158
|
+
* @param names The frame's accumulating name set.
|
|
159
|
+
*/
|
|
160
|
+
export declare function collectBindingNames(name: BindingName, names: Set<string>): void;
|
|
161
|
+
/**
|
|
162
|
+
* Whether a call is one of the closed scheduling constructs (R6): a bare
|
|
163
|
+
* `setTimeout`/`setInterval`/`queueMicrotask` reference, Node's
|
|
164
|
+
* `process.nextTick`, a promise `.then`/`.catch`/`.finally` continuation,
|
|
165
|
+
* or an `addEventListener` registration. Exported so the detector's
|
|
166
|
+
* deferral attribution consumes precisely the callbacks this module's
|
|
167
|
+
* `deferred` flag names — never a wider or narrower set (Constitution
|
|
168
|
+
* Principle I: the two walks agree on what "deferred" means).
|
|
169
|
+
*
|
|
170
|
+
* @param node The call expression.
|
|
171
|
+
* @returns Whether the callee matches the scheduling set.
|
|
172
|
+
*/
|
|
173
|
+
export declare function isSchedulingCall(node: CallExpression): boolean;
|
|
174
|
+
/**
|
|
175
|
+
* A function-like that owns its own extraction record (the R4 table's
|
|
176
|
+
* forms): a body-bearing function declaration, method, accessor, or
|
|
177
|
+
* constructor — the `body` presence the runtime predicate checks, with
|
|
178
|
+
* each declaration or member form's optional `FunctionBody` narrowed to a
|
|
179
|
+
* required `Block` — or an arrow or function expression, whose body is
|
|
180
|
+
* grammatically always present (`ConciseBody` and `FunctionBody`).
|
|
181
|
+
*/
|
|
182
|
+
export type ExtractedFunctionLike = ArrowFunction | FunctionExpression | (FunctionDeclaration & {
|
|
183
|
+
readonly body: Block;
|
|
184
|
+
}) | (MethodDeclaration & {
|
|
185
|
+
readonly body: Block;
|
|
186
|
+
}) | (ConstructorDeclaration & {
|
|
187
|
+
readonly body: Block;
|
|
188
|
+
}) | (GetAccessorDeclaration & {
|
|
189
|
+
readonly body: Block;
|
|
190
|
+
}) | (SetAccessorDeclaration & {
|
|
191
|
+
readonly body: Block;
|
|
192
|
+
});
|
|
193
|
+
/**
|
|
194
|
+
* Whether a function-like node is one of the R4 forms that owns its own
|
|
195
|
+
* extraction record — the shared half of the FR-009 attribution boundary:
|
|
196
|
+
* `extractFunctions` emits a record for exactly these, so a per-record
|
|
197
|
+
* consumer walk stops at exactly these (a nested form's constructs belong
|
|
198
|
+
* to its own record) and traverses unassigned function expressions into
|
|
199
|
+
* the enclosing record instead. The conditions mirror the walker dispatch
|
|
200
|
+
* above (body presence for the declaration and member forms, a
|
|
201
|
+
* name-giving parent position for the expression forms); exported so
|
|
202
|
+
* both per-record consumer walks — the complexity engine's attribution
|
|
203
|
+
* walk (FR-022) and the detector's FR-009 walk — consume the one form
|
|
204
|
+
* table with no duplicated dispatch to drift.
|
|
205
|
+
*
|
|
206
|
+
* @param node The node to test.
|
|
207
|
+
* @returns Whether the node's body belongs to its own extraction record.
|
|
208
|
+
*/
|
|
209
|
+
export declare function isExtractedFunctionLike(node: Node): node is ExtractedFunctionLike;
|