Skip to content
Merged
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
4 changes: 4 additions & 0 deletions src/parser/expr.js
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,10 @@ module.exports = {
this.error();
}
right = this.read_new_expr();
} else if (this.token === "(") {
right = this.next().read_expr();
this.expect(")") && this.next();
right = this.recursive_variable_chain_scan(right, false, false);
} else {
right = this.read_variable(false, false);
}
Expand Down
212 changes: 212 additions & 0 deletions test/snapshot/__snapshots__/byref.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,218 @@ Program {
}
`;

exports[`byref propertylookup #2 1`] = `
Program {
"children": [
ExpressionStatement {
"expression": AssignRef {
"kind": "assignref",
"left": Variable {
"curly": false,
"kind": "variable",
"name": "var",
},
"right": PropertyLookup {
"kind": "propertylookup",
"offset": Identifier {
"kind": "identifier",
"name": "test",
},
"what": Variable {
"curly": false,
"kind": "variable",
"name": "var",
},
},
},
"kind": "expressionstatement",
},
],
"errors": [],
"kind": "program",
}
`;

exports[`byref propertylookup #3 - method call 1`] = `
Program {
"children": [
ExpressionStatement {
"expression": AssignRef {
"kind": "assignref",
"left": Variable {
"curly": false,
"kind": "variable",
"name": "var",
},
"right": Call {
"arguments": [],
"kind": "call",
"what": PropertyLookup {
"kind": "propertylookup",
"offset": Identifier {
"kind": "identifier",
"name": "method",
},
"what": Variable {
"curly": false,
"kind": "variable",
"name": "var",
},
},
},
},
"kind": "expressionstatement",
},
],
"errors": [],
"kind": "program",
}
`;

exports[`byref propertylookup #4 - chained 1`] = `
Program {
"children": [
ExpressionStatement {
"expression": AssignRef {
"kind": "assignref",
"left": Variable {
"curly": false,
"kind": "variable",
"name": "var",
},
"right": PropertyLookup {
"kind": "propertylookup",
"offset": Identifier {
"kind": "identifier",
"name": "nested",
},
"what": PropertyLookup {
"kind": "propertylookup",
"offset": Identifier {
"kind": "identifier",
"name": "prop",
},
"what": Variable {
"curly": false,
"kind": "variable",
"name": "var",
},
},
},
},
"kind": "expressionstatement",
},
],
"errors": [],
"kind": "program",
}
`;

exports[`byref propertylookup #5 - offset lookup 1`] = `
Program {
"children": [
ExpressionStatement {
"expression": AssignRef {
"kind": "assignref",
"left": Variable {
"curly": false,
"kind": "variable",
"name": "var",
},
"right": OffsetLookup {
"kind": "offsetlookup",
"offset": Variable {
"curly": false,
"kind": "variable",
"name": "key",
},
"what": Variable {
"curly": false,
"kind": "variable",
"name": "var",
},
},
},
"kind": "expressionstatement",
},
],
"errors": [],
"kind": "program",
}
`;

exports[`byref propertylookup #6 - static property 1`] = `
Program {
"children": [
ExpressionStatement {
"expression": AssignRef {
"kind": "assignref",
"left": Variable {
"curly": false,
"kind": "variable",
"name": "var",
},
"right": StaticLookup {
"kind": "staticlookup",
"offset": Variable {
"curly": false,
"kind": "variable",
"name": "prop",
},
"what": Variable {
"curly": false,
"kind": "variable",
"name": "var",
},
},
},
"kind": "expressionstatement",
},
],
"errors": [],
"kind": "program",
}
`;

exports[`byref propertylookup #7 - expr in parens 1`] = `
Program {
"children": [
ExpressionStatement {
"expression": AssignRef {
"kind": "assignref",
"left": Variable {
"curly": false,
"kind": "variable",
"name": "var",
},
"right": PropertyLookup {
"kind": "propertylookup",
"offset": Identifier {
"kind": "identifier",
"name": "test",
},
"what": PropertyLookup {
"kind": "propertylookup",
"offset": Identifier {
"kind": "identifier",
"name": "prop",
},
"what": Variable {
"curly": false,
"kind": "variable",
"name": "obj",
},
},
},
},
"kind": "expressionstatement",
},
],
"errors": [],
"kind": "program",
}
`;

exports[`byref propertylookup 1`] = `
Program {
"children": [
Expand Down
17 changes: 16 additions & 1 deletion test/snapshot/byref.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,24 @@ describe("byref", () => {
it("propertylookup", () => {
expect(parser.parseEval("$var = &$var->test;")).toMatchSnapshot();
});
it.skip("propertylookup #2", () => {
it("propertylookup #2", () => {
expect(parser.parseEval("$var = &($var)->test;")).toMatchSnapshot();
});
it("propertylookup #3 - method call", () => {
expect(parser.parseEval("$var = &($var)->method();")).toMatchSnapshot();
});
it("propertylookup #4 - chained", () => {
expect(parser.parseEval("$var = &($var)->prop->nested;")).toMatchSnapshot();
});
it("propertylookup #5 - offset lookup", () => {
expect(parser.parseEval("$var = &($var)[$key];")).toMatchSnapshot();
});
it("propertylookup #6 - static property", () => {
expect(parser.parseEval("$var = &($var)::$prop;")).toMatchSnapshot();
});
it("propertylookup #7 - expr in parens", () => {
expect(parser.parseEval("$var = &($obj->prop)->test;")).toMatchSnapshot();
});
it("with bin", () => {
expect(parser.parseEval("$foo = &$bar || $bar;")).toMatchSnapshot();
});
Expand Down
Loading