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

asyncToGenerator transformer always returns function with 0 length. #1618

Closed
PinkaminaDianePie opened this Issue May 24, 2015 · 10 comments

Comments

Projects
None yet
2 participants
@PinkaminaDianePie

PinkaminaDianePie commented May 24, 2015

some frameworks (such as mocha) checks function length (parameters count), but if i used asyncToGenerator it transforms my code to

before(_asyncToGenerator(function* (done) {
}));

where result of _asyncToGenerator will be babel's helper function:

function () { var gen = fn.apply(this, arguments); 

it's length always 0.
need to transpile code to something like this:

before(function(done) {
    _asyncToGenerator(function* (done) {
    }).apply(this, arguments);
});

then will be work fine.

@kittens

This comment has been minimized.

Show comment
Hide comment
@kittens

kittens May 24, 2015

Member

There's nothing that can be done about this. You can't mock or change a functions parameter length without explicitly specifying it and since the asyncToGenerator function is dynamic it's impossible.

Member

kittens commented May 24, 2015

There's nothing that can be done about this. You can't mock or change a functions parameter length without explicitly specifying it and since the asyncToGenerator function is dynamic it's impossible.

@kittens kittens closed this May 24, 2015

@kittens kittens added the cantfix label May 24, 2015

@PinkaminaDianePie

This comment has been minimized.

Show comment
Hide comment
@PinkaminaDianePie

PinkaminaDianePie May 24, 2015

But you can wrap _asyncToGenerator with additional function with same params! At now you transpile

async function(params){}

to:

_asyncToGenerator(function* (params) {});

but you can transpile it to:

function(params) {
    _asyncToGenerator(function* (params) {}).apply(this, arguments);
}

PinkaminaDianePie commented May 24, 2015

But you can wrap _asyncToGenerator with additional function with same params! At now you transpile

async function(params){}

to:

_asyncToGenerator(function* (params) {});

but you can transpile it to:

function(params) {
    _asyncToGenerator(function* (params) {}).apply(this, arguments);
}
@kittens

This comment has been minimized.

Show comment
Hide comment
@kittens

kittens May 24, 2015

Member

Want to send a PR?

On Sun, May 24, 2015 at 1:00 PM, PinkaminaDianePie
notifications@github.com wrote:

But you can wrap _asyncToGenerator with additional function with same params! At now you transpile

async function(params){}

to:

_asyncToGenerator(function* (params) {});

but you can transpile it to:

function(params) {
    _asyncToGenerator(function* (params) {}).apply(this, arguments);
}

Reply to this email directly or view it on GitHub:
#1618 (comment)

Member

kittens commented May 24, 2015

Want to send a PR?

On Sun, May 24, 2015 at 1:00 PM, PinkaminaDianePie
notifications@github.com wrote:

But you can wrap _asyncToGenerator with additional function with same params! At now you transpile

async function(params){}

to:

_asyncToGenerator(function* (params) {});

but you can transpile it to:

function(params) {
    _asyncToGenerator(function* (params) {}).apply(this, arguments);
}

Reply to this email directly or view it on GitHub:
#1618 (comment)

@PinkaminaDianePie

This comment has been minimized.

Show comment
Hide comment
@PinkaminaDianePie

PinkaminaDianePie May 24, 2015

Sorry, i dont understand how babel works so i cant fix this issue =(

PinkaminaDianePie commented May 24, 2015

Sorry, i dont understand how babel works so i cant fix this issue =(

@PinkaminaDianePie

This comment has been minimized.

Show comment
Hide comment
@PinkaminaDianePie

PinkaminaDianePie May 29, 2015

so what about this issue? still closed with "cantfix" label? why my algorithm is wrong?

PinkaminaDianePie commented May 29, 2015

so what about this issue? still closed with "cantfix" label? why my algorithm is wrong?

@kittens

This comment has been minimized.

Show comment
Hide comment
@kittens

kittens May 29, 2015

Member

As I said, happy to accept a PR. As for the timebeing, this is expected
behaviour.

On Friday, 29 May 2015, PinkaminaDianePie notifications@github.com wrote:

so what about this issue? still closed with "cantfix" label? why my
algorithm is wrong?

Reply to this email directly or view it on GitHub
#1618 (comment).

Sebastian McKenzie

Member

kittens commented May 29, 2015

As I said, happy to accept a PR. As for the timebeing, this is expected
behaviour.

On Friday, 29 May 2015, PinkaminaDianePie notifications@github.com wrote:

so what about this issue? still closed with "cantfix" label? why my
algorithm is wrong?

Reply to this email directly or view it on GitHub
#1618 (comment).

Sebastian McKenzie

@PinkaminaDianePie

This comment has been minimized.

Show comment
Hide comment
@PinkaminaDianePie

PinkaminaDianePie May 29, 2015

if you want pr - change label to "help wanted" and reopen issue. with this "expected" behavior i cant use some libs such https://github.com/mochajs/mocha. very soon nodejs will be merged with iojs so there will be native generators + let + const, but i cant use them with this issue. i cant send you pr cause i dont know how babel works but maybe someone another can fixed it.

PinkaminaDianePie commented May 29, 2015

if you want pr - change label to "help wanted" and reopen issue. with this "expected" behavior i cant use some libs such https://github.com/mochajs/mocha. very soon nodejs will be merged with iojs so there will be native generators + let + const, but i cant use them with this issue. i cant send you pr cause i dont know how babel works but maybe someone another can fixed it.

@PinkaminaDianePie

This comment has been minimized.

Show comment
Hide comment
@PinkaminaDianePie

PinkaminaDianePie Jun 20, 2015

still waiting for fixing this >_<

PinkaminaDianePie commented Jun 20, 2015

still waiting for fixing this >_<

@kittens

This comment has been minimized.

Show comment
Hide comment
@kittens

kittens Jun 20, 2015

Member

Still waiting for a PR ;)

On Sat, Jun 20, 2015 at 1:56 PM, PinkaminaDianePie
notifications@github.com wrote:

still waiting for fixing this >_<

Reply to this email directly or view it on GitHub:
#1618 (comment)

Member

kittens commented Jun 20, 2015

Still waiting for a PR ;)

On Sat, Jun 20, 2015 at 1:56 PM, PinkaminaDianePie
notifications@github.com wrote:

still waiting for fixing this >_<

Reply to this email directly or view it on GitHub:
#1618 (comment)

@PinkaminaDianePie

This comment has been minimized.

Show comment
Hide comment
@PinkaminaDianePie

PinkaminaDianePie Jun 20, 2015

but i will not do it. i dont want to waste week of time to understand how babel works just for fix, what can be done for 5 minutes by you. i tried to understand what the crap are going on in remap-async-to-generator.js, but understands nothing. just reopen this issue with "help wanted" label if you dont want do something with bugs, maybe someone another will fix it =\

PinkaminaDianePie commented Jun 20, 2015

but i will not do it. i dont want to waste week of time to understand how babel works just for fix, what can be done for 5 minutes by you. i tried to understand what the crap are going on in remap-async-to-generator.js, but understands nothing. just reopen this issue with "help wanted" label if you dont want do something with bugs, maybe someone another will fix it =\

cb1kenobi added a commit to cb1kenobi/babel that referenced this issue Oct 29, 2015

Proper arity for asyncToGenerator calls.
asyncToGenerator() returns a function has no explicit arguments and thus it has a length of zero. This is problematic since you should be able to get the length of a async function. Regenerator works correctly.

Fixes babel#1618

@lock lock bot added the outdated label Jul 15, 2018

@lock lock bot locked as resolved and limited conversation to collaborators Jul 15, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.