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

Parameter errors in generators should throw #16

Open
zenparsing opened this issue Mar 9, 2015 · 2 comments
Open

Parameter errors in generators should throw #16

zenparsing opened this issue Mar 9, 2015 · 2 comments

Comments

@zenparsing
Copy link
Owner

Errors which occur during parameter binding and evaluation should result in exceptions.

function* f(a = null.x) {}
f(); // Throws an exception

Currently, it does not because defaults are evaluated in the body of the generator.

The same applies to async generator functions.

@hax
Copy link

hax commented May 7, 2015

I think async function could just return a rejected promise. The only important thing is the timing.

function *g(a = A()) {
    console.log(11)
    yield a
    console.log(12)
}
const it = g()
console.log(10)
while (!it.next().done) {}

async function af(a = A()) {
    console.log(20)
    await Promise.resolve(a)
    console.log(22)
}
af().then(_ => console.log(23), _ => console.log(24))
console.log(21)

function A() {
    console.log('ok')
    return 'a'
}

babel output:

ok
10
11
12
ok
20
21
22
23

traceur (0.0.62) output

10
ok
11
12
ok
20
21
22
23

esdown output:

10
ok
11
12
ok
20
21
24

@zenparsing
Copy link
Owner Author

@hax Ah, that's a different translation bug (#21). Thanks for the report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants