Skip to content

Commit

Permalink
Merge pull request #225 from glayzzle/issue-201
Browse files Browse the repository at this point in the history
fix: staticlookup inside call - I validate this commit, will open another issue as it's introduce a minor side effect
  • Loading branch information
ichiriac committed Nov 10, 2018
2 parents e6752a9 + 15fbf83 commit e002a44
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/parser/variable.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ module.exports = {
name = this.text();
this.next();
offset = offset(name);
} else if (this.token === "{") {
offset = this.next().read_expr();
this.expect("}") && this.next();
this.expect("(");
} else {
this.error([this.tok.T_VARIABLE, this.tok.T_STRING]);
// graceful mode : set getter as error node and continue
Expand Down
59 changes: 59 additions & 0 deletions test/snapshot/__snapshots__/call.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,65 @@ Program {
}
`;

exports[`Test call inside staticlookup (10) 1`] = `
Program {
"children": Array [
Call {
"arguments": Array [],
"kind": "call",
"what": Call {
"arguments": Array [],
"kind": "call",
"what": StaticLookup {
"kind": "staticlookup",
"offset": Identifier {
"kind": "identifier",
"name": "call",
},
"what": ClassReference {
"kind": "classreference",
"name": "Order",
"resolution": "uqn",
},
},
},
},
],
"errors": Array [],
"kind": "program",
}
`;

exports[`Test call inside staticlookup (11) 1`] = `
Program {
"children": Array [
Call {
"arguments": Array [],
"kind": "call",
"what": StaticLookup {
"kind": "staticlookup",
"offset": Call {
"arguments": Array [],
"kind": "call",
"what": ClassReference {
"kind": "classreference",
"name": "call",
"resolution": "uqn",
},
},
"what": ClassReference {
"kind": "classreference",
"name": "Order",
"resolution": "uqn",
},
},
},
],
"errors": Array [],
"kind": "program",
}
`;

exports[`Test call inside staticlookup 1`] = `
Program {
"children": Array [
Expand Down
67 changes: 67 additions & 0 deletions test/snapshot/__snapshots__/graceful.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,73 @@ Program {
}
`;

exports[`Test graceful mode to suppress errors should fail ! 1`] = `
Program {
"children": Array [
ExpressionStatement {
"expression": New {
"arguments": Array [],
"kind": "new",
"what": StaticLookup {
"kind": "staticlookup",
"offset": Call {
"arguments": Array [],
"kind": "call",
"what": ClassReference {
"kind": "classreference",
"name": "call",
"resolution": "uqn",
},
},
"what": ClassReference {
"kind": "classreference",
"name": "Foo",
"resolution": "uqn",
},
},
},
"kind": "expressionstatement",
},
],
"errors": Array [],
"kind": "program",
}
`;

exports[`Test graceful mode to suppress errors staticlookup 1`] = `
Program {
"children": Array [
StaticLookup {
"kind": "staticlookup",
"offset": Call {
"arguments": Array [],
"kind": "call",
"what": ClassReference {
"kind": "classreference",
"name": "call",
"resolution": "uqn",
},
},
"what": ClassReference {
"kind": "classreference",
"name": "Order",
"resolution": "uqn",
},
},
],
"errors": Array [
Error {
"expected": "(",
"kind": "error",
"line": 1,
"message": "Parse Error : syntax error, unexpected ';', expecting '(' on line 1",
"token": "';'",
},
],
"kind": "program",
}
`;

exports[`Test graceful mode to suppress errors test class 1`] = `
Program {
"children": Array [
Expand Down
18 changes: 18 additions & 0 deletions test/snapshot/call.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,4 +280,22 @@ describe("Test call", function() {
);
expect(ast).toMatchSnapshot();
});
it("inside staticlookup (10)", function() {
const ast = parser.parseEval(
'Order::call()();',
{
parser: { debug: false }
}
);
expect(ast).toMatchSnapshot();
});
it("inside staticlookup (11)", function() {
const ast = parser.parseEval(
'Order::{call()}();',
{
parser: { debug: false }
}
);
expect(ast).toMatchSnapshot();
});
});
9 changes: 9 additions & 0 deletions test/snapshot/graceful.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,14 @@ describe("Test graceful mode", function() {
->
`)).toMatchSnapshot();
});

it("staticlookup", function() {
expect(test.parseEval('Order::{call()};')).toMatchSnapshot();
});

it("should fail !", function() {
expect(test.parseEval('new Foo::{call()}();')).toMatchSnapshot();
});

});
});

0 comments on commit e002a44

Please sign in to comment.