Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 4464e9e

Browse files
Handle variance sigils on class properties, fixes #149 (#243)
1 parent 499e475 commit 4464e9e

File tree

6 files changed

+30
-0
lines changed

6 files changed

+30
-0
lines changed

src/transform.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,9 +361,23 @@ const transform = {
361361
},
362362
ClassProperty(path, state) {
363363
trackComments(path.node, state);
364+
365+
const { node } = path;
366+
if (node.variance && node.variance.kind === "plus") {
367+
node.readonly = true;
368+
}
369+
delete node.variance;
364370
},
365371
ClassPrivateProperty(path, state) {
366372
trackComments(path.node, state);
373+
374+
// There's a @babel/generator bug such that the `readonly` modifier isn't
375+
// included in the output.
376+
const { node } = path;
377+
if (node.variance && node.variance.kind === "plus") {
378+
node.readonly = true;
379+
}
380+
delete node.variance;
367381
},
368382

369383
// All other non-leaf nodes must be processed on exit()

test.json

Whitespace-only changes.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export default class FooBar {
2+
+foo: number;
3+
+#bar: number;
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export default class FooBar {
2+
readonly foo: number;
3+
#bar: number;
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export default class FooBar {
2+
-foo: number;
3+
-#bar: number;
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export default class FooBar {
2+
foo: number;
3+
#bar: number;
4+
}

0 commit comments

Comments
 (0)