Skip to content

Commit 7fb7b1c

Browse files
committed
refactor: update extract-declarations module
1 parent c49ee27 commit 7fb7b1c

File tree

5 files changed

+46
-8
lines changed

5 files changed

+46
-8
lines changed

src/ambient-modules-declarations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Node, type Project } from "ts-morph";
2+
import type { FoundDeclaration } from "./extract-declarations.ts";
23
import { isHidden } from "./is-hidden.ts";
34
import { sourceFilePath } from "./source-file-path.ts";
4-
import type { FoundDeclaration } from "./types.ts";
55

66
export function ambientModulesDeclarations(
77
containerName: string,

src/export-equals-declarations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { ModuleDeclaration, SourceFile, SyntaxKind } from "ts-morph";
22
import { isNamespace } from "./declaration-type-guards.ts";
3+
import type { FoundDeclaration } from "./extract-declarations.ts";
34
import { isExportedDeclarations } from "./is-exported-declarations.ts";
45
import { isHidden } from "./is-hidden.ts";
56
import { isShorthandAmbientModule } from "./is-shorthand-ambient-module.ts";
6-
import type { FoundDeclaration } from "./types.ts";
77

88
export function exportEqualsDeclarations(
99
containerName: string,

src/exported-declarations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { ModuleDeclaration, SourceFile } from "ts-morph";
2+
import type { FoundDeclaration } from "./extract-declarations.ts";
23
import { isExportedDeclarations } from "./is-exported-declarations.ts";
34
import { isHidden } from "./is-hidden.ts";
4-
import type { FoundDeclaration } from "./types.ts";
55

66
export function exportedDeclarations(
77
containerName: string,

src/extract-declarations.ts

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
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";
39
import { ambientModulesDeclarations } from "./ambient-modules-declarations.ts";
410
import {
511
isClass,
@@ -29,7 +35,39 @@ import { extractVariableAssignmentExpression } from "./extract-variable-assignme
2935
import { extractVariable } from "./extract-variable.ts";
3036
import { globalAmbientDeclarations } from "./global-ambient-declarations.ts";
3137
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+
}
3371

3472
/**
3573
`extractDeclarations` extracts the top-level declarations
@@ -68,14 +106,14 @@ export async function extractDeclarations({
68106
return orderBy(extractedDeclarations, "id");
69107
}
70108

71-
type ExtractDeclarationOptions = {
109+
interface ExtractDeclarationOptions {
72110
containerName: string;
73111
exportName: string;
74112
declaration: ExportedDeclarations;
75113
maxDepth: number;
76114
seenFunctions: Set<string>;
77115
seenNamespaces: Set<string>;
78-
};
116+
}
79117

80118
async function extractDeclaration({
81119
containerName,

src/global-ambient-declarations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { SourceFile } from "ts-morph";
2+
import type { FoundDeclaration } from "./extract-declarations.ts";
23
import { isGlobal } from "./is-global.ts";
34
import { isHidden } from "./is-hidden.ts";
4-
import type { FoundDeclaration } from "./types.ts";
55

66
export function globalAmbientDeclarations(
77
containerName: string,

0 commit comments

Comments
 (0)