aboutsummaryrefslogtreecommitdiff
path: root/test/compress/reduce_vars.js
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2017-03-09 19:11:05 +0800
committerGitHub <noreply@github.com>2017-03-09 19:11:05 +0800
commitb633706ce42576b7e2aa85a96c5691bde87e71ac (patch)
tree524e6ab7980d86f0837c188cdb35fe8aa77b7487 /test/compress/reduce_vars.js
parente9920f7ca162ce062cc481b876be293d7324a714 (diff)
downloadtracifyjs-b633706ce42576b7e2aa85a96c5691bde87e71ac.tar.gz
tracifyjs-b633706ce42576b7e2aa85a96c5691bde87e71ac.zip
fix & improve function argument compression (#1584)
- one-use function call => IIFE should take `eval()` & `arguments` into account - if unused parameter cannot be eliminated, replace it with `0` fixes #1583
Diffstat (limited to 'test/compress/reduce_vars.js')
-rw-r--r--test/compress/reduce_vars.js108
1 files changed, 108 insertions, 0 deletions
diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js
index 10dc9d98..734ce4ed 100644
--- a/test/compress/reduce_vars.js
+++ b/test/compress/reduce_vars.js
@@ -1144,3 +1144,111 @@ double_reference: {
}
}
}
+
+iife_arguments_1: {
+ options = {
+ reduce_vars: true,
+ unused: true,
+ }
+ input: {
+ (function(x) {
+ console.log(x() === arguments[0]);
+ })(function f() {
+ return f;
+ });
+ }
+ expect: {
+ (function(x) {
+ console.log(x() === arguments[0]);
+ })(function f() {
+ return f;
+ });
+ }
+}
+
+iife_arguments_2: {
+ options = {
+ reduce_vars: true,
+ unused: true,
+ }
+ input: {
+ (function() {
+ var x = function f() {
+ return f;
+ };
+ console.log(x() === arguments[0]);
+ })();
+ }
+ expect: {
+ (function() {
+ console.log(function f() {
+ return f;
+ }() === arguments[0]);
+ })();
+ }
+}
+
+iife_eval_1: {
+ options = {
+ reduce_vars: true,
+ unused: true,
+ }
+ input: {
+ (function(x) {
+ console.log(x() === eval("x"));
+ })(function f() {
+ return f;
+ });
+ }
+ expect: {
+ (function(x) {
+ console.log(x() === eval("x"));
+ })(function f() {
+ return f;
+ });
+ }
+}
+
+iife_eval_2: {
+ options = {
+ reduce_vars: true,
+ unused: true,
+ }
+ input: {
+ (function() {
+ var x = function f() {
+ return f;
+ };
+ console.log(x() === eval("x"));
+ })();
+ }
+ expect: {
+ (function() {
+ var x = function f() {
+ return f;
+ };
+ console.log(x() === eval("x"));
+ })();
+ }
+}
+
+iife_func_side_effects: {
+ options = {
+ reduce_vars: true,
+ unused: true,
+ }
+ input: {
+ (function(a, b, c) {
+ return b();
+ })(x(), function() {
+ return y();
+ }, z());
+ }
+ expect: {
+ (function(a, b, c) {
+ return function() {
+ return y();
+ }();
+ })(x(), 0, z());
+ }
+}