@cplieger/deadset-ts 8.0.0-dev.15 → 8.0.0-dev.17
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 +0 -5
- package/dist/src/amd.js +81 -0
- package/dist/src/analysis.js +94 -54
- package/dist/src/augmentations.js +23 -24
- package/dist/src/bindings.js +382 -0
- package/dist/src/calls.js +25 -8
- package/dist/src/commands/read.js +6 -7
- package/dist/src/commands/tools.js +5 -9
- package/dist/src/component-files.js +3 -2
- package/dist/src/conformance-record.js +1 -1
- package/dist/src/consumers.js +9 -10
- package/dist/src/contextual-uses.js +1 -17
- package/dist/src/contract/config.generated.js +5 -2
- package/dist/src/contract/contract.generated.js +119 -2
- package/dist/src/contract/report.generated.js +6 -2
- package/dist/src/dependencies.js +98 -71
- package/dist/src/destructuring.js +1 -19
- package/dist/src/element-access.js +179 -164
- package/dist/src/entries/build-scripts.js +222 -0
- package/dist/src/{configuration-files.js → entries/configuration-files.js} +22 -64
- package/dist/src/{convention-rows.js → entries/convention-rows.js} +120 -27
- package/dist/src/entries/conventions.js +739 -0
- package/dist/src/{html-entries.js → entries/html-entries.js} +9 -12
- package/dist/src/{mdx-entries.js → entries/mdx-entries.js} +3 -3
- package/dist/src/entries/run-directories.js +77 -0
- package/dist/src/entries/sources.js +144 -0
- package/dist/src/entries/static-module.js +670 -0
- package/dist/src/entries/test-runners.js +684 -0
- package/dist/src/{workflow-steps.js → entries/workflow-steps.js} +18 -8
- package/dist/src/extensions.js +37 -0
- package/dist/src/facts.js +38 -0
- package/dist/src/findings/completion.js +40 -4
- package/dist/src/findings/emitters.js +5 -8
- package/dist/src/{implementations.js → findings/implementations.js} +3 -3
- package/dist/src/{in-operands.js → findings/in-operands.js} +2 -2
- package/dist/src/findings/self-check.js +36 -20
- package/dist/src/findings-pass.js +5 -6
- package/dist/src/framework-lifecycle.js +42 -15
- package/dist/src/fs/manifest.js +15 -20
- package/dist/src/generated-file.js +172 -29
- package/dist/src/graph.js +14 -8
- package/dist/src/import-bindings.js +73 -28
- package/dist/src/index/sites.js +557 -0
- package/dist/src/index.js +1 -1
- package/dist/src/indexed-access.js +523 -478
- package/dist/src/injection-container.js +1 -1
- package/dist/src/interface-satisfaction.js +1 -1
- package/dist/src/inventory/commonjs.js +62 -17
- package/dist/src/inventory/enumerate.js +2 -1
- package/dist/src/javascript-file.js +26 -11
- package/dist/src/keyof-comparisons.js +124 -103
- package/dist/src/load/classify.js +28 -9
- package/dist/src/load/diagnostics.js +8 -1
- package/dist/src/load/discover.js +15 -7
- package/dist/src/load/expected-module.js +2 -2
- package/dist/src/load/plan.js +2 -2
- package/dist/src/load/specifiers.js +2 -4
- package/dist/src/load/synthesize.js +10 -5
- package/dist/src/load/workspace-manifests.js +1 -1
- package/dist/src/load/workspace-resolution.js +2 -2
- package/dist/src/matrix.js +12 -17
- package/dist/src/module-declarations.js +70 -85
- package/dist/src/overrides.js +134 -112
- package/dist/src/paths.js +56 -1
- package/dist/src/platform-calls.js +78 -0
- package/dist/src/platform-symbols.js +134 -0
- package/dist/src/references/read-rule.js +1 -0
- package/dist/src/references/read-rules.js +48 -0
- package/dist/src/references/sink.js +151 -0
- package/dist/src/references/sources.js +450 -0
- package/dist/src/references.js +111 -1116
- package/dist/src/resolve.js +1 -1
- package/dist/src/{configured-declarations.js → roots/configured-declarations.js} +7 -4
- package/dist/src/{entry-point-gaps.js → roots/entry-point-gaps.js} +5 -8
- package/dist/src/{manifest.js → roots/manifest.js} +4 -4
- package/dist/src/roots/published-reach.js +412 -0
- package/dist/src/roots/root-set.js +489 -0
- package/dist/src/roots/unseen-loads.js +236 -0
- package/dist/src/serialization-contract.js +9 -4
- package/dist/src/source-files.js +5 -9
- package/dist/src/stores.js +4 -2
- package/dist/src/suppress.js +30 -32
- package/dist/src/sweep.js +25 -13
- package/dist/src/symbol-keys.js +89 -83
- package/dist/src/tests/file-class.js +76 -0
- package/dist/src/{outside-tests.js → tests/outside.js} +7 -7
- package/dist/src/{test-support.js → tests/support.js} +5 -12
- package/dist/src/type-parameter-reads.js +178 -139
- package/dist/src/unimplemented-callees.js +262 -242
- package/dist/src/verbs/analyze.js +15 -3
- package/dist/src/verbs/describe.js +5 -3
- package/dist/src/verbs/explain.js +50 -28
- package/dist/src/verbs/print-retained.js +2 -2
- package/jsr.json +1 -1
- package/package.json +3 -3
- package/src/alias-chain.ts +0 -7
- package/src/amd.ts +130 -0
- package/src/analysis.ts +156 -70
- package/src/augmentations.ts +41 -27
- package/src/automatic-types.ts +1 -1
- package/src/bindings.ts +460 -0
- package/src/calls.ts +25 -7
- package/src/commands/read.ts +6 -8
- package/src/commands/tools.ts +5 -11
- package/src/component-files.ts +4 -2
- package/src/conformance-record.ts +1 -1
- package/src/consumers.ts +12 -11
- package/src/contextual-uses.ts +2 -22
- package/src/contract/config.generated.ts +5 -2
- package/src/contract/contract.generated.ts +138 -2
- package/src/contract/report.generated.ts +6 -2
- package/src/dependencies.ts +117 -71
- package/src/destructuring.ts +1 -31
- package/src/element-access.ts +188 -182
- package/src/entries/build-scripts.ts +292 -0
- package/src/{configuration-files.ts → entries/configuration-files.ts} +33 -82
- package/src/{convention-rows.ts → entries/convention-rows.ts} +167 -28
- package/src/{conventions.ts → entries/conventions.ts} +349 -523
- package/src/{html-entries.ts → entries/html-entries.ts} +19 -18
- package/src/{mdx-entries.ts → entries/mdx-entries.ts} +5 -5
- package/src/entries/run-directories.ts +108 -0
- package/src/entries/sources.ts +266 -0
- package/src/entries/static-module.ts +858 -0
- package/src/entries/test-runners.ts +868 -0
- package/src/{workflow-steps.ts → entries/workflow-steps.ts} +29 -11
- package/src/exempt.ts +3 -2
- package/src/extensions.ts +45 -0
- package/src/facts.ts +46 -0
- package/src/file-facts.ts +1 -1
- package/src/findings/boundary.ts +2 -0
- package/src/findings/completion.ts +43 -4
- package/src/findings/emitter.ts +1 -1
- package/src/findings/emitters.ts +14 -10
- package/src/{implementations.ts → findings/implementations.ts} +4 -4
- package/src/{in-operands.ts → findings/in-operands.ts} +3 -3
- package/src/findings/self-check.ts +41 -22
- package/src/findings/visibility-narrowing.ts +1 -1
- package/src/findings-pass.ts +5 -12
- package/src/framework-lifecycle.ts +43 -15
- package/src/fs/manifest.ts +25 -21
- package/src/generated-file.ts +240 -36
- package/src/graph.ts +27 -11
- package/src/import-bindings.ts +98 -29
- package/src/index/sites.ts +781 -0
- package/src/index.ts +1 -1
- package/src/indexed-access.ts +570 -527
- package/src/injection-container.ts +1 -1
- package/src/interface-satisfaction.ts +1 -1
- package/src/inventory/commonjs.ts +102 -17
- package/src/inventory/enumerate.ts +2 -1
- package/src/javascript-file.ts +29 -12
- package/src/keyof-comparisons.ts +131 -116
- package/src/load/classify.ts +49 -13
- package/src/load/diagnostics.ts +11 -1
- package/src/load/discover.ts +27 -11
- package/src/load/expected-module.ts +8 -2
- package/src/load/plan.ts +11 -2
- package/src/load/specifiers.ts +8 -5
- package/src/load/synthesize.ts +12 -6
- package/src/load/test-globals.ts +1 -1
- package/src/load/workspace-manifests.ts +1 -1
- package/src/load/workspace-resolution.ts +9 -2
- package/src/load/workspace-run.ts +1 -1
- package/src/matrix.ts +13 -17
- package/src/module-declarations.ts +74 -98
- package/src/overrides.ts +162 -134
- package/src/paths.ts +65 -1
- package/src/platform-calls.ts +119 -0
- package/src/platform-symbols.ts +189 -0
- package/src/references/read-rule.ts +60 -0
- package/src/references/read-rules.ts +55 -0
- package/src/references/sink.ts +213 -0
- package/src/references/sources.ts +632 -0
- package/src/references.ts +174 -1492
- package/src/report.ts +2 -2
- package/src/resolve.ts +1 -1
- package/src/{configured-declarations.ts → roots/configured-declarations.ts} +10 -7
- package/src/{entry-point-gaps.ts → roots/entry-point-gaps.ts} +5 -8
- package/src/{manifest.ts → roots/manifest.ts} +5 -5
- package/src/roots/published-reach.ts +481 -0
- package/src/{roots.ts → roots/root-set.ts} +203 -630
- package/src/roots/unseen-loads.ts +345 -0
- package/src/serialization-contract.ts +9 -4
- package/src/source-files.ts +5 -10
- package/src/stores.ts +13 -2
- package/src/suppress.ts +48 -33
- package/src/sweep.ts +37 -14
- package/src/symbol-keys.ts +102 -102
- package/src/tests/file-class.ts +118 -0
- package/src/{outside-tests.ts → tests/outside.ts} +16 -10
- package/src/{test-support.ts → tests/support.ts} +15 -21
- package/src/type-parameter-reads.ts +187 -158
- package/src/unimplemented-callees.ts +297 -280
- package/src/verbs/analyze.ts +19 -5
- package/src/verbs/describe.ts +5 -2
- package/src/verbs/explain.ts +75 -32
- package/src/verbs/print-retained.ts +2 -2
- package/dist/src/build-scripts.js +0 -418
- package/dist/src/conventions.js +0 -907
- package/dist/src/entry-points.js +0 -444
- package/dist/src/own-body.js +0 -28
- package/dist/src/roots.js +0 -865
- package/dist/src/unseen-loads.js +0 -189
- package/src/build-scripts.ts +0 -536
- package/src/entry-points.ts +0 -584
- package/src/own-body.ts +0 -42
- package/src/unseen-loads.ts +0 -282
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which calls are the platform's `require` or AMD's `define` and which constructions its `URL`
|
|
3
|
+
* (roots.23, references-ts.37, references-ts.1), decided once over the bindings of the names a callee is written with: the
|
|
4
|
+
* checker's in a program, the file's own scopes in a module read outside every program.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
isBindingElement,
|
|
9
|
+
isCallExpression,
|
|
10
|
+
isExportSpecifier,
|
|
11
|
+
isIdentifier,
|
|
12
|
+
isImportSpecifier,
|
|
13
|
+
isPropertyAccessExpression,
|
|
14
|
+
isStringLiteral,
|
|
15
|
+
isVariableDeclaration,
|
|
16
|
+
type Identifier,
|
|
17
|
+
type Node,
|
|
18
|
+
} from "@typescript/native/ast";
|
|
19
|
+
import { parenthesesRemoved, unwrapped } from "./unwrap.ts";
|
|
20
|
+
|
|
21
|
+
/** A name of the platform the analysis reads calls of. */
|
|
22
|
+
type PlatformName = "require" | "createRequire" | "define" | "URL";
|
|
23
|
+
|
|
24
|
+
/** What one written name is bound to, as far as its reader can tell. */
|
|
25
|
+
export interface Bound {
|
|
26
|
+
/** Its own name, and each one an import, a re-export or a destructuring carries it by. */
|
|
27
|
+
readonly names: ReadonlySet<string>;
|
|
28
|
+
/** The declarations of the target it resolves to, a variable's initializer read through. */
|
|
29
|
+
readonly own: readonly Node[];
|
|
30
|
+
/** Whether the type checker proves it the target's own, a function or a class it writes with a body. */
|
|
31
|
+
readonly provenOwn: boolean;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** The binding of each written name, `undefined` where nothing answers which declaration it names. */
|
|
35
|
+
export type BindingOf = (written: Identifier) => Bound | undefined;
|
|
36
|
+
|
|
37
|
+
/** The name one declaration carries a binding by beside its own: the export an import or a re-export names, or the property a destructuring reads. */
|
|
38
|
+
export function carriedNames(node: Node): readonly string[] {
|
|
39
|
+
if (isImportSpecifier(node) || isExportSpecifier(node)) {
|
|
40
|
+
return [(node.propertyName ?? node.name).text];
|
|
41
|
+
}
|
|
42
|
+
const property = isBindingElement(node) ? node.propertyName : undefined;
|
|
43
|
+
return property !== undefined && (isIdentifier(property) || isStringLiteral(property))
|
|
44
|
+
? [property.text]
|
|
45
|
+
: [];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* A written name's binding as a file states it, with no checker to ask, so nothing is
|
|
50
|
+
* proven the target's own (conventions.3): `declarationOf` names the declaration a name
|
|
51
|
+
* resolves to, and a property is read by how it is written alone.
|
|
52
|
+
*/
|
|
53
|
+
export function lexicalBinding(
|
|
54
|
+
declarationOf: (written: Identifier) => Node | undefined,
|
|
55
|
+
): BindingOf {
|
|
56
|
+
return (written) => {
|
|
57
|
+
const parent = written.parent;
|
|
58
|
+
if (isPropertyAccessExpression(parent) && parent.name === written) {
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
const declaration = declarationOf(written);
|
|
62
|
+
return {
|
|
63
|
+
names: new Set([
|
|
64
|
+
written.text,
|
|
65
|
+
...(declaration === undefined ? [] : carriedNames(declaration)),
|
|
66
|
+
]),
|
|
67
|
+
own: declaration === undefined ? [] : [declaration],
|
|
68
|
+
provenOwn: false,
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** The name a callee or a constructor is written with, parentheses removed: an identifier or a property name. */
|
|
74
|
+
export function writtenName(expression: Node): Identifier | undefined {
|
|
75
|
+
const at = parenthesesRemoved(expression);
|
|
76
|
+
if (isIdentifier(at)) {
|
|
77
|
+
return at;
|
|
78
|
+
}
|
|
79
|
+
return isPropertyAccessExpression(at) && isIdentifier(at.name) ? at.name : undefined;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Whether a call or construction through `callee` is one of the platform's `name`: never
|
|
84
|
+
* where its binding is proven the target's own; otherwise where it is written or carried
|
|
85
|
+
* by that name, or resolves to a variable of the target whose initializer is such a
|
|
86
|
+
* callee or, for `require`, a call of a `createRequire`. A callee nothing binds is read by
|
|
87
|
+
* how it is written.
|
|
88
|
+
*/
|
|
89
|
+
export function callsPlatformBy(
|
|
90
|
+
name: PlatformName,
|
|
91
|
+
callee: Identifier,
|
|
92
|
+
bindingOf: BindingOf,
|
|
93
|
+
seen = new Set<Node>(),
|
|
94
|
+
): boolean {
|
|
95
|
+
const bound = bindingOf(callee);
|
|
96
|
+
if (bound?.provenOwn === true) {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
if (callee.text === name || bound?.names.has(name) === true) {
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
return (bound?.own ?? []).some((node) => {
|
|
103
|
+
if (seen.has(node) || !isVariableDeclaration(node) || node.initializer === undefined) {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
seen.add(node);
|
|
107
|
+
const value = unwrapped(node.initializer);
|
|
108
|
+
if (isCallExpression(value)) {
|
|
109
|
+
const called = writtenName(value.expression);
|
|
110
|
+
return (
|
|
111
|
+
name === "require" &&
|
|
112
|
+
called !== undefined &&
|
|
113
|
+
callsPlatformBy("createRequire", called, bindingOf, seen)
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
const written = writtenName(value);
|
|
117
|
+
return written !== undefined && callsPlatformBy(name, written, bindingOf, seen);
|
|
118
|
+
});
|
|
119
|
+
}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The platform's names read through a program's checker: its `require` and `URL`, as
|
|
3
|
+
* `platform-calls.ts` decides them, its worker constructors and `navigator`, and Node's
|
|
4
|
+
* `Worker`.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
isArrowFunction,
|
|
9
|
+
isClassDeclaration,
|
|
10
|
+
isClassExpression,
|
|
11
|
+
isFunctionDeclaration,
|
|
12
|
+
isFunctionExpression,
|
|
13
|
+
isMethodDeclaration,
|
|
14
|
+
isModuleDeclaration,
|
|
15
|
+
isPropertyAssignment,
|
|
16
|
+
isPropertyDeclaration,
|
|
17
|
+
isSourceFile,
|
|
18
|
+
isStringLiteralLikeNode,
|
|
19
|
+
isVariableDeclaration,
|
|
20
|
+
type Identifier,
|
|
21
|
+
type Node,
|
|
22
|
+
} from "@typescript/native/ast";
|
|
23
|
+
import { SymbolFlags, type Symbol as TSSymbol } from "@typescript/native/sync";
|
|
24
|
+
import { UNANSWERED, type Answer } from "./query.ts";
|
|
25
|
+
import type { ProjectView } from "./session.ts";
|
|
26
|
+
import { boundExports, NAMESPACE } from "./entries/static-module.ts";
|
|
27
|
+
import { isAmbient } from "./inventory.ts";
|
|
28
|
+
import { callsPlatformBy, carriedNames, type BindingOf, type Bound } from "./platform-calls.ts";
|
|
29
|
+
import { unwrapped } from "./unwrap.ts";
|
|
30
|
+
|
|
31
|
+
/** The symbol one symbol names through its aliases, or the symbol itself where it is none. */
|
|
32
|
+
function dealiased<Brand>(project: ProjectView<Brand>, symbol: TSSymbol): Answer<TSSymbol> {
|
|
33
|
+
if ((symbol.flags & SymbolFlags.Alias) === 0) {
|
|
34
|
+
return symbol;
|
|
35
|
+
}
|
|
36
|
+
return project.queries.aliased(symbol);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Each declaration of `symbol` in a file of the target, read in this project's program. */
|
|
40
|
+
function ownDeclarations<Brand>(project: ProjectView<Brand>, symbol: TSSymbol): readonly Node[] {
|
|
41
|
+
const own = project.ownPaths();
|
|
42
|
+
return symbol.declarations.flatMap((handle) => {
|
|
43
|
+
const node = own.has(handle.path) ? project.declarationAt(handle)?.node : undefined;
|
|
44
|
+
return node === undefined ? [] : [node];
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Whether one declaration writes a function or a class with a body (roots.23): a function
|
|
50
|
+
* or method declaration with a body, a class declaration, or a variable, a property or a
|
|
51
|
+
* class field whose initializer is a function, an arrow function or a class expression,
|
|
52
|
+
* under no `declare` modifier and in no declaration file.
|
|
53
|
+
*/
|
|
54
|
+
function writesBody(node: Node): boolean {
|
|
55
|
+
const value =
|
|
56
|
+
(isVariableDeclaration(node) || isPropertyAssignment(node) || isPropertyDeclaration(node)) &&
|
|
57
|
+
node.initializer !== undefined
|
|
58
|
+
? unwrapped(node.initializer)
|
|
59
|
+
: node;
|
|
60
|
+
return (
|
|
61
|
+
(isFunctionDeclaration(value) || isMethodDeclaration(value)
|
|
62
|
+
? value.body !== undefined
|
|
63
|
+
: isFunctionExpression(value) ||
|
|
64
|
+
isArrowFunction(value) ||
|
|
65
|
+
isClassDeclaration(value) ||
|
|
66
|
+
isClassExpression(value)) && !isAmbient(value.getSourceFile(), value)
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* What the checker binds `symbol` to, one alias step at a time: every name a step of the
|
|
72
|
+
* chain carries it by, and the declarations of the target its last step reaches, which
|
|
73
|
+
* prove it the target's own where one {@link writesBody}. A chain that ends at no
|
|
74
|
+
* declaration, or that the checker leaves unanswered, reaches none.
|
|
75
|
+
*/
|
|
76
|
+
function boundBy<Brand>(
|
|
77
|
+
project: ProjectView<Brand>,
|
|
78
|
+
symbol: Answer<TSSymbol> | undefined,
|
|
79
|
+
): Bound | undefined {
|
|
80
|
+
if (typeof symbol !== "object") {
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
const names = new Set<string>();
|
|
84
|
+
const stepped = new Set<number>();
|
|
85
|
+
for (let at: TSSymbol | undefined = symbol; at !== undefined && !stepped.has(at.id);) {
|
|
86
|
+
stepped.add(at.id);
|
|
87
|
+
names.add(at.name);
|
|
88
|
+
const own = ownDeclarations(project, at);
|
|
89
|
+
for (const node of own) {
|
|
90
|
+
carriedNames(node).forEach((one) => names.add(one));
|
|
91
|
+
}
|
|
92
|
+
if ((at.flags & SymbolFlags.Alias) === 0) {
|
|
93
|
+
return { names, own, provenOwn: own.some(writesBody) };
|
|
94
|
+
}
|
|
95
|
+
const next = project.aliasStepOf(at);
|
|
96
|
+
at = typeof next === "object" ? next : undefined;
|
|
97
|
+
}
|
|
98
|
+
return { names, own: [], provenOwn: false };
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Each written name's binding, as this project's checker answers it. */
|
|
102
|
+
function checkerBinding<Brand>(project: ProjectView<Brand>): BindingOf {
|
|
103
|
+
return (written) => boundBy(project, project.symbolsAt([project.handle(written)])[0]);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Whether a call or construction through `callee`, the batch's answer for which is `symbol`,
|
|
108
|
+
* is one of the platform's `require`, AMD's `define` or `URL` (roots.23, references-ts.37,
|
|
109
|
+
* references-ts.1), as {@link callsPlatformBy} decides it over this project's checker.
|
|
110
|
+
*/
|
|
111
|
+
export function callsPlatform<Brand>(
|
|
112
|
+
project: ProjectView<Brand>,
|
|
113
|
+
name: "require" | "define" | "URL",
|
|
114
|
+
callee: Identifier,
|
|
115
|
+
symbol: Answer<TSSymbol> | undefined,
|
|
116
|
+
): boolean {
|
|
117
|
+
const others = checkerBinding(project);
|
|
118
|
+
return callsPlatformBy(name, callee, (written) =>
|
|
119
|
+
written === callee ? boundBy(project, symbol) : others(written),
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Whether a worker's constructor or `navigator`, the batch's answer for which is `symbol`, is
|
|
125
|
+
* the platform's (references-ts.2): a name the checker leaves unanswered, or one whose symbol
|
|
126
|
+
* is no alias and has a declaration outside the target's files.
|
|
127
|
+
*/
|
|
128
|
+
export function isPlatformGlobal<Brand>(
|
|
129
|
+
project: ProjectView<Brand>,
|
|
130
|
+
symbol: Answer<TSSymbol> | undefined,
|
|
131
|
+
): boolean {
|
|
132
|
+
if (symbol === UNANSWERED) {
|
|
133
|
+
return true;
|
|
134
|
+
}
|
|
135
|
+
const own = project.ownPaths();
|
|
136
|
+
return (
|
|
137
|
+
symbol !== undefined &&
|
|
138
|
+
(symbol.flags & SymbolFlags.Alias) === 0 &&
|
|
139
|
+
symbol.declarations.some((handle) => !own.has(handle.path))
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** The module names Node's worker threads are imported by. */
|
|
144
|
+
const THREADS: ReadonlySet<string> = new Set(["worker_threads", "node:worker_threads"]);
|
|
145
|
+
|
|
146
|
+
function namesThreads(node: Node | undefined): boolean {
|
|
147
|
+
return node !== undefined && isStringLiteralLikeNode(node) && THREADS.has(node.text);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** Whether one declaration is written in the body of `declare module "worker_threads"`. */
|
|
151
|
+
function inThreadsModule(node: Node): boolean {
|
|
152
|
+
for (let at = node; !isSourceFile(at); at = at.parent) {
|
|
153
|
+
if (isModuleDeclaration(at) && namesThreads(at.name)) {
|
|
154
|
+
return true;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Whether a `Worker` constructor, the batch's answer for which is `symbol`, is Node's
|
|
162
|
+
* (references-ts.2): its symbol resolves to a declaration of `worker_threads`, or one of its
|
|
163
|
+
* own declarations binds the module's `Worker`, or `holder`, the namespace it is read
|
|
164
|
+
* through, binds the module, each binding read as {@link boundExports} reads one, which
|
|
165
|
+
* decides where the module has no declaration.
|
|
166
|
+
*/
|
|
167
|
+
export function startsThread<Brand>(
|
|
168
|
+
project: ProjectView<Brand>,
|
|
169
|
+
symbol: Answer<TSSymbol> | undefined,
|
|
170
|
+
holder: Answer<TSSymbol> | undefined,
|
|
171
|
+
): boolean {
|
|
172
|
+
const bindingOf = checkerBinding(project);
|
|
173
|
+
const declared = (one: Answer<TSSymbol> | undefined, member: string): boolean =>
|
|
174
|
+
typeof one === "object" &&
|
|
175
|
+
ownDeclarations(project, one).some((node) =>
|
|
176
|
+
boundExports(node, (specifier) => THREADS.has(specifier), bindingOf).includes(member),
|
|
177
|
+
);
|
|
178
|
+
if (declared(symbol, "Worker") || declared(holder, NAMESPACE)) {
|
|
179
|
+
return true;
|
|
180
|
+
}
|
|
181
|
+
const named = typeof symbol === "object" ? dealiased(project, symbol) : undefined;
|
|
182
|
+
return (
|
|
183
|
+
typeof named === "object" &&
|
|
184
|
+
named.declarations.some((handle) => {
|
|
185
|
+
const node = project.declarationAt(handle)?.node;
|
|
186
|
+
return node !== undefined && inThreadsModule(node);
|
|
187
|
+
})
|
|
188
|
+
);
|
|
189
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { Node, SourceFile } from "@typescript/native/ast";
|
|
2
|
+
import type { Type } from "@typescript/native/sync";
|
|
3
|
+
import type { AliasChains } from "../alias-chain.ts";
|
|
4
|
+
import type { Inventory } from "../inventory.ts";
|
|
5
|
+
import type { Position } from "../position.ts";
|
|
6
|
+
import type { Resolution } from "../references.ts";
|
|
7
|
+
import type { ProjectView } from "../session.ts";
|
|
8
|
+
|
|
9
|
+
/** Where the walk offered a read rule one node: the file, and the declaration enclosing the node. */
|
|
10
|
+
interface ReadSite {
|
|
11
|
+
readonly file: SourceFile;
|
|
12
|
+
readonly from: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** What a read rule reads its answers through, after the walk of every file of the side. */
|
|
16
|
+
export interface ReadContext<Brand> {
|
|
17
|
+
readonly project: ProjectView<Brand>;
|
|
18
|
+
readonly held: Inventory;
|
|
19
|
+
readonly chains: AliasChains;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* One read a rule makes: a use of the declaration `to` by `from` at a node of a walked file,
|
|
24
|
+
* or, where a question the read needed went unanswered, a hold. A hold names what the answer
|
|
25
|
+
* could have made live (program.33): the declarations `ids`, each declaration bearing one of
|
|
26
|
+
* `names`, each member of one of `types`, or with `members` every member the inventory holds;
|
|
27
|
+
* the declaration making the read is held as well. A named read sits at a node of `file`, or
|
|
28
|
+
* at a declaration's own position in it.
|
|
29
|
+
*/
|
|
30
|
+
export type Read =
|
|
31
|
+
| {
|
|
32
|
+
readonly kind: "named";
|
|
33
|
+
readonly from: string;
|
|
34
|
+
readonly to: string;
|
|
35
|
+
readonly file: SourceFile;
|
|
36
|
+
readonly at: Node | Position;
|
|
37
|
+
readonly use: "read" | "write";
|
|
38
|
+
readonly via: Resolution;
|
|
39
|
+
/** A read a rule counts as production code's whoever writes it. */
|
|
40
|
+
readonly production?: true;
|
|
41
|
+
}
|
|
42
|
+
| {
|
|
43
|
+
readonly kind: "held";
|
|
44
|
+
readonly from: string;
|
|
45
|
+
readonly ids?: readonly string[];
|
|
46
|
+
readonly names?: readonly string[];
|
|
47
|
+
readonly types?: readonly Type[];
|
|
48
|
+
readonly members?: true;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/** One pass of one read rule over the files of one side: it collects while the walk offers nodes, then reads. */
|
|
52
|
+
interface ReadRuleRun {
|
|
53
|
+
visit(node: Node, site: ReadSite): void;
|
|
54
|
+
reads<Brand>(context: ReadContext<Brand>): readonly Read[];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** One rule of the references pages that reads declarations no name node names. */
|
|
58
|
+
export interface ReadRule {
|
|
59
|
+
start(): ReadRuleRun;
|
|
60
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { elementAccess } from "../element-access.ts";
|
|
2
|
+
import { indexedAccess } from "../indexed-access.ts";
|
|
3
|
+
import { keyofComparisons } from "../keyof-comparisons.ts";
|
|
4
|
+
import { moduleDeclarations } from "../module-declarations.ts";
|
|
5
|
+
import { overrides } from "../overrides.ts";
|
|
6
|
+
import { isAnswered } from "../query.ts";
|
|
7
|
+
import { iteration } from "../symbol-keys.ts";
|
|
8
|
+
import { typeParameterReads } from "../type-parameter-reads.ts";
|
|
9
|
+
import { unimplementedCallees } from "../unimplemented-callees.ts";
|
|
10
|
+
import type { Read, ReadContext, ReadRule } from "./read-rule.ts";
|
|
11
|
+
|
|
12
|
+
/** The member kinds a hold of every member names. */
|
|
13
|
+
const MEMBER_KINDS: ReadonlySet<string> = new Set([
|
|
14
|
+
"method",
|
|
15
|
+
"class-member",
|
|
16
|
+
"interface-method",
|
|
17
|
+
"type-member",
|
|
18
|
+
"enum-member",
|
|
19
|
+
]);
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Every read rule, each run over every side's walked files with the reference sources:
|
|
23
|
+
* a consumer's read of a target member is a reference as the target's own is.
|
|
24
|
+
*/
|
|
25
|
+
export const READ_RULES: readonly ReadRule[] = [
|
|
26
|
+
overrides,
|
|
27
|
+
indexedAccess,
|
|
28
|
+
elementAccess,
|
|
29
|
+
keyofComparisons,
|
|
30
|
+
iteration,
|
|
31
|
+
typeParameterReads,
|
|
32
|
+
unimplementedCallees,
|
|
33
|
+
moduleDeclarations,
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
/** The declarations one hold names, with the declaration whose read it is. */
|
|
37
|
+
export function heldBy<Brand>(
|
|
38
|
+
read: Extract<Read, { kind: "held" }>,
|
|
39
|
+
{ project, held, chains }: ReadContext<Brand>,
|
|
40
|
+
): readonly string[] {
|
|
41
|
+
const ids = [...(read.from === "" ? [] : [read.from]), ...(read.ids ?? [])];
|
|
42
|
+
for (const name of read.names ?? []) {
|
|
43
|
+
ids.push(...(held.byName.get(name) ?? []));
|
|
44
|
+
}
|
|
45
|
+
for (const type of read.types ?? []) {
|
|
46
|
+
const properties = project.queries.propertiesOf(type);
|
|
47
|
+
for (const property of isAnswered(properties) ? properties : []) {
|
|
48
|
+
ids.push(...chains.declarationsOf(property));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (read.members === true) {
|
|
52
|
+
ids.push(...held.symbols.filter((one) => MEMBER_KINDS.has(one.kind)).map((one) => one.id));
|
|
53
|
+
}
|
|
54
|
+
return ids;
|
|
55
|
+
}
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isBinaryExpression,
|
|
3
|
+
isParenthesizedExpression,
|
|
4
|
+
isPropertyAccessExpression,
|
|
5
|
+
SyntaxKind,
|
|
6
|
+
type Node,
|
|
7
|
+
type SourceFile,
|
|
8
|
+
} from "@typescript/native/ast";
|
|
9
|
+
import { bindingsOf } from "../import-bindings.ts";
|
|
10
|
+
import type { Site } from "../index/sites.ts";
|
|
11
|
+
import { byPosition, renderPosition, type Position } from "../position.ts";
|
|
12
|
+
import type { ConsumerSide, Reference, Resolution, Use } from "../references.ts";
|
|
13
|
+
import { bytewise } from "../text/compare.ts";
|
|
14
|
+
|
|
15
|
+
/** One declaration a use names: `guessed` where only its name answered, `stepped` where an alias chain led to it. */
|
|
16
|
+
export interface Target {
|
|
17
|
+
readonly id: string;
|
|
18
|
+
readonly guessed?: boolean;
|
|
19
|
+
readonly stepped?: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** One write's index among the records, by its file, with the value it stores. */
|
|
23
|
+
interface Valued {
|
|
24
|
+
readonly index: number;
|
|
25
|
+
readonly value: Node;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Where every reference of one pass is made: it renders the position against the side's
|
|
30
|
+
* root, takes the writing file's test class from the file classes, marks a use only a
|
|
31
|
+
* declaration's name answered `guessed` and an alias step's `alias`, tags a consumer's
|
|
32
|
+
* reference with the consumer, and orders the records.
|
|
33
|
+
*/
|
|
34
|
+
export class Sink {
|
|
35
|
+
readonly #root: string;
|
|
36
|
+
readonly #testFile: (file: SourceFile) => boolean;
|
|
37
|
+
readonly #consumer: ConsumerSide | undefined;
|
|
38
|
+
readonly #found: Reference[] = [];
|
|
39
|
+
readonly #valued = new Map<SourceFile, Valued[]>();
|
|
40
|
+
readonly #held = new Set<string>();
|
|
41
|
+
|
|
42
|
+
constructor(
|
|
43
|
+
root: string,
|
|
44
|
+
testFile: (file: SourceFile) => boolean,
|
|
45
|
+
consumer: ConsumerSide | undefined,
|
|
46
|
+
) {
|
|
47
|
+
this.#root = root;
|
|
48
|
+
this.#testFile = testFile;
|
|
49
|
+
this.#consumer = consumer;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Whether a test file wrote one walked file's uses. */
|
|
53
|
+
isTest(file: SourceFile): boolean {
|
|
54
|
+
return this.#testFile(file);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** The position one node of a walked file renders at. */
|
|
58
|
+
position(file: SourceFile, at: Node): Position {
|
|
59
|
+
return renderPosition(file, this.#root, at.getStart());
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Records one use of each target, made by `from` at `at` in `file`. A write that stores
|
|
64
|
+
* `value` is remembered for the import bindings only its values use. A `production` use is
|
|
65
|
+
* production code's whoever writes it.
|
|
66
|
+
*/
|
|
67
|
+
add(
|
|
68
|
+
file: SourceFile,
|
|
69
|
+
at: Node | Position,
|
|
70
|
+
from: string,
|
|
71
|
+
targets: Iterable<Target | string>,
|
|
72
|
+
use: Use,
|
|
73
|
+
via: Resolution,
|
|
74
|
+
value?: Node,
|
|
75
|
+
production = false,
|
|
76
|
+
): void {
|
|
77
|
+
const position = "column" in at ? at : this.position(file, at);
|
|
78
|
+
const test = !production && this.#testFile(file);
|
|
79
|
+
for (const one of targets) {
|
|
80
|
+
const target = typeof one === "string" ? { id: one } : one;
|
|
81
|
+
this.#found.push({
|
|
82
|
+
from,
|
|
83
|
+
to: target.id,
|
|
84
|
+
position,
|
|
85
|
+
use,
|
|
86
|
+
resolution: target.guessed === true ? "by-name" : target.stepped === true ? "alias" : via,
|
|
87
|
+
test,
|
|
88
|
+
...(target.guessed === true ? { guessed: true as const } : {}),
|
|
89
|
+
});
|
|
90
|
+
if (use === "write" && value !== undefined) {
|
|
91
|
+
const valued = this.#valued.get(file) ?? [];
|
|
92
|
+
valued.push({ index: this.#found.length - 1, value });
|
|
93
|
+
this.#valued.set(file, valued);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Holds declarations an unanswered question could have made live, and the one whose read asked it. */
|
|
99
|
+
hold(ids: Iterable<string>): void {
|
|
100
|
+
for (const id of ids) {
|
|
101
|
+
this.#held.add(id);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** The records made so far, before {@link finish} orders them. */
|
|
106
|
+
get made(): readonly Reference[] {
|
|
107
|
+
return this.#found;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Appends records another stage derived from these, rendered already. */
|
|
111
|
+
extend(references: readonly Reference[]): void {
|
|
112
|
+
this.#found.push(...references);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* The records in position order, then the declaration named, the referencing declaration
|
|
117
|
+
* and the use, each write marked with the import bindings only its values use, and the
|
|
118
|
+
* held declarations. `usesOf` gives each walked file's name sites.
|
|
119
|
+
*/
|
|
120
|
+
finish(usesOf: ReadonlyMap<SourceFile, readonly Site[]>): {
|
|
121
|
+
readonly references: readonly Reference[];
|
|
122
|
+
readonly held: readonly string[];
|
|
123
|
+
} {
|
|
124
|
+
const found = this.#found;
|
|
125
|
+
for (const [file, writes] of this.#valued) {
|
|
126
|
+
for (const { index, names } of aloneIn(file, usesOf.get(file) ?? [], writes, found)) {
|
|
127
|
+
const reference = found[index];
|
|
128
|
+
if (reference !== undefined) {
|
|
129
|
+
found[index] = { ...reference, alone: names };
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
found.sort(
|
|
134
|
+
(a, b) =>
|
|
135
|
+
byPosition(a.position, b.position) ||
|
|
136
|
+
bytewise(a.to, b.to) ||
|
|
137
|
+
bytewise(a.from, b.from) ||
|
|
138
|
+
bytewise(a.use, b.use),
|
|
139
|
+
);
|
|
140
|
+
const consumer = this.#consumer;
|
|
141
|
+
return {
|
|
142
|
+
references:
|
|
143
|
+
consumer === undefined
|
|
144
|
+
? found
|
|
145
|
+
: found.map((reference) => ({ ...reference, consumer: consumer.id })),
|
|
146
|
+
held: [...this.#held].sort(bytewise),
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** The value one assignment stores through the name it writes, where it is a plain assignment. */
|
|
152
|
+
export function storedValue(name: Node): Node | undefined {
|
|
153
|
+
let target: Node = name;
|
|
154
|
+
if (isPropertyAccessExpression(name.parent) && name.parent.name === name) {
|
|
155
|
+
target = name.parent;
|
|
156
|
+
}
|
|
157
|
+
while (isParenthesizedExpression(target.parent)) {
|
|
158
|
+
target = target.parent;
|
|
159
|
+
}
|
|
160
|
+
const parent = target.parent;
|
|
161
|
+
return isBinaryExpression(parent) &&
|
|
162
|
+
parent.operatorToken.kind === SyntaxKind.EqualsToken &&
|
|
163
|
+
parent.left === target
|
|
164
|
+
? parent.right
|
|
165
|
+
: undefined;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* The import bindings of one file that only the values written into one declaration
|
|
170
|
+
* use, for each write into it. A binding is named by an identifier that spells its
|
|
171
|
+
* local name and is not the member a property access names.
|
|
172
|
+
*/
|
|
173
|
+
function aloneIn(
|
|
174
|
+
file: SourceFile,
|
|
175
|
+
uses: readonly Site[],
|
|
176
|
+
writes: readonly Valued[],
|
|
177
|
+
found: readonly Reference[],
|
|
178
|
+
): readonly { index: number; names: readonly string[] }[] {
|
|
179
|
+
const bindings = new Set(bindingsOf(file).map((binding) => binding.name.text));
|
|
180
|
+
if (bindings.size === 0) {
|
|
181
|
+
return [];
|
|
182
|
+
}
|
|
183
|
+
const occurrences = new Map<string, Node[]>();
|
|
184
|
+
for (const site of uses) {
|
|
185
|
+
const text = site.node.getText();
|
|
186
|
+
const parent = site.node.parent;
|
|
187
|
+
if (!bindings.has(text) || (isPropertyAccessExpression(parent) && parent.name === site.node)) {
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
if (!occurrences.get(text)?.includes(site.node)) {
|
|
191
|
+
occurrences.set(text, [...(occurrences.get(text) ?? []), site.node]);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
const inside = (node: Node, value: Node): boolean =>
|
|
195
|
+
node.pos >= value.pos && node.end <= value.end;
|
|
196
|
+
const result: { index: number; names: readonly string[] }[] = [];
|
|
197
|
+
for (const write of writes) {
|
|
198
|
+
const to = found[write.index]?.to;
|
|
199
|
+
const sameTarget = writes.filter((one) => found[one.index]?.to === to);
|
|
200
|
+
const names = [...occurrences]
|
|
201
|
+
.filter(
|
|
202
|
+
([, nodes]) =>
|
|
203
|
+
nodes.some((node) => inside(node, write.value)) &&
|
|
204
|
+
nodes.every((node) => sameTarget.some((one) => inside(node, one.value))),
|
|
205
|
+
)
|
|
206
|
+
.map(([name]) => name)
|
|
207
|
+
.sort(bytewise);
|
|
208
|
+
if (names.length > 0) {
|
|
209
|
+
result.push({ index: write.index, names });
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return result;
|
|
213
|
+
}
|