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
Avoid adding #__PURE__ annotation to .bind(this)() expressions #7043
Avoid adding #__PURE__ annotation to .bind(this)() expressions #7043
Conversation
Fixes the #__PURE__ annotation getting added to (async () => {})() IIFEs when the arrow function transform is running with spec: true.
I think a proper fix would be to check in the |
@nicolo-ribaudo that would, unfortunately, then break the not-IIFE case for spec arrow functions ( EDIT: though I guess that could be worked around by specifically whitelisting |
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/6231/ |
@nicolo-ribaudo looks like it's not possible as the |
["transform-arrow-functions", { "spec": true }], | ||
"transform-regenerator", | ||
"transform-async-to-generator", | ||
"external-helpers" |
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.
indentation is wrong here
We could build version accepting NodePaths exclusively on top of the existing helper. |
I am trying a different approach by wrapping the calls on |
return _context4.stop(); | ||
} | ||
}, _callee4, this); | ||
})).bind(this); |
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.
The call to .bind(this)
makes this not eligible for DCE by Uglify, even with the #__PURE__
annotation.
Maybe changing this to just check for MemberExpression
at all is sufficient; or should we stay optimistic and add the #__PURE__
annotation in this case? 🤔
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.
Is .bind
impure only when the user modifies Function.prototype.bind
? If yes, I vote for being optimistic (since Babel has always assumed that builtins are unchanged), otherwise we should remove it.
I'll merge it just so this bug is not on the next beta anymore, and I'm going to see if using sequence expressions in #7044 instead works out better. |
This improves on the fix done on #6999.
Fixes the
#__PURE__
annotation getting added to(async () => {})()
IIFEs when the arrow function transform is running with"spec": true
.The arrow function transform will change the function to be wrapped with a call to
.bind(this)
, which throws off the naïveisIIFE
check. This adds a fancierisIIFE
check that will also catch immediately invoking the result of.bind(this)
.