diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2020-05-17 15:25:13 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-17 22:25:13 +0800 |
commit | 48b62393a4d947fe22d5516e53267a37245347c5 (patch) | |
tree | 01785e7ecc8f0e303762d674943152a729da7d5f | |
parent | a00f8dade75838862d1d284440eea6d35198b63e (diff) | |
download | tracifyjs-48b62393a4d947fe22d5516e53267a37245347c5.tar.gz tracifyjs-48b62393a4d947fe22d5516e53267a37245347c5.zip |
fix corner case in `evaluate` (#3904)
fixes #3903
-rw-r--r-- | lib/compress.js | 6 | ||||
-rw-r--r-- | test/compress/evaluate.js | 26 |
2 files changed, 31 insertions, 1 deletions
diff --git a/lib/compress.js b/lib/compress.js index 986bed38..02d36d6c 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -3571,6 +3571,7 @@ merge(Compressor.prototype, { var args = eval_args(this.args); if (!args && !ignore_side_effects) return this; if (!stat.value) return; + var cached_args = []; if (args && !all(fn.argnames, function(sym, i) { var value = args[i]; var def = sym.definition(); @@ -3579,13 +3580,16 @@ merge(Compressor.prototype, { node._eval = function() { return value; }; - cached.push(node); + cached_args.push(node); }); return true; }) && !ignore_side_effects) return this; fn.evaluating = true; var val = stat.value._eval(compressor, ignore_side_effects, cached, depth); delete fn.evaluating; + cached_args.forEach(function(node) { + delete node._eval; + }); if (val === stat.value) return this; return val; } else if (compressor.option("unsafe") && exp instanceof AST_PropAccess) { diff --git a/test/compress/evaluate.js b/test/compress/evaluate.js index 8425abe2..3f9f1014 100644 --- a/test/compress/evaluate.js +++ b/test/compress/evaluate.js @@ -2418,3 +2418,29 @@ issue_3887: { } expect_stdout: "PASS" } + +issue_3903: { + options = { + evaluate: true, + reduce_vars: true, + toplevel: true, + unused: true, + } + input: { + var a = "PASS"; + function f(b, c) { + return console, c; + } + var d = f(f(), a = a); + console.log(d); + } + expect: { + var a = "PASS"; + function f(b, c) { + return console, c; + } + var d = f(f(), a = a); + console.log(d); + } + expect_stdout: "PASS" +} |