diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2021-07-10 21:11:10 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-11 04:11:10 +0800 |
commit | d147d5d7f0bc61b1284a18a31eaa41c208a278ea (patch) | |
tree | 735c1a32a787dd09d3096b63b79e0d23ec9825d8 | |
parent | aae1fcd12d1dbd656f4225458a787d5b06f9222b (diff) | |
download | tracifyjs-d147d5d7f0bc61b1284a18a31eaa41c208a278ea.tar.gz tracifyjs-d147d5d7f0bc61b1284a18a31eaa41c208a278ea.zip |
fix corner case in `inline` (#5068)
fixes #5067
-rw-r--r-- | lib/compress.js | 4 | ||||
-rw-r--r-- | test/compress/functions.js | 15 |
2 files changed, 17 insertions, 2 deletions
diff --git a/lib/compress.js b/lib/compress.js index bfbb8ddc..947ca6cd 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -2207,7 +2207,7 @@ merge(Compressor.prototype, { fn = fn.fixed_value(); } if (!(fn instanceof AST_Lambda)) return !node.is_expr_pure(compressor); - if (def && recursive_ref(compressor, def)) return true; + if (def && recursive_ref(compressor, def, fn)) return true; if (fn.collapse_scanning) return false; fn.collapse_scanning = true; var replace = can_replace; @@ -9481,7 +9481,7 @@ merge(Compressor.prototype, { && !fn.uses_arguments && !fn.pinned() && !(fn.name && fn instanceof AST_LambdaExpression) - && (exp === fn || !recursive_ref(compressor, def = exp.definition()) + && (exp === fn || !recursive_ref(compressor, def = exp.definition(), fn) && fn.is_constant_expression(find_scope(compressor))) && !has_spread && (value = can_flatten_body(stat)) diff --git a/test/compress/functions.js b/test/compress/functions.js index 7c6ebe03..a4a876fa 100644 --- a/test/compress/functions.js +++ b/test/compress/functions.js @@ -6398,3 +6398,18 @@ issue_5061_2: { "bar", ] } + +issue_5067: { + options = { + inline: true, + reduce_vars: true, + toplevel: true, + unused: true, + } + input: { + var f = function() { + f(); + }; + } + expect: {} +} |