diff --git a/packages/babel-plugin-transform-block-scoping/src/loop.ts b/packages/babel-plugin-transform-block-scoping/src/loop.ts index 6c0fa83aad28..1fbe72eadd26 100644 --- a/packages/babel-plugin-transform-block-scoping/src/loop.ts +++ b/packages/babel-plugin-transform-block-scoping/src/loop.ts @@ -254,45 +254,92 @@ export function wrapLoopBody( } } if (varNames.length) { - bodyStmts.push( - t.variableDeclaration( - "var", - varNames.map(name => t.variableDeclarator(t.identifier(name))), - ), + varPath.pushContainer( + "declarations", + varNames.map(name => t.variableDeclarator(t.identifier(name))), ); } - if (state.breaksContinues.length === 0 && state.returns.length === 0) { + const labelNum = state.breaksContinues.length; + const returnNum = state.returns.length; + if (labelNum + returnNum === 0) { bodyStmts.push(t.expressionStatement(call)); + } else if (labelNum === 1 && returnNum === 0) { + for (const path of state.breaksContinues) { + const { node } = path; + const { type, label } = node; + let name = type === "BreakStatement" ? "break" : "continue"; + if (label) name += " " + label.name; + path.replaceWith( + t.addComment( + t.returnStatement(t.numericLiteral(1)), + "trailing", + " " + name, + true, + ), + ); + if (updaterNode) path.insertBefore(t.cloneNode(updaterNode)); + + bodyStmts.push( + template.statement.ast` + if (${call}) ${node} + `, + ); + } } else { const completionId = loopPath.scope.generateUid("ret"); - bodyStmts.push( - t.variableDeclaration("var", [ - t.variableDeclarator(t.identifier(completionId), call), - ]), - ); - const injected = new Set(); + if (varPath.isVariableDeclaration()) { + varPath.pushContainer("declarations", [ + t.variableDeclarator(t.identifier(completionId)), + ]); + bodyStmts.push( + t.expressionStatement( + t.assignmentExpression("=", t.identifier(completionId), call), + ), + ); + } else { + bodyStmts.push( + t.variableDeclaration("var", [ + t.variableDeclarator(t.identifier(completionId), call), + ]), + ); + } + + const injected: string[] = []; for (const path of state.breaksContinues) { const { node } = path; const { type, label } = node; let name = type === "BreakStatement" ? "break" : "continue"; - if (label) name += "|" + label.name; - path.replaceWith(t.returnStatement(t.stringLiteral(name))); + if (label) name += " " + label.name; + + let i = injected.indexOf(name); + const hasInjected = i !== -1; + if (!hasInjected) { + injected.push(name); + i = injected.length - 1; + } + + path.replaceWith( + t.addComment( + t.returnStatement(t.numericLiteral(i)), + "trailing", + " " + name, + true, + ), + ); if (updaterNode) path.insertBefore(t.cloneNode(updaterNode)); - if (injected.has(name)) continue; - injected.add(name); + if (hasInjected) continue; bodyStmts.push( template.statement.ast` - if ( - ${t.identifier(completionId)} === ${t.stringLiteral(name)} - ) ${node} + if (${t.identifier(completionId)} === ${t.numericLiteral(i)}) ${node} `, ); } - if (state.returns.length) { + + if (returnNum) { for (const path of state.returns) { const arg = path.node.argument || path.scope.buildUndefinedNode(); path.replaceWith( @@ -304,9 +351,10 @@ export function wrapLoopBody( bodyStmts.push( template.statement.ast` - if (typeof ${t.identifier(completionId)} === "object") - return ${t.identifier(completionId)}.v; - `, + if (${t.identifier(completionId)}) return ${t.identifier( + completionId, + )}.v; + `, ); } } diff --git a/packages/babel-plugin-transform-block-scoping/test/fixtures/general/block-inside-switch-inside-loop/output.js b/packages/babel-plugin-transform-block-scoping/test/fixtures/general/block-inside-switch-inside-loop/output.js index 6aebc4bb8a8e..a79ae09809f3 100644 --- a/packages/babel-plugin-transform-block-scoping/test/fixtures/general/block-inside-switch-inside-loop/output.js +++ b/packages/babel-plugin-transform-block-scoping/test/fixtures/general/block-inside-switch-inside-loop/output.js @@ -20,7 +20,7 @@ var j = 0; var _loop2 = function () { switch (i) { case 0: - return "continue"; + return 1; // continue } j++; var z = 3; @@ -29,37 +29,35 @@ var _loop2 = function () { }); }; for (i = 0; i < 10; i++) { - var _ret = _loop2(); - if (_ret === "continue") continue; + if (_loop2()) continue; } expect(j).toBe(9); // it should work with loops nested within switch j = 0; var _loop3 = function () { - switch (i) { - case 0: - var _loop4 = function () { - var z = 3; - (function () { - return z; - }); - j++; - return "break"; - }; - for (k = 0; k < 10; k++) { - var _ret2 = _loop4(); - if (_ret2 === "break") break; - } - break; - } - var z = 3; - (function () { - return z; - }); -}; + switch (i) { + case 0: + var _loop4 = function () { + var z = 3; + (function () { + return z; + }); + j++; + return 1; // break + }; + for (k = 0; k < 10; k++) { + if (_loop4()) break; + } + break; + } + var z = 3; + (function () { + return z; + }); + }, + k; for (i = 0; i < 10; i++) { - var k; _loop3(); } expect(j).toBe(1); diff --git a/packages/babel-plugin-transform-block-scoping/test/fixtures/general/closure-in-generator-or-async/output.js b/packages/babel-plugin-transform-block-scoping/test/fixtures/general/closure-in-generator-or-async/output.js index 38820e647c6f..c254921a6721 100644 --- a/packages/babel-plugin-transform-block-scoping/test/fixtures/general/closure-in-generator-or-async/output.js +++ b/packages/babel-plugin-transform-block-scoping/test/fixtures/general/closure-in-generator-or-async/output.js @@ -1,38 +1,38 @@ function* a() { var _loop = function* () { - var x = yield "iteration"; - fn = function () { - return x; - }; - }; + var x = yield "iteration"; + fn = function () { + return x; + }; + }, + fn; do { - var fn; yield* _loop(); } while (false); return fn; } async function b() { var _loop2 = async function () { - var x = await "iteration"; - fn = function () { - return x; - }; - }; + var x = await "iteration"; + fn = function () { + return x; + }; + }, + fn; do { - var fn; await _loop2(); } while (false); return fn; } async function* c() { var _loop3 = async function* () { - var x = yield "iteration"; - fn = function () { - return x; - }; - }; + var x = yield "iteration"; + fn = function () { + return x; + }; + }, + fn; do { - var fn; yield* _loop3(); } while (false); return fn; diff --git a/packages/babel-plugin-transform-block-scoping/test/fixtures/general/for-break-continue-closure/output.js b/packages/babel-plugin-transform-block-scoping/test/fixtures/general/for-break-continue-closure/output.js index 4c201717d9f3..b40e2e2a4f93 100644 --- a/packages/babel-plugin-transform-block-scoping/test/fixtures/general/for-break-continue-closure/output.js +++ b/packages/babel-plugin-transform-block-scoping/test/fixtures/general/for-break-continue-closure/output.js @@ -7,7 +7,7 @@ var _loop = function () { return b; }); if (true) break; - return "continue"; + return 1; // continue } case false: { @@ -16,6 +16,5 @@ var _loop = function () { } }; for (var a of [1]) { - var _ret = _loop(); - if (_ret === "continue") continue; + if (_loop()) continue; } diff --git a/packages/babel-plugin-transform-block-scoping/test/fixtures/general/for-break-continue-return/output.js b/packages/babel-plugin-transform-block-scoping/test/fixtures/general/for-break-continue-return/output.js index 5346bb81f0b0..5ddf73940134 100644 --- a/packages/babel-plugin-transform-block-scoping/test/fixtures/general/for-break-continue-return/output.js +++ b/packages/babel-plugin-transform-block-scoping/test/fixtures/general/for-break-continue-return/output.js @@ -1,22 +1,23 @@ (function () { var _loop = function (i) { - fns.push(function () { - return i; - }); - if (i === 1) { - return "continue"; - } else if (i === 2) { - return "break"; - } else if (i === 3) { - return { - v: i - }; - } - }; + fns.push(function () { + return i; + }); + if (i === 1) { + return 0; // continue + } else if (i === 2) { + return 1; // break + } else if (i === 3) { + return { + v: i + }; + } + }, + _ret; for (var i in nums) { - var _ret = _loop(i); - if (_ret === "continue") continue; - if (_ret === "break") break; - if (typeof _ret === "object") return _ret.v; + _ret = _loop(i); + if (_ret === 0) continue; + if (_ret === 1) break; + if (_ret) return _ret.v; } })(); diff --git a/packages/babel-plugin-transform-block-scoping/test/fixtures/general/for-break/output.js b/packages/babel-plugin-transform-block-scoping/test/fixtures/general/for-break/output.js index f56ed8ecc53b..e915606befda 100644 --- a/packages/babel-plugin-transform-block-scoping/test/fixtures/general/for-break/output.js +++ b/packages/babel-plugin-transform-block-scoping/test/fixtures/general/for-break/output.js @@ -2,9 +2,8 @@ var _loop = function (i) { fns.push(function () { return i; }); - return "break"; + return 1; // break }; for (var i in nums) { - var _ret = _loop(i); - if (_ret === "break") break; + if (_loop(i)) break; } diff --git a/packages/babel-plugin-transform-block-scoping/test/fixtures/general/for-continue/output.js b/packages/babel-plugin-transform-block-scoping/test/fixtures/general/for-continue/output.js index 951ee239e3d0..ce828c5dc878 100644 --- a/packages/babel-plugin-transform-block-scoping/test/fixtures/general/for-continue/output.js +++ b/packages/babel-plugin-transform-block-scoping/test/fixtures/general/for-continue/output.js @@ -2,9 +2,8 @@ var _loop = function (i) { fns.push(function () { return i; }); - return "continue"; + return 1; // continue }; for (var i in nums) { - var _ret = _loop(i); - if (_ret === "continue") continue; + if (_loop(i)) continue; } diff --git a/packages/babel-plugin-transform-block-scoping/test/fixtures/general/for-return-undefined/output.js b/packages/babel-plugin-transform-block-scoping/test/fixtures/general/for-return-undefined/output.js index 696a057f2d63..6b79e1925fe5 100644 --- a/packages/babel-plugin-transform-block-scoping/test/fixtures/general/for-return-undefined/output.js +++ b/packages/babel-plugin-transform-block-scoping/test/fixtures/general/for-return-undefined/output.js @@ -1,14 +1,15 @@ (function () { var _loop = function (i) { - fns.push(function () { - return i; - }); - return { - v: void 0 - }; - }; + fns.push(function () { + return i; + }); + return { + v: void 0 + }; + }, + _ret; for (var i in nums) { - var _ret = _loop(i); - if (typeof _ret === "object") return _ret.v; + _ret = _loop(i); + if (_ret) return _ret.v; } })(); diff --git a/packages/babel-plugin-transform-block-scoping/test/fixtures/general/for-return/output.js b/packages/babel-plugin-transform-block-scoping/test/fixtures/general/for-return/output.js index 444319e058af..25523d7caee7 100644 --- a/packages/babel-plugin-transform-block-scoping/test/fixtures/general/for-return/output.js +++ b/packages/babel-plugin-transform-block-scoping/test/fixtures/general/for-return/output.js @@ -1,14 +1,15 @@ (function () { var _loop = function (i) { - fns.push(function () { - return i; - }); - return { - v: i - }; - }; + fns.push(function () { + return i; + }); + return { + v: i + }; + }, + _ret; for (var i in nums) { - var _ret = _loop(i); - if (typeof _ret === "object") return _ret.v; + _ret = _loop(i); + if (_ret) return _ret.v; } })(); diff --git a/packages/babel-plugin-transform-block-scoping/test/fixtures/general/hoisting/output.js b/packages/babel-plugin-transform-block-scoping/test/fixtures/general/hoisting/output.js index 389258c3f917..5756895ddd6f 100644 --- a/packages/babel-plugin-transform-block-scoping/test/fixtures/general/hoisting/output.js +++ b/packages/babel-plugin-transform-block-scoping/test/fixtures/general/hoisting/output.js @@ -1,20 +1,21 @@ var _loop = function (i) { - x = 5; - ({ - f - } = { - f: 2 - }); - fns.push(function () { - return i * x; - }); -}; + x = 5; + ({ + f + } = { + f: 2 + }); + fns.push(function () { + return i * x; + }); + }, + x, + f; var _iterator = babelHelpers.createForOfIteratorHelper(nums), _step; try { for (_iterator.s(); !(_step = _iterator.n()).done;) { var i = _step.value; - var x, f; _loop(i); } } catch (err) { diff --git a/packages/babel-plugin-transform-block-scoping/test/fixtures/general/issue-1051/output.js b/packages/babel-plugin-transform-block-scoping/test/fixtures/general/issue-1051/output.js index 88b179fe5a75..0d99cb0e69f6 100644 --- a/packages/babel-plugin-transform-block-scoping/test/fixtures/general/issue-1051/output.js +++ b/packages/babel-plugin-transform-block-scoping/test/fixtures/general/issue-1051/output.js @@ -7,12 +7,11 @@ foo.func1 = function () { func4(function () { func2(); }); - return "break"; + return 1; // break } }; for (;;) { - var _ret = _loop(); - if (_ret === "break") break; + if (_loop()) break; } } }; diff --git a/packages/babel-plugin-transform-block-scoping/test/fixtures/general/label-complex/input.js b/packages/babel-plugin-transform-block-scoping/test/fixtures/general/label-complex/input.js new file mode 100644 index 000000000000..84b09ba7deba --- /dev/null +++ b/packages/babel-plugin-transform-block-scoping/test/fixtures/general/label-complex/input.js @@ -0,0 +1,13 @@ +outer: while (t) { + inner: while (t2) { + for (let i = 0; i < 3; i++) { + later(() => i); + if (test1) break outer; + else if (test2) break inner; + else if (test3) continue outer; + else if (test4) continue inner; + else if (test5) break; + else if (test6) continue; + } + } +} diff --git a/packages/babel-plugin-transform-block-scoping/test/fixtures/general/label-complex/output.js b/packages/babel-plugin-transform-block-scoping/test/fixtures/general/label-complex/output.js new file mode 100644 index 000000000000..730a215776a5 --- /dev/null +++ b/packages/babel-plugin-transform-block-scoping/test/fixtures/general/label-complex/output.js @@ -0,0 +1,25 @@ +outer: while (t) { + inner: while (t2) { + var _loop = function (i) { + later(function () { + return i; + }); + if (test1) return 0; // break outer + else if (test2) return 1; // break inner + else if (test3) return 2; // continue outer + else if (test4) return 3; // continue inner + else if (test5) return 4; // break + else if (test6) return 5; // continue + }, + _ret; + for (var i = 0; i < 3; i++) { + _ret = _loop(i); + if (_ret === 0) break outer; + if (_ret === 1) break inner; + if (_ret === 2) continue outer; + if (_ret === 3) continue inner; + if (_ret === 4) break; + if (_ret === 5) continue; + } + } +} diff --git a/packages/babel-plugin-transform-block-scoping/test/fixtures/general/label/output.js b/packages/babel-plugin-transform-block-scoping/test/fixtures/general/label/output.js index 98f0a12bc6cd..a7684a5ed367 100644 --- a/packages/babel-plugin-transform-block-scoping/test/fixtures/general/label/output.js +++ b/packages/babel-plugin-transform-block-scoping/test/fixtures/general/label/output.js @@ -5,10 +5,9 @@ var _loop = function () { }); switch (true) { case true: - return "break|loop"; + return 1; // break loop } }; loop: for (var i = 0; i < 10; i++) { - var _ret = _loop(); - if (_ret === "break|loop") break loop; + if (_loop()) break loop; } diff --git a/packages/babel-plugin-transform-block-scoping/test/fixtures/general/superswitch/output.js b/packages/babel-plugin-transform-block-scoping/test/fixtures/general/superswitch/output.js index 6cd4d3beb30f..8868488deed7 100644 --- a/packages/babel-plugin-transform-block-scoping/test/fixtures/general/superswitch/output.js +++ b/packages/babel-plugin-transform-block-scoping/test/fixtures/general/superswitch/output.js @@ -1,24 +1,25 @@ function foo() { var _loop = function () { - switch (2) { - case 0: - { - if (true) { - return { - v: void 0 - }; + switch (2) { + case 0: + { + if (true) { + return { + v: void 0 + }; + } + var stuff = new Map(); + var data = 0; + stuff.forEach(function () { + var d = data; + }); + break; } - var stuff = new Map(); - var data = 0; - stuff.forEach(function () { - var d = data; - }); - break; - } - } - }; + } + }, + _ret; while (true) { - var _ret = _loop(); - if (typeof _ret === "object") return _ret.v; + _ret = _loop(); + if (_ret) return _ret.v; } } diff --git a/packages/babel-plugin-transform-block-scoping/test/fixtures/general/switch-inside-loop/output.js b/packages/babel-plugin-transform-block-scoping/test/fixtures/general/switch-inside-loop/output.js index 6aebc4bb8a8e..a79ae09809f3 100644 --- a/packages/babel-plugin-transform-block-scoping/test/fixtures/general/switch-inside-loop/output.js +++ b/packages/babel-plugin-transform-block-scoping/test/fixtures/general/switch-inside-loop/output.js @@ -20,7 +20,7 @@ var j = 0; var _loop2 = function () { switch (i) { case 0: - return "continue"; + return 1; // continue } j++; var z = 3; @@ -29,37 +29,35 @@ var _loop2 = function () { }); }; for (i = 0; i < 10; i++) { - var _ret = _loop2(); - if (_ret === "continue") continue; + if (_loop2()) continue; } expect(j).toBe(9); // it should work with loops nested within switch j = 0; var _loop3 = function () { - switch (i) { - case 0: - var _loop4 = function () { - var z = 3; - (function () { - return z; - }); - j++; - return "break"; - }; - for (k = 0; k < 10; k++) { - var _ret2 = _loop4(); - if (_ret2 === "break") break; - } - break; - } - var z = 3; - (function () { - return z; - }); -}; + switch (i) { + case 0: + var _loop4 = function () { + var z = 3; + (function () { + return z; + }); + j++; + return 1; // break + }; + for (k = 0; k < 10; k++) { + if (_loop4()) break; + } + break; + } + var z = 3; + (function () { + return z; + }); + }, + k; for (i = 0; i < 10; i++) { - var k; _loop3(); } expect(j).toBe(1); diff --git a/packages/babel-plugin-transform-block-scoping/test/fixtures/general/wrap-closure-shadow-variables-reassignment/output.js b/packages/babel-plugin-transform-block-scoping/test/fixtures/general/wrap-closure-shadow-variables-reassignment/output.js index efd8a2d1a085..1c34692fe697 100644 --- a/packages/babel-plugin-transform-block-scoping/test/fixtures/general/wrap-closure-shadow-variables-reassignment/output.js +++ b/packages/babel-plugin-transform-block-scoping/test/fixtures/general/wrap-closure-shadow-variables-reassignment/output.js @@ -2,7 +2,7 @@ var _loop = function (_index) { if (_index % 2) { _index += 3; index = _index; - return "continue"; + return 1; // continue } var fn = function () { _index; @@ -10,6 +10,5 @@ var _loop = function (_index) { index = _index; }; for (var index = 0; index < 10; index++) { - var _ret = _loop(index); - if (_ret === "continue") continue; + if (_loop(index)) continue; } diff --git a/packages/babel-plugin-transform-parameters/test/fixtures/regression/regression-2364/output.js b/packages/babel-plugin-transform-parameters/test/fixtures/regression/regression-2364/output.js index ed21d7382e33..7389d619c70c 100644 --- a/packages/babel-plugin-transform-parameters/test/fixtures/regression/regression-2364/output.js +++ b/packages/babel-plugin-transform-parameters/test/fixtures/regression/regression-2364/output.js @@ -2,16 +2,17 @@ function wrapper(fn) { return function () { var _arguments = arguments; var _loop = function () { - var val = fn(..._arguments); - return { - v: val.test(function () { - console.log(val); - }) - }; - }; + var val = fn(..._arguments); + return { + v: val.test(function () { + console.log(val); + }) + }; + }, + _ret; while (someCondition) { - var _ret = _loop(); - if (typeof _ret === "object") return _ret.v; + _ret = _loop(); + if (_ret) return _ret.v; } }; } diff --git a/packages/babel-plugin-transform-regenerator/test/fixtures/integration/destructuring/input.js b/packages/babel-plugin-transform-regenerator/test/fixtures/integration/destructuring/input.js new file mode 100644 index 000000000000..47138063fbc9 --- /dev/null +++ b/packages/babel-plugin-transform-regenerator/test/fixtures/integration/destructuring/input.js @@ -0,0 +1,57 @@ +function* foo() { + var { bar } = { bar: "bar" }; + return bar; +} + +expect(foo().next().value).toBe("bar");; + +function* foo2({ bar = 0 }) { + return bar; +} + +expect(foo2({ bar: undefined }).next().value).toBe(0); +expect(foo2({ bar: 3 }).next().value).toBe(3); + +function* foo3() { + loop: + while(true) { + // Changing "let" to "var" makes the tests pass. + let { what, value } = yield "iteration"; + + switch(what) { + case "one": + // Removing these 5 lines makes the tests pass. + if(value === 1) { + break loop; + } else if(value === 2) { + break loop; + } + break; + case "two": + // Removing these 3 lines makes the tests pass. + ["a", "b"].map(function(v) { + return value + v; + }); + + break loop; + break; + case "three": + break loop; + break; + } + } +} + +var gen3 = foo3(); + +expect(gen3.next().value).toBe("iteration"); +expect(gen3.next({what: "one", value: 3}).done).toBe(false); +expect(gen3.next({what: "one", value: 2}).done).toBe(true); + +var gen4 = foo3(); +expect(gen4.next().value).toBe("iteration"); +expect(gen4.next({what: "two", value: "sometext"}).done).toBe(true); + +var gen5 = foo3(); +expect(gen5.next().value).toBe("iteration"); +expect(gen5.next({what: "three"}).done).toBe(true); diff --git a/packages/babel-plugin-transform-regenerator/test/fixtures/integration/destructuring/output.js b/packages/babel-plugin-transform-regenerator/test/fixtures/integration/destructuring/output.js new file mode 100644 index 000000000000..da91fa6add2e --- /dev/null +++ b/packages/babel-plugin-transform-regenerator/test/fixtures/integration/destructuring/output.js @@ -0,0 +1,130 @@ +var _marked = /*#__PURE__*/babelHelpers.regeneratorRuntime().mark(foo), + _marked2 = /*#__PURE__*/babelHelpers.regeneratorRuntime().mark(foo3); +function foo() { + var _bar, bar; + return babelHelpers.regeneratorRuntime().wrap(function foo$(_context) { + while (1) switch (_context.prev = _context.next) { + case 0: + _bar = { + bar: "bar" + }, bar = _bar.bar; + return _context.abrupt("return", bar); + case 2: + case "end": + return _context.stop(); + } + }, _marked); +} +expect(foo().next().value).toBe("bar"); +; +function foo2(_ref) { + var _ref$bar = _ref.bar, + bar = _ref$bar === void 0 ? 0 : _ref$bar; + return /*#__PURE__*/babelHelpers.regeneratorRuntime().mark(function _callee() { + return babelHelpers.regeneratorRuntime().wrap(function _callee$(_context2) { + while (1) switch (_context2.prev = _context2.next) { + case 0: + return _context2.abrupt("return", bar); + case 1: + case "end": + return _context2.stop(); + } + }, _callee); + })(); +} +expect(foo2({ + bar: undefined +}).next().value).toBe(0); +expect(foo2({ + bar: 3 +}).next().value).toBe(3); +function foo3() { + var _loop, _ret; + return babelHelpers.regeneratorRuntime().wrap(function foo3$(_context4) { + while (1) switch (_context4.prev = _context4.next) { + case 0: + _loop = /*#__PURE__*/babelHelpers.regeneratorRuntime().mark(function _callee2() { + var _yield$iteration, what, value; + return babelHelpers.regeneratorRuntime().wrap(function _callee2$(_context3) { + while (1) switch (_context3.prev = _context3.next) { + case 0: + _context3.next = 2; + return "iteration"; + case 2: + _yield$iteration = _context3.sent; + what = _yield$iteration.what; + value = _yield$iteration.value; + _context3.t0 = what; + _context3.next = _context3.t0 === "one" ? 8 : _context3.t0 === "two" ? 15 : _context3.t0 === "three" ? 18 : 20; + break; + case 8: + if (!(value === 1)) { + _context3.next = 12; + break; + } + return _context3.abrupt("return", 0); + case 12: + if (!(value === 2)) { + _context3.next = 14; + break; + } + return _context3.abrupt("return", 0); + case 14: + return _context3.abrupt("break", 20); + case 15: + // Removing these 3 lines makes the tests pass. + ["a", "b"].map(function (v) { + return value + v; + }); + return _context3.abrupt("return", 0); + case 18: + return _context3.abrupt("return", 0); + case 20: + case "end": + return _context3.stop(); + } + }, _callee2); + }); + case 1: + if (!true) { + _context4.next = 8; + break; + } + return _context4.delegateYield(_loop(), "t0", 3); + case 3: + _ret = _context4.t0; + if (!(_ret === 0)) { + _context4.next = 6; + break; + } + return _context4.abrupt("break", 8); + case 6: + _context4.next = 1; + break; + case 8: + case "end": + return _context4.stop(); + } + }, _marked2); +} +var gen3 = foo3(); +expect(gen3.next().value).toBe("iteration"); +expect(gen3.next({ + what: "one", + value: 3 +}).done).toBe(false); +expect(gen3.next({ + what: "one", + value: 2 +}).done).toBe(true); +var gen4 = foo3(); +expect(gen4.next().value).toBe("iteration"); +expect(gen4.next({ + what: "two", + value: "sometext" +}).done).toBe(true); +var gen5 = foo3(); +expect(gen5.next().value).toBe("iteration"); +expect(gen5.next({ + what: "three" +}).done).toBe(true);