JS: fix error in generation of if/else statements in some cases

See KT-19495
This commit is contained in:
Alexey Andreev
2017-09-07 19:21:14 +03:00
parent 4779f4fefb
commit ff0efe59f6
3 changed files with 43 additions and 1 deletions
@@ -644,7 +644,7 @@ public class JsToStringGenerationVisitor extends JsVisitor {
JsStatement thenStmt = x.getThenStatement();
JsStatement elseStatement = x.getElseStatement();
if (elseStatement != null && thenStmt instanceof JsIf && ((JsIf)thenStmt).getElseStatement() == null) {
if (elseStatement != null && isIfWithoutElse(thenStmt)) {
thenStmt = new JsBlock(thenStmt);
}
nestedPush(thenStmt);
@@ -680,6 +680,18 @@ public class JsToStringGenerationVisitor extends JsVisitor {
}
}
private static boolean isIfWithoutElse(@NotNull JsStatement statement) {
while (statement instanceof JsIf) {
JsIf ifStatement = (JsIf) statement;
if (ifStatement.getElseStatement() == null) {
return true;
}
statement = ifStatement.getElseStatement();
}
return false;
}
@Override
public void visitInvocation(@NotNull JsInvocation invocation) {
pushSourceInfo(invocation.getSource());