aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2019-03-20 06:37:51 +0800
committerGitHub <noreply@github.com>2019-03-20 06:37:51 +0800
commitf2286c33f1245ba20f82a9429464c88c5c15b47f (patch)
tree67a37fea5f3d6db90f3094e65f8793693bddd7cb /test
parentb9615f7a62c8d9fb5721b1699d2f4f3f14bcc5be (diff)
downloadtracifyjs-f2286c33f1245ba20f82a9429464c88c5c15b47f.tar.gz
tracifyjs-f2286c33f1245ba20f82a9429464c88c5c15b47f.zip
enhance `unsafe` for `Array` (#3349)
Diffstat (limited to 'test')
-rw-r--r--test/compress/arrays.js110
-rw-r--r--test/compress/reduce_vars.js21
2 files changed, 131 insertions, 0 deletions
diff --git a/test/compress/arrays.js b/test/compress/arrays.js
index 36292206..497e96c4 100644
--- a/test/compress/arrays.js
+++ b/test/compress/arrays.js
@@ -239,3 +239,113 @@ index_length: {
}
expect_stdout: "1 2"
}
+
+constructor_bad: {
+ options = {
+ unsafe: true
+ }
+ input: {
+ try {
+ Array(NaN);
+ console.log("FAIL1");
+ } catch (ex) {
+ try {
+ new Array(NaN);
+ console.log("FAIL2");
+ } catch (ex) {
+ console.log("PASS");
+ }
+ }
+ try {
+ Array(3.14);
+ console.log("FAIL1");
+ } catch (ex) {
+ try {
+ new Array(3.14);
+ console.log("FAIL2");
+ } catch (ex) {
+ console.log("PASS");
+ }
+ }
+ }
+ expect: {
+ try {
+ Array(NaN);
+ console.log("FAIL1");
+ } catch (ex) {
+ try {
+ Array(NaN);
+ console.log("FAIL2");
+ } catch (ex) {
+ console.log("PASS");
+ }
+ }
+ try {
+ Array(3.14);
+ console.log("FAIL1");
+ } catch (ex) {
+ try {
+ Array(3.14);
+ console.log("FAIL2");
+ } catch (ex) {
+ console.log("PASS");
+ }
+ }
+ }
+ expect_stdout: [
+ "PASS",
+ "PASS",
+ ]
+ expect_warnings: [
+ "WARN: Invalid array length: 3.14 [test/compress/arrays.js:13,12]",
+ "WARN: Invalid array length: 3.14 [test/compress/arrays.js:17,16]",
+ ]
+}
+
+constructor_good: {
+ options = {
+ unsafe: true
+ }
+ input: {
+ console.log(Array());
+ console.log(Array(0));
+ console.log(Array(1));
+ console.log(Array(6));
+ console.log(Array(7));
+ console.log(Array(1, 2));
+ console.log(Array(false));
+ console.log(Array("foo"));
+ console.log(Array(Array));
+ console.log(new Array());
+ console.log(new Array(0));
+ console.log(new Array(1));
+ console.log(new Array(6));
+ console.log(new Array(7));
+ console.log(new Array(1, 2));
+ console.log(new Array(false));
+ console.log(new Array("foo"));
+ console.log(new Array(Array));
+ }
+ expect: {
+ console.log([]);
+ console.log([]);
+ console.log([,]);
+ console.log([,,,,,,]);
+ console.log(Array(7));
+ console.log([ 1, 2 ]);
+ console.log([ false ]);
+ console.log([ "foo" ]);
+ console.log(Array(Array));
+ console.log([]);
+ console.log([]);
+ console.log([,]);
+ console.log([,,,,,,]);
+ console.log(Array(7));
+ console.log([ 1, 2 ]);
+ console.log([ false ]);
+ console.log([ "foo" ]);
+ console.log(Array(Array));
+ }
+ expect_stdout: true
+ expect_warnings: []
+}
diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js
index 27e53452..fb5038b5 100644
--- a/test/compress/reduce_vars.js
+++ b/test/compress/reduce_vars.js
@@ -6716,3 +6716,24 @@ issue_3297: {
}
expect_stdout: "true"
}
+
+drop_side_effect_free: {
+ options = {
+ collapse_vars: true,
+ evaluate: true,
+ reduce_vars: true,
+ side_effects: true,
+ toplevel: true,
+ }
+ input: {
+ var a = 123;
+ "" + (a && (a.b = 0) || a);
+ console.log(a);
+ }
+ expect: {
+ var a = 123;
+ a.b = 0;
+ console.log(a);
+ }
+ expect_stdout: "123"
+}