diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2018-01-19 20:41:57 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-19 20:41:57 +0800 |
commit | 3e7873217cad8b6f67839cb06d1e126ca231bc42 (patch) | |
tree | d71382a612f63ab5d2351460a0848f46a8bbba61 /test | |
parent | e21bab7ce65e6a4db0ea966b3336eaab2a634e6e (diff) | |
download | tracifyjs-3e7873217cad8b6f67839cb06d1e126ca231bc42.tar.gz tracifyjs-3e7873217cad8b6f67839cb06d1e126ca231bc42.zip |
improve `unused` on built-in functions (#2817)
Diffstat (limited to 'test')
-rw-r--r-- | test/compress/collapse_vars.js | 23 | ||||
-rw-r--r-- | test/compress/dead-code.js | 17 | ||||
-rw-r--r-- | test/compress/evaluate.js | 36 |
3 files changed, 68 insertions, 8 deletions
diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js index 9597b67f..970f822e 100644 --- a/test/compress/collapse_vars.js +++ b/test/compress/collapse_vars.js @@ -4089,3 +4089,26 @@ cascade_forin: { "2", ] } + +unsafe_builtin: { + options = { + collapse_vars: true, + pure_getters: "strict", + unsafe: true, + unused: true, + } + input: { + function f(a) { + var b = Math.abs(a); + return Math.pow(b, 2); + } + console.log(f(-1), f(2)); + } + expect: { + function f(a) { + return Math.pow(Math.abs(a), 2); + } + console.log(f(-1), f(2)); + } + expect_stdout: "1 4" +} diff --git a/test/compress/dead-code.js b/test/compress/dead-code.js index afc8c568..b66d5ac1 100644 --- a/test/compress/dead-code.js +++ b/test/compress/dead-code.js @@ -862,3 +862,20 @@ issue_2749: { } expect_stdout: "PASS" } + +unsafe_builtin: { + options = { + side_effects: true, + unsafe: true, + } + input: { + (!w).constructor(x); + Math.abs(y); + [ 1, 2, z ].valueOf(); + } + expect: { + w, x; + y; + z; + } +} diff --git a/test/compress/evaluate.js b/test/compress/evaluate.js index 6106fce3..d40880f3 100644 --- a/test/compress/evaluate.js +++ b/test/compress/evaluate.js @@ -1194,6 +1194,9 @@ issue_2231_1: { console.log(Object.keys(void 0)); } expect_stdout: true + expect_warnings: [ + "WARN: Error evaluating Object.keys(void 0) [test/compress/evaluate.js:1191,20]", + ] } issue_2231_2: { @@ -1208,6 +1211,23 @@ issue_2231_2: { console.log(Object.getOwnPropertyNames(null)); } expect_stdout: true + expect_warnings: [ + "WARN: Error evaluating Object.getOwnPropertyNames(null) [test/compress/evaluate.js:1208,20]", + ] +} + +issue_2231_3: { + options = { + evaluate: true, + unsafe: true, + } + input: { + console.log(Object.keys({ foo: "bar" })[0]); + } + expect: { + console.log("foo"); + } + expect_stdout: "foo" } self_comparison_1: { @@ -1330,13 +1350,13 @@ issue_2535_3: { } expect_stdout: true expect_warnings: [ - "WARN: Dropping side-effect-free && [test/compress/evaluate.js:1316,20]", - "WARN: Dropping side-effect-free && [test/compress/evaluate.js:1317,20]", - "WARN: Dropping side-effect-free && [test/compress/evaluate.js:1318,20]", - "WARN: Condition left of && always false [test/compress/evaluate.js:1318,20]", - "WARN: Dropping side-effect-free || [test/compress/evaluate.js:1319,20]", - "WARN: Dropping side-effect-free || [test/compress/evaluate.js:1320,20]", - "WARN: Dropping side-effect-free || [test/compress/evaluate.js:1321,20]", - "WARN: Condition left of || always true [test/compress/evaluate.js:1321,20]", + "WARN: Dropping side-effect-free && [test/compress/evaluate.js:1336,20]", + "WARN: Dropping side-effect-free && [test/compress/evaluate.js:1337,20]", + "WARN: Dropping side-effect-free && [test/compress/evaluate.js:1338,20]", + "WARN: Condition left of && always false [test/compress/evaluate.js:1338,20]", + "WARN: Dropping side-effect-free || [test/compress/evaluate.js:1339,20]", + "WARN: Dropping side-effect-free || [test/compress/evaluate.js:1340,20]", + "WARN: Dropping side-effect-free || [test/compress/evaluate.js:1341,20]", + "WARN: Condition left of || always true [test/compress/evaluate.js:1341,20]", ] } |