diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2020-05-15 11:03:56 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-15 18:03:56 +0800 |
commit | 8d81d264f46b78a86491bfa6e33817cd7237f43f (patch) | |
tree | eb9921c88a74bf7862badb3444574e7115d96f48 | |
parent | 5ef7060098e231e1c31800f0ebcb19317bf0e077 (diff) | |
download | tracifyjs-8d81d264f46b78a86491bfa6e33817cd7237f43f.tar.gz tracifyjs-8d81d264f46b78a86491bfa6e33817cd7237f43f.zip |
fix corner case in `functions` (#3900)
fixes #3899
-rw-r--r-- | lib/compress.js | 1 | ||||
-rw-r--r-- | test/compress/drop-unused.js | 35 |
2 files changed, 35 insertions, 1 deletions
diff --git a/lib/compress.js b/lib/compress.js index 36a04a70..986bed38 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -4363,6 +4363,7 @@ merge(Compressor.prototype, { } else if (compressor.option("functions") && !compressor.option("ie8") && var_defs.length == 1 + && sym.assignments == 0 && def.value === def.name.fixed_value() && def.value instanceof AST_Function && !(def.value.name && def.value.name.definition().assignments) diff --git a/test/compress/drop-unused.js b/test/compress/drop-unused.js index ff230ae2..e3166970 100644 --- a/test/compress/drop-unused.js +++ b/test/compress/drop-unused.js @@ -2527,7 +2527,40 @@ issue_3802_2: { } expect: { 0; - function a() {}; + var a = function() {}; + console.log(typeof a); + } + expect_stdout: "function" +} + +issue_3899: { + options = { + assignments: true, + evaluate: true, + functions: true, + inline: true, + join_vars: true, + passes: 2, + reduce_vars: true, + side_effects: true, + toplevel: true, + unused: true, + } + input: { + var a = 0; + a = a + 1; + var a = function f(b) { + return function() { + return b; + }; + }(2); + console.log(typeof a); + } + expect: { + ++a; + var a = function() { + return 2; + }; console.log(typeof a); } expect_stdout: "function" |