Skip to content

Commit

Permalink
fix(transformer/class-static-blocks): static block converted to IIFE …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
overlookmotel committed Jan 16, 2025
1 parent 712633f commit a048337
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_transformer/src/es2022/class_static_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit a048337

Please sign in to comment.