Skip to content

Commit 9e3571f

Browse files
authored
fix(isolated-declarations): private accessors keep their types (oxc-project#9132)
Input: ```ts export class Cls { accessor d: string; private accessor e: string; private static accessor f: string; } ``` Expected: ```ts export declare class Cls { accessor d: string; private accessor e; private static accessor f; } ``` Actual: ```ts export declare class Cls { accessor d: string; private accessor e: string; private static accessor f: string; } ``` ts playground: https://www.typescriptlang.org/play/?#code/MYGwhgzhAEDCIwN4ChrTMYBTKB7ATtACYBc0EALvgJYB2A5gNyrQAONAbmBVupjhALQsZSjQbM07alx7kK3asD7Y8hAGaiqdJsgC+yZEA
1 parent 19fdf89 commit 9e3571f

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

crates/oxc_isolated_declarations/src/class.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,11 @@ impl<'a> IsolatedDeclarations<'a> {
504504
continue;
505505
}
506506

507+
let type_annotation = match property.accessibility {
508+
Some(TSAccessibility::Private) => None,
509+
_ => property.type_annotation.clone_in(self.ast.allocator),
510+
};
511+
507512
// FIXME: missing many fields
508513
let new_element = self.ast.class_element_accessor_property(
509514
property.span,
@@ -514,7 +519,7 @@ impl<'a> IsolatedDeclarations<'a> {
514519
property.computed,
515520
property.r#static,
516521
property.definite,
517-
property.type_annotation.clone_in(self.ast.allocator),
522+
type_annotation,
518523
property.accessibility,
519524
);
520525
elements.push(new_element);

crates/oxc_isolated_declarations/tests/fixtures/set-get-accessor.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ class Cls {
1414

1515
private get c() {}
1616
private set c() {}
17+
18+
accessor d: string;
19+
private accessor e: string;
20+
private static accessor f: string;
1721
}
1822

1923
// Incorrect

crates/oxc_isolated_declarations/tests/snapshots/set-get-accessor.snap

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ declare class Cls {
1212
set b(v: string);
1313
private get c();
1414
private set c(value);
15+
accessor d: string;
16+
private accessor e;
17+
private static accessor f;
1518
}
1619
declare class ClsBad {
1720
get a();
@@ -23,11 +26,11 @@ declare class ClsBad {
2326
2427
x TS9009: At least one accessor must have an explicit return type annotation
2528
| with --isolatedDeclarations.
26-
,-[21:7]
27-
20 | class ClsBad {
28-
21 | get a() {
29+
,-[25:7]
30+
24 | class ClsBad {
31+
25 | get a() {
2932
: ^
30-
22 | return;
33+
26 | return;
3134
`----
3235
3336

0 commit comments

Comments
 (0)