compress duplicated variable definitions (#1817)

These are surprisingly common, as people reuse the same variable name within loops or switch branches.
This commit is contained in:
Alex Lam S.L
2017-04-17 17:11:29 +08:00
committed by GitHub
parent 71a8d0d236
commit 4ffb6fce76
4 changed files with 73 additions and 11 deletions

View File

@@ -1029,3 +1029,30 @@ delete_assign_2: {
}
expect_stdout: true
}
drop_var: {
options = {
toplevel: true,
unused: true,
}
input: {
var a;
console.log(a, b);
var a = 1, b = 2;
console.log(a, b);
var a = 3;
console.log(a, b);
}
expect: {
console.log(a, b);
var a = 1, b = 2;
console.log(a, b);
a = 3;
console.log(a, b);
}
expect_stdout: [
"undefined undefined",
"1 2",
"3 2",
]
}

View File

@@ -1639,7 +1639,7 @@ redefine_arguments_1: {
return typeof arguments;
}
function g() {
return"number";
return "number";
}
function h(x) {
var arguments = x;
@@ -1951,7 +1951,6 @@ pure_getters_2: {
var a = a && a.b;
}
expect: {
var a;
var a = a && a.b;
}
}