[Pkg-javascript-commits] [uglifyjs] 18/77: Add a "keep_fnames" option to the compressor to retain function expression names

Jonas Smedegaard dr at jones.dk
Tue May 19 00:02:28 UTC 2015


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

js pushed a commit to tag v2.4.18
in repository uglifyjs.

commit 0d48af3f36e99252a42b2f40d8fc6d361aa5a7b1
Author: Richard van Velzen <rvanvelzen1 at gmail.com>
Date:   Sun Jan 4 20:14:38 2015 +0100

    Add a "keep_fnames" option to the compressor to retain function expression names
    
    See #552. This is useful for stack traces.
---
 lib/compress.js              |  3 ++-
 test/compress/drop-unused.js | 14 ++++++++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/lib/compress.js b/lib/compress.js
index 2c95099..345d8ad 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -62,6 +62,7 @@ function Compressor(options, false_by_default) {
         unused        : !false_by_default,
         hoist_funs    : !false_by_default,
         keep_fargs    : false,
+        keep_fnames   : false,
         hoist_vars    : false,
         if_return     : !false_by_default,
         join_vars     : !false_by_default,
@@ -1666,7 +1667,7 @@ merge(Compressor.prototype, {
 
     OPT(AST_Function, function(self, compressor){
         self = AST_Lambda.prototype.optimize.call(self, compressor);
-        if (compressor.option("unused")) {
+        if (compressor.option("unused") && !compressor.option("keep_fnames")) {
             if (self.name && self.name.unreferenced()) {
                 self.name = null;
             }
diff --git a/test/compress/drop-unused.js b/test/compress/drop-unused.js
index 89bf008..de4b222 100644
--- a/test/compress/drop-unused.js
+++ b/test/compress/drop-unused.js
@@ -163,3 +163,17 @@ used_var_in_catch: {
         }
     }
 }
+
+keep_fnames: {
+    options = { unused: true, keep_fnames: true };
+    input: {
+        function foo() {
+            return function bar(baz) {};
+        }
+    }
+    expect: {
+        function foo() {
+            return function bar() {};
+        }
+    }
+}
\ 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