extend `keep_fnames` to classes (#4793)
authorAlex Lam S.L <alexlamsl@gmail.com>
Wed, 17 Mar 2021 01:28:27 +0000 (01:28 +0000)
committerGitHub <noreply@github.com>
Wed, 17 Mar 2021 01:28:27 +0000 (09:28 +0800)
lib/scope.js
test/compress/classes.js
test/compress/issue-1202.js

index 6345bfd..9d4b890 100644 (file)
@@ -96,8 +96,10 @@ SymbolDef.prototype = {
             || this.undeclared
             || !options.eval && this.scope.pinned()
             || options.keep_fnames
-                && (this.orig[0] instanceof AST_SymbolLambda
-                    || this.orig[0] instanceof AST_SymbolDefun);
+                && (this.orig[0] instanceof AST_SymbolClass
+                    || this.orig[0] instanceof AST_SymbolDefClass
+                    || this.orig[0] instanceof AST_SymbolDefun
+                    || this.orig[0] instanceof AST_SymbolLambda);
     },
 };
 
index cebccf9..46749a2 100644 (file)
@@ -779,6 +779,27 @@ computed_key_generator: {
     node_version: ">=4"
 }
 
+keep_fnames: {
+    options = {
+        keep_fnames: true,
+        toplevel: true,
+    }
+    mangle = {
+        keep_fnames: true,
+        toplevel: true,
+    }
+    input: {
+        "use strict";
+        class Foo {}
+        console.log(Foo.name, class Bar {}.name);
+    }
+    expect: {
+        "use strict";
+        class Foo {}
+        console.log(Foo.name, class Bar {}.name);
+    }
+}
+
 issue_805_1: {
     options = {
         inline: true,
index 1a34a3f..1ad6be7 100644 (file)
@@ -4,7 +4,7 @@ mangle_keep_fnames_false: {
         keep_fnames: true,
     }
     mangle = {
-        keep_fnames : false,
+        keep_fnames: false,
     }
     input: {
         "use strict";
@@ -30,7 +30,7 @@ mangle_keep_fnames_true: {
         keep_fnames: true,
     }
     mangle = {
-        keep_fnames : true,
+        keep_fnames: true,
     }
     input: {
         "use strict";