aboutsummaryrefslogtreecommitdiff
path: root/test/compress/reduce_vars.js
diff options
context:
space:
mode:
Diffstat (limited to 'test/compress/reduce_vars.js')
-rw-r--r--test/compress/reduce_vars.js193
1 files changed, 189 insertions, 4 deletions
diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js
index 4e096d9d..c1da2991 100644
--- a/test/compress/reduce_vars.js
+++ b/test/compress/reduce_vars.js
@@ -172,6 +172,7 @@ unsafe_evaluate: {
options = {
evaluate : true,
reduce_vars : true,
+ side_effects : true,
unsafe : true,
unused : true
}
@@ -1898,10 +1899,7 @@ redefine_farg_3: {
console.log(f([]), g([]), h([]));
}
expect: {
- console.log(function(a) {
- var a;
- return typeof a;
- }([]), "number", "undefined");
+ console.log(typeof [], "number", "undefined");
}
expect_stdout: "object number undefined"
}
@@ -2629,3 +2627,190 @@ for_in_prop: {
}
expect_stdout: "1"
}
+
+obj_var_1: {
+ options = {
+ evaluate: true,
+ passes: 2,
+ reduce_vars: true,
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ var C = 1;
+ var obj = {
+ bar: function() {
+ return C + C;
+ }
+ };
+ console.log(obj.bar());
+ }
+ expect: {
+ console.log({
+ bar: function() {
+ return 2;
+ }
+ }.bar());
+ }
+ expect_stdout: "2"
+}
+
+obj_var_2: {
+ options = {
+ evaluate: true,
+ inline: true,
+ passes: 2,
+ reduce_vars: true,
+ side_effects: true,
+ toplevel: true,
+ unsafe: true,
+ unused: true,
+ }
+ input: {
+ var C = 1;
+ var obj = {
+ bar: function() {
+ return C + C;
+ }
+ };
+ console.log(obj.bar());
+ }
+ expect: {
+ console.log(2);
+ }
+ expect_stdout: "2"
+}
+
+obj_arg_1: {
+ options = {
+ evaluate: true,
+ inline: true,
+ passes: 2,
+ reduce_vars: true,
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ var C = 1;
+ function f(obj) {
+ return obj.bar();
+ }
+ console.log(f({
+ bar: function() {
+ return C + C;
+ }
+ }));
+ }
+ expect: {
+ console.log({
+ bar: function() {
+ return 2;
+ }
+ }.bar());
+ }
+ expect_stdout: "2"
+}
+
+obj_arg_2: {
+ options = {
+ evaluate: true,
+ inline: true,
+ passes: 2,
+ reduce_vars: true,
+ side_effects: true,
+ toplevel: true,
+ unsafe: true,
+ unused: true,
+ }
+ input: {
+ var C = 1;
+ function f(obj) {
+ return obj.bar();
+ }
+ console.log(f({
+ bar: function() {
+ return C + C;
+ }
+ }));
+ }
+ expect: {
+ console.log(2);
+ }
+ expect_stdout: "2"
+}
+
+func_arg_1: {
+ options = {
+ evaluate: true,
+ inline: true,
+ passes: 2,
+ reduce_vars: true,
+ side_effects: true,
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ var a = 42;
+ !function(a) {
+ console.log(a());
+ }(function() {
+ return a;
+ });
+ }
+ expect: {
+ console.log(42);
+ }
+ expect_stdout: "42"
+}
+
+func_arg_2: {
+ options = {
+ evaluate: true,
+ inline: true,
+ passes: 2,
+ reduce_vars: true,
+ side_effects: true,
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ var a = 42;
+ !function(a) {
+ console.log(a());
+ }(function(a) {
+ return a;
+ });
+ }
+ expect: {
+ console.log(void 0);
+ }
+ expect_stdout: "undefined"
+}
+
+regex_loop: {
+ options = {
+ reduce_vars: true,
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ function f(x) {
+ for (var r, s = "acdabcdeabbb"; r = x().exec(s);)
+ console.log(r[0]);
+ }
+ var a = /ab*/g;
+ f(function() {
+ return a;
+ });
+ }
+ expect: {
+ var a = /ab*/g;
+ (function(x) {
+ for (var r, s = "acdabcdeabbb"; r = x().exec(s);)
+ console.log(r[0]);
+ })(function() {
+ return a;
+ });
+ }
+ expect_stdout: true
+}