index.js 1.4 KB

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