carrick 0.3.139 → 0.3.141
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/package.json +6 -6
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/sidecar/dist/src/argument-modes.d.ts +56 -0
- package/sidecar/dist/src/argument-modes.js +448 -0
- package/sidecar/dist/src/capture/api.d.ts +11 -0
- package/sidecar/dist/src/capture/self-check.js +131 -1
- package/sidecar/dist/src/index.js +13 -20
- package/sidecar/dist/src/infer-cache.d.ts +0 -8
- package/sidecar/dist/src/infer-cache.js +0 -14
- package/sidecar/dist/src/library-claims.js +4 -3
- package/sidecar/dist/src/loop-element.d.ts +58 -0
- package/sidecar/dist/src/loop-element.js +307 -0
- package/sidecar/dist/src/origin.d.ts +10 -7
- package/sidecar/dist/src/origin.js +10 -7
- package/sidecar/dist/src/program-files.d.ts +34 -11
- package/sidecar/dist/src/program-files.js +52 -10
- package/sidecar/dist/src/project-loader.js +9 -0
- package/sidecar/dist/src/response-modes.d.ts +7 -2
- package/sidecar/dist/src/response-modes.js +1 -1
- package/sidecar/dist/src/retype-deferred.d.ts +34 -0
- package/sidecar/dist/src/retype-deferred.js +326 -0
- package/sidecar/dist/src/retype-selector.d.ts +43 -0
- package/sidecar/dist/src/retype-selector.js +217 -0
- package/sidecar/dist/src/retype.d.ts +11 -2
- package/sidecar/dist/src/retype.js +39 -14
- package/sidecar/dist/src/type-inferrer.d.ts +43 -7
- package/sidecar/dist/src/type-inferrer.js +232 -11
- package/sidecar/dist/src/types.d.ts +21 -1
- package/sidecar/dist/src/validators.d.ts +25 -12
- package/sidecar/dist/src/validators.js +2 -0
- package/templates/skills/carrick-reuse.md +1 -1
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether the type argument a retype fills can only SELECT (carrick#3158): in
|
|
3
|
+
* the call's result it appears as a conditional's check or extends type, or
|
|
4
|
+
* not at all. Such a call's result does not depend on the type stated, as
|
|
5
|
+
* long as the stated type is not a union, so the retype's "the call's type
|
|
6
|
+
* argument does not reach its result" can be answered before the rewrite for
|
|
7
|
+
* any stated type that is a new object type.
|
|
8
|
+
*
|
|
9
|
+
* Reads only the consumer's code. Every rule fails closed: a shape this
|
|
10
|
+
* file does not understand answers `false` and the call goes to the full
|
|
11
|
+
* retype, which is unchanged.
|
|
12
|
+
*
|
|
13
|
+
* C0 one signature, with type parameters and a written return type.
|
|
14
|
+
* C1 every type parameter after the first is closed: a written argument
|
|
15
|
+
* (explicit branch) or a default naming no type parameter. When the
|
|
16
|
+
* stated type breaks the first parameter's constraint, TypeScript fills
|
|
17
|
+
* unwritten arguments with their raw defaults, so a default that names
|
|
18
|
+
* a type parameter would change the result.
|
|
19
|
+
* C3 the call sits in no generic declaration: a producer type naming a
|
|
20
|
+
* type parameter in scope would defer the conditional.
|
|
21
|
+
* C2 the first parameter appears in the return type only in the check or
|
|
22
|
+
* extends type of a conditional that resolves (extends type without
|
|
23
|
+
* `infer`, only tracked type parameters named in either type).
|
|
24
|
+
*/
|
|
25
|
+
import { ts } from 'ts-morph';
|
|
26
|
+
import type { CallExpression } from 'ts-morph';
|
|
27
|
+
export declare function typeArgumentOnlySelects(call: CallExpression): boolean;
|
|
28
|
+
export declare function resolvedDeclaration(call: CallExpression): ts.SignatureDeclaration | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* C0: the declaration the call resolves to, when the callee has one call
|
|
31
|
+
* signature (not a union), that signature has type parameters, and its
|
|
32
|
+
* return type is written.
|
|
33
|
+
*/
|
|
34
|
+
export declare function singleSignatureDeclaration(call: CallExpression): (ts.SignatureDeclaration & {
|
|
35
|
+
type: ts.TypeNode;
|
|
36
|
+
}) | undefined;
|
|
37
|
+
/** Whether `test` holds for any direct child (`forEachChild` stops only on a truthy return). */
|
|
38
|
+
export declare function anyChild(node: ts.Node, test: (child: ts.Node) => boolean): boolean;
|
|
39
|
+
/** Names no type parameter, no `this` and no `typeof`. */
|
|
40
|
+
export declare function isClosedType(node: ts.Node, checker: ts.TypeChecker): boolean;
|
|
41
|
+
export declare function referencedSymbol(node: ts.TypeReferenceNode, checker: ts.TypeChecker): ts.Symbol | undefined;
|
|
42
|
+
export declare function isTypeParameter(node: ts.TypeReferenceNode, checker: ts.TypeChecker): boolean;
|
|
43
|
+
export declare function holdsInfer(node: ts.Node): boolean;
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether the type argument a retype fills can only SELECT (carrick#3158): in
|
|
3
|
+
* the call's result it appears as a conditional's check or extends type, or
|
|
4
|
+
* not at all. Such a call's result does not depend on the type stated, as
|
|
5
|
+
* long as the stated type is not a union, so the retype's "the call's type
|
|
6
|
+
* argument does not reach its result" can be answered before the rewrite for
|
|
7
|
+
* any stated type that is a new object type.
|
|
8
|
+
*
|
|
9
|
+
* Reads only the consumer's code. Every rule fails closed: a shape this
|
|
10
|
+
* file does not understand answers `false` and the call goes to the full
|
|
11
|
+
* retype, which is unchanged.
|
|
12
|
+
*
|
|
13
|
+
* C0 one signature, with type parameters and a written return type.
|
|
14
|
+
* C1 every type parameter after the first is closed: a written argument
|
|
15
|
+
* (explicit branch) or a default naming no type parameter. When the
|
|
16
|
+
* stated type breaks the first parameter's constraint, TypeScript fills
|
|
17
|
+
* unwritten arguments with their raw defaults, so a default that names
|
|
18
|
+
* a type parameter would change the result.
|
|
19
|
+
* C3 the call sits in no generic declaration: a producer type naming a
|
|
20
|
+
* type parameter in scope would defer the conditional.
|
|
21
|
+
* C2 the first parameter appears in the return type only in the check or
|
|
22
|
+
* extends type of a conditional that resolves (extends type without
|
|
23
|
+
* `infer`, only tracked type parameters named in either type).
|
|
24
|
+
*/
|
|
25
|
+
import { Node, ts } from 'ts-morph';
|
|
26
|
+
const MAX_DEPTH = 64;
|
|
27
|
+
export function typeArgumentOnlySelects(call) {
|
|
28
|
+
// A producer type may name a type parameter in scope at the call. The
|
|
29
|
+
// conditional then defers and the stated type reaches the result, so the
|
|
30
|
+
// full retype must judge it.
|
|
31
|
+
if (call.getAncestors().some((a) => Node.isTypeParametered(a) && a.getTypeParameters().length > 0)) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
const typeArgs = call.getTypeArguments();
|
|
35
|
+
const checker = call.getProject().getTypeChecker().compilerObject;
|
|
36
|
+
const declaration = singleSignatureDeclaration(call);
|
|
37
|
+
const parameters = declaration?.typeParameters;
|
|
38
|
+
if (!declaration || !parameters)
|
|
39
|
+
return false;
|
|
40
|
+
const explicit = typeArgs.length > 0;
|
|
41
|
+
if (typeArgs.length > parameters.length)
|
|
42
|
+
return false;
|
|
43
|
+
// C1.
|
|
44
|
+
const roles = new Map();
|
|
45
|
+
for (let i = 0; i < parameters.length; i++) {
|
|
46
|
+
const symbol = checker.getSymbolAtLocation(parameters[i].name);
|
|
47
|
+
if (!symbol)
|
|
48
|
+
return false;
|
|
49
|
+
if (i === 0) {
|
|
50
|
+
roles.set(symbol, 'D');
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
const written = explicit && i < typeArgs.length ? typeArgs[i].compilerNode : undefined;
|
|
54
|
+
const source = written ?? parameters[i].default;
|
|
55
|
+
if (!source || !isClosedType(source, checker))
|
|
56
|
+
return false;
|
|
57
|
+
roles.set(symbol, 'closed');
|
|
58
|
+
}
|
|
59
|
+
// C2.
|
|
60
|
+
return selectsOnly(declaration.type, roles, checker, new Set(), 0);
|
|
61
|
+
}
|
|
62
|
+
export function resolvedDeclaration(call) {
|
|
63
|
+
const signature = call
|
|
64
|
+
.getProject()
|
|
65
|
+
.getTypeChecker()
|
|
66
|
+
.compilerObject.getResolvedSignature(call.compilerNode);
|
|
67
|
+
return signature?.getDeclaration();
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* C0: the declaration the call resolves to, when the callee has one call
|
|
71
|
+
* signature (not a union), that signature has type parameters, and its
|
|
72
|
+
* return type is written.
|
|
73
|
+
*/
|
|
74
|
+
export function singleSignatureDeclaration(call) {
|
|
75
|
+
const declaration = resolvedDeclaration(call);
|
|
76
|
+
const parameters = declaration?.typeParameters;
|
|
77
|
+
if (!declaration || !parameters || parameters.length === 0 || !declaration.type)
|
|
78
|
+
return undefined;
|
|
79
|
+
const callee = call.getExpression().getType();
|
|
80
|
+
if (callee.isUnion() || callee.getCallSignatures().length !== 1)
|
|
81
|
+
return undefined;
|
|
82
|
+
return declaration;
|
|
83
|
+
}
|
|
84
|
+
/** Whether `test` holds for any direct child (`forEachChild` stops only on a truthy return). */
|
|
85
|
+
export function anyChild(node, test) {
|
|
86
|
+
return ts.forEachChild(node, (child) => (test(child) ? true : undefined)) ?? false;
|
|
87
|
+
}
|
|
88
|
+
/** Names no type parameter, no `this` and no `typeof`. */
|
|
89
|
+
export function isClosedType(node, checker) {
|
|
90
|
+
if (ts.isTypeQueryNode(node) || ts.isThisTypeNode(node))
|
|
91
|
+
return false;
|
|
92
|
+
if (ts.isTypeReferenceNode(node) && isTypeParameter(node, checker))
|
|
93
|
+
return false;
|
|
94
|
+
return !anyChild(node, (child) => !isClosedType(child, checker));
|
|
95
|
+
}
|
|
96
|
+
export function referencedSymbol(node, checker) {
|
|
97
|
+
const name = ts.isQualifiedName(node.typeName) ? node.typeName.right : node.typeName;
|
|
98
|
+
const symbol = checker.getSymbolAtLocation(name);
|
|
99
|
+
if (symbol && symbol.flags & ts.SymbolFlags.Alias) {
|
|
100
|
+
try {
|
|
101
|
+
return checker.getAliasedSymbol(symbol);
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
return symbol;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return symbol;
|
|
108
|
+
}
|
|
109
|
+
export function isTypeParameter(node, checker) {
|
|
110
|
+
const symbol = referencedSymbol(node, checker);
|
|
111
|
+
return !!symbol && (symbol.flags & ts.SymbolFlags.TypeParameter) !== 0;
|
|
112
|
+
}
|
|
113
|
+
/** Whether `node` names a type parameter whose role is `D`. */
|
|
114
|
+
function namesD(node, roles, checker) {
|
|
115
|
+
if (ts.isTypeReferenceNode(node)) {
|
|
116
|
+
const symbol = referencedSymbol(node, checker);
|
|
117
|
+
if (symbol && roles.get(symbol) === 'D')
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
return anyChild(node, (child) => namesD(child, roles, checker));
|
|
121
|
+
}
|
|
122
|
+
/** A conditional's check or extends type: tracked parameters only. */
|
|
123
|
+
function namesOnlyTracked(node, roles, checker) {
|
|
124
|
+
if (ts.isThisTypeNode(node) || ts.isTypeQueryNode(node))
|
|
125
|
+
return false;
|
|
126
|
+
if (ts.isTypeReferenceNode(node)) {
|
|
127
|
+
const symbol = referencedSymbol(node, checker);
|
|
128
|
+
if (symbol && symbol.flags & ts.SymbolFlags.TypeParameter && !roles.has(symbol))
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
return !anyChild(node, (child) => !namesOnlyTracked(child, roles, checker));
|
|
132
|
+
}
|
|
133
|
+
export function holdsInfer(node) {
|
|
134
|
+
if (ts.isInferTypeNode(node))
|
|
135
|
+
return true;
|
|
136
|
+
return anyChild(node, holdsInfer);
|
|
137
|
+
}
|
|
138
|
+
/** C2: `D` reaches nothing in `node` except as a resolving conditional's selector. */
|
|
139
|
+
function selectsOnly(node, roles, checker, visiting, depth) {
|
|
140
|
+
if (depth > MAX_DEPTH)
|
|
141
|
+
return false;
|
|
142
|
+
if (ts.isTypeQueryNode(node))
|
|
143
|
+
return false;
|
|
144
|
+
if (ts.isConditionalTypeNode(node) && namesD(node, roles, checker)) {
|
|
145
|
+
if (holdsInfer(node.extendsType))
|
|
146
|
+
return false;
|
|
147
|
+
if (!namesOnlyTracked(node.checkType, roles, checker) ||
|
|
148
|
+
!namesOnlyTracked(node.extendsType, roles, checker)) {
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
return (selectsOnly(node.trueType, roles, checker, visiting, depth + 1) &&
|
|
152
|
+
selectsOnly(node.falseType, roles, checker, visiting, depth + 1));
|
|
153
|
+
}
|
|
154
|
+
if (ts.isTypeReferenceNode(node)) {
|
|
155
|
+
const symbol = referencedSymbol(node, checker);
|
|
156
|
+
if (!symbol)
|
|
157
|
+
return !namesD(node, roles, checker);
|
|
158
|
+
if (symbol.flags & ts.SymbolFlags.TypeParameter)
|
|
159
|
+
return roles.get(symbol) !== 'D';
|
|
160
|
+
if (symbol.flags & ts.SymbolFlags.TypeAlias) {
|
|
161
|
+
if (!namesD(node, roles, checker))
|
|
162
|
+
return true;
|
|
163
|
+
return aliasSelectsOnly(node, symbol, roles, checker, visiting, depth);
|
|
164
|
+
}
|
|
165
|
+
// An interface, a class or an enum: its arguments are read like any node.
|
|
166
|
+
}
|
|
167
|
+
return !anyChild(node, (child) => !selectsOnly(child, roles, checker, visiting, depth + 1));
|
|
168
|
+
}
|
|
169
|
+
/** A reference to a type alias whose arguments name `D`: walk the alias. */
|
|
170
|
+
function aliasSelectsOnly(node, symbol, roles, checker, visiting, depth) {
|
|
171
|
+
// A JSDoc typedef, or an alias this cannot read, has `D` among its
|
|
172
|
+
// arguments: not decided.
|
|
173
|
+
const declaration = symbol.declarations?.find(ts.isTypeAliasDeclaration);
|
|
174
|
+
if (!declaration || symbol.declarations?.length !== 1)
|
|
175
|
+
return false;
|
|
176
|
+
if (visiting.has(symbol))
|
|
177
|
+
return false;
|
|
178
|
+
const parameters = declaration.typeParameters ?? [];
|
|
179
|
+
const args = node.typeArguments ?? [];
|
|
180
|
+
if (args.length > parameters.length)
|
|
181
|
+
return false;
|
|
182
|
+
const inner = new Map();
|
|
183
|
+
for (let i = 0; i < parameters.length; i++) {
|
|
184
|
+
const parameter = checker.getSymbolAtLocation(parameters[i].name);
|
|
185
|
+
if (!parameter)
|
|
186
|
+
return false;
|
|
187
|
+
const written = i < args.length ? args[i] : undefined;
|
|
188
|
+
const source = written ?? parameters[i].default;
|
|
189
|
+
if (!source)
|
|
190
|
+
return false;
|
|
191
|
+
// The scope the argument is read in: the caller's, or the alias's own for
|
|
192
|
+
// a default.
|
|
193
|
+
const scope = written ? roles : inner;
|
|
194
|
+
if (!namesD(source, scope, checker)) {
|
|
195
|
+
inner.set(parameter, 'closed');
|
|
196
|
+
}
|
|
197
|
+
else if (bareD(source, scope, checker)) {
|
|
198
|
+
inner.set(parameter, 'D');
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
return false;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
visiting.add(symbol);
|
|
205
|
+
const ok = selectsOnly(declaration.type, inner, checker, visiting, depth + 1);
|
|
206
|
+
visiting.delete(symbol);
|
|
207
|
+
return ok;
|
|
208
|
+
}
|
|
209
|
+
/** `D` itself, not a type built from it. */
|
|
210
|
+
function bareD(node, roles, checker) {
|
|
211
|
+
if (ts.isParenthesizedTypeNode(node))
|
|
212
|
+
return bareD(node.type, roles, checker);
|
|
213
|
+
if (!ts.isTypeReferenceNode(node) || node.typeArguments?.length)
|
|
214
|
+
return false;
|
|
215
|
+
const symbol = referencedSymbol(node, checker);
|
|
216
|
+
return !!symbol && roles.get(symbol) === 'D';
|
|
217
|
+
}
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
import { ts } from 'ts-morph';
|
|
28
28
|
import type { Project } from 'ts-morph';
|
|
29
29
|
import type { TypeInferrer } from './type-inferrer.js';
|
|
30
|
-
import type { RetypeItem, RetypeLocatorItem, RetypeOutcome } from './types.js';
|
|
30
|
+
import type { RetypeItem, RetypeLocatorItem, RetypeOutcome, RetypePrescreen } from './types.js';
|
|
31
31
|
/**
|
|
32
32
|
* The check phase's structural any/unknown walk (`findDisqualifyingTopTypes`
|
|
33
33
|
* in the capture bundle): member paths below `root` that hold a top type.
|
|
@@ -67,7 +67,7 @@ export declare class Retyper {
|
|
|
67
67
|
* program. A call that throws here is left to the retype, which reports
|
|
68
68
|
* the failure itself.
|
|
69
69
|
*/
|
|
70
|
-
prescreen(items: RetypeLocatorItem[]): Array<
|
|
70
|
+
prescreen(items: RetypeLocatorItem[]): Array<Omit<RetypePrescreen, 'item_id'>>;
|
|
71
71
|
/**
|
|
72
72
|
* The call and how to state a type at it, or why the retype abstains
|
|
73
73
|
* before any rewrite. Reads only the consumer's own code: the producer's
|
|
@@ -124,4 +124,13 @@ export declare class Retyper {
|
|
|
124
124
|
* consumer against the wrong thing, so the item abstains.
|
|
125
125
|
*/
|
|
126
126
|
private typeArgumentReachesResult;
|
|
127
|
+
/** What the call yields once awaited: the type the reach test compares. */
|
|
128
|
+
private resultOf;
|
|
129
|
+
/**
|
|
130
|
+
* The abstention for a call whose type argument is not in its result. The
|
|
131
|
+
* one place the sentence is built: the reach test gives it after the
|
|
132
|
+
* rewrite, and the prescreen gives it before one (carrick#3158), so the two
|
|
133
|
+
* can never word it differently.
|
|
134
|
+
*/
|
|
135
|
+
private notReachedReason;
|
|
127
136
|
}
|
|
@@ -25,10 +25,13 @@
|
|
|
25
25
|
* project other requests read is the project the scan loaded.
|
|
26
26
|
*/
|
|
27
27
|
import { Node, SyntaxKind, ts } from 'ts-morph';
|
|
28
|
+
import { replaceFileText } from './program-files.js';
|
|
28
29
|
import { readsResponseStatus, statusesIn, SUCCEEDED, testsOnPath, } from './failure-path.js';
|
|
29
30
|
import { statesNoBody } from './capture/index.js';
|
|
30
31
|
import { lineIndex } from './line-index.js';
|
|
31
32
|
import { typeToStringAsDeclared } from './print-type.js';
|
|
33
|
+
import { deferredResultNeedsUndefined } from './retype-deferred.js';
|
|
34
|
+
import { resolvedDeclaration, typeArgumentOnlySelects } from './retype-selector.js';
|
|
32
35
|
import { fileDiagnostics } from './unwidened.js';
|
|
33
36
|
/** Names appended to a file that is not ours carry this prefix. */
|
|
34
37
|
const PREFIX = '__carrick_';
|
|
@@ -155,10 +158,24 @@ export class Retyper {
|
|
|
155
158
|
return items.map((item) => {
|
|
156
159
|
try {
|
|
157
160
|
const found = this.beforeRewrite(item);
|
|
158
|
-
|
|
161
|
+
if (typeof found === 'string')
|
|
162
|
+
return { reason: found };
|
|
163
|
+
// carrick#3158: no producer type is read here, so this is only the
|
|
164
|
+
// reason the retype would give for ANY object type literal; the
|
|
165
|
+
// scanner applies it when the producer's type is one.
|
|
166
|
+
if (typeArgumentOnlySelects(found.call)) {
|
|
167
|
+
return { fresh_type_reason: this.notReachedReason(found.call) };
|
|
168
|
+
}
|
|
169
|
+
// carrick#3165: a deferred result whose every member holds an
|
|
170
|
+
// `undefined` the stated type does not reach. The scanner applies it
|
|
171
|
+
// when the producer's type has no top-level `undefined`. The quoted
|
|
172
|
+
// type is the call's own result, as no producer type is read here.
|
|
173
|
+
return deferredResultNeedsUndefined(found.call)
|
|
174
|
+
? { undefined_free_reason: this.notReachedReason(found.call) }
|
|
175
|
+
: {};
|
|
159
176
|
}
|
|
160
177
|
catch {
|
|
161
|
-
return
|
|
178
|
+
return {};
|
|
162
179
|
}
|
|
163
180
|
});
|
|
164
181
|
}
|
|
@@ -303,7 +320,7 @@ export class Retyper {
|
|
|
303
320
|
const rewritten = applyEdits(original, rewrite.edits) + appendix;
|
|
304
321
|
const bodyEnd = rewritten.length - appendix.length;
|
|
305
322
|
const originOf = (pos) => pos >= bodyEnd ? { kind: 'inserted' } : mapBack(pos, rewrite.edits);
|
|
306
|
-
sourceFile
|
|
323
|
+
replaceFileText(sourceFile, rewritten);
|
|
307
324
|
try {
|
|
308
325
|
if (rewrite.typeArgumentCall) {
|
|
309
326
|
const reached = this.typeArgumentReachesResult(sourceFile, rewrite.typeArgumentCall);
|
|
@@ -349,7 +366,7 @@ export class Retyper {
|
|
|
349
366
|
return { kind: 'checked', added };
|
|
350
367
|
}
|
|
351
368
|
finally {
|
|
352
|
-
sourceFile
|
|
369
|
+
replaceFileText(sourceFile, original);
|
|
353
370
|
}
|
|
354
371
|
}
|
|
355
372
|
/**
|
|
@@ -430,8 +447,7 @@ export class Retyper {
|
|
|
430
447
|
if (!stated)
|
|
431
448
|
return 'the retyped call carries no type argument';
|
|
432
449
|
const checker = this.project.getTypeChecker().compilerObject;
|
|
433
|
-
const
|
|
434
|
-
const result = checker.getAwaitedType(returned) ?? returned;
|
|
450
|
+
const result = this.resultOf(call);
|
|
435
451
|
const target = stated.compilerType;
|
|
436
452
|
if (result === target)
|
|
437
453
|
return true;
|
|
@@ -449,8 +465,24 @@ export class Retyper {
|
|
|
449
465
|
if (checker.getTypeOfSymbolAtLocation(property, call.compilerNode) === target)
|
|
450
466
|
return true;
|
|
451
467
|
}
|
|
468
|
+
return this.notReachedReason(call);
|
|
469
|
+
}
|
|
470
|
+
/** What the call yields once awaited: the type the reach test compares. */
|
|
471
|
+
resultOf(call) {
|
|
472
|
+
const checker = this.project.getTypeChecker().compilerObject;
|
|
473
|
+
const returned = call.getType().compilerType;
|
|
474
|
+
return checker.getAwaitedType(returned) ?? returned;
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* The abstention for a call whose type argument is not in its result. The
|
|
478
|
+
* one place the sentence is built: the reach test gives it after the
|
|
479
|
+
* rewrite, and the prescreen gives it before one (carrick#3158), so the two
|
|
480
|
+
* can never word it differently.
|
|
481
|
+
*/
|
|
482
|
+
notReachedReason(call) {
|
|
483
|
+
const checker = this.project.getTypeChecker().compilerObject;
|
|
452
484
|
return ("the call's type argument does not reach its result " +
|
|
453
|
-
`('${checker.typeToString(
|
|
485
|
+
`('${checker.typeToString(this.resultOf(call))}'), so it does not state the response`);
|
|
454
486
|
}
|
|
455
487
|
}
|
|
456
488
|
function abstain(item, reason) {
|
|
@@ -490,13 +522,6 @@ function resultIsDiscarded(call) {
|
|
|
490
522
|
}
|
|
491
523
|
return !!parent && Node.isExpressionStatement(parent);
|
|
492
524
|
}
|
|
493
|
-
function resolvedDeclaration(call) {
|
|
494
|
-
const signature = call
|
|
495
|
-
.getProject()
|
|
496
|
-
.getTypeChecker()
|
|
497
|
-
.compilerObject.getResolvedSignature(call.compilerNode);
|
|
498
|
-
return signature?.getDeclaration();
|
|
499
|
-
}
|
|
500
525
|
/**
|
|
501
526
|
* Why the call's result leaves what this file's type-check can see, or
|
|
502
527
|
* `undefined` when every use of it stays in view.
|
|
@@ -108,13 +108,6 @@ export type InferRequestDone = () => void;
|
|
|
108
108
|
* every request is done, so this is what keeps a long one from going silent.
|
|
109
109
|
*/
|
|
110
110
|
export type UnwidenedStepDone = () => void;
|
|
111
|
-
/**
|
|
112
|
-
* TypeInferrer - Extracts types from source code, both explicit and inferred
|
|
113
|
-
*
|
|
114
|
-
* Usage:
|
|
115
|
-
* const inferrer = new TypeInferrer({ project });
|
|
116
|
-
* const result = inferrer.infer(requests, extractionConfig);
|
|
117
|
-
*/
|
|
118
111
|
export declare class TypeInferrer {
|
|
119
112
|
private readonly project;
|
|
120
113
|
private readonly packageOf;
|
|
@@ -187,6 +180,23 @@ export declare class TypeInferrer {
|
|
|
187
180
|
* carrick#1836: list on `result` the declarations behind the names its text
|
|
188
181
|
* prints that the request's file cannot resolve (`PrintedTypes.namesIn`).
|
|
189
182
|
*/
|
|
183
|
+
/** `inferSingle`, with what the names it prints meant (carrick#1836). */
|
|
184
|
+
private inferRecordingNames;
|
|
185
|
+
/**
|
|
186
|
+
* carrick#1029: the loop element a route row's path names, when its
|
|
187
|
+
* registration is made once per element of a constant list
|
|
188
|
+
* (`loop-element.ts`). Only a route row that states its path is read.
|
|
189
|
+
*/
|
|
190
|
+
private loopPickFor;
|
|
191
|
+
/**
|
|
192
|
+
* The request inferred with the loop's list rewritten to the one element
|
|
193
|
+
* `pick` names, so the compiler types the handler for that element. The
|
|
194
|
+
* file is restored before returning, and the names the reading prints are
|
|
195
|
+
* recorded while the rewritten program is still the project's. Lines do not
|
|
196
|
+
* move (the rewrite is padded); a span after the list moves by the length
|
|
197
|
+
* the rewrite changed.
|
|
198
|
+
*/
|
|
199
|
+
private inferForLoopElement;
|
|
190
200
|
private recordPrintedNames;
|
|
191
201
|
/**
|
|
192
202
|
* carrick#1516: read each response inference again with the literals on its
|
|
@@ -453,6 +463,32 @@ export declare class TypeInferrer {
|
|
|
453
463
|
* or the redirect location back in.
|
|
454
464
|
*/
|
|
455
465
|
private inferFromResponseSites;
|
|
466
|
+
/**
|
|
467
|
+
* carrick#2372: what `func` returns when it returns one call into a
|
|
468
|
+
* function of the program: see `callNarrowedByArguments`.
|
|
469
|
+
*/
|
|
470
|
+
private returnNarrowedByArguments;
|
|
471
|
+
/**
|
|
472
|
+
* carrick#2372: the one member of `awaited` (the awaited result type of
|
|
473
|
+
* `call`) the called function's returns can give for the arguments `call`
|
|
474
|
+
* passes, and the parameters the callee tests that those arguments state.
|
|
475
|
+
* `undefined` when `call` runs no function of the program (or runs
|
|
476
|
+
* `caller` itself), or its result is not a union.
|
|
477
|
+
*
|
|
478
|
+
* Each kept return is matched to the union members it is assignable to; a
|
|
479
|
+
* return that matches none (another union, a call) keeps every member, as
|
|
480
|
+
* does a narrowing that leaves more than one member.
|
|
481
|
+
*/
|
|
482
|
+
private callNarrowedByArguments;
|
|
483
|
+
/**
|
|
484
|
+
* carrick#2372: a union read from an executor whose bodies depend on
|
|
485
|
+
* arguments the route passes, where those arguments could not tell the
|
|
486
|
+
* bodies apart. Each such parameter is listed as an `argument` read, so a
|
|
487
|
+
* mismatch against the union is not reported as this route's: no call can
|
|
488
|
+
* say which body the route sends.
|
|
489
|
+
*/
|
|
490
|
+
private withArgumentReads;
|
|
491
|
+
private addArgumentReads;
|
|
456
492
|
/**
|
|
457
493
|
* The response sends `func` makes as statements (`res.status(409).json(e);`),
|
|
458
494
|
* for a handler that sends through a parameter and returns nothing. Only the
|