Skip to content

Commit ad3899c

Browse files
committed
fix #167
1 parent b1541e9 commit ad3899c

File tree

4 files changed

+106
-19
lines changed

4 files changed

+106
-19
lines changed

src/parser/variable.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ module.exports = {
290290
let offset;
291291
while (this.token != this.EOF) {
292292
const node = this.node();
293+
/*
293294
if (this.token == "[") {
294295
offset = null;
295296
if (encapsed) {
@@ -299,7 +300,8 @@ module.exports = {
299300
}
300301
this.expect("]") && this.next();
301302
result = node("offsetlookup", result, offset);
302-
} else if (this.token == "{" && !encapsed) {
303+
} else */
304+
if (this.token == "{" && !encapsed) {
303305
offset = this.next().read_expr();
304306
this.expect("}") && this.next();
305307
result = node("offsetlookup", result, offset);

test/debug.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
const util = require('util');
1818
const parser = require("../src/index");
1919
const ast = parser.parseEval(`
20-
true;
20+
Foo::$bar['baz']();
2121
`, {
2222
parser: {
2323
debug: true
2424
}
2525
}
2626
);
2727
console.log(
28-
util.inspect(ast, false, 5, true)
28+
util.inspect(ast, false, 10, true)
2929
);

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

Lines changed: 97 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -715,33 +715,33 @@ exports[`Test variables Variable chains 1`] = `
715715
Program {
716716
"children": Array [
717717
ExpressionStatement {
718-
"expression": StaticLookup {
719-
"kind": "staticlookup",
720-
"offset": OffsetLookup {
718+
"expression": OffsetLookup {
719+
"kind": "offsetlookup",
720+
"offset": Number {
721+
"kind": "number",
722+
"value": "2",
723+
},
724+
"what": OffsetLookup {
721725
"kind": "offsetlookup",
722726
"offset": Number {
723727
"kind": "number",
724-
"value": "2",
728+
"value": "1",
725729
},
726-
"what": OffsetLookup {
727-
"kind": "offsetlookup",
728-
"offset": Number {
729-
"kind": "number",
730-
"value": "1",
731-
},
732-
"what": Variable {
730+
"what": StaticLookup {
731+
"kind": "staticlookup",
732+
"offset": Variable {
733733
"byref": false,
734734
"curly": false,
735735
"kind": "variable",
736736
"name": "a",
737737
},
738+
"what": ClassReference {
739+
"kind": "classreference",
740+
"name": "foo",
741+
"resolution": "uqn",
742+
},
738743
},
739744
},
740-
"what": ClassReference {
741-
"kind": "classreference",
742-
"name": "foo",
743-
"resolution": "uqn",
744-
},
745745
},
746746
"kind": "expressionstatement",
747747
},
@@ -870,3 +870,84 @@ Program {
870870
"kind": "program",
871871
}
872872
`;
873+
874+
exports[`Test variables fix #167 1`] = `
875+
Program {
876+
"children": Array [
877+
ExpressionStatement {
878+
"expression": Assign {
879+
"kind": "assign",
880+
"left": Variable {
881+
"byref": false,
882+
"curly": false,
883+
"kind": "variable",
884+
"name": "var",
885+
},
886+
"operator": "=",
887+
"right": Call {
888+
"arguments": Array [],
889+
"kind": "call",
890+
"what": StaticLookup {
891+
"kind": "staticlookup",
892+
"offset": OffsetLookup {
893+
"kind": "offsetlookup",
894+
"offset": String {
895+
"isDoubleQuote": false,
896+
"kind": "string",
897+
"raw": "'baz'",
898+
"unicode": false,
899+
"value": "baz",
900+
},
901+
"what": Variable {
902+
"byref": false,
903+
"curly": false,
904+
"kind": "variable",
905+
"name": "bar",
906+
},
907+
},
908+
"what": ClassReference {
909+
"kind": "classreference",
910+
"name": "Foo",
911+
"resolution": "uqn",
912+
},
913+
},
914+
},
915+
},
916+
"kind": "expressionstatement",
917+
},
918+
ExpressionStatement {
919+
"expression": Call {
920+
"arguments": Array [],
921+
"kind": "call",
922+
"what": OffsetLookup {
923+
"kind": "offsetlookup",
924+
"offset": String {
925+
"isDoubleQuote": false,
926+
"kind": "string",
927+
"raw": "'baz'",
928+
"unicode": false,
929+
"value": "baz",
930+
},
931+
"what": StaticLookup {
932+
"kind": "staticlookup",
933+
"offset": Variable {
934+
"byref": false,
935+
"curly": false,
936+
"kind": "variable",
937+
"name": "bar",
938+
},
939+
"what": ClassReference {
940+
"kind": "classreference",
941+
"name": "Foo",
942+
"resolution": "uqn",
943+
},
944+
},
945+
},
946+
},
947+
"kind": "expressionstatement",
948+
},
949+
],
950+
"errors": Array [],
951+
"kind": "program",
952+
}
953+
`;

test/snapshot/variable.test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ describe("Test variables", function() {
1717
expect(parser.parseEval("foo::$a[1][2];")).toMatchSnapshot();
1818
});
1919

20+
it("fix #167", function() {
21+
expect(parser.parseEval("$var = Foo::{$bar['baz']}();Foo::$bar['baz']();")).toMatchSnapshot();
22+
});
23+
2024
it("Class constants", function() {
2125
expect(parser.parseEval(`
2226
static::foo();

0 commit comments

Comments
 (0)