diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2019-04-24 14:01:01 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-24 14:01:01 +0800 |
commit | dafed54764c7d85a6aa337ee6fdc54d9f9312b55 (patch) | |
tree | d36bb90e3350eda936eab7768ee33fe0e8dd7967 | |
parent | a84beafd1bbdb61ea5fc3662e349f6c960f1ba66 (diff) | |
download | tracifyjs-dafed54764c7d85a6aa337ee6fdc54d9f9312b55.tar.gz tracifyjs-dafed54764c7d85a6aa337ee6fdc54d9f9312b55.zip |
fix corner case in `reduce_vars` (#3378)
fixes #3377
-rw-r--r-- | lib/compress.js | 6 | ||||
-rw-r--r-- | test/compress/reduce_vars.js | 18 |
2 files changed, 21 insertions, 3 deletions
diff --git a/lib/compress.js b/lib/compress.js index 3fb835f5..9430c15d 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -744,7 +744,7 @@ merge(Compressor.prototype, { d.fixed = false; } else if (d.fixed) { value = this.fixed_value(); - if (value instanceof AST_Lambda && recursive_ref(tw, d)) { + if (recursive_ref(tw, d)) { d.recursive_refs++; } else if (value && ref_once(tw, compressor, d)) { d.single_use = value instanceof AST_Lambda && !value.pinned() @@ -2603,9 +2603,9 @@ merge(Compressor.prototype, { } function convert_to_predicate(obj) { - for (var key in obj) { + Object.keys(obj).forEach(function(key) { obj[key] = makePredicate(obj[key]); - } + }); } var object_fns = [ diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js index 169ae5a5..7ad8ab94 100644 --- a/test/compress/reduce_vars.js +++ b/test/compress/reduce_vars.js @@ -6737,3 +6737,21 @@ drop_side_effect_free: { } expect_stdout: "123" } + +issue_3377: { + options = { + reduce_vars: true, + unused: true, + } + input: { + console.log(function f() { + return f[0], (f = 42); + }()); + } + expect: { + console.log(function f() { + return f[0], (f = 42); + }()); + } + expect_stdout: "42" +} |