fix for-of loop with const iterator (#1899)

This commit is contained in:
kzc
2017-05-09 23:36:03 -04:00
committed by Alex Lam S.L
parent 6ddb5bd94d
commit 9d59c693c2
2 changed files with 35 additions and 3 deletions

View File

@@ -1785,7 +1785,7 @@ function parse($TEXT, options) {
name : as_symbol(sym_type), name : as_symbol(sym_type),
value : is("operator", "=") value : is("operator", "=")
? (next(), expression(false, no_in)) ? (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, ? croak("Missing initializer in const declaration") : null,
end : prev() end : prev()
}) })
@@ -1814,10 +1814,10 @@ function parse($TEXT, options) {
}); });
}; };
var const_ = function() { var const_ = function(no_in) {
return new AST_Const({ return new AST_Const({
start : prev(), start : prev(),
definitions : vardefs(false, "const"), definitions : vardefs(no_in, "const"),
end : prev() end : prev()
}); });
}; };

View File

@@ -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();
}
}