From 0a42457df64944187a069b26491fcebd8ce55ce0 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Sat, 27 Feb 2021 01:26:15 +0000 Subject: [PATCH] fix corner case with `arguments` (#4697) fixes #4696 --- lib/ast.js | 2 +- lib/scope.js | 1 + test/compress/arguments.js | 22 ++++++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/ast.js b/lib/ast.js index 5fe6efc1..1aee1044 100644 --- a/lib/ast.js +++ b/lib/ast.js @@ -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" diff --git a/lib/scope.js b/lib/scope.js index 600a6869..b22f77a2 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -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; } diff --git a/test/compress/arguments.js b/test/compress/arguments.js index 655d75a4..4c602a68 100644 --- a/test/compress/arguments.js +++ b/test/compress/arguments.js @@ -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" +} -- 2.34.1