-
Notifications
You must be signed in to change notification settings - Fork 75
Conversation
Could you link the issue related to this change? |
@@ -134,37 +117,22 @@ That follows from the design choice of specifying the scope of short-circuiting | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Above desugaring is incorrect.
@@ -134,37 +117,22 @@ That follows from the design choice of specifying the scope of short-circuiting | |||
|
|||
Note that, whatever the semantics are, there is no practical reason to use parentheses in that position anyway. | |||
|
|||
### Optional deletion |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to remove ”optional deletion”, you must add additional static semantics in Section The delete Operator, in order to forbid specifically a LeftHandSideExpression containing an OptionalChain to be used with the delete operator.
As I said in #40, ”Optional deletion has very few practical use cases; but forbidding it has probably no practical utility either.” However, forbidding optional deletion adds positive complexity to the spec.
|
||
* optional function execution: `a?.()` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👏#59
README.md
Outdated
The following is not supported, although it has some use cases; see [Issue #18](//github.com/tc39/proposal-optional-chaining/issues/18) for discussion: | ||
|
||
* optional property assignment: `a?.b = c` | ||
* optional assignment: `a?.b?.c = x` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: a?.b = x
was simpler
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, ”optional property assignment” was more precise than ”optional assignment”. We’re not discussing about an optional version of a = b
, but about an optional version of a.b = c
.
@@ -590,12 +535,6 @@ <h1>Runtime Semantics: ChainEvaluation</h1> | |||
1. If the code matched by this production is strict mode code, let _strict_ be *true*, else let _strict_ be *false*. | |||
1. Return ? EvaluateStaticPropertyAccess(_baseValue_, |IdentifierName|, _strict_). | |||
</emu-alg> | |||
<emu-grammar>OptionalChain : OptionalChainingPunctuator Arguments</emu-grammar> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to delete the OptionalChainingPunctuator Arguments [?Yield, ?Await]
in the OptionalChain [Yield, Await]
syntax.
spec.html
Outdated
@@ -612,15 +551,6 @@ <h1>Runtime Semantics: ChainEvaluation</h1> | |||
1. If the code matched by this production is strict mode code, let _strict_ be *true*, else let _strict_ be *false*. | |||
1. Return ? EvaluateStaticPropertyAccess(_newValue_, |IdentifierName|, _strict_). | |||
</emu-alg> | |||
<emu-grammar>OptionalChain : OptionalChain Arguments</emu-grammar> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is still necessary, it defines the runtime semantics for a?.b()
spec.html
Outdated
@@ -651,7 +581,6 @@ <h1>Expression Rules</h1> | |||
<emu-grammar> | |||
OptionalExpression : | |||
MemberExpression OptionalChain | |||
CallExpression OptionalChain |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This defines tail call semantics for return a()?.b
. You're looking for the OptionalChainingPunctuator Arguments
below.
Thanks for making a PR! |
Could you explain the rationale for arriving at these choices? At this point, I am somewhat skeptical of the null/undefined change, personally. |
I also have a feeling the |
@Mouvedia, the issues would be #69 and #65. Since both discussions favor NOT returning null, I'm wondering why this decision was made. In my opinion it makes this operator more confusing. It also isn't in line with most other languages, see #69 (comment). |
Here's a consolidated table (using data from @noppa, @hax, and @claudepache's comments in #69) on what current libraries do, with inputs of
Idx is the only one of this list that returns Notes:
|
@Zarel to be clear, all of these accept both null and undefined as input, but only one of them potentially outputs both null and undefined? |
@ljharb Yes, your interpretation is correct. I've edited my comment to be slightly clearer. |
idx is not popular enough to deserve that change. Let's just compare it to the module separated from lodash; as of today:
If you consider that most ppl either use lodash (18M+) or underscore (6M+) and a bundler for tree shaking you realize that the familiarity wouldn't be the criterion that would support to pick idx's way. Why did underscore/lodash pick always Also what @zenparsing pointed out earlier is a strong argument against * #58 |
From a mental model perspective, it makes sense that so many of these libraries chose |
Removing optional function execution is mainly due to discussions around semantics and grammatical inconsistencies that have stalled this proposal in the past. By scoping this down to the primary use case of object property access, we can get a crucial feature added while we evaluate better options and viability of optional function execution at a later time. As for the change of
Thanks to everyone for voicing their opinions on the matter 😄 |
It’s worth noting that either choice will be controversial; there are those of us that feel strongly about having the null/ undefined semantics. |
@dustinsavery It'd help if you could draw these conclusions on the issue threads where the topics are being discussed, to engage the people there.
The scoping down here will not meet all strong opinions that have been expressed in TC39, unfortunately. However, I think the switch to null will be something that many committee members are strongly opposed to. We can discuss this further offline if you'd like. |
I would go even further and support only |
Do you mean there are still strong opinions with respect to the remaining scope (e.g. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's still a OptionalChainingPunctuator Arguments
in the Tail Position Calls section that needs to be removed.
spec.html
Outdated
<emu-clause id="sec-optional-chaining-evaluation"> | ||
<h1>Runtime Semantics: Evaluation</h1> | ||
<emu-grammar> | ||
OptionalExpression : | ||
MemberExpression OptionalChain | ||
CallExpression OptionalChain |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one's still needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thought I got that one, fixing now.
I agree, there's no way to please everyone. The
I strongly considered this. The only reason I kept the bracket syntax is because the use case that this proposal is targeting felt incomplete without it. However, I would like to see |
@dustinsavery, @Mouvedia - could someone point me to any issues where |
@jackkoppa It's spread across a couple of issues: #59, and the original debate about all syntax options: #51 |
@jackkoppa @Mouvedia optional member access without optional bracket access is an incomplete feature that is highly unlikely to progress. |
@dustinsavery @Mouvedia The committee rejected dropping The committee seems to have vetoed every popular option, leaving us in a rather tough place. |
Just to clarify, they rejected dropping optional bracket access I believe, not the syntax specifically. |
Yes, I believe @ljharb had some concerns with it, if in conjunction with |
My understanding is that each concern is shared by multiple committee members, such as the following (some of these I share, some I do not)
I'm sure I've missed some, and I'm happy to edit if anyone thinks I've mis-stated any of the concerns. |
@jackkoppa #5 but @dustinsavery is right it's spread on several issues. |
I think you were the one to say it’s necessary. 😜 I’m fine if it’s |
@jridgewell i was, but I’m not the only one who thinks that - just the only one to have spoken up :-) |
@jridgewell opposes If this proposal progresses in its current form, how likely is it that we'll ever see optional function calls, given that both of those requirements can't be fulfilled if I wouldn't personally mind if we didn't get optional call expressions, but it's important that everyone is on the same page about the finality of this change. Are we temporarily scoping down the operator or is this, in fact, a nail in the coffin for optional calls? |
spec.html
Outdated
@@ -558,7 +502,6 @@ <h1>Tagged Templates (<a href="https://tc39.github.io/ecma262/#sec-tagged-templa | |||
<emu-clause id="sec-optional-chains"> | |||
<h1>Optional Chains</h1> | |||
<emu-note>An optional chain is a chain of property accesses and function calls introduced by an |OptionalChainingPunctuator|.</emu-note> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you remove ”optional function call”, this description is no more exact, and should be somewhat complexified, e.g.:
An optional chain is a chain introduced by an |OptionalChainingPunctuator|, and consisting of a property access facultatively followed by other property accesses and/or function calls.
(IOW, removing optional function calls does mean removing some form of regularity; so that I contend that it does not really ”simplify this proposal”.)
Given the history and debate around this proposal, my goal is to get the pieces of least debate through that have the most impact. While I would love to see all of it get through, optional chaining for property access would have, by far, the most use. As for optional function execution, I understand that not everyone is on board with the semantics. However from my perspective if we go down the path of re-opening the syntax to try |
I am so happy that we can have some progress finally! I agree optional function call is not very useful and even a little bit confusing. There are also many cases About [!-- Someone told me he always think Keep I hope this PR could get consensus in TC39 soon, we have waited these wonderful features too loooong! |
I agree with former speaker. ”Optional function execution” is something I personally would consider less prioritized. And if the journey of this proposal would easen up by leaving it outside of it, then that’s a no-brainer to me. The square bracket syntax (”foo?.[bar]”) is obviously not ideal. But weighing it towards consistency, it’s definitely worth it. |
Glad to see this PR merged, does it mean TC39 has consensus on current syntax and semantic? Can we forward it to stage 3 in near future? |
@hax We're not even at Stage 2 yet. I presented the updated proposal today and it seems like we're getting closer. A couple of notable concerns around consistency with the operator, but overall, I think most are agreeable to the proposal now. Will be seeking Stage 2 in March. |
@dustinsavery You merged the PR, but it had still an unaddressed technical issue: You explicitly added ”optional deletion” in the ”Not supported” section of the README, but you didn’t in fact modify the normative text in order to remove ”optional deletion” support. Now, the README and the spec text contradict themselves. As I said in https://github.com/tc39/proposal-optional-chaining/pull/73/files#r229990799, if you do want remove ”optional deletion” support, you must add explicit appropriate restrictions in the use of the |
@claudepache I spoke with @jridgewell about this and we agreed that as the spec currently stands, it doesn't need to be modified to actively reject optional chaining syntax. Could you clarify what needs to be updated? |
@dustinsavery I have already explained it in other comments, but I’ll repeat here with all details. I guess that it may be confusing that:
Below are all the relevant technical details: First, as the spec currently stands, UnaryExpression: delete UnaryExpression (per ecma262:prod-UnaryExpression) and from the proposal: LeftHandSideExpression: OptionalExpression (per optional-chaining:prod-LeftHandSideExpression) and Concerning the runtime semantics of
At this point, in order to be super-explicit, I must add: If
If you want to remove optional deletion support. Quoting myself from
My advice is: Unless you are willing to actively forbid optional deletion, note in the README that optional deletion is accidentally supported. |
So maybe we can just support |
@claudepache I see where the problem was. Fortunately, it's now a moot point. We had a very productive breakout session today and I managed to get everyone on board with the original spec as was written prior to my modifications. So I have a new PR (#75) that will effectively revert all of my updates. Completely unexpected turn of events, but I'm happy none-the-less! |
This update attempts to simplify this proposal. It:
- (null)?.b should evaluate to null, not undefined #69 Changes the return from automaticundefined
tonull
/undefined
based on value.