diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2020-10-15 14:52:40 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-15 21:52:40 +0800 |
commit | 4f833937fea193e466a33e2f03f21d0b909a407d (patch) | |
tree | 0ce9d00bde8ad44507083f3e11d6d9c8e78522fb | |
parent | 3d71e97dd100fe150db3a5585d744e109bfa53ac (diff) | |
download | tracifyjs-4f833937fea193e466a33e2f03f21d0b909a407d.tar.gz tracifyjs-4f833937fea193e466a33e2f03f21d0b909a407d.zip |
fix corner case in `inline` (#4223)
fixes #4222
-rw-r--r-- | lib/compress.js | 2 | ||||
-rw-r--r-- | test/compress/const.js | 30 |
2 files changed, 31 insertions, 1 deletions
diff --git a/lib/compress.js b/lib/compress.js index e66331d4..504bf39b 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -7041,7 +7041,7 @@ merge(Compressor.prototype, { && fn.is_constant_expression(find_scope(compressor))) && (value = can_flatten_body(stat)) && !fn.contains_this()) { - var replacing = exp === fn || compressor.option("unused") && def.references.length - def.replaced == 1; + var replacing = exp === fn || def.single_use && def.references.length - def.replaced == 1; if (can_substitute_directly()) { var args = self.args.slice(); var refs = []; diff --git a/test/compress/const.js b/test/compress/const.js index cd951fff..ef5c9675 100644 --- a/test/compress/const.js +++ b/test/compress/const.js @@ -1104,3 +1104,33 @@ issue_4220: { } expect_stdout: true } + +issue_4222: { + options = { + inline: true, + reduce_vars: true, + toplevel: true, + unused: true, + } + input: { + { + const a = function() { + return function() {}; + }; + var b = a(); + } + b(); + console.log(typeof a); + } + expect: { + { + const a = function() { + return function() {}; + }; + var b = a(); + } + b(); + console.log(typeof a); + } + expect_stdout: true +} |