Skip to content
This repository was archived by the owner on Mar 29, 2023. It is now read-only.

Commit b73c103

Browse files
committed
glayzzle#185 - fix get_class($var)::$$$$$property;
1 parent c66df36 commit b73c103

File tree

4 files changed

+59
-2
lines changed

4 files changed

+59
-2
lines changed

src/parser/variable.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ module.exports = {
151151
what = what(name, false, false);
152152
break;
153153
case "$":
154-
this.next().expect(["{", this.tok.T_VARIABLE]);
154+
this.next().expect(["$", "{", this.tok.T_VARIABLE]);
155155
if (this.token === "{") {
156156
// $obj->${$varname}
157157
what = this.next().read_expr();

test/debug.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
const util = require('util');
1818
const parser = require("../src/index");
1919
const ast = parser.parseEval(`
20-
Foo::$bar['baz']();
20+
get_class($var)::$$$$$property;
2121
`, {
2222
parser: {
2323
debug: true

test/snapshot/__snapshots__/variable.test.js.snap

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -951,3 +951,55 @@ Program {
951951
"kind": "program",
952952
}
953953
`;
954+
955+
exports[`Test variables valid offset lookup 1`] = `
956+
Program {
957+
"children": Array [
958+
ExpressionStatement {
959+
"expression": StaticLookup {
960+
"kind": "staticlookup",
961+
"offset": Variable {
962+
"byref": false,
963+
"curly": false,
964+
"kind": "variable",
965+
"name": Variable {
966+
"byref": false,
967+
"curly": false,
968+
"kind": "variable",
969+
"name": Variable {
970+
"byref": false,
971+
"curly": false,
972+
"kind": "variable",
973+
"name": Variable {
974+
"byref": false,
975+
"curly": false,
976+
"kind": "variable",
977+
"name": "property",
978+
},
979+
},
980+
},
981+
},
982+
"what": Call {
983+
"arguments": Array [
984+
Variable {
985+
"byref": false,
986+
"curly": false,
987+
"kind": "variable",
988+
"name": "var",
989+
},
990+
],
991+
"kind": "call",
992+
"what": ClassReference {
993+
"kind": "classreference",
994+
"name": "get_class",
995+
"resolution": "uqn",
996+
},
997+
},
998+
},
999+
"kind": "expressionstatement",
1000+
},
1001+
],
1002+
"errors": Array [],
1003+
"kind": "program",
1004+
}
1005+
`;

test/snapshot/variable.test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ describe("Test variables", function() {
2121
expect(parser.parseEval("$var = Foo::{$bar['baz']}();Foo::$bar['baz']();")).toMatchSnapshot();
2222
});
2323

24+
it("valid offset lookup", function() {
25+
expect(parser.parseEval("get_class($var)::$$$$$property;")).toMatchSnapshot();
26+
});
27+
28+
2429
it("Class constants", function() {
2530
expect(parser.parseEval(`
2631
static::foo();

0 commit comments

Comments
 (0)