if (this.option("expression")) {
node.process_expression(true);
}
+ var merge_vars = this.options.merge_vars;
var passes = +this.options.passes || 1;
var min_count = 1 / 0;
var stopping = false;
node.figure_out_scope(mangle);
if (pass > 0 || this.option("reduce_vars"))
node.reset_opt_flags(this);
+ this.options.merge_vars = merge_vars && (stopping || pass == passes - 1);
node = node.transform(this);
if (passes > 1) {
var count = 0;
descend(node, this);
var opt = node.optimize(this);
if (is_scope && opt === node && !this.has_directive("use asm") && !opt.pinned()) {
- opt.merge_variables(this);
opt.drop_unused(this);
+ if (opt.merge_variables(this)) opt.drop_unused(this);
descend(opt, this);
}
if (opt === node) opt._squeezed = true;
});
tw.directives = Object.create(compressor.directives);
self.walk(tw);
+ var changed = false;
var merged = Object.create(null);
while (first.length && last.length) {
var head = first.pop();
def.references = refs.concat(def.references);
def.fixed = tail.definition.fixed && def.fixed;
merged[id] = def;
+ changed = true;
break;
} while (last.length);
if (skipped.length) last = last.concat(skipped);
}
+ return changed;
function push() {
segment = Object.create(segment);
hoist_props: true,
inline: true,
merge_vars: true,
- passes: 3,
+ passes: 4,
reduce_vars: true,
sequences: true,
side_effects: true,
console.log(obj.foo(1, 2), global.log("PASS"));
}
expect: {
- var obj = console;
- global.log = obj.log,
+ var con = console;
+ global.log = con.log,
console.log((console.log("BAR:", 3), -1), global.log("PASS"));
}
expect_stdout: [
try {
throw 42;
} catch (e) {
- var a = e;
- for (e in a);
- a = function() {};
+ var o = e;
+ for (e in o);
+ function a() {}
console.log(typeof a);
return a;
}
}
expect_stdout: "42"
}
+
+issue_5182: {
+ options = {
+ arrows: true,
+ collapse_vars: true,
+ evaluate: true,
+ hoist_props: true,
+ inline: true,
+ merge_vars: true,
+ passes: 4,
+ reduce_vars: true,
+ sequences: true,
+ side_effects: true,
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ try {
+ var con = console;
+ } catch (x) {}
+ global.log = con.log;
+ var jump = function(x) {
+ console.log("JUMP:", x * 10);
+ return x + x;
+ };
+ var jump2 = jump;
+ var run = function(x) {
+ console.log("RUN:", x * -10);
+ return x * x;
+ };
+ var run2 = run;
+ var bar = (x, y) => {
+ console.log("BAR:", x + y);
+ return x - y;
+ };
+ var bar2 = bar;
+ var obj = {
+ foo: bar2,
+ go: run2,
+ not_used: jump2,
+ };
+ console.log(obj.foo(1, 2), global.log("PASS"));
+ }
+ expect: {
+ try {
+ var con = console;
+ } catch (x) {}
+ global.log = con.log,
+ console.log((console.log("BAR:", 3), -1), global.log("PASS"));
+ }
+ expect_stdout: [
+ "BAR: 3",
+ "PASS",
+ "-1 undefined",
+ ]
+ node_version: ">=4"
+}