esdown icon indicating copy to clipboard operation
esdown copied to clipboard

Parameter errors in generators should throw

Open zenparsing opened this issue 10 years ago • 2 comments

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.

zenparsing avatar Mar 09 '15 03:03 zenparsing

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

hax avatar May 07 '15 09:05 hax

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

zenparsing avatar May 07 '15 12:05 zenparsing