if (node instanceof AST_Defun) return funarg && lhs.name === node.name.name;
if (node instanceof AST_DWLoop) return true;
if (node instanceof AST_LoopControl) return true;
+ if (node instanceof AST_SymbolRef) {
+ if (node.is_declared(compressor) ? node.fixed_value() || all(node.definition().orig, function(sym) {
+ return !(sym instanceof AST_SymbolConst || sym instanceof AST_SymbolLet);
+ }) : parent instanceof AST_Assign && parent.operator == "=" && parent.left === node) return false;
+ if (!replace_all) return true;
+ scan_rhs = false;
+ return false;
+ }
if (node instanceof AST_Try) return true;
if (node instanceof AST_With) return true;
- if (replace_all) return false;
- return node instanceof AST_SymbolRef
- && !node.is_declared(compressor)
- && !(parent instanceof AST_Assign && parent.operator == "=" && parent.left === node);
+ return false;
}
function in_conditional(node, parent) {
extract_candidates(expr.condition);
extract_candidates(expr.consequent);
extract_candidates(expr.alternative);
+ } else if (expr instanceof AST_Definitions) {
+ expr.definitions.forEach(extract_candidates);
} else if (expr instanceof AST_Dot) {
extract_candidates(expr.expression);
} else if (expr instanceof AST_DWLoop) {
} else {
extract_candidates(expr.expression);
}
- } else if (expr instanceof AST_Var) {
- expr.definitions.forEach(extract_candidates);
} else if (expr instanceof AST_VarDef) {
- if (expr.value) {
- var def = expr.name.definition();
- if (def.references.length > def.replaced) {
- candidates.push(hit_stack.slice());
+ if (expr.name instanceof AST_SymbolVar) {
+ if (expr.value) {
+ var def = expr.name.definition();
+ if (def.references.length > def.replaced) {
+ candidates.push(hit_stack.slice());
+ }
+ } else {
+ declare_only[expr.name.name] = (declare_only[expr.name.name] || 0) + 1;
}
- extract_candidates(expr.value);
- } else {
- declare_only[expr.name.name] = (declare_only[expr.name.name] || 0) + 1;
}
+ if (expr.value) extract_candidates(expr.value);
}
hit_stack.pop();
}