@@ -7,14 +7,33 @@ import { ExportNode } from '../models';
77export function parseExport (
88 exportSymbol : ts . Symbol ,
99 parserContext : ParserContext ,
10- ) : ExportNode | undefined {
10+ parentNamespaces : string [ ] = [ ] ,
11+ ) : ExportNode [ ] | undefined {
1112 const { checker, sourceFile } = parserContext ;
1213
1314 const exportDeclaration = exportSymbol . declarations ?. [ 0 ] ;
1415 if ( ! exportDeclaration ) {
1516 return ;
1617 }
1718
19+ if ( ts . isModuleDeclaration ( exportDeclaration ) ) {
20+ // Handle exported namespace
21+ const namespaceSymbol = checker . getSymbolAtLocation ( exportDeclaration . name ) ;
22+ if ( ! namespaceSymbol ) return ;
23+ const members = checker . getExportsOfModule ( namespaceSymbol ) ;
24+ const nsName = exportDeclaration . name . getText ( ) ;
25+ const results : ExportNode [ ] = [ ] ;
26+ for ( const member of members ) {
27+ const memberExports = parseExport ( member , parserContext , [ ...parentNamespaces , nsName ] ) ;
28+ if ( Array . isArray ( memberExports ) ) {
29+ results . push ( ...memberExports ) ;
30+ } else if ( memberExports ) {
31+ results . push ( memberExports ) ;
32+ }
33+ }
34+ return results ;
35+ }
36+
1837 if ( ts . isExportSpecifier ( exportDeclaration ) ) {
1938 // export { x }
2039 // export { x as y }
@@ -38,7 +57,7 @@ export function parseExport(
3857 }
3958
4059 const type = checker . getTypeOfSymbol ( targetSymbol ) ;
41- return createExportNode ( exportSymbol . name , targetSymbol , type ) ;
60+ return createExportNode ( exportSymbol . name , targetSymbol , type , parentNamespaces ) ;
4261 } else if ( ts . isExportAssignment ( exportDeclaration ) ) {
4362 // export default x
4463 const exportedSymbol = checker . getSymbolAtLocation ( exportDeclaration . expression ) ;
@@ -51,6 +70,7 @@ export function parseExport(
5170 exportSymbol . name ,
5271 exportedSymbol ,
5372 checker . getTypeOfSymbol ( exportedSymbol ) ,
73+ parentNamespaces ,
5474 ) ;
5575 } else if (
5676 ts . isVariableDeclaration ( exportDeclaration ) ||
@@ -69,7 +89,7 @@ export function parseExport(
6989 }
7090
7191 const type = checker . getTypeOfSymbol ( exportedSymbol ) ;
72- return createExportNode ( exportSymbol . name , exportedSymbol , type ) ;
92+ return createExportNode ( exportSymbol . name , exportedSymbol , type , parentNamespaces ) ;
7393 } else if ( ts . isEnumDeclaration ( exportDeclaration ) ) {
7494 // export enum x {}
7595 if ( ! exportDeclaration . name ) {
@@ -87,13 +107,22 @@ export function parseExport(
87107 }
88108
89109 const type = checker . getTypeAtLocation ( exportedSymbol . declarations [ 0 ] ) ;
90- return createExportNode ( exportSymbol . name , exportedSymbol , type ) ;
110+ return createExportNode ( exportSymbol . name , exportedSymbol , type , parentNamespaces ) ;
91111 }
92112
93- function createExportNode ( name : string , symbol : ts . Symbol , type : ts . Type ) {
113+ function createExportNode (
114+ name : string ,
115+ symbol : ts . Symbol ,
116+ type : ts . Type ,
117+ parentNamespaces : string [ ] ,
118+ ) {
94119 const parsedType = resolveType ( type , symbol . getName ( ) , parserContext ) ;
95120 if ( parsedType ) {
96- return new ExportNode ( name , parsedType , getDocumentationFromSymbol ( symbol , checker ) ) ;
121+ // Patch parentNamespaces if the type supports it
122+ if ( parsedType && 'parentNamespaces' in parsedType ) {
123+ parsedType . parentNamespaces = parentNamespaces ;
124+ }
125+ return [ new ExportNode ( name , parsedType , getDocumentationFromSymbol ( symbol , checker ) ) ] ;
97126 }
98127 }
99128}
0 commit comments