You are here

protected function Twig_NodeVisitor_Optimizer::doEnterNode in Translation template extractor 7.3

Called before child nodes are visited.

Parameters

Twig_Node $node The node to visit:

Twig_Environment $env The Twig environment instance:

Return value

Twig_Node The modified node

Overrides Twig_BaseNodeVisitor::doEnterNode

File

vendor/Twig/NodeVisitor/Optimizer.php, line 53

Class

Twig_NodeVisitor_Optimizer
Twig_NodeVisitor_Optimizer tries to optimizes the AST.

Code

protected function doEnterNode(Twig_Node $node, Twig_Environment $env) {
  if (self::OPTIMIZE_FOR === (self::OPTIMIZE_FOR & $this->optimizers)) {
    $this
      ->enterOptimizeFor($node, $env);
  }
  if (PHP_VERSION_ID < 50400 && self::OPTIMIZE_VAR_ACCESS === (self::OPTIMIZE_VAR_ACCESS & $this->optimizers) && !$env
    ->isStrictVariables() && !$env
    ->hasExtension('sandbox')) {
    if ($this->inABody) {
      if (!$node instanceof Twig_Node_Expression) {
        if (get_class($node) !== 'Twig_Node') {
          array_unshift($this->prependedNodes, array());
        }
      }
      else {
        $node = $this
          ->optimizeVariables($node, $env);
      }
    }
    elseif ($node instanceof Twig_Node_Body) {
      $this->inABody = true;
    }
  }
  return $node;
}