diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2017-05-06 23:18:55 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-06 23:18:55 +0800 |
commit | 2c7ee956fd829624cacfdbde43d74ee8d3bb5e82 (patch) | |
tree | 6569ffecf4748f7da96e34a268167eb319fb082c /test | |
parent | ecf3563c45e7cbf58cc9b7528ee5804691420a60 (diff) | |
download | tracifyjs-2c7ee956fd829624cacfdbde43d74ee8d3bb5e82.tar.gz tracifyjs-2c7ee956fd829624cacfdbde43d74ee8d3bb5e82.zip |
fix `unsafe` on `evaluate` of `reduce_vars` (#1870)
Determine if variables with non-constant values can escape and be modified.
fixes #1865
Diffstat (limited to 'test')
-rw-r--r-- | test/compress/reduce_vars.js | 92 |
1 files changed, 68 insertions, 24 deletions
diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js index f7bdcb36..22c1a874 100644 --- a/test/compress/reduce_vars.js +++ b/test/compress/reduce_vars.js @@ -297,7 +297,7 @@ unsafe_evaluate_array: { } } -unsafe_evaluate_equality: { +unsafe_evaluate_equality_1: { options = { evaluate : true, reduce_vars : true, @@ -305,47 +305,62 @@ unsafe_evaluate_equality: { unused : true } input: { - function f0(){ + function f0() { var a = {}; - console.log(a === a); + return a === a; } - - function f1(){ + function f1() { var a = []; - console.log(a === a); + return a === a; + } + console.log(f0(), f1()); + } + expect: { + function f0() { + return true; + } + function f1() { + return true; } + console.log(f0(), f1()); + } + expect_stdout: true +} - function f2(){ +unsafe_evaluate_equality_2: { + options = { + collapse_vars: true, + evaluate : true, + passes : 2, + reduce_vars : true, + unsafe : true, + unused : true + } + input: { + function f2() { var a = {a:1, b:2}; var b = a; var c = a; - console.log(b === c); + return b === c; } - - function f3(){ + function f3() { var a = [1, 2, 3]; var b = a; var c = a; - console.log(b === c); + return b === c; } + console.log(f2(), f3()); } expect: { - function f0(){ - console.log(true); - } - - function f1(){ - console.log(true); - } - - function f2(){ - console.log(true); + function f2() { + return true; } - - function f3(){ - console.log(true); + function f3() { + return true; } + console.log(f2(), f3()); } + expect_stdout: true } passes: { @@ -2417,3 +2432,32 @@ issue_1850_4: { } expect_stdout: true } + +issue_1865: { + options = { + evaluate: true, + reduce_vars: true, + unsafe: true, + } + input: { + function f(a) { + a.b = false; + } + console.log(function() { + var some = { thing: true }; + f(some); + return some.thing; + }()); + } + expect: { + function f(a) { + a.b = false; + } + console.log(function() { + var some = { thing: true }; + f(some); + return some.thing; + }()); + } + expect_stdout: true +} |