Adding support for the ...spread operator on arrays and hashes

This commit is contained in:
Ryan Weaver
2023-05-05 06:54:25 -04:00
committed by Fabien Potencier
parent 3fd3645601
commit ba4fe3ba34
14 changed files with 253 additions and 62 deletions
+16 -1
View File
@@ -334,7 +334,14 @@ class ExpressionParser
}
$first = false;
$node->addElement($this->parseExpression());
if ($stream->test(/* Token::SPREAD_TYPE */ 13)) {
$stream->next();
$expr = $this->parseExpression();
$expr->setAttribute('spread', true);
$node->addElement($expr);
} else {
$node->addElement($this->parseExpression());
}
}
$stream->expect(/* Token::PUNCTUATION_TYPE */ 9, ']', 'An opened array is not properly closed');
@@ -359,6 +366,14 @@ class ExpressionParser
}
$first = false;
if ($stream->test(/* Token::SPREAD_TYPE */ 13)) {
$stream->next();
$value = $this->parseExpression();
$value->setAttribute('spread', true);
$node->addElement($value);
continue;
}
// a hash key can be:
//
// * a number -- 12