enhance side_effects (#4675)

This commit is contained in:
Alex Lam S.L
2021-02-22 07:44:16 +00:00
committed by GitHub
parent 960668ccdb
commit f9a2a9d78e
2 changed files with 25 additions and 2 deletions

View File

@@ -8516,6 +8516,8 @@ merge(Compressor.prototype, {
} }
}); });
return node; return node;
} else if (!node.has_side_effects(compressor)) {
self.drop_side_effect_free = return_null;
} }
} }
var arg_used, insert, in_loop, scope; var arg_used, insert, in_loop, scope;

View File

@@ -348,8 +348,6 @@ issue_3983_1: {
} }
expect: { expect: {
var a = "PASS"; var a = "PASS";
g();
function g() {}
console.log(a); console.log(a);
} }
expect_stdout: "PASS" expect_stdout: "PASS"
@@ -537,3 +535,26 @@ issue_4668: {
} }
expect_stdout: "undefined" expect_stdout: "undefined"
} }
drop_side_effect_free_call: {
options = {
inline: true,
reduce_vars: true,
side_effects: true,
toplevel: true,
}
input: {
function f(a) {
return "PA" + a;
}
f(42);
console.log(f("SS"));
}
expect: {
function f(a) {
return "PA" + a;
}
console.log(f("SS"));
}
expect_stdout: "PASS"
}