Merge branch '3.x' into 4.x

* 3.x:
  Move static attributes for Function|Filter|TestExpression to the constructor
This commit is contained in:
Fabien Potencier
2024-08-07 22:41:08 +02:00
3 changed files with 5 additions and 13 deletions
+2 -5
View File
@@ -19,16 +19,13 @@ class FilterExpression extends CallExpression
{
public function __construct(Node $node, ConstantExpression $filterName, Node $arguments, int $lineno, ?string $tag = null)
{
parent::__construct(['node' => $node, 'filter' => $filterName, 'arguments' => $arguments], [], $lineno, $tag);
parent::__construct(['node' => $node, 'filter' => $filterName, 'arguments' => $arguments], ['name' => $filterName->getAttribute('value'), 'type' => 'filter'], $lineno, $tag);
}
public function compile(Compiler $compiler): void
{
$name = $this->getNode('filter')->getAttribute('value');
$filter = $compiler->getEnvironment()->getFilter($name);
$filter = $compiler->getEnvironment()->getFilter($this->getAttribute('name'));
$this->setAttribute('name', $name);
$this->setAttribute('type', 'filter');
$this->setAttribute('needs_charset', $filter->needsCharset());
$this->setAttribute('needs_environment', $filter->needsEnvironment());
$this->setAttribute('needs_context', $filter->needsContext());
+1 -3
View File
@@ -19,7 +19,7 @@ class FunctionExpression extends CallExpression
{
public function __construct(string $name, Node $arguments, int $lineno)
{
parent::__construct(['arguments' => $arguments], ['name' => $name, 'is_defined_test' => false], $lineno);
parent::__construct(['arguments' => $arguments], ['name' => $name, 'type' => 'function', 'is_defined_test' => false], $lineno);
}
public function compile(Compiler $compiler)
@@ -27,8 +27,6 @@ class FunctionExpression extends CallExpression
$name = $this->getAttribute('name');
$function = $compiler->getEnvironment()->getFunction($name);
$this->setAttribute('name', $name);
$this->setAttribute('type', 'function');
$this->setAttribute('needs_charset', $function->needsCharset());
$this->setAttribute('needs_environment', $function->needsEnvironment());
$this->setAttribute('needs_context', $function->needsContext());
+2 -5
View File
@@ -23,16 +23,13 @@ class TestExpression extends CallExpression
$nodes['arguments'] = $arguments;
}
parent::__construct($nodes, ['name' => $name], $lineno);
parent::__construct($nodes, ['name' => $name, 'type' => 'test'], $lineno);
}
public function compile(Compiler $compiler): void
{
$name = $this->getAttribute('name');
$test = $compiler->getEnvironment()->getTest($name);
$test = $compiler->getEnvironment()->getTest($this->getAttribute('name'));
$this->setAttribute('name', $name);
$this->setAttribute('type', 'test');
$this->setAttribute('arguments', $test->getArguments());
$this->setAttribute('callable', $test->getCallable());
$this->setAttribute('is_variadic', $test->isVariadic());