Skip to content

Commit

Permalink
fix(isolated-declarations): False positive for class private getter w…
Browse files Browse the repository at this point in the history
…ith non-inferrable return type (#5987)

Fixes a case missing from #5964

Co-authored-by: MichaelMitchell-at <=>
  • Loading branch information
MichaelMitchell-at committed Sep 23, 2024
1 parent 859227e commit 97a2c41
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
4 changes: 4 additions & 0 deletions crates/oxc_isolated_declarations/src/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,10 @@ impl<'a> IsolatedDeclarations<'a> {
entry.1 = Some(&mut first_param.pattern.type_annotation);
}
MethodDefinitionKind::Get => {
if method.accessibility.is_some_and(TSAccessibility::is_private) {
continue;
}

let function = &mut method.value;
if function.return_type.is_none() {
function.return_type = self.infer_function_return_type(function);
Expand Down
6 changes: 6 additions & 0 deletions crates/oxc_isolated_declarations/tests/fixtures/class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,14 @@ export class PrivateFieldsWithConstructorAssignments {

export class PrivateMethodClass {
private good(a): void {}
private get goodGetter() {
return {[('x')]: 1};
}
}

export class PublicMethodClass {
public bad(a): void {}
public get badGetter() {
return {[('x')]: 1};
}
}
19 changes: 15 additions & 4 deletions crates/oxc_isolated_declarations/tests/snapshots/class.snap
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,32 @@ export declare class PrivateFieldsWithConstructorAssignments {
}
export declare class PrivateMethodClass {
private good;
private get goodGetter();
}
export declare class PublicMethodClass {
bad(a): void;
get badGetter(): {};
}


==================== Errors ====================

x TS9038: Computed property names on class or object literals cannot be
| inferred with --isolatedDeclarations.
,-[69:14]
68 | public get badGetter() {
69 | return {[('x')]: 1};
: ^^^^^
70 | }
`----
x TS9011: Parameter must have an explicit type annotation with
| --isolatedDeclarations.
,-[64:14]
63 | export class PublicMethodClass {
64 | public bad(a): void {}
,-[67:14]
66 | export class PublicMethodClass {
67 | public bad(a): void {}
: ^
65 | }
68 | public get badGetter() {
`----
Expand Down

0 comments on commit 97a2c41

Please sign in to comment.