fix corner case with `arguments` (#4697)
authorAlex Lam S.L <alexlamsl@gmail.com>
Sat, 27 Feb 2021 01:26:15 +0000 (01:26 +0000)
committerGitHub <noreply@github.com>
Sat, 27 Feb 2021 01:26:15 +0000 (09:26 +0800)
fixes #4696

lib/ast.js
lib/scope.js
test/compress/arguments.js

index 5fe6efc..1aee104 100644 (file)
@@ -428,7 +428,7 @@ var AST_For = DEFNODE("For", "init condition step", {
 }, AST_IterationStatement);
 
 var AST_ForEnumeration = DEFNODE("ForEnumeration", "init object", {
-    $documentation: "Base class for enumeration loops, i.e. `for ... in`, `for ... of` &  `for await ... of`",
+    $documentation: "Base class for enumeration loops, i.e. `for ... in`, `for ... of` & `for await ... of`",
     $propdoc: {
         init: "[AST_Node] the assignment target during iteration",
         object: "[AST_Node] the object to iterate over"
index 600a686..b22f77a 100644 (file)
@@ -108,6 +108,7 @@ function is_lhs(node, parent) {
     if (parent instanceof AST_DefaultValue) return parent.name === node && node;
     if (parent instanceof AST_Destructured) return node;
     if (parent instanceof AST_DestructuredKeyVal) return node;
+    if (parent instanceof AST_ForEnumeration) return parent.init === node && node;
     if (parent instanceof AST_Unary) return unary_side_effects[parent.operator] && parent.expression;
 }
 
index 655d75a..4c602a6 100644 (file)
@@ -977,3 +977,25 @@ issue_4432: {
     }
     expect_stdout: "PASS"
 }
+
+issue_4696: {
+    options = {
+        arguments: true,
+        keep_fargs: false,
+    }
+    input: {
+        console.log(function() {
+            for (arguments in [ 42 ]);
+            for (var a in arguments[0])
+                return "PASS";
+        }());
+    }
+    expect: {
+        console.log(function() {
+            for (arguments in [ 42 ]);
+            for (var a in arguments[0])
+                return "PASS";
+        }());
+    }
+    expect_stdout: "PASS"
+}