aboutsummaryrefslogtreecommitdiff
path: root/test/compress
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2021-01-07 02:04:09 +0000
committerGitHub <noreply@github.com>2021-01-07 10:04:09 +0800
commitc3d358a5b8e00c51ba7a2e9d8c25b7771f5f5a46 (patch)
treed255e5d319d1e872a966578b9377d31e87caaed3 /test/compress
parent68497d025877a4f364187c9ce771d863c73fe7f0 (diff)
downloadtracifyjs-c3d358a5b8e00c51ba7a2e9d8c25b7771f5f5a46.tar.gz
tracifyjs-c3d358a5b8e00c51ba7a2e9d8c25b7771f5f5a46.zip
support rest parameters (#4515)
Diffstat (limited to 'test/compress')
-rw-r--r--test/compress/awaits.js (renamed from test/compress/async.js)0
-rw-r--r--test/compress/rests.js487
-rw-r--r--test/compress/spreads.js (renamed from test/compress/spread.js)28
3 files changed, 501 insertions, 14 deletions
diff --git a/test/compress/async.js b/test/compress/awaits.js
index 7ae753fb..7ae753fb 100644
--- a/test/compress/async.js
+++ b/test/compress/awaits.js
diff --git a/test/compress/rests.js b/test/compress/rests.js
new file mode 100644
index 00000000..1a27860d
--- /dev/null
+++ b/test/compress/rests.js
@@ -0,0 +1,487 @@
+arrow_1: {
+ input: {
+ console.log.apply(console, ((...a) => a)("PASS", 42));
+ }
+ expect_exact: 'console.log.apply(console,((...a)=>a)("PASS",42));'
+ expect_stdout: "PASS 42"
+ node_version: ">=6"
+}
+
+arrow_2: {
+ input: {
+ console.log.apply(console, ((a, ...b) => b)("FAIL", "PASS", 42));
+ }
+ expect_exact: 'console.log.apply(console,((a,...b)=>b)("FAIL","PASS",42));'
+ expect_stdout: "PASS 42"
+ node_version: ">=6"
+}
+
+arrow_destructured_array_1: {
+ input: {
+ console.log.apply(console, (([ ...a ]) => a)("PASS"));
+ }
+ expect_exact: 'console.log.apply(console,(([...a])=>a)("PASS"));'
+ expect_stdout: "P A S S"
+ node_version: ">=6"
+}
+
+arrow_destructured_array_2: {
+ input: {
+ console.log.apply(console, (([ a, ...b ]) => b)([ "FAIL", "PASS", 42 ]));
+ }
+ expect_exact: 'console.log.apply(console,(([a,...b])=>b)(["FAIL","PASS",42]));'
+ expect_stdout: "PASS 42"
+ node_version: ">=6"
+}
+
+arrow_destructured_array_3: {
+ input: {
+ console.log((([ [ ...a ] = "FAIL" ]) => a)([ "PASS" ]).join("|"));
+ }
+ expect_exact: 'console.log((([[...a]="FAIL"])=>a)(["PASS"]).join("|"));'
+ expect_stdout: "P|A|S|S"
+ node_version: ">=6"
+}
+
+arrow_destructured_object_1: {
+ input: {
+ var f = ({ ...a }) => a, o = f({ PASS: 42 });
+ for (var k in o)
+ console.log(k, o[k]);
+ }
+ expect_exact: "var f=({...a})=>a,o=f({PASS:42});for(var k in o)console.log(k,o[k]);"
+ expect_stdout: "PASS 42"
+ node_version: ">=8"
+}
+
+arrow_destructured_object_2: {
+ input: {
+ var f = ({ FAIL: a, ...b }) => b, o = f({ PASS: 42, FAIL: null });
+ for (var k in o)
+ console.log(k, o[k]);
+ }
+ expect_exact: "var f=({FAIL:a,...b})=>b,o=f({PASS:42,FAIL:null});for(var k in o)console.log(k,o[k]);"
+ expect_stdout: "PASS 42"
+ node_version: ">=8"
+}
+
+arrow_destructured_object_3: {
+ input: {
+ var f = ([ { ...a } = [ "FAIL" ] ]) => a;
+ var o = f([ "PASS" ]);
+ for (var k in o)
+ console.log(k, o[k]);
+ }
+ expect_exact: 'var f=([{...a}=["FAIL"]])=>a;var o=f(["PASS"]);for(var k in o)console.log(k,o[k]);'
+ expect_stdout: [
+ "0 P",
+ "1 A",
+ "2 S",
+ "3 S",
+ ]
+ node_version: ">=8"
+}
+
+funarg_1: {
+ input: {
+ console.log.apply(console, function(...a) {
+ return a;
+ }("PASS", 42));
+ }
+ expect_exact: 'console.log.apply(console,function(...a){return a}("PASS",42));'
+ expect_stdout: "PASS 42"
+ node_version: ">=6"
+}
+
+funarg_2: {
+ input: {
+ console.log.apply(console, function(a, ...b) {
+ return b;
+ }("FAIL", "PASS", 42));
+ }
+ expect_exact: 'console.log.apply(console,function(a,...b){return b}("FAIL","PASS",42));'
+ expect_stdout: "PASS 42"
+ node_version: ">=6"
+}
+
+destructured_array_1: {
+ input: {
+ var [ ...a ] = [ "PASS", 42 ];
+ console.log.apply(console, a);
+ }
+ expect_exact: 'var[...a]=["PASS",42];console.log.apply(console,a);'
+ expect_stdout: "PASS 42"
+ node_version: ">=6"
+}
+
+destructured_array_2: {
+ input: {
+ var [ a, ...b ] = [ "FAIL", "PASS", 42 ];
+ console.log.apply(console, b);
+ }
+ expect_exact: 'var[a,...b]=["FAIL","PASS",42];console.log.apply(console,b);'
+ expect_stdout: "PASS 42"
+ node_version: ">=6"
+}
+
+destructured_object_1: {
+ input: {
+ var { ...a } = [ "FAIL", "PASS", 42 ];
+ console.log(a[1], a[2]);
+ }
+ expect_exact: 'var{...a}=["FAIL","PASS",42];console.log(a[1],a[2]);'
+ expect_stdout: "PASS 42"
+ node_version: ">=8"
+}
+
+destructured_object_2: {
+ input: {
+ var { 0: a, ...b } = [ "FAIL", "PASS", 42 ];
+ console.log(b[1], b[2]);
+ }
+ expect_exact: 'var{0:a,...b}=["FAIL","PASS",42];console.log(b[1],b[2]);'
+ expect_stdout: "PASS 42"
+ node_version: ">=8"
+}
+
+drop_fargs: {
+ options = {
+ keep_fargs: false,
+ rests: true,
+ unused: true,
+ }
+ input: {
+ console.log(function(a, ...b) {
+ return b[0];
+ }("FAIL", "PASS"));
+ }
+ expect: {
+ console.log(function(b) {
+ return b[0];
+ }([ "PASS" ]));
+ }
+ expect_stdout: "PASS"
+ node_version: ">=6"
+}
+
+inline: {
+ options = {
+ inline: true,
+ toplevel: true,
+ }
+ input: {
+ console.log(function(a, ...[ b, c ]) {
+ return c + b + a;
+ }("SS", "A", "P"));
+ }
+ expect: {
+ console.log(([ a, ...[ b, c ] ] = [ "SS", "A", "P" ], c + b + a));
+ var a, b, c;
+ }
+ expect_stdout: "PASS"
+ node_version: ">=6"
+}
+
+retain_var: {
+ options = {
+ unused: true,
+ }
+ input: {
+ var [ ...a ] = [ "PASS" ];
+ console.log(a[0]);
+ }
+ expect: {
+ var [ ...a ] = [ "PASS" ];
+ console.log(a[0]);
+ }
+ expect_stdout: "PASS"
+ node_version: ">=6"
+}
+
+reduce_destructured_array: {
+ options = {
+ reduce_vars: true,
+ rests: true,
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ var [ ...a ] = [ "PASS" ];
+ console.log(a[0]);
+ }
+ expect: {
+ console.log([ "PASS" ][0]);
+ }
+ expect_stdout: "PASS"
+ node_version: ">=6"
+}
+
+reduce_destructured_object: {
+ options = {
+ reduce_vars: true,
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ var { ...a } = [ "PASS" ];
+ console.log(a[0]);
+ }
+ expect: {
+ var { ...a } = [ "PASS" ];
+ console.log(a[0]);
+ }
+ expect_stdout: "PASS"
+ node_version: ">=8"
+}
+
+retain_destructured_array: {
+ options = {
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ var [ a, ...b ] = [ "FAIL", "PASS", 42 ];
+ console.log.apply(console, b);
+ }
+ expect: {
+ var [ , ...b ] = [ "FAIL", "PASS", 42 ];
+ console.log.apply(console, b);
+ }
+ expect_stdout: "PASS 42"
+ node_version: ">=6"
+}
+
+retain_destructured_object_1: {
+ options = {
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ var { 0: a, ...b } = [ "FAIL", "PASS", 42 ];
+ for (var k in b)
+ console.log(k, b[k]);
+ }
+ expect: {
+ var { 0: a, ...b } = [ "FAIL", "PASS", 42 ];
+ for (var k in b)
+ console.log(k, b[k]);
+ }
+ expect_stdout: [
+ "1 PASS",
+ "2 42",
+ ]
+ node_version: ">=8"
+}
+
+retain_destructured_object_2: {
+ options = {
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ var { foo: [ a ], ...b } = { foo: [ "FAIL" ], bar: "PASS", baz: 42 };
+ for (var k in b)
+ console.log(k, b[k]);
+ }
+ expect: {
+ var { foo: [], ...b } = { foo: [ "FAIL" ], bar: "PASS", baz: 42 };
+ for (var k in b)
+ console.log(k, b[k]);
+ }
+ expect_stdout: [
+ "bar PASS",
+ "baz 42",
+ ]
+ node_version: ">=8"
+}
+
+retain_funarg_destructured_array_1: {
+ options = {
+ inline: true,
+ keep_fargs: false,
+ pure_getters: "strict",
+ unused: true,
+ }
+ input: {
+ console.log((([ ...a ]) => a)([ "PASS" ])[0]);
+ }
+ expect: {
+ console.log((([ ...a ]) => a)([ "PASS" ])[0]);
+ }
+ expect_stdout: "PASS"
+ node_version: ">=6"
+}
+
+retain_funarg_destructured_array_2: {
+ options = {
+ unused: true,
+ }
+ input: {
+ console.log(function([ a, ...b ]) {
+ return b;
+ }("bar")[1]);
+ }
+ expect: {
+ console.log(function([ , ...b ]) {
+ return b;
+ }("bar")[1]);
+ }
+ expect_stdout: "r"
+ node_version: ">=6"
+}
+
+retain_funarg_destructured_object_1: {
+ options = {
+ inline: true,
+ keep_fargs: false,
+ pure_getters: "strict",
+ unused: true,
+ }
+ input: {
+ console.log((({ ...a }) => a)([ "PASS" ])[0]);
+ }
+ expect: {
+ console.log((({ ...a }) => a)([ "PASS" ])[0]);
+ }
+ expect_stdout: "PASS"
+ node_version: ">=8"
+}
+
+retain_funarg_destructured_object_2: {
+ options = {
+ unused: true,
+ }
+ input: {
+ console.log(function({ p: a, ... b }) {
+ return b;
+ }({ p: "FAIL" }).p || "PASS");
+ }
+ expect: {
+ console.log(function({ p: a, ... b }) {
+ return b;
+ }({ p: "FAIL" }).p || "PASS");
+ }
+ expect_stdout: "PASS"
+ node_version: ">=8"
+}
+
+drop_unused_call_args_1: {
+ options = {
+ rests: true,
+ unused: true,
+ }
+ input: {
+ (function(...a) {
+ console.log(a[0]);
+ })(42, console.log("PASS"));
+ }
+ expect: {
+ (function(a) {
+ console.log(a[0]);
+ })([ 42, console.log("PASS") ]);
+ }
+ expect_stdout: [
+ "PASS",
+ "42",
+ ]
+ node_version: ">=6"
+}
+
+drop_unused_call_args_2: {
+ options = {
+ keep_fargs: false,
+ rests: true,
+ unused: true,
+ }
+ input: {
+ console.log(function(a, ...b) {
+ return b;
+ }(console).length);
+ }
+ expect: {
+ console.log(function(b) {
+ return b;
+ }((console, [])).length);
+ }
+ expect_stdout: "0"
+ node_version: ">=6"
+}
+
+merge_funarg: {
+ options = {
+ merge_vars: true,
+ }
+ input: {
+ (function(...a) {
+ var b = a.length;
+ console.log(b);
+ })();
+ }
+ expect: {
+ (function(...b) {
+ var b = b.length;
+ console.log(b);
+ })();
+ }
+ expect_stdout: "0"
+ node_version: ">=6"
+}
+
+merge_funarg_destructured_array: {
+ options = {
+ merge_vars: true,
+ }
+ input: {
+ (function([ ...a ]) {
+ var b = a.length;
+ console.log(b);
+ })([]);
+ }
+ expect: {
+ (function([ ...b ]) {
+ var b = b.length;
+ console.log(b);
+ })([]);
+ }
+ expect_stdout: "0"
+ node_version: ">=6"
+}
+
+merge_funarg_destructured_object: {
+ options = {
+ merge_vars: true,
+ }
+ input: {
+ (function({ ...a }) {
+ var b = a[0];
+ console.log(b);
+ })([ "PASS" ]);
+ }
+ expect: {
+ (function({ ...b }) {
+ var b = b[0];
+ console.log(b);
+ })([ "PASS" ]);
+ }
+ expect_stdout: "PASS"
+ node_version: ">=8"
+}
+
+keep_arguments: {
+ options = {
+ arguments: true,
+ keep_fargs: false,
+ }
+ input: {
+ (function(...[ {} ]) {
+ console.log(arguments[0]);
+ })("PASS");
+ }
+ expect: {
+ (function(...[ {} ]) {
+ console.log(arguments[0]);
+ })("PASS");
+ }
+ expect_stdout: "PASS"
+ node_version: ">=6"
+}
diff --git a/test/compress/spread.js b/test/compress/spreads.js
index 944915fe..1e4dcbf6 100644
--- a/test/compress/spread.js
+++ b/test/compress/spreads.js
@@ -128,7 +128,7 @@ dont_inline: {
do_inline: {
options = {
inline: true,
- spread: true,
+ spreads: true,
}
input: {
console.log(function(a) {
@@ -167,7 +167,7 @@ drop_empty_call_1: {
drop_empty_call_2: {
options = {
side_effects: true,
- spread: true,
+ spreads: true,
}
input: {
(function() {})(...[ console.log("PASS") ]);
@@ -181,7 +181,7 @@ drop_empty_call_2: {
convert_hole: {
options = {
- spread: true,
+ spreads: true,
}
input: {
console.log(...[ "PASS", , 42 ]);
@@ -275,7 +275,7 @@ reduce_vars_2: {
convert_setter: {
options = {
objects: true,
- spread: true,
+ spreads: true,
}
input: {
var o = {
@@ -419,7 +419,7 @@ keep_getter_4: {
keep_accessor: {
options = {
objects: true,
- spread: true,
+ spreads: true,
}
input: {
var o = {
@@ -467,7 +467,7 @@ keep_accessor: {
object_key_order_1: {
options = {
objects: true,
- spread: true,
+ spreads: true,
}
input: {
var o = {
@@ -497,7 +497,7 @@ object_key_order_1: {
object_key_order_2: {
options = {
objects: true,
- spread: true,
+ spreads: true,
}
input: {
var o = {
@@ -527,7 +527,7 @@ object_key_order_2: {
object_key_order_3: {
options = {
objects: true,
- spread: true,
+ spreads: true,
}
input: {
var o = {
@@ -557,7 +557,7 @@ object_key_order_3: {
object_key_order_4: {
options = {
objects: true,
- spread: true,
+ spreads: true,
}
input: {
var o = {
@@ -587,7 +587,7 @@ object_key_order_4: {
object_spread_array: {
options = {
objects: true,
- spread: true,
+ spreads: true,
}
input: {
var o = {
@@ -613,7 +613,7 @@ object_spread_array: {
object_spread_string: {
options = {
objects: true,
- spread: true,
+ spreads: true,
}
input: {
var o = {
@@ -670,7 +670,7 @@ unused_var_side_effects: {
issue_4329: {
options = {
objects: true,
- spread: true,
+ spreads: true,
}
input: {
console.log({
@@ -749,7 +749,7 @@ issue_4342: {
issue_4345: {
options = {
objects: true,
- spread: true,
+ spreads: true,
}
input: {
console.log({
@@ -809,7 +809,7 @@ issue_4361: {
issue_4363: {
options = {
objects: true,
- spread: true,
+ spreads: true,
}
input: {
({