Skip to content

Commit

Permalink
Add a test to validate that RemoveUnusedCode cannot handle multiple d…
Browse files Browse the repository at this point in the history
…eclarations within the for-loop initialization expression (gh-4207).

PiperOrigin-RevId: 719474294
  • Loading branch information
12wrigja authored and copybara-github committed Jan 25, 2025
1 parent daf973d commit 82e7fbe
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions test/com/google/javascript/jscomp/RemoveUnusedCodeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3484,4 +3484,16 @@ public void testPreserveDestructuringWithObjectRest() {
"const {['one']: unused, ...remaining} = obj;",
"console.log(remaining);"));
}

@Test
public void testConfirmsGithubIssue4207() {
// This test confirms the behavior that was reported in
// https://github.com/google/closure-compiler/issues/4207
test(
lines(
"const arr = [];", "for (let i = 0, d = arr; i < 5; i++) {", " d[i] = \"test\";", "}"),
// This behavior is not correct - we should back off on removing the loop content and array
// declaration.
lines("for (let i = 0; i < 5; i++) {", "}"));
}
}

0 comments on commit 82e7fbe

Please sign in to comment.