@tslite/checker 1.9.0 → 1.13.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 +55 -0
- package/NOTICE +14 -0
- package/dist/_namespaces/ts.d.ts +9 -0
- package/dist/_namespaces/ts.js +12 -0
- package/dist/_namespaces/ts.moduleSpecifiers.d.ts +1 -0
- package/dist/_namespaces/ts.moduleSpecifiers.js +2 -0
- package/dist/check.d.ts +75 -0
- package/dist/check.js +316 -0
- package/dist/checker.d.ts +5 -0
- package/dist/checker.js +20881 -0
- package/dist/index.d.ts +1 -1132
- package/dist/index.js +4 -1
- package/dist/moduleSpecifiers.d.ts +12 -0
- package/dist/moduleSpecifiers.js +104 -0
- package/dist/symbolWalker.d.ts +3 -0
- package/dist/symbolWalker.js +167 -0
- package/dist/types.d.ts +864 -0
- package/dist/types.js +355 -0
- package/dist/utilities.d.ts +34 -0
- package/dist/utilities.js +157 -0
- package/lib/lib.tslite.d.ts +56 -0
- package/package.json +28 -49
- package/dist/chunk-NXZILQOD.js +0 -1
- package/dist/index.cjs +0 -1
- package/dist/index.d.cts +0 -1132
- package/dist/types/index.cjs +0 -1
- package/dist/types/index.d.cts +0 -1135
- package/dist/types/index.d.ts +0 -1135
- package/dist/types/index.js +0 -1
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
// Modificado de microsoft/TypeScript v3.9.10, src/compiler/symbolWalker.ts: o namespace virou módulo ES, com os imports explícitos.
|
|
2
|
+
// O walker percorre os tipos e os símbolos que um tipo alcança; quem o pede é o refactor que extrai um trecho, para achar
|
|
3
|
+
// os parâmetros de tipo que o trecho usa (CK-60, CK-67). Saem dele o `thisType` de uma interface (o `this`, CK-02), as
|
|
4
|
+
// construct signatures de um tipo e a flag de classe (CK-02). Os parâmetros do `getBaseTypes` e do `getResolvedSymbol`
|
|
5
|
+
// têm o tipo que o TypeScript 5 deu a eles (o §5 do `docs/ARCHITECTURE.md`).
|
|
6
|
+
import { SyntaxKind, clear, forEach, getOwnValues, getSymbolId, } from "./_namespaces/ts.js";
|
|
7
|
+
export function createGetSymbolWalker(getRestTypeOfSignature, getTypePredicateOfSignature, getReturnTypeOfSignature, getBaseTypes, resolveStructuredTypeMembers, getTypeOfSymbol, getResolvedSymbol, getIndexTypeOfStructuredType, getConstraintOfTypeParameter, getFirstIdentifier, getTypeArguments) {
|
|
8
|
+
return getSymbolWalker;
|
|
9
|
+
function getSymbolWalker(accept = () => true) {
|
|
10
|
+
const visitedTypes = []; // Sparse array from id to type
|
|
11
|
+
const visitedSymbols = []; // Sparse array from id to symbol
|
|
12
|
+
return {
|
|
13
|
+
walkType: type => {
|
|
14
|
+
try {
|
|
15
|
+
visitType(type);
|
|
16
|
+
return { visitedTypes: getOwnValues(visitedTypes), visitedSymbols: getOwnValues(visitedSymbols) };
|
|
17
|
+
}
|
|
18
|
+
finally {
|
|
19
|
+
clear(visitedTypes);
|
|
20
|
+
clear(visitedSymbols);
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
walkSymbol: symbol => {
|
|
24
|
+
try {
|
|
25
|
+
visitSymbol(symbol);
|
|
26
|
+
return { visitedTypes: getOwnValues(visitedTypes), visitedSymbols: getOwnValues(visitedSymbols) };
|
|
27
|
+
}
|
|
28
|
+
finally {
|
|
29
|
+
clear(visitedTypes);
|
|
30
|
+
clear(visitedSymbols);
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
function visitType(type) {
|
|
35
|
+
if (!type) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (visitedTypes[type.id]) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
visitedTypes[type.id] = type;
|
|
42
|
+
// Reuse visitSymbol to visit the type's symbol,
|
|
43
|
+
// but be sure to bail on recuring into the type if accept declines the symbol.
|
|
44
|
+
const shouldBail = visitSymbol(type.symbol);
|
|
45
|
+
if (shouldBail)
|
|
46
|
+
return;
|
|
47
|
+
// Visit the type's related types, if any
|
|
48
|
+
if (type.flags & 524288 /* TypeFlags.Object */) {
|
|
49
|
+
const objectType = type;
|
|
50
|
+
const objectFlags = objectType.objectFlags;
|
|
51
|
+
if (objectFlags & 4 /* ObjectFlags.Reference */) {
|
|
52
|
+
visitTypeReference(type);
|
|
53
|
+
}
|
|
54
|
+
if (objectFlags & 32 /* ObjectFlags.Mapped */) {
|
|
55
|
+
visitMappedType(type);
|
|
56
|
+
}
|
|
57
|
+
// Na tag, também a classe (CK-02).
|
|
58
|
+
if (objectFlags & 2 /* ObjectFlags.Interface */) {
|
|
59
|
+
visitInterfaceType(type);
|
|
60
|
+
}
|
|
61
|
+
if (objectFlags & (8 /* ObjectFlags.Tuple */ | 16 /* ObjectFlags.Anonymous */)) {
|
|
62
|
+
visitObjectType(objectType);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (type.flags & 262144 /* TypeFlags.TypeParameter */) {
|
|
66
|
+
visitTypeParameter(type);
|
|
67
|
+
}
|
|
68
|
+
if (type.flags & 3145728 /* TypeFlags.UnionOrIntersection */) {
|
|
69
|
+
visitUnionOrIntersectionType(type);
|
|
70
|
+
}
|
|
71
|
+
if (type.flags & 4194304 /* TypeFlags.Index */) {
|
|
72
|
+
visitIndexType(type);
|
|
73
|
+
}
|
|
74
|
+
if (type.flags & 8388608 /* TypeFlags.IndexedAccess */) {
|
|
75
|
+
visitIndexedAccessType(type);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function visitTypeReference(type) {
|
|
79
|
+
visitType(type.target);
|
|
80
|
+
forEach(getTypeArguments(type), visitType);
|
|
81
|
+
}
|
|
82
|
+
function visitTypeParameter(type) {
|
|
83
|
+
visitType(getConstraintOfTypeParameter(type));
|
|
84
|
+
}
|
|
85
|
+
function visitUnionOrIntersectionType(type) {
|
|
86
|
+
forEach(type.types, visitType);
|
|
87
|
+
}
|
|
88
|
+
function visitIndexType(type) {
|
|
89
|
+
visitType(type.type);
|
|
90
|
+
}
|
|
91
|
+
function visitIndexedAccessType(type) {
|
|
92
|
+
visitType(type.objectType);
|
|
93
|
+
visitType(type.indexType);
|
|
94
|
+
visitType(type.constraint);
|
|
95
|
+
}
|
|
96
|
+
function visitMappedType(type) {
|
|
97
|
+
visitType(type.typeParameter);
|
|
98
|
+
visitType(type.constraintType);
|
|
99
|
+
visitType(type.templateType);
|
|
100
|
+
visitType(type.modifiersType);
|
|
101
|
+
}
|
|
102
|
+
function visitSignature(signature) {
|
|
103
|
+
const typePredicate = getTypePredicateOfSignature(signature);
|
|
104
|
+
if (typePredicate) {
|
|
105
|
+
visitType(typePredicate.type);
|
|
106
|
+
}
|
|
107
|
+
forEach(signature.typeParameters, visitType);
|
|
108
|
+
for (const parameter of signature.parameters) {
|
|
109
|
+
visitSymbol(parameter);
|
|
110
|
+
}
|
|
111
|
+
visitType(getRestTypeOfSignature(signature));
|
|
112
|
+
visitType(getReturnTypeOfSignature(signature));
|
|
113
|
+
}
|
|
114
|
+
// Na tag, também o tipo `this` da interface (CK-02). A interface que fica é a de um embutido, que nasce com as
|
|
115
|
+
// bases resolvidas (CK-48), ou o alvo de uma tupla.
|
|
116
|
+
function visitInterfaceType(interfaceT) {
|
|
117
|
+
visitObjectType(interfaceT);
|
|
118
|
+
forEach(interfaceT.typeParameters, visitType);
|
|
119
|
+
forEach(getBaseTypes(interfaceT), visitType);
|
|
120
|
+
}
|
|
121
|
+
// Na tag, também as construct signatures (CK-02).
|
|
122
|
+
function visitObjectType(type) {
|
|
123
|
+
const stringIndexType = getIndexTypeOfStructuredType(type, 0 /* IndexKind.String */);
|
|
124
|
+
visitType(stringIndexType);
|
|
125
|
+
const numberIndexType = getIndexTypeOfStructuredType(type, 1 /* IndexKind.Number */);
|
|
126
|
+
visitType(numberIndexType);
|
|
127
|
+
// The two checks above *should* have already resolved the type (if needed), so this should be cached
|
|
128
|
+
const resolved = resolveStructuredTypeMembers(type);
|
|
129
|
+
for (const signature of resolved.callSignatures) {
|
|
130
|
+
visitSignature(signature);
|
|
131
|
+
}
|
|
132
|
+
for (const p of resolved.properties) {
|
|
133
|
+
visitSymbol(p);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
function visitSymbol(symbol) {
|
|
137
|
+
if (!symbol) {
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
const symbolId = getSymbolId(symbol);
|
|
141
|
+
if (visitedSymbols[symbolId]) {
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
visitedSymbols[symbolId] = symbol;
|
|
145
|
+
if (!accept(symbol)) {
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
const t = getTypeOfSymbol(symbol);
|
|
149
|
+
visitType(t); // Should handle members on classes and such
|
|
150
|
+
if (symbol.exports) {
|
|
151
|
+
symbol.exports.forEach(visitSymbol);
|
|
152
|
+
}
|
|
153
|
+
forEach(symbol.declarations, d => {
|
|
154
|
+
// Type queries are too far resolved when we just visit the symbol's type
|
|
155
|
+
// (their type resolved directly to the member deeply referenced)
|
|
156
|
+
// So to get the intervening symbols, we need to check if there's a type
|
|
157
|
+
// query node on any of the symbol's declarations and get symbols there
|
|
158
|
+
if (d.type && d.type.kind === SyntaxKind.TypeQuery) {
|
|
159
|
+
const query = d.type;
|
|
160
|
+
const entity = getResolvedSymbol(getFirstIdentifier(query.exprName));
|
|
161
|
+
visitSymbol(entity);
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|