@@ -25,7 +25,11 @@ function getDefaultValue(declaration: ts.Declaration) {
2525 return declaration . initializer . getText ( ) ;
2626}
2727
28- export default function extractDocumentation ( sourceFile : ts . SourceFile , checker : ts . TypeChecker ) : Array < TestUtilsDoc > {
28+ export default function extractDocumentation (
29+ sourceFile : ts . SourceFile ,
30+ checker : ts . TypeChecker ,
31+ extraExports : Array < string >
32+ ) : Array < TestUtilsDoc > {
2933 const moduleSymbol = checker . getSymbolAtLocation ( sourceFile ) ;
3034 if ( ! moduleSymbol ) {
3135 throw new Error ( `Unable to resolve module: ${ sourceFile . fileName } ` ) ;
@@ -35,14 +39,21 @@ export default function extractDocumentation(sourceFile: ts.SourceFile, checker:
3539 const definitions : Array < TestUtilsDoc > = [ ] ;
3640
3741 for ( const symbol of exportSymbols ) {
42+ const className = symbol . getName ( ) ;
43+ if ( extraExports . includes ( className ) ) {
44+ continue ;
45+ }
3846 if ( ! ( symbol . flags & ts . SymbolFlags . Class ) ) {
3947 throw new Error ( `Exported symbol is not a class, got ${ checker . symbolToString ( symbol ) } ` ) ;
4048 }
41- const className = symbol . getName ( ) ;
49+
4250 const classType = checker . getTypeAtLocation ( extractDeclaration ( symbol ) ) ;
4351 const classDefinition : TestUtilsDoc = { name : className , methods : [ ] } ;
4452 for ( const property of classType . getProperties ( ) ) {
45- const declaration = extractDeclaration ( property ) ;
53+ const declaration = property . valueDeclaration ;
54+ if ( ! declaration ) {
55+ throw new Error ( `Unexpected member on ${ className } – ${ property . getName ( ) } ` ) ;
56+ }
4657 const modifiers = ( ts . canHaveModifiers ( declaration ) && ts . getModifiers ( declaration ) ) || [ ] ;
4758 if (
4859 modifiers . find (
@@ -52,26 +63,25 @@ export default function extractDocumentation(sourceFile: ts.SourceFile, checker:
5263 continue ;
5364 }
5465 const type = checker . getTypeAtLocation ( declaration ) ;
55- if ( type . getCallSignatures ( ) . length !== 1 ) {
56- throw new Error ( `Unexpected member on ${ className } – ${ property . getName ( ) } : ${ stringifyType ( type , checker ) } ` ) ;
66+ for ( const signature of type . getCallSignatures ( ) ) {
67+ // report each function signature as a separate method
68+ classDefinition . methods . push ( {
69+ name : property . getName ( ) ,
70+ description : getDescription ( property . getDocumentationComment ( checker ) , declaration ) . text ,
71+ returnType : { name : stringifyType ( signature . getReturnType ( ) , checker ) } ,
72+ parameters : signature . parameters . map ( parameter => {
73+ const paramType = checker . getTypeAtLocation ( extractDeclaration ( parameter ) ) ;
74+ return {
75+ name : parameter . name ,
76+ typeName : stringifyType ( paramType , checker ) ,
77+ description : getDescription ( parameter . getDocumentationComment ( checker ) , declaration ) . text ,
78+ flags : { isOptional : isOptional ( paramType ) } ,
79+ defaultValue : getDefaultValue ( extractDeclaration ( parameter ) ) ,
80+ } ;
81+ } ) ,
82+ inheritedFrom : getInheritedFrom ( declaration , className ) ,
83+ } ) ;
5784 }
58- const returnType = type . getCallSignatures ( ) [ 0 ] . getReturnType ( ) ;
59- classDefinition . methods . push ( {
60- name : property . getName ( ) ,
61- description : getDescription ( property . getDocumentationComment ( checker ) , declaration ) . text ,
62- inheritedFrom : getInheritedFrom ( declaration , className ) ,
63- parameters : type . getCallSignatures ( ) [ 0 ] . parameters . map ( parameter => {
64- const paramType = checker . getTypeAtLocation ( extractDeclaration ( parameter ) ) ;
65- return {
66- name : parameter . name ,
67- typeName : stringifyType ( paramType , checker ) ,
68- description : getDescription ( parameter . getDocumentationComment ( checker ) , declaration ) . text ,
69- flags : { isOptional : isOptional ( paramType ) } ,
70- defaultValue : getDefaultValue ( extractDeclaration ( parameter ) ) ,
71- } ;
72- } ) ,
73- returnType : { name : stringifyType ( returnType , checker ) } ,
74- } ) ;
7585 }
7686 classDefinition . methods . sort ( ( a , b ) => a . name . localeCompare ( b . name ) ) ;
7787
0 commit comments