diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2021-03-27 14:14:37 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-27 22:14:37 +0800 |
commit | d5599604e80ab8771af422ca2f43302949b2eb15 (patch) | |
tree | 52ea714f2155c9b0d95eac81ee183d8933839409 | |
parent | 072933f1d597a756618d6891d4e12013f49aa789 (diff) | |
download | tracifyjs-d5599604e80ab8771af422ca2f43302949b2eb15.tar.gz tracifyjs-d5599604e80ab8771af422ca2f43302949b2eb15.zip |
enhance `collapse_vars` (#4826)
-rw-r--r-- | lib/compress.js | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/lib/compress.js b/lib/compress.js index f3e40f7e..6286741f 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -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) { @@ -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); |