public function compile(JsCompiler $compiler, \Twig_NodeInterface $node) { if (!$node instanceof \Twig_Node_Expression_Function) { throw new \RuntimeException(sprintf('$node must be an instanceof of \\Expression_Function, but got "%s".', get_class($node))); } $function = $compiler->getEnvironment()->getFunction($node->getAttribute('name')); if (false === $function) { throw new \Twig_Error_Syntax(sprintf('The function "%s" does not exist', $node->getAttribute('name')), $node->getLine()); } if ($jsFunction = $compiler->getJsFunction($node->getAttribute('name'))) { $compiler->raw($jsFunction . '('); } else { $compiler->raw('this.env_.invoke(')->string($node->getAttribute('name'))->raw(', '); } $compiler->raw($function->needsEnvironment() ? 'this.env_' : ''); if ($function->needsContext()) { $compiler->raw($function->needsEnvironment() ? ', context' : 'context'); } $first = true; foreach ($node->getNode('arguments') as $argNode) { if (!$first) { $compiler->raw(', '); } else { if ($function->needsEnvironment() || $function->needsContext()) { $compiler->raw(', '); } $first = false; } $compiler->subcompile($argNode); } $compiler->raw(')'); }