aboutsummaryrefslogtreecommitdiff
path: root/lib/compress.js
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2020-04-18 23:28:01 +0100
committerGitHub <noreply@github.com>2020-04-19 06:28:01 +0800
commite38754e8021c46b08595a4c71f26d20b2d538409 (patch)
tree2a2a645a086d9dcd020f873505844829e4d046df /lib/compress.js
parenteb6f32bfc3c9af65f417e2e4440115cec21ac075 (diff)
downloadtracifyjs-e38754e8021c46b08595a4c71f26d20b2d538409.tar.gz
tracifyjs-e38754e8021c46b08595a4c71f26d20b2d538409.zip
fix corner case in `functions` & `unused` (#3803)
fixes #3802
Diffstat (limited to 'lib/compress.js')
-rw-r--r--lib/compress.js19
1 files changed, 9 insertions, 10 deletions
diff --git a/lib/compress.js b/lib/compress.js
index b0e25dde..6742aef3 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -4151,22 +4151,17 @@ merge(Compressor.prototype, {
def.value = def.value.drop_side_effect_free(compressor);
}
var var_defs = var_defs_by_id.get(sym.id);
- if (var_defs.length > 1) {
- if (!def.value) {
+ if (!def.value) {
+ 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++;
- return;
- }
- if (sym.orig.indexOf(def.name) > sym.eliminated) {
- remove(var_defs, def);
- duplicated++;
+ } else {
+ head.push(def);
}
- }
- if (!def.value) {
- head.push(def);
} else if (compressor.option("functions")
&& !compressor.option("ie8")
+ && var_defs.length == 1
&& def.value === def.name.fixed_value()
&& def.value instanceof AST_Function
&& !(def.value.name && def.value.name.definition().assignments)
@@ -4188,6 +4183,10 @@ merge(Compressor.prototype, {
}
body.push(defun);
} else {
+ if (var_defs.length > 1 && sym.orig.indexOf(def.name) > sym.eliminated) {
+ remove(var_defs, def);
+ duplicated++;
+ }
if (side_effects.length > 0) {
if (tail.length > 0) {
side_effects.push(def.value);