fix(transformer): missing initializer for readonly consructor properties (#4103)

This commit is contained in:
Don Isaac 2024-07-08 00:45:50 -04:00 committed by GitHub
parent e386b62331
commit 4413e2d298
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 26 additions and 8 deletions

View file

@ -241,7 +241,7 @@ impl<'a> TypeScriptAnnotations<'a> {
// for each of them in the constructor body.
if def.kind == MethodDefinitionKind::Constructor {
for param in def.value.params.items.as_mut_slice() {
if param.accessibility.is_some() {
if param.accessibility.is_some() || param.readonly || param.r#override {
if let Some(id) = param.pattern.get_binding_identifier() {
self.assignments.push(Assignment {
span: id.span,

View file

@ -1,5 +1,11 @@
class Foo {
constructor(public foo, private bar, protected zoo, too) {
boom: number;
constructor(public foo, private bar, protected zoo, readonly bang, too) {
}
}
}
class Bar extends Foo {
constructor(public foo, private bar, protected zoo, readonly bang, override boom, too) {
super(foo, bar, zoo, bang, too);
}
}

View file

@ -1,7 +1,19 @@
class Foo {
constructor(foo, bar, zoo, too) {
this.foo = foo;
this.bar = bar;
this.zoo = zoo;
boom;
constructor(foo, bar, zoo, bang, too) {
this.foo = foo;
this.bar = bar;
this.zoo = zoo;
this.bang = bang;
}
}
}
class Bar extends Foo {
constructor(foo, bar, zoo, bang, boom, too) {
super(foo, bar, zoo, bang, too);
this.foo = foo;
this.bar = bar;
this.zoo = zoo;
this.bang = bang;
this.boom = boom;
}
}