Skip to content

Commit 3f2cfc3

Browse files
committed
interfact support
1 parent 4ad9385 commit 3f2cfc3

14 files changed

+359
-12
lines changed

src/parser/class.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,6 @@ module.exports = {
213213

214214
// Property is using a hook to define getter/setters
215215
if (this.token === "{") {
216-
this.next();
217216
property_hooks = this.read_property_hooks();
218217
} else {
219218
this.expect([";", ","]);
@@ -252,6 +251,8 @@ module.exports = {
252251
if (this.version < 804) {
253252
this.raiseError("Parse Error: Typed Class Constants requires PHP 8.4+");
254253
}
254+
this.expect("{");
255+
this.next();
255256

256257
const hooks = [];
257258

@@ -548,9 +549,11 @@ module.exports = {
548549
this.next();
549550
}
550551
attrs = [];
552+
} else if (this.token === this.tok.T_STRING) {
553+
result.push(this.read_variable_list(flags, attrs));
551554
} else {
552555
// raise an error
553-
this.error([this.tok.T_CONST, this.tok.T_FUNCTION]);
556+
this.error([this.tok.T_CONST, this.tok.T_FUNCTION, this.tok.T_STRING]);
554557
this.next();
555558
}
556559
}

test/snapshot/__snapshots__/acid.test.js.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,8 @@ Program {
831831
"visibility": "",
832832
},
833833
PropertyStatement {
834+
"isAbstract": false,
835+
"isFinal": false,
834836
"isStatic": false,
835837
"kind": "propertystatement",
836838
"loc": Location {

test/snapshot/__snapshots__/attributes.test.js.snap

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,8 @@ Program {
365365
"attrGroups": [],
366366
"body": [
367367
PropertyStatement {
368+
"isAbstract": false,
369+
"isFinal": false,
368370
"isStatic": false,
369371
"kind": "propertystatement",
370372
"properties": [
@@ -400,6 +402,8 @@ Program {
400402
"visibility": "public",
401403
},
402404
PropertyStatement {
405+
"isAbstract": false,
406+
"isFinal": false,
403407
"isStatic": false,
404408
"kind": "propertystatement",
405409
"properties": [
@@ -435,6 +439,8 @@ Program {
435439
"visibility": "private",
436440
},
437441
PropertyStatement {
442+
"isAbstract": false,
443+
"isFinal": false,
438444
"isStatic": false,
439445
"kind": "propertystatement",
440446
"properties": [
@@ -2569,6 +2575,8 @@ Program {
25692575
"attrGroups": [],
25702576
"body": [
25712577
PropertyStatement {
2578+
"isAbstract": false,
2579+
"isFinal": false,
25722580
"isStatic": false,
25732581
"kind": "propertystatement",
25742582
"properties": [

test/snapshot/__snapshots__/class.test.js.snap

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ Program {
4040
],
4141
},
4242
PropertyStatement {
43+
"isAbstract": false,
44+
"isFinal": false,
4345
"isStatic": false,
4446
"kind": "propertystatement",
4547
"leadingComments": [
@@ -462,6 +464,8 @@ Program {
462464
"attrGroups": [],
463465
"body": [
464466
PropertyStatement {
467+
"isAbstract": false,
468+
"isFinal": false,
465469
"isStatic": false,
466470
"kind": "propertystatement",
467471
"properties": [
@@ -511,6 +515,8 @@ Program {
511515
"attrGroups": [],
512516
"body": [
513517
PropertyStatement {
518+
"isAbstract": false,
519+
"isFinal": false,
514520
"isStatic": false,
515521
"kind": "propertystatement",
516522
"properties": [
@@ -538,6 +544,8 @@ Program {
538544
"visibility": "public",
539545
},
540546
PropertyStatement {
547+
"isAbstract": false,
548+
"isFinal": false,
541549
"isStatic": true,
542550
"kind": "propertystatement",
543551
"properties": [
@@ -598,6 +606,8 @@ Program {
598606
"attrGroups": [],
599607
"body": [
600608
PropertyStatement {
609+
"isAbstract": false,
610+
"isFinal": false,
601611
"isStatic": true,
602612
"kind": "propertystatement",
603613
"properties": [
@@ -1196,6 +1206,8 @@ Program {
11961206
"visibility": "",
11971207
},
11981208
PropertyStatement {
1209+
"isAbstract": false,
1210+
"isFinal": false,
11991211
"isStatic": true,
12001212
"kind": "propertystatement",
12011213
"properties": [
@@ -1372,6 +1384,8 @@ Program {
13721384
"visibility": "public",
13731385
},
13741386
PropertyStatement {
1387+
"isAbstract": false,
1388+
"isFinal": false,
13751389
"isStatic": false,
13761390
"kind": "propertystatement",
13771391
"properties": [
@@ -1392,6 +1406,8 @@ Program {
13921406
"visibility": "protected",
13931407
},
13941408
PropertyStatement {
1409+
"isAbstract": false,
1410+
"isFinal": false,
13951411
"isStatic": false,
13961412
"kind": "propertystatement",
13971413
"properties": [
@@ -1769,6 +1785,8 @@ Program {
17691785
"attrGroups": [],
17701786
"body": [
17711787
PropertyStatement {
1788+
"isAbstract": false,
1789+
"isFinal": false,
17721790
"isStatic": false,
17731791
"kind": "propertystatement",
17741792
"properties": [

test/snapshot/__snapshots__/classpropertyhooks.test.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ Program {
750750
}
751751
`;
752752

753-
exports[`classpropertyhooks not supported in php < 8.4 1`] = `"Parse Error: Typed Class Constants requires PHP 8.4+ on line 3"`;
753+
exports[`classpropertyhooks not supported in php < 8.4 1`] = `"Parse Error: Typed Class Constants requires PHP 8.4+ on line 2"`;
754754

755755
exports[`classpropertyhooks setter block form with explicit typed $value 1`] = `
756756
Program {

test/snapshot/__snapshots__/comment.test.js.snap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1846,6 +1846,8 @@ Program {
18461846
"attrGroups": [],
18471847
"body": [
18481848
PropertyStatement {
1849+
"isAbstract": false,
1850+
"isFinal": false,
18491851
"isStatic": false,
18501852
"kind": "propertystatement",
18511853
"leadingComments": [
@@ -1892,6 +1894,8 @@ Program {
18921894
"visibility": "protected",
18931895
},
18941896
PropertyStatement {
1897+
"isAbstract": false,
1898+
"isFinal": false,
18951899
"isStatic": true,
18961900
"kind": "propertystatement",
18971901
"leadingComments": [

test/snapshot/__snapshots__/graceful.test.js.snap

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,34 @@ Program {
55
"children": [
66
Interface {
77
"attrGroups": [],
8-
"body": [],
8+
"body": [
9+
PropertyStatement {
10+
"isAbstract": false,
11+
"isFinal": false,
12+
"isStatic": false,
13+
"kind": "propertystatement",
14+
"properties": [
15+
Property {
16+
"attrGroups": [],
17+
"hooks": null,
18+
"kind": "property",
19+
"name": Identifier {
20+
"kind": "identifier",
21+
"name": "",
22+
},
23+
"nullable": false,
24+
"readonly": false,
25+
"type": Name {
26+
"kind": "name",
27+
"name": "baz",
28+
"resolution": "uqn",
29+
},
30+
"value": null,
31+
},
32+
],
33+
"visibility": "",
34+
},
35+
],
936
"extends": null,
1037
"kind": "interface",
1138
"name": Identifier {
@@ -22,25 +49,34 @@ Program {
2249
"message": "Parse Error : syntax error, unexpected 'implement' (T_STRING), expecting '{' on line 1",
2350
"token": "'implement' (T_STRING)",
2451
},
52+
Error {
53+
"expected": 222,
54+
"kind": "error",
55+
"line": 1,
56+
"message": "Parse Error : syntax error, unexpected '{', expecting T_VARIABLE on line 1",
57+
"token": "'{'",
58+
},
2559
Error {
2660
"expected": [
27-
198,
28-
182,
61+
",",
62+
";",
63+
"=",
64+
"{",
2965
],
3066
"kind": "error",
3167
"line": 1,
32-
"message": "Parse Error : syntax error, unexpected 'baz' (T_STRING) on line 1",
33-
"token": "'baz' (T_STRING)",
68+
"message": "Parse Error : syntax error, unexpected '}' on line 1",
69+
"token": "'}'",
3470
},
3571
Error {
3672
"expected": [
37-
198,
38-
182,
73+
";",
74+
",",
3975
],
4076
"kind": "error",
4177
"line": 1,
42-
"message": "Parse Error : syntax error, unexpected '{' on line 1",
43-
"token": "'{'",
78+
"message": "Parse Error : syntax error, unexpected '}' on line 1",
79+
"token": "'}'",
4480
},
4581
],
4682
"kind": "program",
@@ -296,6 +332,8 @@ Program {
296332
"attrGroups": [],
297333
"body": [
298334
PropertyStatement {
335+
"isAbstract": false,
336+
"isFinal": false,
299337
"isStatic": false,
300338
"kind": "propertystatement",
301339
"properties": [
@@ -320,6 +358,8 @@ Program {
320358
"visibility": "",
321359
},
322360
PropertyStatement {
361+
"isAbstract": false,
362+
"isFinal": false,
323363
"isStatic": false,
324364
"kind": "propertystatement",
325365
"properties": [
@@ -886,6 +926,8 @@ Program {
886926
Trait {
887927
"body": [
888928
PropertyStatement {
929+
"isAbstract": false,
930+
"isFinal": false,
889931
"isStatic": false,
890932
"kind": "propertystatement",
891933
"properties": [
@@ -910,6 +952,8 @@ Program {
910952
"visibility": "",
911953
},
912954
PropertyStatement {
955+
"isAbstract": false,
956+
"isFinal": false,
913957
"isStatic": false,
914958
"kind": "propertystatement",
915959
"properties": [

test/snapshot/__snapshots__/heredoc.test.js.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1716,6 +1716,8 @@ FOOBAR",
17161716
"visibility": "",
17171717
},
17181718
PropertyStatement {
1719+
"isAbstract": false,
1720+
"isFinal": false,
17191721
"isStatic": false,
17201722
"kind": "propertystatement",
17211723
"properties": [

0 commit comments

Comments
 (0)