babel-core
Version:
Turn ES6 code into readable vanilla ES5 with source maps
40 lines (31 loc) • 993 B
JavaScript
;
var _interopRequire = function (obj) { return obj && obj.__esModule ? obj["default"] : obj; };
var t = _interopRequire(require("../../types"));
var visitor = {
enter: function enter(node) {
if (t.isFunction(node)) this.skip();
if (t.isAwaitExpression(node)) {
node.type = "YieldExpression";
if (node.all) {
// await* foo; -> yield Promise.all(foo);
node.all = false;
node.argument = t.callExpression(t.memberExpression(t.identifier("Promise"), t.identifier("all")), [node.argument]);
}
}
}
};
module.exports = function (node, callId, scope) {
node.async = false;
node.generator = true;
scope.traverse(node, visitor);
var call = t.callExpression(callId, [node]);
var id = node.id;
node.id = null;
if (t.isFunctionDeclaration(node)) {
var declar = t.variableDeclaration("let", [t.variableDeclarator(id, call)]);
declar._blockHoist = true;
return declar;
} else {
return call;
}
};