fix corner case in keep_fnames
authoralexlamsl <alexlamsl@gmail.com>
Sat, 18 Feb 2017 11:00:54 +0000 (19:00 +0800)
committeralexlamsl <alexlamsl@gmail.com>
Sat, 18 Feb 2017 11:00:54 +0000 (19:00 +0800)
happens when inner function:
- just below top level
- not referenced
- `unused` is disabled

closes #1445

lib/scope.js
test/compress/issue-1431.js

index 0fe8d83..d5cadd3 100644 (file)
@@ -268,12 +268,12 @@ AST_SymbolRef.DEFMETHOD("reference", function(options) {
     var s = this.scope;
     while (s) {
         push_uniq(s.enclosed, def);
-        if (s === def.scope) break;
         if (options.keep_fnames) {
-            s.variables.each(function(d) {
+            s.functions.each(function(d) {
                 push_uniq(def.scope.enclosed, d);
             });
         }
+        if (s === def.scope) break;
         s = s.parent_scope;
     }
 });
index 731ebba..9493fd3 100644 (file)
@@ -1,3 +1,32 @@
+level_zero: {
+    options = {
+        keep_fnames: true
+    }
+    mangle = {
+        keep_fnames: true
+    }
+    input: {
+        function f(x) {
+            function n(a) {
+                return a * a;
+            }
+            return function() {
+                return x;
+            };
+        }
+    }
+    expect: {
+        function f(r) {
+            function n(n) {
+                return n * n;
+            }
+            return function() {
+                return r;
+            };
+        }
+    }
+}
+
 level_one: {
     options = {
         keep_fnames: true