aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/compress.js12
-rw-r--r--test/compress/varify.js52
2 files changed, 62 insertions, 2 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 18c1d265..6010752d 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -6096,7 +6096,7 @@ merge(Compressor.prototype, {
return !compressor.exposed(def) && def.references.length == def.replaced;
} : function(def) {
if (!(def.id in in_use_ids)) return true;
- if (def.orig.length < 2) return false;
+ if (def.orig.length - def.eliminated < 2) return false;
// function argument will always overshadow its name
if (def.orig[1] instanceof AST_SymbolFunarg) return true;
// retain if referenced within destructured object of argument
@@ -8551,7 +8551,7 @@ merge(Compressor.prototype, {
def.scope = scope;
scope.variables.set(def.name, def);
}),
- value: defn.value
+ value: defn.value,
});
})
});
@@ -10672,6 +10672,14 @@ merge(Compressor.prototype, {
lambda_def.recursive_refs = def.recursive_refs;
}
value.walk(new TreeWalker(function(node) {
+ if (node instanceof AST_SymbolDeclaration) {
+ if (node !== name) {
+ var def = node.definition();
+ def.orig.push(node);
+ def.eliminated++;
+ }
+ return;
+ }
if (!(node instanceof AST_SymbolRef)) return;
var def = node.definition();
if (def === defun_def) {
diff --git a/test/compress/varify.js b/test/compress/varify.js
index f60c5474..75d50e6d 100644
--- a/test/compress/varify.js
+++ b/test/compress/varify.js
@@ -523,3 +523,55 @@ default_init: {
expect_stdout: "PASS"
node_version: ">=4"
}
+
+issue_4933_1: {
+ options = {
+ reduce_vars: true,
+ toplevel: true,
+ unused: true,
+ varify: true,
+ }
+ input: {
+ console.log(f());
+ function f() {
+ var a;
+ for (console in a = [ f ]) {
+ const b = a;
+ }
+ }
+ }
+ expect: {
+ console.log(function f() {
+ var a;
+ for (console in a = [ f ]) {
+ const b = a;
+ }
+ }());
+ }
+ expect_stdout: "undefined"
+}
+
+issue_4933_2: {
+ options = {
+ passes: 2,
+ reduce_vars: true,
+ toplevel: true,
+ unused: true,
+ varify: true,
+ }
+ input: {
+ console.log(f());
+ function f() {
+ var a;
+ for (console in a = [ f ]) {
+ const b = a;
+ }
+ }
+ }
+ expect: {
+ console.log(function f() {
+ for (console in [ f ]);
+ }());
+ }
+ expect_stdout: "undefined"
+}