diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2020-12-25 00:38:24 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-25 08:38:24 +0800 |
commit | b2f27fd873665013e0e6c9a54e0162e88955d489 (patch) | |
tree | 320e396a62bb2be550ea308f3b5ea0666ca189da | |
parent | ced32f9bd87e3fdc693412d1bdc924a99ecc9712 (diff) | |
download | tracifyjs-b2f27fd873665013e0e6c9a54e0162e88955d489.tar.gz tracifyjs-b2f27fd873665013e0e6c9a54e0162e88955d489.zip |
fix corner case in `functions` & `reduce_vars` (#4452)
fixes #4451
-rw-r--r-- | lib/compress.js | 4 | ||||
-rw-r--r-- | test/compress/functions.js | 28 |
2 files changed, 28 insertions, 4 deletions
diff --git a/lib/compress.js b/lib/compress.js index a6615773..33aa5b91 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -933,10 +933,10 @@ merge(Compressor.prototype, { def.fixed = false; } }, true); - } else if (init instanceof AST_SymbolRef && !init.is_immutable()) { + } else if (init instanceof AST_SymbolRef) { var def = init.definition(); def.assignments++; - def.fixed = false; + if (!init.is_immutable()) def.fixed = false; } this.body.walk(tw); pop(tw); diff --git a/test/compress/functions.js b/test/compress/functions.js index 837d0a04..066bc3ca 100644 --- a/test/compress/functions.js +++ b/test/compress/functions.js @@ -5134,8 +5134,8 @@ issue_4259: { console.log(typeof a); } expect: { - function a() { - for (a in a); + var a = function b() { + for (b in b); } a(); console.log(typeof a); @@ -5225,3 +5225,27 @@ trailing_comma: { expect_exact: 'new function(a,b){console.log(b,a)}(42,"PASS");' expect_stdout: "PASS 42" } + +issue_4451: { + options = { + functions: true, + reduce_vars: true, + toplevel: true, + unused: true, + } + input: { + var a = function f() { + for (f in "foo") + return f; + }; + while (console.log(typeof a())); + } + expect: { + var a = function f() { + for (f in "foo") + return f; + }; + while (console.log(typeof a())); + } + expect_stdout: "function" +} |