Skip to content

Commit bf80c6f

Browse files
feat: spread_operator_for_array
1 parent d5e7dcf commit bf80c6f

21 files changed

+4665
-1061
lines changed

src/ast/entry.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,20 @@ const KIND = "entry";
1414
* @extends {Expression}
1515
* @property {Node|null} key The entry key/offset
1616
* @property {Node} value The entry value
17+
* @property {Boolean} byRef By reference
18+
* @property {Boolean} unpack Argument unpacking
1719
*/
1820
module.exports = Expression.extends(KIND, function Entry(
1921
key,
2022
value,
23+
byRef,
24+
unpack,
2125
docs,
2226
location
2327
) {
2428
Expression.apply(this, [KIND, docs, location]);
2529
this.key = key;
2630
this.value = value;
31+
this.byRef = byRef;
32+
this.unpack = unpack;
2733
});

src/parser/array.js

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
*/
66
"use strict";
77

8-
const ArrayExpr = "array";
9-
const ArrayEntry = "entry";
10-
118
module.exports = {
129
/**
1310
* Parse an array
@@ -19,7 +16,7 @@ module.exports = {
1916
read_array: function() {
2017
let expect = null;
2118
let shortForm = false;
22-
const result = this.node(ArrayExpr);
19+
const result = this.node("array");
2320

2421
if (this.token === this.tok.T_ARRAY) {
2522
this.next().expect("(");
@@ -69,27 +66,45 @@ module.exports = {
6966
) {
7067
return;
7168
}
69+
7270
if (this.token === ",") {
7371
return this.node("noop")();
7472
}
73+
74+
const entry = this.node("entry");
75+
76+
let key = null;
77+
let value = null;
78+
let byRef = false;
79+
let unpack = false;
80+
7581
if (this.token === "&") {
76-
return this.read_byref(this.read_variable.bind(this, true, false));
82+
this.next();
83+
byRef = true;
84+
value = this.read_variable(true, false);
85+
} else if (this.token === this.tok.T_ELLIPSIS && this.php74) {
86+
this.next();
87+
unpack = true;
88+
value = this.read_expr()
7789
} else {
78-
const entry = this.node(ArrayEntry);
7990
const expr = this.read_expr();
91+
8092
if (this.token === this.tok.T_DOUBLE_ARROW) {
81-
if (this.next().token === "&") {
82-
return entry(
83-
expr,
84-
this.read_byref(this.read_variable.bind(this, true, false))
85-
);
93+
this.next();
94+
key = expr;
95+
96+
if (this.token === "&") {
97+
this.next();
98+
byRef = true;
99+
value = this.read_variable(true, false);
86100
} else {
87-
return entry(expr, this.read_expr());
101+
value = this.read_expr();
88102
}
89103
} else {
90-
entry.destroy();
104+
value = expr;
91105
}
92-
return expr;
93106
}
107+
108+
return entry(key, value, byRef, unpack);
94109
}
95110
};

src/parser/variable.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,11 +237,6 @@ module.exports = {
237237
}
238238
return result;
239239
},
240-
241-
read_encaps_var: function() {
242-
243-
},
244-
245240
/**
246241
* https://github.com/php/php-src/blob/493524454d66adde84e00d249d607ecd540de99f/Zend/zend_language_parser.y#L1231
247242
*/

0 commit comments

Comments
 (0)