11use swc_core:: ecma:: {
2- ast:: { Callee , Expr , FnDecl , FnExpr , Pat , Program , ReturnStmt , VarDeclarator } ,
2+ ast:: { Callee , Expr , FnDecl , FnExpr , Pat , Program , ReturnStmt , Stmt , VarDeclarator } ,
33 visit:: { Visit , VisitWith } ,
44} ;
55
@@ -34,6 +34,25 @@ impl Visit for Finder {
3434 node. visit_children_with ( self ) ;
3535 }
3636
37+ fn visit_expr ( & mut self , node : & Expr ) {
38+ if self . found {
39+ return ;
40+ }
41+ if matches ! (
42+ node,
43+ Expr :: JSXMember ( ..)
44+ | Expr :: JSXNamespacedName ( ..)
45+ | Expr :: JSXEmpty ( ..)
46+ | Expr :: JSXElement ( ..)
47+ | Expr :: JSXFragment ( ..)
48+ ) {
49+ self . found = true ;
50+ return ;
51+ }
52+
53+ node. visit_children_with ( self ) ;
54+ }
55+
3756 fn visit_fn_decl ( & mut self , node : & FnDecl ) {
3857 let old = self . is_interested ;
3958 self . is_interested = node. ident . sym . starts_with ( "use" )
@@ -47,7 +66,7 @@ impl Visit for Finder {
4766 fn visit_fn_expr ( & mut self , node : & FnExpr ) {
4867 let old = self . is_interested ;
4968
50- self . is_interested = node. ident . as_ref ( ) . is_some_and ( |ident| {
69+ self . is_interested | = node. ident . as_ref ( ) . is_some_and ( |ident| {
5170 ident. sym . starts_with ( "use" ) || ident. sym . starts_with ( |c : char | c. is_ascii_uppercase ( ) )
5271 } ) ;
5372
@@ -69,6 +88,13 @@ impl Visit for Finder {
6988 node. visit_children_with ( self ) ;
7089 }
7190
91+ fn visit_stmt ( & mut self , node : & Stmt ) {
92+ if self . found {
93+ return ;
94+ }
95+ node. visit_children_with ( self ) ;
96+ }
97+
7298 fn visit_var_declarator ( & mut self , node : & VarDeclarator ) {
7399 let old = self . is_interested ;
74100
0 commit comments