@@ -82,6 +82,7 @@ function createExportedTypes(m: dom.ModuleDeclaration, ast: AstQuery, componentN
8282 const classDecl = dom . create . class ( componentName ) ;
8383 classDecl . baseType = dom . create . interface ( `Component<${ interf . name } , any>` ) ;
8484 classDecl . flags = exportType ;
85+ classDecl . members . push ( dom . create . method ( 'render' , [ ] , dom . create . namedTypeReference ( 'JSX.Element' ) ) ) ;
8586 m . members . push ( classDecl ) ;
8687 } else {
8788 const funcDelc = dom . create . function ( componentName , propTypes ? [ dom . create . parameter ( 'props' , interf ) ] : [ ] ,
@@ -318,7 +319,7 @@ function getComponentNamesByStaticPropTypeAttribute(ast: AstQuery): string[] {
318319 ]
319320 ` ) ;
320321 if ( res . length > 0 ) {
321- return res . map ( match => match . id . name ) ;
322+ return res . map ( match => match . id ? match . id . name : '' ) ;
322323 }
323324 return [ ] ;
324325}
@@ -337,7 +338,7 @@ function getComponentNamesByJsxInBody(ast: AstQuery): string[] {
337338 ]
338339 ` ) ;
339340 if ( res . length > 0 ) {
340- return res . map ( match => match . id . name ) ;
341+ return res . map ( match => match . id ? match . id . name : '' ) ;
341342 }
342343 return [ ] ;
343344}
@@ -358,6 +359,19 @@ function getPropTypesFromAssignment(ast: AstQuery, componentName: string): any|u
358359}
359360
360361function getPropTypesFromStaticAttribute ( ast : AstQuery , componentName : string ) : any | undefined {
362+ if ( componentName === '' ) {
363+ const res = ast . query ( `
364+ //ClassDeclaration
365+ /:body *
366+ //ClassProperty[
367+ /:key Identifier[@name == 'propTypes']
368+ ]
369+ /:value*
370+ ` ) ;
371+ if ( res . length > 0 && ! res [ 0 ] . id ) {
372+ return res [ 0 ] ;
373+ }
374+ }
361375 const res = ast . query ( `
362376 //ClassDeclaration[
363377 /:id Identifier[@name == '${ componentName } ']
@@ -375,6 +389,19 @@ function getPropTypesFromStaticAttribute(ast: AstQuery, componentName: string):
375389}
376390
377391function getComponentExportType ( ast : AstQuery , componentName : string ) : dom . DeclarationFlags | undefined {
392+ if ( componentName === '' ) {
393+ // case: unnamed default export
394+ const res = ast . query ( `
395+ // ExportDefaultDeclaration[
396+ // ClassDeclaration
397+ ||
398+ // FunctionDeclaration
399+ ]
400+ ` ) ;
401+ if ( res . length > 0 && ! res [ 0 ] . id ) {
402+ return dom . DeclarationFlags . ExportDefault ;
403+ }
404+ }
378405 let res = ast . query ( `
379406 // ExportDefaultDeclaration[
380407 // ClassDeclaration
@@ -424,6 +451,14 @@ function getComponentExportType(ast: AstQuery, componentName: string): dom.Decla
424451
425452function isClassComponent ( ast : AstQuery , componentName : string ,
426453 reactComponentName : string | undefined ) : boolean {
454+ if ( componentName === '' ) {
455+ const res = ast . query ( `
456+ // ClassDeclaration
457+ ` ) ;
458+ if ( res . length > 0 && ! res [ 0 ] . id ) {
459+ return true ;
460+ }
461+ }
427462 const res = ast . query ( `
428463 // ClassDeclaration
429464 /:id Identifier[@name == '${ componentName } ']
0 commit comments