aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2020-12-21 06:03:18 +0000
committerGitHub <noreply@github.com>2020-12-21 14:03:18 +0800
commitc3190303737db4cb3380e6fba19ec1cd86c12124 (patch)
treeba2eec5ad94da1d58272c3b1174f5e0fc78ac937
parent47b63ed1a09caf5e15a51276adad83a94c89abac (diff)
downloadtracifyjs-c3190303737db4cb3380e6fba19ec1cd86c12124.tar.gz
tracifyjs-c3190303737db4cb3380e6fba19ec1cd86c12124.zip
fix corner case in `reduce_vars` (#4433)
fixes #4432
-rw-r--r--lib/compress.js12
-rw-r--r--test/compress/arguments.js20
2 files changed, 29 insertions, 3 deletions
diff --git a/lib/compress.js b/lib/compress.js
index d532300c..81fe8866 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -912,10 +912,16 @@ merge(Compressor.prototype, {
init.walk(tw);
if (init instanceof AST_Definitions) {
init.definitions[0].name.match_symbol(function(node) {
- if (node instanceof AST_SymbolDeclaration) node.definition().fixed = false;
+ if (node instanceof AST_SymbolDeclaration) {
+ var def = node.definition();
+ def.assignments++;
+ def.fixed = false;
+ }
}, true);
- } else if (init instanceof AST_SymbolRef) {
- init.definition().fixed = false;
+ } else if (init instanceof AST_SymbolRef && !init.is_immutable()) {
+ var def = init.definition();
+ def.assignments++;
+ def.fixed = false;
}
this.body.walk(tw);
pop(tw);
diff --git a/test/compress/arguments.js b/test/compress/arguments.js
index 39628b50..ddf5695b 100644
--- a/test/compress/arguments.js
+++ b/test/compress/arguments.js
@@ -942,3 +942,23 @@ issue_4410_3: {
}
expect_stdout: "PASS"
}
+
+issue_4432: {
+ options = {
+ arguments: true,
+ reduce_vars: true,
+ }
+ input: {
+ console.log(function(a) {
+ for (a in { FAIL: 42 });
+ return arguments[0];
+ }() || "PASS");
+ }
+ expect: {
+ console.log(function(a) {
+ for (a in { FAIL: 42 });
+ return arguments[0];
+ }() || "PASS");
+ }
+ expect_stdout: "PASS"
+}