tc39 / proposal-do-expressions

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

Add documentation why a new keyword is necessary. #78

Closed jguddas closed 11 months ago

jguddas commented 11 months 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 11 months ago
let x = {
  m()
  {
    if (foo) y
    else z
  }
}

is already legal JS.

ljharb commented 11 months ago
let x = {
  a: b
}

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

jguddas commented 11 months ago

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