fix corner case in booleans (#4375)

fixes #4374
This commit is contained in:
Alex Lam S.L
2020-12-12 21:01:38 +00:00
committed by GitHub
parent af97629912
commit 5d19bb8d5d
2 changed files with 35 additions and 8 deletions

View File

@@ -1451,14 +1451,13 @@ TreeWalker.prototype = {
|| p.tail_node() === self) { || p.tail_node() === self) {
self = p; self = p;
} else if (p instanceof AST_Return) { } else if (p instanceof AST_Return) {
var fn; for (var call, fn = p; call = this.parent(++i); fn = call) {
do { if (call.TYPE == "Call") {
fn = this.parent(++i); if (!(fn instanceof AST_Lambda) || fn.name) return false;
if (!fn) return false; } else if (fn instanceof AST_Lambda) {
} while (!(fn instanceof AST_Lambda)); return false;
if (fn.name) return false; }
self = this.parent(++i); }
if (!self || self.TYPE != "Call" || self.expression !== fn) return false;
} else { } else {
return false; return false;
} }

View File

@@ -153,3 +153,31 @@ issue_3690: {
} }
expect_stdout: "PASS" expect_stdout: "PASS"
} }
issue_4374: {
options = {
booleans: true,
conditionals: true,
if_return: true,
reduce_vars: true,
unused: true,
}
input: {
(function() {
console.log(f());
function f(a) {
if (null) return 0;
if (a) return 1;
return 0;
}
})();
}
expect: {
(function() {
console.log(function(a) {
return !null && a ? 1 : 0;
}());
})();
}
expect_stdout: "0"
}