@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.
Files changed (207) hide show
  1. package/dist/src/alias-chain.js +0 -5
  2. package/dist/src/amd.js +81 -0
  3. package/dist/src/analysis.js +94 -54
  4. package/dist/src/augmentations.js +23 -24
  5. package/dist/src/bindings.js +382 -0
  6. package/dist/src/calls.js +25 -8
  7. package/dist/src/commands/read.js +6 -7
  8. package/dist/src/commands/tools.js +5 -9
  9. package/dist/src/component-files.js +3 -2
  10. package/dist/src/conformance-record.js +1 -1
  11. package/dist/src/consumers.js +9 -10
  12. package/dist/src/contextual-uses.js +1 -17
  13. package/dist/src/contract/config.generated.js +5 -2
  14. package/dist/src/contract/contract.generated.js +119 -2
  15. package/dist/src/contract/report.generated.js +6 -2
  16. package/dist/src/dependencies.js +98 -71
  17. package/dist/src/destructuring.js +1 -19
  18. package/dist/src/element-access.js +179 -164
  19. package/dist/src/entries/build-scripts.js +222 -0
  20. package/dist/src/{configuration-files.js → entries/configuration-files.js} +22 -64
  21. package/dist/src/{convention-rows.js → entries/convention-rows.js} +120 -27
  22. package/dist/src/entries/conventions.js +739 -0
  23. package/dist/src/{html-entries.js → entries/html-entries.js} +9 -12
  24. package/dist/src/{mdx-entries.js → entries/mdx-entries.js} +3 -3
  25. package/dist/src/entries/run-directories.js +77 -0
  26. package/dist/src/entries/sources.js +144 -0
  27. package/dist/src/entries/static-module.js +670 -0
  28. package/dist/src/entries/test-runners.js +684 -0
  29. package/dist/src/{workflow-steps.js → entries/workflow-steps.js} +18 -8
  30. package/dist/src/extensions.js +37 -0
  31. package/dist/src/facts.js +38 -0
  32. package/dist/src/findings/completion.js +40 -4
  33. package/dist/src/findings/emitters.js +5 -8
  34. package/dist/src/{implementations.js → findings/implementations.js} +3 -3
  35. package/dist/src/{in-operands.js → findings/in-operands.js} +2 -2
  36. package/dist/src/findings/self-check.js +36 -20
  37. package/dist/src/findings-pass.js +5 -6
  38. package/dist/src/framework-lifecycle.js +42 -15
  39. package/dist/src/fs/manifest.js +15 -20
  40. package/dist/src/generated-file.js +172 -29
  41. package/dist/src/graph.js +14 -8
  42. package/dist/src/import-bindings.js +73 -28
  43. package/dist/src/index/sites.js +557 -0
  44. package/dist/src/index.js +1 -1
  45. package/dist/src/indexed-access.js +523 -478
  46. package/dist/src/injection-container.js +1 -1
  47. package/dist/src/interface-satisfaction.js +1 -1
  48. package/dist/src/inventory/commonjs.js +62 -17
  49. package/dist/src/inventory/enumerate.js +2 -1
  50. package/dist/src/javascript-file.js +26 -11
  51. package/dist/src/keyof-comparisons.js +124 -103
  52. package/dist/src/load/classify.js +28 -9
  53. package/dist/src/load/diagnostics.js +8 -1
  54. package/dist/src/load/discover.js +15 -7
  55. package/dist/src/load/expected-module.js +2 -2
  56. package/dist/src/load/plan.js +2 -2
  57. package/dist/src/load/specifiers.js +2 -4
  58. package/dist/src/load/synthesize.js +10 -5
  59. package/dist/src/load/workspace-manifests.js +1 -1
  60. package/dist/src/load/workspace-resolution.js +2 -2
  61. package/dist/src/matrix.js +12 -17
  62. package/dist/src/module-declarations.js +70 -85
  63. package/dist/src/overrides.js +134 -112
  64. package/dist/src/paths.js +56 -1
  65. package/dist/src/platform-calls.js +78 -0
  66. package/dist/src/platform-symbols.js +134 -0
  67. package/dist/src/references/read-rule.js +1 -0
  68. package/dist/src/references/read-rules.js +48 -0
  69. package/dist/src/references/sink.js +151 -0
  70. package/dist/src/references/sources.js +450 -0
  71. package/dist/src/references.js +111 -1116
  72. package/dist/src/resolve.js +1 -1
  73. package/dist/src/{configured-declarations.js → roots/configured-declarations.js} +7 -4
  74. package/dist/src/{entry-point-gaps.js → roots/entry-point-gaps.js} +5 -8
  75. package/dist/src/{manifest.js → roots/manifest.js} +4 -4
  76. package/dist/src/roots/published-reach.js +412 -0
  77. package/dist/src/roots/root-set.js +489 -0
  78. package/dist/src/roots/unseen-loads.js +236 -0
  79. package/dist/src/serialization-contract.js +9 -4
  80. package/dist/src/source-files.js +5 -9
  81. package/dist/src/stores.js +4 -2
  82. package/dist/src/suppress.js +30 -32
  83. package/dist/src/sweep.js +25 -13
  84. package/dist/src/symbol-keys.js +89 -83
  85. package/dist/src/tests/file-class.js +76 -0
  86. package/dist/src/{outside-tests.js → tests/outside.js} +7 -7
  87. package/dist/src/{test-support.js → tests/support.js} +5 -12
  88. package/dist/src/type-parameter-reads.js +178 -139
  89. package/dist/src/unimplemented-callees.js +262 -242
  90. package/dist/src/verbs/analyze.js +15 -3
  91. package/dist/src/verbs/describe.js +5 -3
  92. package/dist/src/verbs/explain.js +50 -28
  93. package/dist/src/verbs/print-retained.js +2 -2
  94. package/jsr.json +1 -1
  95. package/package.json +3 -3
  96. package/src/alias-chain.ts +0 -7
  97. package/src/amd.ts +130 -0
  98. package/src/analysis.ts +156 -70
  99. package/src/augmentations.ts +41 -27
  100. package/src/automatic-types.ts +1 -1
  101. package/src/bindings.ts +460 -0
  102. package/src/calls.ts +25 -7
  103. package/src/commands/read.ts +6 -8
  104. package/src/commands/tools.ts +5 -11
  105. package/src/component-files.ts +4 -2
  106. package/src/conformance-record.ts +1 -1
  107. package/src/consumers.ts +12 -11
  108. package/src/contextual-uses.ts +2 -22
  109. package/src/contract/config.generated.ts +5 -2
  110. package/src/contract/contract.generated.ts +138 -2
  111. package/src/contract/report.generated.ts +6 -2
  112. package/src/dependencies.ts +117 -71
  113. package/src/destructuring.ts +1 -31
  114. package/src/element-access.ts +188 -182
  115. package/src/entries/build-scripts.ts +292 -0
  116. package/src/{configuration-files.ts → entries/configuration-files.ts} +33 -82
  117. package/src/{convention-rows.ts → entries/convention-rows.ts} +167 -28
  118. package/src/{conventions.ts → entries/conventions.ts} +349 -523
  119. package/src/{html-entries.ts → entries/html-entries.ts} +19 -18
  120. package/src/{mdx-entries.ts → entries/mdx-entries.ts} +5 -5
  121. package/src/entries/run-directories.ts +108 -0
  122. package/src/entries/sources.ts +266 -0
  123. package/src/entries/static-module.ts +858 -0
  124. package/src/entries/test-runners.ts +868 -0
  125. package/src/{workflow-steps.ts → entries/workflow-steps.ts} +29 -11
  126. package/src/exempt.ts +3 -2
  127. package/src/extensions.ts +45 -0
  128. package/src/facts.ts +46 -0
  129. package/src/file-facts.ts +1 -1
  130. package/src/findings/boundary.ts +2 -0
  131. package/src/findings/completion.ts +43 -4
  132. package/src/findings/emitter.ts +1 -1
  133. package/src/findings/emitters.ts +14 -10
  134. package/src/{implementations.ts → findings/implementations.ts} +4 -4
  135. package/src/{in-operands.ts → findings/in-operands.ts} +3 -3
  136. package/src/findings/self-check.ts +41 -22
  137. package/src/findings/visibility-narrowing.ts +1 -1
  138. package/src/findings-pass.ts +5 -12
  139. package/src/framework-lifecycle.ts +43 -15
  140. package/src/fs/manifest.ts +25 -21
  141. package/src/generated-file.ts +240 -36
  142. package/src/graph.ts +27 -11
  143. package/src/import-bindings.ts +98 -29
  144. package/src/index/sites.ts +781 -0
  145. package/src/index.ts +1 -1
  146. package/src/indexed-access.ts +570 -527
  147. package/src/injection-container.ts +1 -1
  148. package/src/interface-satisfaction.ts +1 -1
  149. package/src/inventory/commonjs.ts +102 -17
  150. package/src/inventory/enumerate.ts +2 -1
  151. package/src/javascript-file.ts +29 -12
  152. package/src/keyof-comparisons.ts +131 -116
  153. package/src/load/classify.ts +49 -13
  154. package/src/load/diagnostics.ts +11 -1
  155. package/src/load/discover.ts +27 -11
  156. package/src/load/expected-module.ts +8 -2
  157. package/src/load/plan.ts +11 -2
  158. package/src/load/specifiers.ts +8 -5
  159. package/src/load/synthesize.ts +12 -6
  160. package/src/load/test-globals.ts +1 -1
  161. package/src/load/workspace-manifests.ts +1 -1
  162. package/src/load/workspace-resolution.ts +9 -2
  163. package/src/load/workspace-run.ts +1 -1
  164. package/src/matrix.ts +13 -17
  165. package/src/module-declarations.ts +74 -98
  166. package/src/overrides.ts +162 -134
  167. package/src/paths.ts +65 -1
  168. package/src/platform-calls.ts +119 -0
  169. package/src/platform-symbols.ts +189 -0
  170. package/src/references/read-rule.ts +60 -0
  171. package/src/references/read-rules.ts +55 -0
  172. package/src/references/sink.ts +213 -0
  173. package/src/references/sources.ts +632 -0
  174. package/src/references.ts +174 -1492
  175. package/src/report.ts +2 -2
  176. package/src/resolve.ts +1 -1
  177. package/src/{configured-declarations.ts → roots/configured-declarations.ts} +10 -7
  178. package/src/{entry-point-gaps.ts → roots/entry-point-gaps.ts} +5 -8
  179. package/src/{manifest.ts → roots/manifest.ts} +5 -5
  180. package/src/roots/published-reach.ts +481 -0
  181. package/src/{roots.ts → roots/root-set.ts} +203 -630
  182. package/src/roots/unseen-loads.ts +345 -0
  183. package/src/serialization-contract.ts +9 -4
  184. package/src/source-files.ts +5 -10
  185. package/src/stores.ts +13 -2
  186. package/src/suppress.ts +48 -33
  187. package/src/sweep.ts +37 -14
  188. package/src/symbol-keys.ts +102 -102
  189. package/src/tests/file-class.ts +118 -0
  190. package/src/{outside-tests.ts → tests/outside.ts} +16 -10
  191. package/src/{test-support.ts → tests/support.ts} +15 -21
  192. package/src/type-parameter-reads.ts +187 -158
  193. package/src/unimplemented-callees.ts +297 -280
  194. package/src/verbs/analyze.ts +19 -5
  195. package/src/verbs/describe.ts +5 -2
  196. package/src/verbs/explain.ts +75 -32
  197. package/src/verbs/print-retained.ts +2 -2
  198. package/dist/src/build-scripts.js +0 -418
  199. package/dist/src/conventions.js +0 -907
  200. package/dist/src/entry-points.js +0 -444
  201. package/dist/src/own-body.js +0 -28
  202. package/dist/src/roots.js +0 -865
  203. package/dist/src/unseen-loads.js +0 -189
  204. package/src/build-scripts.ts +0 -536
  205. package/src/entry-points.ts +0 -584
  206. package/src/own-body.ts +0 -42
  207. package/src/unseen-loads.ts +0 -282
