Add option `keep_fargs`.
authorMihai Bazon <mihai@bazon.net>
Sat, 8 Feb 2014 10:33:56 +0000 (12:33 +0200)
committerMihai Bazon <mihai@bazon.net>
Sat, 8 Feb 2014 10:33:56 +0000 (12:33 +0200)
By default it's `false`.  Pass `true` if you need to keep unused function
arguments.

Close #188.

lib/compress.js

index 005c606..b589aca 100644 (file)
@@ -61,6 +61,7 @@ function Compressor(options, false_by_default) {
         loops         : !false_by_default,
         unused        : !false_by_default,
         hoist_funs    : !false_by_default,
+        keep_fargs    : false,
         hoist_vars    : false,
         if_return     : !false_by_default,
         join_vars     : !false_by_default,
@@ -1044,18 +1045,20 @@ merge(Compressor.prototype, {
             var tt = new TreeTransformer(
                 function before(node, descend, in_list) {
                     if (node instanceof AST_Lambda && !(node instanceof AST_Accessor)) {
-                        for (var a = node.argnames, i = a.length; --i >= 0;) {
-                            var sym = a[i];
-                            if (sym.unreferenced()) {
-                                a.pop();
-                                compressor.warn("Dropping unused function argument {name} [{file}:{line},{col}]", {
-                                    name : sym.name,
-                                    file : sym.start.file,
-                                    line : sym.start.line,
-                                    col  : sym.start.col
-                                });
+                        if (!compressor.option("keep_fargs")) {
+                            for (var a = node.argnames, i = a.length; --i >= 0;) {
+                                var sym = a[i];
+                                if (sym.unreferenced()) {
+                                    a.pop();
+                                    compressor.warn("Dropping unused function argument {name} [{file}:{line},{col}]", {
+                                        name : sym.name,
+                                        file : sym.start.file,
+                                        line : sym.start.line,
+                                        col  : sym.start.col
+                                    });
+                                }
+                                else break;
                             }
-                            else break;
                         }
                     }
                     if (node instanceof AST_Defun && node !== self) {