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

Returned async fat-arrow function with argument destructuring gets the parent function's arguments #5485

Closed
jetpacmonkey opened this issue Mar 16, 2017 · 4 comments
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@jetpacmonkey
Copy link

It seems like something's going wrong with a combination of canonical arguments, argument destructuring, and async-to-generator.

Input Code

// This one calls the inner function with the outer function's arguments
function breaks(fn) {
  return async (...args) => {
    return fn(...args);
  };
}

// This passes the arguments along as expected
function works(fn) {
  return async (...args) => {
    const dummy = args;
    return fn(...args);
  };
}

REPL link

Babel Configuration (.babelrc, package.json, cli command)

{
  "presets": ["es2015", "stage-2"]
}

Expected Behavior

Both calls should log { data: "_str_" } to the console

Current Behavior

The first one, which doesn't access args, is logging

{
  "data": `_function (a) {
  return { data: \'_\' + a + \'_\' };
}_`
}

Possible Solution

It seems like something in async-to-generator is conflicting with... something else. Sorry, I'm not very familiar with babel's internals.

Context

I was trying to write a wrapper function, which would work regardless of whether the inner function returned a promise or not. I noticed the inner function was getting the wrong arguments, so I added a console.log(args) in there to try and debug, and... all of the sudden everything worked as expected.

Your Environment

Reproduced in the REPL, so I'm not sure how relevant this is, but here you go...

software version
Babel 6.22.0
node 7.7.1
npm 4.1.2
Operating System macOS 10.12.3
@babel-bot
Copy link
Collaborator

Hey @jetpacmonkey! We really appreciate you taking the time to report an issue. The collaborators
on this project attempt to help as many people as possible, but we're a limited number of volunteers,
so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
community that typically always has someone willing to help. You can sign-up here
for an invite.

@existentialism
Copy link
Member

existentialism commented Mar 16, 2017

Thanks for the issue @jetpacmonkey!

We're actively tracking this issue in #4219 (and all the linked issues, including #5330 are related).

We will try to get it addressed as soon as possible, but welcome any help!

@jetpacmonkey
Copy link
Author

Whoops, thanks! I blame Github's weak issue search for my oversight 😏

@hzoo
Copy link
Member

hzoo commented Mar 16, 2017

All good, we really should of fixed this earlier 😄

@hzoo hzoo closed this as completed Mar 16, 2017
@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label May 5, 2018
@lock lock bot locked as resolved and limited conversation to collaborators May 5, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

No branches or pull requests

4 participants