fix corner case in `arguments` & `reduce_vars` (#3331)
authorAlex Lam S.L <alexlamsl@gmail.com>
Wed, 13 Mar 2019 00:46:03 +0000 (08:46 +0800)
committerGitHub <noreply@github.com>
Wed, 13 Mar 2019 00:46:03 +0000 (08:46 +0800)
fixes #3282

lib/compress.js
test/compress/arguments.js

index 9109a69..75914b3 100644 (file)
@@ -6334,8 +6334,8 @@ merge(Compressor.prototype, {
             && expr instanceof AST_SymbolRef
             && expr.name == "arguments"
             && expr.definition().orig.length == 1
-            && (fn = expr.scope) instanceof AST_Lambda
-            && prop instanceof AST_Number) {
+            && prop instanceof AST_Number
+            && (fn = expr.scope) === compressor.find_parent(AST_Lambda)) {
             var index = prop.getValue();
             var argname = fn.argnames[index];
             if (argname && compressor.has_directive("use strict")) {
index 8a19c8a..fba271c 100644 (file)
@@ -404,3 +404,175 @@ issue_3273_global_strict_reduce_vars: {
         "1 0",
     ]
 }
+
+issue_3282_1: {
+    options = {
+        arguments: true,
+        reduce_funcs: true,
+        reduce_vars: true,
+        keep_fargs: false,
+        unused: true,
+    }
+    input: {
+        (function(t) {
+            return function() {
+                t();
+            };
+        })(function() {
+            'use strict';
+            function e() {
+                return arguments[0];
+            }
+            e();
+            e();
+        })();
+    }
+    expect: {
+        (function() {
+            return function() {
+                (function() {
+                    "use strict";
+                    function e() {
+                        return arguments[0];
+                    }
+                    e();
+                    e();
+                })();
+            };
+        })()();
+    }
+    expect_stdout: true
+}
+
+issue_3282_1_passes: {
+    options = {
+        arguments: true,
+        passes: 2,
+        reduce_funcs: true,
+        reduce_vars: true,
+        keep_fargs: false,
+        unused: true,
+    }
+    input: {
+        (function(t) {
+            return function() {
+                t();
+            };
+        })(function() {
+            'use strict';
+            function e() {
+                return arguments[0];
+            }
+            e();
+            e();
+        })();
+    }
+    expect: {
+        (function() {
+            return function() {
+                (function() {
+                    "use strict";
+                    function e(argument_0) {
+                        return argument_0;
+                    }
+                    e();
+                    e();
+                })();
+            };
+        })()();
+    }
+    expect_stdout: true
+}
+
+issue_3282_2: {
+    options = {
+        arguments: true,
+        reduce_vars: true,
+        keep_fargs: false,
+        unused: true,
+    }
+    input: {
+        (function(f) {
+            f();
+        })(function() {
+            return (function(t) {
+                return function() {
+                    t();
+                };
+            })(function() {
+                'use strict';
+                function e() {
+                    return arguments[0];
+                }
+                e();
+                e();
+            })();
+        });
+    }
+    expect: {
+        (function() {
+            (function() {
+                return function(t) {
+                    return function() {
+                        t();
+                    };
+                }(function() {
+                    "use strict";
+                    function e() {
+                        return arguments[0];
+                    }
+                    e();
+                    e();
+                })();
+            })();
+        })();
+    }
+    expect_stdout: true
+}
+
+issue_3282_2_passes: {
+    options = {
+        arguments: true,
+        passes: 2,
+        reduce_vars: true,
+        keep_fargs: false,
+        unused: true,
+    }
+    input: {
+        (function(f) {
+            f();
+        })(function() {
+            return (function(t) {
+                return function() {
+                    t();
+                };
+            })(function() {
+                'use strict';
+                function e() {
+                    return arguments[0];
+                }
+                e();
+                e();
+            })();
+        });
+    }
+    expect: {
+        (function() {
+            (function() {
+                return function(t) {
+                    return function() {
+                        t();
+                    };
+                }(function() {
+                    "use strict";
+                    function e(argument_0) {
+                        return argument_0;
+                    }
+                    e();
+                    e();
+                })();
+            })();
+        })();
+    }
+    expect_stdout: true
+}