index.js
1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"use strict";
exports.__esModule = true;
exports.default = function (_ref) {
var t = _ref.types;
var yieldStarVisitor = {
Function: function Function(path) {
path.skip();
},
YieldExpression: function YieldExpression(_ref2, state) {
var node = _ref2.node;
if (!node.delegate) return;
var callee = state.addHelper("asyncGeneratorDelegate");
node.argument = t.callExpression(callee, [t.callExpression(state.addHelper("asyncIterator"), [node.argument]), t.memberExpression(state.addHelper("asyncGenerator"), t.identifier("await"))]);
}
};
return {
inherits: require("babel-plugin-syntax-async-generators"),
visitor: {
Function: function Function(path, state) {
if (!path.node.async || !path.node.generator) return;
path.traverse(yieldStarVisitor, state);
(0, _babelHelperRemapAsyncToGenerator2.default)(path, state.file, {
wrapAsync: t.memberExpression(state.addHelper("asyncGenerator"), t.identifier("wrap")),
wrapAwait: t.memberExpression(state.addHelper("asyncGenerator"), t.identifier("await"))
});
}
}
};
};
var _babelHelperRemapAsyncToGenerator = require("babel-helper-remap-async-to-generator");
var _babelHelperRemapAsyncToGenerator2 = _interopRequireDefault(_babelHelperRemapAsyncToGenerator);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
module.exports = exports["default"];