This commit introduces 4 changes:
1) Function declarations are wrapped using function declarations.
This has two advantages:
- We can rely on native hoisting, instead of using _blockHoist
- The function isn't wrapped until it is called. This avoids
problems where `regeneratorRuntime.wrap` was called before
that `babel-polyfill` was imported.
Example:
function fn() {}
// becomes
function fn() { return _fn.apply(this, arguments); }
function _fn() {
_fn = _wrapper(/* Original function ... */);
return _fn.apply(this, arguments);
}
2) Use a single template for both named and anonymous function
expressions. They already had the same behavior, but the one
used for named functions was a bit longer.
3) Use normal functions instead of arrow functions to wrap
function expressions.
4) Generate a name based on the original one for wrapped
functions (e.g. `foo` becomes `_foo` instead of `_ref`).
34 lines
893 B
JavaScript
34 lines
893 B
JavaScript
function f() {
|
|
return _f.apply(this, arguments);
|
|
}
|
|
|
|
function _f() {
|
|
_f = babelHelpers.asyncToGenerator(function* () {
|
|
var _iteratorNormalCompletion = true;
|
|
var _didIteratorError = false;
|
|
|
|
var _iteratorError;
|
|
|
|
try {
|
|
for (var _iterator = babelHelpers.asyncIterator(y), _step, _value; _step = yield _iterator.next(), _iteratorNormalCompletion = _step.done, _value = yield _step.value, !_iteratorNormalCompletion; _iteratorNormalCompletion = true) {
|
|
let x = _value;
|
|
g(x);
|
|
}
|
|
} catch (err) {
|
|
_didIteratorError = true;
|
|
_iteratorError = err;
|
|
} finally {
|
|
try {
|
|
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
yield _iterator.return();
|
|
}
|
|
} finally {
|
|
if (_didIteratorError) {
|
|
throw _iteratorError;
|
|
}
|
|
}
|
|
}
|
|
});
|
|
return _f.apply(this, arguments);
|
|
}
|