diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2017-01-26 19:14:18 +0800 |
---|---|---|
committer | Richard van Velzen <rvanvelzen1@gmail.com> | 2017-01-26 12:14:18 +0100 |
commit | 0d7d4918eb6fb73c3cf9863479b3e66d38fad6df (patch) | |
tree | aba146adb5371e19935493b132fc605abbe081ca /test/compress/reduce_vars.js | |
parent | 48284844a461e6113bb9911cdcdad7ab8a3d85de (diff) | |
download | tracifyjs-0d7d4918eb6fb73c3cf9863479b3e66d38fad6df.tar.gz tracifyjs-0d7d4918eb6fb73c3cf9863479b3e66d38fad6df.zip |
augment evaluate to extract within objects (#1425)
- gated by `unsafe`
- replaces previous optimisation specific to String.length
- "123"[0] => 1
- [1, 2, 3][0] => 1
- [1, 2, 3].length => 3
- does not apply to objects with overridden prototype functions
Diffstat (limited to 'test/compress/reduce_vars.js')
-rw-r--r-- | test/compress/reduce_vars.js | 183 |
1 files changed, 182 insertions, 1 deletions
diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js index a1d05012..c401ac66 100644 --- a/test/compress/reduce_vars.js +++ b/test/compress/reduce_vars.js @@ -168,4 +168,185 @@ modified: { console.log(B ? 'yes' : 'no'); } } -}
\ No newline at end of file +} + +unsafe_evaluate: { + options = { + evaluate : true, + reduce_vars : true, + unsafe : true, + unused : true + } + input: { + function f0(){ + var a = { + b:1 + }; + console.log(a.b + 3); + } + + function f1(){ + var a = { + b:{ + c:1 + }, + d:2 + }; + console.log(a.b + 3, a.d + 4, a.b.c + 5, a.d.c + 6); + } + } + expect: { + function f0(){ + console.log(4); + } + + function f1(){ + var a = { + b:{ + c:1 + }, + d:2 + }; + console.log(a.b + 3, 6, 6, 2..c + 6); + } + } +} + +unsafe_evaluate_object: { + options = { + evaluate : true, + reduce_vars : true, + unsafe : true + } + input: { + function f0(){ + var a = 1; + var b = {}; + b[a] = 2; + console.log(a + 3); + } + + function f1(){ + var a = { + b:1 + }; + a.b = 2; + console.log(a.b + 3); + } + } + expect: { + function f0(){ + var a = 1; + var b = {}; + b[a] = 2; + console.log(4); + } + + function f1(){ + var a = { + b:1 + }; + a.b = 2; + console.log(a.b + 3); + } + } +} + +unsafe_evaluate_array: { + options = { + evaluate : true, + reduce_vars : true, + unsafe : true + } + input: { + function f0(){ + var a = 1; + var b = []; + b[a] = 2; + console.log(a + 3); + } + + function f1(){ + var a = [1]; + a[2] = 3; + console.log(a.length); + } + + function f2(){ + var a = [1]; + a.push(2); + console.log(a.length); + } + } + expect: { + function f0(){ + var a = 1; + var b = []; + b[a] = 2; + console.log(4); + } + + function f1(){ + var a = [1]; + a[2] = 3; + console.log(a.length); + } + + function f2(){ + var a = [1]; + a.push(2); + console.log(a.length); + } + } +} + +unsafe_evaluate_equality: { + options = { + evaluate : true, + reduce_vars : true, + unsafe : true, + unused : true + } + input: { + function f0(){ + var a = {}; + console.log(a === a); + } + + function f1(){ + var a = []; + console.log(a === a); + } + + function f2(){ + var a = {a:1, b:2}; + var b = a; + var c = a; + console.log(b === c); + } + + function f3(){ + var a = [1, 2, 3]; + var b = a; + var c = a; + console.log(b === c); + } + } + expect: { + function f0(){ + console.log(true); + } + + function f1(){ + console.log(true); + } + + function f2(){ + console.log(true); + } + + function f3(){ + console.log(true); + } + } +} |