statements.length = n;
}
- function join_assigns(defn, body) {
+ function join_assigns(defn, body, keep) {
var exprs;
if (body instanceof AST_Assign) {
exprs = [ body ];
if (defn instanceof AST_Definitions) {
var def = defn.definitions[defn.definitions.length - 1];
if (trim_assigns(def.name, def.value, exprs)) trimmed = true;
- if (join_var_assign(defn.definitions, exprs)) trimmed = true;
+ if (join_var_assign(defn.definitions, exprs, keep || 0)) trimmed = true;
}
return trimmed && exprs;
}
- function join_var_assign(definitions, exprs) {
+ function join_var_assign(definitions, exprs, keep) {
var trimmed = false;
- while (exprs.length) {
+ while (exprs.length > keep) {
var expr = exprs[0];
if (!(expr instanceof AST_Assign)) break;
if (expr.operator != "=") break;
if (!(lhs instanceof AST_SymbolRef)) break;
if (is_undeclared_ref(lhs)) break;
var def = lhs.definition();
- if (def.scope !== definitions[0].name.scope) break;
+ if (def.scope !== lhs.scope) break;
+ if (def.orig.length > def.eliminated + 1) break;
+ if (def.orig[0].TYPE != "SymbolVar") break;
var name = make_node(AST_SymbolVar, lhs, lhs);
definitions.push(make_node(AST_VarDef, expr, {
name: name,
function join_assigns_expr(value) {
statements[++j] = stat;
- var exprs = join_assigns(prev, value);
+ var exprs = join_assigns(prev, value, 1);
if (!exprs) return value;
CHANGED = true;
var tail = value.tail_node();
function can_inject_symbols() {
var catches = Object.create(null);
+ var child;
+ scope = compressor.self();
do {
+ child = scope;
scope = compressor.parent(++level);
if (scope instanceof AST_Catch) {
catches[scope.argname.name] = true;
- } else if (scope instanceof AST_IterationStatement) {
+ } else if (scope instanceof AST_DWLoop) {
+ in_loop = [];
+ } else if (scope instanceof AST_For) {
+ if (scope.init === child) continue;
+ in_loop = [];
+ } else if (scope instanceof AST_ForIn) {
+ if (scope.init === child) continue;
+ if (scope.object === child) continue;
in_loop = [];
} else if (scope instanceof AST_SymbolRef) {
if (scope.fixed_value() instanceof AST_Scope) return false;
uglify_code = uglify_code.code;
uglify_result = sandbox.run_code(uglify_code, toplevel);
ok = sandbox.same_stdout(original_result, uglify_result);
- if (!ok && typeof uglify_result == "string" && o.compress.unsafe_math) {
+ if (!ok && typeof uglify_result == "string" && o.compress && o.compress.unsafe_math) {
ok = fuzzy_match(original_result, uglify_result);
if (!ok) {
var fuzzy_result = sandbox.run_code(original_code.replace(/( - 0\.1){3}/g, " - 0.3"), toplevel);