@@ -66,20 +66,25 @@ function analyzeFile(
6666 return `(${ parameters } ): ${ returnType } ` ;
6767 }
6868
69- function getVisibility ( node : ts . Declaration ) : string {
69+ function getVisibility ( node : ts . Declaration | ts . VariableStatement ) : string {
70+ if ( ts . isVariableStatement ( node ) ) {
71+ return node . modifiers ?. some ( ( m ) => m . kind === ts . SyntaxKind . ExportKeyword )
72+ ? "public"
73+ : "private" ;
74+ }
7075 const modifiers = ts . getCombinedModifierFlags ( node ) ;
7176 if ( modifiers & ts . ModifierFlags . Private ) return "private" ;
7277 if ( modifiers & ts . ModifierFlags . Protected ) return "protected" ;
73- return "public" ;
78+ if ( modifiers & ts . ModifierFlags . Export ) return "public" ;
79+ return "private" ; // Non-exported top-level declarations are considered private
7480 }
7581
76- function isVisibleEnough ( node : ts . Declaration ) : boolean {
77- const nodeVisibility = getVisibility ( node ) ;
82+ function isVisibleEnough ( visibility : string ) : boolean {
7883 switch ( visibilityLevel ) {
7984 case VisibilityLevel . Public :
80- return nodeVisibility === "public" ;
85+ return visibility === "public" ;
8186 case VisibilityLevel . Protected :
82- return nodeVisibility === "public" || nodeVisibility === "protected" ;
87+ return visibility === "public" || visibility === "protected" ;
8388 case VisibilityLevel . Private :
8489 return true ;
8590 }
@@ -93,10 +98,10 @@ function analyzeFile(
9398 ts . isClassDeclaration ( node ) ||
9499 ts . isVariableStatement ( node )
95100 ) {
96- let exportType = "export " ;
101+ let exportType = "" ;
97102 let name = "" ;
98103 let isDefault = false ;
99- let visibility = "public " ;
104+ let visibility = "private " ;
100105
101106 if (
102107 ts . isFunctionDeclaration ( node ) ||
@@ -118,17 +123,11 @@ function analyzeFile(
118123 if ( ts . isIdentifier ( declaration . name ) ) {
119124 exportType = "const" ;
120125 name = declaration . name . text ;
121- visibility = node . modifiers ?. some (
122- ( m ) => m . kind === ts . SyntaxKind . ExportKeyword ,
123- )
124- ? "public"
125- : "private" ;
126+ visibility = getVisibility ( node ) ;
126127 }
127128 }
128129
129- const shouldInclude = ts . isVariableStatement ( node )
130- ? visibilityLevel === VisibilityLevel . Private || visibility === "public"
131- : isVisibleEnough ( node as ts . Declaration ) ;
130+ const shouldInclude = isVisibleEnough ( visibility ) ;
132131
133132 if ( name && shouldInclude ) {
134133 const visibilityPrefix =
@@ -139,17 +138,18 @@ function analyzeFile(
139138 output += "\n" ;
140139 node . members . forEach ( ( member ) => {
141140 if (
142- ( ts . isMethodDeclaration ( member ) ||
143- ts . isConstructorDeclaration ( member ) ) &&
144- isVisibleEnough ( member )
141+ ts . isMethodDeclaration ( member ) ||
142+ ts . isConstructorDeclaration ( member )
145143 ) {
146144 const methodName = ts . isConstructorDeclaration ( member )
147145 ? "constructor"
148146 : member . name . getText ( ) ;
149147 const memberVisibility = getVisibility ( member ) ;
150- const memberVisibilityPrefix =
151- memberVisibility !== "public" ? `${ memberVisibility } ` : "" ;
152- output += ` ├─ ${ memberVisibilityPrefix } ${ methodName } ${ getMethodSignature ( member ) } \n` ;
148+ if ( isVisibleEnough ( memberVisibility ) ) {
149+ const memberVisibilityPrefix =
150+ memberVisibility !== "public" ? `${ memberVisibility } ` : "" ;
151+ output += ` ├─ ${ memberVisibilityPrefix } ${ methodName } ${ getMethodSignature ( member ) } \n` ;
152+ }
153153 }
154154 } ) ;
155155 } else if ( ts . isFunctionDeclaration ( node ) ) {
0 commit comments