File tree 12 files changed +176
-13
lines changed
swc_ecma_parser/tests/typescript/class/override
swc_ecma_transforms/tests/fixture/legacy-only/issues/862
swc_ecma_transforms_typescript/src
12 files changed +176
-13
lines changed Original file line number Diff line number Diff line change @@ -1466,6 +1466,12 @@ where
1466
1466
formatting_space ! ( ) ;
1467
1467
}
1468
1468
}
1469
+
1470
+ if n. is_override {
1471
+ keyword ! ( "override" ) ;
1472
+ space ! ( )
1473
+ }
1474
+
1469
1475
match n. kind {
1470
1476
MethodKind :: Method => {
1471
1477
if n. function . is_async {
@@ -1544,6 +1550,11 @@ where
1544
1550
space ! ( ) ;
1545
1551
}
1546
1552
1553
+ if n. is_override {
1554
+ keyword ! ( "override" ) ;
1555
+ space ! ( )
1556
+ }
1557
+
1547
1558
if n. readonly {
1548
1559
keyword ! ( "readonly" ) ;
1549
1560
space ! ( ) ;
@@ -1590,15 +1601,18 @@ where
1590
1601
emit ! ( dec)
1591
1602
}
1592
1603
1593
- if n. accessibility != Some ( Accessibility :: Public ) {
1594
- self . emit_accessibility ( n. accessibility ) ?;
1595
- }
1604
+ self . emit_accessibility ( n. accessibility ) ?;
1596
1605
1597
1606
if n. is_static {
1598
1607
keyword ! ( "static" ) ;
1599
1608
space ! ( ) ;
1600
1609
}
1601
1610
1611
+ if n. is_override {
1612
+ keyword ! ( "override" ) ;
1613
+ space ! ( )
1614
+ }
1615
+
1602
1616
if n. readonly {
1603
1617
keyword ! ( "readonly" ) ;
1604
1618
space ! ( )
Original file line number Diff line number Diff line change
1
+ class MyClass extends Base {
2
+ public override method ( param : number ) : string {
3
+ }
4
+ }
Original file line number Diff line number Diff line change
1
+ class MyClass extends Base {
2
+ public override method ( param : number ) : string { }
3
+ }
Original file line number Diff line number Diff line change
1
+ class MyClass extends Base { public override method ( param :number ) :string { } }
Original file line number Diff line number Diff line change 1
- class MyClass {
1
+ class MyClass extends Base {
2
2
prop1 ?: string ;
3
3
prop2 ! : string ;
4
4
#prop3?: string ;
5
5
#prop4?: string = "test" ;
6
6
static readonly prop5 ! : string ;
7
7
readonly #prop6 = "asdf" ;
8
+ public override readonly prop7 = 5 ;
9
+ override readonly #prop8 = 5 ;
8
10
}
Original file line number Diff line number Diff line change 1
- class MyClass {
1
+ class MyClass extends Base {
2
2
prop1 ?: string ;
3
3
prop2 ! : string ;
4
4
#prop3?: string ;
5
5
#prop4?: string = "test" ;
6
6
static readonly prop5 ! : string ;
7
7
readonly #prop6 = "asdf" ;
8
+ public override readonly prop7 = 5 ;
9
+ override readonly #prop8 = 5 ;
8
10
}
Original file line number Diff line number Diff line change 1
- class MyClass { prop1 ?: string ; prop2 ! : string ; #prop3?: string ; #prop4?: string = "test" ; static readonly prop5 ! : string ; readonly #prop6= "asdf" }
1
+ class MyClass extends Base { prop1 ?: string ; prop2 ! : string ; #prop3?: string ; #prop4?: string = "test" ; static readonly prop5 ! : string ; readonly #prop6= "asdf" ; public override readonly prop7 = 5 ; override readonly #prop8 = 5 }
Original file line number Diff line number Diff line change
1
+ class C extends B {
2
+ override prop = 5 ;
3
+ override method ( ) {
4
+ }
5
+ }
Original file line number Diff line number Diff line change
1
+ {
2
+ "type" : " Script" ,
3
+ "span" : {
4
+ "start" : 1 ,
5
+ "end" : 69 ,
6
+ "ctxt" : 0
7
+ },
8
+ "body" : [
9
+ {
10
+ "type" : " ClassDeclaration" ,
11
+ "identifier" : {
12
+ "type" : " Identifier" ,
13
+ "span" : {
14
+ "start" : 7 ,
15
+ "end" : 8 ,
16
+ "ctxt" : 0
17
+ },
18
+ "value" : " C" ,
19
+ "optional" : false
20
+ },
21
+ "declare" : false ,
22
+ "span" : {
23
+ "start" : 1 ,
24
+ "end" : 69 ,
25
+ "ctxt" : 0
26
+ },
27
+ "decorators" : [],
28
+ "body" : [
29
+ {
30
+ "type" : " ClassProperty" ,
31
+ "span" : {
32
+ "start" : 23 ,
33
+ "end" : 41 ,
34
+ "ctxt" : 0
35
+ },
36
+ "key" : {
37
+ "type" : " Identifier" ,
38
+ "span" : {
39
+ "start" : 32 ,
40
+ "end" : 36 ,
41
+ "ctxt" : 0
42
+ },
43
+ "value" : " prop" ,
44
+ "optional" : false
45
+ },
46
+ "value" : {
47
+ "type" : " NumericLiteral" ,
48
+ "span" : {
49
+ "start" : 39 ,
50
+ "end" : 40 ,
51
+ "ctxt" : 0
52
+ },
53
+ "value" : 5.0 ,
54
+ "raw" : " 5"
55
+ },
56
+ "typeAnnotation" : null ,
57
+ "isStatic" : false ,
58
+ "decorators" : [],
59
+ "accessibility" : null ,
60
+ "isAbstract" : false ,
61
+ "isOptional" : false ,
62
+ "isOverride" : true ,
63
+ "readonly" : false ,
64
+ "declare" : false ,
65
+ "definite" : false
66
+ },
67
+ {
68
+ "type" : " ClassMethod" ,
69
+ "span" : {
70
+ "start" : 44 ,
71
+ "end" : 67 ,
72
+ "ctxt" : 0
73
+ },
74
+ "key" : {
75
+ "type" : " Identifier" ,
76
+ "span" : {
77
+ "start" : 53 ,
78
+ "end" : 59 ,
79
+ "ctxt" : 0
80
+ },
81
+ "value" : " method" ,
82
+ "optional" : false
83
+ },
84
+ "function" : {
85
+ "params" : [],
86
+ "decorators" : [],
87
+ "span" : {
88
+ "start" : 44 ,
89
+ "end" : 67 ,
90
+ "ctxt" : 0
91
+ },
92
+ "body" : {
93
+ "type" : " BlockStatement" ,
94
+ "span" : {
95
+ "start" : 62 ,
96
+ "end" : 67 ,
97
+ "ctxt" : 0
98
+ },
99
+ "stmts" : []
100
+ },
101
+ "generator" : false ,
102
+ "async" : false ,
103
+ "typeParameters" : null ,
104
+ "returnType" : null
105
+ },
106
+ "kind" : " method" ,
107
+ "isStatic" : false ,
108
+ "accessibility" : null ,
109
+ "isAbstract" : false ,
110
+ "isOptional" : false ,
111
+ "isOverride" : true
112
+ }
113
+ ],
114
+ "superClass" : {
115
+ "type" : " Identifier" ,
116
+ "span" : {
117
+ "start" : 17 ,
118
+ "end" : 18 ,
119
+ "ctxt" : 0
120
+ },
121
+ "value" : " B" ,
122
+ "optional" : false
123
+ },
124
+ "isAbstract" : false ,
125
+ "typeParams" : null ,
126
+ "superTypeParams" : null ,
127
+ "implements" : []
128
+ }
129
+ ],
130
+ "interpreter" : null
131
+ }
Original file line number Diff line number Diff line change 1
1
export class Product extends TimestampedEntity {
2
- id ! : string ;
3
- price ! : number ;
4
- type ! : ProductType ;
5
- productEntityId ! : string ;
6
- /* ANCHOR: Relations ------------------------------------------------------ */ orders ! : Order [ ] ;
7
- discounts ! : Discount [ ] ;
2
+ public id ! : string ;
3
+ public price ! : number ;
4
+ public type ! : ProductType ;
5
+ public productEntityId ! : string ;
6
+ /* ANCHOR: Relations ------------------------------------------------------ */ public orders ! : Order [ ] ;
7
+ public discounts ! : Discount [ ] ;
8
8
}
9
9
_ts_decorate ( [
10
10
PrimaryGeneratedColumn ( "uuid" )
Original file line number Diff line number Diff line change 1
1
export class Product extends TimestampedEntity {
2
- id ! : string ;
2
+ public id ! : string ;
3
3
}
4
4
_ts_decorate ( [
5
5
PrimaryGeneratedColumn ( "uuid" )
Original file line number Diff line number Diff line change @@ -137,6 +137,7 @@ impl VisitMut for StripType {
137
137
138
138
fn visit_mut_class_method ( & mut self , n : & mut ClassMethod ) {
139
139
n. accessibility = None ;
140
+ n. is_override = false ;
140
141
n. visit_mut_children_with ( self ) ;
141
142
}
142
143
You can’t perform that action at this time.
0 commit comments