tc39 / proposal-do-expressions

Proposal for `do` expressions
MIT License
1.11k stars 14 forks source link

Return in function parameter initializer #73

Closed Jack-Works closed 2 years ago

Jack-Works commented 3 years ago

Is this allowed?

function x(y = do { return true }) {}
bakkot commented 3 years ago

See the readme:

return is allowed even within function parameter lists, as in function f(x = do { return null; }) {}.

Jack-Works commented 3 years ago

Hmm, can we ban it? It seems like break or continue in the for loop heads. And it's also hard to implement as the method in #63

pitaj commented 3 years ago

The problem is that you'd need different rules just for when the do expression is used in default parameter position. Whereas the restrictions to break and continue apply to all do blocks.

Jack-Works commented 3 years ago

The problem is that you'd need different rules just for when the do expression is used in default parameter position. Whereas the restrictions to break and continue apply to all do blocks.

Can you give an example? I didn't catch your meaning

EdSaleh commented 3 years ago

https://github.com/tc39/proposal-do-expressions/issues/74

Jack-Works commented 2 years ago

implemented