Skip to content

Commit c30a473

Browse files
committed
refactor: update exportEqualsDeclarations
1 parent 8f2c122 commit c30a473

File tree

1 file changed

+9
-20
lines changed

1 file changed

+9
-20
lines changed

src/export-equals-declarations.ts

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,27 @@
1-
import { ModuleDeclaration, SourceFile, SyntaxKind, type ExportedDeclarations } from "ts-morph";
1+
import { ModuleDeclaration, SourceFile, SyntaxKind } from "ts-morph";
22
import { isNamespace } from "./declaration-type-guards.ts";
33
import { isExportedDeclarations } from "./is-exported-declarations.ts";
44
import { isHidden } from "./is-hidden.ts";
55
import { isShorthandAmbientModule } from "./is-shorthand-ambient-module.ts";
6-
7-
export type ExportEqualsDeclarationsReturn = {
8-
containerName: string;
9-
exportName: string;
10-
declaration: Exclude<ExportedDeclarations, ModuleDeclaration>;
11-
}[];
6+
import type { FoundDeclaration } from "./types.ts";
127

138
export function exportEqualsDeclarations(
149
containerName: string,
1510
container: SourceFile | ModuleDeclaration,
16-
): ExportEqualsDeclarationsReturn {
17-
if (isShorthandAmbientModule(container)) {
18-
// Export equals declarations may exist inside the body of ambient modules.
19-
// However, this is impossible for shorthand ambient modules with no body.
20-
return [];
21-
}
11+
): FoundDeclaration[] {
12+
// Shorthand ambient modules have no body and thus no declarations.
13+
if (isShorthandAmbientModule(container)) return [];
2214
const exportIdentifier = container
2315
.getExportAssignment((assignment) => assignment.isExportEquals())
2416
?.getLastChildByKind(SyntaxKind.Identifier);
25-
if (!exportIdentifier) {
26-
return [];
27-
}
17+
if (!exportIdentifier) return [];
2818
const exportName = exportIdentifier.getText();
2919
const exportEqualsDeclarations = [];
3020
for (const declaration of exportIdentifier.getDefinitionNodes()) {
31-
if (isHidden(declaration) || !isExportedDeclarations(declaration)) {
32-
continue;
33-
}
21+
if (!isExportedDeclarations(declaration)) continue;
22+
if (isHidden(declaration)) continue;
3423
if (isNamespace(declaration)) {
35-
// Skip namespaces since `exportedDeclarations()` already extracts
24+
// Ignore namespaces since `exportedDeclarations()` already extracts
3625
// the inner declarations of an export equals namespace as
3726
// non-namespaced declarations belonging to the parent container.
3827
// See snapshot for `export-equals-function-and-namespace.test.ts`.

0 commit comments

Comments
 (0)