tc39 / proposal-call-this

A proposal for a simple call-this operator in JavaScript.
https://tc39.es/proposal-call-this/
MIT License
121 stars 5 forks source link

Ambiguity when `?.` in LHS? #19

Closed js-choi closed 2 years ago

js-choi commented 2 years ago

At the Committee plenary today, @waldemarhorwat expressed concern that (from my memory, might be incorrect) a.b?.c::fn is ambiguous.

I’m not sure where the ambiguity comes from yet. a.b?.c::fn is equivalent to (a.b?.c)::fn. The specification has an OptionalChain :: OptionalChain :: SimpleMemberExpression production, and a.b?.c::fn should be:

But I may well be missing something.

ljharb commented 2 years ago

Perhaps, because to a human a.b?.c::fn() could mean:

  1. (a.b?.c)::fn()
  2. (a.b)?.(c::fn())

?

js-choi commented 2 years ago

@ljharb: Maybe, although I think that a.b?.c::fn() “obviously” reads as (a.b?.c)::fn(), in the same way that a.b?.c.d() “obviously” reads as (a.b?.c).d(), but maybe I’m wrong. I guess we’re not sure if @waldemarhorwat meant human visual ambiguity or grammatical ambiguity.

waldemarhorwat commented 2 years ago

Look at the meeting notes. The example I gave during the meeting is a?.b::c.d. The OptionalChain production parses it as both «a?.b::c».d and a?.b::«c.d».

js-choi commented 2 years ago

@waldemarhorwat: Thanks for the catch. This indeed seems like a bug. It seems like it should be fixable by changing:

OptionalChain :
  OptionalChain `::` SimpleMemberExpression

…to:

OptionalChain :
  OptionalChain `::` SimpleMemberExpression [lookahead != `.`]