Skip to content

Commit 4413e2d

Browse files
authored
fix(transformer): missing initializer for readonly consructor properties (#4103)
1 parent e386b62 commit 4413e2d

File tree

3 files changed

+26
-8
lines changed
  • crates/oxc_transformer/src/typescript
  • tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/class-constructor-arguments

3 files changed

+26
-8
lines changed

crates/oxc_transformer/src/typescript/annotations.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ impl<'a> TypeScriptAnnotations<'a> {
241241
// for each of them in the constructor body.
242242
if def.kind == MethodDefinitionKind::Constructor {
243243
for param in def.value.params.items.as_mut_slice() {
244-
if param.accessibility.is_some() {
244+
if param.accessibility.is_some() || param.readonly || param.r#override {
245245
if let Some(id) = param.pattern.get_binding_identifier() {
246246
self.assignments.push(Assignment {
247247
span: id.span,
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
class Foo {
2-
constructor(public foo, private bar, protected zoo, too) {
2+
boom: number;
3+
constructor(public foo, private bar, protected zoo, readonly bang, too) {
34

45
}
5-
}
6+
}
7+
class Bar extends Foo {
8+
constructor(public foo, private bar, protected zoo, readonly bang, override boom, too) {
9+
super(foo, bar, zoo, bang, too);
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
class Foo {
2-
constructor(foo, bar, zoo, too) {
3-
this.foo = foo;
4-
this.bar = bar;
5-
this.zoo = zoo;
2+
boom;
3+
constructor(foo, bar, zoo, bang, too) {
4+
this.foo = foo;
5+
this.bar = bar;
6+
this.zoo = zoo;
7+
this.bang = bang;
68
}
7-
}
9+
}
10+
class Bar extends Foo {
11+
constructor(foo, bar, zoo, bang, boom, too) {
12+
super(foo, bar, zoo, bang, too);
13+
this.foo = foo;
14+
this.bar = bar;
15+
this.zoo = zoo;
16+
this.bang = bang;
17+
this.boom = boom;
18+
}
19+
}

0 commit comments

Comments
 (0)