diff --git a/crates/oxc_transformer/src/es2022/class_properties/private.rs b/crates/oxc_transformer/src/es2022/class_properties/private.rs index ba8ebd27f425f..3320e94202f99 100644 --- a/crates/oxc_transformer/src/es2022/class_properties/private.rs +++ b/crates/oxc_transformer/src/es2022/class_properties/private.rs @@ -1096,6 +1096,7 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> { let is_optional = field_expr.optional; let object = &mut field_expr.object; + let left = if is_optional { Some(self.transform_expression_to_wrap_nullish_check(object, ctx)) } else { @@ -1192,9 +1193,17 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> { object: &mut Expression<'a>, ctx: &mut TraverseCtx<'a>, ) -> Expression<'a> { - let owned_object = ctx.ast.move_expression(object.get_inner_expression_mut()); - let owned_object = - Self::ensure_optional_expression_wrapped_by_chain_expression(owned_object, ctx); + let mut owned_object = ctx.ast.move_expression(object.get_inner_expression_mut()); + + let owned_object = if let Some(result) = + self.transform_chain_element_recursively(&mut owned_object, ctx) + { + // If the `object` contains PrivateFieldExpression, we need to transform it first. + Self::wrap_conditional_check(result, owned_object, ctx) + } else { + Self::ensure_optional_expression_wrapped_by_chain_expression(owned_object, ctx) + }; + let (assignment, reference1, reference2) = self.duplicate_object_twice(owned_object, ctx); *object = reference1; self.wrap_nullish_check(assignment, reference2, ctx) diff --git a/tasks/transform_conformance/snapshots/babel.snap.md b/tasks/transform_conformance/snapshots/babel.snap.md index d6643ba21a451..bcf589b613d9f 100644 --- a/tasks/transform_conformance/snapshots/babel.snap.md +++ b/tasks/transform_conformance/snapshots/babel.snap.md @@ -1,6 +1,6 @@ commit: 54a8389f -Passed: 480/846 +Passed: 482/846 # All Passed: * babel-plugin-transform-class-static-block @@ -276,7 +276,7 @@ x Output mismatch x Output mismatch -# babel-plugin-transform-class-properties (153/264) +# babel-plugin-transform-class-properties (155/264) * assumption-constantSuper/complex-super-class/input.js x Output mismatch @@ -488,9 +488,6 @@ x Output mismatch * private/optional-chain-optional-member-call-with-transform/input.js x Output mismatch -* private/optional-chain-optional-property/input.js -x Output mismatch - * private/optional-chain-optional-property-with-transform/input.js x Output mismatch @@ -675,9 +672,6 @@ x Output mismatch * private-loose/optional-chain-optional-member-call-with-transform/input.js x Output mismatch -* private-loose/optional-chain-optional-property/input.js -x Output mismatch - * private-loose/optional-chain-optional-property-with-transform/input.js x Output mismatch