@@ -1,7 +1,7 @@
1
1
  import { SETTINGS } from "./contract/config.generated.js";
2
2
  import { FAMILY_KEY_LENGTH } from "./contract/contract.generated.js";
3
3
  import {} from "./config.js";
4
- import { CONVENTION_ROWS } from "./convention-rows.js";
4
+ import { CONVENTION_ROWS } from "./entries/convention-rows.js";
5
5
  import { refuseOverBound } from "./fs/document.js";
6
6
  import { dotted, isRecord, locatedFault, placeIn, pointerOf, readStrict, StrictJSONError, } from "./json-document.js";
7
7
  import { FIXED_SEVERITY_CODES } from "./kinds.js";
@@ -6,10 +6,10 @@
6
6
  */
7
7
  import { isCallExpression, isExportDeclaration, isExternalModuleReference, isImportDeclaration, isImportEqualsDeclaration, isNoSubstitutionTemplateLiteral, isStringLiteral, SyntaxKind, } from "@typescript/native/ast";
8
8
  import { SymbolFlags } from "@typescript/native/sync";
9
- import { resolvedTargets } from "./calls.js";
10
- import { declaredComponent } from "./inventory.js";
11
- import { must, Unanswerable } from "./query.js";
12
- import { nameComponent } from "./ref.js";
9
+ import { resolvedTargets } from "../calls.js";
10
+ import { declaredComponent } from "../inventory.js";
11
+ import { must, Unanswerable } from "../query.js";
12
+ import { nameComponent } from "../ref.js";
13
13
  /** The meanings a name of the global scope is looked up under: any of them. */
