File tree Expand file tree Collapse file tree 3 files changed +77
-2
lines changed Expand file tree Collapse file tree 3 files changed +77
-2
lines changed Original file line number Diff line number Diff line change @@ -257,7 +257,6 @@ module.exports = {
257
257
let readonly = false ;
258
258
let attrs = [ ] ;
259
259
if ( this . token === this . tok . T_ATTRIBUTE ) attrs = this . read_attr_list ( ) ;
260
- const flags = this . read_promoted ( ) ;
261
260
262
261
if ( this . version >= 801 && this . token === this . tok . T_READ_ONLY ) {
263
262
if ( is_class_constructor ) {
@@ -270,6 +269,23 @@ module.exports = {
270
269
}
271
270
}
272
271
272
+ const flags = this . read_promoted ( ) ;
273
+
274
+ if (
275
+ ! readonly &&
276
+ this . version >= 801 &&
277
+ this . token === this . tok . T_READ_ONLY
278
+ ) {
279
+ if ( is_class_constructor ) {
280
+ this . next ( ) ;
281
+ readonly = true ;
282
+ } else {
283
+ this . raiseError (
284
+ "readonly properties can be used only on class constructor"
285
+ ) ;
286
+ }
287
+ }
288
+
273
289
if ( this . token === "?" ) {
274
290
this . next ( ) ;
275
291
nullable = true ;
Original file line number Diff line number Diff line change @@ -1070,6 +1070,61 @@ Program {
1070
1070
" name" : " Bob" ,
1071
1071
},
1072
1072
},
1073
+ Class {
1074
+ " attrGroups" : Array [],
1075
+ " body" : Array [
1076
+ Method {
1077
+ " arguments" : Array [
1078
+ Parameter {
1079
+ " attrGroups" : Array [],
1080
+ " byref" : false ,
1081
+ " flags" : 1 ,
1082
+ " kind" : " parameter" ,
1083
+ " name" : Identifier {
1084
+ " kind" : " identifier" ,
1085
+ " name" : " id" ,
1086
+ },
1087
+ " nullable" : false ,
1088
+ " readonly" : true ,
1089
+ " type" : TypeReference {
1090
+ " kind" : " typereference" ,
1091
+ " name" : " int" ,
1092
+ " raw" : " int" ,
1093
+ },
1094
+ " value" : null ,
1095
+ " variadic" : false ,
1096
+ },
1097
+ ],
1098
+ " attrGroups" : Array [],
1099
+ " body" : Block {
1100
+ " children" : Array [],
1101
+ " kind" : " block" ,
1102
+ },
1103
+ " byref" : false ,
1104
+ " isAbstract" : false ,
1105
+ " isFinal" : false ,
1106
+ " isStatic" : false ,
1107
+ " kind" : " method" ,
1108
+ " name" : Identifier {
1109
+ " kind" : " identifier" ,
1110
+ " name" : " __construct" ,
1111
+ },
1112
+ " nullable" : false ,
1113
+ " type" : null ,
1114
+ " visibility" : " public" ,
1115
+ },
1116
+ ],
1117
+ " extends" : null ,
1118
+ " implements" : null ,
1119
+ " isAbstract" : false ,
1120
+ " isAnonymous" : false ,
1121
+ " isFinal" : false ,
1122
+ " kind" : " class" ,
1123
+ " name" : Identifier {
1124
+ " kind" : " identifier" ,
1125
+ " name" : " Bob2" ,
1126
+ },
1127
+ },
1073
1128
],
1074
1129
" errors" : Array [],
1075
1130
" kind" : " program" ,
Original file line number Diff line number Diff line change @@ -167,7 +167,11 @@ describe("Test classes", function () {
167
167
`
168
168
class Bob {
169
169
public function __construct(public readonly int $id) {}
170
- }` ,
170
+ }
171
+ class Bob2 {
172
+ public function __construct(readonly public int $id) {}
173
+ }
174
+ ` ,
171
175
{
172
176
parser : {
173
177
version : "8.1" ,
You can’t perform that action at this time.
0 commit comments