fallow-type-aware 3.35.0 → 3.37.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/package.json +10 -1
- package/src/backend-preflight.mjs +33 -4
- package/src/backend-selection.mjs +18 -0
- package/src/backend.mjs +169 -0
- package/src/computed-member-access.mjs +45 -0
- package/src/generated-protocol.mjs +12 -0
- package/src/mutant-typecheck.mjs +13 -10
- package/src/namespace-uses.mjs +499 -0
- package/src/project-package.mjs +37 -0
- package/src/project-state.mjs +12 -10
- package/src/protocol.mjs +7 -16
- package/src/reference-names.mjs +18 -9
- package/src/semantic-identity.mjs +7 -5
- package/src/semantic-input.mjs +32 -0
- package/src/semantic.mjs +88 -153
- package/src/shorthand-references.mjs +243 -0
- package/src/symbol-impact.mjs +3 -6
- package/src/symbol-targets.mjs +7 -1
package/src/reference-names.mjs
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ast } from "./backend.mjs";
|
|
2
|
+
|
|
3
|
+
const {
|
|
2
4
|
isExportDeclaration,
|
|
3
5
|
isImportDeclaration,
|
|
4
6
|
isImportEqualsDeclaration,
|
|
@@ -7,7 +9,7 @@ import {
|
|
|
7
9
|
isNamedExports,
|
|
8
10
|
isNamespaceExportDeclaration,
|
|
9
11
|
isNamespaceImport,
|
|
10
|
-
}
|
|
12
|
+
} = ast;
|
|
11
13
|
|
|
12
14
|
const JAVASCRIPT_FILE = /\.[cm]?jsx?$/iu;
|
|
13
15
|
|
|
@@ -28,9 +30,10 @@ const exportNames = ({ exportClause }) => {
|
|
|
28
30
|
return [exportClause.name];
|
|
29
31
|
};
|
|
30
32
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
/** Returns the statements of a `namespace` or `declare module` body, also when nested. */
|
|
34
|
+
export const moduleBodyStatements = (body) => {
|
|
35
|
+
if (body && isModuleDeclaration(body)) return moduleBodyStatements(body.body);
|
|
36
|
+
return body && isModuleBlock(body) ? body.statements : [];
|
|
34
37
|
};
|
|
35
38
|
|
|
36
39
|
const statementAliasNames = (statement) => {
|
|
@@ -39,26 +42,32 @@ const statementAliasNames = (statement) => {
|
|
|
39
42
|
return [statement.name];
|
|
40
43
|
}
|
|
41
44
|
if (isExportDeclaration(statement)) return exportNames(statement);
|
|
42
|
-
if (isModuleDeclaration(statement))
|
|
45
|
+
if (isModuleDeclaration(statement)) {
|
|
46
|
+
return moduleBodyStatements(statement.body).flatMap(statementAliasNames);
|
|
47
|
+
}
|
|
43
48
|
return [];
|
|
44
49
|
};
|
|
45
50
|
|
|
46
51
|
// Default-library and external-library files sit below node_modules. The
|
|
47
52
|
// path check skips them before the source file and its metadata, which each
|
|
48
53
|
// cost a checker round trip.
|
|
49
|
-
const NODE_MODULES_SEGMENT = /[\\/]node_modules[\\/]/u;
|
|
54
|
+
export const NODE_MODULES_SEGMENT = /[\\/]node_modules[\\/]/u;
|
|
50
55
|
|
|
51
56
|
const isOwnSourceFile = (project, sourceFile) =>
|
|
52
57
|
Boolean(sourceFile) &&
|
|
53
58
|
!project.program.isSourceFileDefaultLibrary(sourceFile) &&
|
|
54
59
|
!project.program.isSourceFileFromExternalLibrary(sourceFile);
|
|
55
60
|
|
|
56
|
-
|
|
61
|
+
/** Returns the program files outside node_modules and the default libraries. */
|
|
62
|
+
export const ownSourceFiles = (project) =>
|
|
57
63
|
project.program
|
|
58
64
|
.getSourceFileNames()
|
|
59
65
|
.filter((fileName) => !NODE_MODULES_SEGMENT.test(fileName))
|
|
60
66
|
.map((fileName) => project.program.getSourceFile(fileName))
|
|
61
|
-
.filter((sourceFile) => isOwnSourceFile(project, sourceFile))
|
|
67
|
+
.filter((sourceFile) => isOwnSourceFile(project, sourceFile));
|
|
68
|
+
|
|
69
|
+
const programAliasNames = (project) =>
|
|
70
|
+
ownSourceFiles(project)
|
|
62
71
|
.flatMap((sourceFile) => sourceFile.statements.flatMap(statementAliasNames))
|
|
63
72
|
.map((name) => name?.text)
|
|
64
73
|
.filter((text) => typeof text === "string");
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
|
|
3
|
+
import { sync, ast } from "./backend.mjs";
|
|
4
|
+
|
|
5
|
+
import { canonicalFileIdentity } from "./file-identity.mjs";
|
|
6
|
+
|
|
7
|
+
const { SymbolFlags } = sync;
|
|
8
|
+
const {
|
|
5
9
|
isClassDeclaration,
|
|
6
10
|
isClassExpression,
|
|
7
11
|
isEnumDeclaration,
|
|
@@ -19,9 +23,7 @@ import {
|
|
|
19
23
|
isSourceFile,
|
|
20
24
|
isTypeAliasDeclaration,
|
|
21
25
|
isVariableDeclaration,
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
import { canonicalFileIdentity } from "./file-identity.mjs";
|
|
26
|
+
} = ast;
|
|
25
27
|
|
|
26
28
|
const DECLARATION_KIND_RULES = [
|
|
27
29
|
[[isClassDeclaration, isClassExpression], "class"],
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
/** Source extensions accepted by the semantic backend, including declaration-file suffixes. */
|
|
5
|
+
export const MODULE_SOURCE_EXTENSIONS = [
|
|
6
|
+
".ts",
|
|
7
|
+
".tsx",
|
|
8
|
+
".mts",
|
|
9
|
+
".cts",
|
|
10
|
+
".js",
|
|
11
|
+
".jsx",
|
|
12
|
+
".mjs",
|
|
13
|
+
".cjs",
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
/** Whether the backend can parse the query's source without a component transform. */
|
|
17
|
+
export const isSupportedSemanticQuery = (query) =>
|
|
18
|
+
!query.symbol ||
|
|
19
|
+
MODULE_SOURCE_EXTENSIONS.includes(path.extname(query.symbol.absolutePath).toLowerCase());
|
|
20
|
+
|
|
21
|
+
/** Component files must stay out of openFiles because the backend cannot infer their script kind. */
|
|
22
|
+
export const semanticOpenFiles = (queries) =>
|
|
23
|
+
queries
|
|
24
|
+
.filter((query) => query.symbol && isSupportedSemanticQuery(query))
|
|
25
|
+
.map((query) => query.symbol.absolutePath);
|
|
26
|
+
|
|
27
|
+
/** Resolve explicit projects or the conventional root project. */
|
|
28
|
+
export const semanticOpenProjects = (root, projects) => {
|
|
29
|
+
if (projects.length > 0) return projects.map((project) => project.absolutePath);
|
|
30
|
+
const conventionalProject = path.join(root, "tsconfig.json");
|
|
31
|
+
return existsSync(conventionalProject) ? [conventionalProject] : [];
|
|
32
|
+
};
|
package/src/semantic.mjs
CHANGED
|
@@ -1,33 +1,11 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
-
import { existsSync
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
isCallExpression,
|
|
8
|
-
isClassDeclaration,
|
|
9
|
-
isClassExpression,
|
|
10
|
-
isDecorator,
|
|
11
|
-
isElementAccessExpression,
|
|
12
|
-
isExportDeclaration,
|
|
13
|
-
isExportSpecifier,
|
|
14
|
-
isFunctionBody,
|
|
15
|
-
isGetAccessorDeclaration,
|
|
16
|
-
isIdentifier,
|
|
17
|
-
isImportDeclaration,
|
|
18
|
-
isImportSpecifier,
|
|
19
|
-
isImportTypeNode,
|
|
20
|
-
isNamespaceImport,
|
|
21
|
-
isPropertyAccessExpression,
|
|
22
|
-
isQualifiedName,
|
|
23
|
-
isPrivateIdentifier,
|
|
24
|
-
isSetAccessorDeclaration,
|
|
25
|
-
isStringLiteralLikeNode,
|
|
26
|
-
isTypeNode,
|
|
27
|
-
isTypeQueryNode,
|
|
28
|
-
} from "typescript/unstable/ast/is";
|
|
5
|
+
import { ast, createApi as createBackendApi, heritageTypeName, sync } from "./backend.mjs";
|
|
29
6
|
|
|
30
7
|
import { canonicalFileIdentity } from "./file-identity.mjs";
|
|
8
|
+
import { packagePathTargets, projectPackage } from "./project-package.mjs";
|
|
31
9
|
import { projectResult, projectState } from "./project-state.mjs";
|
|
32
10
|
import {
|
|
33
11
|
declarationName,
|
|
@@ -51,8 +29,54 @@ import {
|
|
|
51
29
|
} from "./semantic-identity.mjs";
|
|
52
30
|
import { analyzeSymbolImpact } from "./symbol-impact.mjs";
|
|
53
31
|
import { isJavaScriptFile, referenceNames } from "./reference-names.mjs";
|
|
54
|
-
import {
|
|
32
|
+
import { recordComputedMemberAccess } from "./computed-member-access.mjs";
|
|
33
|
+
import {
|
|
34
|
+
namespaceSourceIdentity,
|
|
35
|
+
recordDynamicImportUncertainty,
|
|
36
|
+
recordNamespaceUse,
|
|
37
|
+
} from "./namespace-uses.mjs";
|
|
38
|
+
import {
|
|
39
|
+
isLiteralMemberName,
|
|
40
|
+
qualifierExpression,
|
|
41
|
+
referenceValueSymbol,
|
|
42
|
+
shorthandReferenceSymbols,
|
|
43
|
+
} from "./shorthand-references.mjs";
|
|
44
|
+
import {
|
|
45
|
+
matchingAliasEntries,
|
|
46
|
+
matchingSymbolEntries,
|
|
47
|
+
recordSymbolUncertainty,
|
|
48
|
+
targetName,
|
|
49
|
+
} from "./symbol-targets.mjs";
|
|
55
50
|
import { analyzeTypeCoupling } from "./type-coupling.mjs";
|
|
51
|
+
import {
|
|
52
|
+
MODULE_SOURCE_EXTENSIONS,
|
|
53
|
+
isSupportedSemanticQuery,
|
|
54
|
+
semanticOpenFiles,
|
|
55
|
+
semanticOpenProjects,
|
|
56
|
+
} from "./semantic-input.mjs";
|
|
57
|
+
|
|
58
|
+
const { SignatureKind, SymbolFlags } = sync;
|
|
59
|
+
const {
|
|
60
|
+
isCallExpression,
|
|
61
|
+
isClassDeclaration,
|
|
62
|
+
isClassExpression,
|
|
63
|
+
isDecorator,
|
|
64
|
+
isExportDeclaration,
|
|
65
|
+
isExportSpecifier,
|
|
66
|
+
isFunctionBody,
|
|
67
|
+
isGetAccessorDeclaration,
|
|
68
|
+
isIdentifier,
|
|
69
|
+
isImportDeclaration,
|
|
70
|
+
isImportSpecifier,
|
|
71
|
+
isImportTypeNode,
|
|
72
|
+
isNamespaceImport,
|
|
73
|
+
isPropertyAccessExpression,
|
|
74
|
+
isPrivateIdentifier,
|
|
75
|
+
isSetAccessorDeclaration,
|
|
76
|
+
isStringLiteralLikeNode,
|
|
77
|
+
isTypeNode,
|
|
78
|
+
isTypeQueryNode,
|
|
79
|
+
} = ast;
|
|
56
80
|
|
|
57
81
|
const ATTACHED_COMMENT_PATTERN = /\/\/|\/\*/u;
|
|
58
82
|
const MAX_SYMBOL_USE_EVIDENCE = 1;
|
|
@@ -358,13 +382,10 @@ const candidateNameMatches = (candidateNames, name) => !candidateNames || candid
|
|
|
358
382
|
const isIdentifierReference = (node, names) =>
|
|
359
383
|
isIdentifier(node) && candidateNameMatches(names, node.text);
|
|
360
384
|
|
|
361
|
-
const isElementNameNode = (node) =>
|
|
362
|
-
isStringLiteralLikeNode(node) &&
|
|
363
|
-
isElementAccessExpression(node.parent) &&
|
|
364
|
-
node.parent.argumentExpression === node;
|
|
365
|
-
|
|
366
385
|
const isElementReference = (node, candidateNames) =>
|
|
367
|
-
|
|
386
|
+
isStringLiteralLikeNode(node) &&
|
|
387
|
+
candidateNameMatches(candidateNames, node.text) &&
|
|
388
|
+
isLiteralMemberName(node);
|
|
368
389
|
|
|
369
390
|
const entriesByName = (entries) => {
|
|
370
391
|
const byName = new Map();
|
|
@@ -478,11 +499,6 @@ const importTypeSpecifier = (node) => {
|
|
|
478
499
|
return literal && isStringLiteralLikeNode(literal) ? literal : undefined;
|
|
479
500
|
};
|
|
480
501
|
|
|
481
|
-
const isDynamicImportCall = (node) =>
|
|
482
|
-
isCallExpression(node) && node.expression.getText(node.getSourceFile()) === "import";
|
|
483
|
-
|
|
484
|
-
const MODULE_SOURCE_EXTENSIONS = [".ts", ".tsx", ".mts", ".cts", ".js", ".jsx", ".mjs", ".cjs"];
|
|
485
|
-
|
|
486
502
|
const lexicalModuleIdentityForText = (project, sourceFile, specifierText) => {
|
|
487
503
|
if (!specifierText?.startsWith(".")) return undefined;
|
|
488
504
|
const resolved = path.resolve(path.dirname(sourceFile.fileName), specifierText);
|
|
@@ -516,19 +532,8 @@ const moduleIdentityForSpecifier = (project, specifier) => {
|
|
|
516
532
|
};
|
|
517
533
|
|
|
518
534
|
const namespaceImportDeclaration = (project, node) => {
|
|
519
|
-
const
|
|
520
|
-
if (!
|
|
521
|
-
const namespace = isPropertyAccessExpression(parent)
|
|
522
|
-
? parent.name === node
|
|
523
|
-
? parent.expression
|
|
524
|
-
: undefined
|
|
525
|
-
: isElementAccessExpression(parent) && parent.argumentExpression === node
|
|
526
|
-
? parent.expression
|
|
527
|
-
: isQualifiedName(parent) && parent.right === node
|
|
528
|
-
? parent.left
|
|
529
|
-
: undefined;
|
|
530
|
-
if (!namespace) return undefined;
|
|
531
|
-
if (!isIdentifier(namespace)) return undefined;
|
|
535
|
+
const namespace = qualifierExpression(node);
|
|
536
|
+
if (!namespace || !isIdentifier(namespace)) return undefined;
|
|
532
537
|
const symbol = project.checker.getSymbolAtLocation(namespace);
|
|
533
538
|
return symbol?.declarations
|
|
534
539
|
?.map((declaration) => declaration.resolve(project))
|
|
@@ -536,7 +541,7 @@ const namespaceImportDeclaration = (project, node) => {
|
|
|
536
541
|
};
|
|
537
542
|
|
|
538
543
|
const localAliasModuleEdgeDeclaration = (project, node) => {
|
|
539
|
-
const symbol = project
|
|
544
|
+
const symbol = referenceValueSymbol(project, node);
|
|
540
545
|
return symbol?.declarations
|
|
541
546
|
?.map((declaration) => moduleEdgeDeclaration(declaration.resolve(project)))
|
|
542
547
|
.find(Boolean);
|
|
@@ -567,7 +572,8 @@ const referencedModuleIdentity = (project, node) => {
|
|
|
567
572
|
|
|
568
573
|
const isExactExportReference = (project, entry, node) => {
|
|
569
574
|
if (entry.query.symbol.declarationKind !== "export") return true;
|
|
570
|
-
const referencedModule =
|
|
575
|
+
const referencedModule =
|
|
576
|
+
referencedModuleIdentity(project, node) ?? namespaceSourceIdentity(project, node);
|
|
571
577
|
if (!referencedModule) return false;
|
|
572
578
|
const queryModule = canonicalFileIdentity(entry.query.symbol.absolutePath);
|
|
573
579
|
return (
|
|
@@ -612,58 +618,17 @@ const classMemberEntrySetForProject = (state, project) => {
|
|
|
612
618
|
return entries;
|
|
613
619
|
};
|
|
614
620
|
|
|
615
|
-
const
|
|
616
|
-
|
|
617
|
-
};
|
|
618
|
-
|
|
619
|
-
const isExactElementReference = (node) => isElementNameNode(node) && typeof node.text === "string";
|
|
621
|
+
const isExactElementReference = (node) =>
|
|
622
|
+
isLiteralMemberName(node) && typeof node.text === "string";
|
|
620
623
|
|
|
621
|
-
const
|
|
622
|
-
if (!isStringLiteralLikeNode(node) || isExactElementReference(node)) return;
|
|
624
|
+
const recordNameUncertainty = (state, projectEntries, node) =>
|
|
623
625
|
(state.classMemberEntriesByName.get(node.text) ?? [])
|
|
624
626
|
.filter((entry) => projectEntries.has(entry))
|
|
625
627
|
.forEach((entry) => recordSymbolUncertainty(state, entry, "dynamic-member-access"));
|
|
626
|
-
};
|
|
627
|
-
|
|
628
|
-
const recordComputedMemberAccess = (state, project, entries, node) => {
|
|
629
|
-
if (
|
|
630
|
-
entries.size === 0 ||
|
|
631
|
-
state.projectsWithUnknownDynamicAccess.has(project) ||
|
|
632
|
-
!isElementAccessExpression(node) ||
|
|
633
|
-
node.argumentExpression === undefined ||
|
|
634
|
-
isStringLiteralLikeNode(node.argumentExpression)
|
|
635
|
-
) {
|
|
636
|
-
return;
|
|
637
|
-
}
|
|
638
|
-
const receiverType = project.checker.getTypeAtLocation(node.expression);
|
|
639
|
-
const receiverProperties = project.checker.getPropertiesOfType(receiverType);
|
|
640
|
-
if (receiverProperties.length === 0) {
|
|
641
|
-
entries.forEach((entry) => recordSymbolUncertainty(state, entry, "dynamic-member-access"));
|
|
642
|
-
state.projectsWithUnknownDynamicAccess.add(project);
|
|
643
|
-
return;
|
|
644
|
-
}
|
|
645
|
-
const matched = new Set(
|
|
646
|
-
receiverProperties
|
|
647
|
-
.filter((property) => state.candidateNames.has(property.name))
|
|
648
|
-
.flatMap((property) => [...matchingSymbolEntries(project, property, "value", state)]),
|
|
649
|
-
);
|
|
650
|
-
matched.forEach((entry) => recordSymbolUncertainty(state, entry, "dynamic-member-access"));
|
|
651
|
-
};
|
|
652
628
|
|
|
653
|
-
const
|
|
654
|
-
if (!
|
|
655
|
-
|
|
656
|
-
if (!specifier || !isStringLiteralLikeNode(specifier)) {
|
|
657
|
-
(state.exportEntriesByProject.get(project) ?? []).forEach((entry) =>
|
|
658
|
-
recordSymbolUncertainty(state, entry, "dynamic-behavior"),
|
|
659
|
-
);
|
|
660
|
-
return;
|
|
661
|
-
}
|
|
662
|
-
const moduleIdentity = moduleIdentityForSpecifier(project, specifier);
|
|
663
|
-
if (!moduleIdentity) return;
|
|
664
|
-
(state.exportEntriesByModule.get(moduleIdentity) ?? []).forEach((entry) =>
|
|
665
|
-
recordSymbolUncertainty(state, entry, "dynamic-behavior"),
|
|
666
|
-
);
|
|
629
|
+
const recordStringDispatchedMemberAccess = (state, projectEntries, node) => {
|
|
630
|
+
if (!isStringLiteralLikeNode(node) || isExactElementReference(node)) return;
|
|
631
|
+
recordNameUncertainty(state, projectEntries, node);
|
|
667
632
|
};
|
|
668
633
|
|
|
669
634
|
const referenceNamespaces = (project, node, rawSymbol) => {
|
|
@@ -706,7 +671,7 @@ const scanSymbolUseFile = (root, state, project, sourceFile, names) => {
|
|
|
706
671
|
const projectEntries = classMemberEntrySetForProject(state, project);
|
|
707
672
|
const nodes = [];
|
|
708
673
|
visit(sourceFile, (node) => {
|
|
709
|
-
recordDynamicImportUncertainty(state, project, node);
|
|
674
|
+
recordDynamicImportUncertainty(state, project, node, moduleIdentityForSpecifier);
|
|
710
675
|
if (projectEntries.size > 0) {
|
|
711
676
|
recordStringDispatchedMemberAccess(state, projectEntries, node);
|
|
712
677
|
recordComputedMemberAccess(state, project, projectEntries, node);
|
|
@@ -718,11 +683,16 @@ const scanSymbolUseFile = (root, state, project, sourceFile, names) => {
|
|
|
718
683
|
if (isElementReference(node, state.candidateNames)) nodes.push(node);
|
|
719
684
|
});
|
|
720
685
|
const symbols = project.checker.getSymbolAtLocation(nodes);
|
|
686
|
+
const references = shorthandReferenceSymbols(project, nodes, symbols, state);
|
|
687
|
+
references.unresolved.forEach((node) => recordNameUncertainty(state, projectEntries, node));
|
|
721
688
|
nodes.forEach((node, index) => {
|
|
722
689
|
const rawSymbol = symbols[index];
|
|
690
|
+
recordNamespaceUse(state, project, node, rawSymbol);
|
|
723
691
|
referenceNamespaces(project, node, rawSymbol).forEach((namespace) => {
|
|
724
692
|
const entries = new Set([
|
|
725
|
-
...
|
|
693
|
+
...references.symbols[index].flatMap((symbol) => [
|
|
694
|
+
...matchingAliasEntries(project, symbol, namespace, state),
|
|
695
|
+
]),
|
|
726
696
|
...surfaceEntriesForNode(state, project, node, namespace),
|
|
727
697
|
]);
|
|
728
698
|
entries.forEach((entry) => recordSymbolUse(root, state, project, entry, node, namespace));
|
|
@@ -782,11 +752,11 @@ const selectSymbolContext = (
|
|
|
782
752
|
query,
|
|
783
753
|
allowDefaultFallback,
|
|
784
754
|
) => {
|
|
785
|
-
if (!DECLARATION_KINDS.has(query.symbol.declarationKind)) {
|
|
755
|
+
if (!isSupportedSemanticQuery(query) || !DECLARATION_KINDS.has(query.symbol.declarationKind)) {
|
|
786
756
|
return symbolResolutionError(
|
|
787
757
|
query,
|
|
788
758
|
"unsupported-syntax",
|
|
789
|
-
"Use a supported declaration
|
|
759
|
+
"Use a supported TypeScript or JavaScript declaration or retain the syntactic finding.",
|
|
790
760
|
);
|
|
791
761
|
}
|
|
792
762
|
let owners = owningProjectContexts(statesByProject, query.symbol.absolutePath);
|
|
@@ -972,7 +942,7 @@ const frameworkContractRelationsFor = (root, project, declaration, contracts, me
|
|
|
972
942
|
: "extends";
|
|
973
943
|
for (const heritageType of clause.types ?? []) {
|
|
974
944
|
const rawSymbol =
|
|
975
|
-
project.checker.getSymbolAtLocation(heritageType
|
|
945
|
+
project.checker.getSymbolAtLocation(heritageTypeName(heritageType)) ??
|
|
976
946
|
project.checker.getTypeAtLocation(heritageType).aliasSymbol ??
|
|
977
947
|
project.checker.getTypeAtLocation(heritageType).symbol;
|
|
978
948
|
const symbol = resolveAlias(project.checker, rawSymbol);
|
|
@@ -1253,31 +1223,6 @@ const wildcardPattern = (target) => {
|
|
|
1253
1223
|
return new RegExp(`^${escaped}$`, "u");
|
|
1254
1224
|
};
|
|
1255
1225
|
|
|
1256
|
-
const pathWithin = (root, candidate) =>
|
|
1257
|
-
candidate === root || candidate.startsWith(`${root}${path.sep}`);
|
|
1258
|
-
|
|
1259
|
-
const packageAt = (directory) => {
|
|
1260
|
-
const packageFile = path.join(directory, "package.json");
|
|
1261
|
-
if (!existsSync(packageFile)) return undefined;
|
|
1262
|
-
try {
|
|
1263
|
-
return { root: directory, json: JSON.parse(readFileSync(packageFile, "utf8")) };
|
|
1264
|
-
} catch {
|
|
1265
|
-
return { root: directory, json: {} };
|
|
1266
|
-
}
|
|
1267
|
-
};
|
|
1268
|
-
|
|
1269
|
-
const projectPackage = (root, project) => {
|
|
1270
|
-
const normalizedRoot = path.resolve(root);
|
|
1271
|
-
let current = path.dirname(project.configFileName);
|
|
1272
|
-
while (pathWithin(normalizedRoot, current)) {
|
|
1273
|
-
const found = packageAt(current);
|
|
1274
|
-
if (found) return found;
|
|
1275
|
-
if (current === normalizedRoot) break;
|
|
1276
|
-
current = path.dirname(current);
|
|
1277
|
-
}
|
|
1278
|
-
return { root: normalizedRoot, json: {} };
|
|
1279
|
-
};
|
|
1280
|
-
|
|
1281
1226
|
const ancestorRoots = (root, start) => {
|
|
1282
1227
|
const normalizedRoot = path.resolve(root);
|
|
1283
1228
|
const roots = [];
|
|
@@ -1345,12 +1290,6 @@ const addPathEntry = (entries, sourceFiles, roots, target) => {
|
|
|
1345
1290
|
);
|
|
1346
1291
|
};
|
|
1347
1292
|
|
|
1348
|
-
const packagePathTargets = (project, packageJson) => {
|
|
1349
|
-
const packageName = packageJson.name;
|
|
1350
|
-
if (typeof packageName !== "string") return [];
|
|
1351
|
-
return project.compilerOptions.paths?.[packageName] ?? [];
|
|
1352
|
-
};
|
|
1353
|
-
|
|
1354
1293
|
const discoverEntryPoints = (root, project, requested) => {
|
|
1355
1294
|
const sourceFiles = sourceFileIndex(project);
|
|
1356
1295
|
if (requested.length > 0) return requestedEntryPoints(requested, sourceFiles);
|
|
@@ -1468,16 +1407,16 @@ const signatureTypes = (project, type, anchor) =>
|
|
|
1468
1407
|
|
|
1469
1408
|
const checkerTypeChildren = (project, type, anchor, hasNamedDeclaration) => {
|
|
1470
1409
|
if (type.isTypeParameter()) {
|
|
1471
|
-
const constraint = safeCheckerValue(
|
|
1472
|
-
() => project.checker.getConstraintOfTypeParameter(type),
|
|
1473
|
-
undefined,
|
|
1474
|
-
);
|
|
1410
|
+
const constraint = safeCheckerValue(() => project.checker.getConstraintOfTypeParameter(type));
|
|
1475
1411
|
return constraint ? [constraint] : [];
|
|
1476
1412
|
}
|
|
1477
1413
|
const structural = [
|
|
1478
1414
|
...(type.getTypes() ?? []),
|
|
1479
1415
|
...safeCheckerValue(() => type.getAliasTypeArguments(), []),
|
|
1480
|
-
|
|
1416
|
+
// On tsrs, this call panics to stderr for a type that is not a reference.
|
|
1417
|
+
...(type.isTypeReference()
|
|
1418
|
+
? safeCheckerValue(() => project.checker.getTypeArguments(type), [])
|
|
1419
|
+
: []),
|
|
1481
1420
|
].filter(Boolean);
|
|
1482
1421
|
if (hasNamedDeclaration) return structural;
|
|
1483
1422
|
const direct = [...structural, ...signatureTypes(project, type, anchor)];
|
|
@@ -1790,8 +1729,10 @@ const emptySemanticAnalysis = (queries) => ({
|
|
|
1790
1729
|
results: queries.map((query) =>
|
|
1791
1730
|
unavailable(
|
|
1792
1731
|
query,
|
|
1793
|
-
"no-project",
|
|
1794
|
-
|
|
1732
|
+
isSupportedSemanticQuery(query) ? "no-project" : "unsupported-syntax",
|
|
1733
|
+
isSupportedSemanticQuery(query)
|
|
1734
|
+
? "Pass an explicit tsconfig with --type-aware-project and retry."
|
|
1735
|
+
: "Use a supported TypeScript or JavaScript declaration or retain the syntactic finding.",
|
|
1795
1736
|
),
|
|
1796
1737
|
),
|
|
1797
1738
|
phaseTimings: { project_setup: 0, diagnostics: 0, semantic_queries: 0 },
|
|
@@ -2021,15 +1962,6 @@ const emptyRequestedAnalysis = () => ({
|
|
|
2021
1962
|
warnings: [],
|
|
2022
1963
|
});
|
|
2023
1964
|
|
|
2024
|
-
const semanticOpenFiles = (queries) =>
|
|
2025
|
-
queries.filter((query) => query.symbol).map((query) => query.symbol.absolutePath);
|
|
2026
|
-
|
|
2027
|
-
const semanticOpenProjects = (root, projects) => {
|
|
2028
|
-
if (projects.length > 0) return projects.map((project) => project.absolutePath);
|
|
2029
|
-
const conventionalProject = path.join(root, "tsconfig.json");
|
|
2030
|
-
return existsSync(conventionalProject) ? [conventionalProject] : [];
|
|
2031
|
-
};
|
|
2032
|
-
|
|
2033
1965
|
const semanticProjectSelection = (snapshot, openProjects, openFiles, allowDefaultFallback) => {
|
|
2034
1966
|
const explicitProjects = openProjects
|
|
2035
1967
|
.map((project) => snapshot.getProject(project))
|
|
@@ -2164,7 +2096,7 @@ const executeDisposableSemanticAnalysis = (input) => {
|
|
|
2164
2096
|
|
|
2165
2097
|
export const analyzeSemanticQueries = (
|
|
2166
2098
|
{ root, projects, queries, evidenceLimit },
|
|
2167
|
-
{ createApi = (cwd) =>
|
|
2099
|
+
{ createApi = (cwd) => createBackendApi({ cwd }) } = {},
|
|
2168
2100
|
) => {
|
|
2169
2101
|
if (queries.length === 0) return emptyRequestedAnalysis();
|
|
2170
2102
|
const setupStartedAt = performance.now();
|
|
@@ -2183,7 +2115,10 @@ export const analyzeSemanticQueries = (
|
|
|
2183
2115
|
}
|
|
2184
2116
|
};
|
|
2185
2117
|
|
|
2186
|
-
export const createSemanticSession = (
|
|
2118
|
+
export const createSemanticSession = (
|
|
2119
|
+
root,
|
|
2120
|
+
{ createApi = (cwd) => createBackendApi({ cwd }) } = {},
|
|
2121
|
+
) => {
|
|
2187
2122
|
const api = createApi(root);
|
|
2188
2123
|
const state = {
|
|
2189
2124
|
openFiles: new Set(),
|