tc39 / proposal-do-expressions

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

Add documentation why a new keyword is necessary. #78

Closed jguddas closed 1 year ago

jguddas commented 1 year ago

Did a quick read through and couldn't find anything about the reasoning behind adding a new keyword.

Back in the day we had lightscript (not as old as coffescript but still old and abandoned now) that could do stuff like this.

Example: lscdiag


How I would expect it to look like without a new keyword:

- let x = do {
+ let x = {
    let tmp = f();
    tmp * tmp + 1
  };

- let x = do {
-   if (foo()) { f() }
+ let x = if (foo()) { f() }
    else if (bar()) { g() }
    else { h() }
- };
  return (
    <nav>
      <Home />
      {
-       do {
          if (loggedIn) {
            <LogoutButton />
          } else {
            <LoginButton />
          }
-       }
      }
    </nav>
  )
bakkot commented 1 year ago
let x = {
  m()
  {
    if (foo) y
    else z
  }
}

is already legal JS.

ljharb commented 1 year ago
let x = {
  a: b
}

is this a labelled statement in a statement block, or an object literal?

jguddas commented 1 year ago

You are right, assignable block statements are a bad idea.