Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(isolated_declarations): Fix readonly specifier on class constructor params #4030

Merged
merged 4 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
Loading