diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2017-11-04 00:31:37 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-04 00:31:37 +0800 |
commit | c8b6f4733d35db48b5b7e2373264db0d99eb299f (patch) | |
tree | f609933db48323267cc3709cb63732dd6a2df895 /test/compress | |
parent | a48f87abf2fb09cc8296444eb613021ef66492c3 (diff) | |
download | tracifyjs-c8b6f4733d35db48b5b7e2373264db0d99eb299f.tar.gz tracifyjs-c8b6f4733d35db48b5b7e2373264db0d99eb299f.zip |
reduce `this` within functions (#2421)
- only replace same-scope usages
- augment `test/ufuzz.js` to test for `this`
fixes #2420
Diffstat (limited to 'test/compress')
-rw-r--r-- | test/compress/reduce_vars.js | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js index d7fdee18..e4d22e9b 100644 --- a/test/compress/reduce_vars.js +++ b/test/compress/reduce_vars.js @@ -3295,3 +3295,87 @@ escaped_prop: { } expect_stdout: "2" } + +issue_2420_1: { + options = { + reduce_vars: true, + unused: true, + } + input: { + function run() { + var self = this; + if (self.count++) + self.foo(); + else + self.bar(); + } + var o = { + count: 0, + foo: function() { console.log("foo"); }, + bar: function() { console.log("bar"); }, + }; + run.call(o); + run.call(o); + } + expect: { + function run() { + if (this.count++) + this.foo(); + else + this.bar(); + } + var o = { + count: 0, + foo: function() { console.log("foo"); }, + bar: function() { console.log("bar"); }, + }; + run.call(o); + run.call(o); + } + expect_stdout: [ + "bar", + "foo", + ] +} + +issue_2420_2: { + options = { + reduce_vars: true, + unused: true, + } + input: { + function f() { + var that = this; + if (that.bar) + that.foo(); + else + !function(that, self) { + console.log(this === that, self === this, that === self); + }(that, this); + } + f.call({ + bar: 1, + foo: function() { console.log("foo", this.bar); }, + }); + f.call({}); + } + expect: { + function f() { + if (this.bar) + this.foo(); + else + !function(that, self) { + console.log(this === that, self === this, that === self); + }(this, this); + } + f.call({ + bar: 1, + foo: function() { console.log("foo", this.bar); }, + }); + f.call({}); + } + expect_stdout: [ + "foo 1", + "false false true", + ] +} |