@cplieger/deadset-ts 3.3.1 → 3.5.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.
@@ -0,0 +1,405 @@
1
+ /**
2
+ * The serialization-contract class: the properties of a class whose values reach
3
+ * `JSON.stringify` or a call `ts.serializers` names, and those and `toJSON` and
4
+ * `toString` where a value is passed to an `unknown` or `any` parameter of a function
5
+ * outside the analysis. A function of the project handing such a parameter of its own
6
+ * to a destination is one, holding back what that destination does, to a fixpoint. A
7
+ * function invoked through `Function.prototype.call`, `apply` or `bind` is the callee,
8
+ * given the arguments those methods pass it.
9
+ */
10
+ import { isArrayLiteralExpression, isArrowFunction, isCallExpression, isClassDeclaration, isClassExpression, isClassStaticBlockDeclaration, isFunctionDeclaration, isFunctionExpression, isGetAccessorDeclaration, isIdentifier, isMethodDeclaration, isNoSubstitutionTemplateLiteral, isNumericLiteral, isObjectLiteralExpression, isParenthesizedExpression, isPropertyAccessExpression, isSetAccessorDeclaration, isSpreadElement, isStringLiteral, isVariableDeclaration, ModifierFlags, SyntaxKind, } from "@typescript/native/unstable/ast";
11
+ import { SignatureKind, SymbolFlags, TypeFlags, } from "@typescript/native/unstable/sync";
12
+ import { aliasChains } from "./alias-chain.js";
13
+ import { calleeName, resolvedTargets, valuesPassed } from "./calls.js";
14
+ import { classMembers, memberComponent, typesAt } from "./class-members.js";
15
+ import { names, namesADeclaration, resolveEntries, spelledEntry, } from "./configured-declarations.js";
16
+ import { nodeKey } from "./inventory.js";
17
+ import { renderPosition } from "./position.js";
18
+ import { valueReach } from "./value-reach.js";
19
+ /** The serializer every run reads, whatever the configuration names. */
20
+ const JSON_STRINGIFY = { shape: "global", global: "JSON.stringify" };
21
+ /** The methods a serializer and a formatter resolve by name on a value that left the analysis. */
22
+ const CONVERSIONS = new Set(["toJSON", "toString"]);
23
+ /** The parameter types that keep nothing of the value they are given. */
24
+ const ERASED = TypeFlags.Any | TypeFlags.Unknown;
25
+ /** The wider of two reaches, where either may be absent. */
26
+ function wider(a, b) {
27
+ return a === "conversions" || b === "conversions" ? "conversions" : (a ?? b);
28
+ }
29
+ /** Whether one node declares a static member, whose `this` is the class itself. */
30
+ function isStatic(node) {
31
+ const flags = node.modifierFlags ?? 0;
32
+ return (flags & ModifierFlags.Static) !== 0;
33
+ }
34
+ /** Whether one node opens a body whose `this` is not an instance of the enclosing class. */
35
+ function resetsThis(node) {
36
+ return (isFunctionDeclaration(node) ||
37
+ isFunctionExpression(node) ||
38
+ isClassStaticBlockDeclaration(node) ||
39
+ isStatic(node) ||
40
+ ((isMethodDeclaration(node) ||
41
+ isGetAccessorDeclaration(node) ||
42
+ isSetAccessorDeclaration(node)) &&
43
+ isObjectLiteralExpression(node.parent)));
44
+ }
45
+ /** The parameters and declaring node of one function-like declaration of the project. */
46
+ function functionOf(node) {
47
+ if (isFunctionDeclaration(node) ||
48
+ (isMethodDeclaration(node) && !isObjectLiteralExpression(node.parent))) {
49
+ return { declared: node, parameters: node.parameters };
50
+ }
51
+ if (isVariableDeclaration(node) &&
52
+ node.initializer !== undefined &&
53
+ (isArrowFunction(node.initializer) || isFunctionExpression(node.initializer))) {
54
+ return { declared: node, parameters: node.initializer.parameters };
55
+ }
56
+ return undefined;
57
+ }
58
+ /** Whether one parameter is a `this` parameter, which types `this` and binds no argument. */
59
+ function isThisParameter(parameter) {
60
+ return isIdentifier(parameter.name) && parameter.name.text === "this";
61
+ }
62
+ /** Whether an argument is written in a form that holds no class instance, which saves a type. */
63
+ function holdsNoInstance(argument) {
64
+ return (isArrowFunction(argument) ||
65
+ isFunctionExpression(argument) ||
66
+ isStringLiteral(argument) ||
67
+ isNumericLiteral(argument) ||
68
+ isNoSubstitutionTemplateLiteral(argument) ||
69
+ argument.kind === SyntaxKind.TemplateExpression);
70
+ }
71
+ /** The expression an argument evaluates, through parentheses and a spread. */
72
+ function evaluated(argument) {
73
+ const value = isSpreadElement(argument) ? argument.expression : argument;
74
+ return isParenthesizedExpression(value) ? evaluated(value.expression) : value;
75
+ }
76
+ /** The methods of `Function.prototype` that invoke a function with arguments of their own. */
77
+ const FUNCTION_METHODS = new Set(["call", "apply", "bind"]);
78
+ /** The interfaces of the standard library that declare those methods for a function value. */
79
+ const FUNCTION_INTERFACES = new Set([
80
+ "Function",
81
+ "CallableFunction",
82
+ "NewableFunction",
83
+ ]);
84
+ function unparenthesized(expression) {
85
+ return isParenthesizedExpression(expression)
86
+ ? unparenthesized(expression.expression)
87
+ : expression;
88
+ }
89
+ /**
90
+ * The invocation a call writes through a method of `Function.prototype`, read from
91
+ * the syntax alone: `f.call(self, a)`, `f.apply(self, [a])`, `f.bind(self, a)`, which
92
+ * binds `a`, and `f.bind(self, a)(b)`, which passes `b` after it. An `apply` argument
93
+ * that is no array literal is the value of the first parameter, whose elements it
94
+ * carries. Whether the method is the prototype's is resolution's to say.
95
+ */
96
+ function throughMethod(call) {
97
+ const expression = unparenthesized(call.expression);
98
+ if (isPropertyAccessExpression(expression) && FUNCTION_METHODS.has(expression.name.text)) {
99
+ const [, ...rest] = call.arguments;
100
+ let passed = rest;
101
+ if (expression.name.text === "apply") {
102
+ const list = rest[0] === undefined ? undefined : unparenthesized(rest[0]);
103
+ passed = list === undefined ? [] : isArrayLiteralExpression(list) ? list.elements : [list];
104
+ }
105
+ return {
106
+ method: expression.name,
107
+ invocation: { callee: expression.expression, arguments: passed, indirect: true },
108
+ };
109
+ }
110
+ if (isCallExpression(expression)) {
111
+ const bound = unparenthesized(expression.expression);
112
+ if (isPropertyAccessExpression(bound) && bound.name.text === "bind") {
113
+ return {
114
+ method: bound.name,
115
+ invocation: {
116
+ callee: bound.expression,
117
+ arguments: [...expression.arguments.slice(1), ...call.arguments],
118
+ indirect: true,
119
+ },
120
+ };
121
+ }
122
+ }
123
+ return undefined;
124
+ }
125
+ /**
126
+ * Every call of the project's own files with the class `this` stands for there, and
127
+ * every identifier-named parameter of every function, method and function-valued
128
+ * variable the project declares, at the position of the argument it binds.
129
+ */
130
+ function walkProject(project, held) {
131
+ const sites = [];
132
+ const parameters = [];
133
+ for (const file of project.ownSourceFiles()) {
134
+ const visit = (node, self) => {
135
+ let inner = self;
136
+ if (isClassDeclaration(node) || isClassExpression(node)) {
137
+ inner = held.declarations.get(nodeKey(file, node));
138
+ }
139
+ else if (resetsThis(node)) {
140
+ inner = undefined;
141
+ }
142
+ if (node.kind === SyntaxKind.CallExpression) {
143
+ sites.push({ call: node, self });
144
+ }
145
+ const fn = functionOf(node);
146
+ const id = fn === undefined ? undefined : held.declarations.get(nodeKey(file, fn.declared));
147
+ if (fn !== undefined && id !== undefined) {
148
+ fn.parameters
149
+ .filter((parameter) => !isThisParameter(parameter))
150
+ .forEach((parameter, index) => {
151
+ if (isIdentifier(parameter.name)) {
152
+ parameters.push({
153
+ fn: id,
154
+ index,
155
+ rest: parameter.dotDotDotToken !== undefined,
156
+ name: parameter.name,
157
+ });
158
+ }
159
+ });
160
+ }
161
+ node.forEachChild((child) => {
162
+ visit(child, inner);
163
+ });
164
+ };
165
+ file.forEachChild((child) => {
166
+ visit(child, undefined);
167
+ });
168
+ }
169
+ return { sites, parameters };
170
+ }
171
+ /**
172
+ * The parameters that keep nothing of the value they are given: one typed `unknown` or
173
+ * `any`, and a rest parameter whose elements are, each by its symbol.
174
+ */
175
+ function erasedParameters(project, parameters) {
176
+ const types = typesAt(project, parameters.map((parameter) => parameter.name));
177
+ const erased = parameters.filter((parameter, index) => {
178
+ const type = types[index];
179
+ if (type === undefined) {
180
+ return false;
181
+ }
182
+ if (!parameter.rest) {
183
+ return (type.flags & ERASED) !== 0;
184
+ }
185
+ const [element] = type.isTypeReference() ? project.checker.getTypeArguments(type) : [];
186
+ return element !== undefined && (element.flags & ERASED) !== 0;
187
+ });
188
+ const bySymbol = new Map();
189
+ project
190
+ .symbolsAt(erased.map((parameter) => project.handle(parameter.name)))
191
+ .forEach((symbol, index) => {
192
+ const parameter = erased[index];
193
+ if (symbol !== undefined && parameter !== undefined) {
194
+ bySymbol.set(symbol.id, parameter);
195
+ }
196
+ });
197
+ return bySymbol;
198
+ }
199
+ /** Each place a call's argument passes one of the erased parameters it can see. */
200
+ function handedOn(project, sites, erased, invocationOf) {
201
+ const spellings = new Set([...erased.values()].map((parameter) => parameter.name.getText()));
202
+ const candidates = sites.flatMap((site) => invocationOf(site.call).arguments.flatMap((argument, index) => valuesPassed(argument)
203
+ .filter((value) => spellings.has(value.name.getText()))
204
+ .map((value) => ({ site, argument: index, value }))));
205
+ const plain = candidates.filter((one) => !one.value.shorthand);
206
+ const resolved = project.symbolsAt(plain.map((one) => project.handle(one.value.name)));
207
+ const symbolOf = new Map(plain.map((one, index) => [one, resolved[index]]));
208
+ return candidates.flatMap((one) => {
209
+ const symbol = one.value.shorthand
210
+ ? project.shorthandValueAt(project.handle(one.value.name))
211
+ : symbolOf.get(one);
212
+ const parameter = symbol === undefined ? undefined : erased.get(symbol.id);
213
+ return parameter === undefined ? [] : [{ parameter, site: one.site, argument: one.argument }];
214
+ });
215
+ }
216
+ /**
217
+ * The destinations of one project's calls. A call is one at every argument where its
218
+ * callee is a serializer an entry names; at the arguments its resolved signature types
219
+ * `unknown` or `any` where its callee is declared outside the analysis; and, where its
220
+ * callee is a function of the project, at each parameter the function hands on to a
221
+ * destination, holding back the widest of what those destinations hold back, which is
222
+ * settled by widening until no parameter moves.
223
+ */
224
+ function destinations(input, chains, walked) {
225
+ const { project, held } = input;
226
+ const checker = project.checker;
227
+ const own = new Set(project.ownSourceFiles().map((file) => file.fileName));
228
+ const named = resolveEntries(project, held, [JSON_STRINGIFY, ...input.ts.serializers]).filter(namesADeclaration);
229
+ const forms = new Map();
230
+ for (const site of walked.sites) {
231
+ const form = throughMethod(site.call);
232
+ if (form !== undefined) {
233
+ forms.set(site.call, form);
234
+ }
235
+ }
236
+ const callees = resolvedTargets(project, [
237
+ ...walked.sites.flatMap((site) => calleeName(site.call.expression) ?? []),
238
+ ...[...forms.values()].flatMap((form) => {
239
+ const name = calleeName(form.invocation.callee);
240
+ return name === undefined ? [form.method] : [form.method, name];
241
+ }),
242
+ ]);
243
+ const erased = erasedParameters(project, walked.parameters);
244
+ const byFunction = new Map();
245
+ for (const parameter of erased.values()) {
246
+ byFunction.set(parameter.fn, [...(byFunction.get(parameter.fn) ?? []), parameter]);
247
+ }
248
+ const outside = (target) => target.declarations.length > 0 &&
249
+ target.declarations.every((handle) => !own.has(handle.path) &&
250
+ !input.consumers.some((root) => handle.path === root || handle.path.startsWith(`${root}/`)));
251
+ const invocation = (call) => {
252
+ const form = forms.get(call);
253
+ const method = form === undefined ? undefined : callees.get(form.method);
254
+ // Only the standard library's function methods pass their arguments on: the
255
+ // program's own `call` and `Reflect.apply` invoke nothing here.
256
+ if (form !== undefined &&
257
+ method !== undefined &&
258
+ outside(method) &&
259
+ FUNCTION_INTERFACES.has(method.getParent()?.name ?? "")) {
260
+ return form.invocation;
261
+ }
262
+ return { callee: call.expression, arguments: call.arguments, indirect: false };
263
+ };
264
+ const calleeOf = (call) => {
265
+ const name = calleeName(invocation(call).callee);
266
+ return name === undefined ? undefined : callees.get(name);
267
+ };
268
+ const erasedArguments = new Map();
269
+ const erasedAt = (call, argument) => {
270
+ let indexes = erasedArguments.get(call);
271
+ if (indexes === undefined) {
272
+ const invoked = invocation(call);
273
+ // Through a method of the prototype the resolved signature is the method's, so
274
+ // the parameters are read off the callee's own signatures, any one erasing.
275
+ const type = invoked.indirect ? checker.getTypeAtLocation(invoked.callee) : undefined;
276
+ const signatures = invoked.indirect
277
+ ? type === undefined
278
+ ? []
279
+ : checker.getSignaturesOfType(type, SignatureKind.Call)
280
+ : [checker.getResolvedSignature(call)].filter((one) => one !== undefined);
281
+ indexes = new Set(invoked.arguments.flatMap((_unused, index) => signatures.some((signature) => {
282
+ const parameter = checker.getParameterType(signature, index);
283
+ return parameter !== undefined && (parameter.flags & ERASED) !== 0;
284
+ })
285
+ ? [index]
286
+ : []));
287
+ erasedArguments.set(call, indexes);
288
+ }
289
+ return indexes.has(argument);
290
+ };
291
+ const forwards = new Map();
292
+ const keyOf = (parameter) => `${parameter.fn}\u0000${String(parameter.index)}`;
293
+ const at = (call, argument) => {
294
+ const target = calleeOf(call);
295
+ if (target === undefined) {
296
+ return undefined;
297
+ }
298
+ const entry = named.find((one) => names(one, target, chains));
299
+ if (entry !== undefined) {
300
+ return { reach: "properties", callee: spelledEntry(entry.entry, held) };
301
+ }
302
+ const declared = chains.declarationsOf(target);
303
+ if (declared.length === 0) {
304
+ return outside(target) && erasedAt(call, argument)
305
+ ? {
306
+ reach: "conversions",
307
+ callee: invocation(call).callee.getText().replace(/\s+/gu, ""),
308
+ }
309
+ : undefined;
310
+ }
311
+ for (const fn of declared) {
312
+ const parameter = (byFunction.get(fn) ?? []).find((one) => one.index === argument || (one.rest && one.index <= argument));
313
+ const reach = parameter === undefined ? undefined : forwards.get(keyOf(parameter));
314
+ if (reach !== undefined) {
315
+ return { reach, callee: held.symbols.find((symbol) => symbol.id === fn)?.name ?? fn };
316
+ }
317
+ }
318
+ return undefined;
319
+ };
320
+ const forwarded = handedOn(project, walked.sites, erased, invocation);
321
+ for (let moved = true; moved;) {
322
+ moved = false;
323
+ for (const one of forwarded) {
324
+ const key = keyOf(one.parameter);
325
+ const before = forwards.get(key);
326
+ const after = wider(before, at(one.site.call, one.argument)?.reach);
327
+ if (after !== undefined && after !== before) {
328
+ forwards.set(key, after);
329
+ moved = true;
330
+ }
331
+ }
332
+ }
333
+ const mayReceive = (call) => {
334
+ const target = calleeOf(call);
335
+ if (target === undefined) {
336
+ return false;
337
+ }
338
+ const declared = chains.declarationsOf(target);
339
+ if (named.some((one) => names(one, target, chains))) {
340
+ return true;
341
+ }
342
+ if (declared.length === 0) {
343
+ return outside(target);
344
+ }
345
+ return declared.some((fn) => (byFunction.get(fn) ?? []).some((parameter) => forwards.has(keyOf(parameter))));
346
+ };
347
+ return { invocation, at, mayReceive };
348
+ }
349
+ /** Each argument of a call that can receive one whose value carries a class of the target. */
350
+ function flowsOf(project, held, sites, to) {
351
+ const reach = valueReach(project, held);
352
+ const arguments_ = sites.flatMap((site) => to.mayReceive(site.call)
353
+ ? to.invocation(site.call).arguments.flatMap((argument, index) => {
354
+ const value = evaluated(argument);
355
+ return holdsNoInstance(value) ? [] : [{ site, argument: index, value }];
356
+ })
357
+ : []);
358
+ const asked = arguments_.filter((one) => one.value.kind !== SyntaxKind.ThisKeyword);
359
+ const types = typesAt(project, asked.map((one) => one.value));
360
+ const typeOf = new Map(asked.map((one, index) => [one.value, types[index]]));
361
+ return arguments_.flatMap((one) => {
362
+ const type = typeOf.get(one.value);
363
+ let classes = new Set();
364
+ if (one.value.kind === SyntaxKind.ThisKeyword) {
365
+ classes = new Set(one.site.self === undefined ? [] : [one.site.self]);
366
+ }
367
+ else if (type !== undefined) {
368
+ classes = reach.classesOf(type);
369
+ }
370
+ const destination = classes.size === 0 ? undefined : to.at(one.site.call, one.argument);
371
+ return destination === undefined ? [] : [{ site: one.value, classes, to: destination }];
372
+ });
373
+ }
374
+ /**
375
+ * The serialization-contract detector: each property of each class whose values reach
376
+ * a destination, and the two conversion methods where the destination is outside the
377
+ * analysis, recorded at the argument with the callee named.
378
+ */
379
+ export function serializationContract(input) {
380
+ const { project, held, targetRoot } = input;
381
+ const walked = walkProject(project, held);
382
+ const flows = flowsOf(project, held, walked.sites, destinations(input, aliasChains(project, held), walked));
383
+ if (flows.length === 0) {
384
+ return [];
385
+ }
386
+ const members = classMembers(project, held, new Set(flows.flatMap((flow) => [...flow.classes])), "instance");
387
+ const byId = new Map(held.symbols.map((symbol) => [symbol.id, symbol]));
388
+ const found = [];
389
+ for (const flow of flows) {
390
+ const site = renderPosition(flow.site.getSourceFile(), targetRoot, flow.site.getStart());
391
+ const detail = `passed to ${flow.to.callee}`;
392
+ for (const member of [...flow.classes].flatMap((id) => members.get(id) ?? [])) {
393
+ const symbol = byId.get(member.id);
394
+ const isProperty = (member.flags & SymbolFlags.Property) !== 0;
395
+ const converts = flow.to.reach === "conversions" &&
396
+ (member.flags & SymbolFlags.Method) !== 0 &&
397
+ symbol !== undefined &&
398
+ CONVERSIONS.has(memberComponent(symbol, byId) ?? "");
399
+ if (isProperty || converts) {
400
+ found.push({ id: member.id, detail, site });
401
+ }
402
+ }
403
+ }
404
+ return found;
405
+ }
@@ -0,0 +1,120 @@
1
+ /**
2
+ * The classes of the target a value of one type carries, as a serializer walking the
3
+ * value reaches them: through union and intersection constituents, array and tuple
4
+ * elements, and the data members of the target's classes and of object types the
5
+ * target writes. The walk stops at `any`, `unknown`, a type parameter, a function and
6
+ * an interface or class of another program, so an instance held only there is missed.
7
+ */
8
+ import { ObjectFlags, SymbolFlags, } from "@typescript/native/unstable/sync";
9
+ import { classNames, typesAt } from "./class-members.js";
10
+ /** The object types whose members the walk reads whatever declares them. */
11
+ const WRITTEN = ObjectFlags.ObjectLiteral | ObjectFlags.Mapped;
12
+ /** The symbols of an anonymous object type the target writes as a type. */
13
+ const LITERAL_SYMBOLS = SymbolFlags.TypeLiteral | SymbolFlags.ObjectLiteral;
14
+ /** The global array types, whose element type is what an array value carries. */
15
+ function arrayTargets(project) {
16
+ const checker = project.checker;
17
+ return new Set(["Array", "ReadonlyArray"].flatMap((name) => {
18
+ const symbol = checker.resolveName(name, SymbolFlags.Type, undefined, false);
19
+ return symbol === undefined ? [] : [checker.getDeclaredTypeOfSymbol(symbol).id];
20
+ }));
21
+ }
22
+ /**
23
+ * The walk over one project's types, against the classes of `held`, the same
24
+ * project's inventory.
25
+ */
26
+ export function valueReach(project, held) {
27
+ const checker = project.checker;
28
+ const names = [...classNames(project, held)];
29
+ const declared = typesAt(project, names.map(([, node]) => node));
30
+ const classOfTarget = new Map();
31
+ names.forEach(([id], index) => {
32
+ const type = declared[index];
33
+ if (type !== undefined) {
34
+ classOfTarget.set(type.id, id);
35
+ }
36
+ });
37
+ const arrays = arrayTargets(project);
38
+ const own = new Set(project.ownSourceFiles().map((file) => file.fileName));
39
+ const children = new Map();
40
+ /** The generic target of a type reference, and the type itself otherwise. */
41
+ const targetOf = (type) => (type.objectFlags & ObjectFlags.Reference) !== 0 && type.isTypeReference()
42
+ ? type.getTarget()
43
+ : type;
44
+ const classOf = (type) => {
45
+ if (!type.isObjectType()) {
46
+ return undefined;
47
+ }
48
+ return classOfTarget.get(type.id) ?? classOfTarget.get(targetOf(type).id);
49
+ };
50
+ /** Whether the target writes the object type, so its members are what the value holds. */
51
+ const isWritten = (type) => {
52
+ if ((type.objectFlags & WRITTEN) !== 0) {
53
+ return true;
54
+ }
55
+ const symbol = type.getSymbol();
56
+ if (symbol === undefined) {
57
+ return false;
58
+ }
59
+ if ((type.objectFlags & ObjectFlags.Anonymous) !== 0) {
60
+ return (symbol.flags & LITERAL_SYMBOLS) !== 0;
61
+ }
62
+ return ((symbol.flags & SymbolFlags.Interface) !== 0 &&
63
+ symbol.declarations.every((handle) => own.has(handle.path)));
64
+ };
65
+ /** The types a value of one object type holds in its data members. */
66
+ const memberTypes = (type) => {
67
+ const properties = checker
68
+ .getPropertiesOfType(type)
69
+ .filter((property) => (property.flags & SymbolFlags.Property) !== 0);
70
+ const types = properties.length === 0 ? [] : checker.getTypeOfSymbol(properties);
71
+ return [
72
+ ...types.filter((held) => held !== undefined),
73
+ ...checker.getIndexInfosOfType(type).map((info) => info.valueType),
74
+ ];
75
+ };
76
+ /** The types a value of one type holds, read once per type. */
77
+ const childrenOf = (type) => {
78
+ const known = children.get(type.id);
79
+ if (known !== undefined) {
80
+ return known;
81
+ }
82
+ let found = [];
83
+ if (type.isUnionType() || type.isIntersectionType()) {
84
+ found = type.getTypes();
85
+ }
86
+ else if (type.isObjectType()) {
87
+ const target = targetOf(type);
88
+ const isList = type.isTypeReference() &&
89
+ (arrays.has(target.id) ||
90
+ (target.isObjectType() && (target.objectFlags & ObjectFlags.Tuple) !== 0));
91
+ if (classOf(type) !== undefined || (!isList && isWritten(type))) {
92
+ found = memberTypes(type);
93
+ }
94
+ else if (isList && type.isTypeReference()) {
95
+ found = checker.getTypeArguments(type);
96
+ }
97
+ }
98
+ children.set(type.id, found);
99
+ return found;
100
+ };
101
+ return {
102
+ classesOf: (type) => {
103
+ const found = new Set();
104
+ const seen = new Set();
105
+ const pending = [type];
106
+ for (let next = pending.pop(); next !== undefined; next = pending.pop()) {
107
+ if (seen.has(next.id)) {
108
+ continue;
109
+ }
110
+ seen.add(next.id);
111
+ const owner = classOf(next);
112
+ if (owner !== undefined) {
113
+ found.add(owner);
114
+ }
115
+ pending.push(...childrenOf(next));
116
+ }
117
+ return found;
118
+ },
119
+ };
120
+ }
@@ -4,4 +4,4 @@
4
4
  * independently of the analyzer's own version, which is the one the host answers
