@@ -48,7 +48,7 @@ export function createTypings(moduleName: string|null, programAst: any, options:
4848 const m = dom . create . module ( moduleName || 'moduleName' ) ;
4949
5050 if ( hasReactClass ( ast , reactComponentName ) ) {
51- m . members . push ( dom . create . importNamed ( 'Component' , reactImport ) ) ;
51+ m . members . push ( dom . create . importNamed ( reactComponentName || 'Component' , reactImport ) ) ;
5252 } else {
5353 tripleSlashDirectives . push ( dom . create . tripleSlashReferenceTypesDirective ( 'react' ) ) ;
5454 }
@@ -95,19 +95,29 @@ function createExportedTypes(m: dom.ModuleDeclaration, ast: AstQuery, componentN
9595 }
9696
9797 if ( classComponent ) {
98- const classDecl = dom . create . class ( componentName ) ;
99- classDecl . baseType = dom . create . interface ( `Component<${ interf . name } , any>` ) ;
100- classDecl . flags = exportType ;
101- classDecl . members . push ( dom . create . method ( 'render' , [ ] , dom . create . namedTypeReference ( 'JSX.Element' ) ) ) ;
102- m . members . push ( classDecl ) ;
98+ createExportedClassComponent ( m , componentName , reactComponentName , exportType , interf ) ;
10399 } else {
104- const funcDelc = dom . create . function ( componentName , propTypes ? [ dom . create . parameter ( 'props' , interf ) ] : [ ] ,
105- dom . create . namedTypeReference ( 'JSX.Element' ) ) ;
106- funcDelc . flags = exportType ;
107- m . members . push ( funcDelc ) ;
100+ createExportedFunctionalComponent ( m , componentName , propTypes , exportType , interf ) ;
108101 }
109102}
110103
104+ function createExportedClassComponent ( m : dom . ModuleDeclaration , componentName : string ,
105+ reactComponentName : string | undefined , exportType : dom . DeclarationFlags , interf : dom . InterfaceDeclaration ) : void {
106+ const classDecl = dom . create . class ( componentName ) ;
107+ classDecl . baseType = dom . create . interface ( `${ reactComponentName || 'Component' } <${ interf . name } , any>` ) ;
108+ classDecl . flags = exportType ;
109+ classDecl . members . push ( dom . create . method ( 'render' , [ ] , dom . create . namedTypeReference ( 'JSX.Element' ) ) ) ;
110+ m . members . push ( classDecl ) ;
111+ }
112+
113+ function createExportedFunctionalComponent ( m : dom . ModuleDeclaration , componentName : string , propTypes : any ,
114+ exportType : dom . DeclarationFlags , interf : dom . InterfaceDeclaration ) : void {
115+ const funcDelc = dom . create . function ( componentName , propTypes ? [ dom . create . parameter ( 'props' , interf ) ] : [ ] ,
116+ dom . create . namedTypeReference ( 'JSX.Element' ) ) ;
117+ funcDelc . flags = exportType ;
118+ m . members . push ( funcDelc ) ;
119+ }
120+
111121function createPropTypeTypings ( interf : dom . InterfaceDeclaration , ast : AstQuery , propTypes : any ,
112122 importedPropTypes : ImportedPropTypes , options : IOptions ) : void {
113123 const res = ast . querySubtree ( propTypes , `
@@ -209,7 +219,7 @@ function getReactComponentName(ast: AstQuery): string|undefined {
209219 /:source StringLiteral[@value == 'react']
210220 ]
211221 /:specifiers *[
212- / Identifier[@name == 'Component']
222+ / Identifier[@name == 'Component'] || / Identifier[@name == 'PureComponent']
213223 ]
214224 /:local Identifier
215225 ` ) ;
0 commit comments