Skip to content

Commit 7b8c9bf

Browse files
author
Maarten Staa
committed
Add VariadicPlaceholder AST node.
1 parent a265846 commit 7b8c9bf

File tree

4 files changed

+38
-5
lines changed

4 files changed

+38
-5
lines changed

src/ast.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,7 @@ AST.prototype.checkNodes = function () {
580580
require("./ast/useitem"),
581581
require("./ast/variable"),
582582
require("./ast/variadic"),
583+
require("./ast/variadicplaceholder"),
583584
require("./ast/while"),
584585
require("./ast/yield"),
585586
require("./ast/yieldfrom"),

src/ast/variadicplaceholder.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* Copyright (C) 2018 Glayzzle (BSD3 License)
3+
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
4+
* @url http://glayzzle.com
5+
*/
6+
"use strict";
7+
8+
const Node = require("./node");
9+
const KIND = "variadicplaceholder";
10+
11+
/**
12+
* Defines a variadic placeholder (the ellipsis in PHP 8.1+'s first-class callable syntax)
13+
* @constructor VariadicPlaceholder
14+
* @memberOf module:php-parser
15+
* @extends {Node}
16+
* @see {Namespace}
17+
* @see http://php.net/manual/en/language.namespaces.importing.php
18+
*/
19+
module.exports = Node.extends(
20+
KIND,
21+
function VariadicPlaceholder(docs, location) {
22+
Node.apply(this, [KIND, docs, location]);
23+
}
24+
);

src/parser/function.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ module.exports = {
366366
let result = [];
367367
this.expect("(") && this.next();
368368
if (this.token === this.tok.T_ELLIPSIS && this.peek() === ")") {
369-
result.push(this.token);
369+
result.push(this.node("variadicplaceholder")());
370370
this.next();
371371
} else if (this.token !== ")") {
372372
result = this.read_non_empty_argument_list();

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,9 @@ Program {
203203
"operator": "=",
204204
"right": Call {
205205
"arguments": Array [
206-
229,
206+
VariadicPlaceholder {
207+
"kind": "variadicplaceholder",
208+
},
207209
],
208210
"kind": "call",
209211
"what": Name {
@@ -226,7 +228,9 @@ Program {
226228
"operator": "=",
227229
"right": Call {
228230
"arguments": Array [
229-
229,
231+
VariadicPlaceholder {
232+
"kind": "variadicplaceholder",
233+
},
230234
],
231235
"kind": "call",
232236
"what": PropertyLookup {
@@ -256,7 +260,9 @@ Program {
256260
"operator": "=",
257261
"right": Call {
258262
"arguments": Array [
259-
229,
263+
VariadicPlaceholder {
264+
"kind": "variadicplaceholder",
265+
},
260266
],
261267
"kind": "call",
262268
"what": StaticLookup {
@@ -286,7 +292,9 @@ Program {
286292
"operator": "=",
287293
"right": Call {
288294
"arguments": Array [
289-
229,
295+
VariadicPlaceholder {
296+
"kind": "variadicplaceholder",
297+
},
290298
],
291299
"kind": "call",
292300
"what": StaticLookup {

0 commit comments

Comments
 (0)