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,603 @@
|
|
|
1
|
+
// Assertion-to-effect inference — the fallback chains and US4's
|
|
2
|
+
// provenance passes (T018/T031; FR-009/FR-010/FR-011; research R7;
|
|
3
|
+
// data-model.md Sections 5.5 and 7; Constitution Principles I and II).
|
|
4
|
+
//
|
|
5
|
+
// `inferSideEffectType` answers the mapping row's `side_effect_type`:
|
|
6
|
+
// which canonical taxonomy name the assertion observes about its paired
|
|
7
|
+
// target. Error rows select by assertion kind alone (US4-5). Value rows
|
|
8
|
+
// run US4's four provenance passes in fixed order over the asserted
|
|
9
|
+
// expression — direct identity, indirect root resolution, helper
|
|
10
|
+
// bridging, inline call matching — and a succeeding pass prefers the
|
|
11
|
+
// return family (`ReturnValue` → `GeneratorYield` →
|
|
12
|
+
// `AsyncGeneratorYield`) ahead of the US1 fallback chain; with no
|
|
13
|
+
// succeeding pass, or no return-family effect to prefer, the fallback
|
|
14
|
+
// chain governs unchanged (US4-6/US4-7).
|
|
15
|
+
//
|
|
16
|
+
// The passes are conservative by pinned boundary (US4-8): they never
|
|
17
|
+
// cross nested functions other than the single pass-3 helper bridge,
|
|
18
|
+
// never follow alias chains, and never cross control-flow merges —
|
|
19
|
+
// unsupported provenance falls back deterministically rather than
|
|
20
|
+
// guessing. Every walk is depth-bounded by the shared
|
|
21
|
+
// `MAPPING_WALK_DEPTH_BUDGET`; a sentinel past the budget (or a
|
|
22
|
+
// materialization `RangeError`) is caught at the provenance boundary
|
|
23
|
+
// and treated as no evidence — the row still emits under the fallback
|
|
24
|
+
// chain, so nothing is skipped and no diagnostic is written, unlike
|
|
25
|
+
// the pairing and assertion walks whose budget skips lose rows.
|
|
26
|
+
//
|
|
27
|
+
// Inference is TOTAL (US1-7): every (assertion, effect-set) shape maps
|
|
28
|
+
// to a canonical name — a target with no detected effects at all maps
|
|
29
|
+
// the `ReturnValue` fallback, never an omission. The fallback chains are
|
|
30
|
+
// presence-based, not position-based: `ReturnValue` wins over an earlier
|
|
31
|
+
// P0 effect in the array, and `ErrorReturn` wins over an earlier
|
|
32
|
+
// `ErrorSignal` — only the P0 pass reads the array's order (the first
|
|
33
|
+
// P0 effect in effect-array order, the pin `detectEffects`'
|
|
34
|
+
// deterministic `(line, column, type)` emission makes stable).
|
|
35
|
+
import { isArrowFunction, isAwaitExpression, isBlock, isCallExpression, isElementAccessExpression, isFunctionDeclaration, isFunctionExpression, isIdentifier, isNewExpression, isParenthesizedExpression, isPropertyAccessExpression, isReturnStatement, isVariableDeclaration, isVariableStatement, NodeFlags, } from "typescript/unstable/ast";
|
|
36
|
+
import { collectBindingNames } from "../extract.js";
|
|
37
|
+
import { MAPPING_WALK_DEPTH_BUDGET } from "../internal.js";
|
|
38
|
+
import { resolveSymbolAliases } from "../program.js";
|
|
39
|
+
import { TIER_MAP } from "../taxonomy.js";
|
|
40
|
+
/** The error-row chain's first preference: the error-channel return effect. */
|
|
41
|
+
const ERROR_RETURN = "ErrorReturn";
|
|
42
|
+
/** The error-row chain's second preference: the error-channel signal effect. */
|
|
43
|
+
const ERROR_SIGNAL = "ErrorSignal";
|
|
44
|
+
/** The value-row chain's first preference and both chains' total fallback. */
|
|
45
|
+
const RETURN_VALUE = "ReturnValue";
|
|
46
|
+
/** The value-row chain's generator pass, ahead of the async form. */
|
|
47
|
+
const GENERATOR_YIELD = "GeneratorYield";
|
|
48
|
+
/** The value-row chain's final generator pass. */
|
|
49
|
+
const ASYNC_GENERATOR_YIELD = "AsyncGeneratorYield";
|
|
50
|
+
/**
|
|
51
|
+
* Whether the effect set carries an effect of the given canonical type.
|
|
52
|
+
*
|
|
53
|
+
* @param effects The target's detected effects, in effect-array order.
|
|
54
|
+
* @param type The canonical type to look for.
|
|
55
|
+
*/
|
|
56
|
+
function carries(effects, type) {
|
|
57
|
+
return effects.some((effect) => effect.type === type);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The error-row chain (FR-009; data-model Section 7): error rows —
|
|
61
|
+
* `assertion_type === "error_check"` — select by assertion type ALONE,
|
|
62
|
+
* never provenance (US4-5). `ErrorReturn` when the target carries it,
|
|
63
|
+
* else `ErrorSignal` when it carries that, else the `ErrorReturn`
|
|
64
|
+
* fallback — total over every effect-set shape including the empty set.
|
|
65
|
+
*
|
|
66
|
+
* @param effects The paired target's detected effects.
|
|
67
|
+
* @returns The mapped canonical side-effect type.
|
|
68
|
+
*/
|
|
69
|
+
function errorRowType(effects) {
|
|
70
|
+
if (carries(effects, ERROR_RETURN)) {
|
|
71
|
+
return ERROR_RETURN;
|
|
72
|
+
}
|
|
73
|
+
if (carries(effects, ERROR_SIGNAL)) {
|
|
74
|
+
return ERROR_SIGNAL;
|
|
75
|
+
}
|
|
76
|
+
return ERROR_RETURN;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* The value-row fallback chain (FR-010; data-model Section 7): value
|
|
80
|
+
* rows — every kind except `error_check` (`equality`, `nil_check`,
|
|
81
|
+
* `diff_check`, `custom`) — follow the standard chain:
|
|
82
|
+
*
|
|
83
|
+
* 1. `ReturnValue` when present (presence-based: it shadows a P0 effect
|
|
84
|
+
* that precedes it in the array);
|
|
85
|
+
* 2. else the target's FIRST P0 effect in effect-array order
|
|
86
|
+
* (`TIER_MAP` membership — the pin `detectEffects`' deterministic
|
|
87
|
+
* source-order emission makes stable);
|
|
88
|
+
* 3. else `GeneratorYield` when present;
|
|
89
|
+
* 4. else `AsyncGeneratorYield` when present;
|
|
90
|
+
* 5. else the `ReturnValue` fallback — total for every effect-set shape
|
|
91
|
+
* including the empty set (US1-7).
|
|
92
|
+
*
|
|
93
|
+
* @param effects The paired target's detected effects.
|
|
94
|
+
* @returns The mapped canonical side-effect type.
|
|
95
|
+
*/
|
|
96
|
+
function valueRowType(effects) {
|
|
97
|
+
if (carries(effects, RETURN_VALUE)) {
|
|
98
|
+
return RETURN_VALUE;
|
|
99
|
+
}
|
|
100
|
+
const firstP0 = effects.find((effect) => TIER_MAP[effect.type] === "P0");
|
|
101
|
+
if (firstP0 !== undefined) {
|
|
102
|
+
return firstP0.type;
|
|
103
|
+
}
|
|
104
|
+
if (carries(effects, GENERATOR_YIELD)) {
|
|
105
|
+
return GENERATOR_YIELD;
|
|
106
|
+
}
|
|
107
|
+
if (carries(effects, ASYNC_GENERATOR_YIELD)) {
|
|
108
|
+
return ASYNC_GENERATOR_YIELD;
|
|
109
|
+
}
|
|
110
|
+
return RETURN_VALUE;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* The provenance walks' depth sentinel: raised when a pass's AST walk
|
|
114
|
+
* passes the shared `MAPPING_WALK_DEPTH_BUDGET`, caught at the
|
|
115
|
+
* `provenanceEstablished` boundary — never escapes this module (the
|
|
116
|
+
* pairing.ts and assertions.ts sentinel discipline, each module owning
|
|
117
|
+
* its private copy). A `RangeError` from lazy node materialization is
|
|
118
|
+
* caught at the same site and treated identically.
|
|
119
|
+
*/
|
|
120
|
+
class MappingWalkDepthExceeded extends Error {
|
|
121
|
+
constructor() {
|
|
122
|
+
super("ast depth exceeds budget");
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Collects a test file's file-local helper table (pass 3's bridge
|
|
127
|
+
* domain): file-scope declared functions and const-bound function
|
|
128
|
+
* expressions — the two declaration forms research R7 pins.
|
|
129
|
+
*
|
|
130
|
+
* Statement top level only, and never entered: the scan reads the
|
|
131
|
+
* source's own statement list (no recursion, so no depth budget), and
|
|
132
|
+
* the const requirement is the conservative-boundary spirit (US4-8) —
|
|
133
|
+
* a `let`/`var` binding is reassignable, so its initializer proves
|
|
134
|
+
* nothing about any later call site. Overload signatures (a declared
|
|
135
|
+
* function with no body) are skipped: the checker's symbol for the
|
|
136
|
+
* callee carries the implementation's declaration, so the body-bearing
|
|
137
|
+
* twin is the bridge evidence. This is not a function-extraction walk —
|
|
138
|
+
* a helper here is evidence for pass 3, never a mapping target itself
|
|
139
|
+
* (test files are outside the target arm by construction, FR-006).
|
|
140
|
+
*
|
|
141
|
+
* @param sourceFile The test file's parsed source.
|
|
142
|
+
* @returns The helpers in statement order; `[]` for a file declaring none.
|
|
143
|
+
*/
|
|
144
|
+
export function collectFileLocalHelpers(sourceFile) {
|
|
145
|
+
const helpers = [];
|
|
146
|
+
for (const statement of sourceFile.statements) {
|
|
147
|
+
if (isFunctionDeclaration(statement)) {
|
|
148
|
+
if (statement.name !== undefined && statement.body !== undefined) {
|
|
149
|
+
helpers.push({
|
|
150
|
+
name: statement.name.text,
|
|
151
|
+
declaration: statement,
|
|
152
|
+
fn: statement,
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
if (!isVariableStatement(statement)) {
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
if ((statement.declarationList.flags & NodeFlags.Const) === 0) {
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
164
|
+
const initializer = declaration.initializer;
|
|
165
|
+
if (isIdentifier(declaration.name) &&
|
|
166
|
+
initializer !== undefined &&
|
|
167
|
+
(isArrowFunction(initializer) || isFunctionExpression(initializer))) {
|
|
168
|
+
helpers.push({ name: declaration.name.text, declaration, fn: initializer });
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return helpers;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Strips `await` and parenthesized wrappers — the transparency the
|
|
176
|
+
* passes pin for direct-call evidence (research R7: `const r = await
|
|
177
|
+
* target()`; the assertions module's anchor unwrapping is the same
|
|
178
|
+
* discipline, upward through parents). Bounded by the walk budget: an
|
|
179
|
+
* adversarial wrapper nest deeper than `MAPPING_WALK_DEPTH_BUDGET`
|
|
180
|
+
* raises the sentinel rather than looping.
|
|
181
|
+
*
|
|
182
|
+
* @param node The expression to unwrap.
|
|
183
|
+
* @returns The innermost expression that is neither wrapper form.
|
|
184
|
+
*/
|
|
185
|
+
function unwrapAwaitParens(node) {
|
|
186
|
+
let current = node;
|
|
187
|
+
for (let steps = 0; steps <= MAPPING_WALK_DEPTH_BUDGET; steps += 1) {
|
|
188
|
+
if (isParenthesizedExpression(current) || isAwaitExpression(current)) {
|
|
189
|
+
current = current.expression;
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
return current;
|
|
193
|
+
}
|
|
194
|
+
throw new MappingWalkDepthExceeded();
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Whether a call resolves to the pair's target, per mode (research R7):
|
|
198
|
+
* checker mode through the symbol route — `getSymbolAtLocation` at the
|
|
199
|
+
* callee's terminal identifier, aliases followed, any resolved
|
|
200
|
+
* declaration matching `pair.target.node` — and parse-only through
|
|
201
|
+
* terminal-identifier text equality with the target's declared name.
|
|
202
|
+
*
|
|
203
|
+
* This is the pairing `calls` strategy's `collectCallTarget` route in
|
|
204
|
+
* predicate form: the SAME terminal-identifier query node (the callee
|
|
205
|
+
* identifier, or the invoked property's name for a method callee —
|
|
206
|
+
* every other callee form resolves to nothing), the same
|
|
207
|
+
* alias-resolution and declaration matching — so a call that paired the
|
|
208
|
+
* test resolves for provenance and vice versa (Constitution Principle
|
|
209
|
+
* I: the two walks can never disagree on what "a call to the target"
|
|
210
|
+
* means).
|
|
211
|
+
*
|
|
212
|
+
* @param call The call expression to test.
|
|
213
|
+
* @param pair The test-to-target pair the row is being built for.
|
|
214
|
+
* @param context The live analysis context of the same run.
|
|
215
|
+
*/
|
|
216
|
+
function callResolvesToTarget(call, pair, context) {
|
|
217
|
+
const callee = call.expression;
|
|
218
|
+
const terminal = isIdentifier(callee)
|
|
219
|
+
? callee
|
|
220
|
+
: isPropertyAccessExpression(callee)
|
|
221
|
+
? callee.name
|
|
222
|
+
: null;
|
|
223
|
+
if (terminal === null) {
|
|
224
|
+
return false;
|
|
225
|
+
}
|
|
226
|
+
if (context.mode === "program") {
|
|
227
|
+
const { checker } = context;
|
|
228
|
+
const symbol = checker.getSymbolAtLocation(terminal);
|
|
229
|
+
const resolved = resolveSymbolAliases(checker, symbol);
|
|
230
|
+
if (resolved === null) {
|
|
231
|
+
return false;
|
|
232
|
+
}
|
|
233
|
+
for (const declaration of resolved.declarations) {
|
|
234
|
+
if (declaration.resolve() === pair.target.node) {
|
|
235
|
+
return true;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return false;
|
|
239
|
+
}
|
|
240
|
+
return terminal.text === pair.target.name;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Whether an expression is a direct call to the pair's target with
|
|
244
|
+
* `await`/paren transparency — the one spelling of "direct call" that
|
|
245
|
+
* pass 1's subject, pass 2's declarator initializer, and pass 3's
|
|
246
|
+
* helper returns all read (research R7).
|
|
247
|
+
*
|
|
248
|
+
* @param expression The expression to test.
|
|
249
|
+
* @param pair The test-to-target pair the row is being built for.
|
|
250
|
+
* @param context The live analysis context of the same run.
|
|
251
|
+
*/
|
|
252
|
+
function isDirectTargetCall(expression, pair, context) {
|
|
253
|
+
const unwrapped = unwrapAwaitParens(expression);
|
|
254
|
+
return isCallExpression(unwrapped) && callResolvesToTarget(unwrapped, pair, context);
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Walks the asserted expression's left spine: `await`/paren wrappers
|
|
258
|
+
* transparent, then down property accesses, element accesses, and
|
|
259
|
+
* call/new callees — the expression's head — until the walk roots at an
|
|
260
|
+
* identifier (returned with the bottom-most call it heads) or at any
|
|
261
|
+
* other node form (both null — a conditional, template, or binary
|
|
262
|
+
* expression root carries no single provenance subject, and the
|
|
263
|
+
* conservative answer is no evidence). Bounded by the walk budget.
|
|
264
|
+
*
|
|
265
|
+
* @param expression The asserted expression.
|
|
266
|
+
* @returns The spine's root identifier and root call.
|
|
267
|
+
*/
|
|
268
|
+
function spineRootOf(expression) {
|
|
269
|
+
let call = null;
|
|
270
|
+
let current = unwrapAwaitParens(expression);
|
|
271
|
+
for (let steps = 0; steps <= MAPPING_WALK_DEPTH_BUDGET; steps += 1) {
|
|
272
|
+
if (isPropertyAccessExpression(current) || isElementAccessExpression(current)) {
|
|
273
|
+
current = current.expression;
|
|
274
|
+
continue;
|
|
275
|
+
}
|
|
276
|
+
if (isCallExpression(current)) {
|
|
277
|
+
call = current;
|
|
278
|
+
current = current.expression;
|
|
279
|
+
continue;
|
|
280
|
+
}
|
|
281
|
+
if (isNewExpression(current)) {
|
|
282
|
+
current = current.expression;
|
|
283
|
+
continue;
|
|
284
|
+
}
|
|
285
|
+
return { identifier: isIdentifier(current) ? current : null, call };
|
|
286
|
+
}
|
|
287
|
+
throw new MappingWalkDepthExceeded();
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Pass 2 — indirect root resolution (FR-011; research R7): the root
|
|
291
|
+
* identifier is locally bound IN THE TEST FUNCTION by a declarator
|
|
292
|
+
* whose initializer is a direct call to the target — `await` wrappers
|
|
293
|
+
* and destructuring patterns transparent (`const r = await target()`,
|
|
294
|
+
* `const { items } = target()`, `const [first] = target()`).
|
|
295
|
+
*
|
|
296
|
+
* The binding search is the test callback's own declarators only
|
|
297
|
+
* (US4-8): a binding in a describe scope or an inner closure does not
|
|
298
|
+
* qualify — the walk starts at the callback's body and never enters a
|
|
299
|
+
* nested function-like. Alias chains never qualify (an initializer must
|
|
300
|
+
* be a call, never a bare identifier reference), and control-flow
|
|
301
|
+
* merges are structurally unreachable (only declarator initializers are
|
|
302
|
+
* read — a `let` assigned inside `if`/loop branches is never an
|
|
303
|
+
* initializer). Destructuring transparency reuses `collectBindingNames`
|
|
304
|
+
* — the one binding-spelling collector (the extract.ts export) — so
|
|
305
|
+
* every pattern form the scope tracker tracks is a form pass 2 binds.
|
|
306
|
+
*
|
|
307
|
+
* @param pair The test-to-target pair the row is being built for.
|
|
308
|
+
* @param identifier The asserted expression's root identifier text.
|
|
309
|
+
* @param context The live analysis context of the same run.
|
|
310
|
+
*/
|
|
311
|
+
function callbackBindsTargetCall(pair, identifier, context) {
|
|
312
|
+
const callback = pair.test.callback;
|
|
313
|
+
if (callback === null) {
|
|
314
|
+
return false;
|
|
315
|
+
}
|
|
316
|
+
if (!isFunctionExpression(callback) && !isArrowFunction(callback)) {
|
|
317
|
+
return false;
|
|
318
|
+
}
|
|
319
|
+
return declaratorsBindTargetCall(callback.body, identifier, pair, context, 0);
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* The pass-2 declarator walk: a descent over the test callback's body
|
|
323
|
+
* (the node before its children — irrelevant to the boolean result, but
|
|
324
|
+
* deterministic), nested function-likes excluded (their locals are not
|
|
325
|
+
* the test's). Depth-bounded by the shared budget; the sentinel raised
|
|
326
|
+
* past it is caught by `provenanceEstablished`.
|
|
327
|
+
*
|
|
328
|
+
* @param node The subtree root (the callback's body).
|
|
329
|
+
* @param identifier The root identifier text to find a binding for.
|
|
330
|
+
* @param pair The test-to-target pair the row is being built for.
|
|
331
|
+
* @param context The live analysis context of the same run.
|
|
332
|
+
* @param depth The current nesting depth (0 at the body root).
|
|
333
|
+
*/
|
|
334
|
+
function declaratorsBindTargetCall(node, identifier, pair, context, depth) {
|
|
335
|
+
if (depth > MAPPING_WALK_DEPTH_BUDGET) {
|
|
336
|
+
throw new MappingWalkDepthExceeded();
|
|
337
|
+
}
|
|
338
|
+
if (isFunctionDeclaration(node) ||
|
|
339
|
+
isFunctionExpression(node) ||
|
|
340
|
+
isArrowFunction(node)) {
|
|
341
|
+
return false;
|
|
342
|
+
}
|
|
343
|
+
if (isVariableDeclaration(node) && node.initializer !== undefined) {
|
|
344
|
+
const spellings = new Set();
|
|
345
|
+
collectBindingNames(node.name, spellings);
|
|
346
|
+
if (spellings.has(identifier) &&
|
|
347
|
+
isDirectTargetCall(node.initializer, pair, context)) {
|
|
348
|
+
return true;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
let found = false;
|
|
352
|
+
node.forEachChild((child) => {
|
|
353
|
+
if (!found) {
|
|
354
|
+
found = declaratorsBindTargetCall(child, identifier, pair, context, depth + 1);
|
|
355
|
+
}
|
|
356
|
+
});
|
|
357
|
+
return found;
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* Pass 3 — helper function bridging (FR-011; research R7): the spine's
|
|
361
|
+
* root call's callee is a file-local helper whose returned value
|
|
362
|
+
* derives from a direct call to the target — a `return [await]
|
|
363
|
+
* target(...)` statement in a block body, or an expression-bodied
|
|
364
|
+
* arrow whose expression IS the direct call.
|
|
365
|
+
*
|
|
366
|
+
* A SINGLE bridge (US4-8): the helper's own returns are read, never a
|
|
367
|
+
* helper-of-a-helper chain, and a returned closure does not bridge
|
|
368
|
+
* (its body runs only when the test invokes it — the returned value
|
|
369
|
+
* derives from the closure, not yet from the target). Checker mode
|
|
370
|
+
* resolves the callee through the symbol route onto the helper's
|
|
371
|
+
* declaring node; parse-only matches the declared name (the documented
|
|
372
|
+
* name-collision surface of lexical matching — degradation reduces
|
|
373
|
+
* precision, never availability).
|
|
374
|
+
*
|
|
375
|
+
* @param call The asserted expression's root call.
|
|
376
|
+
* @param helpers The test file's file-local helper table.
|
|
377
|
+
* @param pair The test-to-target pair the row is being built for.
|
|
378
|
+
* @param context The live analysis context of the same run.
|
|
379
|
+
*/
|
|
380
|
+
function helperBridgesTarget(call, helpers, pair, context) {
|
|
381
|
+
const callee = call.expression;
|
|
382
|
+
if (!isIdentifier(callee)) {
|
|
383
|
+
return false;
|
|
384
|
+
}
|
|
385
|
+
const helper = resolveHelper(callee, helpers, context);
|
|
386
|
+
return helper !== undefined && helperReturnsTargetCall(helper, pair, context);
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Resolves a root-call callee onto the helper table, per mode: checker
|
|
390
|
+
* mode through the symbol route (the callee symbol's resolved
|
|
391
|
+
* declarations matched against each helper's declaring node), parse-only
|
|
392
|
+
* through declared-name equality.
|
|
393
|
+
*
|
|
394
|
+
* @param callee The root call's identifier callee.
|
|
395
|
+
* @param helpers The test file's file-local helper table.
|
|
396
|
+
* @param context The live analysis context of the same run.
|
|
397
|
+
* @returns The helper the callee names, or undefined when none does.
|
|
398
|
+
*/
|
|
399
|
+
function resolveHelper(callee, helpers, context) {
|
|
400
|
+
if (context.mode === "program") {
|
|
401
|
+
const { checker } = context;
|
|
402
|
+
const symbol = checker.getSymbolAtLocation(callee);
|
|
403
|
+
const resolved = resolveSymbolAliases(checker, symbol);
|
|
404
|
+
if (resolved === null) {
|
|
405
|
+
return undefined;
|
|
406
|
+
}
|
|
407
|
+
return helpers.find((helper) => resolved.declarations.some((declaration) => declaration.resolve() === helper.declaration));
|
|
408
|
+
}
|
|
409
|
+
return helpers.find((helper) => helper.name === callee.text);
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* Whether a helper's returned value derives from a direct call to the
|
|
413
|
+
* target: an expression-bodied arrow whose expression IS the direct
|
|
414
|
+
* call (await/paren transparent), or a block body with at least one
|
|
415
|
+
* return statement whose expression is (research R7's `return [await]
|
|
416
|
+
* target(...)`).
|
|
417
|
+
*
|
|
418
|
+
* @param helper The bridge candidate helper.
|
|
419
|
+
* @param pair The test-to-target pair the row is being built for.
|
|
420
|
+
* @param context The live analysis context of the same run.
|
|
421
|
+
*/
|
|
422
|
+
function helperReturnsTargetCall(helper, pair, context) {
|
|
423
|
+
const body = helper.fn.body;
|
|
424
|
+
if (body === undefined) {
|
|
425
|
+
// A body-less fn (an overload signature) never reaches the table
|
|
426
|
+
// (`collectFileLocalHelpers` skips it); the guard keeps the type
|
|
427
|
+
// total over the function-like union.
|
|
428
|
+
return false;
|
|
429
|
+
}
|
|
430
|
+
if (!isBlock(body)) {
|
|
431
|
+
return isDirectTargetCall(body, pair, context);
|
|
432
|
+
}
|
|
433
|
+
return returnsTargetCall(body, pair, context, 0);
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* The pass-3 return walk: a descent over the helper's block body
|
|
437
|
+
* reading its return statements (the node before its children —
|
|
438
|
+
* deterministic), nested function-likes excluded (a return inside a
|
|
439
|
+
* nested function returns from THAT function, not the helper — US4-8's
|
|
440
|
+
* single-bridge boundary). Depth-bounded by the shared budget; the
|
|
441
|
+
* sentinel raised past it is caught by `provenanceEstablished`.
|
|
442
|
+
*
|
|
443
|
+
* @param node The subtree root (the helper's block body).
|
|
444
|
+
* @param pair The test-to-target pair the row is being built for.
|
|
445
|
+
* @param context The live analysis context of the same run.
|
|
446
|
+
* @param depth The current nesting depth (0 at the body root).
|
|
447
|
+
*/
|
|
448
|
+
function returnsTargetCall(node, pair, context, depth) {
|
|
449
|
+
if (depth > MAPPING_WALK_DEPTH_BUDGET) {
|
|
450
|
+
throw new MappingWalkDepthExceeded();
|
|
451
|
+
}
|
|
452
|
+
if (isFunctionDeclaration(node) ||
|
|
453
|
+
isFunctionExpression(node) ||
|
|
454
|
+
isArrowFunction(node)) {
|
|
455
|
+
return false;
|
|
456
|
+
}
|
|
457
|
+
if (isReturnStatement(node) &&
|
|
458
|
+
node.expression !== undefined &&
|
|
459
|
+
isDirectTargetCall(node.expression, pair, context)) {
|
|
460
|
+
return true;
|
|
461
|
+
}
|
|
462
|
+
let found = false;
|
|
463
|
+
node.forEachChild((child) => {
|
|
464
|
+
if (!found) {
|
|
465
|
+
found = returnsTargetCall(child, pair, context, depth + 1);
|
|
466
|
+
}
|
|
467
|
+
});
|
|
468
|
+
return found;
|
|
469
|
+
}
|
|
470
|
+
/**
|
|
471
|
+
* Pass 4 — inline call matching (FR-011; research R7; data-model
|
|
472
|
+
* Section 5.2's `argumentSubtree` pin): a call resolving to the target
|
|
473
|
+
* appears inline anywhere within the assertion's argument subtree — the
|
|
474
|
+
* invoked matcher invocation's full `CallExpression` for expect chains
|
|
475
|
+
* (spanning the `expect(...)` arguments and the matcher's own arguments
|
|
476
|
+
* — `expect(list).toContain(target(item))` scans `list` and
|
|
477
|
+
* `target(item)` alike), the assert call's full argument list for
|
|
478
|
+
* `node:assert` forms. Nested function-likes inside the subtree are
|
|
479
|
+
* included: the subtree sits inside the test callback — the same scan
|
|
480
|
+
* domain the `calls` pairing strategy reads — and US4-8's boundary pins
|
|
481
|
+
* govern the binding searches (passes 2 and 3), never this subtree
|
|
482
|
+
* scan. Depth-bounded by the shared budget.
|
|
483
|
+
*
|
|
484
|
+
* @param node The subtree root (the assertion's `argumentSubtree`).
|
|
485
|
+
* @param pair The test-to-target pair the row is being built for.
|
|
486
|
+
* @param context The live analysis context of the same run.
|
|
487
|
+
* @param depth The current nesting depth (0 at the subtree root).
|
|
488
|
+
*/
|
|
489
|
+
function subtreeCallsTarget(node, pair, context, depth) {
|
|
490
|
+
if (depth > MAPPING_WALK_DEPTH_BUDGET) {
|
|
491
|
+
throw new MappingWalkDepthExceeded();
|
|
492
|
+
}
|
|
493
|
+
if (isCallExpression(node) && callResolvesToTarget(node, pair, context)) {
|
|
494
|
+
return true;
|
|
495
|
+
}
|
|
496
|
+
let found = false;
|
|
497
|
+
node.forEachChild((child) => {
|
|
498
|
+
if (!found) {
|
|
499
|
+
found = subtreeCallsTarget(child, pair, context, depth + 1);
|
|
500
|
+
}
|
|
501
|
+
});
|
|
502
|
+
return found;
|
|
503
|
+
}
|
|
504
|
+
/**
|
|
505
|
+
* Runs the four passes in fixed order (FR-011; research R7): direct
|
|
506
|
+
* identity, indirect root resolution, helper bridging, inline call
|
|
507
|
+
* matching — the first succeeding pass establishes provenance. Passes
|
|
508
|
+
* 1-3 read the asserted expression (an absent asserted expression —
|
|
509
|
+
* `expect()` with no arguments — leaves pass 4, whose scan domain is
|
|
510
|
+
* the argument subtree); pass 4 always runs.
|
|
511
|
+
*
|
|
512
|
+
* The depth sentinel (and a materialization `RangeError`) is caught
|
|
513
|
+
* HERE as no evidence: nothing is skipped — the row still emits under
|
|
514
|
+
* the fallback chain — so no diagnostic is written, unlike the pairing
|
|
515
|
+
* and assertion walks whose budget skips lose rows. Anything else
|
|
516
|
+
* escapes (a crash is never a silent skip — the `collectAssertions`
|
|
517
|
+
* rethrow discipline).
|
|
518
|
+
*
|
|
519
|
+
* @param assertion The classified assertion site.
|
|
520
|
+
* @param pair The test-to-target pair the row is being built for.
|
|
521
|
+
* @param inputs The pass inputs — live context and helper table.
|
|
522
|
+
* @returns Whether any pass established provenance.
|
|
523
|
+
*/
|
|
524
|
+
function provenanceEstablished(assertion, pair, inputs) {
|
|
525
|
+
try {
|
|
526
|
+
const asserted = assertion.assertedExpression;
|
|
527
|
+
if (asserted !== null) {
|
|
528
|
+
// Pass 1 — direct identity: the asserted expression IS a direct
|
|
529
|
+
// target call (await/paren transparent).
|
|
530
|
+
if (isDirectTargetCall(asserted, pair, inputs.context)) {
|
|
531
|
+
return true;
|
|
532
|
+
}
|
|
533
|
+
const spine = spineRootOf(asserted);
|
|
534
|
+
// Pass 2 — indirect root resolution: the root identifier is bound
|
|
535
|
+
// in the test callback to the target's call result.
|
|
536
|
+
if (spine.identifier !== null &&
|
|
537
|
+
callbackBindsTargetCall(pair, spine.identifier.text, inputs.context)) {
|
|
538
|
+
return true;
|
|
539
|
+
}
|
|
540
|
+
// Pass 3 — helper bridging: the root call's helper returns the
|
|
541
|
+
// target's call result.
|
|
542
|
+
if (spine.call !== null &&
|
|
543
|
+
helperBridgesTarget(spine.call, inputs.helpers, pair, inputs.context)) {
|
|
544
|
+
return true;
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
// Pass 4 — inline call matching: a target call inside the
|
|
548
|
+
// assertion's argument subtree.
|
|
549
|
+
return subtreeCallsTarget(assertion.argumentSubtree, pair, inputs.context, 0);
|
|
550
|
+
}
|
|
551
|
+
catch (error) {
|
|
552
|
+
if (!(error instanceof MappingWalkDepthExceeded || error instanceof RangeError)) {
|
|
553
|
+
throw error;
|
|
554
|
+
}
|
|
555
|
+
return false;
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
/**
|
|
559
|
+
* Infers one mapping row's `side_effect_type` (FR-009/FR-010/FR-011;
|
|
560
|
+
* research R7; data-model Section 7): which canonical taxonomy name the
|
|
561
|
+
* assertion observes about its paired target.
|
|
562
|
+
*
|
|
563
|
+
* Error rows select by assertion type alone; value rows run US4's
|
|
564
|
+
* provenance passes ahead of the standard chain — a succeeding pass
|
|
565
|
+
* prefers the return family (`ReturnValue` → `GeneratorYield` →
|
|
566
|
+
* `AsyncGeneratorYield`), and with no return-family effect present, or
|
|
567
|
+
* no succeeding pass, the standard chain governs unchanged.
|
|
568
|
+
*
|
|
569
|
+
* Pure and total (Constitution Principles I and II): a deterministic
|
|
570
|
+
* function of the assertion's kind, the pair's AST evidence, and the
|
|
571
|
+
* target's effect set, defined for every shape including the empty set.
|
|
572
|
+
*
|
|
573
|
+
* @param assertion The classified assertion site.
|
|
574
|
+
* @param pair The test-to-target pair the row is being built for — the
|
|
575
|
+
* provenance-pass subject (unread by the fallback chains).
|
|
576
|
+
* @param effects The paired target's detected effects (`detectEffects`'
|
|
577
|
+
* output for its record), in effect-array order.
|
|
578
|
+
* @param provenance The pass inputs — live context and the test file's
|
|
579
|
+
* helper table. Optional so fallback-chain fixtures exercise FR-010 in
|
|
580
|
+
* isolation; the pipeline always supplies it.
|
|
581
|
+
* @returns The canonical side-effect type — one of the 48 taxonomy
|
|
582
|
+
* names, never an alias, never an omission.
|
|
583
|
+
*/
|
|
584
|
+
export function inferSideEffectType(assertion, pair, effects, provenance) {
|
|
585
|
+
if (assertion.kind === "error_check") {
|
|
586
|
+
return errorRowType(effects);
|
|
587
|
+
}
|
|
588
|
+
if (provenance !== undefined && provenanceEstablished(assertion, pair, provenance)) {
|
|
589
|
+
if (carries(effects, RETURN_VALUE)) {
|
|
590
|
+
return RETURN_VALUE;
|
|
591
|
+
}
|
|
592
|
+
if (carries(effects, GENERATOR_YIELD)) {
|
|
593
|
+
return GENERATOR_YIELD;
|
|
594
|
+
}
|
|
595
|
+
if (carries(effects, ASYNC_GENERATOR_YIELD)) {
|
|
596
|
+
return ASYNC_GENERATOR_YIELD;
|
|
597
|
+
}
|
|
598
|
+
// No return-family effect to prefer: the standard chain governs
|
|
599
|
+
// (US4-7 — provenance only reorders the return family ahead of it).
|
|
600
|
+
}
|
|
601
|
+
return valueRowType(effects);
|
|
602
|
+
}
|
|
603
|
+
//# sourceMappingURL=inference.js.map
|