aboutsummaryrefslogtreecommitdiff
path: root/lib/compress.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/compress.js')
-rw-r--r--lib/compress.js37
1 files changed, 33 insertions, 4 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 4da13758..1bb6d542 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -4542,7 +4542,7 @@ merge(Compressor.prototype, {
var def = node.definition();
if (member(def.scope, scopes)) return true;
if (scope && !def.redefined()) {
- var scope_def = scope.find_variable(node);
+ var scope_def = scope.find_variable(node.name);
if (def.undeclared ? !scope_def : scope_def === def) {
result = "f";
return true;
@@ -4842,7 +4842,9 @@ merge(Compressor.prototype, {
if (!(ref instanceof AST_SymbolRef)) return;
var def = ref.definition();
var ldef = node.variables.get(ref.name);
- if (ldef && (ldef === def || def.undeclared || node.parent_scope.find_variable(ref) === def)) {
+ if (ldef && (ldef === def
+ || def.undeclared
+ || node.parent_scope.find_variable(ref.name) === def)) {
references[def.id] = false;
references[ldef.id] = false;
} else {
@@ -5468,7 +5470,7 @@ merge(Compressor.prototype, {
}) : def.value === def.name.fixed_value())
&& (!def.value.name || (old_def = def.value.name.definition()).assignments == 0
&& (old_def.name == def.name.name || all(old_def.references, function(ref) {
- return ref.scope.find_variable(def.name) === def.name.definition();
+ return ref.scope.find_variable(def.name.name) === def.name.definition();
})))
&& can_declare_defun()
&& can_rename(def.value, def.name.name)) {
@@ -5759,6 +5761,33 @@ merge(Compressor.prototype, {
if (init instanceof AST_SymbolRef) return init;
}
+ function find_variable(name) {
+ var level = 0;
+ var scope = self;
+ while (true) {
+ var in_arg = false;
+ do {
+ var parent = compressor.parent(level++);
+ if (parent instanceof AST_DestructuredKeyVal && parent.key === scope) {
+ var fn = compressor.parent(level + 1);
+ if (fn instanceof AST_Lambda) {
+ in_arg = fn.argnames.indexOf(compressor.parent(level)) >= 0;
+ level += 2;
+ scope = fn;
+ break;
+ }
+ }
+ if (!parent) return;
+ scope = parent;
+ } while (!(scope instanceof AST_BlockScope));
+ var def = scope.variables.get(name);
+ if (!def) continue;
+ if (!in_arg) return def;
+ var sym = def.orig[0];
+ if (sym instanceof AST_SymbolFunarg || sym instanceof AST_SymbolLambda) return def;
+ }
+ }
+
function scan_ref_scoped(node, descend, init) {
if (node instanceof AST_Assign && node.left instanceof AST_SymbolRef) {
var def = node.left.definition();
@@ -5807,7 +5836,7 @@ merge(Compressor.prototype, {
if (!sym) return;
var def = sym.definition();
if (def.scope !== self) {
- var d = self.find_variable(sym);
+ var d = find_variable(sym.name);
if ((d && d.redefined() || d) === def) return;
}
node.object.walk(tw);