Skip to content

Commit

Permalink
fix for-of loop with const iterator (#1899)
Browse files Browse the repository at this point in the history
  • Loading branch information
kzc authored and alexlamsl committed May 10, 2017
1 parent 6ddb5bd commit 9d59c69
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -1785,7 +1785,7 @@ function parse($TEXT, options) {
name : as_symbol(sym_type),
value : is("operator", "=")
? (next(), expression(false, no_in))
: kind === "const" && S.input.has_directive("use strict")
: !no_in && kind === "const" && S.input.has_directive("use strict")
? croak("Missing initializer in const declaration") : null,
end : prev()
})
Expand Down Expand Up @@ -1814,10 +1814,10 @@ function parse($TEXT, options) {
});
};

var const_ = function() {
var const_ = function(no_in) {
return new AST_Const({
start : prev(),
definitions : vardefs(false, "const"),
definitions : vardefs(no_in, "const"),
end : prev()
});
};
Expand Down
32 changes: 32 additions & 0 deletions test/compress/harmony.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,3 +392,35 @@ format_methods: {
"}",
]
}

issue_1898: {
options = {
}
mangle = {
}
input: {
class Foo {
bar() {
for (const x of [ 6, 5 ]) {
for (let y of [ 4, 3 ]) {
for (var z of [ 2, 1 ]) {
console.log(x, y, z);
}
}
}
}
}
new Foo().bar();
}
expect: {
class Foo {
bar() {
for (const n of [ 6, 5 ])
for (let r of [ 4, 3 ])
for (var o of [ 2, 1 ])
console.log(n, r, o);
}
}
new Foo().bar();
}
}

0 comments on commit 9d59c69

Please sign in to comment.