aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2021-07-08 09:31:04 +0100
committerGitHub <noreply@github.com>2021-07-08 16:31:04 +0800
commitea7829daf55f8829cc48466379cc6f6cf3394dbd (patch)
treee9a897a9b81cdd8f94c2b08f602043d1e6dca444
parent6577d641ac82419d462f11fee73a7b067e793003 (diff)
downloadtracifyjs-ea7829daf55f8829cc48466379cc6f6cf3394dbd.tar.gz
tracifyjs-ea7829daf55f8829cc48466379cc6f6cf3394dbd.zip
fix corner case in `reduce_vars` (#5062)
fixes #5061
-rw-r--r--lib/compress.js1
-rw-r--r--test/compress/functions.js52
2 files changed, 53 insertions, 0 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 90261d0a..dbfc2e75 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -889,6 +889,7 @@ merge(Compressor.prototype, {
} else {
right.parent_scope.resolve().fn_defs.push(right);
right.safe_ids = null;
+ if (!node.write_only) mark_fn_def(tw, ld, right);
}
return true;
} else if (scan) {
diff --git a/test/compress/functions.js b/test/compress/functions.js
index 6d41a265..7c6ebe03 100644
--- a/test/compress/functions.js
+++ b/test/compress/functions.js
@@ -6346,3 +6346,55 @@ issue_5046: {
}
expect_stdout: "PASS"
}
+
+issue_5061_1: {
+ options = {
+ evaluate: true,
+ reduce_vars: true,
+ toplevel: true,
+ }
+ input: {
+ var f, a = 1;
+ (f = function() {
+ console.log(a ? "foo" : "bar");
+ })();
+ f(a = 0);
+ }
+ expect: {
+ var f, a = 1;
+ (f = function() {
+ console.log(a ? "foo" : "bar");
+ })();
+ f(a = 0);
+ }
+ expect_stdout: [
+ "foo",
+ "bar",
+ ]
+}
+
+issue_5061_2: {
+ options = {
+ reduce_vars: true,
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ var f, a = 1;
+ (f = function() {
+ console.log(a ? "foo" : "bar");
+ })();
+ f(a = 0);
+ }
+ expect: {
+ var f, a = 1;
+ (f = function() {
+ console.log(a ? "foo" : "bar");
+ })();
+ f(a = 0);
+ }
+ expect_stdout: [
+ "foo",
+ "bar",
+ ]
+}