diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2017-04-08 14:25:28 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-08 14:25:28 +0800 |
commit | cf72fe552f5a51ccfe40c32e0fb86d549e0ca848 (patch) | |
tree | c8fae2eef25cb24475a37d06cbd502dbf5599671 /test/compress | |
parent | a1532eb076d506fbf87a04c0ec4f26e1929aa902 (diff) | |
download | tracifyjs-cf72fe552f5a51ccfe40c32e0fb86d549e0ca848.tar.gz tracifyjs-cf72fe552f5a51ccfe40c32e0fb86d549e0ca848.zip |
fix `delete` corner cases (#1799)
- assignment
- boolean
- conditional
- sequence
Diffstat (limited to 'test/compress')
-rw-r--r-- | test/compress/conditionals.js | 53 | ||||
-rw-r--r-- | test/compress/drop-unused.js | 55 | ||||
-rw-r--r-- | test/compress/evaluate.js | 79 | ||||
-rw-r--r-- | test/compress/sequences.js | 144 |
4 files changed, 330 insertions, 1 deletions
diff --git a/test/compress/conditionals.js b/test/compress/conditionals.js index e7ea2bb2..200b487f 100644 --- a/test/compress/conditionals.js +++ b/test/compress/conditionals.js @@ -962,3 +962,56 @@ condition_symbol_matches_consequent: { } expect_stdout: "3 7 true 4" } + +delete_conditional_1: { + options = { + booleans: true, + conditionals: true, + evaluate: true, + side_effects: true, + } + input: { + console.log(delete (1 ? undefined : x)); + console.log(delete (1 ? void 0 : x)); + console.log(delete (1 ? Infinity : x)); + console.log(delete (1 ? 1 / 0 : x)); + console.log(delete (1 ? NaN : x)); + console.log(delete (1 ? 0 / 0 : x)); + } + expect: { + console.log((void 0, !0)); + console.log((void 0, !0)); + console.log((1 / 0, !0)); + console.log((1 / 0, !0)); + console.log((NaN, !0)); + console.log((NaN, !0)); + } + expect_stdout: true +} + +delete_conditional_2: { + options = { + booleans: true, + conditionals: true, + evaluate: true, + keep_infinity: true, + side_effects: true, + } + input: { + console.log(delete (0 ? x : undefined)); + console.log(delete (0 ? x : void 0)); + console.log(delete (0 ? x : Infinity)); + console.log(delete (0 ? x : 1 / 0)); + console.log(delete (0 ? x : NaN)); + console.log(delete (0 ? x : 0 / 0)); + } + expect: { + console.log((void 0, !0)); + console.log((void 0, !0)); + console.log((Infinity, !0)); + console.log((1 / 0, !0)); + console.log((NaN, !0)); + console.log((NaN, !0)); + } + expect_stdout: true +} diff --git a/test/compress/drop-unused.js b/test/compress/drop-unused.js index 28118fc4..99d9cace 100644 --- a/test/compress/drop-unused.js +++ b/test/compress/drop-unused.js @@ -974,3 +974,58 @@ issue_1715_4: { } expect_stdout: "1" } + +delete_assign_1: { + options = { + booleans: true, + side_effects: true, + toplevel: true, + unused: true, + } + input: { + var a; + console.log(delete (a = undefined)); + console.log(delete (a = void 0)); + console.log(delete (a = Infinity)); + console.log(delete (a = 1 / 0)); + console.log(delete (a = NaN)); + console.log(delete (a = 0 / 0)); + } + expect: { + console.log((void 0, !0)); + console.log((void 0, !0)); + console.log((1 / 0, !0)); + console.log((1 / 0, !0)); + console.log((NaN, !0)); + console.log((0 / 0, !0)); + } + expect_stdout: true +} + +delete_assign_2: { + options = { + booleans: true, + keep_infinity: true, + side_effects: true, + toplevel: true, + unused: true, + } + input: { + var a; + console.log(delete (a = undefined)); + console.log(delete (a = void 0)); + console.log(delete (a = Infinity)); + console.log(delete (a = 1 / 0)); + console.log(delete (a = NaN)); + console.log(delete (a = 0 / 0)); + } + expect: { + console.log((void 0, !0)); + console.log((void 0, !0)); + console.log((Infinity, !0)); + console.log((1 / 0, !0)); + console.log((NaN, !0)); + console.log((0 / 0, !0)); + } + expect_stdout: true +} diff --git a/test/compress/evaluate.js b/test/compress/evaluate.js index e660071d..3c16e201 100644 --- a/test/compress/evaluate.js +++ b/test/compress/evaluate.js @@ -858,8 +858,9 @@ issue_1760_2: { expect_stdout: "Infinity" } -delete_expr: { +delete_expr_1: { options = { + booleans: true, evaluate: true, } input: { @@ -872,11 +873,87 @@ delete_expr: { } expect: { console.log(delete undefined); + console.log((void 0, !0)); + console.log(delete Infinity); + console.log((1 / 0, !0)); + console.log(delete NaN); + console.log((0 / 0, !0)); + } + expect_stdout: true +} + +delete_expr_2: { + options = { + booleans: true, + evaluate: true, + keep_infinity: true, + } + input: { + console.log(delete undefined); console.log(delete void 0); console.log(delete Infinity); console.log(delete (1 / 0)); console.log(delete NaN); console.log(delete (0 / 0)); } + expect: { + console.log(delete undefined); + console.log((void 0, !0)); + console.log(delete Infinity); + console.log((1 / 0, !0)); + console.log(delete NaN); + console.log((0 / 0, !0)); + } + expect_stdout: true +} + +delete_binary_1: { + options = { + booleans: true, + evaluate: true, + side_effects: true, + } + input: { + console.log(delete (true && undefined)); + console.log(delete (true && void 0)); + console.log(delete (true && Infinity)); + console.log(delete (true && (1 / 0))); + console.log(delete (true && NaN)); + console.log(delete (true && (0 / 0))); + } + expect: { + console.log((void 0, !0)); + console.log((void 0, !0)); + console.log((1 / 0, !0)); + console.log((1 / 0, !0)); + console.log((NaN, !0)); + console.log((NaN, !0)); + } + expect_stdout: true +} + +delete_binary_2: { + options = { + booleans: true, + evaluate: true, + keep_infinity: true, + side_effects: true, + } + input: { + console.log(delete (false || undefined)); + console.log(delete (false || void 0)); + console.log(delete (false || Infinity)); + console.log(delete (false || (1 / 0))); + console.log(delete (false || NaN)); + console.log(delete (false || (0 / 0))); + } + expect: { + console.log((void 0, !0)); + console.log((void 0, !0)); + console.log((Infinity, !0)); + console.log((1 / 0, !0)); + console.log((NaN, !0)); + console.log((NaN, !0)); + } expect_stdout: true } diff --git a/test/compress/sequences.js b/test/compress/sequences.js index b3c54635..699341c0 100644 --- a/test/compress/sequences.js +++ b/test/compress/sequences.js @@ -466,3 +466,147 @@ issue_1758: { } expect_stdout: "undefined" } + +delete_seq_1: { + options = { + booleans: true, + side_effects: true, + } + input: { + console.log(delete (1, undefined)); + console.log(delete (1, void 0)); + console.log(delete (1, Infinity)); + console.log(delete (1, 1 / 0)); + console.log(delete (1, NaN)); + console.log(delete (1, 0 / 0)); + } + expect: { + console.log((void 0, !0)); + console.log((void 0, !0)); + console.log((1 / 0, !0)); + console.log((1 / 0, !0)); + console.log((NaN, !0)); + console.log((0 / 0, !0)); + } + expect_stdout: true +} + +delete_seq_2: { + options = { + booleans: true, + side_effects: true, + } + input: { + console.log(delete (1, 2, undefined)); + console.log(delete (1, 2, void 0)); + console.log(delete (1, 2, Infinity)); + console.log(delete (1, 2, 1 / 0)); + console.log(delete (1, 2, NaN)); + console.log(delete (1, 2, 0 / 0)); + } + expect: { + console.log((void 0, !0)); + console.log((void 0, !0)); + console.log((1 / 0, !0)); + console.log((1 / 0, !0)); + console.log((NaN, !0)); + console.log((0 / 0, !0)); + } + expect_stdout: true +} + +delete_seq_3: { + options = { + booleans: true, + keep_infinity: true, + side_effects: true, + } + input: { + console.log(delete (1, 2, undefined)); + console.log(delete (1, 2, void 0)); + console.log(delete (1, 2, Infinity)); + console.log(delete (1, 2, 1 / 0)); + console.log(delete (1, 2, NaN)); + console.log(delete (1, 2, 0 / 0)); + } + expect: { + console.log((void 0, !0)); + console.log((void 0, !0)); + console.log((Infinity, !0)); + console.log((1 / 0, !0)); + console.log((NaN, !0)); + console.log((0 / 0, !0)); + } + expect_stdout: true +} + +delete_seq_4: { + options = { + booleans: true, + sequences: true, + side_effects: true, + } + input: { + function f() {} + console.log(delete (f(), undefined)); + console.log(delete (f(), void 0)); + console.log(delete (f(), Infinity)); + console.log(delete (f(), 1 / 0)); + console.log(delete (f(), NaN)); + console.log(delete (f(), 0 / 0)); + } + expect: { + function f() {} + console.log((f(), !0)), + console.log((f(), !0)), + console.log((f(), !0)), + console.log((f(), !0)), + console.log((f(), !0)), + console.log((f(), !0)); + } + expect_stdout: true +} + +delete_seq_5: { + options = { + booleans: true, + keep_infinity: true, + sequences: true, + side_effects: true, + } + input: { + function f() {} + console.log(delete (f(), undefined)); + console.log(delete (f(), void 0)); + console.log(delete (f(), Infinity)); + console.log(delete (f(), 1 / 0)); + console.log(delete (f(), NaN)); + console.log(delete (f(), 0 / 0)); + } + expect: { + function f() {} + console.log((f(), !0)), + console.log((f(), !0)), + console.log((f(), !0)), + console.log((f(), !0)), + console.log((f(), !0)), + console.log((f(), !0)); + } + expect_stdout: true +} + +delete_seq_6: { + options = { + booleans: true, + side_effects: true, + } + input: { + var a; + console.log(delete (1, a)); + } + expect: { + var a; + console.log((a, !0)); + } + expect_stdout: true +} |