proposal-do-expressions
proposal-do-expressions copied to clipboard
Block-Like vs IIFE-Like
Basically this issue is about whether to treat do-expressions as block like therefore allowing control flow or whether they should behave like IIFE's and disallow control flow that affects anything outside the do-block.
Note: For the IIFE-like form I don't propose requiring return instead of completion values, I'd propose for that form that instead of implicit return undefined like in regular functions there'd be an implicit return <<CompletionValue>>
Something that'd be nice to see is examples and advantages of both types.
In favor of IIFE-like I see extensibility for async (and/or generator) variants (see here and here).
It also has the advantage that there's no difference if moving the do ... into a function.
e.g. These would always do the same thing irrespective of context:
const x = do {
...
}
const f = _ => do {
...
}
const x = f()
In favor of Block-like I can see how early interruption in case of certain conditions (e.g. trivial cases) could be used. But I don't see cases where it wouldn't be trivial to move those cases before the do-block so some motivating examples for control flow in do-expressions would be nice.
I prefer block-like behavior, but I wouldn't mind additional syntax for IIFE behavior
👍 for block-behavior. I'd expect yields inside a do expression in a generator to work:
function *gen() {
return do {
yield x;
};
}
Any further discussion on this?
I much prefer the ability to do early returns with IIFE behavior.
Recent discussion at #34