1
1
use swc_core:: ecma:: {
2
- ast:: { Callee , Expr , FnDecl , FnExpr , Pat , Program , ReturnStmt , VarDeclarator } ,
2
+ ast:: { Callee , Expr , FnDecl , FnExpr , Pat , Program , ReturnStmt , Stmt , VarDeclarator } ,
3
3
visit:: { Visit , VisitWith } ,
4
4
} ;
5
5
@@ -34,6 +34,25 @@ impl Visit for Finder {
34
34
node. visit_children_with ( self ) ;
35
35
}
36
36
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
+
37
56
fn visit_fn_decl ( & mut self , node : & FnDecl ) {
38
57
let old = self . is_interested ;
39
58
self . is_interested = node. ident . sym . starts_with ( "use" )
@@ -47,7 +66,7 @@ impl Visit for Finder {
47
66
fn visit_fn_expr ( & mut self , node : & FnExpr ) {
48
67
let old = self . is_interested ;
49
68
50
- self . is_interested = node. ident . as_ref ( ) . is_some_and ( |ident| {
69
+ self . is_interested | = node. ident . as_ref ( ) . is_some_and ( |ident| {
51
70
ident. sym . starts_with ( "use" ) || ident. sym . starts_with ( |c : char | c. is_ascii_uppercase ( ) )
52
71
} ) ;
53
72
@@ -69,6 +88,13 @@ impl Visit for Finder {
69
88
node. visit_children_with ( self ) ;
70
89
}
71
90
91
+ fn visit_stmt ( & mut self , node : & Stmt ) {
92
+ if self . found {
93
+ return ;
94
+ }
95
+ node. visit_children_with ( self ) ;
96
+ }
97
+
72
98
fn visit_var_declarator ( & mut self , node : & VarDeclarator ) {
73
99
let old = self . is_interested ;
74
100
0 commit comments