d.fixed = false;
} else if (d.fixed) {
var value = node.fixed_value();
- if (unused && value && d.references.length == 1) {
+ if (value && ref_once(d)) {
if (value instanceof AST_Lambda) {
d.single_use = d.scope === node.scope
&& !(d.orig[0] instanceof AST_SymbolFunarg)
} else {
d.fixed = node;
mark(d, true);
- if (unused && d.references.length == 1) {
+ if (ref_once(d)) {
d.single_use = d.scope === d.references[0].scope
|| node.is_constant_expression(d.references[0].scope);
}
function reset_def(def) {
def.direct_access = false;
def.escaped = false;
- if (def.scope.uses_eval) {
+ if (def.scope.uses_eval || def.scope.uses_with) {
def.fixed = false;
} else if (!compressor.exposed(def)) {
def.fixed = undefined;
def.single_use = undefined;
}
+ function ref_once(def) {
+ return unused && !def.scope.uses_eval && !def.scope.uses_with && def.references.length == 1;
+ }
+
function is_immutable(value) {
if (!value) return false;
return value.is_constant()
if (fixed instanceof AST_Defun) {
d.fixed = fixed = make_node(AST_Function, fixed, fixed);
}
- if (compressor.option("unused")
- && fixed
- && d.references.length == 1
- && d.single_use) {
+ if (fixed && d.single_use) {
var value = fixed.optimize(compressor);
return value === fixed ? fixed.clone(true) : value;
}