@cplieger/deadset-ts 8.0.0-dev.20 → 8.0.0-dev.21
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/dist/src/alias-chain.js +33 -2
- package/dist/src/analysis.js +18 -77
- package/dist/src/conformance-record.js +2 -2
- package/dist/src/contract/contract.generated.js +4 -3
- package/dist/src/dependencies.js +1 -1
- package/dist/src/exemptions/argument-places.js +131 -0
- package/dist/src/{calls.js → exemptions/calls.js} +126 -179
- package/dist/src/{exempt-classes.js → exemptions/classes.js} +1 -1
- package/dist/src/{decorator.js → exemptions/decorator.js} +19 -30
- package/dist/src/exemptions/detectors.js +48 -0
- package/dist/src/{enum-group.js → exemptions/enum-group.js} +7 -7
- package/dist/src/{erased-stores.js → exemptions/erased-stores.js} +4 -6
- package/dist/src/{framework-lifecycle.js → exemptions/framework-lifecycle.js} +31 -36
- package/dist/src/{generated-file.js → exemptions/generated-file.js} +4 -4
- package/dist/src/{injection-container.js → exemptions/injection-container.js} +19 -25
- package/dist/src/exemptions/installed-globals.js +173 -0
- package/dist/src/{interface-satisfaction.js → exemptions/interface-satisfaction.js} +52 -121
- package/dist/src/exemptions/lifecycle.js +150 -0
- package/dist/src/{reflective-lookup.js → exemptions/reflective-lookup.js} +3 -3
- package/dist/src/{serialization-contract.js → exemptions/serialization-contract.js} +415 -329
- package/dist/src/exemptions/sites.js +182 -0
- package/dist/src/{template-field.js → exemptions/template-field.js} +7 -7
- package/dist/src/{value-reach.js → exemptions/value-reach.js} +14 -7
- package/dist/src/index/sites.js +1 -1
- package/dist/src/index/values.js +124 -0
- package/dist/src/liveness/sweep.js +2 -2
- package/dist/src/query.js +48 -0
- package/dist/src/roots/configured-declarations.js +1 -1
- package/dist/src/verbs/print-retained.js +23 -1
- package/jsr.json +1 -1
- package/package.json +1 -1
- package/src/alias-chain.ts +38 -2
- package/src/analysis.ts +19 -100
- package/src/bindings.ts +1 -1
- package/src/conformance-record.ts +2 -2
- package/src/contract/contract.generated.ts +4 -3
- package/src/dependencies.ts +1 -1
- package/src/exemptions/argument-places.ts +198 -0
- package/src/{calls.ts → exemptions/calls.ts} +190 -224
- package/src/{exempt-classes.ts → exemptions/classes.ts} +1 -1
- package/src/exemptions/decorator.ts +56 -0
- package/src/exemptions/detectors.ts +75 -0
- package/src/{enum-group.ts → exemptions/enum-group.ts} +9 -9
- package/src/{erased-stores.ts → exemptions/erased-stores.ts} +5 -8
- package/src/{framework-lifecycle.ts → exemptions/framework-lifecycle.ts} +39 -48
- package/src/{generated-file.ts → exemptions/generated-file.ts} +6 -6
- package/src/{injection-container.ts → exemptions/injection-container.ts} +28 -33
- package/src/exemptions/installed-globals.ts +255 -0
- package/src/{interface-satisfaction.ts → exemptions/interface-satisfaction.ts} +69 -160
- package/src/exemptions/lifecycle.ts +286 -0
- package/src/{reflective-lookup.ts → exemptions/reflective-lookup.ts} +5 -5
- package/src/{serialization-contract.ts → exemptions/serialization-contract.ts} +563 -429
- package/src/exemptions/sites.ts +293 -0
- package/src/{template-field.ts → exemptions/template-field.ts} +11 -11
- package/src/{value-reach.ts → exemptions/value-reach.ts} +16 -8
- package/src/facts.ts +1 -1
- package/src/index/sites.ts +1 -1
- package/src/index/values.ts +170 -0
- package/src/liveness/sweep.ts +2 -2
- package/src/query.ts +109 -10
- package/src/roots/configured-declarations.ts +1 -2
- package/src/stores.ts +1 -1
- package/src/verbs/print-retained.ts +29 -1
- package/dist/src/exempt.js +0 -164
- package/dist/src/value-flow.js +0 -74
- package/src/decorator.ts +0 -78
- package/src/exempt.ts +0 -295
- package/src/value-flow.ts +0 -104
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one walk of a project's own files every detector shares: its calls and the class
|
|
3
|
+
* `this` stands for at each, its classes, the values it hands to positions typed by
|
|
4
|
+
* their context, its functions' parameters, its decorated declarations and its
|
|
5
|
+
* assignments to properties. The walk reads syntax only; what a call invokes through a
|
|
6
|
+
* method of `Function.prototype` asks the checker, once per project, at the first
|
|
7
|
+
* detector that needs it.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
isArrowFunction,
|
|
12
|
+
isBinaryExpression,
|
|
13
|
+
isClassDeclaration,
|
|
14
|
+
isClassExpression,
|
|
15
|
+
isClassStaticBlockDeclaration,
|
|
16
|
+
isElementAccessExpression,
|
|
17
|
+
isFunctionDeclaration,
|
|
18
|
+
isFunctionExpression,
|
|
19
|
+
isGetAccessorDeclaration,
|
|
20
|
+
isIdentifier,
|
|
21
|
+
isMethodDeclaration,
|
|
22
|
+
isNoSubstitutionTemplateLiteral,
|
|
23
|
+
isObjectLiteralExpression,
|
|
24
|
+
isPropertyAccessExpression,
|
|
25
|
+
isPropertyDeclaration,
|
|
26
|
+
isSetAccessorDeclaration,
|
|
27
|
+
isStringLiteral,
|
|
28
|
+
isVariableDeclaration,
|
|
29
|
+
ModifierFlags,
|
|
30
|
+
SyntaxKind,
|
|
31
|
+
type CallExpression,
|
|
32
|
+
type ClassLikeDeclaration,
|
|
33
|
+
type Expression,
|
|
34
|
+
type Node,
|
|
35
|
+
type ParameterDeclaration,
|
|
36
|
+
} from "@typescript/native/ast";
|
|
37
|
+
import { handedOn, valuesOf } from "../index/values.ts";
|
|
38
|
+
import { isParameterProperty, nodeKey, type Inventory } from "../inventory.ts";
|
|
39
|
+
import type { ProjectView } from "../session.ts";
|
|
40
|
+
import { parenthesesRemoved } from "../unwrap.ts";
|
|
41
|
+
import { decoratorsOf, invocations, type Invocations } from "./calls.ts";
|
|
42
|
+
|
|
43
|
+
/** One call of the project's own files, and the class `this` is a value of where it is written. */
|
|
44
|
+
export interface CallSite {
|
|
45
|
+
readonly call: CallExpression;
|
|
46
|
+
/** The inventory's identifier of the class, where `this` is an instance of one. */
|
|
47
|
+
readonly self: string | undefined;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** One class the inventory holds, declared or written as an expression. */
|
|
51
|
+
interface ClassSite {
|
|
52
|
+
readonly id: string;
|
|
53
|
+
readonly node: ClassLikeDeclaration;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** One value the project hands to a position the checker types from its context. */
|
|
57
|
+
interface FlowSite {
|
|
58
|
+
readonly value: Expression;
|
|
59
|
+
/** The class `this` stands for, where the value is `this` inside an instance member. */
|
|
60
|
+
readonly self: string | undefined;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** One identifier-named parameter of a function, method or function-valued variable of the project. */
|
|
64
|
+
export interface ParameterSite {
|
|
65
|
+
/** The inventory's identifier of the function's declaration. */
|
|
66
|
+
readonly fn: string;
|
|
67
|
+
/** Its place among the arguments a call binds, a `this` parameter taking none. */
|
|
68
|
+
readonly index: number;
|
|
69
|
+
readonly rest: boolean;
|
|
70
|
+
readonly name: Node;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** One assignment of a value to a property a key written as a name or a string names. */
|
|
74
|
+
interface StoreSite {
|
|
75
|
+
readonly store: Expression;
|
|
76
|
+
readonly receiver: Expression;
|
|
77
|
+
readonly key: string;
|
|
78
|
+
readonly value: Expression;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** The property one assignment's left side names on its receiver, where a written key names it. */
|
|
82
|
+
function storeOf(node: Node): StoreSite | undefined {
|
|
83
|
+
if (!isBinaryExpression(node) || node.operatorToken.kind !== SyntaxKind.EqualsToken) {
|
|
84
|
+
return undefined;
|
|
85
|
+
}
|
|
86
|
+
const left = parenthesesRemoved(node.left);
|
|
87
|
+
if (isPropertyAccessExpression(left) && isIdentifier(left.name)) {
|
|
88
|
+
return { store: node, receiver: left.expression, key: left.name.text, value: node.right };
|
|
89
|
+
}
|
|
90
|
+
if (
|
|
91
|
+
isElementAccessExpression(left) &&
|
|
92
|
+
(isStringLiteral(left.argumentExpression) ||
|
|
93
|
+
isNoSubstitutionTemplateLiteral(left.argumentExpression))
|
|
94
|
+
) {
|
|
95
|
+
return {
|
|
96
|
+
store: node,
|
|
97
|
+
receiver: left.expression,
|
|
98
|
+
key: left.argumentExpression.text,
|
|
99
|
+
value: node.right,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
return undefined;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** One declaration the inventory holds that carries a decorator. */
|
|
106
|
+
interface DecoratedSite {
|
|
107
|
+
readonly id: string;
|
|
108
|
+
readonly node: Node;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** What one walk of a project's own files found. */
|
|
112
|
+
interface Walked {
|
|
113
|
+
readonly calls: readonly CallSite[];
|
|
114
|
+
readonly classes: readonly ClassSite[];
|
|
115
|
+
readonly flows: readonly FlowSite[];
|
|
116
|
+
readonly parameters: readonly ParameterSite[];
|
|
117
|
+
readonly decorated: readonly DecoratedSite[];
|
|
118
|
+
/** The assignments to a property a written key names. */
|
|
119
|
+
readonly stores: readonly StoreSite[];
|
|
120
|
+
/** The parameter properties the inventory holds, by identifier. */
|
|
121
|
+
readonly parameterProperties: ReadonlySet<string>;
|
|
122
|
+
/** The class properties whose declaration writes an initializer, by identifier. */
|
|
123
|
+
readonly initialized: ReadonlySet<string>;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** Whether one node declares a static member, whose `this` is the class itself. */
|
|
127
|
+
function isStatic(node: Node): boolean {
|
|
128
|
+
const flags = (node as { readonly modifierFlags?: number }).modifierFlags ?? 0;
|
|
129
|
+
return (flags & ModifierFlags.Static) !== 0;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Whether one node opens a body whose `this` is no instance of the enclosing class: a
|
|
134
|
+
* function that is not an arrow, a static block, a static member, and a method or an
|
|
135
|
+
* accessor of an object literal, whose `this` is the literal.
|
|
136
|
+
*/
|
|
137
|
+
function resetsThis(node: Node): boolean {
|
|
138
|
+
return (
|
|
139
|
+
isFunctionDeclaration(node) ||
|
|
140
|
+
isFunctionExpression(node) ||
|
|
141
|
+
isClassStaticBlockDeclaration(node) ||
|
|
142
|
+
isStatic(node) ||
|
|
143
|
+
((isMethodDeclaration(node) ||
|
|
144
|
+
isGetAccessorDeclaration(node) ||
|
|
145
|
+
isSetAccessorDeclaration(node)) &&
|
|
146
|
+
isObjectLiteralExpression(node.parent))
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** The parameters and declaring node of one function-like declaration of the project. */
|
|
151
|
+
function functionOf(
|
|
152
|
+
node: Node,
|
|
153
|
+
): { readonly declared: Node; readonly parameters: readonly ParameterDeclaration[] } | undefined {
|
|
154
|
+
if (
|
|
155
|
+
isFunctionDeclaration(node) ||
|
|
156
|
+
(isMethodDeclaration(node) && !isObjectLiteralExpression(node.parent))
|
|
157
|
+
) {
|
|
158
|
+
return { declared: node, parameters: node.parameters };
|
|
159
|
+
}
|
|
160
|
+
if (
|
|
161
|
+
isVariableDeclaration(node) &&
|
|
162
|
+
node.initializer !== undefined &&
|
|
163
|
+
(isArrowFunction(node.initializer) || isFunctionExpression(node.initializer))
|
|
164
|
+
) {
|
|
165
|
+
return { declared: node, parameters: node.initializer.parameters };
|
|
166
|
+
}
|
|
167
|
+
return undefined;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function walk<Brand>(project: ProjectView<Brand>, held: Inventory): Walked {
|
|
171
|
+
const calls: CallSite[] = [];
|
|
172
|
+
const classes: ClassSite[] = [];
|
|
173
|
+
const flows: FlowSite[] = [];
|
|
174
|
+
const parameters: ParameterSite[] = [];
|
|
175
|
+
const decorated: DecoratedSite[] = [];
|
|
176
|
+
const stores: StoreSite[] = [];
|
|
177
|
+
const parameterProperties = new Set<string>();
|
|
178
|
+
const initialized = new Set<string>();
|
|
179
|
+
for (const file of project.ownSourceFiles()) {
|
|
180
|
+
const visit = (node: Node, self: string | undefined): void => {
|
|
181
|
+
const id = held.declarations.get(nodeKey(file, node));
|
|
182
|
+
let inner = self;
|
|
183
|
+
if (isClassDeclaration(node) || isClassExpression(node)) {
|
|
184
|
+
inner = id;
|
|
185
|
+
if (id !== undefined) {
|
|
186
|
+
classes.push({ id, node });
|
|
187
|
+
}
|
|
188
|
+
} else if (resetsThis(node)) {
|
|
189
|
+
inner = undefined;
|
|
190
|
+
}
|
|
191
|
+
if (id !== undefined) {
|
|
192
|
+
if (isParameterProperty(node)) {
|
|
193
|
+
parameterProperties.add(id);
|
|
194
|
+
}
|
|
195
|
+
if (decoratorsOf(node).length > 0) {
|
|
196
|
+
decorated.push({ id, node });
|
|
197
|
+
}
|
|
198
|
+
if (isPropertyDeclaration(node) && node.initializer !== undefined) {
|
|
199
|
+
initialized.add(id);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
if (node.kind === SyntaxKind.CallExpression) {
|
|
203
|
+
calls.push({ call: node as CallExpression, self: inner });
|
|
204
|
+
}
|
|
205
|
+
const store = storeOf(node);
|
|
206
|
+
if (store !== undefined) {
|
|
207
|
+
stores.push(store);
|
|
208
|
+
}
|
|
209
|
+
for (const written of handedOn(node)) {
|
|
210
|
+
for (const value of valuesOf(written)) {
|
|
211
|
+
flows.push({ value, self: value.kind === SyntaxKind.ThisKeyword ? inner : undefined });
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
const fn = functionOf(node);
|
|
215
|
+
const fnId = fn === undefined ? undefined : held.declarations.get(nodeKey(file, fn.declared));
|
|
216
|
+
if (fn !== undefined && fnId !== undefined) {
|
|
217
|
+
fn.parameters
|
|
218
|
+
.filter((parameter) => !(isIdentifier(parameter.name) && parameter.name.text === "this"))
|
|
219
|
+
.forEach((parameter, index) => {
|
|
220
|
+
if (isIdentifier(parameter.name)) {
|
|
221
|
+
parameters.push({
|
|
222
|
+
fn: fnId,
|
|
223
|
+
index,
|
|
224
|
+
rest: parameter.dotDotDotToken !== undefined,
|
|
225
|
+
name: parameter.name,
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
node.forEachChild((child) => {
|
|
231
|
+
visit(child, inner);
|
|
232
|
+
});
|
|
233
|
+
};
|
|
234
|
+
file.forEachChild((child) => {
|
|
235
|
+
visit(child, undefined);
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
return {
|
|
239
|
+
calls,
|
|
240
|
+
classes,
|
|
241
|
+
flows,
|
|
242
|
+
parameters,
|
|
243
|
+
decorated,
|
|
244
|
+
stores,
|
|
245
|
+
parameterProperties,
|
|
246
|
+
initialized,
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/** One project's sites, walked at the first detector that reads them. */
|
|
251
|
+
export interface ProjectSites extends Walked {
|
|
252
|
+
/** What each call invokes, a call through `call`, `apply` or `bind` included. */
|
|
253
|
+
readonly invocations: Invocations;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/** The sites of one project's own files, each walk and each checker question made once. */
|
|
257
|
+
export function projectSites<Brand>(project: ProjectView<Brand>, held: Inventory): ProjectSites {
|
|
258
|
+
let walked: Walked | undefined;
|
|
259
|
+
let invoked: Invocations | undefined;
|
|
260
|
+
const sites = (): Walked => (walked ??= walk(project, held));
|
|
261
|
+
return {
|
|
262
|
+
get calls() {
|
|
263
|
+
return sites().calls;
|
|
264
|
+
},
|
|
265
|
+
get classes() {
|
|
266
|
+
return sites().classes;
|
|
267
|
+
},
|
|
268
|
+
get flows() {
|
|
269
|
+
return sites().flows;
|
|
270
|
+
},
|
|
271
|
+
get parameters() {
|
|
272
|
+
return sites().parameters;
|
|
273
|
+
},
|
|
274
|
+
get decorated() {
|
|
275
|
+
return sites().decorated;
|
|
276
|
+
},
|
|
277
|
+
get stores() {
|
|
278
|
+
return sites().stores;
|
|
279
|
+
},
|
|
280
|
+
get parameterProperties() {
|
|
281
|
+
return sites().parameterProperties;
|
|
282
|
+
},
|
|
283
|
+
get initialized() {
|
|
284
|
+
return sites().initialized;
|
|
285
|
+
},
|
|
286
|
+
get invocations() {
|
|
287
|
+
return (invoked ??= invocations(
|
|
288
|
+
project,
|
|
289
|
+
sites().calls.map((one) => one.call),
|
|
290
|
+
));
|
|
291
|
+
},
|
|
292
|
+
};
|
|
293
|
+
}
|
|
@@ -12,17 +12,17 @@
|
|
|
12
12
|
* type, because nothing ties the name to a type.
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
import { readComponent } from "
|
|
16
|
-
import type { ResolvedConfig, TemplateDelimiters } from "
|
|
17
|
-
import type { DetectorInput, Evidence } from "./
|
|
18
|
-
import type { Host } from "
|
|
19
|
-
import type { SymbolKind } from "
|
|
20
|
-
import { memberNames } from "
|
|
21
|
-
import { extensionOf, isAbsolutePath, joinPath, normalizePath, relativePath } from "
|
|
22
|
-
import { isComponentFile, type Position } from "
|
|
23
|
-
import { bytewise } from "
|
|
24
|
-
import { filesBelow } from "
|
|
25
|
-
import { UsageError } from "
|
|
15
|
+
import { readComponent } from "../component-files.ts";
|
|
16
|
+
import type { ResolvedConfig, TemplateDelimiters } from "../config.ts";
|
|
17
|
+
import type { DetectorInput, Evidence } from "./lifecycle.ts";
|
|
18
|
+
import type { Host } from "../host.ts";
|
|
19
|
+
import type { SymbolKind } from "../inventory.ts";
|
|
20
|
+
import { memberNames } from "../member-names.ts";
|
|
21
|
+
import { extensionOf, isAbsolutePath, joinPath, normalizePath, relativePath } from "../paths.ts";
|
|
22
|
+
import { isComponentFile, type Position } from "../position.ts";
|
|
23
|
+
import { bytewise } from "../text/compare.ts";
|
|
24
|
+
import { filesBelow } from "../fs/tree.ts";
|
|
25
|
+
import { UsageError } from "../usage.ts";
|
|
26
26
|
|
|
27
27
|
/** One template, by its path below the target root. */
|
|
28
28
|
interface TemplateFile {
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
* The classes of the target a value of one type carries, and the members of the other
|
|
3
3
|
* object types the target writes that it carries, as a serializer walking the value reaches
|
|
4
4
|
* them: through constituents, array and tuple elements, the data members and index
|
|
5
|
-
* signatures of the types the target writes,
|
|
6
|
-
* it erases them. The walk stops at `any`, `unknown`,
|
|
7
|
-
* interface or class of another program, so an
|
|
5
|
+
* signatures of the types the target writes, a class's polymorphic `this` type, and the values
|
|
6
|
+
* `stored` gives for a type where it erases them. The walk stops at `any`, `unknown`, any
|
|
7
|
+
* other type parameter, a function and an interface or class of another program, so an
|
|
8
|
+
* instance held only there is missed.
|
|
8
9
|
*/
|
|
9
10
|
|
|
10
11
|
import {
|
|
@@ -17,14 +18,15 @@ import {
|
|
|
17
18
|
import {
|
|
18
19
|
ObjectFlags,
|
|
19
20
|
SymbolFlags,
|
|
21
|
+
TypeFlags,
|
|
20
22
|
type ObjectType,
|
|
21
23
|
type Symbol as TSSymbol,
|
|
22
24
|
type Type,
|
|
23
25
|
} from "@typescript/native/sync";
|
|
24
|
-
import { classNames, typesAt } from "
|
|
25
|
-
import type { Inventory } from "
|
|
26
|
-
import { must } from "
|
|
27
|
-
import type { ProjectView } from "
|
|
26
|
+
import { classNames, typesAt } from "../class-members.ts";
|
|
27
|
+
import type { Inventory } from "../inventory.ts";
|
|
28
|
+
import { must } from "../query.ts";
|
|
29
|
+
import type { ProjectView } from "../session.ts";
|
|
28
30
|
|
|
29
31
|
/**
|
|
30
32
|
* The object types whose members the walk reads whatever declares them. A reverse-mapped
|
|
@@ -53,7 +55,10 @@ interface ValueReach {
|
|
|
53
55
|
}
|
|
54
56
|
|
|
55
57
|
/** The two conversion methods a serializer or a formatter resolves on a value's own shape. */
|
|
56
|
-
const CONVERSION_NAMES: ReadonlySet<string> = new Set(["toJSON", "toString"]);
|
|
58
|
+
export const CONVERSION_NAMES: ReadonlySet<string> = new Set(["toJSON", "toString"]);
|
|
59
|
+
|
|
60
|
+
/** The types that keep nothing of a value they are given, or that a decode gives a value. */
|
|
61
|
+
export const ERASED = TypeFlags.Any | TypeFlags.Unknown;
|
|
57
62
|
|
|
58
63
|
/**
|
|
59
64
|
* The members that can answer a conversion: a serializer reads the name with `[[Get]]`
|
|
@@ -208,6 +213,9 @@ export function valueReach<Brand>(
|
|
|
208
213
|
let found: readonly Type[] = [];
|
|
209
214
|
if (type.isUnionType() || type.isIntersectionType()) {
|
|
210
215
|
found = must(queries.constituents(type));
|
|
216
|
+
} else if (type.isTypeParameter() && type.isThisType === true) {
|
|
217
|
+
// A value of a class's polymorphic `this` type is an instance of the class.
|
|
218
|
+
found = [must(queries.constraintOf(type))].filter((one) => one !== undefined);
|
|
211
219
|
} else if (type.isObjectType()) {
|
|
212
220
|
const target = targetOf(type);
|
|
213
221
|
const isList =
|
package/src/facts.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
import { FACTS_VERSION } from "./contract/contract.generated.ts";
|
|
8
8
|
import type { BindingRecord } from "./bindings.ts";
|
|
9
|
-
import type { GeneratedFact } from "./generated-file.ts";
|
|
9
|
+
import type { GeneratedFact } from "./exemptions/generated-file.ts";
|
|
10
10
|
import { LANGUAGE, PRODUCT } from "./product.ts";
|
|
11
11
|
import { bytewise } from "./text/compare.ts";
|
|
12
12
|
|
package/src/index/sites.ts
CHANGED
|
@@ -56,7 +56,7 @@ import type { Use } from "../references.ts";
|
|
|
56
56
|
import { isLoadCall, type LoadCall } from "../roots/unseen-loads.ts";
|
|
57
57
|
import { keyNameOf, type KeyedAccess } from "../symbol-keys.ts";
|
|
58
58
|
import { parenthesesRemoved } from "../unwrap.ts";
|
|
59
|
-
import { handedOn, valuesOf } from "
|
|
59
|
+
import { handedOn, valuesOf } from "./values.ts";
|
|
60
60
|
|
|
61
61
|
/**
|
|
62
62
|
* The operators whose left side one assignment stores into. A compound assignment is
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a written expression evaluates to, the one definition every pass shares: the
|
|
3
|
+
* values it can be, the values a call's argument carries inside the literals it writes,
|
|
4
|
+
* and the positions a program hands a value to that the checker types from their context.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
isArrayLiteralExpression,
|
|
9
|
+
isArrowFunction,
|
|
10
|
+
isAsExpression,
|
|
11
|
+
isBinaryExpression,
|
|
12
|
+
isCallExpression,
|
|
13
|
+
isConditionalExpression,
|
|
14
|
+
isIdentifier,
|
|
15
|
+
isNewExpression,
|
|
16
|
+
isNonNullExpression,
|
|
17
|
+
isObjectLiteralExpression,
|
|
18
|
+
isOmittedExpression,
|
|
19
|
+
isParameterDeclaration,
|
|
20
|
+
isParenthesizedExpression,
|
|
21
|
+
isPropertyAccessExpression,
|
|
22
|
+
isPropertyAssignment,
|
|
23
|
+
isPropertyDeclaration,
|
|
24
|
+
isReturnStatement,
|
|
25
|
+
isSatisfiesExpression,
|
|
26
|
+
isShorthandPropertyAssignment,
|
|
27
|
+
isSpreadAssignment,
|
|
28
|
+
isSpreadElement,
|
|
29
|
+
isVariableDeclaration,
|
|
30
|
+
SyntaxKind,
|
|
31
|
+
type Expression,
|
|
32
|
+
type Node,
|
|
33
|
+
} from "@typescript/native/ast";
|
|
34
|
+
|
|
35
|
+
/** The operators of an assignment whose right side is stored into the left side's type. */
|
|
36
|
+
const STORES: ReadonlySet<SyntaxKind> = new Set([
|
|
37
|
+
SyntaxKind.EqualsToken,
|
|
38
|
+
SyntaxKind.QuestionQuestionEqualsToken,
|
|
39
|
+
SyntaxKind.BarBarEqualsToken,
|
|
40
|
+
SyntaxKind.AmpersandAmpersandEqualsToken,
|
|
41
|
+
]);
|
|
42
|
+
|
|
43
|
+
/** Whether a declaration writes its type, so its initializer is read in that type's context. */
|
|
44
|
+
function writesType(node: Node): boolean {
|
|
45
|
+
return (node as { readonly type?: Node }).type !== undefined;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The expressions one written value can evaluate to, each read alone because the checker
|
|
50
|
+
* reduces a union by subtype, so the type at the whole drops a class another branch's
|
|
51
|
+
* extends: the operand of a spread, of parentheses and of `!`, each branch of a
|
|
52
|
+
* conditional, each operand of `??` and `||`, and the right operand of `&&` and of a
|
|
53
|
+
* comma. The left operand of `&&` is its value only where it is falsy, which no object
|
|
54
|
+
* is. An assertion is a value of its own, whose type its reader decides.
|
|
55
|
+
*/
|
|
56
|
+
export function valuesOf(expression: Expression): readonly Expression[] {
|
|
57
|
+
if (isSpreadElement(expression) || isParenthesizedExpression(expression)) {
|
|
58
|
+
return valuesOf(expression.expression);
|
|
59
|
+
}
|
|
60
|
+
if (isNonNullExpression(expression)) {
|
|
61
|
+
return valuesOf(expression.expression);
|
|
62
|
+
}
|
|
63
|
+
if (isConditionalExpression(expression)) {
|
|
64
|
+
return [...valuesOf(expression.whenTrue), ...valuesOf(expression.whenFalse)];
|
|
65
|
+
}
|
|
66
|
+
if (isBinaryExpression(expression)) {
|
|
67
|
+
const operator = expression.operatorToken.kind;
|
|
68
|
+
if (operator === SyntaxKind.QuestionQuestionToken || operator === SyntaxKind.BarBarToken) {
|
|
69
|
+
return [...valuesOf(expression.left), ...valuesOf(expression.right)];
|
|
70
|
+
}
|
|
71
|
+
if (operator === SyntaxKind.AmpersandAmpersandToken || operator === SyntaxKind.CommaToken) {
|
|
72
|
+
return valuesOf(expression.right);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return [expression];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** The name node a callee, a decorator expression or a value resolves through, where it has one. */
|
|
79
|
+
export function nameOf(expression: Expression): Node | undefined {
|
|
80
|
+
if (isParenthesizedExpression(expression)) {
|
|
81
|
+
return nameOf(expression.expression);
|
|
82
|
+
}
|
|
83
|
+
if (isPropertyAccessExpression(expression)) {
|
|
84
|
+
return expression.name;
|
|
85
|
+
}
|
|
86
|
+
return isIdentifier(expression) ? expression : undefined;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** One value an argument carries, and the node its declaration is resolved from. */
|
|
90
|
+
export interface CarriedValue {
|
|
91
|
+
/** Where the value is written, which is where a record of it sits. */
|
|
92
|
+
readonly site: Node;
|
|
93
|
+
/** The name the value is resolved through, the shorthand assignment that holds it, or none. */
|
|
94
|
+
readonly name: Node | undefined;
|
|
95
|
+
readonly shorthand: boolean;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* The values one argument carries: each value it can be ({@link valuesOf}), or what an
|
|
100
|
+
* array or object literal it can be holds, at any depth, through spreads and shorthand
|
|
101
|
+
* properties. Each value is read inside every assertion around it.
|
|
102
|
+
*/
|
|
103
|
+
export function carriedValues(argument: Expression): readonly CarriedValue[] {
|
|
104
|
+
return valuesOf(argument).flatMap((value): readonly CarriedValue[] => {
|
|
105
|
+
let at = value;
|
|
106
|
+
while (isAsExpression(at) || isSatisfiesExpression(at)) {
|
|
107
|
+
at = at.expression;
|
|
108
|
+
}
|
|
109
|
+
if (at !== value) {
|
|
110
|
+
return carriedValues(at);
|
|
111
|
+
}
|
|
112
|
+
if (isArrayLiteralExpression(value)) {
|
|
113
|
+
return value.elements.flatMap(carriedValues);
|
|
114
|
+
}
|
|
115
|
+
if (isObjectLiteralExpression(value)) {
|
|
116
|
+
return value.properties.flatMap((property): readonly CarriedValue[] => {
|
|
117
|
+
if (isPropertyAssignment(property)) {
|
|
118
|
+
return carriedValues(property.initializer);
|
|
119
|
+
}
|
|
120
|
+
if (isSpreadAssignment(property)) {
|
|
121
|
+
return carriedValues(property.expression);
|
|
122
|
+
}
|
|
123
|
+
return isShorthandPropertyAssignment(property)
|
|
124
|
+
? [{ site: property.name, name: property, shorthand: true }]
|
|
125
|
+
: [];
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
return isOmittedExpression(value)
|
|
129
|
+
? []
|
|
130
|
+
: [{ site: value, name: nameOf(value), shorthand: false }];
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** The expressions one node hands to a position typed by its context. */
|
|
135
|
+
export function handedOn(node: Node): readonly Expression[] {
|
|
136
|
+
if (
|
|
137
|
+
(isVariableDeclaration(node) || isPropertyDeclaration(node) || isParameterDeclaration(node)) &&
|
|
138
|
+
node.initializer !== undefined &&
|
|
139
|
+
writesType(node)
|
|
140
|
+
) {
|
|
141
|
+
return [node.initializer];
|
|
142
|
+
}
|
|
143
|
+
if (isBinaryExpression(node) && STORES.has(node.operatorToken.kind)) {
|
|
144
|
+
return [node.right];
|
|
145
|
+
}
|
|
146
|
+
if (isCallExpression(node) || isNewExpression(node)) {
|
|
147
|
+
return (node.arguments ?? []).filter((argument) => !isSpreadElement(argument));
|
|
148
|
+
}
|
|
149
|
+
if (isReturnStatement(node)) {
|
|
150
|
+
return node.expression === undefined ? [] : [node.expression];
|
|
151
|
+
}
|
|
152
|
+
if (isArrowFunction(node)) {
|
|
153
|
+
return node.body.kind === SyntaxKind.Block ? [] : [node.body];
|
|
154
|
+
}
|
|
155
|
+
if (isArrayLiteralExpression(node)) {
|
|
156
|
+
return node.elements.filter(
|
|
157
|
+
(element) => !isSpreadElement(element) && element.kind !== SyntaxKind.OmittedExpression,
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
if (isPropertyAssignment(node)) {
|
|
161
|
+
return [node.initializer];
|
|
162
|
+
}
|
|
163
|
+
if (isShorthandPropertyAssignment(node)) {
|
|
164
|
+
return isIdentifier(node.name) ? [node.name] : [];
|
|
165
|
+
}
|
|
166
|
+
if (isAsExpression(node) || isSatisfiesExpression(node)) {
|
|
167
|
+
return [node.expression];
|
|
168
|
+
}
|
|
169
|
+
return [];
|
|
170
|
+
}
|
package/src/liveness/sweep.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* unanswered checker question; each Contract rule "live only through" one is a view up to it.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import { exemptionsOf,
|
|
10
|
+
import { exemptionsOf, type Exemption } from "../exemptions/lifecycle.ts";
|
|
11
11
|
import type { InventorySymbol } from "../inventory.ts";
|
|
12
12
|
import { edgeWithheldBy, type Mode } from "../tests/file-class.ts";
|
|
13
13
|
import { componentsOf, type Component, type Positional } from "./components.ts";
|
|
@@ -644,7 +644,7 @@ function seedsOf(
|
|
|
644
644
|
const seed = { at, origin: { k: "exemption", record } as const };
|
|
645
645
|
if (record.whileLive !== undefined) {
|
|
646
646
|
gate(record.whileLive, seed);
|
|
647
|
-
} else if (
|
|
647
|
+
} else if (record.unanswered === true) {
|
|
648
648
|
unanswered.push(seed);
|
|
649
649
|
} else {
|
|
650
650
|
records.push(seed);
|