|
1 | | -import { ModuleDeclaration, SourceFile, SyntaxKind, type ExportedDeclarations } from "ts-morph"; |
| 1 | +import { ModuleDeclaration, SourceFile, SyntaxKind } from "ts-morph"; |
2 | 2 | import { isNamespace } from "./declaration-type-guards.ts"; |
3 | 3 | import { isExportedDeclarations } from "./is-exported-declarations.ts"; |
4 | 4 | import { isHidden } from "./is-hidden.ts"; |
5 | 5 | 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"; |
12 | 7 |
|
13 | 8 | export function exportEqualsDeclarations( |
14 | 9 | containerName: string, |
15 | 10 | 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 []; |
22 | 14 | const exportIdentifier = container |
23 | 15 | .getExportAssignment((assignment) => assignment.isExportEquals()) |
24 | 16 | ?.getLastChildByKind(SyntaxKind.Identifier); |
25 | | - if (!exportIdentifier) { |
26 | | - return []; |
27 | | - } |
| 17 | + if (!exportIdentifier) return []; |
28 | 18 | const exportName = exportIdentifier.getText(); |
29 | 19 | const exportEqualsDeclarations = []; |
30 | 20 | 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; |
34 | 23 | if (isNamespace(declaration)) { |
35 | | - // Skip namespaces since `exportedDeclarations()` already extracts |
| 24 | + // Ignore namespaces since `exportedDeclarations()` already extracts |
36 | 25 | // the inner declarations of an export equals namespace as |
37 | 26 | // non-namespaced declarations belonging to the parent container. |
38 | 27 | // See snapshot for `export-equals-function-and-namespace.test.ts`. |
|
0 commit comments