|
1 | 1 | import { orderBy } from "natural-orderby"; |
2 | | -import { Node, type ExportedDeclarations } from "ts-morph"; |
| 2 | +import { |
| 3 | + type ExportedDeclarations, |
| 4 | + type ModuleDeclaration, |
| 5 | + Node, |
| 6 | + type Project, |
| 7 | + type SourceFile, |
| 8 | +} from "ts-morph"; |
3 | 9 | import { ambientModulesDeclarations } from "./ambient-modules-declarations.ts"; |
4 | 10 | import { |
5 | 11 | isClass, |
@@ -29,7 +35,39 @@ import { extractVariableAssignmentExpression } from "./extract-variable-assignme |
29 | 35 | import { extractVariable } from "./extract-variable.ts"; |
30 | 36 | import { globalAmbientDeclarations } from "./global-ambient-declarations.ts"; |
31 | 37 | import { id } from "./id.ts"; |
32 | | -import type { ExtractDeclarationsOptions, ExtractedDeclaration } from "./types.ts"; |
| 38 | +import type { ExtractedDeclaration } from "./types.ts"; |
| 39 | + |
| 40 | +/** `ExtractDeclarationsOptions` contains the options for calling {@link extractDeclarations}. */ |
| 41 | +export interface ExtractDeclarationsOptions { |
| 42 | + /** Container that exports the top-level declarations. */ |
| 43 | + container: SourceFile | ModuleDeclaration; |
| 44 | + |
| 45 | + /** |
| 46 | + Container name (e.g., the name of a namespace), used to generate declaration IDs. |
| 47 | + */ |
| 48 | + containerName: string; |
| 49 | + |
| 50 | + /** Maximum extraction depth for nested namespaces. */ |
| 51 | + maxDepth: number; |
| 52 | + |
| 53 | + /** Instance of a `ts-morph` `Project`, used to find ambient modules. */ |
| 54 | + project?: Project; |
| 55 | + |
| 56 | + /** Name of the package being analyzed, used to filter ambient modules. */ |
| 57 | + pkgName?: string; |
| 58 | +} |
| 59 | + |
| 60 | +/** `FoundDeclaration` represents a declaration found during the initial extraction process. */ |
| 61 | +export interface FoundDeclaration { |
| 62 | + /** Declaration container name. */ |
| 63 | + containerName: string; |
| 64 | + |
| 65 | + /** Export name (may differ from the original name). */ |
| 66 | + exportName: string; |
| 67 | + |
| 68 | + /** Declaration. */ |
| 69 | + declaration: ExportedDeclarations; |
| 70 | +} |
33 | 71 |
|
34 | 72 | /** |
35 | 73 | `extractDeclarations` extracts the top-level declarations |
@@ -68,14 +106,14 @@ export async function extractDeclarations({ |
68 | 106 | return orderBy(extractedDeclarations, "id"); |
69 | 107 | } |
70 | 108 |
|
71 | | -type ExtractDeclarationOptions = { |
| 109 | +interface ExtractDeclarationOptions { |
72 | 110 | containerName: string; |
73 | 111 | exportName: string; |
74 | 112 | declaration: ExportedDeclarations; |
75 | 113 | maxDepth: number; |
76 | 114 | seenFunctions: Set<string>; |
77 | 115 | seenNamespaces: Set<string>; |
78 | | -}; |
| 116 | +} |
79 | 117 |
|
80 | 118 | async function extractDeclaration({ |
81 | 119 | containerName, |
|
0 commit comments