Skip to content

Commit a284ac0

Browse files
fix: staticlookup inside call
1 parent f3c737b commit a284ac0

File tree

6 files changed

+120
-1
lines changed

6 files changed

+120
-1
lines changed

src/parser/variable.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ module.exports = {
9393
name = this.text();
9494
this.next();
9595
offset = offset(name);
96+
} else if (this.token === "{") {
97+
offset = this.next().read_expr();
98+
this.expect("}") && this.next();
99+
this.expect("(");
96100
} else {
97101
this.error([this.tok.T_VARIABLE, this.tok.T_STRING]);
98102
// 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__/encapsed.test.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ exports[`encapsed variable curly (simple syntax) 1`] = `
296296
Program {
297297
"children": Array [
298298
Echo {
299-
"arguments": Array [
299+
"expressions": Array [
300300
Encapsed {
301301
"kind": "encapsed",
302302
"raw": "\\"string \${var} string\\"",

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

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

68+
exports[`Test graceful mode to suppress errors staticlookup 1`] = `
69+
Program {
70+
"children": Array [
71+
StaticLookup {
72+
"kind": "staticlookup",
73+
"offset": Call {
74+
"arguments": Array [],
75+
"kind": "call",
76+
"what": ClassReference {
77+
"kind": "classreference",
78+
"name": "call",
79+
"resolution": "uqn",
80+
},
81+
},
82+
"what": ClassReference {
83+
"kind": "classreference",
84+
"name": "Order",
85+
"resolution": "uqn",
86+
},
87+
},
88+
],
89+
"errors": Array [
90+
Error {
91+
"expected": "(",
92+
"kind": "error",
93+
"line": 1,
94+
"message": "Parse Error : syntax error, unexpected ';', expecting '(' on line 1",
95+
"token": "';'",
96+
},
97+
],
98+
"kind": "program",
99+
}
100+
`;
101+
68102
exports[`Test graceful mode to suppress errors test class 1`] = `
69103
Program {
70104
"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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,9 @@ describe("Test graceful mode", function() {
4646
->
4747
`)).toMatchSnapshot();
4848
});
49+
50+
it("staticlookup", function() {
51+
expect(test.parseEval('Order::{call()};')).toMatchSnapshot();
52+
});
4953
});
5054
});

0 commit comments

Comments
 (0)