aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2021-03-17 01:28:27 +0000
committerGitHub <noreply@github.com>2021-03-17 09:28:27 +0800
commit997d09bb33f95cf414235b8fc3d3b0539d33d2a2 (patch)
treea851c195749d27ee14d5a536100dd58f048769a6
parentb244b4ec21fdb65870068879f02e5471ab371d1d (diff)
downloadtracifyjs-997d09bb33f95cf414235b8fc3d3b0539d33d2a2.tar.gz
tracifyjs-997d09bb33f95cf414235b8fc3d3b0539d33d2a2.zip
extend `keep_fnames` to classes (#4793)
-rw-r--r--lib/scope.js6
-rw-r--r--test/compress/classes.js21
-rw-r--r--test/compress/issue-1202.js4
3 files changed, 27 insertions, 4 deletions
diff --git a/lib/scope.js b/lib/scope.js
index 6345bfd3..9d4b8900 100644
--- a/lib/scope.js
+++ b/lib/scope.js
@@ -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);
},
};
diff --git a/test/compress/classes.js b/test/compress/classes.js
index cebccf95..46749a27 100644
--- a/test/compress/classes.js
+++ b/test/compress/classes.js
@@ -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,
diff --git a/test/compress/issue-1202.js b/test/compress/issue-1202.js
index 1a34a3f1..1ad6be7b 100644
--- a/test/compress/issue-1202.js
+++ b/test/compress/issue-1202.js
@@ -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";