@@ -15,7 +15,7 @@ use swc_core::{
1515 PropName , PropOrSpread , Stmt , Str , Tpl , UnaryExpr , UnaryOp ,
1616 } ,
1717 utils:: { private_ident, quote_ident, ExprFactory } ,
18- visit:: { fold_pass , Fold , FoldWith , VisitMut , VisitMutWith } ,
18+ visit:: { visit_mut_pass , VisitMut , VisitMutWith } ,
1919 } ,
2020 quote,
2121} ;
@@ -34,7 +34,7 @@ pub fn next_dynamic(
3434 filename : Arc < FileName > ,
3535 pages_or_app_dir : Option < PathBuf > ,
3636) -> impl Pass {
37- fold_pass ( NextDynamicPatcher {
37+ visit_mut_pass ( NextDynamicPatcher {
3838 is_development,
3939 is_server_compiler,
4040 is_react_server_layer,
@@ -117,33 +117,24 @@ enum TurbopackImport {
117117 } ,
118118}
119119
120- impl Fold for NextDynamicPatcher {
121- fn fold_module_items ( & mut self , mut items : Vec < ModuleItem > ) -> Vec < ModuleItem > {
122- items = items . fold_children_with ( self ) ;
120+ impl VisitMut for NextDynamicPatcher {
121+ fn visit_mut_module_items ( & mut self , items : & mut Vec < ModuleItem > ) {
122+ items. visit_mut_children_with ( self ) ;
123123
124- self . maybe_add_dynamically_imported_specifier ( & mut items) ;
125-
126- items
124+ self . maybe_add_dynamically_imported_specifier ( items) ;
127125 }
128126
129- fn fold_import_decl ( & mut self , decl : ImportDecl ) -> ImportDecl {
130- let ImportDecl {
131- ref src,
132- ref specifiers,
133- ..
134- } = decl;
135- if & src. value == "next/dynamic" {
136- for specifier in specifiers {
127+ fn visit_mut_import_decl ( & mut self , decl : & mut ImportDecl ) {
128+ if & decl. src . value == "next/dynamic" {
129+ for specifier in & decl. specifiers {
137130 if let ImportSpecifier :: Default ( default_specifier) = specifier {
138131 self . dynamic_bindings . push ( default_specifier. local . to_id ( ) ) ;
139132 }
140133 }
141134 }
142-
143- decl
144135 }
145136
146- fn fold_call_expr ( & mut self , expr : CallExpr ) -> CallExpr {
137+ fn visit_mut_call_expr ( & mut self , expr : & mut CallExpr ) {
147138 if self . is_next_dynamic_first_arg {
148139 if let Callee :: Import ( ..) = & expr. callee {
149140 match & * expr. args [ 0 ] . expr {
@@ -157,9 +148,12 @@ impl Fold for NextDynamicPatcher {
157148 _ => { }
158149 }
159150 }
160- return expr. fold_children_with ( self ) ;
151+ expr. visit_mut_children_with ( self ) ;
152+ return ;
161153 }
162- let mut expr = expr. fold_children_with ( self ) ;
154+
155+ expr. visit_mut_children_with ( self ) ;
156+
163157 if let Callee :: Expr ( i) = & expr. callee {
164158 if let Expr :: Ident ( identifier) = & * * i {
165159 if self . dynamic_bindings . contains ( & identifier. to_id ( ) ) {
@@ -172,7 +166,7 @@ impl Fold for NextDynamicPatcher {
172166 )
173167 . emit ( )
174168 } ) ;
175- return expr ;
169+ return ;
176170 } else if expr. args . len ( ) > 2 {
177171 HANDLER . with ( |handler| {
178172 handler
@@ -182,7 +176,7 @@ impl Fold for NextDynamicPatcher {
182176 )
183177 . emit ( )
184178 } ) ;
185- return expr ;
179+ return ;
186180 }
187181 if expr. args . len ( ) == 2 {
188182 match & * expr. args [ 1 ] . expr {
@@ -196,19 +190,19 @@ impl Fold for NextDynamicPatcher {
196190 )
197191 . emit ( ) ;
198192 } ) ;
199- return expr ;
193+ return ;
200194 }
201195 }
202196 }
203197
204198 self . is_next_dynamic_first_arg = true ;
205- expr. args [ 0 ] . expr = expr . args [ 0 ] . expr . clone ( ) . fold_with ( self ) ;
199+ expr. args [ 0 ] . expr . visit_mut_with ( self ) ;
206200 self . is_next_dynamic_first_arg = false ;
207201
208202 let Some ( ( dynamically_imported_specifier, dynamically_imported_specifier_span) ) =
209203 self . dynamically_imported_specifier . take ( )
210204 else {
211- return expr ;
205+ return ;
212206 } ;
213207
214208 let project_dir = match self . pages_or_app_dir . as_deref ( ) {
@@ -419,7 +413,6 @@ impl Fold for NextDynamicPatcher {
419413 }
420414 }
421415 }
422- expr
423416 }
424417}
425418
0 commit comments