Skip to content

Commit bb4a187

Browse files
author
Maarten Staa
committed
Only parse first class callables on PHP version 8.1 or later.
1 parent 7b8c9bf commit bb4a187

File tree

3 files changed

+71
-1
lines changed

3 files changed

+71
-1
lines changed

src/parser/function.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,11 @@ module.exports = {
365365
read_argument_list: function () {
366366
let result = [];
367367
this.expect("(") && this.next();
368-
if (this.token === this.tok.T_ELLIPSIS && this.peek() === ")") {
368+
if (
369+
this.version >= 801 &&
370+
this.token === this.tok.T_ELLIPSIS &&
371+
this.peek() === ")"
372+
) {
369373
result.push(this.node("variadicplaceholder")());
370374
this.next();
371375
} else if (this.token !== ")") {

test/snapshot/__snapshots__/function.test.js.snap

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,56 @@ Program {
319319
}
320320
`;
321321

322+
exports[`Function tests first class callable support requires PHP 8.1+ 1`] = `
323+
Program {
324+
"children": Array [
325+
ExpressionStatement {
326+
"expression": Assign {
327+
"kind": "assign",
328+
"left": Variable {
329+
"curly": false,
330+
"kind": "variable",
331+
"name": "callable",
332+
},
333+
"operator": "=",
334+
"right": Call {
335+
"arguments": Array [
336+
variadic {
337+
"kind": "variadic",
338+
"what": undefined,
339+
},
340+
],
341+
"kind": "call",
342+
"what": Name {
343+
"kind": "name",
344+
"name": "strlen",
345+
"resolution": "uqn",
346+
},
347+
},
348+
},
349+
"kind": "expressionstatement",
350+
},
351+
],
352+
"errors": Array [
353+
Error {
354+
"expected": "EXPR",
355+
"kind": "error",
356+
"line": 2,
357+
"message": "Parse Error : syntax error, unexpected ')' on line 2",
358+
"token": "')'",
359+
},
360+
Error {
361+
"expected": ")",
362+
"kind": "error",
363+
"line": 2,
364+
"message": "Parse Error : syntax error, unexpected ';', expecting ')' on line 2",
365+
"token": "';'",
366+
},
367+
],
368+
"kind": "program",
369+
}
370+
`;
371+
322372
exports[`Function tests implement #113 : typehint nodes 1`] = `
323373
Program {
324374
"children": Array [

test/snapshot/function.test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,4 +249,20 @@ describe("Function tests", function () {
249249
)
250250
).toMatchSnapshot();
251251
});
252+
253+
test("first class callable support requires PHP 8.1+", function () {
254+
expect(
255+
parser.parseEval(
256+
`
257+
$callable = strlen(...);
258+
`,
259+
{
260+
parser: {
261+
suppressErrors: true,
262+
version: "8.0",
263+
},
264+
}
265+
)
266+
).toMatchSnapshot();
267+
});
252268
});

0 commit comments

Comments
 (0)