This repository was archived by the owner on Apr 26, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 6 files changed +30
-0
lines changed
test/fixtures/convert/classes
readonly-class-properties Expand file tree Collapse file tree 6 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -361,9 +361,23 @@ const transform = {
361
361
} ,
362
362
ClassProperty ( path , state ) {
363
363
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 ;
364
370
} ,
365
371
ClassPrivateProperty ( path , state ) {
366
372
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 ;
367
381
} ,
368
382
369
383
// All other non-leaf nodes must be processed on exit()
Original file line number Diff line number Diff line change
1
+ export default class FooBar {
2
+ + foo : number ;
3
+ + #bar: number ;
4
+ }
Original file line number Diff line number Diff line change
1
+ export default class FooBar {
2
+ readonly foo : number ;
3
+ #bar: number ;
4
+ }
Original file line number Diff line number Diff line change
1
+ export default class FooBar {
2
+ - foo : number ;
3
+ - #bar: number ;
4
+ }
Original file line number Diff line number Diff line change
1
+ export default class FooBar {
2
+ foo : number ;
3
+ #bar: number ;
4
+ }
You can’t perform that action at this time.
0 commit comments