From: Alex Lam S.L Date: Fri, 2 Oct 2020 23:03:39 +0000 (+0100) Subject: fix corner case in `merge_vars` (#4170) X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=8cb509d50e8bbc4c79d9bd0274a625f5ec37fe42;p=UglifyJS.git fix corner case in `merge_vars` (#4170) fixes #4168 --- diff --git a/lib/compress.js b/lib/compress.js index 27ddd22f..513528e7 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -4406,7 +4406,12 @@ merge(Compressor.prototype, { push(); segment.block = node; if (node === self) root = segment; - if (node instanceof AST_Lambda && node.name) references[node.name.definition().id] = false; + if (node instanceof AST_Lambda) { + if (node.name) references[node.name.definition().id] = false; + if (node.uses_arguments && !tw.has_directive("use strict")) node.argnames.forEach(function(node) { + references[node.definition().id] = false; + }); + } descend(); pop(); return true; @@ -4474,6 +4479,7 @@ merge(Compressor.prototype, { return true; } }); + tw.directives = Object.create(compressor.directives); self.walk(tw); var merged = Object.create(null); while (first.length && last.length) { diff --git a/test/compress/merge_vars.js b/test/compress/merge_vars.js index 5f4b6606..a12781d3 100644 --- a/test/compress/merge_vars.js +++ b/test/compress/merge_vars.js @@ -2928,3 +2928,83 @@ issue_4157_2: { } expect_stdout: "undefined" } + +issue_4168: { + options = { + merge_vars: true, + } + input: { + var o = { + f: function(a, b, c) { + var d = a.d; + var e = b.e; + var f = c.f; + this.g(arguments); + if (d) + console.log(e, f); + }, + g: function(args) { + console.log(args[0], args[1], args[2]); + }, + }; + o.f("PASS", true, 42); + } + expect: { + var o = { + f: function(a, b, c) { + var d = a.d; + var e = b.e; + var f = c.f; + this.g(arguments); + if (d) + console.log(e, f); + }, + g: function(args) { + console.log(args[0], args[1], args[2]); + }, + }; + o.f("PASS", true, 42); + } + expect_stdout: "PASS true 42" +} + +issue_4168_use_strict: { + options = { + merge_vars: true, + } + input: { + "use strict"; + var o = { + f: function(a, b, c) { + var d = a.d; + var e = b.e; + var f = c.f; + this.g(arguments); + if (d) + console.log(e, f); + }, + g: function(args) { + console.log(args[0], args[1], args[2]); + }, + }; + o.f("PASS", true, 42); + } + expect: { + "use strict"; + var o = { + f: function(d, e, f) { + var d = d.d; + var e = e.e; + var f = f.f; + this.g(arguments); + if (d) + console.log(e, f); + }, + g: function(args) { + console.log(args[0], args[1], args[2]); + }, + }; + o.f("PASS", true, 42); + } + expect_stdout: "PASS true 42" +}