@stateward/core 1.0.1 → 1.1.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/dist/backend/fingerprints.d.ts +22 -2
- package/dist/backend/fingerprints.js +160 -18
- package/dist/backend/program-record.d.ts +1 -1
- package/dist/backend/qualified-ids.d.ts +6 -0
- package/dist/backend/qualified-ids.js +66 -10
- package/dist/backend/typescript6.d.ts +28 -9
- package/dist/backend/typescript6.js +223 -22
- package/dist/cache.d.ts +5 -4
- package/dist/cache.js +2 -2
- package/dist/checker.d.ts +14 -2
- package/dist/checker.js +27 -5
- package/dist/config.js +47 -4
- package/dist/disk-cache.d.ts +24 -2
- package/dist/disk-cache.js +43 -5
- package/dist/engine.d.ts +25 -3
- package/dist/engine.js +186 -50
- package/dist/guarantees.d.ts +41 -0
- package/dist/guarantees.js +68 -0
- package/dist/ignores.d.ts +2 -4
- package/dist/ignores.js +11 -15
- package/dist/index.d.ts +1 -1
- package/dist/internal.d.ts +5 -3
- package/dist/internal.js +4 -3
- package/dist/plan.d.ts +17 -0
- package/dist/plan.js +22 -5
- package/dist/testing-tsc.d.ts +11 -0
- package/dist/testing-tsc.js +125 -0
- package/dist/testing.d.ts +1 -0
- package/dist/testing.js +13 -0
- package/dist/types.d.ts +121 -0
- package/package.json +1 -1
|
@@ -1,6 +1,26 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
2
|
/** The hash of a parsed file's text, computed once per parsed file. */
|
|
3
3
|
export declare function textHash(sourceFile: ts.SourceFile): string;
|
|
4
|
+
/**
|
|
5
|
+
* The hash of what a rule handed `node` (`TypeQueries.declarationOf`) can learn from its file,
|
|
6
|
+
* short of the file's whole text: a cache entry that read `node` holds while this is the same.
|
|
7
|
+
*
|
|
8
|
+
* - The top-level statement `node` is in, as written, with the comments before it (JSDoc tags are
|
|
9
|
+
* read: `calleeTags`). A rule walks up from a declaration (a `const`'s keyword, a method's class,
|
|
10
|
+
* a parameter's function), so the whole statement counts, not the node alone.
|
|
11
|
+
* - Every other top-level statement related to it by name, transitively: one that declares a name
|
|
12
|
+
* it mentions (a helper it calls, a constant whose literal type is read, an import, the overloads
|
|
13
|
+
* and merged declarations of its own name, a declaration added that shadows a global), and one
|
|
14
|
+
* that mentions a name of the set without declaring any (`X.y = …`, `export default X`,
|
|
15
|
+
* `export { X }`; a re-export adds no names of its own). Names are matched by text, not
|
|
16
|
+
* by scope: more is included than is needed, never less.
|
|
17
|
+
*
|
|
18
|
+
* Positions are not part of it (a comment added above shifts them): a rule that keeps another
|
|
19
|
+
* file's offsets in what it returns is noted as reading that whole file (engine `readsAfter`).
|
|
20
|
+
* Syntax only, no parent pointers needed (`node` is found by position). A JavaScript file's types
|
|
21
|
+
* come from JSDoc, whose names are not matched: its hash is its whole text.
|
|
22
|
+
*/
|
|
23
|
+
export declare function declarationTextHash(sourceFile: ts.SourceFile, node: ts.Node): string;
|
|
4
24
|
/**
|
|
5
25
|
* The hash of what a file shows its importers through the type checker (`shapeText`), or of its
|
|
6
26
|
* full text when it has no smaller shape. Computed once per parsed file: it is syntax only.
|
|
@@ -22,8 +42,8 @@ export declare function shapeHash(sourceFile: ts.SourceFile): string;
|
|
|
22
42
|
*
|
|
23
43
|
* Kept as well: every parsed JSDoc comment on what is kept (`TypeQueries.calleeTags` reads its
|
|
24
44
|
* tags), the comments at the top of the file that hold a pragma or a directive (`@jsx…`,
|
|
25
|
-
* `/// <reference …/>`)
|
|
26
|
-
* counts
|
|
45
|
+
* `/// <reference …/>`). The offset of a top-level `X.y = …` is not kept: the qualified id of `y`
|
|
46
|
+
* counts the same-named ones before it (qualified-ids.ts), which the statements' tokens show.
|
|
27
47
|
*
|
|
28
48
|
* A function without a declared return type keeps its body: its type is inferred from it.
|
|
29
49
|
*/
|
|
@@ -27,9 +27,9 @@ import { stronglyConnectedComponents } from "../graph.js";
|
|
|
27
27
|
* fingerprint.
|
|
28
28
|
*
|
|
29
29
|
* A rule can also be handed another file's syntax (`TypeQueries.declarationOf`) and read beyond
|
|
30
|
-
* its shape: a function's body, a `const`'s initializer. Each
|
|
31
|
-
* recorded
|
|
32
|
-
* each of those is the same (docs/architecture.md, "Incremental runs").
|
|
30
|
+
* its shape: a function's body, a `const`'s initializer. Each declaration a rule on a file was
|
|
31
|
+
* handed is recorded by its qualified id with `declarationTextHash` (`ProjectUnit.readsOf`), and a
|
|
32
|
+
* result is reused only while each of those is the same (docs/architecture.md, "Incremental runs").
|
|
33
33
|
*/
|
|
34
34
|
const textHashes = new WeakMap();
|
|
35
35
|
function sha1(text) {
|
|
@@ -44,6 +44,161 @@ export function textHash(sourceFile) {
|
|
|
44
44
|
}
|
|
45
45
|
return hash;
|
|
46
46
|
}
|
|
47
|
+
/** The names each top-level statement declares and mentions, per parsed file. */
|
|
48
|
+
const statementNames = new WeakMap();
|
|
49
|
+
function bindingNames(name, into) {
|
|
50
|
+
if (ts.isIdentifier(name)) {
|
|
51
|
+
into.push(name.text);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
for (const element of name.elements) {
|
|
55
|
+
if (ts.isBindingElement(element))
|
|
56
|
+
bindingNames(element.name, into);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/** The names a top-level statement declares, exported or not; empty for one that declares none. */
|
|
60
|
+
function declaredNames(statement) {
|
|
61
|
+
if (ts.isVariableStatement(statement)) {
|
|
62
|
+
const names = [];
|
|
63
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
64
|
+
bindingNames(declaration.name, names);
|
|
65
|
+
}
|
|
66
|
+
return names;
|
|
67
|
+
}
|
|
68
|
+
if (ts.isImportDeclaration(statement)) {
|
|
69
|
+
const clause = statement.importClause;
|
|
70
|
+
const names = [];
|
|
71
|
+
if (clause?.name !== undefined)
|
|
72
|
+
names.push(clause.name.text);
|
|
73
|
+
const bindings = clause?.namedBindings;
|
|
74
|
+
if (bindings !== undefined && ts.isNamespaceImport(bindings))
|
|
75
|
+
names.push(bindings.name.text);
|
|
76
|
+
if (bindings !== undefined && ts.isNamedImports(bindings)) {
|
|
77
|
+
for (const element of bindings.elements)
|
|
78
|
+
names.push(element.name.text);
|
|
79
|
+
}
|
|
80
|
+
return names;
|
|
81
|
+
}
|
|
82
|
+
if ((ts.isFunctionDeclaration(statement) ||
|
|
83
|
+
ts.isClassDeclaration(statement) ||
|
|
84
|
+
ts.isInterfaceDeclaration(statement) ||
|
|
85
|
+
ts.isTypeAliasDeclaration(statement) ||
|
|
86
|
+
ts.isEnumDeclaration(statement) ||
|
|
87
|
+
ts.isImportEqualsDeclaration(statement) ||
|
|
88
|
+
ts.isModuleDeclaration(statement)) &&
|
|
89
|
+
statement.name !== undefined &&
|
|
90
|
+
ts.isIdentifier(statement.name)) {
|
|
91
|
+
return [statement.name.text];
|
|
92
|
+
}
|
|
93
|
+
return [];
|
|
94
|
+
}
|
|
95
|
+
function namesOfStatements(sourceFile) {
|
|
96
|
+
let found = statementNames.get(sourceFile);
|
|
97
|
+
if (found !== undefined)
|
|
98
|
+
return found;
|
|
99
|
+
found = sourceFile.statements.map((statement) => {
|
|
100
|
+
const mentions = new Set();
|
|
101
|
+
const visit = (node) => {
|
|
102
|
+
if (ts.isIdentifier(node))
|
|
103
|
+
mentions.add(node.text);
|
|
104
|
+
else
|
|
105
|
+
ts.forEachChild(node, visit);
|
|
106
|
+
};
|
|
107
|
+
visit(statement);
|
|
108
|
+
return {
|
|
109
|
+
declares: declaredNames(statement),
|
|
110
|
+
mentions,
|
|
111
|
+
expands: !ts.isExportDeclaration(statement) && !ts.isExportAssignment(statement),
|
|
112
|
+
};
|
|
113
|
+
});
|
|
114
|
+
statementNames.set(sourceFile, found);
|
|
115
|
+
return found;
|
|
116
|
+
}
|
|
117
|
+
/** The hash of each top-level statement's related text, per parsed file, by statement index. */
|
|
118
|
+
const declarationHashes = new WeakMap();
|
|
119
|
+
/**
|
|
120
|
+
* The hash of what a rule handed `node` (`TypeQueries.declarationOf`) can learn from its file,
|
|
121
|
+
* short of the file's whole text: a cache entry that read `node` holds while this is the same.
|
|
122
|
+
*
|
|
123
|
+
* - The top-level statement `node` is in, as written, with the comments before it (JSDoc tags are
|
|
124
|
+
* read: `calleeTags`). A rule walks up from a declaration (a `const`'s keyword, a method's class,
|
|
125
|
+
* a parameter's function), so the whole statement counts, not the node alone.
|
|
126
|
+
* - Every other top-level statement related to it by name, transitively: one that declares a name
|
|
127
|
+
* it mentions (a helper it calls, a constant whose literal type is read, an import, the overloads
|
|
128
|
+
* and merged declarations of its own name, a declaration added that shadows a global), and one
|
|
129
|
+
* that mentions a name of the set without declaring any (`X.y = …`, `export default X`,
|
|
130
|
+
* `export { X }`; a re-export adds no names of its own). Names are matched by text, not
|
|
131
|
+
* by scope: more is included than is needed, never less.
|
|
132
|
+
*
|
|
133
|
+
* Positions are not part of it (a comment added above shifts them): a rule that keeps another
|
|
134
|
+
* file's offsets in what it returns is noted as reading that whole file (engine `readsAfter`).
|
|
135
|
+
* Syntax only, no parent pointers needed (`node` is found by position). A JavaScript file's types
|
|
136
|
+
* come from JSDoc, whose names are not matched: its hash is its whole text.
|
|
137
|
+
*/
|
|
138
|
+
export function declarationTextHash(sourceFile, node) {
|
|
139
|
+
// JavaScript types come from JSDoc, whose names `mentions` does not see: the whole text.
|
|
140
|
+
if (ts.isSourceFile(node) || !TYPESCRIPT_SOURCE.test(sourceFile.fileName)) {
|
|
141
|
+
return textHash(sourceFile);
|
|
142
|
+
}
|
|
143
|
+
const { statements, text } = sourceFile;
|
|
144
|
+
const index = statements.findIndex((statement) => statement.pos <= node.pos && node.end <= statement.end);
|
|
145
|
+
if (index < 0)
|
|
146
|
+
return textHash(sourceFile);
|
|
147
|
+
let byIndex = declarationHashes.get(sourceFile);
|
|
148
|
+
if (byIndex === undefined) {
|
|
149
|
+
byIndex = new Map();
|
|
150
|
+
declarationHashes.set(sourceFile, byIndex);
|
|
151
|
+
}
|
|
152
|
+
const known = byIndex.get(index);
|
|
153
|
+
if (known !== undefined)
|
|
154
|
+
return known;
|
|
155
|
+
const names = namesOfStatements(sourceFile);
|
|
156
|
+
const declaredBy = new Map();
|
|
157
|
+
const mentionedBy = new Map();
|
|
158
|
+
names.forEach((statement, at) => {
|
|
159
|
+
const into = statement.declares.length > 0 ? declaredBy : mentionedBy;
|
|
160
|
+
const keys = statement.declares.length > 0 ? statement.declares : statement.mentions;
|
|
161
|
+
for (const key of keys) {
|
|
162
|
+
const list = into.get(key) ?? [];
|
|
163
|
+
list.push(at);
|
|
164
|
+
into.set(key, list);
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
const included = new Set();
|
|
168
|
+
const seen = new Set();
|
|
169
|
+
const pending = [];
|
|
170
|
+
const include = (at, expand) => {
|
|
171
|
+
if (included.has(at))
|
|
172
|
+
return;
|
|
173
|
+
included.add(at);
|
|
174
|
+
const statement = names[at];
|
|
175
|
+
if (statement === undefined || !expand)
|
|
176
|
+
return;
|
|
177
|
+
for (const name of statement.declares)
|
|
178
|
+
pending.push(name);
|
|
179
|
+
for (const name of statement.mentions)
|
|
180
|
+
pending.push(name);
|
|
181
|
+
};
|
|
182
|
+
include(index, true);
|
|
183
|
+
for (let name = pending.pop(); name !== undefined; name = pending.pop()) {
|
|
184
|
+
if (seen.has(name))
|
|
185
|
+
continue;
|
|
186
|
+
seen.add(name);
|
|
187
|
+
for (const at of declaredBy.get(name) ?? [])
|
|
188
|
+
include(at, true);
|
|
189
|
+
for (const at of mentionedBy.get(name) ?? [])
|
|
190
|
+
include(at, names[at]?.expands === true);
|
|
191
|
+
}
|
|
192
|
+
const parts = [...included]
|
|
193
|
+
.sort((a, b) => a - b)
|
|
194
|
+
.map((at) => {
|
|
195
|
+
const statement = statements[at];
|
|
196
|
+
return statement === undefined ? "" : text.slice(statement.pos, statement.end);
|
|
197
|
+
});
|
|
198
|
+
const hash = sha1(`declaration\u0000${parts.join("\u0000")}`);
|
|
199
|
+
byIndex.set(index, hash);
|
|
200
|
+
return hash;
|
|
201
|
+
}
|
|
47
202
|
const shapeHashes = new WeakMap();
|
|
48
203
|
/**
|
|
49
204
|
* The hash of what a file shows its importers through the type checker (`shapeText`), or of its
|
|
@@ -97,16 +252,6 @@ function localNames(statement) {
|
|
|
97
252
|
}
|
|
98
253
|
return undefined;
|
|
99
254
|
}
|
|
100
|
-
/** `X.y = …` at the top of a module: TypeScript declares `y` on `X` there (an expando). */
|
|
101
|
-
function isExpandoAssignment(statement) {
|
|
102
|
-
if (!ts.isExpressionStatement(statement))
|
|
103
|
-
return false;
|
|
104
|
-
const { expression } = statement;
|
|
105
|
-
return (ts.isBinaryExpression(expression) &&
|
|
106
|
-
expression.operatorToken.kind === ts.SyntaxKind.EqualsToken &&
|
|
107
|
-
(ts.isPropertyAccessExpression(expression.left) ||
|
|
108
|
-
ts.isElementAccessExpression(expression.left)));
|
|
109
|
-
}
|
|
110
255
|
/** The text of each parsed JSDoc comment on `node` (parsed only in the modes that read it). */
|
|
111
256
|
function jsDocTexts(node, text, into) {
|
|
112
257
|
const docs = Reflect.get(node, "jsDoc");
|
|
@@ -138,8 +283,8 @@ function jsDocTexts(node, text, into) {
|
|
|
138
283
|
*
|
|
139
284
|
* Kept as well: every parsed JSDoc comment on what is kept (`TypeQueries.calleeTags` reads its
|
|
140
285
|
* tags), the comments at the top of the file that hold a pragma or a directive (`@jsx…`,
|
|
141
|
-
* `/// <reference …/>`)
|
|
142
|
-
* counts
|
|
286
|
+
* `/// <reference …/>`). The offset of a top-level `X.y = …` is not kept: the qualified id of `y`
|
|
287
|
+
* counts the same-named ones before it (qualified-ids.ts), which the statements' tokens show.
|
|
143
288
|
*
|
|
144
289
|
* A function without a declared return type keeps its body: its type is inferred from it.
|
|
145
290
|
*/
|
|
@@ -231,9 +376,6 @@ export function shapeText(sourceFile) {
|
|
|
231
376
|
if (statement === undefined || kept.has(index))
|
|
232
377
|
return;
|
|
233
378
|
kept.add(index);
|
|
234
|
-
if (isExpandoAssignment(statement)) {
|
|
235
|
-
notes.push(`expando at ${String(statement.getStart(sourceFile))}`);
|
|
236
|
-
}
|
|
237
379
|
tokens = "";
|
|
238
380
|
visit(statement);
|
|
239
381
|
printed[index] = tokens;
|
|
@@ -25,7 +25,7 @@ export type ProgramRecord = {
|
|
|
25
25
|
/** Their dependency fingerprints. */
|
|
26
26
|
readonly fingerprints: Readonly<Record<string, string>>;
|
|
27
27
|
/**
|
|
28
|
-
* The
|
|
28
|
+
* The hashes of what rules read of other files, by read id (`ProjectUnit.readFingerprint`):
|
|
29
29
|
* filled while the run that built the program asks for them.
|
|
30
30
|
*/
|
|
31
31
|
readonly reads: Record<string, string>;
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
|
+
/**
|
|
3
|
+
* The declaration at `path` in `sourceFile` (see above; "" is the file itself), or undefined when
|
|
4
|
+
* the file has none there: it was renamed, moved or removed. Only the paths the walk names: one
|
|
5
|
+
* placed by its offset (`$Kind@12`) is not looked up. Needs no parent pointers.
|
|
6
|
+
*/
|
|
7
|
+
export declare function declarationAtPath(sourceFile: ts.SourceFile, path: string): ts.Node | undefined;
|
|
2
8
|
/** The path of `declaration` in its file (see above); "" for the file itself. */
|
|
3
9
|
export declare function declarationPath(declaration: ts.Node): string;
|
|
4
10
|
//# sourceMappingURL=qualified-ids.d.ts.map
|
|
@@ -3,12 +3,15 @@ import ts from "typescript";
|
|
|
3
3
|
* Qualified ids: `<file relative to the project>#<path>`, where the
|
|
4
4
|
* path is the chain of declaration names from the file down (`src/cart.ts#useCart.onAdd`). A name
|
|
5
5
|
* that repeats under the same parent gets a counter in file order (`#App.handler$2`); a declaration
|
|
6
|
-
* without a name is `$<SyntaxKind>` (`#default.$ArrowFunction`).
|
|
6
|
+
* without a name is `$<SyntaxKind>` (`#default.$ArrowFunction`). An assignment statement
|
|
7
|
+
* `X.y = …` (or `X["y"] = …`), where TypeScript declares `y` on `X` (an expando), is
|
|
8
|
+
* `$expando:y`, with a counter among the same-named ones under its parent (`#$expando:label$2`):
|
|
9
|
+
* never its offset, so a comment above it keeps the id. The module itself is `<file>#`.
|
|
7
10
|
* Syntax only: an edit that does not rename, add or remove a declaration of the same name before
|
|
8
11
|
* this one under the same parent keeps every id, unlike an offset.
|
|
9
12
|
*/
|
|
10
13
|
/** The text of a declaration's name; undefined for a binding pattern or no name. */
|
|
11
|
-
function nameText(name) {
|
|
14
|
+
function nameText(name, sourceFile) {
|
|
12
15
|
if (name === undefined)
|
|
13
16
|
return undefined;
|
|
14
17
|
if (ts.isIdentifier(name) ||
|
|
@@ -17,8 +20,9 @@ function nameText(name) {
|
|
|
17
20
|
ts.isNumericLiteral(name)) {
|
|
18
21
|
return name.text;
|
|
19
22
|
}
|
|
23
|
+
// The file is passed: a file parsed for a read (`declarationAtPath`) may have no parents yet.
|
|
20
24
|
if (ts.isComputedPropertyName(name))
|
|
21
|
-
return `[${name.expression.getText()}]`;
|
|
25
|
+
return `[${name.expression.getText(sourceFile)}]`;
|
|
22
26
|
if (ts.isJsxNamespacedName(name))
|
|
23
27
|
return `${name.namespace.text}:${name.name.text}`;
|
|
24
28
|
return undefined;
|
|
@@ -27,9 +31,9 @@ function isDefaultExport(node) {
|
|
|
27
31
|
return (node.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.DefaultKeyword) ?? false);
|
|
28
32
|
}
|
|
29
33
|
/** The path segment a node adds, when it is a named declaration. */
|
|
30
|
-
function declarationName(node) {
|
|
34
|
+
function declarationName(node, sourceFile) {
|
|
31
35
|
if (ts.isFunctionDeclaration(node) || ts.isClassDeclaration(node)) {
|
|
32
|
-
return nameText(node.name) ?? (isDefaultExport(node) ? "default" : undefined);
|
|
36
|
+
return nameText(node.name, sourceFile) ?? (isDefaultExport(node) ? "default" : undefined);
|
|
33
37
|
}
|
|
34
38
|
if (ts.isConstructorDeclaration(node))
|
|
35
39
|
return "constructor";
|
|
@@ -61,11 +65,34 @@ function declarationName(node) {
|
|
|
61
65
|
ts.isImportClause(node) ||
|
|
62
66
|
ts.isImportEqualsDeclaration(node) ||
|
|
63
67
|
ts.isJsxAttribute(node)) {
|
|
64
|
-
return nameText(node.name);
|
|
68
|
+
return nameText(node.name, sourceFile);
|
|
65
69
|
}
|
|
66
70
|
return undefined;
|
|
67
71
|
}
|
|
68
72
|
const K = ts.SyntaxKind;
|
|
73
|
+
/**
|
|
74
|
+
* The target of a statement `X.y = …`: the access expression TypeScript declares an expando
|
|
75
|
+
* property by, with the name it declares. Undefined for any other statement. No parent pointers.
|
|
76
|
+
*/
|
|
77
|
+
function expandoOf(statement, sourceFile) {
|
|
78
|
+
const { expression } = statement;
|
|
79
|
+
if (!ts.isBinaryExpression(expression) || expression.operatorToken.kind !== K.EqualsToken) {
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
const { left } = expression;
|
|
83
|
+
if (ts.isPropertyAccessExpression(left)) {
|
|
84
|
+
const name = nameText(left.name, sourceFile);
|
|
85
|
+
return name === undefined ? undefined : { target: left, name };
|
|
86
|
+
}
|
|
87
|
+
if (ts.isElementAccessExpression(left)) {
|
|
88
|
+
const argument = left.argumentExpression;
|
|
89
|
+
const name = ts.isStringLiteralLike(argument) || ts.isNumericLiteral(argument)
|
|
90
|
+
? argument.text
|
|
91
|
+
: `[${argument.getText(sourceFile)}]`;
|
|
92
|
+
return { target: left, name };
|
|
93
|
+
}
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
69
96
|
/** The kinds `declarationName` names: a cheap test before the typed one, as the walk visits every node. */
|
|
70
97
|
const NAMED_KINDS = new Set([
|
|
71
98
|
K.FunctionDeclaration,
|
|
@@ -146,8 +173,15 @@ function computePaths(sourceFile) {
|
|
|
146
173
|
return qualified;
|
|
147
174
|
};
|
|
148
175
|
const visit = (node, parent) => {
|
|
149
|
-
const name = NAMED_KINDS.has(node.kind) ? declarationName(node) : undefined;
|
|
176
|
+
const name = NAMED_KINDS.has(node.kind) ? declarationName(node, sourceFile) : undefined;
|
|
150
177
|
let inner = parent;
|
|
178
|
+
// Named by its ordinal, not its offset: a comment above it keeps the id (and the file's shape,
|
|
179
|
+
// fingerprints.ts). What it assigns keeps the parent, as before.
|
|
180
|
+
const expando = ts.isExpressionStatement(node) ? expandoOf(node, sourceFile) : undefined;
|
|
181
|
+
if (expando !== undefined) {
|
|
182
|
+
const segment = `$expando:${expando.name}`;
|
|
183
|
+
record(expando.target, parent === "" ? segment : `${parent}.${segment}`);
|
|
184
|
+
}
|
|
151
185
|
if (name !== undefined) {
|
|
152
186
|
inner = record(node, parent === "" ? name : `${parent}.${name}`);
|
|
153
187
|
}
|
|
@@ -169,14 +203,36 @@ function computePaths(sourceFile) {
|
|
|
169
203
|
});
|
|
170
204
|
return paths;
|
|
171
205
|
}
|
|
172
|
-
|
|
173
|
-
export function declarationPath(declaration) {
|
|
174
|
-
const sourceFile = declaration.getSourceFile();
|
|
206
|
+
function pathsOf(sourceFile) {
|
|
175
207
|
let paths = pathsByFile.get(sourceFile);
|
|
176
208
|
if (paths === undefined) {
|
|
177
209
|
paths = computePaths(sourceFile);
|
|
178
210
|
pathsByFile.set(sourceFile, paths);
|
|
179
211
|
}
|
|
212
|
+
return paths;
|
|
213
|
+
}
|
|
214
|
+
/** Declarations by path, per parsed file: the inverse of `pathsByFile`. */
|
|
215
|
+
const nodesByFile = new WeakMap();
|
|
216
|
+
/**
|
|
217
|
+
* The declaration at `path` in `sourceFile` (see above; "" is the file itself), or undefined when
|
|
218
|
+
* the file has none there: it was renamed, moved or removed. Only the paths the walk names: one
|
|
219
|
+
* placed by its offset (`$Kind@12`) is not looked up. Needs no parent pointers.
|
|
220
|
+
*/
|
|
221
|
+
export function declarationAtPath(sourceFile, path) {
|
|
222
|
+
let nodes = nodesByFile.get(sourceFile);
|
|
223
|
+
if (nodes === undefined) {
|
|
224
|
+
const inverse = new Map();
|
|
225
|
+
for (const [node, at] of pathsOf(sourceFile))
|
|
226
|
+
inverse.set(at, node);
|
|
227
|
+
nodes = inverse;
|
|
228
|
+
nodesByFile.set(sourceFile, nodes);
|
|
229
|
+
}
|
|
230
|
+
return nodes.get(path);
|
|
231
|
+
}
|
|
232
|
+
/** The path of `declaration` in its file (see above); "" for the file itself. */
|
|
233
|
+
export function declarationPath(declaration) {
|
|
234
|
+
const sourceFile = declaration.getSourceFile();
|
|
235
|
+
const paths = pathsOf(sourceFile);
|
|
180
236
|
const found = paths.get(declaration);
|
|
181
237
|
if (found !== undefined)
|
|
182
238
|
return found;
|
|
@@ -48,19 +48,26 @@ export type ProjectUnit = {
|
|
|
48
48
|
*/
|
|
49
49
|
fingerprint(file: string): string | undefined;
|
|
50
50
|
/**
|
|
51
|
-
* The queries for the rules of one run on one of `files`: `types`, except that each
|
|
52
|
-
*
|
|
53
|
-
* call, so a plugin's memo kept by queries (a `WeakMap` on them) lasts one file's
|
|
54
|
-
* remembers was read, and noted, for that file.
|
|
51
|
+
* The queries for the rules of one run on one of `files`: `types`, except that each node of
|
|
52
|
+
* another file that `declarationOf` hands out is noted as read for `file` (`readsOf`). A new
|
|
53
|
+
* object per call, so a plugin's memo kept by queries (a `WeakMap` on them) lasts one file's
|
|
54
|
+
* rules: what it remembers was read, and noted, for that file.
|
|
55
55
|
*/
|
|
56
56
|
typesFor(file: string): TypeQueries;
|
|
57
|
-
/** The files other than `file` whose syntax a rule on `file` was handed in this program, sorted. */
|
|
58
|
-
readsOf(file: string): readonly string[];
|
|
59
57
|
/**
|
|
60
|
-
*
|
|
61
|
-
*
|
|
58
|
+
* What a rule on `file` was handed of other files in this program, as read ids, sorted: the
|
|
59
|
+
* qualified id of each declaration of an own file (`src/a.ts#load`), or the file's own id
|
|
60
|
+
* (`src/a.ts#`, its whole text) for any other file, a module, a declaration whose id is placed by
|
|
61
|
+
* offset, and a file `mentioned` says the results name (they keep its offsets: a comment added
|
|
62
|
+
* above would move them).
|
|
62
63
|
*/
|
|
63
|
-
|
|
64
|
+
readsOf(file: string, mentioned: (readFile: string) => boolean): readonly string[];
|
|
65
|
+
/**
|
|
66
|
+
* The hash of what a read id stands for in this program (`declarationTextHash`, or the whole
|
|
67
|
+
* text for a file's own id); undefined when the program has no such declaration (renamed, moved,
|
|
68
|
+
* removed). A result that read it holds while it is the same.
|
|
69
|
+
*/
|
|
70
|
+
readFingerprint(read: string): string | undefined;
|
|
64
71
|
/** The first syntax error of one of `files`, or undefined when it parses cleanly. */
|
|
65
72
|
syntaxError(file: string): SyntaxError | undefined;
|
|
66
73
|
/**
|
|
@@ -69,6 +76,16 @@ export type ProjectUnit = {
|
|
|
69
76
|
* no types and is not listed.
|
|
70
77
|
*/
|
|
71
78
|
unresolvedImports(file: string): readonly UnresolvedImport[];
|
|
79
|
+
/**
|
|
80
|
+
* Whether the project checks with `strictNullChecks` (its own setting, else `strict`, else
|
|
81
|
+
* TypeScript 6's default, on). Read from the tsconfig: no program is built for it.
|
|
82
|
+
*/
|
|
83
|
+
readonly strictNullChecks: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Whether `module` resolves to declarations (types) from the project's folder, by its options:
|
|
86
|
+
* `react` does when `@types/react` or a typed `react` is installed. No program is built for it.
|
|
87
|
+
*/
|
|
88
|
+
typesResolve(module: string): boolean;
|
|
72
89
|
/**
|
|
73
90
|
* Binds the program (creating its type checker), which gives every node its parent: call it
|
|
74
91
|
* before a rule or a plugin sees a node of `files`. Parsing does not set parents.
|
|
@@ -116,6 +133,8 @@ export type UnresolvedImport = {
|
|
|
116
133
|
readonly start: number;
|
|
117
134
|
readonly end: number;
|
|
118
135
|
};
|
|
136
|
+
/** Whether a project with these options checks with `strictNullChecks` (TypeScript 6: on unless turned off). */
|
|
137
|
+
export declare function checksNulls(options: ts.CompilerOptions): boolean;
|
|
119
138
|
export type Backend = {
|
|
120
139
|
/** One unit per project that has own files, in references order (depth first). */
|
|
121
140
|
open(overlays: ReadonlyMap<string, string>): readonly ProjectUnit[];
|