Skip to content

Commit

Permalink
enhance collapse_vars (#4826)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlamsl committed Mar 27, 2021
1 parent 072933f commit d559960
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions lib/compress.js
Expand Up @@ -1826,6 +1826,18 @@ merge(Compressor.prototype, {
can_replace = replace;
return signal_abort(node);
}
// Scan but don't replace inside block scope with colliding variable
if (node instanceof AST_BlockScope
&& !(node instanceof AST_Scope)
&& !(node.variables && node.variables.all(function(def) {
return !lvalues.has(def.name);
}))) {
var replace = can_replace;
can_replace = false;
if (!handle_custom_scan_order(node, scanner)) descend(node, scanner);
can_replace = replace;
return signal_abort(node);
}
return handle_custom_scan_order(node, scanner);
}, signal_abort);
var multi_replacer = new TreeTransformer(function(node) {
Expand Down Expand Up @@ -1964,13 +1976,6 @@ merge(Compressor.prototype, {
}
// Skip (non-executed) functions
if (node instanceof AST_Scope) return node;
// Stop upon collision with block-scoped variables
if (!(node.variables && node.variables.all(function(def) {
return !lvalues.has(def.name);
}))) {
abort = true;
return node;
}
// Scan object only in a for-in/of statement
if (node instanceof AST_ForEnumeration) {
node.object = node.object.transform(tt);
Expand Down

0 comments on commit d559960

Please sign in to comment.