diff --git a/teavm-core/src/main/java/org/teavm/debugging/Debugger.java b/teavm-core/src/main/java/org/teavm/debugging/Debugger.java index 4aa568231..6f148b6f5 100644 --- a/teavm-core/src/main/java/org/teavm/debugging/Debugger.java +++ b/teavm-core/src/main/java/org/teavm/debugging/Debugger.java @@ -108,18 +108,8 @@ public class Debugger { if (callSiteLoc != null) { callMethod = debugInfo.getCallSite(callSiteLoc); } - SourceLocation[] following = debugInfo.getFollowingLines(frame.getLocation()); - if (following != null) { - for (SourceLocation successor : following) { - if (successor == null) { - exits = true; - } else { - for (GeneratedLocation loc : debugInfo.getGeneratedLocations(successor)) { - successors.add(new JavaScriptLocation(script, loc.getLine(), loc.getColumn())); - } - } - } - } + exits = addFollowing(debugInfo, frame.getLocation(), script, new HashSet(), + successors); if (enterMethod && callMethod != null) { for (MethodReference potentialMethod : debugInfo.getOverridingMethods(callMethod)) { for (GeneratedLocation loc : debugInfo.getMethodEntrances(potentialMethod)) { @@ -140,6 +130,32 @@ public class Debugger { javaScriptDebugger.resume(); } + private boolean addFollowing(DebugInformation debugInfo, SourceLocation location, String script, + Set visited, Set successors) { + if (!visited.add(location)) { + return false; + } + SourceLocation[] following = debugInfo.getFollowingLines(location); + boolean exits = false; + if (following != null) { + for (SourceLocation successor : following) { + if (successor == null) { + exits = true; + } else { + Collection genLocations = debugInfo.getGeneratedLocations(successor); + if (!genLocations.isEmpty()) { + for (GeneratedLocation loc : genLocations) { + successors.add(new JavaScriptLocation(script, loc.getLine(), loc.getColumn())); + } + } else { + exits |= addFollowing(debugInfo, successor, script, visited, successors); + } + } + } + } + return exits; + } + private List debugInformationBySource(String sourceFile) { Map list = debugInformationFileMap.get(sourceFile); return list != null ? new ArrayList<>(list.keySet()) : Collections.emptyList(); diff --git a/teavm-core/src/main/java/org/teavm/javascript/Renderer.java b/teavm-core/src/main/java/org/teavm/javascript/Renderer.java index 9527a1aa5..e89f37d5e 100644 --- a/teavm-core/src/main/java/org/teavm/javascript/Renderer.java +++ b/teavm-core/src/main/java/org/teavm/javascript/Renderer.java @@ -631,9 +631,15 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext public void visit(ConditionalStatement statement) { try { while (true) { + if (statement.getCondition().getLocation() != null) { + pushLocation(statement.getCondition().getLocation()); + } writer.append("if").ws().append("("); statement.getCondition().acceptVisitor(this); writer.append(")").ws().append("{").softNewLine().indent(); + if (statement.getCondition().getLocation() != null) { + popLocation(); + } for (Statement part : statement.getConsequent()) { part.acceptVisitor(this); }