5
5
  * from the package the analyzer was installed from.
6
6
  */
7
- export const CONTRACT_VERSION = "3.0.0";
7
+ export const CONTRACT_VERSION = "3.2.0";
package/jsr.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cplieger/deadset-ts",
3
- "version": "3.3.1",
3
+ "version": "3.5.0",
4
4
  "license": "GPL-3.0-or-later",
5
5
  "exports": {
6
6
  ".": "./src/index.ts"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cplieger/deadset-ts",
3
- "version": "3.3.1",
3
+ "version": "3.5.0",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "description": "Deterministic dead-code analysis for TypeScript, class and type members included",
@@ -37,7 +37,7 @@
37
37
  "fast-check": "4.10.2",
38
38
  "prettier": "3.9.9",
39
39
  "typescript": "npm:@typescript/typescript6@6.0.2",
40
- "typescript-eslint": "8.70.1",
40
+ "typescript-eslint": "8.71.0",
41
41
  "vitest": "5.0.2"
42
42
  },
43
43
  "publishConfig": {
package/src/analysis.ts CHANGED
@@ -22,7 +22,9 @@ import {
22
22
  } from "./exempt.ts";
23
23
  import type { TSExemptionClass } from "./exempt-classes.ts";
24
24
  import type { Finding } from "./finding.ts";
25
+ import { frameworkLifecycle } from "./framework-lifecycle.ts";
25
26
  import type { Host } from "./host.ts";
27
+ import { injectionContainer } from "./injection-container.ts";
26
28
  import { interfaceSatisfaction } from "./interface-satisfaction.ts";
27
29
  import { inventory, type Inventory } from "./inventory.ts";
28
30
  import { readManifest } from "./manifest.ts";
@@ -33,6 +35,7 @@ import { reflectiveLookup } from "./reflective-lookup.ts";
33
35
  import { references } from "./references.ts";
34
36
  import { roots, unmatchedEverywhere, unmatchedRoots, type RootKind, type Roots } from "./roots.ts";
35
37
  import type { Scope } from "./scope.ts";
38
+ import { serializationContract } from "./serialization-contract.ts";
36
39
  import { diagnosticsOf, runSession, type Engine, type ProjectView } from "./session.ts";
37
40
  import type { Exemption, SweepInput } from "./sweep.ts";
38
41
  import { readTemplates, templateField } from "./template-field.ts";
@@ -222,6 +225,9 @@ const DETECTORS: Detectors = new Map<TSExemptionClass, Detector>([
222
225
  ["template-field", templateField],
223
226
  ["reflective-lookup", reflectiveLookup],
224
227
  ["decorator", decorator],
228
+ ["injection-container", injectionContainer],
229
+ ["framework-lifecycle", frameworkLifecycle],
230
+ ["serialization-contract", serializationContract],
225
231
  ]);
226
232
 
227
233
  /**
@@ -247,6 +253,7 @@ export function runSweep(
247
253
  const templates = disabled.has("template-field")
248
254
  ? { delimiters: config.analysis.templateDelimiters, files: [] }
249
255
  : readTemplates(host, targetRoot, config.analysis);
256
+ const consumers = scope.consumers.map((consumer) => consumer.path);
250
257
  const read = readProjects(engine, host, scope, config, (project, projectRead) => {
251
258
  const resolved = references(project, projectRead.held, targetRoot, {
252
259
  testFiles: config.ts.testFiles,
@@ -259,7 +266,7 @@ export function runSweep(
259
266
  testFiles: resolved.testFilePaths,
260
267
  };
261
268
  const exempt = computeExemptions(
262
- { project, held: projectRead.held, targetRoot, templates },
269
+ { project, held: projectRead.held, targetRoot, templates, ts: config.ts, consumers },
263
270
  detectors,
264
271
  {
265
272
  disabled,