Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ const Parser = function (lexer, ast) {
this.tok.T_STATIC,
this.tok.T_ABSTRACT,
this.tok.T_FINAL,
this.tok.T_READ_ONLY,
].map(mapIt),
),
EOS: new Map([";", this.EOF, this.tok.T_INLINE_HTML].map(mapIt)),
Expand Down
11 changes: 8 additions & 3 deletions src/parser/class.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ module.exports = {
*/
function read_variable_declaration() {
const result = this.node("property");
let readonly = false;
if (this.token === this.tok.T_READ_ONLY) {
let readonly = flags[3] === 1;
if (!readonly && this.token === this.tok.T_READ_ONLY) {
readonly = true;
this.next();
}
Expand Down Expand Up @@ -273,7 +273,7 @@ module.exports = {
* 3rd index : 0 => normal, 1 => abstract member, 2 => final member
*/
read_member_flags(asInterface) {
const result = [-1, -1, -1];
const result = [-1, -1, -1, -1];
if (this.is("T_MEMBER_FLAGS")) {
let idx = 0,
val = 0;
Expand Down Expand Up @@ -303,6 +303,10 @@ module.exports = {
idx = 2;
val = 2;
break;
case this.tok.T_READ_ONLY:
idx = 3;
val = 1;
break;
}
if (asInterface) {
if (idx === 0 && val === 2) {
Expand All @@ -326,6 +330,7 @@ module.exports = {

if (result[1] === -1) result[1] = 0;
if (result[2] === -1) result[2] = 0;
if (result[3] === -1) result[3] = 0;
return result;
},

Expand Down
48 changes: 48 additions & 0 deletions test/snapshot/__snapshots__/class.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,54 @@ Program {
}
`;

exports[`Test classes Implement readonly property with readonly before visibility 1`] = `
Program {
"children": [
Class {
"attrGroups": [],
"body": [
PropertyStatement {
"isStatic": false,
"kind": "propertystatement",
"properties": [
Property {
"attrGroups": [],
"kind": "property",
"name": Identifier {
"kind": "identifier",
"name": "test",
},
"nullable": false,
"readonly": true,
"type": TypeReference {
"kind": "typereference",
"name": "int",
"raw": "int",
},
"value": null,
},
],
"visibility": "public",
},
],
"extends": null,
"implements": null,
"isAbstract": false,
"isAnonymous": false,
"isFinal": false,
"isReadonly": false,
"kind": "class",
"name": Identifier {
"kind": "identifier",
"name": "Test",
},
},
],
"errors": [],
"kind": "program",
}
`;

exports[`Test classes Implement typed_properties_v2 / php74 1`] = `
Program {
"children": [
Expand Down
17 changes: 17 additions & 0 deletions test/snapshot/class.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,23 @@ describe("Test classes", function () {
).toMatchSnapshot();
});

it("Implement readonly property with readonly before visibility", function () {
expect(
parser.parseEval(
`
class Test {
readonly public int $test;
}
`,
{
parser: {
version: "8.1",
},
},
),
).toMatchSnapshot();
});

it("Validate usual declarations", function () {
expect(
parser.parseEval(`
Expand Down
Loading