aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2021-04-13 18:22:08 +0100
committerGitHub <noreply@github.com>2021-04-14 01:22:08 +0800
commitc53af3dfb1cb59681de34142aac420f780c0ec05 (patch)
treeaec38748d032dff59f6b4c5c379ba6a3f94e92c9
parentf1f4a4dd8223a764d3bc8a8a613fa0241a1c9c5f (diff)
downloadtracifyjs-c53af3dfb1cb59681de34142aac420f780c0ec05.tar.gz
tracifyjs-c53af3dfb1cb59681de34142aac420f780c0ec05.zip
fix corner case in `collapse_vars` (#4855)
fixes #4854
-rw-r--r--lib/compress.js7
-rw-r--r--test/compress/default-values.js22
2 files changed, 28 insertions, 1 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 911cf554..010dcf46 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -1792,7 +1792,12 @@ merge(Compressor.prototype, {
right: candidate.value
});
}
- candidate.write_only = false;
+ var assign = candidate;
+ while (assign.write_only) {
+ assign.write_only = false;
+ if (!(assign instanceof AST_Assign)) break;
+ assign = assign.right;
+ }
return candidate;
}
// These node types have child nodes that execute sequentially,
diff --git a/test/compress/default-values.js b/test/compress/default-values.js
index 2e85866e..1a21f513 100644
--- a/test/compress/default-values.js
+++ b/test/compress/default-values.js
@@ -1681,3 +1681,25 @@ issue_4817: {
expect_stdout: "function"
node_version: ">=6"
}
+
+issue_4854: {
+ options = {
+ collapse_vars: true,
+ inline: true,
+ side_effects: true,
+ unused: true,
+ }
+ input: {
+ console.log(function(a) {
+ (function(b = a = "foo") {
+ [] = "foo";
+ })();
+ a;
+ }());
+ }
+ expect: {
+ console.log(void ([] = "foo"));
+ }
+ expect_stdout: "undefined"
+ node_version: ">=6"
+}