Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • C create-react-app
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 1,547
    • Issues 1,547
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 417
    • Merge requests 417
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Meta
  • create-react-app
  • Merge requests
  • !332

Transform async functions with regenerator

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Administrator requested to merge github/fork/fson/syntax-async-functions into master Aug 02, 2016
  • Overview 2
  • Commits 3
  • Pipelines 0
  • Changes 3

Created by: fson

Remove transform-async-to-generator, which to my understanding is meant to be used in environments that support generators natively.

Because we're compiling generators to ES5 anyway, we can simply use regenerator to transform async functions too, which results in slightly simpler output and only uses the regenerator runtime instead regenerator runtime + _asyncToGenerator Babel helper.

Tested with the example code from #327.

Output (without minification) before:

{
  key: 'componentDidMount',
  value: function () {
    var _ref = _asyncToGenerator(_regenerator2.default.mark(function _callee() {
      return _regenerator2.default.wrap(function _callee$(_context) {
        while (1) {
          switch (_context.prev = _context.next) {
            case 0:
              _context.prev = 0;
              _context.next = 3;
              return fetch('http://google.com');

            case 3:
              _context.next = 8;
              break;

            case 5:
              _context.prev = 5;
              _context.t0 = _context['catch'](0);

              console.log('oh noes');

            case 8:
            case 'end':
              return _context.stop();
          }
        }
      }, _callee, this, [[0, 5]]);
    }));

    function componentDidMount() {
      return _ref.apply(this, arguments);
    }

    return componentDidMount;
  }()
}

After the change:

{
  key: 'componentDidMount',
  value: function componentDidMount() {
    return _regenerator2.default.async(function componentDidMount$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            _context.prev = 0;
            _context.next = 3;
            return _regenerator2.default.awrap(fetch('http://google.com'));

          case 3:
            _context.next = 8;
            break;

          case 5:
            _context.prev = 5;
            _context.t0 = _context['catch'](0);

            console.log('oh noes');

          case 8:
          case 'end':
            return _context.stop();
        }
      }
    }, null, this, [[0, 5]]);
  }
}
Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/fson/syntax-async-functions