diff --git a/lib/parse.js b/lib/parse.js index 492509dee60..bac83ed5437 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -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() }) @@ -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() }); }; diff --git a/test/compress/harmony.js b/test/compress/harmony.js index ee858ca1912..ca36d2eac07 100644 --- a/test/compress/harmony.js +++ b/test/compress/harmony.js @@ -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(); + } +}