Skip to content

Commit

Permalink
Add ClassBindings::get_or_init_temp_binding_into
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Nov 29, 2024
1 parent 0951c13 commit 459ba39
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,20 @@ impl<'a> ClassBindings<'a> {

self.temp.as_ref().unwrap()
}

pub fn get_or_init_temp_binding_into<'b>(
&mut self,
class_binding: &'b mut Option<BoundIdentifier<'a>>,
is_declaration: bool,
transform_ctx: &TransformCtx<'a>,
ctx: &mut TraverseCtx<'a>,
) -> &'b BoundIdentifier<'a> {
if let Some(class_binding) = class_binding {
class_binding
} else {
let binding = self.get_or_init_temp_binding(is_declaration, transform_ctx, ctx);
*class_binding = Some(binding.clone());
class_binding.as_ref().unwrap()
}
}
}
32 changes: 24 additions & 8 deletions crates/oxc_transformer/src/es2022/class_properties/private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,14 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> {
class_binding
} else {
// Only possible to reach here if we're currently transforming static prop initializers.
// TODO: Can we store the new value in private prop?
// TODO: Test that we're transforming static prop initializers right now,
// and not visiting class body. Add some debug assertions for this.
self.class_bindings.get_or_init_temp_binding(self.is_declaration, self.ctx, ctx)
self.class_bindings.get_or_init_temp_binding_into(
class_binding,
self.is_declaration,
self.ctx,
ctx,
)
};
let class_ident = class_binding.create_read_expression(ctx);

Expand Down Expand Up @@ -239,10 +243,14 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> {
class_binding
} else {
// Only possible to reach here if we're currently transforming static prop initializers.
// TODO: Can we store the new value in private prop?
// TODO: Test that we're transforming static prop initializers right now,
// and not visiting class body. Add some debug assertions for this.
self.class_bindings.get_or_init_temp_binding(self.is_declaration, self.ctx, ctx)
self.class_bindings.get_or_init_temp_binding_into(
class_binding,
self.is_declaration,
self.ctx,
ctx,
)
};
let class_ident = class_binding.create_read_expression(ctx);

Expand Down Expand Up @@ -324,10 +332,14 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> {
class_binding
} else {
// Only possible to reach here if we're currently transforming static prop initializers.
// TODO: Can we store the new value in private prop?
// TODO: Test that we're transforming static prop initializers right now,
// and not visiting class body. Add some debug assertions for this.
self.class_bindings.get_or_init_temp_binding(self.is_declaration, self.ctx, ctx)
self.class_bindings.get_or_init_temp_binding_into(
class_binding,
self.is_declaration,
self.ctx,
ctx,
)
};
let class_binding = class_binding.clone();

Expand Down Expand Up @@ -725,10 +737,14 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> {
class_binding
} else {
// Only possible to reach here if we're currently transforming static prop initializers.
// TODO: Can we store the new value in private prop?
// TODO: Test that we're transforming static prop initializers right now,
// and not visiting class body. Add some debug assertions for this.
self.class_bindings.get_or_init_temp_binding(self.is_declaration, self.ctx, ctx)
self.class_bindings.get_or_init_temp_binding_into(
class_binding,
self.is_declaration,
self.ctx,
ctx,
)
};
let class_binding = class_binding.clone();

Expand Down

0 comments on commit 459ba39

Please sign in to comment.