Skip to content
Closed
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
9 changes: 9 additions & 0 deletions src/parser/variable.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,15 @@ module.exports = {
this.next();
what = what(name, false);
break;
case this.tok.T_CLASS:
if (!is_static_lookup) {
this.error();
}
what = this.node("identifier");
name = this.text();
this.next();
what = what(name, false);
break;
case "$":
what = this.node();
this.next().expect(["$", "{", this.tok.T_VARIABLE]);
Expand Down
53 changes: 53 additions & 0 deletions test/snapshot/__snapshots__/variable.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,59 @@ Program {
}
`;

exports[`Test variables class keyword on variables 1`] = `
Program {
"children": [
ExpressionStatement {
"expression": StaticLookup {
"kind": "staticlookup",
"offset": Identifier {
"kind": "identifier",
"name": "class",
},
"what": PropertyLookup {
"kind": "propertylookup",
"offset": Identifier {
"kind": "identifier",
"name": "classProp",
},
"what": Variable {
"curly": false,
"kind": "variable",
"name": "classVariable",
},
},
},
"kind": "expressionstatement",
},
ExpressionStatement {
"expression": StaticLookup {
"kind": "staticlookup",
"offset": Identifier {
"kind": "identifier",
"name": "class",
},
"what": OffsetLookup {
"kind": "offsetlookup",
"offset": Number {
"kind": "number",
"value": "0",
},
"what": Variable {
"curly": false,
"kind": "variable",
"name": "arrayVariable",
},
},
},
"kind": "expressionstatement",
},
],
"errors": [],
"kind": "program",
}
`;

exports[`Test variables default variables 1`] = `
Program {
"children": [
Expand Down
8 changes: 8 additions & 0 deletions test/snapshot/variable.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,12 @@ describe("Test variables", function () {
it("simple variable #4", function () {
expect(parser.parseEval("$var = $$$var;")).toMatchSnapshot();
});
it("class keyword on variables", function () {
expect(
parser.parseEval(
`$classVariable->classProp::class;
$arrayVariable[0]::class;`,
),
).toMatchSnapshot();
});
});