Skip to content

Commit

Permalink
fix(isolated_declarations): Fix readonly specifier on class construct…
Browse files Browse the repository at this point in the history
…or params (#4030)
  • Loading branch information
escaton authored Jul 2, 2024
1 parent da62839 commit b007553
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion crates/oxc_isolated_declarations/src/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ impl<'a> IsolatedDeclarations<'a> {
) -> oxc_allocator::Vec<'a, ClassElement<'a>> {
let mut elements = self.ast.new_vec();
for (index, param) in function.params.items.iter().enumerate() {
if param.accessibility.is_some() {
if param.accessibility.is_some() || param.readonly {
// transformed params will definitely have type annotation
let type_annotation = self.ast.copy(&params.items[index].pattern.type_annotation);
if let Some(new_element) =
Expand Down
9 changes: 1 addition & 8 deletions crates/oxc_isolated_declarations/src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,7 @@ impl<'a> IsolatedDeclarations<'a> {
);
}

Some(self.ast.formal_parameter(
param.span,
pattern,
None,
param.readonly,
false,
self.ast.new_vec(),
))
Some(self.ast.formal_parameter(param.span, pattern, None, false, false, self.ast.new_vec()))
}

pub fn transform_formal_parameters(
Expand Down
8 changes: 8 additions & 0 deletions crates/oxc_isolated_declarations/tests/fixtures/class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,11 @@ export class Baz {
readonly prop1 = 'some string';
prop2 = 'another string';
}

export class Boo {
constructor(
public readonly prop: number = 0,
private readonly prop2: number = 1,
readonly prop3: number = 1,
) {}
}
6 changes: 6 additions & 0 deletions crates/oxc_isolated_declarations/tests/snapshots/class.snap
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,9 @@ export declare class Baz {
readonly prop1: 'some string';
prop2: string;
}
export declare class Boo {
readonly prop: number;
private readonly prop2: number;
readonly prop3: number;
constructor(prop?: number, prop2?: number, prop3?: number);
}

0 comments on commit b007553

Please sign in to comment.