@@ -460,49 +460,41 @@ function getReferencedPropTypesComponentName(ast: AstQuery, propTypes: any|undef
460
460
}
461
461
462
462
function getComponentExportType ( ast : AstQuery , componentName : string ) : dom . DeclarationFlags | undefined {
463
- if ( componentName === '' ) {
464
- // case: unnamed default export
465
- const res = ast . query ( `
466
- // ExportDefaultDeclaration[
467
- // ClassDeclaration
468
- ||
469
- // FunctionDeclaration
470
- ]
471
- ` ) ;
472
- if ( res . length > 0 && ! res [ 0 ] . id ) {
473
- return dom . DeclarationFlags . ExportDefault ;
474
- }
475
- }
476
- let res = ast . query ( `
477
- // ExportDefaultDeclaration[
478
- // ClassDeclaration
479
- /:id Identifier[@name == '${ componentName } ']
480
- ||
481
- // FunctionDeclaration
482
- /:id Identifier[@name == '${ componentName } ']
483
- ||
484
- // VariableDeclaration
485
- / VariableDeclarator
486
- /:id Identifier[@name == '${ componentName } ']
487
- ||
488
- /Identifier[@name == '${ componentName } ']
489
- ]
490
- ,
491
- // AssignmentExpression[
492
- /:left MemberExpression[
493
- /:object Identifier[@name == 'exports']
494
- &&
495
- /:property Identifier[@name == 'default']
496
- ]
497
- &&
498
- /:right Identifier[@name == '${ componentName } ']
499
- ]
500
- ` ) ;
501
- if ( res . length > 0 ) {
463
+ if ( isDefaultExport ( ast , componentName ) ) {
502
464
return dom . DeclarationFlags . ExportDefault ;
503
465
}
504
- res = ast . query ( `
505
- // ExportNamedDeclaration[
466
+
467
+ if ( isNamedExport ( ast , componentName ) ) {
468
+ return dom . DeclarationFlags . Export ;
469
+ }
470
+
471
+ return undefined ;
472
+ }
473
+
474
+ function isDefaultExport ( ast : AstQuery , componentName : string ) : boolean {
475
+ return isUnnamedDefaultExport ( ast , componentName ) || isNamedDefaultExport ( ast , componentName ) ||
476
+ isNamedExportAsDefault ( ast , componentName ) ;
477
+ }
478
+
479
+ function isUnnamedDefaultExport ( ast : AstQuery , componentName : string ) : boolean {
480
+ if ( componentName !== '' ) {
481
+ return false ;
482
+ }
483
+
484
+ const res = ast . query ( `
485
+ // ExportDefaultDeclaration[
486
+ // ClassDeclaration
487
+ ||
488
+ // FunctionDeclaration
489
+ ]
490
+ ` ) ;
491
+
492
+ return res . length > 0 && ! res [ 0 ] . id ;
493
+ }
494
+
495
+ function isNamedDefaultExport ( ast : AstQuery , componentName : string ) : boolean {
496
+ const res = ast . query ( `
497
+ // ExportDefaultDeclaration[
506
498
// ClassDeclaration
507
499
/:id Identifier[@name == '${ componentName } ']
508
500
||
@@ -513,14 +505,55 @@ function getComponentExportType(ast: AstQuery, componentName: string): dom.Decla
513
505
/ VariableDeclarator
514
506
/:id Identifier[@name == '${ componentName } ']
515
507
||
516
- // ExportSpecifier
517
- /:exported Identifier[@name == '${ componentName } ']
508
+ /Identifier[@name == '${ componentName } ']
509
+ ]
510
+ ,
511
+ // AssignmentExpression[
512
+ /:left MemberExpression[
513
+ /:object Identifier[@name == 'exports']
514
+ &&
515
+ /:property Identifier[@name == 'default']
516
+ ]
517
+ &&
518
+ /:right Identifier[@name == '${ componentName } ']
518
519
]
519
520
` ) ;
520
- if ( res . length > 0 ) {
521
- return dom . DeclarationFlags . Export ;
522
- }
523
- return undefined ;
521
+
522
+ return res . length > 0 ;
523
+ }
524
+
525
+ function isNamedExportAsDefault ( ast : AstQuery , componentName : string ) : boolean {
526
+ const res = ast . query ( `
527
+ // ExportNamedDeclaration[
528
+ // ExportSpecifier [
529
+ /:local Identifier[@name == '${ componentName } '] &&
530
+ /:exported Identifier[@name == 'default']
531
+ ]
532
+ ]
533
+ ` ) ;
534
+
535
+ return res . length > 0 ;
536
+ }
537
+
538
+ function isNamedExport ( ast : AstQuery , componentName : string ) : boolean {
539
+ const res = ast . query ( `
540
+ // ExportNamedDeclaration[
541
+ // ClassDeclaration
542
+ /:id Identifier[@name == '${ componentName } ']
543
+ ||
544
+ // FunctionDeclaration
545
+ /:id Identifier[@name == '${ componentName } ']
546
+ ||
547
+ // VariableDeclaration
548
+ / VariableDeclarator
549
+ /:id Identifier[@name == '${ componentName } ']
550
+ ||
551
+ // ExportSpecifier
552
+ /:exported Identifier[@name == '${ componentName } ']
553
+ ]
554
+ ` ) ;
555
+
556
+ return res . length > 0 ;
524
557
}
525
558
526
559
function isClassComponent ( ast : AstQuery , componentName : string ,
0 commit comments