Update @babel/helper-wrap-function templates (#6984)

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`).
This commit is contained in:
Nicolò Ribaudo
2017-12-13 16:21:58 +01:00
committed by GitHub
parent 9cc0a26694
commit 05b22d2597
45 changed files with 546 additions and 611 deletions

View File

@@ -1,13 +1,14 @@
let gen = (() => {
var _ref = _skipFirstGeneratorNext(function* () {
function _skipFirstGeneratorNext(fn) { return function () { var it = fn.apply(this, arguments); it.next(); return it; }; }
function gen() {
return _gen.apply(this, arguments);
}
function _gen() {
_gen = _skipFirstGeneratorNext(function* () {
let _functionSent = yield;
let sent = _functionSent;
});
return function gen() {
return _ref.apply(this, arguments);
};
})();
function _skipFirstGeneratorNext(fn) { return function () { var it = fn.apply(this, arguments); it.next(); return it; }; }
return _gen.apply(this, arguments);
}

View File

@@ -1,17 +1,3 @@
let foo =
/*#__PURE__*/
(() => {
var _ref = _wrapAsyncGenerator(_skipFirstGeneratorNext(function* () {
let _functionSent = yield;
_functionSent = yield _awaitAsyncGenerator(_functionSent);
}));
return function foo() {
return _ref.apply(this, arguments);
};
})();
function _skipFirstGeneratorNext(fn) { return function () { var it = fn.apply(this, arguments); it.next(); return it; }; }
function _awaitAsyncGenerator(value) { return new _AwaitValue(value); }
@@ -29,3 +15,16 @@ _AsyncGenerator.prototype.throw = function (arg) { return this._invoke("throw",
_AsyncGenerator.prototype.return = function (arg) { return this._invoke("return", arg); };
function _AwaitValue(value) { this.wrapped = value; }
function foo() {
return _foo.apply(this, arguments);
}
function _foo() {
_foo = _wrapAsyncGenerator(_skipFirstGeneratorNext(function* () {
let _functionSent = yield;
_functionSent = yield _awaitAsyncGenerator(_functionSent);
}));
return _foo.apply(this, arguments);
}

View File

@@ -1,7 +1,14 @@
function _skipFirstGeneratorNext(fn) { return function () { var it = fn.apply(this, arguments); it.next(); return it; }; }
export default _skipFirstGeneratorNext(function* () {
let _functionSent = yield;
export default function () {
return _ref.apply(this, arguments);
}
return _functionSent;
});
function _ref() {
_ref = _skipFirstGeneratorNext(function* () {
let _functionSent = yield;
return _functionSent;
});
return _ref.apply(this, arguments);
}

View File

@@ -1,15 +1,14 @@
let gen = (() => {
var _ref = _skipFirstGeneratorNext(function* () {
function _skipFirstGeneratorNext(fn) { return function () { var it = fn.apply(this, arguments); it.next(); return it; }; }
export default function gen() {
return _gen.apply(this, arguments);
}
function _gen() {
_gen = _skipFirstGeneratorNext(function* () {
let _functionSent = yield;
return _functionSent;
});
return function gen() {
return _ref.apply(this, arguments);
};
})();
function _skipFirstGeneratorNext(fn) { return function () { var it = fn.apply(this, arguments); it.next(); return it; }; }
export { gen as default };
return _gen.apply(this, arguments);
}

View File

@@ -1,13 +1,14 @@
function _skipFirstGeneratorNext(fn) { return function () { var it = fn.apply(this, arguments); it.next(); return it; }; }
export let gen = (() => {
var _ref = _skipFirstGeneratorNext(function* () {
export function gen() {
return _gen.apply(this, arguments);
}
function _gen() {
_gen = _skipFirstGeneratorNext(function* () {
let _functionSent = yield;
return _functionSent;
});
return function gen() {
return _ref.apply(this, arguments);
};
})();
return _gen.apply(this, arguments);
}

View File

@@ -1,15 +1,13 @@
function _skipFirstGeneratorNext(fn) { return function () { var it = fn.apply(this, arguments); it.next(); return it; }; }
const foo = (() => {
var _ref = _skipFirstGeneratorNext(function* () {
const foo = function () {
var _gen = _skipFirstGeneratorNext(function* () {
let _functionSent = yield;
return _functionSent;
});
function gen() {
return _ref.apply(this, arguments);
}
return gen;
})();
return function gen() {
return _gen.apply(this, arguments);
};
}();

View File

@@ -1,13 +1,14 @@
let gen = (() => {
var _ref = _skipFirstGeneratorNext(function* () {
function _skipFirstGeneratorNext(fn) { return function () { var it = fn.apply(this, arguments); it.next(); return it; }; }
function gen() {
return _gen.apply(this, arguments);
}
function _gen() {
_gen = _skipFirstGeneratorNext(function* () {
let _functionSent = yield;
return _functionSent;
});
return function gen() {
return _ref.apply(this, arguments);
};
})();
function _skipFirstGeneratorNext(fn) { return function () { var it = fn.apply(this, arguments); it.next(); return it; }; }
return _gen.apply(this, arguments);
}