diff --git a/crates/oxc_transformer/src/es2022/class_properties/private.rs b/crates/oxc_transformer/src/es2022/class_properties/private.rs index 211484385cbf43..4c3b8b3fdc5806 100644 --- a/crates/oxc_transformer/src/es2022/class_properties/private.rs +++ b/crates/oxc_transformer/src/es2022/class_properties/private.rs @@ -19,6 +19,15 @@ use super::{ ClassProperties, PrivateProp, }; +/// Details of a private property resolved for a private field. +/// +/// This is the return value of `lookup_private_property`. +struct ResolvedPrivateProp<'a, 'b> { + prop: &'b PrivateProp<'a>, + class_binding: &'b Option>, + is_declaration: bool, +} + impl<'a, 'ctx> ClassProperties<'a, 'ctx> { /// Transform private field expression. /// @@ -44,9 +53,10 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> { ) -> Expression<'a> { let prop_details = self.lookup_private_property(&field_expr.field); // TODO: Should never be `None` - only because implementation is incomplete. - let Some((prop, class_binding, is_declaration)) = prop_details else { + let Some(prop_details) = prop_details else { return Expression::PrivateFieldExpression(field_expr); }; + let ResolvedPrivateProp { prop, class_binding, is_declaration } = prop_details; let prop_ident = prop.binding.create_read_expression(ctx); // TODO: Move this to top of function once `lookup_private_property` does not return `Option` @@ -182,7 +192,7 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> { ctx: &mut TraverseCtx<'a>, ) -> Option<(Expression<'a>, Expression<'a>)> { // TODO: Should never be `None` - only because implementation is incomplete. - let (prop, class_binding, is_declaration) = + let ResolvedPrivateProp { prop, class_binding, is_declaration } = self.lookup_private_property(&field_expr.field)?; let prop_ident = prop.binding.create_read_expression(ctx); @@ -264,7 +274,8 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> { let prop_details = self.lookup_private_property(&field_expr.field); // TODO: Should never be `None` - only because implementation is incomplete. - let Some((prop, class_binding, is_declaration)) = prop_details else { return }; + let Some(prop_details) = prop_details else { return }; + let ResolvedPrivateProp { prop, class_binding, is_declaration } = prop_details; // Note: `transform_static_assignment_expression` and `transform_instance_assignment_expression` // are marked `#[inline]`, so hopefully compiler will see these clones of `BoundIdentifier`s @@ -613,7 +624,9 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> { let prop_details = self.lookup_private_property(&field_expr.field); // TODO: Should never be `None` - only because implementation is incomplete. - let Some((prop, class_binding, is_declaration)) = prop_details else { return }; + let Some(prop_details) = prop_details else { return }; + let ResolvedPrivateProp { prop, class_binding, is_declaration } = prop_details; + let prop_ident = prop.binding.create_read_expression(ctx); let prop_ident2 = prop.binding.create_read_expression(ctx); @@ -1032,15 +1045,19 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> { } /// Lookup details of private property referred to by `ident`. - fn lookup_private_property( - &self, + fn lookup_private_property<'b>( + &'b self, ident: &PrivateIdentifier<'a>, - ) -> Option<(&PrivateProp<'a>, &Option>, /* is_declaration */ bool)> { + ) -> Option> { // Check for binding in closest class first, then enclosing classes // TODO: Check there are tests for bindings in enclosing classes. for private_props in self.private_props_stack.as_slice().iter().rev() { if let Some(prop) = private_props.props.get(&ident.name) { - return Some((prop, &private_props.class_binding, private_props.is_declaration)); + return Some(ResolvedPrivateProp { + prop, + class_binding: &private_props.class_binding, + is_declaration: private_props.is_declaration, + }); } } // TODO: This should be unreachable. Only returning `None` because implementation is incomplete.