diff --git a/crates/oxc_transformer/src/es2015/arrow_functions.rs b/crates/oxc_transformer/src/es2015/arrow_functions.rs index fc110eafbf7b6..ae3722b027d7f 100644 --- a/crates/oxc_transformer/src/es2015/arrow_functions.rs +++ b/crates/oxc_transformer/src/es2015/arrow_functions.rs @@ -119,34 +119,21 @@ impl<'a> ArrowFunctions<'a> { } /// Change to <_this>, and mark it as found - pub fn transform_jsx_opening_element(&mut self, elem: &mut JSXOpeningElement<'a>) { + pub fn transform_jsx_element_name(&mut self, name: &mut JSXElementName<'a>) { if !self.is_inside_arrow_function() { return; } - let mut change_ident = |ident: &mut JSXIdentifier<'a>| { - if ident.name == "this" { - self.mark_this_as_found(); - ident.name = self.get_this_name(); + let ident = match name { + JSXElementName::Identifier(ident) => ident, + JSXElementName::MemberExpression(member_expr) => { + member_expr.get_object_identifier_mut() } + JSXElementName::NamespacedName(_) => return, }; - match &mut elem.name { - JSXElementName::Identifier(ref mut ident) => change_ident(ident), - JSXElementName::MemberExpression(ref mut member) => { - let mut member_expr = member; - loop { - match &mut member_expr.object { - JSXMemberExpressionObject::Identifier(ident) => { - change_ident(ident); - break; - } - JSXMemberExpressionObject::MemberExpression(expr) => { - member_expr = expr; - } - } - } - } - JSXElementName::NamespacedName(_) => {} + if ident.name == "this" { + self.mark_this_as_found(); + ident.name = self.get_this_name(); } } diff --git a/crates/oxc_transformer/src/es2015/mod.rs b/crates/oxc_transformer/src/es2015/mod.rs index 98ce17c68e553..75daa56eadd2d 100644 --- a/crates/oxc_transformer/src/es2015/mod.rs +++ b/crates/oxc_transformer/src/es2015/mod.rs @@ -43,9 +43,9 @@ impl<'a> ES2015<'a> { } } - pub fn transform_jsx_opening_element(&mut self, elem: &mut JSXOpeningElement<'a>) { + pub fn transform_jsx_element_name(&mut self, elem: &mut JSXElementName<'a>) { if self.options.arrow_function.is_some() { - self.arrow_functions.transform_jsx_opening_element(elem); + self.arrow_functions.transform_jsx_element_name(elem); } } diff --git a/crates/oxc_transformer/src/lib.rs b/crates/oxc_transformer/src/lib.rs index 0c73156559d25..25d26a4a3d69a 100644 --- a/crates/oxc_transformer/src/lib.rs +++ b/crates/oxc_transformer/src/lib.rs @@ -201,7 +201,14 @@ impl<'a> Traverse<'a> for Transformer<'a> { ) { self.x0_typescript.transform_jsx_opening_element(elem); self.x1_react.transform_jsx_opening_element(elem, ctx); - self.x3_es2015.transform_jsx_opening_element(elem); + } + + fn enter_jsx_element_name( + &mut self, + elem: &mut JSXElementName<'a>, + _ctx: &mut TraverseCtx<'a>, + ) { + self.x3_es2015.transform_jsx_element_name(elem); } fn enter_method_definition(