<commit_before><?php

namespace Phive\Twig\Extensions\Deferred;

class DeferredNodeVisitor implements \Twig_NodeVisitorInterface
{
    public function enterNode(\Twig_NodeInterface $node, \Twig_Environment $env)
    {
        return $node;
    }

    public function leaveNode(\Twig_NodeInterface $node, \Twig_Environment $env)
    {
        return ($node instanceof \Twig_Node_Module)
            ? new DeferredModuleNode($node)
            : $node;
    }

    public function getPriority()
    {
        return 0;
    }
}<commit_msg>Resolve deferred blocks only when it's necessary<commit_after><?php

namespace Phive\Twig\Extensions\Deferred;

class DeferredNodeVisitor implements \Twig_NodeVisitorInterface
{
    private $hasDeferred = false;

    public function enterNode(\Twig_NodeInterface $node, \Twig_Environment $env)
    {
        if (!$this->hasDeferred && $node instanceof DeferredNode) {
            $this->hasDeferred = true;
        }

        return $node;
    }

    public function leaveNode(\Twig_NodeInterface $node, \Twig_Environment $env)
    {
        if ($this->hasDeferred && $node instanceof \Twig_Node_Module) {
            $node = new DeferredModuleNode($node);
            $this->hasDeferred = false;
        }

        return $node;
    }

    public function getPriority()
    {
        return 0;
    }
}
{'fraction_non_alphanumeric': 0.09648466716529544, 'fraction_numerical': 0.0014958863126402393, 'mean_word_length': 2.6859504132231407, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4010599', 'n_tokens_mistral': 395, 'n_tokens_neox': 386, 'n_words': 87}