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);
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;