示例#1
0
 public function compile(JsCompiler $compiler, \Twig_NodeInterface $node)
 {
     if (!$node instanceof \Twig_Node_Expression_Test) {
         throw new \RuntimeException(sprintf('$node must be an instanceof of \\Expression_Test, but got "%s".', get_class($node)));
     }
     $name = $node->getAttribute('name');
     if ($testCompiler = $compiler->getTestCompiler($name)) {
         $testCompiler->compile($compiler, $node);
         return;
     }
     $subNode = $node->getNode('node');
     $compiler->raw('this.env_.test(')->string($name)->raw(', ')->subcompile($subNode);
     if (null !== $node->getNode('arguments')) {
         $compiler->raw(', ');
         $max = count($node->getNode('arguments')) - 1;
         foreach ($node->getNode('arguments') as $i => $arg) {
             $compiler->subcompile($arg);
             if ($i != $max) {
                 $compiler->raw(', ');
             }
         }
     }
     $compiler->raw(')');
 }