aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2020-05-11 20:24:44 +0100
committerGitHub <noreply@github.com>2020-05-12 03:24:44 +0800
commitbd2f53bc8b505ff5bba4e899ea4886d856128b39 (patch)
tree6a2af7b8dfdff15b9ba99ddeb50850ae51b3b5ee
parente8a7956b6f0a71bed038a2b8936eb30d91e94d73 (diff)
downloadtracifyjs-bd2f53bc8b505ff5bba4e899ea4886d856128b39.tar.gz
tracifyjs-bd2f53bc8b505ff5bba4e899ea4886d856128b39.zip
fix corner case in `evaluate` (#3883)
fixes #3882
-rw-r--r--lib/compress.js11
-rw-r--r--test/compress/evaluate.js26
2 files changed, 34 insertions, 3 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 1e33dc10..cb5d9c7b 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -3268,9 +3268,14 @@ merge(Compressor.prototype, {
});
def(AST_Sequence, function(compressor, ignore_side_effects, cached, depth) {
if (!ignore_side_effects) return this;
- var node = this.tail_node();
- var value = node._eval(compressor, ignore_side_effects, cached, depth);
- return value === node ? this : value;
+ var tail = this.tail_node();
+ this.walk(new TreeWalker(function(node) {
+ if (node === tail) return true;
+ if (node instanceof AST_Assign) modified(node.left);
+ if (node instanceof AST_Unary && unary_arithmetic[node.operator]) modified(node.expression);
+ }));
+ var value = tail._eval(compressor, ignore_side_effects, cached, depth);
+ return value === tail ? this : value;
});
def(AST_Lambda, function(compressor) {
if (compressor.option("unsafe")) {
diff --git a/test/compress/evaluate.js b/test/compress/evaluate.js
index a4bee8cc..60f059a8 100644
--- a/test/compress/evaluate.js
+++ b/test/compress/evaluate.js
@@ -2369,3 +2369,29 @@ issue_3878_2: {
}
expect_stdout: "NaN"
}
+
+issue_3882: {
+ options = {
+ evaluate: true,
+ reduce_vars: true,
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ function f(a) {
+ return console.log(a++), a && this;
+ }
+ var b = f();
+ console.log(b);
+ }
+ expect: {
+ var b = function(a) {
+ return console.log(a++), a && this;
+ }();
+ console.log(b);
+ }
+ expect_stdout: [
+ "NaN",
+ "NaN",
+ ]
+}