From ef2ef07cbd945c7a6456adedc413858145a9ed10 Mon Sep 17 00:00:00 2001 From: Mihai Bazon Date: Sat, 8 Feb 2014 12:33:56 +0200 Subject: [PATCH] Add option `keep_fargs`. By default it's `false`. Pass `true` if you need to keep unused function arguments. Close #188. --- lib/compress.js | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/lib/compress.js b/lib/compress.js index 005c606d..b589aca5 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -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) { -- 2.34.1