Created by: fson
Remove transform-async-to-generator
, which to my understanding is meant
to be used in environments that support generators natively.
Because we're compiling generators to ES5 anyway, we can simply use
regenerator
to transform async functions too, which results in
slightly simpler output and only uses the regenerator runtime instead
regenerator runtime + _asyncToGenerator Babel helper.
Tested with the example code from #327.
Output (without minification) before:
{
key: 'componentDidMount',
value: function () {
var _ref = _asyncToGenerator(_regenerator2.default.mark(function _callee() {
return _regenerator2.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.prev = 0;
_context.next = 3;
return fetch('http://google.com');
case 3:
_context.next = 8;
break;
case 5:
_context.prev = 5;
_context.t0 = _context['catch'](0);
console.log('oh noes');
case 8:
case 'end':
return _context.stop();
}
}
}, _callee, this, [[0, 5]]);
}));
function componentDidMount() {
return _ref.apply(this, arguments);
}
return componentDidMount;
}()
}
After the change:
{
key: 'componentDidMount',
value: function componentDidMount() {
return _regenerator2.default.async(function componentDidMount$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.prev = 0;
_context.next = 3;
return _regenerator2.default.awrap(fetch('http://google.com'));
case 3:
_context.next = 8;
break;
case 5:
_context.prev = 5;
_context.t0 = _context['catch'](0);
console.log('oh noes');
case 8:
case 'end':
return _context.stop();
}
}
}, null, this, [[0, 5]]);
}
}