samuelgoto / proposal-block-params

A syntactical simplification in JS to enable DSLs
205 stars 8 forks source link

Completion value suggestion #27

Open samuelgoto opened 6 years ago

samuelgoto commented 6 years ago

From @erights:

One of the alternatives worth exploring here is to "the last expression without a semicolon" to take as the return value. For example:

let evens = foreach ([1, 2, 3, 4]) do (item) {
  let even;
  if (item % 2 == 0) {
    even = item;
  }
  // returns item if even, undefined otherwise
  even
  // important to note that if a ";" gets added, 
  // undefined is returned
}
erights commented 6 years ago

Crucial to this suggestion is that it would apply to do expressions as well. Anywhere we might be tempted to use completion value, we should use this instead.

The absent semicolon above would be syntax, not a missing semicolon to be repaired by ASI. Since we're only talking about new syntactic forms, we have that option.

Credit where due: Inspired by Rust's syntax.