diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2020-10-13 00:32:17 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-13 07:32:17 +0800 |
commit | 176c09c6a5408ef0a8ddca8da7eb930c9d5e2745 (patch) | |
tree | 46f7b9e1821b3a0ab5a15106075fb574ae5c36f2 /lib | |
parent | 9272f662c0c89387a2bc9e7a47024ccc9d0c09a4 (diff) | |
download | tracifyjs-176c09c6a5408ef0a8ddca8da7eb930c9d5e2745.tar.gz tracifyjs-176c09c6a5408ef0a8ddca8da7eb930c9d5e2745.zip |
fix corner case in `reduce_vars` & `unused` (#4208)
fixes #4207
Diffstat (limited to 'lib')
-rw-r--r-- | lib/compress.js | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/lib/compress.js b/lib/compress.js index bc01ebc3..c59e26ed 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -165,10 +165,12 @@ Compressor.prototype = new TreeTransformer; merge(Compressor.prototype, { option: function(key) { return this.options[key] }, exposed: function(def) { - if (def.global) for (var i = 0; i < def.orig.length; i++) - if (!this.toplevel[def.orig[i] instanceof AST_SymbolDefun ? "funcs" : "vars"]) - return true; - return def.undeclared; + if (def.undeclared) return true; + if (!(def.global || def.scope.resolve() instanceof AST_Toplevel)) return false; + var toplevel = this.toplevel; + return !all(def.orig, function(sym) { + return toplevel[sym instanceof AST_SymbolDefun ? "funcs" : "vars"]; + }); }, compress: function(node) { node = node.resolve_defines(this); @@ -6642,13 +6644,10 @@ merge(Compressor.prototype, { var node = defn.name; if (!node.fixed_value()) return false; var def = node.definition(); + if (compressor.exposed(def)) return false; var scope = def.scope.resolve(); - if (scope instanceof AST_Toplevel) { - if (!compressor.toplevel.vars) return false; - if (def.scope === scope) return true; - return !scope.variables.has(node.name) && !scope.globals.has(node.name); - } if (def.scope === scope) return true; + if (scope instanceof AST_Toplevel) return !scope.variables.has(node.name) && !scope.globals.has(node.name); var s = def.scope; do { s = s.parent_scope; |