aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/compress.js7
-rw-r--r--test/compress/reduce_vars.js28
2 files changed, 34 insertions, 1 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 4166909f..96ed24a5 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -334,6 +334,11 @@ merge(Compressor.prototype, {
if (node instanceof AST_SymbolRef) {
var d = node.definition();
d.references.push(node);
+ if (d.references.length == 1
+ && !d.fixed
+ && d.orig[0] instanceof AST_SymbolDefun) {
+ loop_ids[d.id] = in_loop;
+ }
var value;
if (d.fixed === undefined || !safe_to_read(d) || d.single_use == "m") {
d.fixed = false;
@@ -402,9 +407,9 @@ merge(Compressor.prototype, {
d.fixed = false;
} else {
d.fixed = node;
+ d.single_use = ref_once(d);
loop_ids[d.id] = in_loop;
mark(d, true);
- d.single_use = ref_once(d);
}
var save_ids = safe_ids;
safe_ids = Object.create(null);
diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js
index 108dc0e9..ff93079d 100644
--- a/test/compress/reduce_vars.js
+++ b/test/compress/reduce_vars.js
@@ -4838,3 +4838,31 @@ inverted_var: {
}
expect_stdout: true
}
+
+defun_single_use_loop: {
+ options = {
+ reduce_vars: true,
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ for (var x, i = 2; --i >= 0; ) {
+ var y = x;
+ x = f;
+ console.log(x === y);
+ }
+ function f() {};
+ }
+ expect: {
+ for (var x, i = 2; --i >= 0; ) {
+ var y = x;
+ x = f;
+ console.log(x === y);
+ }
+ function f() {};
+ }
+ expect_stdout: [
+ "false",
+ "true",
+ ]
+}