Skip to content

Commit

Permalink
interfact support
Browse files Browse the repository at this point in the history
  • Loading branch information
genintho committed Dec 2, 2024
1 parent 4ad9385 commit 3f2cfc3
Show file tree
Hide file tree
Showing 14 changed files with 359 additions and 12 deletions.
7 changes: 5 additions & 2 deletions src/parser/class.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ module.exports = {

// Property is using a hook to define getter/setters
if (this.token === "{") {
this.next();
property_hooks = this.read_property_hooks();
} else {
this.expect([";", ","]);
Expand Down Expand Up @@ -252,6 +251,8 @@ module.exports = {
if (this.version < 804) {
this.raiseError("Parse Error: Typed Class Constants requires PHP 8.4+");
}
this.expect("{");
this.next();

const hooks = [];

Expand Down Expand Up @@ -548,9 +549,11 @@ module.exports = {
this.next();
}
attrs = [];
} else if (this.token === this.tok.T_STRING) {
result.push(this.read_variable_list(flags, attrs));
} else {
// raise an error
this.error([this.tok.T_CONST, this.tok.T_FUNCTION]);
this.error([this.tok.T_CONST, this.tok.T_FUNCTION, this.tok.T_STRING]);
this.next();
}
}
Expand Down
2 changes: 2 additions & 0 deletions test/snapshot/__snapshots__/acid.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,8 @@ Program {
"visibility": "",
},
PropertyStatement {
"isAbstract": false,
"isFinal": false,
"isStatic": false,
"kind": "propertystatement",
"loc": Location {
Expand Down
8 changes: 8 additions & 0 deletions test/snapshot/__snapshots__/attributes.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,8 @@ Program {
"attrGroups": [],
"body": [
PropertyStatement {
"isAbstract": false,
"isFinal": false,
"isStatic": false,
"kind": "propertystatement",
"properties": [
Expand Down Expand Up @@ -400,6 +402,8 @@ Program {
"visibility": "public",
},
PropertyStatement {
"isAbstract": false,
"isFinal": false,
"isStatic": false,
"kind": "propertystatement",
"properties": [
Expand Down Expand Up @@ -435,6 +439,8 @@ Program {
"visibility": "private",
},
PropertyStatement {
"isAbstract": false,
"isFinal": false,
"isStatic": false,
"kind": "propertystatement",
"properties": [
Expand Down Expand Up @@ -2569,6 +2575,8 @@ Program {
"attrGroups": [],
"body": [
PropertyStatement {
"isAbstract": false,
"isFinal": false,
"isStatic": false,
"kind": "propertystatement",
"properties": [
Expand Down
18 changes: 18 additions & 0 deletions test/snapshot/__snapshots__/class.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ Program {
],
},
PropertyStatement {
"isAbstract": false,
"isFinal": false,
"isStatic": false,
"kind": "propertystatement",
"leadingComments": [
Expand Down Expand Up @@ -462,6 +464,8 @@ Program {
"attrGroups": [],
"body": [
PropertyStatement {
"isAbstract": false,
"isFinal": false,
"isStatic": false,
"kind": "propertystatement",
"properties": [
Expand Down Expand Up @@ -511,6 +515,8 @@ Program {
"attrGroups": [],
"body": [
PropertyStatement {
"isAbstract": false,
"isFinal": false,
"isStatic": false,
"kind": "propertystatement",
"properties": [
Expand Down Expand Up @@ -538,6 +544,8 @@ Program {
"visibility": "public",
},
PropertyStatement {
"isAbstract": false,
"isFinal": false,
"isStatic": true,
"kind": "propertystatement",
"properties": [
Expand Down Expand Up @@ -598,6 +606,8 @@ Program {
"attrGroups": [],
"body": [
PropertyStatement {
"isAbstract": false,
"isFinal": false,
"isStatic": true,
"kind": "propertystatement",
"properties": [
Expand Down Expand Up @@ -1196,6 +1206,8 @@ Program {
"visibility": "",
},
PropertyStatement {
"isAbstract": false,
"isFinal": false,
"isStatic": true,
"kind": "propertystatement",
"properties": [
Expand Down Expand Up @@ -1372,6 +1384,8 @@ Program {
"visibility": "public",
},
PropertyStatement {
"isAbstract": false,
"isFinal": false,
"isStatic": false,
"kind": "propertystatement",
"properties": [
Expand All @@ -1392,6 +1406,8 @@ Program {
"visibility": "protected",
},
PropertyStatement {
"isAbstract": false,
"isFinal": false,
"isStatic": false,
"kind": "propertystatement",
"properties": [
Expand Down Expand Up @@ -1769,6 +1785,8 @@ Program {
"attrGroups": [],
"body": [
PropertyStatement {
"isAbstract": false,
"isFinal": false,
"isStatic": false,
"kind": "propertystatement",
"properties": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ Program {
}
`;

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

exports[`classpropertyhooks setter block form with explicit typed $value 1`] = `
Program {
Expand Down
4 changes: 4 additions & 0 deletions test/snapshot/__snapshots__/comment.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1846,6 +1846,8 @@ Program {
"attrGroups": [],
"body": [
PropertyStatement {
"isAbstract": false,
"isFinal": false,
"isStatic": false,
"kind": "propertystatement",
"leadingComments": [
Expand Down Expand Up @@ -1892,6 +1894,8 @@ Program {
"visibility": "protected",
},
PropertyStatement {
"isAbstract": false,
"isFinal": false,
"isStatic": true,
"kind": "propertystatement",
"leadingComments": [
Expand Down
62 changes: 53 additions & 9 deletions test/snapshot/__snapshots__/graceful.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,34 @@ Program {
"children": [
Interface {
"attrGroups": [],
"body": [],
"body": [
PropertyStatement {
"isAbstract": false,
"isFinal": false,
"isStatic": false,
"kind": "propertystatement",
"properties": [
Property {
"attrGroups": [],
"hooks": null,
"kind": "property",
"name": Identifier {
"kind": "identifier",
"name": "",
},
"nullable": false,
"readonly": false,
"type": Name {
"kind": "name",
"name": "baz",
"resolution": "uqn",
},
"value": null,
},
],
"visibility": "",
},
],
"extends": null,
"kind": "interface",
"name": Identifier {
Expand All @@ -22,25 +49,34 @@ Program {
"message": "Parse Error : syntax error, unexpected 'implement' (T_STRING), expecting '{' on line 1",
"token": "'implement' (T_STRING)",
},
Error {
"expected": 222,
"kind": "error",
"line": 1,
"message": "Parse Error : syntax error, unexpected '{', expecting T_VARIABLE on line 1",
"token": "'{'",
},
Error {
"expected": [
198,
182,
",",
";",
"=",
"{",
],
"kind": "error",
"line": 1,
"message": "Parse Error : syntax error, unexpected 'baz' (T_STRING) on line 1",
"token": "'baz' (T_STRING)",
"message": "Parse Error : syntax error, unexpected '}' on line 1",
"token": "'}'",
},
Error {
"expected": [
198,
182,
";",
",",
],
"kind": "error",
"line": 1,
"message": "Parse Error : syntax error, unexpected '{' on line 1",
"token": "'{'",
"message": "Parse Error : syntax error, unexpected '}' on line 1",
"token": "'}'",
},
],
"kind": "program",
Expand Down Expand Up @@ -296,6 +332,8 @@ Program {
"attrGroups": [],
"body": [
PropertyStatement {
"isAbstract": false,
"isFinal": false,
"isStatic": false,
"kind": "propertystatement",
"properties": [
Expand All @@ -320,6 +358,8 @@ Program {
"visibility": "",
},
PropertyStatement {
"isAbstract": false,
"isFinal": false,
"isStatic": false,
"kind": "propertystatement",
"properties": [
Expand Down Expand Up @@ -886,6 +926,8 @@ Program {
Trait {
"body": [
PropertyStatement {
"isAbstract": false,
"isFinal": false,
"isStatic": false,
"kind": "propertystatement",
"properties": [
Expand All @@ -910,6 +952,8 @@ Program {
"visibility": "",
},
PropertyStatement {
"isAbstract": false,
"isFinal": false,
"isStatic": false,
"kind": "propertystatement",
"properties": [
Expand Down
2 changes: 2 additions & 0 deletions test/snapshot/__snapshots__/heredoc.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1716,6 +1716,8 @@ FOOBAR",
"visibility": "",
},
PropertyStatement {
"isAbstract": false,
"isFinal": false,
"isStatic": false,
"kind": "propertystatement",
"properties": [
Expand Down
Loading

0 comments on commit 3f2cfc3

Please sign in to comment.