fix corner case in conditionals (#3669)

fixes #3668
This commit is contained in:
Alex Lam S.L
2020-01-04 09:24:28 +08:00
committed by GitHub
parent fdc10086da
commit 1988495d71
2 changed files with 33 additions and 2 deletions

View File

@@ -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) {

View File

@@ -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"
}