aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2020-12-12 21:01:38 +0000
committerGitHub <noreply@github.com>2020-12-13 05:01:38 +0800
commit5d19bb8d5d087c6e7a383974024c67e11b6334a1 (patch)
tree5473a42ebce4d9a31357fe26ac347480aaf34a2b
parentaf9762991222f5a4577aef1631d039b129e683d9 (diff)
downloadtracifyjs-5d19bb8d5d087c6e7a383974024c67e11b6334a1.tar.gz
tracifyjs-5d19bb8d5d087c6e7a383974024c67e11b6334a1.zip
fix corner case in `booleans` (#4375)
fixes #4374
-rw-r--r--lib/ast.js15
-rw-r--r--test/compress/booleans.js28
2 files changed, 35 insertions, 8 deletions
diff --git a/lib/ast.js b/lib/ast.js
index 262372ee..31281c1e 100644
--- a/lib/ast.js
+++ b/lib/ast.js
@@ -1451,14 +1451,13 @@ TreeWalker.prototype = {
|| p.tail_node() === self) {
self = p;
} else if (p instanceof AST_Return) {
- var fn;
- do {
- fn = this.parent(++i);
- if (!fn) return false;
- } while (!(fn instanceof AST_Lambda));
- if (fn.name) return false;
- self = this.parent(++i);
- if (!self || self.TYPE != "Call" || self.expression !== fn) return false;
+ for (var call, fn = p; call = this.parent(++i); fn = call) {
+ if (call.TYPE == "Call") {
+ if (!(fn instanceof AST_Lambda) || fn.name) return false;
+ } else if (fn instanceof AST_Lambda) {
+ return false;
+ }
+ }
} else {
return false;
}
diff --git a/test/compress/booleans.js b/test/compress/booleans.js
index 6e7988bf..779f8d8c 100644
--- a/test/compress/booleans.js
+++ b/test/compress/booleans.js
@@ -153,3 +153,31 @@ issue_3690: {
}
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"
+}