File tree Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,11 @@ use swc_core::ecma::ast::{
11
11
ImportNamedSpecifier ,
12
12
ModuleItem ,
13
13
ModuleDecl ,
14
+ CallExpr ,
15
+ Callee ,
16
+ Expr ,
17
+ Stmt ,
18
+ ExprStmt ,
14
19
} ;
15
20
use swc_core:: ecma:: visit:: {
16
21
as_folder,
@@ -71,6 +76,44 @@ impl VisitMut for TransformVisitor {
71
76
}
72
77
} ) ;
73
78
}
79
+
80
+ fn visit_mut_call_expr ( & mut self , n : & mut CallExpr ) {
81
+ if self . target_variables . is_empty ( ) {
82
+ n. visit_mut_children_with ( self ) ;
83
+ return ;
84
+ }
85
+ let matched = match n. callee {
86
+ Callee :: Expr ( ref expr) => {
87
+ match expr. as_ref ( ) {
88
+ Expr :: Ident ( ref ident) => self . target_variables . contains ( & ident. to_id ( ) ) ,
89
+ _ => false
90
+ }
91
+ } ,
92
+ _ => false
93
+ } ;
94
+ if matched {
95
+ n. take ( ) ;
96
+ } else {
97
+ n. visit_mut_children_with ( self ) ;
98
+ }
99
+ }
100
+
101
+ fn visit_mut_stmt ( & mut self , n : & mut Stmt ) {
102
+ n. visit_mut_children_with ( self ) ;
103
+ match n {
104
+ Stmt :: Expr ( ExprStmt { expr, ..} ) => {
105
+ match expr. as_ref ( ) {
106
+ Expr :: Call ( call_expr) => {
107
+ if * call_expr == CallExpr :: dummy ( ) {
108
+ n. take ( ) ;
109
+ }
110
+ } ,
111
+ _ => { }
112
+ }
113
+ } ,
114
+ _ => { }
115
+ }
116
+ }
74
117
}
75
118
76
119
/// An example plugin function with macro support.
Original file line number Diff line number Diff line change 1
1
const foo = 1 ;
2
2
const bar = 2 ;
3
+ ;
You can’t perform that action at this time.
0 commit comments