mirror of
https://github.com/slawkens/myaac.git
synced 2025-10-15 18:24:56 +02:00
Update Twig to v2.15.4
This commit is contained in:
@@ -11,7 +11,6 @@
|
||||
|
||||
namespace Twig\TokenParser;
|
||||
|
||||
use Twig\Error\SyntaxError;
|
||||
use Twig\Node\Expression\AssignNameExpression;
|
||||
use Twig\Node\ImportNode;
|
||||
use Twig\Token;
|
||||
@@ -20,44 +19,38 @@ use Twig\Token;
|
||||
* Imports macros.
|
||||
*
|
||||
* {% from 'forms.html' import forms %}
|
||||
*
|
||||
* @final
|
||||
*/
|
||||
class FromTokenParser extends AbstractTokenParser
|
||||
final class FromTokenParser extends AbstractTokenParser
|
||||
{
|
||||
public function parse(Token $token)
|
||||
{
|
||||
$macro = $this->parser->getExpressionParser()->parseExpression();
|
||||
$stream = $this->parser->getStream();
|
||||
$stream->expect(Token::NAME_TYPE, 'import');
|
||||
$stream->expect(/* Token::NAME_TYPE */ 5, 'import');
|
||||
|
||||
$targets = [];
|
||||
do {
|
||||
$name = $stream->expect(Token::NAME_TYPE)->getValue();
|
||||
$name = $stream->expect(/* Token::NAME_TYPE */ 5)->getValue();
|
||||
|
||||
$alias = $name;
|
||||
if ($stream->nextIf('as')) {
|
||||
$alias = $stream->expect(Token::NAME_TYPE)->getValue();
|
||||
$alias = $stream->expect(/* Token::NAME_TYPE */ 5)->getValue();
|
||||
}
|
||||
|
||||
$targets[$name] = $alias;
|
||||
|
||||
if (!$stream->nextIf(Token::PUNCTUATION_TYPE, ',')) {
|
||||
if (!$stream->nextIf(/* Token::PUNCTUATION_TYPE */ 9, ',')) {
|
||||
break;
|
||||
}
|
||||
} while (true);
|
||||
|
||||
$stream->expect(Token::BLOCK_END_TYPE);
|
||||
$stream->expect(/* Token::BLOCK_END_TYPE */ 3);
|
||||
|
||||
$var = new AssignNameExpression($this->parser->getVarName(), $token->getLine());
|
||||
$node = new ImportNode($macro, $var, $token->getLine(), $this->getTag());
|
||||
$node = new ImportNode($macro, $var, $token->getLine(), $this->getTag(), $this->parser->isMainScope());
|
||||
|
||||
foreach ($targets as $name => $alias) {
|
||||
if ($this->parser->isReservedMacroName($name)) {
|
||||
throw new SyntaxError(sprintf('"%s" cannot be an imported macro as it is a reserved keyword.', $name), $token->getLine(), $stream->getSourceContext());
|
||||
}
|
||||
|
||||
$this->parser->addImportedSymbol('function', $alias, 'get'.$name, $var);
|
||||
$this->parser->addImportedSymbol('function', $alias, 'macro_'.$name, $var);
|
||||
}
|
||||
|
||||
return $node;
|
||||
|
Reference in New Issue
Block a user