Skip to content

Commit

Permalink
fix corner case in sequences (#3491)
Browse files Browse the repository at this point in the history
fixes #3490
  • Loading branch information
alexlamsl committed Oct 17, 2019
1 parent b571619 commit b1279a4
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/compress.js
Expand Up @@ -2030,14 +2030,14 @@ merge(Compressor.prototype, {
n--;
CHANGED = true;
var left = prev.body;
return make_sequence(left, [ left, right ]).transform(compressor);
return make_sequence(left, [ left, right ]);
}
var n = 0, prev;
for (var i = 0; i < statements.length; i++) {
var stat = statements[i];
if (prev) {
if (stat instanceof AST_Exit) {
stat.value = cons_seq(stat.value || make_node(AST_Undefined, stat).transform(compressor));
stat.value = cons_seq(stat.value || make_node(AST_Undefined, stat)).transform(compressor);
} else if (stat instanceof AST_For) {
if (!(stat.init instanceof AST_Definitions)) {
var abort = false;
Expand Down
63 changes: 63 additions & 0 deletions test/compress/sequences.js
Expand Up @@ -1006,3 +1006,66 @@ angularjs_chain: {
}
}
}

issue_3490_1: {
options = {
conditionals: true,
dead_code: true,
inline: true,
sequences: true,
side_effects: true,
toplevel: true,
}
input: {
var b = 42, c = "FAIL";
if ({
3: function() {
var a;
return (a && a.p) < this;
}(),
}) c = "PASS";
if (b) while ("" == typeof d);
console.log(c, b);
}
expect: {
var b = 42, c = "FAIL";
if (function() {
var a;
a && a.p;
}(), c = "PASS", b) while ("" == typeof d);
console.log(c, b);
}
expect_stdout: "PASS 42"
}

issue_3490_2: {
options = {
conditionals: true,
dead_code: true,
evaluate: true,
inline: true,
reduce_vars: true,
sequences: true,
side_effects: true,
toplevel: true,
}
input: {
var b = 42, c = "FAIL";
if ({
3: function() {
var a;
return (a && a.p) < this;
}(),
}) c = "PASS";
if (b) for (; "" == typeof d;);
console.log(c, b);
}
expect: {
var b = 42, c = "FAIL";
for (function() {
var a;
}(), c = "PASS", b; "" == typeof d;);
console.log(c, b);
}
expect_stdout: "PASS 42"
}

0 comments on commit b1279a4

Please sign in to comment.