Skip to content

Commit 3241a65

Browse files
Merge pull request #4058 from CamWass:fix-cfa
PiperOrigin-RevId: 509559837
2 parents ce52aa6 + 97a50c8 commit 3241a65

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/com/google/javascript/jscomp/ControlFlowAnalysis.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,10 +476,11 @@ private void handleWhile(Node node) {
476476
}
477477

478478
private void handleDo(Node node) {
479-
Node cond = node.getFirstChild();
479+
Node body = node.getFirstChild();
480480
// The first edge can be the initial iteration as well as the iterations
481481
// after.
482-
createEdge(node, Branch.ON_TRUE, computeFallThrough(cond));
482+
createEdge(node, Branch.ON_TRUE, computeFallThrough(body));
483+
Node cond = body.getNext();
483484
if (!cond.isTrue()) {
484485
// The edge that leaves the do loop if the condition fails.
485486
createEdge(node, Branch.ON_FALSE, computeFollowNode(node, this));

test/com/google/javascript/jscomp/ControlFlowAnalysisTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,14 @@ public void testInifiteLoopWhile() {
336336
assertNoEdge(cfg, Token.WHILE, Token.EXPR_RESULT);
337337
}
338338

339+
@Test
340+
public void testInifiteLoopDoWhile() {
341+
String src = "var x; do { } while (true); x();";
342+
ControlFlowGraph<Node> cfg = createCfg(src);
343+
assertDownEdge(cfg, Token.DO, Token.BLOCK, Branch.ON_TRUE);
344+
assertNoEdge(cfg, Token.DO, Token.EXPR_RESULT);
345+
}
346+
339347
@Test
340348
public void testInifiteLoopFor_emptyCond() {
341349
String src = "var x; for(;;) { } x();";

0 commit comments

Comments
 (0)