public function testCompile() { $env = new Context(); $d = new JavascriptNode('"hello".toUpperCase() + \'!\''); $result = $d->compile($env); $this->assertInstanceOf('ILess\\Node\\JavascriptNode', $result); }
/** * Compiles the node * * @param Context $context The context * @param array|null $arguments Array of arguments * @param boolean|null $important Important flag * @return QuotedNode */ public function compile(Context $context, $arguments = null, $important = null) { $value = $this->value; $iterativeReplace = function ($value, $regexp, $replacementFunc) { $evaluatedValue = $value; do { $value = $evaluatedValue; $evaluatedValue = preg_replace_callback($regexp, $replacementFunc, $value); } while ($value !== $evaluatedValue); return $evaluatedValue; }; // javascript replacement $value = $iterativeReplace($value, '/`([^`]+)`/', function ($matches) use($context) { $js = new JavascriptNode($matches[1], $this->index, true); return $js->compile($context)->value; }); // interpolation replacement $value = $iterativeReplace($value, '/@\\{([\\w-]+)\\}/', function ($matches) use(&$context) { $v = new VariableNode('@' . $matches[1], $this->index, $this->currentFileInfo); $canShorted = $context->canShortenColors; $context->canShortenColors = false; $v = $v->compile($context); $v = $v instanceof QuotedNode ? $v->value : $v->toCSS($context); $context->canShortenColors = $canShorted; return $v; }); return new QuotedNode($this->quote . $value . $this->quote, $value, $this->escaped, $this->index, $this->currentFileInfo); }