aboutsummaryrefslogtreecommitdiff
path: root/test/compress
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2017-10-22 20:10:13 +0800
committerGitHub <noreply@github.com>2017-10-22 20:10:13 +0800
commit24aa07855bc608f29cca2a58a40af1988256b116 (patch)
tree52428c6db4496e196b2837dbe7b73324e32558b5 /test/compress
parent5fd723f14394b74f899e7b33bc9084317bf01d7d (diff)
downloadtracifyjs-24aa07855bc608f29cca2a58a40af1988256b116.tar.gz
tracifyjs-24aa07855bc608f29cca2a58a40af1988256b116.zip
safer `properties` transform (#2391)
`{ a: x, b: y }.a` => `[ x, y ][0]` - `x` cannot be function containing `this` `[ x, y, z ][1]` => `(x, z, y)` - only if `z` is side-effect-free
Diffstat (limited to 'test/compress')
-rw-r--r--test/compress/collapse_vars.js67
-rw-r--r--test/compress/evaluate.js22
-rw-r--r--test/compress/functions.js2
-rw-r--r--test/compress/properties.js145
-rw-r--r--test/compress/reduce_vars.js4
5 files changed, 150 insertions, 90 deletions
diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js
index 52b2ddf8..1f702ad7 100644
--- a/test/compress/collapse_vars.js
+++ b/test/compress/collapse_vars.js
@@ -2534,73 +2534,6 @@ issue_2319_3: {
expect_stdout: "true"
}
-prop_side_effects_1: {
- options = {
- collapse_vars: true,
- evaluate: true,
- pure_getters: "strict",
- reduce_vars: true,
- toplevel: true,
- unsafe: true,
- unused: true,
- }
- input: {
- var C = 1;
- console.log(C);
- var obj = {
- bar: function() {
- return C + C;
- }
- };
- console.log(obj.bar());
- }
- expect: {
- console.log(1);
- console.log({
- bar: function() {
- return 2;
- }
- }.bar());
- }
- expect_stdout: [
- "1",
- "2",
- ]
-}
-
-prop_side_effects_2: {
- options = {
- collapse_vars: true,
- evaluate: true,
- inline: true,
- passes: 2,
- pure_getters: "strict",
- reduce_vars: true,
- side_effects: true,
- toplevel: true,
- unsafe: true,
- unused: true,
- }
- input: {
- var C = 1;
- console.log(C);
- var obj = {
- bar: function() {
- return C + C;
- }
- };
- console.log(obj.bar());
- }
- expect: {
- console.log(1);
- console.log(2);
- }
- expect_stdout: [
- "1",
- "2",
- ]
-}
-
issue_2365: {
options = {
collapse_vars: true,
diff --git a/test/compress/evaluate.js b/test/compress/evaluate.js
index 5f5a4a93..fe9464bc 100644
--- a/test/compress/evaluate.js
+++ b/test/compress/evaluate.js
@@ -386,10 +386,10 @@ unsafe_object_accessor: {
}
}
-unsafe_function: {
+prop_function: {
options = {
- evaluate : true,
- unsafe : true
+ evaluate: true,
+ properties: true,
}
input: {
console.log(
@@ -402,9 +402,9 @@ unsafe_function: {
expect: {
console.log(
({a:{b:1},b:function(){}}) + 1,
- ({b:function(){}}, {b:1}) + 1,
- ({a:{b:1}}, function(){}) + 1,
- ({b:function(){}}, {b:1}).b + 1
+ ({b:1}) + 1,
+ function(){} + 1,
+ 2
);
}
expect_stdout: true
@@ -630,10 +630,10 @@ unsafe_string_bad_index: {
expect_stdout: true
}
-unsafe_prototype_function: {
+prototype_function: {
options = {
- evaluate : true,
- unsafe : true
+ evaluate: true,
+ properties: true,
}
input: {
var a = ({valueOf: 0}) < 1;
@@ -652,8 +652,8 @@ unsafe_prototype_function: {
var d = ({toString: 0}) + "";
var e = (({valueOf: 0}) + "")[2];
var f = (({toString: 0}) + "")[2];
- var g = ({}, 0)();
- var h = ({}, 0)();
+ var g = 0();
+ var h = 0();
}
}
diff --git a/test/compress/functions.js b/test/compress/functions.js
index 6c82557d..febf81c1 100644
--- a/test/compress/functions.js
+++ b/test/compress/functions.js
@@ -153,10 +153,10 @@ function_returning_constant_literal: {
options = {
inline: true,
passes: 2,
+ properties: true,
reduce_vars: true,
side_effects: true,
toplevel: true,
- unsafe: true,
unused: true,
}
input: {
diff --git a/test/compress/properties.js b/test/compress/properties.js
index 496a43ca..f435d371 100644
--- a/test/compress/properties.js
+++ b/test/compress/properties.js
@@ -677,8 +677,8 @@ accessor_this: {
issue_2208_1: {
options = {
inline: true,
+ properties: true,
side_effects: true,
- unsafe: true,
}
input: {
console.log({
@@ -696,8 +696,8 @@ issue_2208_1: {
issue_2208_2: {
options = {
inline: true,
+ properties: true,
side_effects: true,
- unsafe: true,
}
input: {
console.log({
@@ -721,8 +721,8 @@ issue_2208_2: {
issue_2208_3: {
options = {
inline: true,
+ properties: true,
side_effects: true,
- unsafe: true,
}
input: {
a = 42;
@@ -746,8 +746,8 @@ issue_2208_3: {
issue_2208_4: {
options = {
inline: true,
+ properties: true,
side_effects: true,
- unsafe: true,
}
input: {
function foo() {}
@@ -770,8 +770,8 @@ issue_2208_4: {
issue_2208_5: {
options = {
inline: true,
+ properties: true,
side_effects: true,
- unsafe: true,
}
input: {
console.log({
@@ -808,7 +808,7 @@ issue_2256: {
lhs_prop_1: {
options = {
evaluate: true,
- unsafe: true,
+ properties: true,
}
input: {
console.log(++{
@@ -827,9 +827,9 @@ lhs_prop_2: {
options = {
evaluate: true,
inline: true,
+ properties: true,
reduce_vars: true,
side_effects: true,
- unsafe: true,
unused: true,
}
input: {
@@ -844,7 +844,7 @@ lhs_prop_2: {
literal_duplicate_key_side_effects: {
options = {
- unsafe: true,
+ properties: true,
}
input: {
console.log({
@@ -853,10 +853,137 @@ literal_duplicate_key_side_effects: {
}.a);
}
expect: {
+ console.log(console.log ? "PASS" : "FAIL");
+ }
+ expect_stdout: "PASS"
+}
+
+prop_side_effects_1: {
+ options = {
+ evaluate: true,
+ inline: true,
+ properties: true,
+ reduce_vars: true,
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ var C = 1;
+ console.log(C);
+ var obj = {
+ bar: function() {
+ return C + C;
+ }
+ };
+ console.log(obj.bar());
+ }
+ expect: {
+ console.log(1);
+ var obj = {
+ bar: function() {
+ return 2;
+ }
+ };
+ console.log(obj.bar());
+ }
+ expect_stdout: [
+ "1",
+ "2",
+ ]
+}
+
+prop_side_effects_2: {
+ options = {
+ evaluate: true,
+ inline: true,
+ passes: 2,
+ properties: true,
+ reduce_vars: true,
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ var C = 1;
+ console.log(C);
+ var obj = {
+ bar: function() {
+ return C + C;
+ }
+ };
+ console.log(obj.bar());
+ }
+ expect: {
+ console.log(1);
+ console.log(2);
+ }
+ expect_stdout: [
+ "1",
+ "2",
+ ]
+}
+
+accessor_1: {
+ options = {
+ properties: true,
+ }
+ input: {
+ console.log({
+ a: "FAIL",
+ get a() {
+ return "PASS";
+ }
+ }.a);
+ }
+ expect: {
console.log({
a: "FAIL",
- a: console.log ? "PASS" : "FAIL"
+ get a() {
+ return "PASS";
+ }
}.a);
}
expect_stdout: "PASS"
+ node_version: ">=4"
+}
+
+accessor_2: {
+ options = {
+ properties: true,
+ }
+ input: {
+ console.log({
+ get a() {
+ return "PASS";
+ },
+ set a(v) {},
+ a: "FAIL"
+ }.a);
+ }
+ expect: {
+ console.log({
+ get a() {
+ return "PASS";
+ },
+ set a(v) {},
+ a: "FAIL"
+ }.a);
+ }
+ expect_stdout: true
+}
+
+array_hole: {
+ options = {
+ properties: true,
+ }
+ input: {
+ console.log(
+ [ 1, 2, , 3][1],
+ [ 1, 2, , 3][2],
+ [ 1, 2, , 3][3]
+ );
+ }
+ expect: {
+ console.log(2, void 0, 3);
+ }
+ expect_stdout: "2 undefined 3"
}
diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js
index 681dafd3..1274024f 100644
--- a/test/compress/reduce_vars.js
+++ b/test/compress/reduce_vars.js
@@ -2660,8 +2660,8 @@ obj_var_2: {
evaluate: true,
inline: true,
passes: 2,
+ properties: true,
reduce_vars: true,
- side_effects: true,
toplevel: true,
unsafe: true,
unused: true,
@@ -2716,10 +2716,10 @@ obj_arg_2: {
evaluate: true,
inline: true,
passes: 2,
+ properties: true,
reduce_vars: true,
side_effects: true,
toplevel: true,
- unsafe: true,
unused: true,
}
input: {