babel: Optional Chaining Bugs Checklist
- Delete on optional chain should work
delete a?.b
: https://github.com/babel/babel/pull/7257 - Optional should be removed from
NewExpression
AST - Optional
MemberExpressions
need to become a new AST nodeOptionalChain
, to fix issues with should-not-parse grammars - Ensure OptionalChain cannot be the LHS of Assignment/Update expressions, tag of a TaggedTemplateLiteral, have a Super object, nor the callee of a NewExpresion
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 29 (29 by maintainers)
Commits related to this issue
- Optional chaining parser fixes Summary: D7029173 implemented basic lexer/parser support for optional chaining, based on the [Babylon implementation](https://github.com/babel/babylon/pull/545) linked ... — committed to facebook/flow by deleted user 6 years ago
- Optional chaining parser fixes Summary: D7029173 implemented basic lexer/parser support for optional chaining, based on the [Babylon implementation](https://github.com/babel/babylon/pull/545) linked ... — committed to facebook/flow by deleted user 6 years ago
With tri-state
optional
field:That is
OptionalChain
. 😉Spec names don’t matter for us. What it’s trying to define is two separate member expressions:
Is an
OptionalMemberExpression
, with objectIdentifier("obj")
, propertyIdentifier("a")
, computedfalse
, and optionaltrue
.If we then add a
.b
to it, we get anotherOptionalMemberExpression
(this is theOptionalChain
thing):Notice that
.b
’soptional
is false, even though it is still anOptionalMemberExpression
. Now, theobject
can be either aOptionalMemberExpression
,MemberExpression
, or aCallExpression
.Also note that
OptionalMemberExpression
can turn into a regularMemberExpression
if surrounded by parenthesis (due to syntax grammars):We can name it whatever. Leaving it
OptionalMemberExpression
will likely be easiest for transforms.OptionalChainingPunctuator
is just the??.
sigil.Hi @nveenjain!
Part 1 is already done.
Part 2/3 are closely intertwined. Unfortunately, they’re rather difficult to accomplish. It’ll take creating a brand new node type, called
OptionalMemberExpression
, which propogates upwards, and can be broken by a non-optional member or call expression (or a parenthesis, because syntax). It’ll also likely break things inside the babel transforms, since they now have to handle a new member syntax.