diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2021-07-04 08:09:05 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-04 15:09:05 +0800 |
commit | f5dbb672b90b0591a824935c4855afc99adc2e59 (patch) | |
tree | bce6ae34ffb1e8718b1bb2196884f46eb9bfe5d6 | |
parent | f4ae2679202ff9d8edd6a0d7c13cf756e5096a96 (diff) | |
download | tracifyjs-f5dbb672b90b0591a824935c4855afc99adc2e59.tar.gz tracifyjs-f5dbb672b90b0591a824935c4855afc99adc2e59.zip |
fix corner case in `reduce_funcs` (#5049)
fixes #5048
-rw-r--r-- | lib/compress.js | 5 | ||||
-rw-r--r-- | test/compress/reduce_vars.js | 19 |
2 files changed, 22 insertions, 2 deletions
diff --git a/lib/compress.js b/lib/compress.js index 2530ec9f..4aefb8db 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -10913,9 +10913,10 @@ merge(Compressor.prototype, { return self; }); - function recursive_ref(compressor, def) { + function recursive_ref(compressor, def, fn) { var level = 0, node = compressor.self(); do { + if (node === fn) return node; if (is_lambda(node) && node.name && node.name.definition() === def) return node; } while (node = compressor.parent(level++)); } @@ -10951,7 +10952,7 @@ merge(Compressor.prototype, { if ((def.scope !== self.scope.resolve() || def.in_loop) && (!compressor.option("reduce_funcs") || def.escaped.depth == 1 || fixed.inlined)) { single_use = false; - } else if (recursive_ref(compressor, def)) { + } else if (recursive_ref(compressor, def, fixed)) { single_use = false; } else if (fixed.name && fixed.name.definition() !== def) { single_use = false; diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js index c1531b25..735688ea 100644 --- a/test/compress/reduce_vars.js +++ b/test/compress/reduce_vars.js @@ -7677,3 +7677,22 @@ issue_4949: { } expect_stdout: "0 1" } + +issue_5048: { + options = { + reduce_funcs: true, + reduce_vars: true, + unused: true, + } + input: { + console.log(function() { + var a = function() { + return a + 42; + }; + }()); + } + expect: { + console.log(function() {}()); + } + expect_stdout: "undefined" +} |