@@ -104,7 +104,7 @@ private static class MustExecVisitor extends JsVisitor {
104104
105105 private final List <JsStatement > mustExec = new ArrayList <JsStatement >();
106106
107- public MustExecVisitor () {
107+ MustExecVisitor () {
108108 }
109109
110110 @ Override
@@ -184,7 +184,9 @@ public boolean visit(JsBinaryOperation x, JsContext ctx) {
184184 evalContext .put (x .getArg2 (), evalContext .get (x ));
185185 } else if (x .getOperator () == JsBinaryOperator .COMMA ) {
186186 evalContext .put (x .getArg1 (), EvalMode .VOID );
187- evalContext .put (x .getArg2 (), evalContext .get (x ));
187+ if (evalContext .containsKey (x )) {
188+ evalContext .put (x .getArg2 (), evalContext .get (x ));
189+ }
188190 }
189191 return true ;
190192 }
@@ -226,8 +228,12 @@ public void endVisit(JsBinaryOperation x, JsContext ctx) {
226228 break ;
227229 }
228230 }
229- evalContext .remove (arg1 );
230- evalContext .remove (arg2 );
231+ if (arg1 != result ) {
232+ evalContext .remove (arg1 );
233+ }
234+ if (arg2 != result ) {
235+ evalContext .remove (arg2 );
236+ }
231237 result = maybeReorderOperations (result );
232238
233239 if (result != x ) {
@@ -667,7 +673,7 @@ protected static JsExpression shortCircuitAnd(JsBinaryOperation expr,
667673 return arg1 ;
668674 }
669675 }
670- if (arg2 instanceof CanBooleanEval && evalContext .containsKey (arg1 )) {
676+ if (arg2 instanceof CanBooleanEval && evalContext .containsKey (arg2 )) {
671677 CanBooleanEval eval2 = (CanBooleanEval ) arg2 ;
672678 if (eval2 .isBooleanTrue () && !arg2 .hasSideEffects ()) {
673679 return arg1 ;
@@ -709,7 +715,7 @@ protected static JsExpression shortCircuitOr(JsBinaryOperation expr,
709715 return arg1 ;
710716 }
711717 }
712- if (arg2 instanceof CanBooleanEval && evalContext .containsKey (arg1 )) {
718+ if (arg2 instanceof CanBooleanEval && evalContext .containsKey (arg2 )) {
713719 CanBooleanEval eval2 = (CanBooleanEval ) arg2 ;
714720 if (eval2 .isBooleanFalse () && !arg2 .hasSideEffects ()) {
715721 return arg1 ;
0 commit comments