Skip to content

Commit

Permalink
Spec compatibility for iteratorClose condition. (babel#6094)
Browse files Browse the repository at this point in the history
* for-of: IteratorClose spec compatibility.

See #3:
https://tc39.github.io/ecma262/#sec-iteratorclose

* Update spec fixtures for for-of.

* Fix IteratorClose case for remap-async-to-generator.

* Fix IteratorClose case for async-generator-function test output.

* Modify few tests according to iteratorClose fix.

* Fix iteratorClose for helpers.slicedToArray also.

* Update iteratorClose fixture for commonjs.
  • Loading branch information
yavorsky authored and hzoo committed Aug 28, 2017
1 parent 827d845 commit b2b3d79
Show file tree
Hide file tree
Showing 23 changed files with 25 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const awaitTemplate = `
ITERATOR_ERROR_KEY = err;
} finally {
try {
if (!ITERATOR_COMPLETION && ITERATOR_KEY.return) {
if (!ITERATOR_COMPLETION && ITERATOR_KEY.return != null) {
yield AWAIT(ITERATOR_KEY.return());
}
} finally {
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-helpers/src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ helpers.slicedToArray = template(`
_e = err;
} finally {
try {
if (!_n && _i["return"]) _i["return"]();
if (!_n && _i["return"] != null) _i["return"]();
} finally {
if (_d) throw _e;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ babelHelpers.asyncToGenerator(function* () {
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
if (!_iteratorNormalCompletion && _iterator.return != null) {
yield _iterator.return();
}
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ let f = (() => {
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
if (!_iteratorNormalCompletion && _iterator.return != null) {
yield _iterator.return();
}
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ let g = (() => {
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
if (!_iteratorNormalCompletion && _iterator.return != null) {
yield babelHelpers.asyncGenerator.await(_iterator.return());
}
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ let f = (() => {
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
if (!_iteratorNormalCompletion && _iterator.return != null) {
yield _iterator.return();
}
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ babelHelpers.asyncToGenerator(function* () {
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
if (!_iteratorNormalCompletion && _iterator.return != null) {
yield _iterator.return();
}
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ try {
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally {
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-plugin-transform-es2015-for-of/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ try {
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally {
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-plugin-transform-es2015-for-of/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default function({ messages, template, types: t }) {
ITERATOR_ERROR_KEY = err;
} finally {
try {
if (!ITERATOR_COMPLETION && ITERATOR_KEY.return) {
if (!ITERATOR_COMPLETION && ITERATOR_KEY.return != null) {
ITERATOR_KEY.return();
}
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function a(b) {
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ try {
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ try {
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ try {
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ try {
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ try {
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ try {
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally {
Expand All @@ -34,7 +34,7 @@ try {
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return) {
if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
_iterator2.return();
}
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ try {
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return) {
if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
_iterator2.return();
}
} finally {
Expand All @@ -34,7 +34,7 @@ try {
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ try {
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict";

var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();

var _foo = require("foo");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ function forOf() {
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ try {
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ try {
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally {
Expand Down

0 comments on commit b2b3d79

Please sign in to comment.