From: Alex Lam S.L Date: Fri, 20 Mar 2020 16:55:24 +0000 (+0800) Subject: fix corner case in `evaluate` & `ie8` (#3751) X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=0a1c9b34cea8bf740c70d5457ef9e3bd37778607;p=UglifyJS.git fix corner case in `evaluate` & `ie8` (#3751) fixes #3750 --- diff --git a/lib/compress.js b/lib/compress.js index 96229369..343994e7 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -3373,15 +3373,18 @@ merge(Compressor.prototype, { var args = eval_args(this.args); if (!args) return this; if (!stat.value) return undefined; - fn.argnames.forEach(function(sym, i) { + if (!all(fn.argnames, function(sym, i) { var value = args[i]; - sym.definition().references.forEach(function(node) { + var def = sym.definition(); + if (def.orig[def.orig.length - 1] !== sym) return false; + def.references.forEach(function(node) { node._eval = function() { return value; }; cached.push(node); }); - }); + return true; + })) return this; fn.evaluating = true; var val = stat.value._eval(compressor, ignore_side_effects, cached, depth); delete fn.evaluating; diff --git a/lib/scope.js b/lib/scope.js index 896efacc..35d97e12 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -219,7 +219,12 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) { var redef; while (redef = new_def.redefined()) new_def = redef; } else { - new_def = self.globals.get(name) || scope.def_variable(node); + new_def = self.globals.get(name); + } + if (new_def) { + new_def.orig.push(node); + } else { + new_def = scope.def_variable(node); } old_def.orig.concat(old_def.references).forEach(function(node) { node.thedef = new_def; diff --git a/lib/utils.js b/lib/utils.js index da82a140..9959305a 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -185,7 +185,7 @@ function makePredicate(words) { function all(array, predicate) { for (var i = array.length; --i >= 0;) - if (!predicate(array[i])) + if (!predicate(array[i], i)) return false; return true; } diff --git a/test/compress/ie8.js b/test/compress/ie8.js index 7ec8037f..4dfa7c6b 100644 --- a/test/compress/ie8.js +++ b/test/compress/ie8.js @@ -2398,3 +2398,25 @@ issue_3703: { } expect_stdout: "PASS" } + +issue_3750: { + options = { + evaluate: true, + ie8: true, + } + input: { + (function(a) { + return function a() { + return a && console.log("PASS"); + }(); + })(); + } + expect: { + (function(a) { + return function a() { + return a && console.log("PASS"); + }(); + })(); + } + expect_stdout: "PASS" +}