[Pkg-javascript-commits] [uglifyjs] 34/49: fix uses_arguments handling (broken since 6605d1578351)

Jonas Smedegaard dr at jones.dk
Fri Dec 9 11:43:28 UTC 2016


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository uglifyjs.

commit 266ddd96399afcdee56d9d58b287f912b8728342
Author: Jann Horn <jann at thejh.net>
Date:   Fri Oct 14 18:04:39 2016 +0200

    fix uses_arguments handling (broken since 6605d1578351)
    
    Using the symbol declaration tracking of UglifyJS doesn't make sense here
    anyway, `arguments` always comes from something in the current scope.
    
    fixes #1299
---
 lib/scope.js            | 6 +++---
 test/mocha/arguments.js | 8 ++++++++
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/lib/scope.js b/lib/scope.js
index fb58329..4943b56 100644
--- a/lib/scope.js
+++ b/lib/scope.js
@@ -204,6 +204,9 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
                 }
             }
             var sym = node.scope.find_variable(name);
+            if (node.scope instanceof AST_Lambda && name == "arguments") {
+                node.scope.uses_arguments = true;
+            }
             if (!sym) {
                 var g;
                 if (globals.has(name)) {
@@ -215,9 +218,6 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
                     globals.set(name, g);
                 }
                 sym = g;
-                if (func && name == "arguments") {
-                    func.uses_arguments = true;
-                }
             }
             node.thedef = sym;
             if (parent instanceof AST_Unary && (parent.operator === '++' || parent.operator === '--')
diff --git a/test/mocha/arguments.js b/test/mocha/arguments.js
index 089826f..73993a7 100644
--- a/test/mocha/arguments.js
+++ b/test/mocha/arguments.js
@@ -19,4 +19,12 @@ describe("arguments", function() {
             value // Select function as scope
         );
     });
+
+    it("Should recognize when a function uses arguments", function() {
+        var ast = UglifyJS.parse("function a(){function b(){function c(){}; return arguments[0];}}");
+        ast.figure_out_scope();
+        assert.strictEqual(ast.body[0].uses_arguments, false);
+        assert.strictEqual(ast.body[0].body[0].uses_arguments, true);
+        assert.strictEqual(ast.body[0].body[0].body[0].uses_arguments, false);
+    });
 });
\ No newline at end of file

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/uglifyjs.git



More information about the Pkg-javascript-commits mailing list