aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/compress/default-values.js10
-rw-r--r--test/compress/destructured.js138
-rw-r--r--test/compress/evaluate.js59
-rw-r--r--test/compress/exports.js2
-rw-r--r--test/compress/rests.js94
-rw-r--r--test/compress/spreads.js72
6 files changed, 275 insertions, 100 deletions
diff --git a/test/compress/default-values.js b/test/compress/default-values.js
index de5374fa..7b67ed17 100644
--- a/test/compress/default-values.js
+++ b/test/compress/default-values.js
@@ -279,7 +279,7 @@ reduce_array: {
console.log(a, b, c);
}
expect: {
- var [ , , c = "baz" ] = [ void 0, null ];
+ var [ c = "baz" ] = [];
console.log("foo", null, c);
}
expect_stdout: "foo null baz"
@@ -299,7 +299,7 @@ reduce_object: {
console.log(a, b, c);
}
expect: {
- var { c = "baz" } = { a: void 0, b: null };
+ var { c = "baz" } = {};
console.log("foo", null, c);
}
expect_stdout: "foo null baz"
@@ -719,7 +719,7 @@ unused_value_var_2: {
console.log(a);
}
expect: {
- var [ a ] = [ "PASS" ];
+ var a = [ "PASS" ][0];
console.log(a);
}
expect_stdout: "PASS"
@@ -1300,7 +1300,7 @@ issue_4468: {
expect: {
(function() {
var {
- [console.log("PASS")]: b = 0,
+ [console.log("PASS")]: b,
} = 0;
})();
}
@@ -1743,7 +1743,7 @@ issue_4854: {
}());
}
expect: {
- console.log(void ([] = "foo"));
+ console.log(void 0);
}
expect_stdout: "undefined"
node_version: ">=6"
diff --git a/test/compress/destructured.js b/test/compress/destructured.js
index 140d48e1..7db2d238 100644
--- a/test/compress/destructured.js
+++ b/test/compress/destructured.js
@@ -1105,7 +1105,7 @@ drop_unused_1: {
try {
throw 42;
} catch (a) {
- var [ a ] = [];
+ var a = [][0];
}
}
}
@@ -1138,6 +1138,142 @@ drop_unused_2: {
node_version: ">=6"
}
+drop_hole: {
+ options = {
+ unused: true,
+ }
+ input: {
+ var [ a ] = [ , ];
+ console.log(a);
+ }
+ expect: {
+ var a = [][0];
+ console.log(a);
+ }
+ expect_stdout: "undefined"
+ node_version: ">=6"
+}
+
+keep_key: {
+ options = {
+ evaluate: true,
+ side_effects: true,
+ unused: true,
+ }
+ input: {
+ ({} = {
+ [(console.log("PASS"), 42)]: null,
+ });
+ }
+ expect: {
+ ({} = {
+ [(console.log("PASS"), 42)]: 0,
+ });
+ }
+ expect_stdout: "PASS"
+ node_version: ">=6"
+}
+
+keep_reference: {
+ options = {
+ reduce_vars: true,
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ var a = [ {}, 42 ];
+ var [ b, c ] = a;
+ console.log(a[0] === b ? "PASS" : "FAIL");
+ }
+ expect: {
+ var a = [ {}, 42 ];
+ var [ b ] = a;
+ console.log(a[0] === b ? "PASS" : "FAIL");
+ }
+ expect_stdout: "PASS"
+ node_version: ">=6"
+}
+
+maintain_position_assign: {
+ options = {
+ unused: true,
+ }
+ input: {
+ console.log(([ , ] = [ , "PASS" ])[1]);
+ }
+ expect: {
+ console.log([ , "PASS" ][1]);
+ }
+ expect_stdout: "PASS"
+ node_version: ">=6"
+}
+
+maintain_position_var: {
+ options = {
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ A = "FAIL";
+ var [ a, b ] = [ A ];
+ console.log(b || "PASS");
+ }
+ expect: {
+ A = "FAIL";
+ var [ , b ] = [ A ];
+ console.log(b || "PASS");
+ }
+ expect_stdout: "PASS"
+ node_version: ">=6"
+}
+
+side_effects_array: {
+ options = {
+ unused: true,
+ }
+ input: {
+ try {
+ var [ a ] = 42;
+ } catch (e) {
+ console.log("PASS");
+ }
+ }
+ expect: {
+ try {
+ var [ a ] = 42;
+ } catch (e) {
+ console.log("PASS");
+ }
+ }
+ expect_stdout: "PASS"
+ node_version: ">=6"
+}
+
+side_effects_object: {
+ options = {
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ var a = null, b = console, { c } = 42;
+ try {
+ c[a = "PASS"];
+ } catch (e) {
+ console.log(a);
+ }
+ }
+ expect: {
+ var a = null, c = (console, 42["c"]);
+ try {
+ c[a = "PASS"];
+ } catch (e) {
+ console.log(a);
+ }
+ }
+ expect_stdout: "PASS"
+ node_version: ">=6"
+}
+
join_vars: {
options = {
conditionals: true,
diff --git a/test/compress/evaluate.js b/test/compress/evaluate.js
index 98ce60e8..ed58ce6f 100644
--- a/test/compress/evaluate.js
+++ b/test/compress/evaluate.js
@@ -684,26 +684,47 @@ prototype_function: {
side_effects: true,
}
input: {
- var a = ({valueOf: 0}) < 1;
- var b = ({toString: 0}) < 1;
- var c = ({valueOf: 0}) + "";
- var d = ({toString: 0}) + "";
- var e = (({valueOf: 0}) + "")[2];
- var f = (({toString: 0}) + "")[2];
- var g = ({valueOf: 0}).valueOf();
- var h = ({toString: 0}).toString();
- }
- expect: {
- var a = ({valueOf: 0}) < 1;
- var b = ({toString: 0}) < 1;
- var c = ({valueOf: 0}) + "";
- var d = ({toString: 0}) + "";
- var e = (({valueOf: 0}) + "")[2];
- var f = (({toString: 0}) + "")[2];
- var g = 0();
- var h = 0();
+ function v() {
+ return this.valueOf === v ? "PASS" : "FAIL";
+ }
+ console.log(({ valueOf: v }) < 1);
+ console.log(({ valueOf: v }) + "");
+ console.log((( {valueOf: v }) + "")[2]);
+ console.log(({ valueOf: v }).valueOf());
+ function t() {
+ return this.toString === t ? "PASS" : "FAIL";
+ }
+ console.log(({ toString: t }) < 1);
+ console.log(({ toString: t }) + "");
+ console.log((( {toString: t }) + "")[2]);
+ console.log(({ toString: t }).toString());
}
- expect_stdout: true
+ expect: {
+ function v() {
+ return this.valueOf === v ? "PASS" : "FAIL";
+ }
+ console.log(({ valueOf: v }) < 1);
+ console.log(({ valueOf: v }) + "");
+ console.log((( {valueOf: v }) + "")[2]);
+ console.log(({ valueOf: v }).valueOf());
+ function t() {
+ return this.toString === t ? "PASS" : "FAIL";
+ }
+ console.log(({ toString: t }) < 1);
+ console.log(({ toString: t }) + "");
+ console.log((( {toString: t }) + "")[2]);
+ console.log(({ toString: t }).toString());
+ }
+ expect_stdout: [
+ "false",
+ "PASS",
+ "S",
+ "PASS",
+ "false",
+ "PASS",
+ "S",
+ "PASS",
+ ]
}
call_args: {
diff --git a/test/compress/exports.js b/test/compress/exports.js
index 0917648b..005a93e6 100644
--- a/test/compress/exports.js
+++ b/test/compress/exports.js
@@ -249,7 +249,7 @@ hoist_exports_2: {
}
}
expect: {
- let e, { foo: a } = 42;
+ let e, a = 42["foo"];
function f(t, { [e]: o }) {
t(o, f);
}
diff --git a/test/compress/rests.js b/test/compress/rests.js
index a22a6b21..6293d58d 100644
--- a/test/compress/rests.js
+++ b/test/compress/rests.js
@@ -244,7 +244,7 @@ retain_destructured_array: {
console.log.apply(console, b);
}
expect: {
- var [ , ...b ] = [ "FAIL", "PASS", 42 ];
+ var [ ...b ] = [ "PASS", 42 ];
console.log.apply(console, b);
}
expect_stdout: "PASS 42"
@@ -284,7 +284,7 @@ retain_destructured_object_2: {
console.log(k, b[k]);
}
expect: {
- var { foo: [], ...b } = { foo: [ "FAIL" ], bar: "PASS", baz: 42 };
+ var { foo: {}, ...b } = { foo: 0, bar: "PASS", baz: 42 };
for (var k in b)
console.log(k, b[k]);
}
@@ -407,6 +407,24 @@ drop_unused_call_args_2: {
node_version: ">=6"
}
+maintain_position: {
+ options = {
+ unused: true,
+ }
+ input: {
+ A = "FAIL";
+ var [ , ...a ] = [ A, "PASS" ];
+ console.log(a[0]);
+ }
+ expect: {
+ A = "FAIL";
+ var [ , ...a ] = [ A, "PASS" ];
+ console.log(a[0]);
+ }
+ expect_stdout: "PASS"
+ node_version: ">=6"
+}
+
merge_funarg: {
options = {
merge_vars: true,
@@ -723,6 +741,78 @@ issue_4544_2: {
node_version: ">=6"
}
+issue_4560_1: {
+ options = {
+ evaluate: true,
+ reduce_vars: true,
+ toplevel: true,
+ }
+ input: {
+ var a = 0;
+ (function(...{
+ [a++]: {},
+ }) {})(2);
+ console.log(a);
+ }
+ expect: {
+ var a = 0;
+ (function(...{
+ [a++]: {},
+ }) {})(2);
+ console.log(a);
+ }
+ expect_stdout: "1"
+ node_version: ">=6"
+}
+
+issue_4560_2: {
+ options = {
+ reduce_vars: true,
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ var a = 0;
+ (function(...{
+ [a++]: {},
+ }) {})(2);
+ console.log(a);
+ }
+ expect: {
+ var a = 0;
+ (function(...{
+ [a++]: {},
+ }) {})(2);
+ console.log(a);
+ }
+ expect_stdout: "1"
+ node_version: ">=6"
+}
+
+issue_4560_3: {
+ options = {
+ collapse_vars: true,
+ reduce_vars: true,
+ toplevel: true,
+ }
+ input: {
+ var a = 0, b;
+ [ ...{
+ [a++]: b,
+ } ] = [ "PASS" ];
+ console.log(b);
+ }
+ expect: {
+ var a = 0, b;
+ [ ...{
+ [a++]: b,
+ } ] = [ "PASS" ];
+ console.log(b);
+ }
+ expect_stdout: "PASS"
+ node_version: ">=6"
+}
+
issue_4562: {
options = {
evaluate: true,
diff --git a/test/compress/spreads.js b/test/compress/spreads.js
index 7ef118e1..3b1ec461 100644
--- a/test/compress/spreads.js
+++ b/test/compress/spreads.js
@@ -945,78 +945,6 @@ issue_4556: {
node_version: ">=6"
}
-issue_4560_1: {
- options = {
- evaluate: true,
- reduce_vars: true,
- toplevel: true,
- }
- input: {
- var a = 0;
- (function(...{
- [a++]: {},
- }) {})(2);
- console.log(a);
- }
- expect: {
- var a = 0;
- (function(...{
- [a++]: {},
- }) {})(2);
- console.log(a);
- }
- expect_stdout: "1"
- node_version: ">=6"
-}
-
-issue_4560_2: {
- options = {
- reduce_vars: true,
- toplevel: true,
- unused: true,
- }
- input: {
- var a = 0;
- (function(...{
- [a++]: {},
- }) {})(2);
- console.log(a);
- }
- expect: {
- var a = 0;
- (function(...{
- [a++]: {},
- }) {})(2);
- console.log(a);
- }
- expect_stdout: "1"
- node_version: ">=6"
-}
-
-issue_4560_3: {
- options = {
- collapse_vars: true,
- reduce_vars: true,
- toplevel: true,
- }
- input: {
- var a = 0, b;
- [ ...{
- [a++]: b,
- } ] = [ "PASS" ];
- console.log(b);
- }
- expect: {
- var a = 0, b;
- [ ...{
- [a++]: b,
- } ] = [ "PASS" ];
- console.log(b);
- }
- expect_stdout: "PASS"
- node_version: ">=6"
-}
-
issue_4614: {
options = {
pure_getters: "strict",