JS: fix error in generation of if/else statements in some cases
See KT-19495
This commit is contained in:
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user