diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2021-05-15 15:38:09 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-15 22:38:09 +0800 |
commit | a7698f88455b3bfc40b6543c812e6a795f00cd99 (patch) | |
tree | 66312e9b794d468a95483b4ffd301cb78820f796 | |
parent | bbed9b13b12a5bdcaad414e4e2ccd469001eb0e7 (diff) | |
download | tracifyjs-a7698f88455b3bfc40b6543c812e6a795f00cd99.tar.gz tracifyjs-a7698f88455b3bfc40b6543c812e6a795f00cd99.zip |
fix corner case in `reduce_vars` (#4938)
fixes #4937
-rw-r--r-- | lib/compress.js | 2 | ||||
-rw-r--r-- | test/compress/reduce_vars.js | 31 |
2 files changed, 32 insertions, 1 deletions
diff --git a/lib/compress.js b/lib/compress.js index 02c034f6..1c49ee79 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -1143,7 +1143,7 @@ merge(Compressor.prototype, { var parent = tw.parent(); if (parent instanceof AST_ExportDeclaration || parent instanceof AST_ExportDefault) def.single_use = false; if (tw.defun_visited[def.id]) return true; - if (tw.defun_ids[def.id] !== tw.safe_ids) return true; + if (def.init === fn && tw.defun_ids[def.id] !== tw.safe_ids) return true; tw.defun_visited[def.id] = true; fn.inlined = false; push(tw); diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js index 5ae0884b..c899fcf0 100644 --- a/test/compress/reduce_vars.js +++ b/test/compress/reduce_vars.js @@ -7631,3 +7631,34 @@ issue_4568: { } expect_stdout: "PASS" } + +issue_4937: { + options = { + reduce_vars: true, + toplevel: true, + unused: true, + } + input: { + function f() { + while (console.log("PASS")); + } + do { + function g() { + f(); + } + } while (!g); + f(); + } + expect: { + function f() { + while (console.log("PASS")); + } + do { + function g() { + f(); + } + } while (!g); + f(); + } + expect_stdout: "PASS" +} |