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`).
67 lines
1.3 KiB
JavaScript
67 lines
1.3 KiB
JavaScript
class Test {
|
|
static method1() {
|
|
var _this = this;
|
|
|
|
return babelHelpers.asyncToGenerator(function* () {
|
|
console.log(_this);
|
|
setTimeout(
|
|
/*#__PURE__*/
|
|
babelHelpers.asyncToGenerator(function* () {
|
|
console.log(_this);
|
|
}));
|
|
})();
|
|
}
|
|
|
|
static method2() {
|
|
var _this2 = this;
|
|
|
|
return babelHelpers.asyncToGenerator(function* () {
|
|
console.log(_this2);
|
|
setTimeout(
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _ref2 = babelHelpers.asyncToGenerator(function* (arg) {
|
|
console.log(_this2);
|
|
});
|
|
|
|
return function (_x) {
|
|
return _ref2.apply(this, arguments);
|
|
};
|
|
}());
|
|
})();
|
|
}
|
|
|
|
method1() {
|
|
var _this3 = this;
|
|
|
|
return babelHelpers.asyncToGenerator(function* () {
|
|
console.log(_this3);
|
|
setTimeout(
|
|
/*#__PURE__*/
|
|
babelHelpers.asyncToGenerator(function* () {
|
|
console.log(_this3);
|
|
}));
|
|
})();
|
|
}
|
|
|
|
method2() {
|
|
var _this4 = this;
|
|
|
|
return babelHelpers.asyncToGenerator(function* () {
|
|
console.log(_this4);
|
|
setTimeout(
|
|
/*#__PURE__*/
|
|
function () {
|
|
var _ref4 = babelHelpers.asyncToGenerator(function* (arg) {
|
|
console.log(_this4);
|
|
});
|
|
|
|
return function (_x2) {
|
|
return _ref4.apply(this, arguments);
|
|
};
|
|
}());
|
|
})();
|
|
}
|
|
|
|
}
|