File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed
Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -155,8 +155,16 @@ protected function visitDyiade(Dyiade $dyiade, $indent)
155155 $ rightHand = $ this ->visitNode ($ dyiade ->rightHand , $ indent );
156156 switch ($ dyiade ->operator ) {
157157 case '|| ' :
158+ if ($ this ->engine ->getOption ('booleanLogicalOperators ' )) {
159+ break ;
160+ }
161+
158162 return $ this ->compileLazyDyiade ($ this ->engine ->getHelperName ('or ' ), $ leftHand , $ rightHand );
159163 case '&& ' :
164+ if ($ this ->engine ->getOption ('booleanLogicalOperators ' )) {
165+ break ;
166+ }
167+
160168 return $ this ->compileLazyDyiade ($ this ->engine ->getHelperName ('and ' ), $ leftHand , $ rightHand );
161169 case '+ ' :
162170 $ arguments = [$ leftHand , $ rightHand ];
Original file line number Diff line number Diff line change @@ -147,4 +147,26 @@ public function testDisableConstants()
147147 ]);
148148 self ::assertSame ('$FOO ' , trim ($ jsPhpize ->compile ('FOO ' ), " \n; " ));
149149 }
150+
151+ /**
152+ * @throws \JsPhpize\Compiler\Exception
153+ * @throws \JsPhpize\Lexer\Exception
154+ * @throws \JsPhpize\Parser\Exception
155+ */
156+ public function testBooleanLogicalOperators ()
157+ {
158+ $ jsPhpize = new JsPhpize ();
159+ $ this ->assertSame (4 , $ jsPhpize ->render ('return 7 && 4 ' ));
160+ $ this ->assertSame (7 , $ jsPhpize ->render ('return 7 || 4 ' ));
161+ $ this ->assertSame (null , $ jsPhpize ->render ('return null && false ' ));
162+ $ this ->assertSame (null , $ jsPhpize ->render ('return 0 || null ' ));
163+
164+ $ jsPhpize = new JsPhpize ([
165+ 'booleanLogicalOperators ' => true ,
166+ ]);
167+ $ this ->assertSame (true , $ jsPhpize ->render ('return 7 && 4 ' ));
168+ $ this ->assertSame (true , $ jsPhpize ->render ('return 7 || 4 ' ));
169+ $ this ->assertSame (false , $ jsPhpize ->render ('return null && false ' ));
170+ $ this ->assertSame (false , $ jsPhpize ->render ('return 0 || null ' ));
171+ }
150172}
You can’t perform that action at this time.
0 commit comments