| @@ 26-48 (lines=23) @@ | ||
| 23 | ||
| 24 | abstract class BinaryCompiler implements TypeCompilerInterface |
|
| 25 | { |
|
| 26 | public function compile(JsCompiler $compiler, \Twig_NodeInterface $node) |
|
| 27 | { |
|
| 28 | if (!$node instanceof \Twig_Node_Expression_Binary) { |
|
| 29 | throw new \RuntimeException( |
|
| 30 | sprintf( |
|
| 31 | '$node must be an instanceof of \Twig_Node_Expression_Binary, but got "%s".', |
|
| 32 | get_class($node) |
|
| 33 | ) |
|
| 34 | ); |
|
| 35 | } |
|
| 36 | ||
| 37 | $compiler |
|
| 38 | ->raw('((') |
|
| 39 | ->subcompile($node->getNode('left')) |
|
| 40 | ->raw(') ') |
|
| 41 | ; |
|
| 42 | $this->operator($compiler, $node); |
|
| 43 | $compiler |
|
| 44 | ->raw(' (') |
|
| 45 | ->subcompile($node->getNode('right')) |
|
| 46 | ->raw('))') |
|
| 47 | ; |
|
| 48 | } |
|
| 49 | ||
| 50 | abstract protected function operator(JsCompiler $compiler, \Twig_NodeInterface $node); |
|
| 51 | } |
|
| @@ 31-51 (lines=21) @@ | ||
| 28 | return 'Twig_Node_Expression_Conditional'; |
|
| 29 | } |
|
| 30 | ||
| 31 | public function compile(JsCompiler $compiler, \Twig_NodeInterface $node) |
|
| 32 | { |
|
| 33 | if (!$node instanceof \Twig_Node_Expression_Conditional) { |
|
| 34 | throw new \RuntimeException( |
|
| 35 | sprintf( |
|
| 36 | '$node must be an instanceof of \Expression_Conditional, but got "%s".', |
|
| 37 | get_class($node) |
|
| 38 | ) |
|
| 39 | ); |
|
| 40 | } |
|
| 41 | ||
| 42 | $compiler |
|
| 43 | ->raw('((') |
|
| 44 | ->subcompile($node->getNode('expr1')) |
|
| 45 | ->raw(') ? (') |
|
| 46 | ->subcompile($node->getNode('expr2')) |
|
| 47 | ->raw(') : (') |
|
| 48 | ->subcompile($node->getNode('expr3')) |
|
| 49 | ->raw('))') |
|
| 50 | ; |
|
| 51 | } |
|
| 52 | } |
|
| 53 | ||