add optional asyncToGenerator transformer - closes #321

This commit is contained in:
Sebastian McKenzie
2015-01-02 01:31:14 +11:00
parent 40f8bc0a65
commit 925b1f7600
9 changed files with 119 additions and 5 deletions

View File

@@ -0,0 +1,3 @@
var foo = async function () {
var wat = await bar();
};

View File

@@ -0,0 +1,42 @@
"use strict";
var _asyncToGenerator = function (fn) {
return function () {
var gen = fn.apply(this, arguments);
return new Promise(function (resolve, reject) {
function step(getNext) {
var next;
try {
next = getNext();
} catch (e) {
reject(e);
return;
}
if (next.done) {
resolve(next.value);
return;
}
Promise.resolve(next.value).then(function (v) {
step(function () {
return gen.next(v);
});
}, function (e) {
step(function () {
return gen["throw"](e);
});
});
}
step(function () {
return gen.next();
});
});
};
};
var foo = _asyncToGenerator(function* () {
var wat = yield bar();
});

View File

@@ -0,0 +1,3 @@
{
"optional": ["asyncToGenerator"]
}