diff --git a/src/Latte/Essential/Nodes/IfNode.php b/src/Latte/Essential/Nodes/IfNode.php index f0d87182c..ca00176df 100644 --- a/src/Latte/Essential/Nodes/IfNode.php +++ b/src/Latte/Essential/Nodes/IfNode.php @@ -10,7 +10,6 @@ namespace Latte\Essential\Nodes; use Latte\CompileException; -use Latte\Compiler\ExpressionBuilder; use Latte\Compiler\Nodes\AreaNode; use Latte\Compiler\Nodes\Php\Expression; use Latte\Compiler\Nodes\Php\ExpressionNode; @@ -83,7 +82,10 @@ private static function buildCondition(TagParser $parser): ExpressionNode $block = $parser->tryConsumeTokenBeforeUnquotedString('block') ?? $parser->stream->tryConsume('#'); $name = $parser->parseUnquotedStringOrExpression(); $list[] = $block || $name instanceof StringNode - ? ExpressionBuilder::variable('$this')->method('hasBlock', [$name])->build() + ? new Expression\AuxiliaryNode( + fn(PrintContext $context, ExpressionNode $name) => '$this->hasBlock(' . $name->print($context) . ')', + $name, + ) : new Expression\IssetNode([$name]); } while ($parser->stream->tryConsume(',')); diff --git a/tests/tags/ifset.block.nodes.phpt b/tests/tags/ifset.block.nodes.phpt index 59c98ead6..e93d627a7 100644 --- a/tests/tags/ifset.block.nodes.phpt +++ b/tests/tags/ifset.block.nodes.phpt @@ -14,14 +14,9 @@ Assert::match(<<<'XX' If: BinaryOp: operator: && - MethodCall: - Variable: - name: this - Identifier: - name: hasBlock - Argument: - String: - value: foo + Auxiliary: + String: + value: foo Isset: Variable: name: item @@ -31,4 +26,5 @@ Assert::match(<<<'XX' Fragment: Text: content: '.else.' + XX, exportTraversing('{ifset foo, $item}.ifset.{else}.else.{/ifset}'));