From 25823c8529e34a78e09c26ba523a8aa27867439f Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Mon, 25 Nov 2024 14:25:27 +0000 Subject: [PATCH] refactor(transformer/class-properties): safer use of `GetAddress` (#7474) Avoid using `Address::from_ptr`, which is error-prone. --- .../oxc_transformer/src/es2022/class_properties/class.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/crates/oxc_transformer/src/es2022/class_properties/class.rs b/crates/oxc_transformer/src/es2022/class_properties/class.rs index 747b3914e..ff7a7bc73 100644 --- a/crates/oxc_transformer/src/es2022/class_properties/class.rs +++ b/crates/oxc_transformer/src/es2022/class_properties/class.rs @@ -1,7 +1,7 @@ //! ES2022: Class Properties //! Transform of class itself. -use oxc_allocator::Address; +use oxc_allocator::{Address, GetAddress}; use oxc_ast::{ast::*, NONE}; use oxc_span::SPAN; use oxc_syntax::{ @@ -35,7 +35,8 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> { ) { let Expression::ClassExpression(class) = expr else { unreachable!() }; - let expr_count = self.transform_class_expression_start(class, ctx); + let class_address = class.address(); + let expr_count = self.transform_class_expression_start(class, class_address, ctx); if expr_count > 0 { self.transform_class_expression_finish(expr, expr_count, ctx); } @@ -44,10 +45,10 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> { fn transform_class_expression_start( &mut self, class: &mut Class<'a>, + class_address: Address, ctx: &mut TraverseCtx<'a>, ) -> usize { // Check this class isn't being visited twice - let class_address = Address::from_ptr(class); if *self.class_expression_addresses_stack.last() == class_address { // This class has already been transformed, and we're now encountering it again // in the sequence expression which was substituted for it. So don't transform it again!