samuelgoto / proposal-block-params

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

Syntax confliction #39

Open hax opened 5 years ago

hax commented 5 years ago
f(arg) {
   ...
}

As current syntax of this proposal, such code will have different semantic in/not in the class body, which is very confusing, error-prone, and harm to code review.

Another example of error:

const x = {
  key: () => {...}
}

Someone may refactor the code from arrow function to plain function for some reason (for example, need name for recursion), and just forgot the function keyword:

const x = {
  key: f() {...}
}

Currently it will cause syntax error, with this proposal, oops...

SiddharthShyniben commented 3 years ago
const x = {
  key: f() {...}
}

becomes

const x = {
  key: f(() => {...})
}

and unless f is defined, you are still getting a ReferenceError. And if f is defined, x.key might not be a function, leading to another error. You'll have to be really lucky if f returns a function.