Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix optional chain optimization in sequence expression #15888

Merged

Conversation

nicolo-ribaudo
Copy link
Member

@nicolo-ribaudo nicolo-ribaudo commented Aug 24, 2023

Q                       A
Fixed Issues? Fixes #15887
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

The problem is that isCompletionRecord in the test code is returning false, because the sequence expression was not in a completion record position.

@nicolo-ribaudo nicolo-ribaudo added PR: Bug Fix 🐛 A type of pull request used for our changelog categories i: regression labels Aug 24, 2023
(t.isExpressionStatement(replacementPath.parent) &&
!replacementPath.isCompletionRecord()) ||
(t.isSequenceExpression(replacementPath.parent) &&
last(replacementPath.parent.expressions) !== replacementPath.node);
Copy link
Member Author

Choose a reason for hiding this comment

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

It might make sense to have a path.isValueObservable() helper eventually.

Copy link
Contributor

Choose a reason for hiding this comment

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

It certainly reminds me of the messy path._getCompletionRecords. Thankfully the switch statement is not an expression.

Copy link
Contributor

Choose a reason for hiding this comment

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

Similar usage:

const shouldPreserveCompletion =
(!isExpressionStatement(parent) && !isSequenceExpression(parent)) ||
path.isCompletionRecord();

@babel-bot
Copy link
Collaborator

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/55206/

@nicolo-ribaudo nicolo-ribaudo merged commit 0534e63 into babel:main Aug 25, 2023
47 of 48 checks passed
@nicolo-ribaudo nicolo-ribaudo deleted the fix-optional-chain-seq-expr branch August 25, 2023 08:13
@nicolo-ribaudo
Copy link
Member Author

Releasing a patch to fix the regression.

@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Nov 25, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
i: regression outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: Bug Fix 🐛 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Optional chaining expressions resolving as true instead of undefined
4 participants