Skip to content

Commit

Permalink
fix cascade on multi-branch evaluations (#2067)
Browse files Browse the repository at this point in the history
Partially reverts #2059 as this has better coverage and performance.

fixes #2062
  • Loading branch information
alexlamsl committed Jun 7, 2017
1 parent f2af093 commit 9db0695
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/compress.js
Expand Up @@ -3187,17 +3187,16 @@ merge(Compressor.prototype, {
if (exp.argnames.length > 0) {
fn.body.push(make_node(AST_Var, self, {
definitions: exp.argnames.map(function(sym, i) {
var arg = self.args[i];
return make_node(AST_VarDef, sym, {
name: sym,
value: arg ? arg.clone(true) : make_node(AST_Undefined, self)
value: self.args[i] || make_node(AST_Undefined, self)
});
})
}));
}
if (self.args.length > exp.argnames.length) {
fn.body.push(make_node(AST_SimpleStatement, self, {
body: make_sequence(self, self.args.slice(exp.argnames.length)).clone(true)
body: make_sequence(self, self.args.slice(exp.argnames.length))
}));
}
fn.body.push(make_node(AST_Return, self, {
Expand Down Expand Up @@ -3316,6 +3315,7 @@ merge(Compressor.prototype, {
continue;
}
var parent = null, field;
expressions[j] = cdr = cdr.clone();
while (true) {
if (cdr.equivalent_to(left)) {
var car = expressions[i];
Expand Down Expand Up @@ -3352,7 +3352,7 @@ merge(Compressor.prototype, {
break;
}
parent = cdr;
cdr = cdr[field];
cdr = cdr[field] = cdr[field].clone();
}
}
end = i;
Expand Down
20 changes: 20 additions & 0 deletions test/compress/sequences.js
Expand Up @@ -710,3 +710,23 @@ issue_27: {
})(jQuery);
}
}

issue_2062: {
options = {
booleans: true,
cascade: true,
conditionals: true,
side_effects: true,
}
input: {
var a = 1;
if ([ a || a++ + a--, a++ + a--, a && a.var ]);
console.log(a);
}
expect: {
var a = 1;
a || (a++, a--), a++, --a && a.var;
console.log(a);
}
expect_stdout: "1"
}

0 comments on commit 9db0695

Please sign in to comment.