diff --git a/crates/oxc_isolated_declarations/src/class.rs b/crates/oxc_isolated_declarations/src/class.rs index fd49597b6ab2c3..1064cdb1086ba1 100644 --- a/crates/oxc_isolated_declarations/src/class.rs +++ b/crates/oxc_isolated_declarations/src/class.rs @@ -247,33 +247,15 @@ impl<'a> IsolatedDeclarations<'a> { elements } - pub fn transform_class( + /// Infer get accessor return type from set accessor + /// Infer set accessor parameter type from get accessor return type + fn collect_inferred_accessor_types( &self, decl: &Class<'a>, - modifiers: Option>, - ) -> Option>> { - if decl.is_declare() { - return None; - } - - if let Some(super_class) = &decl.super_class { - let is_not_allowed = match super_class { - Expression::Identifier(_) => false, - Expression::StaticMemberExpression(expr) => { - !expr.get_first_object().is_identifier_reference() - } - _ => true, - }; - if is_not_allowed { - self.error(extends_clause_expression(super_class.span())); - } - } - + ) -> FxHashMap>> { let mut inferred_accessor_types: FxHashMap, Box<'a, TSTypeAnnotation<'a>>> = FxHashMap::default(); - // Infer get accessor return type from set accessor - // Infer set accessor parameter type from get accessor for element in &decl.body.body { if let ClassElement::MethodDefinition(method) = element { if method.key.is_private_identifier() @@ -318,12 +300,45 @@ impl<'a> IsolatedDeclarations<'a> { } } + inferred_accessor_types + } + + pub fn transform_class( + &self, + decl: &Class<'a>, + modifiers: Option>, + ) -> Option>> { + if decl.is_declare() { + return None; + } + + if let Some(super_class) = &decl.super_class { + let is_not_allowed = match super_class { + Expression::Identifier(_) => false, + Expression::StaticMemberExpression(expr) => { + !expr.get_first_object().is_identifier_reference() + } + _ => true, + }; + if is_not_allowed { + self.error(extends_clause_expression(super_class.span())); + } + } + let mut has_private_key = false; let mut elements = self.ast.new_vec(); + let mut is_function_overloads = false; for element in &decl.body.body { match element { ClassElement::StaticBlock(_) => {} ClassElement::MethodDefinition(ref method) => { + if method.value.body.is_none() { + is_function_overloads = true; + } else if is_function_overloads { + // Skip implementation of function overloads + is_function_overloads = false; + continue; + } if method.key.is_private_identifier() { has_private_key = true; continue; @@ -335,6 +350,8 @@ impl<'a> IsolatedDeclarations<'a> { elements.push(self.transform_private_modifier_method(method)); continue; } + + let inferred_accessor_types = self.collect_inferred_accessor_types(decl); let function = &method.value; let params = if method.kind.is_set() { method.key.static_name().map_or_else( diff --git a/crates/oxc_isolated_declarations/tests/deno.rs b/crates/oxc_isolated_declarations/tests/deno.rs index f471f6e03f64da..fcfea244053ebb 100644 --- a/crates/oxc_isolated_declarations/tests/deno.rs +++ b/crates/oxc_isolated_declarations/tests/deno.rs @@ -103,7 +103,6 @@ export function foo(a: any): number { } #[test] - #[ignore = "Doesn't support class function overloads"] fn dts_class_decl_overloads_test() { transform_dts_test( "export class Foo { diff --git a/napi/transform/package.json b/napi/transform/package.json index 63099b0d565cc4..e13b1feb6c0e4f 100644 --- a/napi/transform/package.json +++ b/napi/transform/package.json @@ -26,5 +26,6 @@ "aarch64-apple-darwin" ] } - } + }, + "packageManager": "pnpm@9.3.0+sha512.ee7b93e0c2bd11409c6424f92b866f31d3ea1bef5fbe47d3c7500cdc3c9668833d2e55681ad66df5b640c61fa9dc25d546efa54d76d7f8bf54b13614ac293631" }