14
14
  const ANY_MEANING = SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace;
15
15
  /** The suffix that marks a static member at the end of a path. */
@@ -140,6 +140,9 @@ function specifierOf(node) {
140
140
  * import resolves. A specifier no file writes resolves to no module.
141
141
  */
142
142
  function modulesNamed(project, specifiers) {
143
+ if (specifiers.size === 0) {
144
+ return new Map();
145
+ }
143
146
  const written = new Map();
144
147
  for (const file of project.ownSourceFiles()) {
145
148
  const visit = (node) => {
@@ -1,13 +1,10 @@
1
1
  /**
2
- * Every entry-point convention this analyzer declines, each with the tool it belongs
3
- * to and why. A file only a declined convention enters is reported as never
4
- * imported, so a project that relies on one names the file in `ts.entry_files` or
5
- * `roots.patterns`, and this list is what tells it to.
6
- *
7
- * Every row carries a reason, because the list is read where the rows are shown
8
- * one at a time: beside a finding, or in a report's declared gaps.
2
+ * Every entry-point convention this analyzer declines, each with its tool and why. A file only
3
+ * a declined convention enters is reported as never imported, so a project relying on one names
4
+ * the file in `ts.entry_files` or `roots.patterns`, and this list tells it to. Every row carries
5
+ * a reason, since rows are shown one at a time, beside a finding or in a report's declared gaps.
9
6
  */
10
- import { bytewise } from "./text/compare.js";
7
+ import { bytewise } from "../text/compare.js";
11
8
  /** What is declined for a tool whose own conventions are entered only through its configuration files. */
12
9
  const EVERY_CONVENTION = "every file it loads by its own convention beyond its configuration files";
13
10
  /** Why a tool whose own conventions are not read declines them. */
@@ -4,10 +4,10 @@
4
4
  * shell running its command or one of its scripts. {@link readManifest} reads one
5
5
  * directory's manifest, {@link packageEntries} those of the packages below the target root.
6
6
  */
7
- import { isAbsolutePath, joinPath, relativePath, resolvePath } from "./paths.js";
8
- import { isRecord } from "./json-document.js";
9
- import { MANIFEST, manifestAt, readJSON } from "./fs/manifest.js";
10
- import { pathsNamed, readCommands } from "./commands/read.js";
7
+ import { isAbsolutePath, joinPath, relativePath, resolvePath } from "../paths.js";
8
+ import { isRecord } from "../json-document.js";
9
+ import { MANIFEST, manifestAt, readJSON } from "../fs/manifest.js";
10
+ import { pathsNamed, readCommands } from "../commands/read.js";
11
11
  /** The three members that name an entry point beside `exports` and `bin`. */
12
12
  const LEGACY_MEMBERS = ["main", "module", "types"];
13
13
  /**
@@ -0,0 +1,412 @@
1
+ /**
2
+ * The published reach of a library: what a consumer outside the target can name, from the
3
+ * files a published manifest entry or a bundle hands it and the declarations a release tag
4
+ * marks, through the types each published declaration names.
5
+ */
6
+ import { isArrowFunction, isAssertionExpression, isExpressionWithTypeArguments, isFunctionLikeDeclaration, isIdentifier, isMethodDeclaration, isObjectLiteralExpression, isParenthesizedExpression, isPropertyAssignment, isReturnStatement, isSatisfiesExpression, isPropertyAccessExpression, isQualifiedName, isTypeQueryNode, isTypeReferenceNode, isPropertyDeclaration, isVariableDeclaration, isVariableStatement, SyntaxKind, } from "@typescript/native/ast";
7
+ import { aliasChains } from "../alias-chain.js";
8
+ import { isGlobalBlock } from "../augmentations.js";
9
+ import { nodeKey } from "../inventory.js";
10
+ import { UNANSWERED } from "../query.js";
11
+ /** A release tag of a documentation comment: `@` and its name, between white space or the ends. */
12
+ const RELEASE_TAG = /(?:^|\s)@(?:public|beta|alpha)(?=\s|$)/u;
13
+ /**
14
+ * Whether the documentation comment of the statement that starts at `start`, the last
15
+ * `/** *\/` comment before it with only white space between the two, holds a release tag.
16
+ */
17
+ function releaseTagIn(text, from, start) {
18
+ const leading = text.slice(from, start);
19
+ const open = leading.lastIndexOf("/**");
20
+ const close = open < 0 ? -1 : leading.indexOf("*/", open + 3);
21
+ if (close < 0 || leading.slice(close + 2).trim() !== "") {
22
+ return false;
23
+ }
24
+ return RELEASE_TAG.test(leading.slice(open + 3, close));
25
+ }
26
+ /** The exported top-level declarations of the program's files a release tag marks. */
27
+ export function releaseTagged(held, files) {
28
+ const exported = new Set(held.symbols.filter((symbol) => symbol.exported).map((one) => one.id));
29
+ const found = [];
30
+ for (const file of files.byPath.values()) {
31
+ for (const statement of file.statements) {
32
+ if (!releaseTagIn(file.text, statement.pos, statement.getStart())) {
33
+ continue;
34
+ }
35
+ const nodes = isVariableStatement(statement)
36
+ ? statement.declarationList.declarations
37
+ : [statement];
38
+ for (const node of nodes) {
39
+ const id = held.declarations.get(nodeKey(file, node));
40
+ if (id !== undefined && exported.has(id)) {
41
+ found.push(id);
42
+ }
43
+ }
44
+ }
45
+ }
46
+ return found;
47
+ }
48
+ /** The kinds of container whose export table, not its members' visibility, says what it publishes. */
49
+ const EXPORTING_CONTAINERS = new Set(["file", "namespace"]);
50
+ /**
51
+ * Every declaration a consumer of the library can name, a published file itself excluded:
52
+ * what the published files export, with a namespace's exported members and any other
53
+ * declaration's public and protected ones; a declaration a published one's type names; an
54
+ * exported declaration a release tag marks; each declaration a `declare global` block holds
55
+ * in a published file or one holding a published declaration; and, as `guessed`, each
56
+ * declaration spelled as a type name the checker leaves unanswered.
57
+ */
58
+ export function publishedAPI(project, published, exportsOf, held, byPath, tagged) {
59
+ const byId = new Map(held.symbols.map((symbol) => [symbol.id, symbol]));
60
+ const children = childrenOf(held);
61
+ const nodes = declarationNodes(held, byPath);
62
+ const chains = aliasChains(project, held);
63
+ const reached = new Set();
64
+ const entered = new Set();
65
+ const guessed = new Set();
66
+ const pending = [];
67
+ const reach = (id) => {
68
+ const file = byId.get(id)?.kind === "file";
69
+ if (!(file ? entered : reached).has(id)) {
70
+ (file ? entered : reached).add(id);
71
+ pending.push(id);
72
+ }
73
+ };
74
+ for (const id of tagged) {
75
+ reach(id);
76
+ }
77
+ for (const file of published) {
78
+ for (const id of exportsOf.get(file.fileName) ?? []) {
79
+ reach(id);
80
+ }
81
+ }
82
+ const files = new Set(held.symbols.filter((one) => one.kind === "file").map((one) => one.id));
83
+ const blocks = held.symbols.filter((one) => isGlobalBlock(one, held, files));
84
+ const fileOf = (id) => {
85
+ let at = byId.get(id);
86
+ while (at !== undefined && at.kind !== "file") {
87
+ at = byId.get(at.parent);
88
+ }
89
+ return at?.id;
90
+ };
91
+ const publishedFiles = published.flatMap((file) => held.declarations.get(nodeKey(file, file)) ?? []);
92
+ const globalsReached = () => {
93
+ const typed = new Set([...publishedFiles, ...[...reached].flatMap((id) => fileOf(id) ?? [])]);
94
+ const before = pending.length;
95
+ for (const block of blocks.filter((one) => typed.has(one.parent))) {
96
+ reach(block.id);
97
+ for (const member of children.get(block.id) ?? []) {
98
+ if (member.kind !== "type-parameter") {
99
+ reach(member.id);
100
+ }
101
+ }
102
+ }
103
+ return pending.length > before;
104
+ };
105
+ do {
106
+ while (pending.length > 0) {
107
+ const round = [];
108
+ for (let next = pending.shift(); next !== undefined; next = pending.shift()) {
109
+ round.push(next);
110
+ const exporting = EXPORTING_CONTAINERS.has(byId.get(next)?.kind ?? "");
111
+ for (const member of children.get(next) ?? []) {
112
+ const reachable = exporting
113
+ ? member.exported
114
+ : member.visibility !== "private" && member.visibility !== "private-name";
115
+ if (member.kind !== "type-parameter" && reachable) {
116
+ reach(member.id);
117
+ }
118
+ }
119
+ }
120
+ const named = round.flatMap((id) => {
121
+ const symbol = byId.get(id);
122
+ return symbol === undefined || symbol.kind === "file" ? [] : nodes.typeNamesOf(symbol);
123
+ });
124
+ const inferred = inferredTypeSymbols(project, round.flatMap((id) => {
125
+ const symbol = byId.get(id);
126
+ return symbol === undefined ? [] : nodes.nodesOf(symbol);
127
+ }));
128
+ for (const symbol of inferred.types) {
129
+ for (const target of chains.chainOf(symbol)) {
130
+ reach(target.id);
131
+ }
132
+ }
133
+ for (const symbol of inferred.members) {
134
+ for (const target of chains.chainOf(symbol)) {
135
+ const member = byId.get(target.id);
136
+ if (member?.visibility === "public" || member?.visibility === "protected") {
137
+ reach(target.id);
138
+ }
139
+ }
140
+ }
141
+ project.symbolsAt(named.map((node) => project.handle(node))).forEach((symbol, index) => {
142
+ if (symbol === UNANSWERED) {
143
+ for (const id of held.byName.get(named[index]?.getText() ?? "") ?? []) {
144
+ guessed.add(id);
145
+ reach(id);
146
+ }
147
+ }
148
+ else if (symbol !== undefined) {
149
+ for (const target of chains.chainOf(symbol)) {
150
+ reach(target.id);
151
+ }
152
+ }
153
+ });
154
+ }
155
+ } while (globalsReached());
156
+ return { ids: [...reached], guessed: [...guessed] };
157
+ }
158
+ /** The type names declarations of the inventory write, each file walked once, when first asked. */
159
+ function declarationNodes(held, byPath) {
160
+ const walked = new Map();
161
+ const nodesIn = (path) => {
162
+ const known = walked.get(path);
163
+ if (known !== undefined) {
164
+ return known;
165
+ }
166
+ const found = { byId: new Map(), nodes: new Set() };
167
+ const file = byPath.get(path);
168
+ if (file !== undefined) {
169
+ const visit = (node) => {
170
+ const id = held.declarations.get(nodeKey(file, node));
171
+ if (id !== undefined) {
172
+ found.nodes.add(node);
173
+ found.byId.set(id, [...(found.byId.get(id) ?? []), node]);
174
+ }
175
+ node.forEachChild(visit);
176
+ };
177
+ visit(file);
178
+ }
179
+ walked.set(path, found);
180
+ return found;
181
+ };
182
+ return {
183
+ typeNamesOf: (symbol) => {
184
+ const { byId, nodes } = nodesIn(symbol.position.path);
185
+ return (byId.get(symbol.id) ?? []).flatMap((declaration) => typeNamesOf(declaration, nodes));
186
+ },
187
+ nodesOf: (symbol) => nodesIn(symbol.position.path).byId.get(symbol.id) ?? [],
188
+ };
189
+ }
190
+ /** How deep the type arguments and constituents of an inferred type are followed. */
191
+ const INFERRED_DEPTH = 4;
192
+ /**
193
+ * The values one function body returns, each through the type assertions around it: the
194
+ * value a caller receives carries the operand's type whatever type the assertion or the
195
+ * signature names. A nested function's returns are its own.
196
+ */
197
+ function returnedValues(body) {
198
+ const found = [];
199
+ const add = (value) => {
200
+ for (let at = value; at !== undefined;) {
201
+ found.push(at);
202
+ at =
203
+ isAssertionExpression(at) || isSatisfiesExpression(at) || isParenthesizedExpression(at)
204
+ ? at.expression
205
+ : undefined;
206
+ }
207
+ };
208
+ if (!isFunctionLikeDeclaration(body.parent) || body.parent.body !== body) {
209
+ return found;
210
+ }
211
+ if (isArrowFunction(body.parent) && body.kind !== SyntaxKind.Block) {
212
+ add(body);
213
+ return found;
214
+ }
215
+ const visit = (node) => {
216
+ if (isFunctionLikeDeclaration(node)) {
217
+ return;
218
+ }
219
+ if (isReturnStatement(node) && node.expression !== undefined) {
220
+ add(node.expression);
221
+ }
222
+ node.forEachChild(visit);
223
+ };
224
+ body.forEachChild(visit);
225
+ return found;
226
+ }
227
+ /** The object literal one returned value is, written there or as the initializer of a variable `body` declares. */
228
+ function returnedLiteral(value, body) {
229
+ if (isObjectLiteralExpression(value)) {
230
+ return value;
231
+ }
232
+ if (!isIdentifier(value)) {
233
+ return undefined;
234
+ }
235
+ let found;
236
+ const visit = (node) => {
237
+ if (isVariableDeclaration(node) &&
238
+ isIdentifier(node.name) &&
239
+ node.name.text === value.text &&
240
+ node.initializer !== undefined) {
241
+ let at = node.initializer;
242
+ while (isAssertionExpression(at) ||
243
+ isSatisfiesExpression(at) ||
244
+ isParenthesizedExpression(at)) {
245
+ at = at.expression;
246
+ }
247
+ found = isObjectLiteralExpression(at) ? at : found;
248
+ }
249
+ if (!isFunctionLikeDeclaration(node)) {
250
+ node.forEachChild(visit);
251
+ }
252
+ };
253
+ body.forEachChild(visit);
254
+ return found;
255
+ }
256
+ /**
257
+ * The values one function body returns, and those each method of an object literal it
258
+ * returns returns, to a fixed depth: a caller holding the literal calls its methods, and
259
+ * receives what they return.
260
+ */
261
+ function returnedThroughLiterals(body, depth = 0) {
262
+ const values = returnedValues(body);
263
+ if (depth >= INFERRED_DEPTH) {
264
+ return values;
265
+ }
266
+ const found = [...values];
267
+ for (const value of values) {
268
+ for (const property of returnedLiteral(value, body)?.properties ?? []) {
269
+ const fn = isMethodDeclaration(property)
270
+ ? property
271
+ : isPropertyAssignment(property) && isFunctionLikeDeclaration(property.initializer)
272
+ ? property.initializer
273
+ : undefined;
274
+ if (fn?.body !== undefined) {
275
+ found.push(...returnedThroughLiterals(fn.body, depth + 1));
276
+ }
277
+ }
278
+ }
279
+ return found;
280
+ }
281
+ /**
282
+ * The declarations of the types the compiler infers where a declaration writes none, and
283
+ * of the values a function returns: the type of a variable or a property with no
284
+ * annotation, the result of a function or a method with no result annotation, and the type
285
+ * of each value its body returns, each with the types its type arguments and its union or
286
+ * intersection constituents name, to a fixed depth; and as `members` the properties of each
287
+ * returned value's type. A question the checker leaves unanswered names nothing.
288
+ */
289
+ function inferredTypeSymbols(project, declarations) {
290
+ const { queries } = project;
291
+ const valued = declarations.flatMap((node) => (isVariableDeclaration(node) || isPropertyDeclaration(node)) &&
292
+ node.type === undefined &&
293
+ !isFunctionLikeDeclaration(node.initializer ?? node)
294
+ ? [node.name]
295
+ : []);
296
+ const returned = declarations.flatMap((node) => {
297
+ const signature = isFunctionLikeDeclaration(node)
298
+ ? node
299
+ : isVariableDeclaration(node) &&
300
+ node.initializer !== undefined &&
301
+ isFunctionLikeDeclaration(node.initializer)
302
+ ? node.initializer
303
+ : undefined;
304
+ return signature?.body === undefined ? [] : returnedThroughLiterals(signature.body);
305
+ });
306
+ const types = [];
307
+ const returnedTypes = [];
308
+ queries.typesAt([...valued, ...returned]).forEach((type, at) => {
309
+ if (type !== UNANSWERED && type !== undefined) {
310
+ (at < valued.length ? types : returnedTypes).push(type);
311
+ }
312
+ });
313
+ types.push(...returnedTypes);
314
+ for (const node of declarations) {
315
+ const signature = isFunctionLikeDeclaration(node)
316
+ ? node
317
+ : isVariableDeclaration(node) &&
318
+ node.type === undefined &&
319
+ node.initializer !== undefined &&
320
+ isFunctionLikeDeclaration(node.initializer)
321
+ ? node.initializer
322
+ : undefined;
323
+ if (signature === undefined || signature.type !== undefined || signature.body === undefined) {
324
+ continue;
325
+ }
326
+ const typed = queries.signatureOf(signature);
327
+ const result = typed === UNANSWERED || typed === undefined ? undefined : queries.returnTypeOf(typed);
328
+ if (result !== UNANSWERED && result !== undefined) {
329
+ types.push(result);
330
+ }
331
+ }
332
+ const found = new Map();
333
+ const seen = new Set();
334
+ const visit = (type, depth) => {
335
+ if (depth > INFERRED_DEPTH || seen.has(type)) {
336
+ return;
337
+ }
338
+ seen.add(type);
339
+ const symbol = queries.symbolOfType(type);
340
+ if (symbol !== UNANSWERED && symbol !== undefined) {
341
+ found.set(symbol.id, symbol);
342
+ }
343
+ const parts = queries.constituents(type);
344
+ const args = queries.typeArguments(type);
345
+ for (const next of [
346
+ ...(parts === UNANSWERED || (parts.length === 1 && parts[0] === type) ? [] : parts),
347
+ ...(args === UNANSWERED ? [] : args),
348
+ ]) {
349
+ visit(next, depth + 1);
350
+ }
351
+ };
352
+ types.forEach((type) => {
353
+ visit(type, 0);
354
+ });
355
+ // A returned value carries each property of its type, one an anonymous type declares or
356
+ // an intersection merges included, which no type name reaches.
357
+ const members = new Map();
358
+ for (const type of returnedTypes) {
359
+ const parts = queries.constituents(type);
360
+ for (const one of [type, ...(parts === UNANSWERED ? [] : parts)]) {
361
+ const properties = queries.propertiesOf(one);
362
+ for (const property of properties === UNANSWERED ? [] : properties) {
363
+ members.set(property.id, property);
364
+ }
365
+ }
366
+ }
367
+ return { types: [...found.values()], members: [...members.values()] };
368
+ }
369
+ /**
370
+ * The names of types one declaration's own syntax writes: in a type reference, a
371
+ * heritage clause or a type query. A function body is not read, and neither is a
372
+ * declaration nested in this one, which `nested` holds and which is read on its own.
373
+ */
374
+ function typeNamesOf(declaration, nested) {
375
+ const found = [];
376
+ const visit = (node) => {
377
+ if (node !== declaration && nested.has(node)) {
378
+ return;
379
+ }
380
+ if (isTypeReferenceNode(node)) {
381
+ found.push(isQualifiedName(node.typeName) ? node.typeName.right : node.typeName);
382
+ }
383
+ else if (isExpressionWithTypeArguments(node)) {
384
+ found.push(isPropertyAccessExpression(node.expression) ? node.expression.name : node.expression);
385
+ }
386
+ else if (isTypeQueryNode(node)) {
387
+ found.push(isQualifiedName(node.exprName) ? node.exprName.right : node.exprName);
388
+ }
389
+ const body = isFunctionLikeDeclaration(node) ? node.body : undefined;
390
+ node.forEachChild((child) => {
391
+ if (child !== body) {
392
+ visit(child);
393
+ }
394
+ });
395
+ };
396
+ visit(declaration);
397
+ return found;
398
+ }
399
+ /** The members of one declaration, indexed by the container that holds them. */
400
+ function childrenOf(held) {
401
+ const byParent = new Map();
402
+ for (const symbol of held.symbols) {
403
+ const siblings = byParent.get(symbol.parent);
404
+ if (siblings === undefined) {
405
+ byParent.set(symbol.parent, [symbol]);
406
+ }
407
+ else {
408
+ siblings.push(symbol);
409
+ }
410
+ }
411
+ return byParent;
412
+ }