From a2932bd5ce66f558d98ae820fe8cb3f6a1705a27 Mon Sep 17 00:00:00 2001 From: Yonas Habteab Date: Wed, 29 Jun 2022 09:36:00 +0200 Subject: [PATCH] Visitor: Transform less tree calls & variable definitions into our own classes --- library/Icinga/Less/Visitor.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/library/Icinga/Less/Visitor.php b/library/Icinga/Less/Visitor.php index 87036bef5..030ea7bc9 100644 --- a/library/Icinga/Less/Visitor.php +++ b/library/Icinga/Less/Visitor.php @@ -4,7 +4,10 @@ namespace Icinga\Less; use Less_Parser; +use Less_Tree_Expression; use Less_Tree_Rule; +use Less_Tree_Value; +use Less_Tree_Variable; use Less_VisitorReplacing; use LogicException; use ReflectionProperty; @@ -68,6 +71,10 @@ CSS; } $this->callingVar = spl_object_hash($c); + } else { + // We need to use our own tree call class , so that we can precompile the arguments before making + // the actual LESS function calls. Otherwise, it will produce lots of invalid argument exceptions! + $c = Call::fromCall($c); } return $c; @@ -136,6 +143,15 @@ CSS; $this->definingVariable = spl_object_hash($r); $this->variableOrigin = $r; + + if ($r->value instanceof Less_Tree_Value) { + if ($r->value->value[0] instanceof Less_Tree_Expression) { + if ($r->value->value[0]->value[0] instanceof Less_Tree_Variable) { + // Transform the variable definition rule into our own class + $r->value->value[0]->value[0] = new DeferredColorProp($r->name, $r->value->value[0]->value[0]); + } + } + } } return $r; @@ -186,6 +202,15 @@ CSS; ->setVariable($v); } + public function visitColor($c) + { + if ($this->definingVariable !== false) { + $c->name = $this->variableOrigin->name; + } + + return $c; + } + public function run($node) { $this->lightMode = new LightMode();