aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2020-10-13 19:49:45 +0100
committerGitHub <noreply@github.com>2020-10-14 02:49:45 +0800
commitb7b8435721a07bebec9fca513700cc2af31ed175 (patch)
tree2a02342a8390dd4d9a999e477117ad3908275447
parentc0c04c33bb1652014365fa893cc9b7d29684e59a (diff)
downloadtracifyjs-b7b8435721a07bebec9fca513700cc2af31ed175.tar.gz
tracifyjs-b7b8435721a07bebec9fca513700cc2af31ed175.zip
fix corner case in `evaluate` (#4215)
fixes #4214
-rw-r--r--lib/compress.js8
-rw-r--r--test/compress/evaluate.js33
2 files changed, 38 insertions, 3 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 5dd10c6c..baa501ff 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -3804,6 +3804,8 @@ merge(Compressor.prototype, {
if (fn.evaluating) return this;
if (fn.name && fn.name.definition().recursive_refs > 0) return this;
if (this.is_expr_pure(compressor)) return this;
+ var args = eval_args(this.args);
+ if (!args && !ignore_side_effects) return this;
var stat = fn.first_statement();
if (!(stat instanceof AST_Return)) {
if (ignore_side_effects) {
@@ -3811,7 +3813,9 @@ merge(Compressor.prototype, {
fn.walk(new TreeWalker(function(node) {
if (found) return true;
if (node instanceof AST_Return) {
- if (node.value && node.value.evaluate(compressor, true) !== undefined) found = true;
+ if (node.value && node.value._eval(compressor, true, cached, depth) !== undefined) {
+ found = true;
+ }
return true;
}
if (node instanceof AST_Scope && node !== fn) return true;
@@ -3820,8 +3824,6 @@ merge(Compressor.prototype, {
}
return this;
}
- var args = eval_args(this.args);
- if (!args && !ignore_side_effects) return this;
var val = stat.value;
if (!val) return;
var cached_args = [];
diff --git a/test/compress/evaluate.js b/test/compress/evaluate.js
index 9504afb5..9fa65202 100644
--- a/test/compress/evaluate.js
+++ b/test/compress/evaluate.js
@@ -3014,3 +3014,36 @@ issue_4119_4: {
}
expect_stdout: "PASS"
}
+
+issue_4214: {
+ options = {
+ evaluate: true,
+ reduce_vars: true,
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ function f(a) {
+ return function() {
+ try {
+ return a;
+ } finally {
+ var b = 0;
+ }
+ }(a++ && this());
+ }
+ var c = f();
+ console.log(c);
+ }
+ expect: {
+ var c = function(a) {
+ return function() {
+ try {
+ return a;
+ } finally {}
+ }(a++ && this());
+ }();
+ console.log(c);
+ }
+ expect_stdout: "NaN"
+}