aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2021-07-24 00:10:14 +0100
committerGitHub <noreply@github.com>2021-07-24 07:10:14 +0800
commit657d525c80e611df9a78812e4b6a35a3eb24d8f4 (patch)
tree011d38b8dc62992972f61270915e62fece469e7c
parent6a3fe9d1dfd3ec4543dc71b72e990bed2c6022ef (diff)
downloadtracifyjs-657d525c80e611df9a78812e4b6a35a3eb24d8f4.tar.gz
tracifyjs-657d525c80e611df9a78812e4b6a35a3eb24d8f4.zip
fix corner case in `reduce_vars` (#5099)
fixes #5098
-rw-r--r--lib/compress.js5
-rw-r--r--test/compress/functions.js30
2 files changed, 34 insertions, 1 deletions
diff --git a/lib/compress.js b/lib/compress.js
index e0252646..dc171ae7 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -981,7 +981,10 @@ merge(Compressor.prototype, {
if (fixed && !modified && !sym.in_arg && safe_to_assign(tw, d)) {
push_ref(d, sym);
mark(tw, d);
- if (d.single_use && left instanceof AST_Destructured) d.single_use = false;
+ if (left instanceof AST_Destructured
+ || d.orig.length == 1 && d.orig[0] instanceof AST_SymbolDefun) {
+ d.single_use = false;
+ }
tw.loop_ids[d.id] = tw.in_loop;
mark_escaped(tw, d, sym.scope, node, right, 0, 1);
sym.fixed = d.fixed = fixed;
diff --git a/test/compress/functions.js b/test/compress/functions.js
index ff727da4..ccfb3044 100644
--- a/test/compress/functions.js
+++ b/test/compress/functions.js
@@ -6535,3 +6535,33 @@ issue_5096_4: {
}
expect_stdout: "PASS"
}
+
+issue_5098: {
+ options = {
+ reduce_vars: true,
+ unused: true,
+ }
+ input: {
+ (function(o) {
+ function f() {
+ f = console.log;
+ if (o.p++)
+ throw "FAIL";
+ f("PASS");
+ }
+ return f;
+ })({ p: 0 })();
+ }
+ expect: {
+ (function(o) {
+ function f() {
+ f = console.log;
+ if (o.p++)
+ throw "FAIL";
+ f("PASS");
+ }
+ return f;
+ })({ p: 0 })();
+ }
+ expect_stdout: "PASS"
+}