-
Notifications
You must be signed in to change notification settings - Fork 75
Spec short-circuiting semantics without using a transient Nil value #20
Comments
I'm a huge fan of this new proposal. These are the syntax semantics I would've expected for Any other thoughts? Maybe someone thinks it is too restrictive. |
To clarify, this means |
@ljharb I think so. |
@ljharb Yes. The parenthesised forms will lead to different parse tree than the non-parenthesised ones (contrarily to the non-optional equivalent). Using spaces to denote precedence,
while
|
This alleviates most of my earlier concerns, so thanks. It sounds like this structure will need to be reflected in any AST format, right? I think it would need to, since Following the format from http://esprima.readthedocs.io/en/latest/syntax-tree-format.html, seems like the new AST structure would be something like this: interface OptionalChainingExpression {
type: 'OptionalChainingExpression';
expression: Expression;
accessChain: ChainedAccessElement[];
}
type ChainedAccessElement = ChainedMemberAccess | ChainedCall;
interface ChainedMemberAccess {
type: 'ChainedMemberAccess';
computed: boolean;
property: Expression;
}
interface ChainedCall {
type: 'ChainedCall';
arguments: ArgumentListElement[];
} Does that look right? It also means that (I realize the focus here is on the spec grammar, which doesn't necessarily need to match AST formats, just curious what the implications are for tools authors.) |
The new spec is available at https://tc39.github.io/proposal-optional-chaining/ |
@littledan #10 (comment)
Your wish is our command! :-) Here is a first draft:
https://github.com/tc39/proposal-optional-chaining/blob/master/ShortCircuitingWithoutNil.md
Question to specialists (cc @waldemarhorwat): Is the grammar correct?
The text was updated successfully, but these errors were encountered: