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

Commit e002a44

Browse files
authored
Merge pull request glayzzle#225 from glayzzle/issue-201
fix: staticlookup inside call - I validate this commit, will open another issue as it's introduce a minor side effect
2 parents e6752a9 + 15fbf83 commit e002a44

File tree

5 files changed

+157
-0
lines changed

5 files changed

+157
-0
lines changed

src/parser/variable.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ module.exports = {
9494
name = this.text();
9595
this.next();
9696
offset = offset(name);
97+
} else if (this.token === "{") {
98+
offset = this.next().read_expr();
99+
this.expect("}") && this.next();
100+
this.expect("(");
97101
} else {
98102
this.error([this.tok.T_VARIABLE, this.tok.T_STRING]);
99103
// graceful mode : set getter as error node and continue

test/snapshot/__snapshots__/call.test.js.snap

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,65 @@ Program {
471471
}
472472
`;
473473

474+
exports[`Test call inside staticlookup (10) 1`] = `
475+
Program {
476+
"children": Array [
477+
Call {
478+
"arguments": Array [],
479+
"kind": "call",
480+
"what": Call {
481+
"arguments": Array [],
482+
"kind": "call",
483+
"what": StaticLookup {
484+
"kind": "staticlookup",
485+
"offset": Identifier {
486+
"kind": "identifier",
487+
"name": "call",
488+
},
489+
"what": ClassReference {
490+
"kind": "classreference",
491+
"name": "Order",
492+
"resolution": "uqn",
493+
},
494+
},
495+
},
496+
},
497+
],
498+
"errors": Array [],
499+
"kind": "program",
500+
}
501+
`;
502+
503+
exports[`Test call inside staticlookup (11) 1`] = `
504+
Program {
505+
"children": Array [
506+
Call {
507+
"arguments": Array [],
508+
"kind": "call",
509+
"what": StaticLookup {
510+
"kind": "staticlookup",
511+
"offset": Call {
512+
"arguments": Array [],
513+
"kind": "call",
514+
"what": ClassReference {
515+
"kind": "classreference",
516+
"name": "call",
517+
"resolution": "uqn",
518+
},
519+
},
520+
"what": ClassReference {
521+
"kind": "classreference",
522+
"name": "Order",
523+
"resolution": "uqn",
524+
},
525+
},
526+
},
527+
],
528+
"errors": Array [],
529+
"kind": "program",
530+
}
531+
`;
532+
474533
exports[`Test call inside staticlookup 1`] = `
475534
Program {
476535
"children": Array [

test/snapshot/__snapshots__/graceful.test.js.snap

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,73 @@ Program {
6565
}
6666
`;
6767

68+
exports[`Test graceful mode to suppress errors should fail ! 1`] = `
69+
Program {
70+
"children": Array [
71+
ExpressionStatement {
72+
"expression": New {
73+
"arguments": Array [],
74+
"kind": "new",
75+
"what": StaticLookup {
76+
"kind": "staticlookup",
77+
"offset": Call {
78+
"arguments": Array [],
79+
"kind": "call",
80+
"what": ClassReference {
81+
"kind": "classreference",
82+
"name": "call",
83+
"resolution": "uqn",
84+
},
85+
},
86+
"what": ClassReference {
87+
"kind": "classreference",
88+
"name": "Foo",
89+
"resolution": "uqn",
90+
},
91+
},
92+
},
93+
"kind": "expressionstatement",
94+
},
95+
],
96+
"errors": Array [],
97+
"kind": "program",
98+
}
99+
`;
100+
101+
exports[`Test graceful mode to suppress errors staticlookup 1`] = `
102+
Program {
103+
"children": Array [
104+
StaticLookup {
105+
"kind": "staticlookup",
106+
"offset": Call {
107+
"arguments": Array [],
108+
"kind": "call",
109+
"what": ClassReference {
110+
"kind": "classreference",
111+
"name": "call",
112+
"resolution": "uqn",
113+
},
114+
},
115+
"what": ClassReference {
116+
"kind": "classreference",
117+
"name": "Order",
118+
"resolution": "uqn",
119+
},
120+
},
121+
],
122+
"errors": Array [
123+
Error {
124+
"expected": "(",
125+
"kind": "error",
126+
"line": 1,
127+
"message": "Parse Error : syntax error, unexpected ';', expecting '(' on line 1",
128+
"token": "';'",
129+
},
130+
],
131+
"kind": "program",
132+
}
133+
`;
134+
68135
exports[`Test graceful mode to suppress errors test class 1`] = `
69136
Program {
70137
"children": Array [

test/snapshot/call.test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,4 +280,22 @@ describe("Test call", function() {
280280
);
281281
expect(ast).toMatchSnapshot();
282282
});
283+
it("inside staticlookup (10)", function() {
284+
const ast = parser.parseEval(
285+
'Order::call()();',
286+
{
287+
parser: { debug: false }
288+
}
289+
);
290+
expect(ast).toMatchSnapshot();
291+
});
292+
it("inside staticlookup (11)", function() {
293+
const ast = parser.parseEval(
294+
'Order::{call()}();',
295+
{
296+
parser: { debug: false }
297+
}
298+
);
299+
expect(ast).toMatchSnapshot();
300+
});
283301
});

test/snapshot/graceful.test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,14 @@ describe("Test graceful mode", function() {
4646
->
4747
`)).toMatchSnapshot();
4848
});
49+
50+
it("staticlookup", function() {
51+
expect(test.parseEval('Order::{call()};')).toMatchSnapshot();
52+
});
53+
54+
it("should fail !", function() {
55+
expect(test.parseEval('new Foo::{call()}();')).toMatchSnapshot();
56+
});
57+
4958
});
5059
});

0 commit comments

Comments
 (0)