From a04833787d17b946a19d8247ca36633f922e308e Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Thu, 16 Jan 2025 14:55:53 +0000 Subject: [PATCH] fix(transformer/class-static-blocks): static block converted to IIFE use span of original block (#8549) Fix spans in class static blocks and class properties transforms. When a static block is converted to an IIFE, the IIFE should take the span of the static block. --- .../src/es2022/class_properties/static_block_and_prop_init.rs | 3 +-- crates/oxc_transformer/src/es2022/class_static_block.rs | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/oxc_transformer/src/es2022/class_properties/static_block_and_prop_init.rs b/crates/oxc_transformer/src/es2022/class_properties/static_block_and_prop_init.rs index 21c0facc340b6..a0660454c44f4 100644 --- a/crates/oxc_transformer/src/es2022/class_properties/static_block_and_prop_init.rs +++ b/crates/oxc_transformer/src/es2022/class_properties/static_block_and_prop_init.rs @@ -7,7 +7,6 @@ use oxc_ast::{ ast::*, visit::{walk_mut, VisitMut}, }; -use oxc_span::SPAN; use oxc_syntax::scope::{ScopeFlags, ScopeId}; use oxc_traverse::TraverseCtx; @@ -90,7 +89,7 @@ impl<'a> ClassProperties<'a, '_> { let outer_scope_id = ctx.current_scope_id(); ctx.scopes_mut().change_parent_id(scope_id, Some(outer_scope_id)); - wrap_statements_in_arrow_function_iife(ctx.ast.move_vec(stmts), scope_id, SPAN, ctx) + wrap_statements_in_arrow_function_iife(ctx.ast.move_vec(stmts), scope_id, block.span, ctx) } fn convert_static_block_with_single_expression_to_expression( diff --git a/crates/oxc_transformer/src/es2022/class_static_block.rs b/crates/oxc_transformer/src/es2022/class_static_block.rs index 2caa456144f5b..7538f8fb5e90b 100644 --- a/crates/oxc_transformer/src/es2022/class_static_block.rs +++ b/crates/oxc_transformer/src/es2022/class_static_block.rs @@ -159,7 +159,7 @@ impl ClassStaticBlock { // Always strict mode since we're in a class. *ctx.scopes_mut().get_flags_mut(scope_id) = ScopeFlags::Function | ScopeFlags::Arrow | ScopeFlags::StrictMode; - wrap_statements_in_arrow_function_iife(ctx.ast.move_vec(stmts), scope_id, SPAN, ctx) + wrap_statements_in_arrow_function_iife(ctx.ast.move_vec(stmts), scope_id, block.span, ctx) } /// Convert static block to expression which will be value of private field,