littledan / proposal-reserved-decorator-like-syntax

Reserved decorator-like syntax as an extension point for future JavaScript syntax
23 stars 0 forks source link

What syntax should we use here? #3

Open littledan opened 5 years ago

littledan commented 5 years ago

The current explainer uses @[expressionLike]. What do you think the syntax should be?

Jamesernator commented 5 years ago

I personally think @[expressionLike] is okay. Other candidates might be something like identifier!/identifier(args)!, @@identifier/@@identifier(args), or something else entirely.

One way to think about it might be to consider what the language would've looked like if all reserved used such syntax:

@[class] Point {
  constructor(x, y) {
    @[this].x = x
    @[this].y = y
  }
}

@[function] add(a, b) {
  @[return] a + b
}

@[async] @[generator] @[function] foo(sequence) {
  @[for await] (@[const] x @[of] sequence) {
    @[yield] 12
  }
}
class! Point {
  constructor(x, y) {
    this!.x = x
    this!.y = y
  }
}

function! add(a, b) {
  return! a + b
}

async! generator! function! foo(sequence) {
  for! await! (const! x of! sequence) {
    yield! 12
  }
}

Although special syntax does make me wonder of the feasibility of macros with some builtin ones that might not be implementable in userland (e.g. tailcall).

Morgul commented 5 years ago

I like @[expressionLike], though would be okay with variations on the theme:

I don't like any of those better than the proposed.

pabloalmunia commented 5 years ago

In my very humble opinion @[expressionLike] reminds the destructuring and I prefer other form as !@expresionlike.

littledan commented 5 years ago

If we go with the static/built-in decorators proposal, we may just be able to use @foo for most of the use cases in this README. I am meaning to update this document, and just haven't gotten around to it yet.

pabloalmunia commented 5 years ago

Good news. Don't worry, you have a lot of work with a lot of proposals.