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

This commit is contained in:
Egor Blinov 2024-07-02 17:26:19 +02:00 committed by GitHub
parent da628399fa
commit b007553ebe
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 16 additions and 9 deletions

View file

@ -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) =

View file

@ -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(

View file

@ -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,
) {}
}

View file

@ -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);
}