refactor(transformer/class-properties): rename misleadingly-named method (#7609)

This method replaces `this` with class temp var, not reference to class name. Name the method accordingly, and update comments.
This commit is contained in:
overlookmotel 2024-12-03 12:43:20 +00:00
parent 206de912dc
commit 7d1c12e5e2

View file

@ -11,8 +11,10 @@ use oxc_traverse::TraverseCtx;
use super::ClassProperties; use super::ClassProperties;
impl<'a, 'ctx> ClassProperties<'a, 'ctx> { impl<'a, 'ctx> ClassProperties<'a, 'ctx> {
/// Transform any `this` in static property initializer to reference to class name, /// Transform static property initializer.
/// and transform private field accesses (`object.#prop`). ///
/// Replace `this` with temp var for class. Transform private fields.
/// See below for full details of transforms.
pub(super) fn transform_static_initializer( pub(super) fn transform_static_initializer(
&mut self, &mut self,
value: &mut Expression<'a>, value: &mut Expression<'a>,
@ -135,7 +137,7 @@ impl<'a, 'ctx, 'v> VisitMut<'a> for StaticInitializerVisitor<'a, 'ctx, 'v> {
// `this` // `this`
Expression::ThisExpression(this_expr) => { Expression::ThisExpression(this_expr) => {
let span = this_expr.span; let span = this_expr.span;
self.replace_this_with_class_name(expr, span); self.replace_this_with_temp_var(expr, span);
return; return;
} }
// `delete this` // `delete this`
@ -263,8 +265,8 @@ impl<'a, 'ctx, 'v> VisitMut<'a> for StaticInitializerVisitor<'a, 'ctx, 'v> {
} }
impl<'a, 'ctx, 'v> StaticInitializerVisitor<'a, 'ctx, 'v> { impl<'a, 'ctx, 'v> StaticInitializerVisitor<'a, 'ctx, 'v> {
/// Replace `this` with reference to class name binding. /// Replace `this` with reference to temp var for class.
fn replace_this_with_class_name(&mut self, expr: &mut Expression<'a>, span: Span) { fn replace_this_with_temp_var(&mut self, expr: &mut Expression<'a>, span: Span) {
if self.this_depth == 0 { if self.this_depth == 0 {
// `PrivateProps` is the source of truth for bindings if class has private props // `PrivateProps` is the source of truth for bindings if class has private props
// because other visitors which transform private fields may create a temp binding // because other visitors which transform private fields may create a temp binding
@ -274,8 +276,8 @@ impl<'a, 'ctx, 'v> StaticInitializerVisitor<'a, 'ctx, 'v> {
None => &mut self.class_properties.class_bindings, None => &mut self.class_properties.class_bindings,
}; };
let class_binding = class_bindings.get_or_init_temp_binding(self.ctx); let temp_binding = class_bindings.get_or_init_temp_binding(self.ctx);
*expr = class_binding.create_spanned_read_expression(span, self.ctx); *expr = temp_binding.create_spanned_read_expression(span, self.ctx);
} }
} }