Extract for-of iterator handling to a helper (#11262)

* Extract for-of iterator handling to a helper

Dis greatly recudes the code size when for-of is used multiple times across the
codebase. Also, makes it easier to read what's happening in a compiled loop.

* Unify spec and loose code

* Legacy implementation fallback

* Update tmp var name

* Updates from review and after rebase
This commit is contained in:
Nicolò Ribaudo
2020-03-17 00:45:34 +01:00
committed by GitHub
parent a11855e586
commit 59976680df
51 changed files with 624 additions and 576 deletions

View File

@@ -1,3 +1,6 @@
{
"plugins": ["transform-for-of", ["transform-runtime", { "corejs": 3 }]]
"plugins": [
"transform-for-of",
["transform-runtime", { "corejs": 3, "version": "7.100.0" }]
]
}

View File

@@ -1,24 +1,14 @@
var _getIterator = require("@babel/runtime-corejs3/core-js/get-iterator");
var _createForOfIteratorHelper = require("@babel/runtime-corejs3/helpers/createForOfIteratorHelper");
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
var _iterator = _createForOfIteratorHelper(arr),
_step;
try {
for (var _iterator = _getIterator(arr), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var i = _step.value;
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
_iterator.e(err);
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
_iterator.f();
}