aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authoralexlamsl <alexlamsl@gmail.com>2017-02-18 19:07:52 +0800
committeralexlamsl <alexlamsl@gmail.com>2017-02-21 13:29:57 +0800
commit6b3c49e45837e8e1b32b60fe3b217b965ac16efd (patch)
tree3e95051778ccaf07859353ef38a1bad53d35f814 /test
parentf584ca8d0766fb6d2a254dd4487afa91ed2c5034 (diff)
downloadtracifyjs-6b3c49e45837e8e1b32b60fe3b217b965ac16efd.tar.gz
tracifyjs-6b3c49e45837e8e1b32b60fe3b217b965ac16efd.zip
improve string concatenation
shuffle associative operations to minimise parentheses and aid other uglification efforts closes #1454
Diffstat (limited to 'test')
-rw-r--r--test/compress/arrays.js8
-rw-r--r--test/compress/concat-strings.js140
2 files changed, 144 insertions, 4 deletions
diff --git a/test/compress/arrays.js b/test/compress/arrays.js
index 2e1f86ed..f0ded06c 100644
--- a/test/compress/arrays.js
+++ b/test/compress/arrays.js
@@ -51,7 +51,7 @@ constant_join: {
var c = boo() + "foo123bar" + bar();
var c1 = "" + boo() + bar() + "foo123bar" + bar();
var c2 = "12foobar" + baz();
- var c3 = boo() + bar() + "foo123bar" + (bar() + "foo");
+ var c3 = boo() + bar() + "foo123bar" + bar() + "foo";
var c4 = "12foobar" + baz();
var c5 = [ boo() + bar() + "foo", 1, 2, 3, "bar", bar() + "foo" ].join();
var c6 = [ "1,2,,,foo,bar", baz() ].join();
@@ -117,11 +117,11 @@ constant_join_3: {
var d = "" + foo;
var e = [ foo, "-", bar ].join("-");
var f = "" + foo + bar;
- var g = "foo" + (bar + "baz");
+ var g = "foo" + bar + "baz";
var h = [ "-foo-", bar + "baz" ].join("-");
- var i = "foo" + bar + (baz + "moo");
+ var i = "foo" + bar + baz + "moo";
var j = foo + "bar" + baz;
- var k = foo + ("bar" + baz);
+ var k = foo + "bar" + baz;
var l = foo + (bar + "baz");
}
}
diff --git a/test/compress/concat-strings.js b/test/compress/concat-strings.js
index 50eef8b8..d2503c6d 100644
--- a/test/compress/concat-strings.js
+++ b/test/compress/concat-strings.js
@@ -24,3 +24,143 @@ concat_1: {
var f = "\x00360\08\0";
}
}
+
+concat_2: {
+ options = {};
+ input: {
+ console.log(
+ 1 + (2 + 3),
+ 1 + (2 + "3"),
+ 1 + ("2" + 3),
+ 1 + ("2" + "3"),
+ "1" + (2 + 3),
+ "1" + (2 + "3"),
+ "1" + ("2" + 3),
+ "1" + ("2" + "3")
+ );
+ }
+ expect: {
+ console.log(
+ 1 + (2 + 3),
+ 1 + (2 + "3"),
+ 1 + "2" + 3,
+ 1 + "2" + "3",
+ "1" + (2 + 3),
+ "1" + 2 + "3",
+ "1" + "2" + 3,
+ "1" + "2" + "3"
+ );
+ }
+}
+
+concat_3: {
+ options = {};
+ input: {
+ console.log(
+ 1 + 2 + (3 + 4 + 5),
+ 1 + 2 + (3 + 4 + "5"),
+ 1 + 2 + (3 + "4" + 5),
+ 1 + 2 + (3 + "4" + "5"),
+ 1 + 2 + ("3" + 4 + 5),
+ 1 + 2 + ("3" + 4 + "5"),
+ 1 + 2 + ("3" + "4" + 5),
+ 1 + 2 + ("3" + "4" + "5")
+ );
+ }
+ expect: {
+ console.log(
+ 1 + 2 + (3 + 4 + 5),
+ 1 + 2 + (3 + 4 + "5"),
+ 1 + 2 + (3 + "4") + 5,
+ 1 + 2 + (3 + "4") + "5",
+ 1 + 2 + "3" + 4 + 5,
+ 1 + 2 + "3" + 4 + "5",
+ 1 + 2 + "3" + "4" + 5,
+ 1 + 2 + "3" + "4" + "5"
+ );
+ }
+}
+
+concat_4: {
+ options = {};
+ input: {
+ console.log(
+ 1 + "2" + (3 + 4 + 5),
+ 1 + "2" + (3 + 4 + "5"),
+ 1 + "2" + (3 + "4" + 5),
+ 1 + "2" + (3 + "4" + "5"),
+ 1 + "2" + ("3" + 4 + 5),
+ 1 + "2" + ("3" + 4 + "5"),
+ 1 + "2" + ("3" + "4" + 5),
+ 1 + "2" + ("3" + "4" + "5")
+ );
+ }
+ expect: {
+ console.log(
+ 1 + "2" + (3 + 4 + 5),
+ 1 + "2" + (3 + 4) + "5",
+ 1 + "2" + 3 + "4" + 5,
+ 1 + "2" + 3 + "4" + "5",
+ 1 + "2" + "3" + 4 + 5,
+ 1 + "2" + "3" + 4 + "5",
+ 1 + "2" + "3" + "4" + 5,
+ 1 + "2" + "3" + "4" + "5"
+ );
+ }
+}
+
+concat_5: {
+ options = {};
+ input: {
+ console.log(
+ "1" + 2 + (3 + 4 + 5),
+ "1" + 2 + (3 + 4 + "5"),
+ "1" + 2 + (3 + "4" + 5),
+ "1" + 2 + (3 + "4" + "5"),
+ "1" + 2 + ("3" + 4 + 5),
+ "1" + 2 + ("3" + 4 + "5"),
+ "1" + 2 + ("3" + "4" + 5),
+ "1" + 2 + ("3" + "4" + "5")
+ );
+ }
+ expect: {
+ console.log(
+ "1" + 2 + (3 + 4 + 5),
+ "1" + 2 + (3 + 4) + "5",
+ "1" + 2 + 3 + "4" + 5,
+ "1" + 2 + 3 + "4" + "5",
+ "1" + 2 + "3" + 4 + 5,
+ "1" + 2 + "3" + 4 + "5",
+ "1" + 2 + "3" + "4" + 5,
+ "1" + 2 + "3" + "4" + "5"
+ );
+ }
+}
+
+concat_6: {
+ options = {};
+ input: {
+ console.log(
+ "1" + "2" + (3 + 4 + 5),
+ "1" + "2" + (3 + 4 + "5"),
+ "1" + "2" + (3 + "4" + 5),
+ "1" + "2" + (3 + "4" + "5"),
+ "1" + "2" + ("3" + 4 + 5),
+ "1" + "2" + ("3" + 4 + "5"),
+ "1" + "2" + ("3" + "4" + 5),
+ "1" + "2" + ("3" + "4" + "5")
+ );
+ }
+ expect: {
+ console.log(
+ "1" + "2" + (3 + 4 + 5),
+ "1" + "2" + (3 + 4) + "5",
+ "1" + "2" + 3 + "4" + 5,
+ "1" + "2" + 3 + "4" + "5",
+ "1" + "2" + "3" + 4 + 5,
+ "1" + "2" + "3" + 4 + "5",
+ "1" + "2" + "3" + "4" + 5,
+ "1" + "2" + "3" + "4" + "5"
+ );
+ }
+}