[Pkg-javascript-commits] [uglifyjs] 85/190: Never mangle arguments and keep them in their scope

Antonio Terceiro terceiro at moszumanska.debian.org
Sun Aug 7 23:17:15 UTC 2016


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

terceiro pushed a commit to annotated tag upstream/2.7.0
in repository uglifyjs.

commit 6605d1578351939ee0e39a13bf68cc9c1708c918
Author: Anthony Van de Gejuchte <anthonyvdgent at gmail.com>
Date:   Sun Jan 10 23:33:54 2016 +0100

    Never mangle arguments and keep them in their scope
    
    Fixes #892
    
    Helped-by: kzc
---
 lib/scope.js               |  8 ++++++++
 test/compress/issue-892.js | 32 ++++++++++++++++++++++++++++++++
 test/run-tests.js          |  4 ++++
 3 files changed, 44 insertions(+)

diff --git a/lib/scope.js b/lib/scope.js
index 1f0986c..5e93020 100644
--- a/lib/scope.js
+++ b/lib/scope.js
@@ -237,6 +237,10 @@ AST_Scope.DEFMETHOD("init_scope_vars", function(nesting){
 AST_Lambda.DEFMETHOD("init_scope_vars", function(){
     AST_Scope.prototype.init_scope_vars.apply(this, arguments);
     this.uses_arguments = false;
+
+    var symbol = new AST_VarDef({ name: "arguments" });
+    var def = new SymbolDef(this, this.variables.size(), symbol);
+    this.variables.set(symbol.name, def);
 });
 
 AST_SymbolRef.DEFMETHOD("reference", function() {
@@ -366,6 +370,10 @@ AST_Toplevel.DEFMETHOD("_default_mangler_options", function(options){
 
 AST_Toplevel.DEFMETHOD("mangle_names", function(options){
     options = this._default_mangler_options(options);
+
+    // Never mangle arguments
+    options.except.push('arguments');
+
     // We only need to mangle declaration nodes.  Special logic wired
     // into the code generator will display the mangled name if it's
     // present (and for AST_SymbolRef-s it'll use the mangled name of
diff --git a/test/compress/issue-892.js b/test/compress/issue-892.js
new file mode 100644
index 0000000..2dab420
--- /dev/null
+++ b/test/compress/issue-892.js
@@ -0,0 +1,32 @@
+dont_mangle_arguments: {
+    mangle = {
+    };
+    options = {
+        sequences     : true,
+        properties    : true,
+        dead_code     : true,
+        drop_debugger : true,
+        conditionals  : true,
+        comparisons   : true,
+        evaluate      : true,
+        booleans      : true,
+        loops         : true,
+        unused        : true,
+        hoist_funs    : true,
+        keep_fargs    : true,
+        keep_fnames   : false,
+        hoist_vars    : true,
+        if_return     : true,
+        join_vars     : true,
+        cascade       : true,
+        side_effects  : true,
+        negate_iife   : false
+    };
+    input: {
+        (function(){
+            var arguments = arguments, not_arguments = 9;
+            console.log(not_arguments, arguments);
+        })(5,6,7);
+    }
+    expect_exact: "(function(){var arguments=arguments,o=9;console.log(o,arguments)})(5,6,7);"
+}
diff --git a/test/run-tests.js b/test/run-tests.js
index b9a0f82..fcb1b37 100755
--- a/test/run-tests.js
+++ b/test/run-tests.js
@@ -103,6 +103,10 @@ function run_compress_tests() {
             }
             var output = input.transform(cmp);
             output.figure_out_scope();
+            if (test.mangle) {
+                output.compute_char_frequency(test.mangle);
+                output.mangle_names(test.mangle);
+            }
             output = make_code(output, output_options);
             if (expect != output) {
                 log("!!! failed\n---INPUT---\n{input}\n---OUTPUT---\n{output}\n---EXPECTED---\n{expected}\n\n", {

-- 
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