| @@ 24-44 (lines=21) @@ | ||
| 21 | use TwigJs\Compiler\Expression\UnaryCompiler; |
|
| 22 | use TwigJs\JsCompiler; |
|
| 23 | ||
| 24 | class NegCompiler extends UnaryCompiler |
|
| 25 | { |
|
| 26 | public function getType() |
|
| 27 | { |
|
| 28 | return 'Twig_Node_Expression_Unary_Neg'; |
|
| 29 | } |
|
| 30 | ||
| 31 | protected function operator(JsCompiler $compiler, \Twig_NodeInterface $node) |
|
| 32 | { |
|
| 33 | if (!$node instanceof \Twig_Node_Expression_Unary_Neg) { |
|
| 34 | throw new \RuntimeException( |
|
| 35 | sprintf( |
|
| 36 | '$node must be an instanceof of \Expression_Unary_Neg, but got "%s".', |
|
| 37 | get_class($node) |
|
| 38 | ) |
|
| 39 | ); |
|
| 40 | } |
|
| 41 | ||
| 42 | $compiler->raw('-'); |
|
| 43 | } |
|
| 44 | } |
|
| 45 | ||
| @@ 24-44 (lines=21) @@ | ||
| 21 | use TwigJs\Compiler\Expression\UnaryCompiler; |
|
| 22 | use TwigJs\JsCompiler; |
|
| 23 | ||
| 24 | class NotCompiler extends UnaryCompiler |
|
| 25 | { |
|
| 26 | public function getType() |
|
| 27 | { |
|
| 28 | return 'Twig_Node_Expression_Unary_Not'; |
|
| 29 | } |
|
| 30 | ||
| 31 | protected function operator(JsCompiler $compiler, \Twig_NodeInterface $node) |
|
| 32 | { |
|
| 33 | if (!$node instanceof \Twig_Node_Expression_Unary_Not) { |
|
| 34 | throw new \RuntimeException( |
|
| 35 | sprintf( |
|
| 36 | '$node must be an instanceof of \Twig_Node_Expression_Unary_Not, but got "%s".', |
|
| 37 | get_class($node) |
|
| 38 | ) |
|
| 39 | ); |
|
| 40 | } |
|
| 41 | ||
| 42 | $compiler->raw('!'); |
|
| 43 | } |
|
| 44 | } |
|
| 45 | ||
| @@ 24-44 (lines=21) @@ | ||
| 21 | use TwigJs\Compiler\Expression\UnaryCompiler; |
|
| 22 | use TwigJs\JsCompiler; |
|
| 23 | ||
| 24 | class PosCompiler extends UnaryCompiler |
|
| 25 | { |
|
| 26 | public function getType() |
|
| 27 | { |
|
| 28 | return 'Twig_Node_Expression_Unary_Pos'; |
|
| 29 | } |
|
| 30 | ||
| 31 | protected function operator(JsCompiler $compiler, \Twig_NodeInterface $node) |
|
| 32 | { |
|
| 33 | if (!$node instanceof \Twig_Node_Expression_Unary_Pos) { |
|
| 34 | throw new \RuntimeException( |
|
| 35 | sprintf( |
|
| 36 | '$node must be an instanceof of \Twig_Node_Expression_Unary_Pos, but got "%s".', |
|
| 37 | get_class($node) |
|
| 38 | ) |
|
| 39 | ); |
|
| 40 | } |
|
| 41 | ||
| 42 | $compiler->raw('+'); |
|
| 43 | } |
|
| 44 | } |
|
| 45 | ||