Skip to content

Commit 38dcd1d

Browse files
committed
fix: 修复export default 没有包裹combine
1 parent b8bc0f4 commit 38dcd1d

File tree

1 file changed

+40
-33
lines changed

1 file changed

+40
-33
lines changed

src/visitor.rs

Lines changed: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,7 @@ impl ModuleMutVisitor {
515515
type_args: None,
516516
})))
517517
} else {
518+
// 高阶函数 return () => jsx
518519
match &mut **expr_in_box {
519520
// export const Index = () => {}
520521
Expr::Arrow(ArrowExpr { body, .. }) => {
@@ -575,6 +576,40 @@ impl ModuleMutVisitor {
575576
fn enable_nesting_for_call_expr (&self, call: &mut CallExpr) {
576577
call.visit_mut_with(&mut &mut self.get_nesting_visitor());
577578
}
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+
}
578613
}
579614

580615
impl VisitMut for ModuleMutVisitor {
@@ -673,6 +708,9 @@ impl VisitMut for ModuleMutVisitor {
673708
_ => ()
674709
}
675710
},
711+
ModuleItem::ModuleDecl(ModuleDecl::ExportDefaultExpr(ExportDefaultExpr { span: _, expr })) => {
712+
self.enable_nesting_for_expr(&mut **expr)
713+
},
676714
ModuleItem::ModuleDecl(ModuleDecl::ExportDecl(ExportDecl { decl, .. })) => {
677715
match decl {
678716
// export class Index {}
@@ -688,21 +726,7 @@ impl VisitMut for ModuleMutVisitor {
688726
var_decl.decls.iter_mut().for_each(|decl| {
689727
match &mut decl.init {
690728
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);
706730
},
707731
None => ()
708732
}
@@ -723,24 +747,7 @@ impl VisitMut for ModuleMutVisitor {
723747
var_decl.decls.iter_mut().for_each(|decl| {
724748
match &mut decl.init {
725749
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);
744751
},
745752
None => (),
746753
}

0 commit comments

Comments
 (0)