From 6e85d6d05e6e269a436fafb24b65483b9779ad75 Mon Sep 17 00:00:00 2001 From: Dunqing Date: Fri, 24 Jan 2025 21:16:15 +0800 Subject: [PATCH] support decorator are used in accessor --- .../src/decorator/legacy_decorator.rs | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/crates/oxc_transformer/src/decorator/legacy_decorator.rs b/crates/oxc_transformer/src/decorator/legacy_decorator.rs index 507a090b3f4854..b8054cabf21727 100644 --- a/crates/oxc_transformer/src/decorator/legacy_decorator.rs +++ b/crates/oxc_transformer/src/decorator/legacy_decorator.rs @@ -322,6 +322,18 @@ impl<'a> LegacyDecorator<'a, '_> { (prop.r#static, &mut prop.key, descriptor, decorations) } + ClassElement::AccessorProperty(accessor) => { + let decorations = Self::convert_decorators_to_array_expression( + accessor.decorators.drain(..), + ctx, + ); + + // We emit `null` here to indicate to `__decorate` that it can invoke `Object.getOwnPropertyDescriptor` directly. + // We have this extra argument here so that we can inject an explicit property descriptor at a later date. + let descriptor = ctx.ast.expression_null_literal(SPAN); + + (accessor.r#static, &mut accessor.key, descriptor, decorations) + } _ => { continue; } @@ -514,6 +526,16 @@ impl<'a> LegacyDecorator<'a, '_> { ); } } + ClassElement::AccessorProperty(accessor) => { + child_is_decorated |= !accessor.decorators.is_empty(); + + if child_is_decorated && !has_private_in_expression_in_decorator { + has_private_in_expression_in_decorator = + PrivateInExpressionDetector::has_private_in_expression( + &accessor.decorators, + ); + } + } _ => {} } } @@ -553,7 +575,7 @@ impl<'a> LegacyDecorator<'a, '_> { PropertyKey::StaticIdentifier(ident) => { ctx.ast.expression_string_literal(SPAN, ident.name, None) } - // Legacy decorators do not support private properties/methods + // Legacy decorators do not support private properties/methods/accessors PropertyKey::PrivateIdentifier(_) => ctx.ast.expression_string_literal(SPAN, "", None), // Copiable literals PropertyKey::NumericLiteral(literal) => {