You are here

protected function Twig_NodeVisitor_Optimizer::doLeaveNode in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/twig/twig/lib/Twig/NodeVisitor/Optimizer.php \Twig_NodeVisitor_Optimizer::doLeaveNode()

Called after child nodes are visited.

Parameters

Twig_Node $node The node to visit:

Twig_Environment $env The Twig environment instance:

Return value

Twig_Node|false The modified node or false if the node must be removed

Overrides Twig_BaseNodeVisitor::doLeaveNode

File

vendor/twig/twig/lib/Twig/NodeVisitor/Optimizer.php, line 79

Class

Twig_NodeVisitor_Optimizer
Twig_NodeVisitor_Optimizer tries to optimizes the AST.

Code

protected function doLeaveNode(Twig_Node $node, Twig_Environment $env) {
  $expression = $node instanceof Twig_Node_Expression;
  if (self::OPTIMIZE_FOR === (self::OPTIMIZE_FOR & $this->optimizers)) {
    $this
      ->leaveOptimizeFor($node, $env);
  }
  if (self::OPTIMIZE_RAW_FILTER === (self::OPTIMIZE_RAW_FILTER & $this->optimizers)) {
    $node = $this
      ->optimizeRawFilter($node, $env);
  }
  $node = $this
    ->optimizePrintNode($node, $env);
  if (self::OPTIMIZE_VAR_ACCESS === (self::OPTIMIZE_VAR_ACCESS & $this->optimizers) && !$env
    ->isStrictVariables() && !$env
    ->hasExtension('sandbox')) {
    if ($node instanceof Twig_Node_Body) {
      $this->inABody = false;
    }
    elseif ($this->inABody) {
      if (!$expression && get_class($node) !== 'Twig_Node' && ($prependedNodes = array_shift($this->prependedNodes))) {
        $nodes = array();
        foreach (array_unique($prependedNodes) as $name) {
          $nodes[] = new Twig_Node_SetTemp($name, $node
            ->getLine());
        }
        $nodes[] = $node;
        $node = new Twig_Node($nodes);
      }
    }
  }
  return $node;
}