Skip to content

Commit b1663e6

Browse files
brad4dcopybara-github
authored andcommitted
Unit test repro for UnreachableCodeElimination bug
Add a unit test demonstrating the bug in UnreachableCodeElimination that causes it to remove a variable declaration without removing all references. PiperOrigin-RevId: 561185244
1 parent 9cad29b commit b1663e6

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,28 @@ public void setUp() throws Exception {
3939
enableComputeSideEffects();
4040
}
4141

42+
@Test
43+
public void testDoNotRemoveDeclarationOfUsedVariable() {
44+
test(
45+
lines(
46+
"var f = function() {", //
47+
" return 1;",
48+
" let b = 5;",
49+
" do {",
50+
" b--;",
51+
" } while (b);",
52+
" return 3;",
53+
"};"),
54+
lines(
55+
"var f = function() {", //
56+
" return 1;",
57+
" do {",
58+
// TODO: b/297246830 - This is broken behavior.
59+
// Either delete all references to `b` or keep its declaration
60+
" } while (b);",
61+
"};"));
62+
}
63+
4264
@Test
4365
public void testDontRemoveExport() {
4466
test(

0 commit comments

Comments
 (0)