Skip to content

Commit 82e7fbe

Browse files
12wrigjacopybara-github
authored andcommitted
Add a test to validate that RemoveUnusedCode cannot handle multiple declarations within the for-loop initialization expression (gh-4207).
PiperOrigin-RevId: 719474294
1 parent daf973d commit 82e7fbe

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

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

+12
Original file line numberDiff line numberDiff line change
@@ -3484,4 +3484,16 @@ public void testPreserveDestructuringWithObjectRest() {
34843484
"const {['one']: unused, ...remaining} = obj;",
34853485
"console.log(remaining);"));
34863486
}
3487+
3488+
@Test
3489+
public void testConfirmsGithubIssue4207() {
3490+
// This test confirms the behavior that was reported in
3491+
// https://github.com/google/closure-compiler/issues/4207
3492+
test(
3493+
lines(
3494+
"const arr = [];", "for (let i = 0, d = arr; i < 5; i++) {", " d[i] = \"test\";", "}"),
3495+
// This behavior is not correct - we should back off on removing the loop content and array
3496+
// declaration.
3497+
lines("for (let i = 0; i < 5; i++) {", "}"));
3498+
}
34873499
}

0 commit comments

Comments
 (0)