From 396e665f999e51af366e9ee60721695f351f04ae Mon Sep 17 00:00:00 2001 From: Zacqary Xeper Date: Tue, 17 Jul 2018 12:31:51 -0500 Subject: [PATCH] Add asyncToGenerator to babel polyfills --- Libraries/polyfills/babelHelpers.js | 32 +++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/Libraries/polyfills/babelHelpers.js b/Libraries/polyfills/babelHelpers.js index f831deaa842fac..c5aba99bf20111 100644 --- a/Libraries/polyfills/babelHelpers.js +++ b/Libraries/polyfills/babelHelpers.js @@ -604,3 +604,35 @@ function _iterableToArray(iter) { } babelHelpers.iterableToArray = _iterableToArray; + +function _asyncToGenerator(fn) { + return function () { + var gen = fn.apply(this, arguments); + return new Promise(function (resolve, reject) { + function step(key, arg) { + try { + var info = gen[key](arg); + var value = info.value; + } catch (error) { + reject(error); + return; + } + + if (info.done) { + resolve(value); + } else { + return Promise.resolve(value).then(function (value) { + step("next", value); + }, function (err) { + step("throw", err); + }); + } + } + + return step("next"); + }); + }; +}; + + +babelHelpers.asyncToGenerator = _asyncToGenerator;