From 8334f86f30074c51ae53f4f69399119fbdd7e273 Mon Sep 17 00:00:00 2001 From: alexlamsl Date: Thu, 2 Nov 2017 18:59:01 +0800 Subject: [PATCH] handle `AST_SymbolFunarg` --- lib/compress.js | 7 +++--- test/compress/reduce_vars.js | 48 +++++++++++++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 4 deletions(-) diff --git a/lib/compress.js b/lib/compress.js index d7b986df..f09f2b9b 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -4217,9 +4217,10 @@ merge(Compressor.prototype, { if (fixed && d.should_replace === undefined) { var init; if (fixed instanceof AST_This) { - if (all(d.references, function(ref) { - return d.scope === ref.scope; - })) { + if (!(d.orig[0] instanceof AST_SymbolFunarg) + && all(d.references, function(ref) { + return d.scope === ref.scope; + })) { init = fixed; } } else { diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js index 13e469da..5ec5bfde 100644 --- a/test/compress/reduce_vars.js +++ b/test/compress/reduce_vars.js @@ -3296,7 +3296,7 @@ escaped_prop: { expect_stdout: "2" } -issue_2420: { +issue_2420_1: { options = { reduce_vars: true, unused: true, @@ -3337,3 +3337,49 @@ issue_2420: { "foo", ] } + +issue_2420_2: { + options = { + reduce_vars: true, + unused: true, + } + input: { + function f() { + var t = this; + if (t.bar) + t.foo(); + else + !function(t) { + console.log(this === t); + }(this); + } + var o = { + bar: 1, + foo: function() { console.log("foo", this.bar); }, + }; + f.call(o); + o.bar = 0; + f.call(o); + } + expect: { + function f() { + if (this.bar) + this.foo(); + else + !function(t) { + console.log(this === t); + }(this); + } + var o = { + bar: 1, + foo: function() { console.log("foo", this.bar); }, + }; + f.call(o); + o.bar = 0; + f.call(o); + } + expect_stdout: [ + "foo 1", + "false", + ] +}