suppress function substitution across loops
This commit is contained in:
parent
012046b8b1
commit
ed115afb03
|
|
@ -324,9 +324,8 @@ merge(Compressor.prototype, {
|
||||||
|| value.is_constant_expression(node.scope);
|
|| value.is_constant_expression(node.scope);
|
||||||
} else {
|
} else {
|
||||||
d.single_use = d.scope === node.scope
|
d.single_use = d.scope === node.scope
|
||||||
&& loop_ids[d.id] === in_loop
|
|
||||||
&& value.is_constant_expression();
|
&& value.is_constant_expression();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
d.single_use = false;
|
d.single_use = false;
|
||||||
}
|
}
|
||||||
|
|
@ -384,6 +383,7 @@ merge(Compressor.prototype, {
|
||||||
d.fixed = false;
|
d.fixed = false;
|
||||||
} else {
|
} else {
|
||||||
d.fixed = node;
|
d.fixed = node;
|
||||||
|
loop_ids[d.id] = in_loop;
|
||||||
mark(d, true);
|
mark(d, true);
|
||||||
if (ref_once(d)) {
|
if (ref_once(d)) {
|
||||||
d.single_use = d.scope === d.references[0].scope
|
d.single_use = d.scope === d.references[0].scope
|
||||||
|
|
@ -577,7 +577,11 @@ merge(Compressor.prototype, {
|
||||||
}
|
}
|
||||||
|
|
||||||
function ref_once(def) {
|
function ref_once(def) {
|
||||||
return unused && !def.scope.uses_eval && !def.scope.uses_with && def.references.length == 1;
|
return unused
|
||||||
|
&& !def.scope.uses_eval
|
||||||
|
&& !def.scope.uses_with
|
||||||
|
&& def.references.length == 1
|
||||||
|
&& loop_ids[def.id] === in_loop;
|
||||||
}
|
}
|
||||||
|
|
||||||
function is_immutable(value) {
|
function is_immutable(value) {
|
||||||
|
|
|
||||||
|
|
@ -1123,11 +1123,12 @@ toplevel_on_loops_1: {
|
||||||
while (x);
|
while (x);
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
|
function bar() {
|
||||||
|
console.log("bar:", --x);
|
||||||
|
}
|
||||||
var x = 3;
|
var x = 3;
|
||||||
do
|
do
|
||||||
(function() {
|
bar();
|
||||||
console.log("bar:", --x);
|
|
||||||
})();
|
|
||||||
while (x);
|
while (x);
|
||||||
}
|
}
|
||||||
expect_stdout: true
|
expect_stdout: true
|
||||||
|
|
@ -1180,9 +1181,10 @@ toplevel_on_loops_2: {
|
||||||
while (x);
|
while (x);
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
for (;;) (function() {
|
function bar() {
|
||||||
console.log("bar:");
|
console.log("bar:");
|
||||||
})();
|
}
|
||||||
|
for (;;) bar();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -3920,3 +3922,70 @@ issue_2450_3: {
|
||||||
}
|
}
|
||||||
expect_stdout: "true"
|
expect_stdout: "true"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_2450_4: {
|
||||||
|
options = {
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a;
|
||||||
|
function f(b) {
|
||||||
|
console.log(a === b);
|
||||||
|
a = b;
|
||||||
|
}
|
||||||
|
function g() {}
|
||||||
|
for (var i = 3; --i >= 0;)
|
||||||
|
f(g);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a;
|
||||||
|
function f(b) {
|
||||||
|
console.log(a === b);
|
||||||
|
a = b;
|
||||||
|
}
|
||||||
|
function g() {}
|
||||||
|
for (var i = 3; --i >= 0;)
|
||||||
|
f(g);
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"false",
|
||||||
|
"true",
|
||||||
|
"true",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_2450_5: {
|
||||||
|
options = {
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a;
|
||||||
|
function f(b) {
|
||||||
|
console.log(a === b);
|
||||||
|
a = b;
|
||||||
|
}
|
||||||
|
function g() {}
|
||||||
|
[1, 2, 3].forEach(function() {
|
||||||
|
f(g);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a;
|
||||||
|
function g() {}
|
||||||
|
[1, 2, 3].forEach(function() {
|
||||||
|
(function(b) {
|
||||||
|
console.log(a === b);
|
||||||
|
a = b;
|
||||||
|
})(g);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
expect_stdout: [
|
||||||
|
"false",
|
||||||
|
"true",
|
||||||
|
"true",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user