_ref mismatch
devMYC opened this issue · 1 comments
devMYC commented
Test code :
import { log } from 'console'
const generator = function* () {
let index = 0
const fn = () =>
new Promise((resolve, reject) =>
index % 2 === 0 ? resolve(index) : reject(index)
)
while (index < 5) {
yield fn
index++
}
}
const gen = generator()
let next = gen.next()
while (!next.done) {
next
.value()
.then(res => log('> Res :', res))
.catch(err => log('> Error :', err))
next = gen.next()
}
Transpiled :
'use strict';
var _console = require('console');
var generator = regeneratorRuntime.mark(function _callee() {
var index, _ref2, _fn;
function _ref2(resolve, reject) {
return index % 2 === 0 ? resolve(index) : reject(index);
}
function _fn() {
return new Promise(_ref);
}
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_ref2 = _ref2;
index = 0;
_fn = _fn;
case 3:
if (!(index < 5)) {
_context.next = 9;
break;
}
_context.next = 6;
return _fn;
case 6:
index++;
_context.next = 3;
break;
case 9:
case 'end':
return _context.stop();
}
}
}, _callee, this);
});
var gen = generator();
var next = gen.next();
function _ref3(res) {
return (0, _console.log)('> Res :', res);
}
function _ref4(err) {
return (0, _console.log)('> Error :', err);
}
while (!next.done) {
next.value().then(_ref3).catch(_ref4);
next = gen.next();
}
//# sourceMappingURL=index.js.map
Got reference error when running the transpiled code
return new Promise(_ref);
^
ReferenceError: _ref is not defined
Had to change _ref
to _ref2
manually to fix it