aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2021-02-15 22:46:45 +0000
committerGitHub <noreply@github.com>2021-02-16 06:46:45 +0800
commitfa8aa204a0bec791b00bd6ceb3682e2a06167900 (patch)
tree73b48cff63365035a70fb7298ab590dce68bbacf
parent76b27891c6f834d35da3b6dc6d25ad53c4f3bc36 (diff)
downloadtracifyjs-fa8aa204a0bec791b00bd6ceb3682e2a06167900.tar.gz
tracifyjs-fa8aa204a0bec791b00bd6ceb3682e2a06167900.zip
fix corner case in `reduce_vars` (#4654)
fixes #4653
-rw-r--r--lib/compress.js25
-rw-r--r--test/compress/merge_vars.js27
2 files changed, 41 insertions, 11 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 5adeb566..b4f9c3a8 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -853,18 +853,21 @@ merge(Compressor.prototype, {
}
return true;
- function walk_prop(node) {
- if (node instanceof AST_Dot) {
- walk_prop(node.expression);
- } else if (node instanceof AST_Sub) {
- walk_prop(node.expression);
- node.property.walk(tw);
- } else if (node instanceof AST_SymbolRef) {
- var d = node.definition();
- push_ref(d, node);
- node.fixed = d.fixed;
+ function walk_prop(lhs) {
+ if (lhs instanceof AST_Dot) {
+ walk_prop(lhs.expression);
+ } else if (lhs instanceof AST_Sub) {
+ walk_prop(lhs.expression);
+ lhs.property.walk(tw);
+ } else if (lhs instanceof AST_SymbolRef) {
+ var d = lhs.definition();
+ push_ref(d, lhs);
+ if (d.fixed) {
+ lhs.fixed = d.fixed;
+ lhs.fixed.assigns = [ node ];
+ }
} else {
- node.walk(tw);
+ lhs.walk(tw);
}
}
});
diff --git a/test/compress/merge_vars.js b/test/compress/merge_vars.js
index 02d17d31..c45f8353 100644
--- a/test/compress/merge_vars.js
+++ b/test/compress/merge_vars.js
@@ -3212,3 +3212,30 @@ issue_4628: {
}
expect_stdout: "undefined"
}
+
+issue_4653: {
+ options = {
+ evaluate: true,
+ merge_vars: true,
+ reduce_vars: true,
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ var a = 1, b;
+ function f(c, d) {
+ c || console.log(d);
+ }
+ f(a++ + (b = b), b |= console.log(a));
+ }
+ expect: {
+ var b = 1;
+ (function(c, d) {
+ c || console.log(d);
+ })(+b + (b = void 0), b |= console.log(2));
+ }
+ expect_stdout: [
+ "2",
+ "0",
+ ]
+}