diff --git a/src/com/google/javascript/jscomp/PeepholeRemoveDeadCode.java b/src/com/google/javascript/jscomp/PeepholeRemoveDeadCode.java index d7443806534..40b044c57a7 100644 --- a/src/com/google/javascript/jscomp/PeepholeRemoveDeadCode.java +++ b/src/com/google/javascript/jscomp/PeepholeRemoveDeadCode.java @@ -58,7 +58,10 @@ Node optimizeSubtree(Node subtree) { case IF: return tryFoldIf(subtree); case WHILE: - throw checkNormalization(false, "WHILE"); + // This pass gets run both before and after denormalize. Hence, the AST could potentially + // contain WHILE (denormalized). + // TODO: Ideally, we should optimize this case instead of returning + return subtree; case FOR: { Node condition = NodeUtil.getConditionExpression(subtree); @@ -787,7 +790,6 @@ Node tryOptimizeBlock(Node n) { for (Node c = n.getFirstChild(); c != null; ) { Node next = c.getNext(); // save c.next, since 'c' may be removed if (!isUnremovableNode(c) && !mayHaveSideEffects(c)) { - checkNormalization(!NodeUtil.isFunctionDeclaration(n), "function declaration"); // TODO(johnlenz): determine what this is actually removing. Candidates // include: EMPTY nodes, control structures without children // (removing infinite loops), empty try blocks. What else? @@ -1377,10 +1379,4 @@ private Node tryRemoveOptionalCall(Node optionalCall) { this.reportChangeToEnclosingScope(result); return result; } - - private static @Nullable IllegalStateException checkNormalization( - boolean condition, String feature) { - checkState(condition, "Unexpected %s. AST should be normalized.", feature); - return null; - } } diff --git a/test/com/google/javascript/jscomp/PeepholeRemoveDeadCodeTest.java b/test/com/google/javascript/jscomp/PeepholeRemoveDeadCodeTest.java index 0dda981eace..d661232a230 100644 --- a/test/com/google/javascript/jscomp/PeepholeRemoveDeadCodeTest.java +++ b/test/com/google/javascript/jscomp/PeepholeRemoveDeadCodeTest.java @@ -55,6 +55,9 @@ public void process(Node externs, Node root) { @Before public void setUp() throws Exception { super.setUp(); + // This pass doesn't need the AST to be normalized as it runs both before and after + // `denormalize`. Since it runs PureFunctionsIdentifier pass which expects the AST to be + // normalized, we're doing `enableNormalize` for these tests. enableNormalize(); // TODO(bradfordcsmith): Stop normalizing the expected output or document why it is necessary. enableNormalizeExpectedOutput();