-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
Memoize call expressions in optional chains in loose mode #11261
Memoize call expressions in optional chains in loose mode #11261
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.
I think we need more test here. Eg,
foo.bar()?.()
foo[bar]()?.()
foo.bar().baz?.()
foo[bar]().baz?.()
This will highlight a few more cases we're failing. To fix, we need to adjust the isCall
checks below.
@jridgewell Please ignore that request for review. I need to make sure we're probably setting the call context. |
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.
If you need help, here's another test case.
@jridgewell Found and fixed my bug! It would be great if you could take a look :) |
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.
Almost there.
@jridgewell I've addressed your feedback again. Really appreciate all of the help! It's early days when it comes to my understanding of Babel - but you and Nico have been incredibly welcoming. |
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.
Nice work @oliverdunk!
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 for contributing!
Thanks Oliver! |
Previously, in loose mode, we weren't memoizing optional call expressions. This resulted in code like
a.get(b)?.();
being compiled toa.get(b) == null ? void 0 : a.get(b)();
, which repeats a function call.This MR changes the behaviour so that memoization is only skipped when no work is done by the call's callee.