@@ -102,7 +102,7 @@ use oxc_syntax::{
102
102
} ;
103
103
use oxc_traverse:: { Ancestor , BoundIdentifier , Traverse , TraverseCtx } ;
104
104
105
- use crate :: EnvOptions ;
105
+ use crate :: { utils :: ast_builder :: wrap_arrow_function_iife , EnvOptions } ;
106
106
107
107
type FxIndexMap < K , V > = IndexMap < K , V , FxBuildHasher > ;
108
108
@@ -419,12 +419,7 @@ impl<'a> Traverse<'a> for ArrowFunctionConverter<'a> {
419
419
// prop = (() => { return async () => {} })();
420
420
// }
421
421
// ```
422
- Some ( Self :: wrap_arrow_function_with_iife (
423
- arrow. span ,
424
- arrow. scope_id ( ) ,
425
- expr,
426
- ctx,
427
- ) )
422
+ Some ( wrap_arrow_function_iife ( expr, ctx) )
428
423
} else {
429
424
return ;
430
425
}
@@ -1207,43 +1202,6 @@ impl<'a> ArrowFunctionConverter<'a> {
1207
1202
1208
1203
statements. insert ( 0 , stmt) ;
1209
1204
}
1210
-
1211
- /// Wrap an arrow function with IIFE
1212
- ///
1213
- /// `() => {}` -> `(() => { return () => {}; })()`
1214
- fn wrap_arrow_function_with_iife (
1215
- span : Span ,
1216
- scope_id : ScopeId ,
1217
- expr : & mut Expression < ' a > ,
1218
- ctx : & mut TraverseCtx < ' a > ,
1219
- ) -> Expression < ' a > {
1220
- let kind = FormalParameterKind :: ArrowFormalParameters ;
1221
- let params = ctx. ast . formal_parameters ( SPAN , kind, ctx. ast . vec ( ) , NONE ) ;
1222
- let statement = ctx. ast . statement_return ( SPAN , Some ( ctx. ast . move_expression ( expr) ) ) ;
1223
- let statements = ctx. ast . vec1 ( statement) ;
1224
- let body = ctx. ast . function_body ( SPAN , ctx. ast . vec ( ) , statements) ;
1225
- let parent_scope_id = ctx
1226
- . create_child_scope ( ctx. current_scope_id ( ) , ScopeFlags :: Arrow | ScopeFlags :: Function ) ;
1227
- ctx. scopes_mut ( ) . change_parent_id ( scope_id, Some ( parent_scope_id) ) ;
1228
- let arrow = ctx. ast . alloc_arrow_function_expression_with_scope_id (
1229
- SPAN ,
1230
- false ,
1231
- false ,
1232
- NONE ,
1233
- params,
1234
- NONE ,
1235
- body,
1236
- parent_scope_id,
1237
- ) ;
1238
- // IIFE
1239
- ctx. ast . expression_call (
1240
- span,
1241
- Expression :: ArrowFunctionExpression ( arrow) ,
1242
- NONE ,
1243
- ctx. ast . vec ( ) ,
1244
- false ,
1245
- )
1246
- }
1247
1205
}
1248
1206
1249
1207
/// Visitor for inserting `this` after `super` in constructor body.
0 commit comments