-
Notifications
You must be signed in to change notification settings - Fork 113
Conversation
This adds the `?. PrivateIdentifier` and `OptionalChain . PrivateIdentifier` grammars and related runtime semantics. Closes tc39/proposal-optional-chaining#28
This is deliberately omitted, as we've discussed several times before, including on that linked thread. So, I'd like to close this as wontfix. cc @mheiber |
We should either add it, or forbid it now and add it later. Right now we're in kind of a broken state. Chrome and XS (the only browsers that support private fields and optional chains?) currently allow class Foo {
static #x = 1;
static test() {
const o = { Foo };
return o?.Foo.#x
}
}
print(Foo.test());
Babel's private fields transform is broken, but I haven't looked into why yet. I think it's weird to have them "fix" it now just to revert that and support the combination later. |
|
What's the best way to progress this discussion? Would it make sense to have optional chaining support for private class fields in a follow-on proposal? |
@mheiber to be clear; "optional chaining support for private class fields" means |
Considering it a separate follow-on proposal feels like overkill to me, and splitting proposals into a million pieces doesn't seem like a great way to keep all the stakeholders in the loop to resolve cross-cutting concerns. I think a PR in this repository, and a discussion at TC39 seeking consensus, is the right place to discuss this issue. I reviewed this too quickly. I was responding negatively to the idea of On the other hand, I agree with @ljharb that we should add I'd welcome a PR which just added the one form and not the other. Then, we could discuss it at a future TC39 meeting. I'd also welcome a volunteer presenter for this; it doesn't have to be me. |
QuickJS also has the same behavior. |
Did we spec
👍 . I'll trim this PR.
I disagree, but we can have that discussion afterwards. |
I'm not sure what is incorrect. The lack of a grammar production means it was prohibited. I guess many people made the same guess at the syntax combination being allowed. We didn't document the interaction. I believe @mheiber added tests at some point, but that may have been after implementations.
Sure; I'd say that we could land this trimmed patch, and consider adding the other part as either a PR to this repo (during Stage 3) or a needs-consensus PR (after Stage 4). At the same time, I would like to come to a prompt conclusion on this question; it's too bad we left it ambiguous for so long. So let's see if we can do that at the March 2020 TC39 meeting. |
Updated to only allow |
`?.` IdentifierName | ||
`?.` Arguments[?Yield, ?Await] | ||
`?.` TemplateLiteral[?Yield, ?Await, +Tagged] | ||
<ins>`?.` PrivateIdentifier</ins> |
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.
Wasn't the idea that this production would be omitted?
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.
See line 198, it’s an explicit syntax error (like the optional template literal syntax, eg)
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.
Ah, I see. I guess I find this editorial strategy strange--isn't just about everything that's not in the grammar reserved in the future? We haven't used this editorial strategy for other things that we've been thinking about including in the future, like private fields in object literals, or concise private field references (without this
). I don't know why this should be treated differently.
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.
I left it this way because the only 3 implementations that support privates and optional chain didn't realize that mixing them isn't in the spec. Conveniently none of them screwed up this production, but maybe the next implementation would.
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.
Good point; we should be clear here. How about a note explaining that this production is specifically omitted?
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.
Right, I'm suggesting to remove the grammatical production and early error, and instead simply have a note that explains that the grammatical production is deliberately excluded.
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.
FYI, there are Test262 cases for this tc39/test262#2408. We also considered this issue while implementing private features on WebKit. Unfortunately, I don't remember who report this issue.
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.
@caiolima Are there any tests for the other case, x?.y.#z
? (I think we should land this patch, which permits this grammar, but currently, it's not permitted in the 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.
Done.
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.
@caiolima Are there any tests for the other case,
x?.y.#z
? (I think we should land this patch, which permits this grammar, but currently, it's not permitted in the grammar.)
I don't think we have, but I'll double check and open a PR to add it.
See the resolution from tc39/proposal-class-fields#301.
See the resolution from tc39/proposal-class-fields#301.
See the resolution from tc39/proposal-class-fields#301.
See the resolution from tc39/proposal-class-fields#301.
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.
Thanks for applying the changes I suggested.
spec.html
Outdated
</emu-grammar> | ||
|
||
<emu-note>`?.` PrivateIdentifier is currently a unstated Syntax Error</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.
Another way to phrase this is,
?.
|PrivateIdentifier| is not part of the grammar for |OptionalChain|; therefore, expressions likex?.#y
cause a SyntaxError when parsed as an |Expression|.
Depends how pedantic you and the editors want to be. But in particular, I don't think "currently" is needed--everything in the spec or proposal is "currently".
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.
is there any reason to not make x?.#y
valid?
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.
Let's follow up with discussion in #302.
For recursive instances this is pretty important, I've been hitting this the last couple days as I've been wanting to do stuff like |
Even without this PR, |
Oops I forgot to put the |
b6e637f
to
fca14ec
Compare
For the record, we reached consensus on also allowing |
This PR has been updated to allow both |
Thanks for bearing with all the back and forth, and updating this patch. Merging per TC39 consensus. |
Hi, Sorry, I missed this thread.
Arguments were given in tc39/proposal-optional-chaining#28 (in particular tc39/proposal-optional-chaining#28 (comment)) for supporting Probably I missed something? |
Hi @claudepache, this PR was merged into class fields proposal. This mean that |
The title of this PR is misleading: following the discussion in this very thread, |
It seems that the discussion continued on #302. I’ll comment further there, sorry the noise. |
See the resolution from tc39/proposal-class-fields#301.
See the resolution from tc39/proposal-class-fields#301.
This adds the
?. PrivateIdentifier
andOptionalChain . PrivateIdentifier
grammars and related runtime semantics.Closes tc39/proposal-optional-chaining#28