aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2020-04-18 17:10:24 +0100
committerGitHub <noreply@github.com>2020-04-19 00:10:24 +0800
commitf110601fb4bfa8f7b362bcc4a7a8a2f850e5132e (patch)
treeaeb3ed932b9554f1270dd7a681e6a417548fee84
parent2a508c6e5f1e69e78d84480b5fc3db2f8087c166 (diff)
downloadtracifyjs-f110601fb4bfa8f7b362bcc4a7a8a2f850e5132e.tar.gz
tracifyjs-f110601fb4bfa8f7b362bcc4a7a8a2f850e5132e.zip
enhance `unused` (#3800)
-rw-r--r--lib/compress.js11
-rw-r--r--test/compress/drop-unused.js25
2 files changed, 33 insertions, 3 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 9504241b..b7a91ea5 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -4200,8 +4200,15 @@ merge(Compressor.prototype, {
} else if (sym.orig[0] instanceof AST_SymbolCatch) {
var value = def.value && def.value.drop_side_effect_free(compressor);
if (value) side_effects.push(value);
- def.value = null;
- head.push(def);
+ var var_defs = var_defs_by_id.get(sym.id);
+ if (var_defs.length > 1) {
+ AST_Node.warn("Dropping duplicated declaration of variable {name} [{file}:{line},{col}]", template(def.name));
+ remove(var_defs, def);
+ sym.eliminated++;
+ } else {
+ def.value = null;
+ head.push(def);
+ }
} else {
var value = def.value && !def.value.single_use && def.value.drop_side_effect_free(compressor);
if (value) {
diff --git a/test/compress/drop-unused.js b/test/compress/drop-unused.js
index 38f132bf..3a61f24e 100644
--- a/test/compress/drop-unused.js
+++ b/test/compress/drop-unused.js
@@ -1173,7 +1173,6 @@ var_catch_toplevel: {
x();
} catch (a) {
var a;
- var a;
}
}();
}
@@ -2465,3 +2464,27 @@ drop_duplicated_side_effects: {
}
expect_stdout: "1"
}
+
+drop_duplicated_var_catch: {
+ options = {
+ unused: true,
+ }
+ input: {
+ function f() {
+ try {
+ x();
+ } catch (a) {
+ var a, a;
+ }
+ }
+ }
+ expect: {
+ function f() {
+ try {
+ x();
+ } catch (a) {
+ var a;
+ }
+ }
+ }
+}