-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Open
Labels
Description
Feature Request
Several helper functions redefine themselves (i.e. replace themselves with a more optimized version) at runtime e.g.:
constructextendsgetgetPrototypeOfsetsetPrototypeOftypeofwrapNativeSuper
This has the advantage of scoping the optimization to the helper, which reportedly makes inline helpers more amenable to minification/tree-shaking in some cases.
The downside is that it a) makes the code less clear, which makes it harder to spot bugs, and b) doesn't work with (and slows down) the (default, non-ES6) external helpers.
If minification/tree-shaking is a concern, external helpers should be used, rather than making the code slower for external helpers and less maintainable for everyone.
I propose that these optimizations should be implemented without redefining the helper e.g.:
Before
export default function _setPrototypeOf (o, p) {
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf (o, p) {
o.__proto__ = p
return o
}
return _setPrototypeOf(o, p)
}After
function _objectSetPrototypeOf (o, p) {
o.__proto__ = p
return o
}
var __setPrototypeOf = Object.setPrototypeOf || _objectSetPrototypeOf
export default function _setPrototypeOf (o, p) {
return __setPrototypeOf(o, p)
}Which, in this case, can be reduced to:
function _objectSetPrototypeOf (o, p) {
o.__proto__ = p
return o
}
export default Object.setPrototypeOf || _objectSetPrototypeOf