@@ -41,8 +41,11 @@ export interface ParentType {
41
41
42
42
export type PropFilter = ( props : PropItem , component : Component ) => boolean ;
43
43
44
+ export type ComponentNameResolver = ( exp : ts . Symbol , source : ts . SourceFile ) => string | undefined | null | false ;
45
+
44
46
export interface ParserOptions {
45
47
propFilter ?: StaticPropFilter | PropFilter ;
48
+ componentNameResolver ?: ComponentNameResolver ;
46
49
}
47
50
48
51
export interface StaticPropFilter {
@@ -166,7 +169,8 @@ class Parser {
166
169
167
170
public getComponentInfo (
168
171
exp : ts . Symbol ,
169
- source : ts . SourceFile
172
+ source : ts . SourceFile ,
173
+ componentNameResolver : ComponentNameResolver = ( ) => undefined
170
174
) : ComponentDoc | null {
171
175
if ( ! ! exp . declarations && exp . declarations . length === 0 ) {
172
176
return null ;
@@ -204,7 +208,8 @@ class Parser {
204
208
this . extractPropsFromTypeIfStatefulComponent ( type ) ;
205
209
206
210
if ( propsType ) {
207
- const componentName = computeComponentName ( exp , source ) ;
211
+ const resolvedComponentName = componentNameResolver ( exp , source ) ;
212
+ const componentName = resolvedComponentName || computeComponentName ( exp , source ) ;
208
213
const defaultProps = this . extractDefaultPropsFromComponent ( exp , source ) ;
209
214
const props = this . getPropsInfo ( propsType , defaultProps ) ;
210
215
@@ -665,18 +670,21 @@ function computeComponentName(exp: ts.Symbol, source: ts.SourceFile) {
665
670
if (
666
671
exportName === 'default' ||
667
672
exportName === '__function' ||
668
- exportName === 'StyledComponentClass' ||
669
673
exportName === 'StatelessComponent'
670
674
) {
671
- // Default export for a file: named after file
675
+ return getDefaultExportForFile ( source ) ;
676
+ } else {
677
+ return exportName ;
678
+ }
679
+ }
680
+
681
+ // Default export for a file: named after file
682
+ export function getDefaultExportForFile ( source : ts . SourceFile ) {
672
683
const name = path . basename ( source . fileName , path . extname ( source . fileName ) ) ;
673
684
674
685
return name === 'index'
675
686
? path . basename ( path . dirname ( source . fileName ) )
676
687
: name ;
677
- } else {
678
- return exportName ;
679
- }
680
688
}
681
689
682
690
function getParentType ( prop : ts . Symbol ) : ParentType | undefined {
@@ -746,7 +754,7 @@ function parseWithProgramProvider(
746
754
docs ,
747
755
checker
748
756
. getExportsOfModule ( moduleSymbol )
749
- . map ( exp => parser . getComponentInfo ( exp , sourceFile ) )
757
+ . map ( exp => parser . getComponentInfo ( exp , sourceFile , parserOpts . componentNameResolver ) )
750
758
. filter ( ( comp ) : comp is ComponentDoc => comp !== null )
751
759
. filter ( ( comp , index , comps ) =>
752
760
comps
0 commit comments