@@ -51,11 +51,10 @@ use std::mem;
51
51
52
52
use oxc_allocator:: CloneIn ;
53
53
use oxc_ast:: { ast:: * , NONE } ;
54
- use oxc_semantic:: ScopeFlags ;
55
54
use oxc_span:: SPAN ;
56
55
use oxc_traverse:: { Ancestor , BoundIdentifier , MaybeBoundIdentifier , Traverse , TraverseCtx } ;
57
56
58
- use crate :: TransformCtx ;
57
+ use crate :: { utils :: ast_builder :: wrap_arrow_function_iife , TransformCtx } ;
59
58
60
59
#[ derive( Debug ) ]
61
60
enum CallContext < ' a > {
@@ -243,34 +242,6 @@ impl<'a> OptionalChaining<'a, '_> {
243
242
ctx. ast . expression_conditional ( SPAN , test, consequent, alternate)
244
243
}
245
244
246
- /// Wrap the expression with an arrow function
247
- ///
248
- /// `expr` -> `(() => { return expr; })()`
249
- fn wrap_arrow_function_iife (
250
- expr : & mut Expression < ' a > ,
251
- ctx : & mut TraverseCtx < ' a > ,
252
- ) -> Expression < ' a > {
253
- let scope_id =
254
- ctx. insert_scope_below_expression ( expr, ScopeFlags :: Arrow | ScopeFlags :: Function ) ;
255
-
256
- let kind = FormalParameterKind :: ArrowFormalParameters ;
257
- let params = ctx. ast . formal_parameters ( SPAN , kind, ctx. ast . vec ( ) , NONE ) ;
258
- let statements =
259
- ctx. ast . vec1 ( ctx. ast . statement_return ( SPAN , Some ( ctx. ast . move_expression ( expr) ) ) ) ;
260
- let body = ctx. ast . function_body ( SPAN , ctx. ast . vec ( ) , statements) ;
261
- let arrow = ctx. ast . alloc_arrow_function_expression_with_scope_id (
262
- SPAN , false , false , NONE , params, NONE , body, scope_id,
263
- ) ;
264
- // IIFE
265
- ctx. ast . expression_call (
266
- SPAN ,
267
- Expression :: ArrowFunctionExpression ( arrow) ,
268
- NONE ,
269
- ctx. ast . vec ( ) ,
270
- false ,
271
- )
272
- }
273
-
274
245
/// Convert chain expression to expression
275
246
///
276
247
/// - [ChainElement::CallExpression] -> [Expression::CallExpression]
@@ -312,7 +283,7 @@ impl<'a> OptionalChaining<'a, '_> {
312
283
// To insert the temp binding in the correct scope, we wrap the expression with
313
284
// an arrow function. During the chain expression transformation, the temp binding
314
285
// will be inserted into the arrow function's body.
315
- Self :: wrap_arrow_function_iife ( expr, ctx)
286
+ wrap_arrow_function_iife ( expr, ctx)
316
287
} else {
317
288
self . transform_chain_expression_impl ( false , expr, ctx)
318
289
}
@@ -326,7 +297,7 @@ impl<'a> OptionalChaining<'a, '_> {
326
297
) {
327
298
* expr = if self . is_inside_function_parameter {
328
299
// Same as the above `transform_chain_expression` explanation
329
- Self :: wrap_arrow_function_iife ( expr, ctx)
300
+ wrap_arrow_function_iife ( expr, ctx)
330
301
} else {
331
302
// Unfortunately no way to get compiler to see that this branch is provably unreachable.
332
303
// We don't want to inline this function, to keep `enter_expression` as small as possible.
0 commit comments