Skip to content

Commit fe9227a

Browse files
authoredMar 2, 2017
fix reference marking in for-in loops (#1535)
fixes #1533
1 parent b49e142 commit fe9227a

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed
 

‎lib/compress.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,11 @@ merge(Compressor.prototype, {
244244
}
245245
if (node instanceof AST_ForIn) {
246246
if (node.init instanceof AST_SymbolRef) {
247-
node.init.definition().fixed = false;
247+
var d = node.init.definition();
248+
d.references.push(node.init);
249+
d.fixed = false;
250+
} else {
251+
node.init.walk(tw);
248252
}
249253
node.object.walk(tw);
250254
push();

‎test/compress/reduce_vars.js

+36
Original file line numberDiff line numberDiff line change
@@ -589,3 +589,39 @@ inner_var_for_in: {
589589
x(1, b, c, d);
590590
}
591591
}
592+
593+
issue_1533_1: {
594+
options = {
595+
collapse_vars: true,
596+
reduce_vars: true,
597+
}
598+
input: {
599+
var id = "";
600+
for (id in {break: "me"})
601+
console.log(id);
602+
}
603+
expect: {
604+
var id = "";
605+
for (id in {break: "me"})
606+
console.log(id);
607+
}
608+
}
609+
610+
issue_1533_2: {
611+
options = {
612+
evaluate: true,
613+
reduce_vars: true,
614+
}
615+
input: {
616+
var id = "";
617+
for (var id in {break: "me"})
618+
console.log(id);
619+
console.log(id);
620+
}
621+
expect: {
622+
var id = "";
623+
for (var id in {break: "me"})
624+
console.log(id);
625+
console.log(id);
626+
}
627+
}

0 commit comments

Comments
 (0)
Please sign in to comment.