Skip to content

Commit

Permalink
use try-finally for macro compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobion committed Sep 24, 2015
1 parent eea6849 commit 53d01ff
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
10 changes: 5 additions & 5 deletions lib/Twig/Node/Macro.php
Expand Up @@ -108,14 +108,14 @@ public function compile(Twig_Compiler $compiler)
->write("try {\n")
->indent()
->subcompile($this->getNode('body'))
->raw("\n")
->write("return ('' === \$tmp = ob_get_contents()) ? '' : new Twig_Markup(\$tmp, \$this->env->getCharset());\n")
->outdent()
->write("} catch (Exception \$e) {\n")
->write("} finally {\n")
->indent()
->write("ob_end_clean();\n\n")
->write("throw \$e;\n")
->write("ob_end_clean();\n")
->outdent()
->write("}\n\n")
->write("return ('' === \$tmp = ob_get_clean()) ? '' : new Twig_Markup(\$tmp, \$this->env->getCharset());\n")
->write("}\n")
->outdent()
->write("}\n\n")
;
Expand Down
8 changes: 3 additions & 5 deletions test/Twig/Tests/Node/MacroTest.php
Expand Up @@ -55,13 +55,11 @@ public function macro_foo(\$__foo__ = null, \$__bar__ = "Foo"$declaration)
ob_start();
try {
echo "foo";
} catch (Exception \$e) {
ob_end_clean();
throw \$e;
return ('' === \$tmp = ob_get_contents()) ? '' : new Twig_Markup(\$tmp, \$this->env->getCharset());
} finally {
ob_end_clean();
}
return ('' === \$tmp = ob_get_clean()) ? '' : new Twig_Markup(\$tmp, \$this->env->getCharset());
}
EOF
),
Expand Down

0 comments on commit 53d01ff

Please sign in to comment.