Skip to content

Commit

Permalink
fix corner case in conditionals (#3669)
Browse files Browse the repository at this point in the history
fixes #3668
  • Loading branch information
alexlamsl committed Jan 4, 2020
1 parent fdc1008 commit 1988495
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/compress.js
Expand Up @@ -5114,8 +5114,8 @@ merge(Compressor.prototype, {
var exit = make_node(self.body.CTOR, self, {
value: make_node(AST_Conditional, self, {
condition : self.condition,
consequent : self.body.value || make_node(AST_Undefined, self.body),
alternative : self.alternative.value || make_node(AST_Undefined, self.alternative)
consequent : self.body.value || make_node(AST_Undefined, self.body).transform(compressor),
alternative : self.alternative.value || make_node(AST_Undefined, self.alternative).transform(compressor)
})
});
if (exit instanceof AST_Return) {
Expand Down
31 changes: 31 additions & 0 deletions test/compress/conditionals.js
Expand Up @@ -1578,3 +1578,34 @@ issue_3576: {
}
expect_stdout: "PASS"
}

issue_3668: {
options = {
conditionals: true,
if_return: true,
}
input: {
function f() {
try {
var undefined = typeof f;
if (!f) return undefined;
return;
} catch (e) {
return "FAIL";
}
}
console.log(f());
}
expect: {
function f() {
try {
var undefined = typeof f;
return f ? void 0 : undefined;
} catch (e) {
return "FAIL";
}
}
console.log(f());
}
expect_stdout: "undefined"
}

0 comments on commit 1988495

Please sign in to comment.