mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 12:19:15 +00:00
feat(isolated-declarations): support for class function overloads (#3811)
This commit is contained in:
parent
dd540c8f0f
commit
2cdb34f6df
2 changed files with 39 additions and 23 deletions
|
|
@ -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<Modifiers<'a>>,
|
||||
) -> Option<Box<'a, Class<'a>>> {
|
||||
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<Atom, Box<'a, TSTypeAnnotation<'a>>> {
|
||||
let mut inferred_accessor_types: FxHashMap<Atom<'a>, 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<Modifiers<'a>>,
|
||||
) -> Option<Box<'a, Class<'a>>> {
|
||||
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(
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in a new issue