fallow-type-aware 3.42.0 → 3.43.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/README.md +6 -0
- package/package.json +1 -1
- package/src/accessor-direction.mjs +113 -0
- package/src/call-evidence.mjs +1493 -0
- package/src/cli.mjs +16 -2
- package/src/declaration-facts.mjs +27 -0
- package/src/file-identity.mjs +18 -2
- package/src/generated-protocol.mjs +2 -0
- package/src/mutant-typecheck.mjs +2 -2
- package/src/optional-chain-proof.mjs +107 -82
- package/src/project-state.mjs +28 -1
- package/src/protocol.mjs +106 -0
- package/src/reference-names.mjs +97 -22
- package/src/semantic-identity.mjs +32 -3
- package/src/semantic.mjs +7 -20
package/README.md
CHANGED
|
@@ -8,6 +8,12 @@ The wire protocol accepts a bounded set of tagged `symbol-use`, `symbol-trace`,
|
|
|
8
8
|
TypeScript project creates one Program. Symbol use, trace, and impact queries
|
|
9
9
|
share one indexed source traversal per Program.
|
|
10
10
|
|
|
11
|
+
The one-shot `call-evidence` operation serves the opt-in `constant-parameter`
|
|
12
|
+
rule of Fallow. For each candidate parameter with a default, it reports whether
|
|
13
|
+
an argument of a call can be `undefined`. For each method of an exported class,
|
|
14
|
+
it lists the calls that the checker resolves, or a stable reason why a call can
|
|
15
|
+
be invisible. A semantic session does not accept this operation.
|
|
16
|
+
|
|
11
17
|
Symbol identities include the canonical project-relative path, value or type
|
|
12
18
|
namespace, declaration kind, exported and local name, one-based line,
|
|
13
19
|
zero-based UTF-8 byte column, and optional owner. Results keep their semantic
|
package/package.json
CHANGED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { ast, SyntaxKind } from "./backend.mjs";
|
|
2
|
+
import { declarationName, ownerDeclaration } from "./semantic-identity.mjs";
|
|
3
|
+
|
|
4
|
+
const { isGetAccessorDeclaration, isSetAccessorDeclaration } = ast;
|
|
5
|
+
|
|
6
|
+
// Node kinds that a write target passes through on the way to its assignment:
|
|
7
|
+
// `[a] = xs`, `({ a } = o)`, `({ k: a } = o)`, `(a as T) = v`.
|
|
8
|
+
const TARGET_WRAPPERS = new Set([
|
|
9
|
+
SyntaxKind.ParenthesizedExpression,
|
|
10
|
+
SyntaxKind.ArrayLiteralExpression,
|
|
11
|
+
SyntaxKind.ObjectLiteralExpression,
|
|
12
|
+
SyntaxKind.ShorthandPropertyAssignment,
|
|
13
|
+
SyntaxKind.SpreadElement,
|
|
14
|
+
SyntaxKind.SpreadAssignment,
|
|
15
|
+
SyntaxKind.AsExpression,
|
|
16
|
+
SyntaxKind.TypeAssertionExpression,
|
|
17
|
+
SyntaxKind.NonNullExpression,
|
|
18
|
+
SyntaxKind.SatisfiesExpression,
|
|
19
|
+
]);
|
|
20
|
+
|
|
21
|
+
const isAssignmentOperator = (kind) =>
|
|
22
|
+
kind >= SyntaxKind.FirstAssignment && kind <= SyntaxKind.LastAssignment;
|
|
23
|
+
|
|
24
|
+
const isIncrementOperator = (kind) =>
|
|
25
|
+
kind === SyntaxKind.PlusPlusToken || kind === SyntaxKind.MinusMinusToken;
|
|
26
|
+
|
|
27
|
+
const memberAccess = (reference) => {
|
|
28
|
+
const parent = reference.parent;
|
|
29
|
+
if (parent?.kind === SyntaxKind.PropertyAccessExpression && parent.name === reference) {
|
|
30
|
+
return parent;
|
|
31
|
+
}
|
|
32
|
+
if (
|
|
33
|
+
parent?.kind === SyntaxKind.ElementAccessExpression &&
|
|
34
|
+
parent.argumentExpression === reference
|
|
35
|
+
) {
|
|
36
|
+
return parent;
|
|
37
|
+
}
|
|
38
|
+
return reference;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const binaryDirection = (parent, node) => {
|
|
42
|
+
if (parent.left !== node || !isAssignmentOperator(parent.operatorToken.kind)) return "read";
|
|
43
|
+
return parent.operatorToken.kind === SyntaxKind.EqualsToken ? "write" : "read-write";
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* How an expression is accessed: `read`, `write` (the target of a plain `=`, a
|
|
48
|
+
* destructuring assignment or a `for...in`/`for...of` head), or `read-write`
|
|
49
|
+
* (a compound assignment, `++` or `--`).
|
|
50
|
+
*/
|
|
51
|
+
export const targetDirection = (target) => {
|
|
52
|
+
let node = target;
|
|
53
|
+
for (let parent = node.parent; parent; parent = node.parent) {
|
|
54
|
+
if (TARGET_WRAPPERS.has(parent.kind)) {
|
|
55
|
+
node = parent;
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
switch (parent.kind) {
|
|
59
|
+
case SyntaxKind.PropertyAssignment:
|
|
60
|
+
if (parent.initializer !== node) return "read";
|
|
61
|
+
node = parent;
|
|
62
|
+
continue;
|
|
63
|
+
case SyntaxKind.BinaryExpression:
|
|
64
|
+
return binaryDirection(parent, node);
|
|
65
|
+
case SyntaxKind.PrefixUnaryExpression:
|
|
66
|
+
case SyntaxKind.PostfixUnaryExpression:
|
|
67
|
+
return isIncrementOperator(parent.operator) ? "read-write" : "read";
|
|
68
|
+
case SyntaxKind.ForInStatement:
|
|
69
|
+
case SyntaxKind.ForOfStatement:
|
|
70
|
+
return parent.initializer === node ? "write" : "read";
|
|
71
|
+
default:
|
|
72
|
+
return "read";
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return "read";
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/** Whether a getter or setter has the other half of its pair in the same owner. */
|
|
79
|
+
export const accessorPairExists = (declaration) => {
|
|
80
|
+
if (!isGetAccessorDeclaration(declaration) && !isSetAccessorDeclaration(declaration)) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
const owner = ownerDeclaration(declaration);
|
|
84
|
+
const name = declarationName(declaration);
|
|
85
|
+
return Boolean(
|
|
86
|
+
owner?.members?.some(
|
|
87
|
+
(member) =>
|
|
88
|
+
member !== declaration &&
|
|
89
|
+
declarationName(member) === name &&
|
|
90
|
+
(isGetAccessorDeclaration(member) || isSetAccessorDeclaration(member)),
|
|
91
|
+
),
|
|
92
|
+
);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Whether a reference counts as a use of this declaration. The checker gives
|
|
97
|
+
* both halves of a get and set accessor pair one symbol, so a read would
|
|
98
|
+
* otherwise confirm the setter and a write would confirm the getter. A lone
|
|
99
|
+
* accessor counts every reference.
|
|
100
|
+
*/
|
|
101
|
+
const isShorthandKey = (reference) =>
|
|
102
|
+
reference.parent?.kind === SyntaxKind.ShorthandPropertyAssignment &&
|
|
103
|
+
reference.parent.name === reference;
|
|
104
|
+
|
|
105
|
+
const memberDirection = (reference) =>
|
|
106
|
+
// The key of `({ value } = inst)` reads `inst.value` and writes only the local binding.
|
|
107
|
+
isShorthandKey(reference) ? "read" : targetDirection(memberAccess(reference));
|
|
108
|
+
|
|
109
|
+
export const countsAsAccessorUse = (declaration, reference) => {
|
|
110
|
+
if (!accessorPairExists(declaration)) return true;
|
|
111
|
+
const direction = memberDirection(reference);
|
|
112
|
+
return isSetAccessorDeclaration(declaration) ? direction !== "read" : direction !== "write";
|
|
113
|
+
};
|