diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2017-07-06 21:51:58 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-06 21:51:58 +0800 |
commit | 4b6ca5e742787c59969b9b00442cf85bbec19ed5 (patch) | |
tree | 23542b1219099a92e4c10f452456f8ee275a93f5 /test/compress/properties.js | |
parent | 9306da3c58831fabc93dfae6a7ea4f45d42183d4 (diff) | |
download | tracifyjs-4b6ca5e742787c59969b9b00442cf85bbec19ed5.tar.gz tracifyjs-4b6ca5e742787c59969b9b00442cf85bbec19ed5.zip |
inline property access of object literal (#2209)
- only if property value is side-effect-free
- guard by `unsafe`
fixes #2208
Diffstat (limited to 'test/compress/properties.js')
-rw-r--r-- | test/compress/properties.js | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/test/compress/properties.js b/test/compress/properties.js index 8126d6c6..a5527de3 100644 --- a/test/compress/properties.js +++ b/test/compress/properties.js @@ -657,3 +657,116 @@ accessor_this: { expect_exact: 'var a=1;var b={get this(){return a},set this(c){a=c}};console.log(b.this,b.this=2,b.this);' expect_stdout: "1 2 2" } + +issue_2208_1: { + options = { + inline: true, + side_effects: true, + unsafe: true, + } + input: { + console.log({ + p: function() { + return 42; + } + }.p()); + } + expect: { + console.log(42); + } + expect_stdout: "42" +} + +issue_2208_2: { + options = { + inline: true, + side_effects: true, + unsafe: true, + } + input: { + console.log({ + a: 42, + p: function() { + return this.a; + } + }.p()); + } + expect: { + console.log({ + a: 42, + p: function() { + return this.a; + } + }.p()); + } + expect_stdout: "42" +} + +issue_2208_3: { + options = { + inline: true, + side_effects: true, + unsafe: true, + } + input: { + a = 42; + console.log({ + p: function() { + return function() { + return this.a; + }(); + } + }.p()); + } + expect: { + a = 42; + console.log(function() { + return this.a; + }()); + } + expect_stdout: "42" +} + +issue_2208_4: { + options = { + inline: true, + side_effects: true, + unsafe: true, + } + input: { + function foo() {} + console.log({ + a: foo(), + p: function() { + return 42; + } + }.p()); + } + expect: { + function foo() {} + console.log((foo(), function() { + return 42; + })()); + } + expect_stdout: "42" +} + +issue_2208_5: { + options = { + inline: true, + side_effects: true, + unsafe: true, + } + input: { + console.log({ + p: "FAIL", + p: function() { + return 42; + } + }.p()); + } + expect: { + console.log(42); + } + expect_stdout: "42" +} |