-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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(es/compat): Fix optional chaining #7530
Conversation
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.
Thank you! Can you fix CI failures?
swc-bump:
- swc_ecma_transforms_compat
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.
Thank you so much!
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.
Automated review comment generated by auto-rebase script
Description:
This fixes a few bugs with optional chaining:
a?.c()
a?.b.c()
a.c?.()
a.b.c?.()
a?.b[c?.d]
delete foo?.bar
function foo(a, b = a?.b) {}
It also optimizes the AST for runtime evaluation. Before, we constructed a leftwards conditional tree (
(_a_b = (_a = a) == null ? void 0 : _a.b) == null ? void 0 : _a_b.c
) instead of a rightward tree ((_a = a) == null ? void 0 : (_a_b = _a.b) == null ? void 0 : _a_b.c
), which required multiple== null
checks after the first nullish is found.BREAKING CHANGE:
Related issue (if exists):
Fixes #7531