mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-21 15:48:42 +00:00
Adding support for the ...spread operator on arrays and hashes
This commit is contained in:
committed by
Fabien Potencier
parent
3fd3645601
commit
ba4fe3ba34
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user