aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2019-12-02 06:43:54 +0800
committerGitHub <noreply@github.com>2019-12-02 06:43:54 +0800
commit9a6faf365bdd481be733bafb8c580bc76f4b353e (patch)
tree5b5d118d87e7ca3e1f49a1d449d8069c872e7f21 /lib
parente915832a36730c7eb29328c84ab9c5eecf1cb1f6 (diff)
downloadtracifyjs-9a6faf365bdd481be733bafb8c580bc76f4b353e.tar.gz
tracifyjs-9a6faf365bdd481be733bafb8c580bc76f4b353e.zip
fix corner cases in `keep_fargs` & `unused` (#3618)
Diffstat (limited to 'lib')
-rw-r--r--lib/compress.js16
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 09019a74..284b79ad 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -5173,12 +5173,14 @@ merge(Compressor.prototype, {
&& !fn.uses_arguments
&& !fn.pinned()) {
var pos = 0, last = 0;
+ var drop_fargs = exp === fn && compressor.drop_fargs(fn, self)
+ && (!fn.name || !fn.name.definition().recursive_refs);
var side_effects = [];
for (var i = 0; i < self.args.length; i++) {
var trim = i >= fn.argnames.length;
if (trim || fn.argnames[i].__unused) {
var node = self.args[i].drop_side_effect_free(compressor);
- if (exp === fn) {
+ if (drop_fargs) {
fn.argnames.splice(i, 1);
self.args.splice(i, 1);
if (node) side_effects.push(node);
@@ -5207,8 +5209,17 @@ merge(Compressor.prototype, {
}
last = pos;
}
+ if (drop_fargs) for (; i < fn.argnames.length; i++) {
+ if (fn.argnames[i].__unused) fn.argnames.splice(i--, 1);
+ }
self.args.length = last;
- if (side_effects.length) self.args.push(make_sequence(self, side_effects));
+ if (side_effects.length) {
+ var arg = make_sequence(self, side_effects);
+ self.args.push(self.args.length < fn.argnames.length ? make_node(AST_UnaryPrefix, self, {
+ operator: "void",
+ expression: arg
+ }) : arg);
+ }
}
if (compressor.option("unsafe")) {
if (is_undeclared_ref(exp)) switch (exp.name) {
@@ -6568,6 +6579,7 @@ merge(Compressor.prototype, {
name.scope = value;
value.name = name;
lambda_def = value.def_function(name);
+ lambda_def.recursive_refs = def.recursive_refs;
}
value.walk(new TreeWalker(function(node) {
if (!(node instanceof AST_SymbolRef)) return;