michael@0: // The decompiler correctly handles for-of loops. michael@0: michael@0: function tokens(code) { michael@0: var arr = []; michael@0: var s = code.replace(/\w+|[^\s]/g, function (tok) { arr.push(tok); return ""; }); michael@0: assertEq(s.trim(), "", "tokens() should find all tokens in code: " + uneval(code)); michael@0: return arr; michael@0: } michael@0: michael@0: function test(code) { michael@0: var before = "function f() { " + code + " }"; michael@0: var after = eval("(" + before + ")").toString(); michael@0: assertEq(tokens(before).join(" "), tokens(after).join(" "), "decompiler failed to round-trip"); michael@0: } michael@0: michael@0: // statements michael@0: test("for (a of b) { f(a); }"); michael@0: test("for (a of b) { f(a); g(a); }"); michael@0: michael@0: // for-of with "in" operator nearby michael@0: test("for (a of b in c ? c : c.items()) { f(a); }"); michael@0: michael@0: // destructuring michael@0: test("for ([a, b] of c) { a.m(b); }"); michael@0: michael@0: // for-let-of michael@0: test("for (let a of b) { f(a); }"); michael@0: test("for (let [a, b] of c) { a.m(b); }"); michael@0: michael@0: // array comprehensions michael@0: test("return [a for (a of b)];"); michael@0: test("return [[b, a] for ([a, b] of c.items())];"); michael@0: michael@0: // generator expressions michael@0: test("return (a for (a of b));"); michael@0: