From 903a5df9a5bfcaac6cc6da8294f3de8599004a23 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Sat, 11 Apr 2020 12:54:26 +0100 Subject: fix corner case in `inline` (#3778) fixes #3777 --- lib/compress.js | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'lib/compress.js') diff --git a/lib/compress.js b/lib/compress.js index 98724bd0..e5b7bf09 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -5820,7 +5820,7 @@ merge(Compressor.prototype, { } } if (is_func) { - var def, value; + var def, value, var_assigned = false; if (can_inline && !fn.uses_arguments && !fn.pinned() @@ -5909,10 +5909,12 @@ merge(Compressor.prototype, { for (var i = 0; i < len; i++) { var line = fn.body[i]; if (line instanceof AST_Var) { - if (stat && !all(line.definitions, function(var_def) { + var assigned = var_assigned || !all(line.definitions, function(var_def) { return !var_def.value; - })) { - return false; + }); + if (assigned) { + var_assigned = true; + if (stat) return false; } } else if (line instanceof AST_Defun || line instanceof AST_EmptyStatement) { continue; @@ -5932,15 +5934,11 @@ merge(Compressor.prototype, { } function can_substitute_directly() { + if (var_assigned) return; if (compressor.option("inline") <= 1 && fn.argnames.length) return; - var var_count = fn.variables.size() - 1; - if (var_count > fn.argnames.length) return; - var var_names = []; - if (!all(fn.argnames, function(argname) { - push_uniq(var_names, argname.name); - return argname.definition().references.length < 2; + if (!fn.variables.all(function(def) { + return def.references.length < 2 && def.orig[0] instanceof AST_SymbolFunarg; })) return; - if (var_count > var_names.length) return; var abort = false; var begin; var in_order = []; -- cgit v1.2.3