@@ -515,6 +515,7 @@ impl ModuleMutVisitor {
515
515
type_args : None ,
516
516
} ) ) )
517
517
} else {
518
+ // 高阶函数 return () => jsx
518
519
match & mut * * expr_in_box {
519
520
// export const Index = () => {}
520
521
Expr :: Arrow ( ArrowExpr { body, .. } ) => {
@@ -575,6 +576,40 @@ impl ModuleMutVisitor {
575
576
fn enable_nesting_for_call_expr ( & self , call : & mut CallExpr ) {
576
577
call. visit_mut_with ( & mut & mut self . get_nesting_visitor ( ) ) ;
577
578
}
579
+ fn enable_nesting_for_expr ( & self , expr : & mut Expr ) {
580
+ match expr {
581
+ // export default () => {}
582
+ Expr :: Arrow ( ArrowExpr { body, .. } ) => {
583
+ self . enable_nesting_for_arrow_function ( body) ;
584
+ } ,
585
+ // export default withXxxx(() => {})
586
+ Expr :: Call ( call) => {
587
+ self . enable_nesting_for_call_expr ( call) ;
588
+ } ,
589
+ Expr :: Fn ( FnExpr { function, .. } ) => {
590
+ // export default function () {}
591
+ self . enable_nesting_for_function ( function) ;
592
+ } ,
593
+ Expr :: Paren ( ParenExpr { expr, .. } ) => {
594
+ match & mut * * expr {
595
+ // export default (() => {})()
596
+ Expr :: Arrow ( ArrowExpr { body, .. } ) => {
597
+ self . enable_nesting_for_arrow_function ( body) ;
598
+ } ,
599
+ // export default withXxxx(() => {})()
600
+ Expr :: Call ( call) => {
601
+ self . enable_nesting_for_call_expr ( call) ;
602
+ } ,
603
+ Expr :: Fn ( FnExpr { function, .. } ) => {
604
+ // export default function () {}
605
+ self . enable_nesting_for_function ( function) ;
606
+ } ,
607
+ _ => ( )
608
+ }
609
+ } ,
610
+ _ => ( )
611
+ } ;
612
+ }
578
613
}
579
614
580
615
impl VisitMut for ModuleMutVisitor {
@@ -673,6 +708,9 @@ impl VisitMut for ModuleMutVisitor {
673
708
_ => ( )
674
709
}
675
710
} ,
711
+ ModuleItem :: ModuleDecl ( ModuleDecl :: ExportDefaultExpr ( ExportDefaultExpr { span : _, expr } ) ) => {
712
+ self . enable_nesting_for_expr ( & mut * * expr)
713
+ } ,
676
714
ModuleItem :: ModuleDecl ( ModuleDecl :: ExportDecl ( ExportDecl { decl, .. } ) ) => {
677
715
match decl {
678
716
// export class Index {}
@@ -688,21 +726,7 @@ impl VisitMut for ModuleMutVisitor {
688
726
var_decl. decls . iter_mut ( ) . for_each ( |decl| {
689
727
match & mut decl. init {
690
728
Some ( init) => {
691
- match & mut * * init {
692
- // export const Index = () => {}
693
- Expr :: Arrow ( ArrowExpr { body, .. } ) => {
694
- self . enable_nesting_for_arrow_function ( body) ;
695
- } ,
696
- // export const Index = withXxxx(() => {})
697
- Expr :: Call ( call) => {
698
- self . enable_nesting_for_call_expr ( call) ;
699
- } ,
700
- // export const Index = function() {}
701
- Expr :: Fn ( FnExpr { function, .. } ) => {
702
- self . enable_nesting_for_function ( function) ;
703
- } ,
704
- _ => ( )
705
- }
729
+ self . enable_nesting_for_expr ( & mut * * init) ;
706
730
} ,
707
731
None => ( )
708
732
}
@@ -723,24 +747,7 @@ impl VisitMut for ModuleMutVisitor {
723
747
var_decl. decls . iter_mut ( ) . for_each ( |decl| {
724
748
match & mut decl. init {
725
749
Some ( init) => {
726
- match & mut * * init {
727
- Expr :: Fn ( FnExpr { function, .. } ) => {
728
- // const Index = function () {}
729
- self . enable_nesting_for_function ( function) ;
730
- } ,
731
- Expr :: Arrow ( ArrowExpr { body, .. } ) => {
732
- // const Index = () => {}
733
- self . enable_nesting_for_arrow_function ( body) ;
734
- } ,
735
- Expr :: Call ( call) => {
736
- // const Index = withStyle()(() => {})
737
- self . enable_nesting_for_call_expr ( call) ;
738
- } ,
739
- _ => { }
740
- // expr => {
741
- // self.enable_nesting_for_expr(expr)
742
- // }
743
- }
750
+ self . enable_nesting_for_expr ( & mut * * init) ;
744
751
} ,
745
752
None => ( ) ,
746
753
}
0 commit comments