Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Name of async recursive function is stripped away #172

Closed
honzabrecka opened this issue Jul 31, 2019 · 3 comments · Fixed by #185
Closed

Name of async recursive function is stripped away #172

honzabrecka opened this issue Jul 31, 2019 · 3 comments · Fixed by #185
Labels
kind: bug Something isn't working scope: upstream Issue in upstream dependency topic: async-to-promises Related to bugs with babel-plugin-async-to-promises

Comments

@honzabrecka
Copy link
Contributor

honzabrecka commented Jul 31, 2019

Current Behavior

Following code:

export function pipeP(...fns: Function[]) {
  return (value: any) =>
    new Promise((resolve, reject) => {
      ;(async function run([f, ...fns], value: any) {
        try {
          if (f === undefined) resolve(value)
          else run(fns, await f(value))
        } catch (e) {
          reject(e)
        }
      })(fns, value)
    })
}

is being compiled to:

function pipeP() {
  for (var _len = arguments.length, fns = new Array(_len), _key = 0; _key < _len; _key++) {
    fns[_key] = arguments[_key];
  }

  return function (value) {
    return new Promise(function (resolve, reject) {

// function run - its name is stripped
      (function (_ref, value) {
        var f = _ref[0],
            fns = _ref.slice(1);

        try {
          return _catch(function () {
            var _temp = function () {
              if (f === undefined) resolve(value);else return Promise.resolve(f(value)).then(function (_f) {
// calling run fails, because theres's no run defined
                run(fns, _f);
              });
            }();

            if (_temp && _temp.then) return _temp.then(function () {});
          }, function (e) {
            reject(e);
          });
        } catch (e) {
          Promise.reject(e);
        }
      })(fns, value);
    });
  };
}

Fails with run is not defined - see comments above for explanation.

Expected behavior

Does not strip function's name

Your environment

Software Version(s)
TSDX 0.7.2
TypeScript 3.5.3
@honzabrecka honzabrecka changed the title Wrong compilation of async recursive function Name of async recursive function is stripped away Jul 31, 2019
@honzabrecka
Copy link
Contributor Author

Causd by babel-plugin-transform-async-to-promises babel plugin, reported here rpetrich/babel-plugin-transform-async-to-promises#37

@rpetrich
Copy link

rpetrich commented Aug 4, 2019

Should be resolved by updating to 0.8.14 of babel-plugin-transform-async-to-promises

@jaredpalmer
Copy link
Owner

@rpetrich can you submit a PR?

@agilgur5 agilgur5 added the scope: upstream Issue in upstream dependency label Mar 10, 2020
@agilgur5 agilgur5 added topic: async-to-promises Related to bugs with babel-plugin-async-to-promises kind: bug Something isn't working labels Mar 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug Something isn't working scope: upstream Issue in upstream dependency topic: async-to-promises Related to bugs with babel-plugin-async-to-promises
Projects
None yet
4 participants