fix corner cases in unused (#3519)
This commit is contained in:
@@ -3738,7 +3738,7 @@ merge(Compressor.prototype, {
|
||||
head.push(def);
|
||||
} else {
|
||||
var value = def.value
|
||||
&& (sym.references.length != 1 || !sym.replaced)
|
||||
&& !def.value.single_use
|
||||
&& def.value.drop_side_effect_free(compressor);
|
||||
if (value) {
|
||||
AST_Node.warn("Side effects in initialization of unused variable {name} [{file}:{line},{col}]", template(def.name));
|
||||
@@ -6158,6 +6158,7 @@ merge(Compressor.prototype, {
|
||||
if (single_use && fixed) {
|
||||
def.single_use = false;
|
||||
fixed._squeezed = true;
|
||||
fixed.single_use = true;
|
||||
if (fixed instanceof AST_Defun) {
|
||||
fixed = make_node(AST_Function, fixed, fixed);
|
||||
fixed.name = make_node(AST_SymbolLambda, fixed.name, fixed.name);
|
||||
|
||||
@@ -2103,7 +2103,7 @@ issue_3497: {
|
||||
expect_stdout: "undefined"
|
||||
}
|
||||
|
||||
issue_3515: {
|
||||
issue_3515_1: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
reduce_vars: true,
|
||||
@@ -2127,3 +2127,62 @@ issue_3515: {
|
||||
}
|
||||
expect_stdout: "1"
|
||||
}
|
||||
|
||||
issue_3515_2: {
|
||||
options = {
|
||||
side_effects: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
var a = "FAIL";
|
||||
function f() {
|
||||
typeof b === "number";
|
||||
delete a;
|
||||
}
|
||||
var b = f(a = "PASS");
|
||||
console.log(a);
|
||||
}
|
||||
expect: {
|
||||
var a = "FAIL";
|
||||
function f() {
|
||||
delete a;
|
||||
}
|
||||
f(a = "PASS");
|
||||
console.log(a);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issue_3515_3: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
var c = "FAIL";
|
||||
(function() {
|
||||
function f() {
|
||||
c = "PASS";
|
||||
}
|
||||
var a = f();
|
||||
var a = function g(b) {
|
||||
b && (b.p = this);
|
||||
}(a);
|
||||
})();
|
||||
console.log(c);
|
||||
}
|
||||
expect: {
|
||||
var c = "FAIL";
|
||||
(function() {
|
||||
function f() {
|
||||
c = "PASS";
|
||||
}
|
||||
(function(b) {
|
||||
b && (b.p = this);
|
||||
})(f());
|
||||
})();
|
||||
console.log(c);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user