aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2017-10-23 01:00:50 +0800
committerGitHub <noreply@github.com>2017-10-23 01:00:50 +0800
commit8a713e449f551d89745d9a8105b7cb33e9893214 (patch)
treebdf1d2585399f6d875c669c95ea85ed872de11be /lib
parent24aa07855bc608f29cca2a58a40af1988256b116 (diff)
downloadtracifyjs-8a713e449f551d89745d9a8105b7cb33e9893214.tar.gz
tracifyjs-8a713e449f551d89745d9a8105b7cb33e9893214.zip
deduplicate declarations regardless of `toplevel` (#2393)
Diffstat (limited to 'lib')
-rw-r--r--lib/compress.js8
1 files changed, 4 insertions, 4 deletions
diff --git a/lib/compress.js b/lib/compress.js
index eb0e2016..7085fcb3 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -2240,7 +2240,6 @@ merge(Compressor.prototype, {
if (self.uses_eval || self.uses_with) return;
var drop_funcs = !(self instanceof AST_Toplevel) || compressor.toplevel.funcs;
var drop_vars = !(self instanceof AST_Toplevel) || compressor.toplevel.vars;
- if (!drop_funcs && !drop_vars) return;
var assign_as_unused = /keep_assign/.test(compressor.option("unused")) ? return_false : function(node) {
if (node instanceof AST_Assign && (node.write_only || node.operator == "=")) {
return node.left;
@@ -2375,7 +2374,8 @@ merge(Compressor.prototype, {
}
return node;
}
- if (drop_vars && node instanceof AST_Definitions && !(tt.parent() instanceof AST_ForIn && tt.parent().init === node)) {
+ var parent = tt.parent();
+ if (node instanceof AST_Definitions && !(parent instanceof AST_ForIn && parent.init === node)) {
// place uninitialized names at the start
var body = [], head = [], tail = [];
// for unused names whose initialization has
@@ -2385,7 +2385,7 @@ merge(Compressor.prototype, {
node.definitions.forEach(function(def) {
if (def.value) def.value = def.value.transform(tt);
var sym = def.name.definition();
- if (sym.id in in_use_ids) {
+ if (!drop_vars || sym.id in in_use_ids) {
if (def.name instanceof AST_SymbolVar) {
var var_defs = var_defs_by_id.get(sym.id);
if (var_defs.length > 1 && !def.value) {
@@ -2467,7 +2467,7 @@ merge(Compressor.prototype, {
&& !((def = def.definition()).id in in_use_ids)
&& self.variables.get(def.name) === def) {
if (node instanceof AST_Assign) {
- return maintain_this_binding(tt.parent(), node, node.right.transform(tt));
+ return maintain_this_binding(parent, node, node.right.transform(tt));
}
return make_node(AST_Number, node, {
value: 0