-
Notifications
You must be signed in to change notification settings - Fork 73
In the spec text, clarify which productions may produce Nil, and statically forbid their use in write context #13
Comments
By |
@rattrayalex By Nil, I mean the spec artefact that is used to implement the short-circuiting semantics of optional chaining. As currently specced, it is “the Nil reference”. If #11 is implemented, it will be “an abrupt completion of type Nil”. Any proposition for a better name is welcome. |
Why are we forbiding optional assignments? |
Because the semantics of |
The burden should be on allowing things, not forbidding them. |
/cc @jdalton
|
That's a pretty solid use case. It seems tho like this would make If this (the difference between a chain and a separate var) ends up being acceptable tho, then conditional assignment might make sense. @jridgewell i think |
Looking at Lodash’s documentation for _.set(), it does not “optional setting”, but “forced-setting” with automatic creation of missing intermediate objects. What is the expected semantics, and what is the useful one? Optional-setting, forced-setting? |
Oh man, I'd forgotten about that. Looking at it again, lodash's forced-setting is fraught with edge cases (do primitives get replaced with object? And the array-indices creating an array not an object). My personal preference would be for optional-setting, but now I'm seeing the complications with forced-setting being expected by some. I think user interest is definitely there, but I'll quietly wait for you to figure out the spec. 😃 |
Done. Except that “optional delete” is not forbidden, see #14 (comment) for justification. If you think that you have sufficiently strong use cases and sufficiently clear semantics for the “optional assignment” case, please open another issue. |
Uh oh!
There was an error while loading. Please reload this page.
I intend to update very soon https://claudepache.github.io/es-optional-chaining/ with the following changes:
?.
in cases such asa?.b = c
, but alsoa?.b.c[x] = d
anddelete a?.b().c
.The precise roadmap is:
X = Y
, when MayProduceNil ofX
is true;X *= Y
, when MayProduceNil ofX
is true.Add an early syntax error rule for the following case.(Or not; see Shoulddelete a?.b
be allowed or forbidden? #14):indelete X
, when MayProduceNil ofX
is true.As an aside, this work is orthogonal to #11 (the grammar and static semantics are the same whether Nil is a reference or an abrupt completion).
The text was updated successfully, but these errors were encountered: