You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Whilst discussing #35, it came to my attention that based on the preprocessor examples in the proposal, the parsing of the ?= operator would be inconsistent with the way that JavaScript is currently parsed.
As a general rule, expressions in JavaScript are contiguous; that is, nowhere in the language do we allow an operator to directly impact a subexpression to which it is not adjacent. Furthermore, an operator always has exactly once precedence and is only evaluated once. The ?= operator breaks both of these rules.
According to the proposal, the ?= "operator is compatible with promises, async functions, and any value that implements the Symbol.result method." However, looking through examples, we can see that the ?= operator is not always adjacent to one of these things. For example, in the following example from the proposal, the ?= operator can only be interpreted as being adjacent to a value of type [Response](https://developer.mozilla.org/en-US/docs/Web/API/Response):
If we try to parse this expression as if it used = instead, it would parse like this:
const[error,response] ?=(await(fetch("https://arthur.place")))// reduced to typesconst[error,response] ?=(await(fetch(string)))// fetch(string) => Promise<Response>const[error,response] ?=(awaitPromise<Response>)// await Promise<Response> => Responseconst[error,response] ?=Response// !!! Response isn't a valid right side for ?=, so a TypeError is thrown!
So the ?= operator needs to "pierce through" the await operator to get to an acceptable RH value. This means that ?= can't parse the same as =. Further, the preprocessor examples show that the ?= operator should also pierce function application! So the real parse is this:
Notice that not only are we parsing in noncontiguous sections, but both step 1 and step 4 are tied to the safe-assignment operator. There is nothing else in JavaScript that requires this sort of nonlinear or double-parsing.
The text was updated successfully, but these errors were encountered:
alray2569
changed the title
Unexpected inconsistency
Unexpected parsing inconsistency
Aug 28, 2024
Whilst discussing #35, it came to my attention that based on the preprocessor examples in the proposal, the parsing of the
?=
operator would be inconsistent with the way that JavaScript is currently parsed.As a general rule, expressions in JavaScript are contiguous; that is, nowhere in the language do we allow an operator to directly impact a subexpression to which it is not adjacent. Furthermore, an operator always has exactly once precedence and is only evaluated once. The
?=
operator breaks both of these rules.According to the proposal, the
?=
"operator is compatible with promises, async functions, and any value that implements theSymbol.result
method." However, looking through examples, we can see that the?=
operator is not always adjacent to one of these things. For example, in the following example from the proposal, the?=
operator can only be interpreted as being adjacent to a value of type[Response](https://developer.mozilla.org/en-US/docs/Web/API/Response)
:If we try to parse this expression as if it used
=
instead, it would parse like this:So the
?=
operator needs to "pierce through" theawait
operator to get to an acceptable RH value. This means that?=
can't parse the same as=
. Further, the preprocessor examples show that the?=
operator should also pierce function application! So the real parse is this:Notice that not only are we parsing in noncontiguous sections, but both step 1 and step 4 are tied to the safe-assignment operator. There is nothing else in JavaScript that requires this sort of nonlinear or double-parsing.
The text was updated successfully, but these errors were encountered: