aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2020-12-20 14:54:27 +0000
committerGitHub <noreply@github.com>2020-12-20 22:54:27 +0800
commit47b63ed1a09caf5e15a51276adad83a94c89abac (patch)
tree0c833c73fc6afd64102695e5aaf0ffc929460e52
parent7aefe97083c63660cf0708e549aebce66248796b (diff)
downloadtracifyjs-47b63ed1a09caf5e15a51276adad83a94c89abac.tar.gz
tracifyjs-47b63ed1a09caf5e15a51276adad83a94c89abac.zip
fix corner case in `collapse_vars` (#4431)
fixes #4430
-rw-r--r--lib/compress.js10
-rw-r--r--test/compress/collapse_vars.js60
2 files changed, 68 insertions, 2 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 7c1c3b42..d532300c 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -1743,7 +1743,11 @@ merge(Compressor.prototype, {
if (node instanceof AST_LoopControl) return true;
if (node instanceof AST_SymbolRef) {
if (node.is_declared(compressor)) {
- if (node.fixed_value() || can_drop_symbol(node)) return false;
+ if (node.fixed_value()) return false;
+ if (can_drop_symbol(node)) {
+ return !(parent instanceof AST_PropAccess && parent.expression === node)
+ && is_arguments(node.definition());
+ }
} else if (parent instanceof AST_Assign && parent.operator == "=" && parent.left === node) {
return false;
}
@@ -1812,7 +1816,9 @@ merge(Compressor.prototype, {
return compressor.option("ie8") && node.name && lvalues.has(node.name.name);
}
if (node instanceof AST_PropAccess) {
- return side_effects || !value_def && node.expression.may_throw_on_access(compressor);
+ var exp = node.expression;
+ return side_effects || !value_def && exp.may_throw_on_access(compressor)
+ || exp instanceof AST_SymbolRef && is_arguments(exp.definition());
}
if (node instanceof AST_Spread) return true;
if (node instanceof AST_SymbolRef) {
diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js
index edf4795a..17ee8d10 100644
--- a/test/compress/collapse_vars.js
+++ b/test/compress/collapse_vars.js
@@ -8602,3 +8602,63 @@ issue_4248: {
}
expect_stdout: "1"
}
+
+issue_4430_1: {
+ options = {
+ collapse_vars: true,
+ pure_getters: "strict",
+ }
+ input: {
+ function f(a) {
+ switch (a = 1, arguments[0]) {
+ case 1:
+ return "PASS";
+ case 2:
+ return "FAIL";
+ }
+ }
+ console.log(f(2));
+ }
+ expect: {
+ function f(a) {
+ switch (a = 1, arguments[0]) {
+ case 1:
+ return "PASS";
+ case 2:
+ return "FAIL";
+ }
+ }
+ console.log(f(2));
+ }
+ expect_stdout: "PASS"
+}
+
+issue_4430_2: {
+ options = {
+ collapse_vars: true,
+ pure_getters: "strict",
+ }
+ input: {
+ function f(a) {
+ switch (a = 0, arguments[0]) {
+ case 0:
+ return "PASS";
+ case 1:
+ return "FAIL";
+ }
+ }
+ console.log(f(1));
+ }
+ expect: {
+ function f(a) {
+ switch (arguments[a = 0]) {
+ case 0:
+ return "PASS";
+ case 1:
+ return "FAIL";
+ }
+ }
+ console.log(f(1));
+ }
+ expect_stdout: "PASS"
+}