From d9cd3d33c8f2b769da922d355373d466f8b30704 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Sat, 28 Dec 2019 20:26:15 +0000 Subject: enhance `evaluate` (#3649) --- test/compress/hoist_props.js | 2 +- test/compress/numbers.js | 82 ++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 81 insertions(+), 3 deletions(-) (limited to 'test/compress') diff --git a/test/compress/hoist_props.js b/test/compress/hoist_props.js index 0d8e771a..c647ccc1 100644 --- a/test/compress/hoist_props.js +++ b/test/compress/hoist_props.js @@ -664,7 +664,7 @@ issue_2519: { } expect: { function testFunc() { - return 1 * ((6 + 5) / 2); + return +((6 + 5) / 2); } console.log(testFunc()); } diff --git a/test/compress/numbers.js b/test/compress/numbers.js index 673ce23a..c432a435 100644 --- a/test/compress/numbers.js +++ b/test/compress/numbers.js @@ -91,7 +91,7 @@ evaluate_1: { expect: { console.log( x + 1 + 2, - 1 * x * 2, + 2 * x, +x + 1 + 2, 1 + x + 2 + 3, 3 | x, @@ -173,7 +173,7 @@ evaluate_2: { var x = "42", y = null; [ x + 1 + 2, - 1 * x * 2, + 2 * x, +x + 1 + 2, 1 + x + 2 + 3, 3 | x, @@ -979,3 +979,81 @@ unsafe_math_swap_constant: { } expect_stdout: "6 6 7 6 6 8 9 10" } + +identity_1: { + options = { + evaluate: true, + } + input: { + 0 + a; + a + 0; + 0 - a; + a - 0; + 1 * a; + a * 1; + 1 / a; + a / 1; + } + expect: { + 0 + a; + a + 0; + -a; + +a; + +a; + +a; + 1 / a; + +a; + } +} + +identity_2: { + options = { + evaluate: true, + } + input: { + 0 + !a; + !a + 0; + 0 - !a; + !a - 0; + 1 * !a; + !a * 1; + 1 / !a; + !a / 1; + } + expect: { + +!a; + +!a; + -!a; + +!a; + +!a; + +!a; + 1 / !a; + +!a; + } +} + +identity_3: { + options = { + evaluate: true, + } + input: { + 0 + --a; + --a + 0; + 0 - --a; + --a - 0; + 1 * --a; + --a * 1; + 1 / --a; + --a / 1; + } + expect: { + --a; + --a; + - --a; + --a; + --a; + --a; + 1 / --a; + --a; + } +} -- cgit v1.2.3