esdown
esdown copied to clipboard
Parameter errors in generators should throw
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.
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 Ah, that's a different translation bug (#21). Thanks for the report!