Skip to content

Conversation

@rbuckton
Copy link
Contributor

@rbuckton rbuckton commented Oct 2, 2019

Relaxing the assertions on updateCall/updatePropertyAccess/updateElementAccess when used with a CallChain/PropertyAccessChain/ElementAccessChain to fix a crash in the TS transform and to improve backwards/forwards compatibility with external consumers of the API.

If you call any of the three mentioned updateX functions on an XChain node, the corresponding updateXChain function is called instead with the current value of node.questionDotToken passed as the questionDotToken argument.

Fixes #33744

@rbuckton rbuckton requested a review from weswigham October 2, 2019 22:20
Copy link
Member

@weswigham weswigham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much friendlier - this means some custom transforms might just support optional chains out of the box (maybe not wholly correctly, but in some way without crashing).

export function updatePropertyAccess(node: PropertyAccessExpression, expression: Expression, name: Identifier) {
Debug.assert(!(node.flags & NodeFlags.OptionalChain), "Cannot update a PropertyAccessChain using updatePropertyAccess. Use updatePropertyAccessChain instead.");
if (isOptionalChain(node)) {
return updatePropertyAccessChain(node, expression, node.questionDotToken, name);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I imagine if we had a way to emit a deprecation warning, we'd do it here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm working on that elsewhere...

@rbuckton rbuckton merged commit c774762 into master Oct 2, 2019
@rbuckton rbuckton deleted the fix33744 branch October 2, 2019 23:13
@microsoft microsoft locked as resolved and limited conversation to collaborators Oct 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Optional chaining, CallChain error

3 participants