diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2021-01-01 02:39:40 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-01 10:39:40 +0800 |
commit | 311c074622e0aabbd79b0d701c19f21b8b093b77 (patch) | |
tree | 7aace77db4792459c6d1a788bb25e95533d17e8a | |
parent | a10c7793bb282a4023337c08c623b7607921655f (diff) | |
download | tracifyjs-311c074622e0aabbd79b0d701c19f21b8b093b77.tar.gz tracifyjs-311c074622e0aabbd79b0d701c19f21b8b093b77.zip |
fix corner case in `functions` (#4488)
fixes #4487
-rw-r--r-- | lib/compress.js | 2 | ||||
-rw-r--r-- | test/compress/hoist_vars.js | 24 |
2 files changed, 25 insertions, 1 deletions
diff --git a/lib/compress.js b/lib/compress.js index 531c9aad..6c26e8a9 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -5659,7 +5659,7 @@ merge(Compressor.prototype, { var defun = make_node(AST_Defun, def, def.value); defun.name = make_node(AST_SymbolDefun, def.name, def.name); var name_def = def.name.scope.resolve().def_function(defun.name); - if (old_def) old_def.references.forEach(function(node) { + if (old_def) old_def.forEach(function(node) { node.name = name_def.name; node.thedef = name_def; node.reference({}); diff --git a/test/compress/hoist_vars.js b/test/compress/hoist_vars.js index 6cd99b06..173aaeaf 100644 --- a/test/compress/hoist_vars.js +++ b/test/compress/hoist_vars.js @@ -134,3 +134,27 @@ issue_2295: { } } } + +issue_4487: { + options = { + functions: true, + hoist_vars: true, + keep_fnames: true, + reduce_vars: true, + toplevel: true, + unused: true, + } + input: { + var a = function f() { + var f = console.log(typeof f); + }; + var b = a(); + } + expect: { + function a() { + var a = console.log(typeof a); + } + a(); + } + expect_stdout: "undefined" +} |