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

@@ -4,6 +4,7 @@
"syntax-jsx",
"transform-react-jsx",
"transform-block-scoped-functions",
"transform-for-of"
"transform-for-of",
["external-helpers", { "helperVersion": "7.100.0" }]
]
}

View File

@@ -10,12 +10,11 @@ var _loop = function (i) {
});
};
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
var _iterator = babelHelpers.createForOfIteratorHelper(nums),
_step;
try {
for (var _iterator = nums[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var i = _step.value;
var x;
var f;
@@ -23,16 +22,7 @@ try {
_loop(i);
}
} 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();
}