syntax
syntax copied to clipboard
Parse empty braces, i.e. `{}` as unit expression.
Motivation
Currently an expression with empty braces results in a syntax error. If you write the same code in Js, it parses. It is quite common while writing code that you write out the “empty braces” first. Not sure if fixing a syntax error is good UX. Let's just parse this as a unit expression. An empty record does not exist, so there’s no conflict here. This is also more consistent with JavaScript and this is a low-risk change from a language perspective: changing a syntax error into a default. The default () seems to be the right semantics for {}.
What does the difference look like?
before

after
let f = () => {}
// parses as
let f = () => {
()
}
for _ in 0 to 10 {
}
// parses as
for _ in 0 to 10 {
()
}