@@ -22,7 +22,7 @@ export function createTypings(moduleName: string|null, ast: any,
2222 }
2323 if ( importStatements . length > 0 ) {
2424 importStatements . forEach ( importStatement => {
25- if ( importStatement . name == undefined ) {
25+ if ( importStatement . name === undefined ) {
2626 m . members . push ( dom . create . importDefault ( importStatement . local , importStatement . path ) ) ;
2727 } else {
2828 throw new Error ( 'Named imports are currently unsupported' ) ;
@@ -34,28 +34,7 @@ export function createTypings(moduleName: string|null, ast: any,
3434 const propTypes = getPropTypesFromAssignment ( astq , ast , componentName ) ||
3535 getPropTypesFromStaticAttribute ( astq , ast , componentName ) ;
3636 if ( exportType ) {
37- const classComponent = isClassComponent ( astq , ast , componentName , reactComponentName ) ;
38-
39- const interf = dom . create . interface ( `${ componentName } Props` ) ;
40- interf . flags = dom . DeclarationFlags . Export ;
41- if ( propTypes ) {
42- createPropTypeTypings ( interf , astq , propTypes , propTypesName ) ;
43- }
44- if ( propTypes || classComponent ) {
45- m . members . push ( interf ) ;
46- }
47-
48- if ( classComponent ) {
49- const classDecl = dom . create . class ( componentName ) ;
50- classDecl . baseType = dom . create . interface ( `React.Component<${ interf . name } , any>` ) ;
51- classDecl . flags = exportType ;
52- m . members . push ( classDecl ) ;
53- } else {
54- const funcDelc = dom . create . function ( componentName , propTypes ? [ dom . create . parameter ( 'props' , interf ) ] : [ ] ,
55- dom . create . namedTypeReference ( 'JSX.Element' ) ) ;
56- funcDelc . flags = exportType ;
57- m . members . push ( funcDelc ) ;
58- }
37+ createExportedTypes ( m , astq , ast , componentName , reactComponentName , propTypes , propTypesName , exportType ) ;
5938 }
6039 } ) ;
6140
@@ -68,6 +47,33 @@ export function createTypings(moduleName: string|null, ast: any,
6847 }
6948} ;
7049
50+ function createExportedTypes ( m : dom . ModuleDeclaration , astq : ASTQ , ast : any , componentName : string ,
51+ reactComponentName : string | undefined , propTypes : any , propTypesName : string | undefined ,
52+ exportType : dom . DeclarationFlags ) : void {
53+ const classComponent = isClassComponent ( astq , ast , componentName , reactComponentName ) ;
54+
55+ const interf = dom . create . interface ( `${ componentName } Props` ) ;
56+ interf . flags = dom . DeclarationFlags . Export ;
57+ if ( propTypes ) {
58+ createPropTypeTypings ( interf , astq , propTypes , propTypesName ) ;
59+ }
60+ if ( propTypes || classComponent ) {
61+ m . members . push ( interf ) ;
62+ }
63+
64+ if ( classComponent ) {
65+ const classDecl = dom . create . class ( componentName ) ;
66+ classDecl . baseType = dom . create . interface ( `React.Component<${ interf . name } , any>` ) ;
67+ classDecl . flags = exportType ;
68+ m . members . push ( classDecl ) ;
69+ } else {
70+ const funcDelc = dom . create . function ( componentName , propTypes ? [ dom . create . parameter ( 'props' , interf ) ] : [ ] ,
71+ dom . create . namedTypeReference ( 'JSX.Element' ) ) ;
72+ funcDelc . flags = exportType ;
73+ m . members . push ( funcDelc ) ;
74+ }
75+ }
76+
7177function createPropTypeTypings ( interf : dom . InterfaceDeclaration , astq : ASTQ , propTypes : any ,
7278 propTypesName : string | undefined ) : void {
7379 const res = astq . query ( propTypes , `
0 commit comments