diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2019-03-15 16:06:47 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-15 16:06:47 +0800 |
commit | 8b3259e0c29b33978c2e025be31e826045d6f6b8 (patch) | |
tree | 4f1689982b1c395adc0c9372d558ea83dfba2cbd | |
parent | b66f47b8dda57af432c60d2515b4e0814620b9d4 (diff) | |
download | tracifyjs-8b3259e0c29b33978c2e025be31e826045d6f6b8.tar.gz tracifyjs-8b3259e0c29b33978c2e025be31e826045d6f6b8.zip |
fix corner case in `reduce_vars` (#3341)
-rw-r--r-- | lib/compress.js | 2 | ||||
-rw-r--r-- | test/compress/reduce_vars.js | 30 |
2 files changed, 31 insertions, 1 deletions
diff --git a/lib/compress.js b/lib/compress.js index 43fd561e..1aa75569 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -5833,7 +5833,7 @@ merge(Compressor.prototype, { var fn = node.fixed_value(); if (!(fn instanceof AST_Lambda)) return; if (!fn.name) return; - if (!fixed.variables.get(fn.name.name)) return; + if (fixed.variables.get(fn.name.name) !== fn.name.definition()) return; fn.name = fn.name.clone(); var value_def = value.variables.get(fn.name.name) || value.def_function(fn.name); node.thedef = value_def; diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js index 32a06b10..27e53452 100644 --- a/test/compress/reduce_vars.js +++ b/test/compress/reduce_vars.js @@ -6686,3 +6686,33 @@ issues_3267_3: { } expect_stdout: "PASS" } + +issue_3297: { + options = { + reduce_vars: true, + unused: true, + } + input: { + (function() { + function f() { + var a; + var b = function a() { + console.log(a === b) && f(); + }; + b(); + } + f(); + })(); + } + expect: { + (function() { + (function f() { + var b = function a() { + console.log(a === b) && f(); + }; + b(); + })(); + })(); + } + expect_stdout: "true" +} |