fix corner case in reduce_vars (#4782)
This commit is contained in:
@@ -10324,7 +10324,7 @@ merge(Compressor.prototype, {
|
|||||||
single_use = false;
|
single_use = false;
|
||||||
} else if (fixed.name && fixed.name.definition() !== def) {
|
} else if (fixed.name && fixed.name.definition() !== def) {
|
||||||
single_use = false;
|
single_use = false;
|
||||||
} else if (fixed.parent_scope !== self.scope.resolve() || is_funarg(def)) {
|
} else if (fixed.parent_scope !== self.scope || is_funarg(def)) {
|
||||||
single_use = fixed.is_constant_expression(self.scope);
|
single_use = fixed.is_constant_expression(self.scope);
|
||||||
if (single_use == "f") {
|
if (single_use == "f") {
|
||||||
var scope = self.scope;
|
var scope = self.scope;
|
||||||
|
|||||||
@@ -359,7 +359,7 @@ reduce_block_2_toplevel: {
|
|||||||
node_version: ">=4"
|
node_version: ">=4"
|
||||||
}
|
}
|
||||||
|
|
||||||
reduce_vars: {
|
reduce_vars_1: {
|
||||||
options = {
|
options = {
|
||||||
evaluate: true,
|
evaluate: true,
|
||||||
reduce_vars: true,
|
reduce_vars: true,
|
||||||
@@ -381,6 +381,86 @@ reduce_vars: {
|
|||||||
node_version: ">=4"
|
node_version: ">=4"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reduce_vars_2: {
|
||||||
|
options = {
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
"use strict";
|
||||||
|
(function() {
|
||||||
|
function f() {
|
||||||
|
console.log(typeof a);
|
||||||
|
}
|
||||||
|
for (let a in [ 42 ])
|
||||||
|
f();
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
"use strict";
|
||||||
|
(function() {
|
||||||
|
function f() {
|
||||||
|
console.log(typeof a);
|
||||||
|
}
|
||||||
|
for (let a in [ 42 ])
|
||||||
|
f();
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
expect_stdout: "undefined"
|
||||||
|
node_version: ">=4"
|
||||||
|
}
|
||||||
|
|
||||||
|
reduce_vars_3: {
|
||||||
|
options = {
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
"use strict";
|
||||||
|
(function(scope) {
|
||||||
|
let i = 1;
|
||||||
|
function f() {
|
||||||
|
i = 0;
|
||||||
|
}
|
||||||
|
for (let i = 0, x = 0; i < scope.length; i++, x++) {
|
||||||
|
if (x != i) {
|
||||||
|
console.log("FAIL");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
f();
|
||||||
|
console.log(scope[i]);
|
||||||
|
}
|
||||||
|
console.log(i);
|
||||||
|
})([ 4, 2 ]);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
"use strict";
|
||||||
|
(function(scope) {
|
||||||
|
let i = 1;
|
||||||
|
function f() {
|
||||||
|
i = 0;
|
||||||
|
}
|
||||||
|
for (let i = 0, x = 0; i < scope.length; i++, x++) {
|
||||||
|
if (x != i) {
|
||||||
|
console.log("FAIL");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
f();
|
||||||
|
console.log(scope[i]);
|
||||||
|
}
|
||||||
|
console.log(i);
|
||||||
|
})([ 4, 2 ]);
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"4",
|
||||||
|
"2",
|
||||||
|
"0",
|
||||||
|
]
|
||||||
|
node_version: ">=4"
|
||||||
|
}
|
||||||
|
|
||||||
hoist_props: {
|
hoist_props: {
|
||||||
options = {
|
options = {
|
||||||
hoist_props: true,
|
hoist_props: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user