You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
babel-minify breaks polyfills added to global built-in objects #738
Then minifying that with the babel-minify cli application, I get the following output (pretty printed):
(function() {
var a = Math.addOne;
Math.addOne = function(a) {
return a + 1
},
console.log(a(1), a(2))
}
)();
As you can see, an alias to the method is created, but that happens before the method was defined, so the alias will be invalid and the code will not work.
If change Math["addOne"] = ... to Math.addOne = ... in the definition of the method, then everything works fine. The problem is that in my actual code, I cannot control how the method is defined, because the method is a polyfill for Math.sign which is provided by core-js, which uses Object.defineProperty to define it.
This has not been resolved. With the latest version of babel-minify I still have a problem when the above example is written with Object.defineProperty, e.g.
(function() {
var a = Math.addOne;
Object.defineProperty(Math, "addOne", {
value: function(a) {
return a + 1
}
}), console.log(a(1), a(2))
})();
As you can see, we have the same problem as before, i.e. the alias a to the method Math.addOne is defined before the method itself. This breaks core-js which uses Object.defineProperty to define its polyfills.
Activity
redneb commentedon May 13, 2018
This has not been resolved. With the latest version of
babel-minifyI still have a problem when the above example is written withObject.defineProperty, e.g.is minified to:
As you can see, we have the same problem as before, i.e. the alias
ato the methodMath.addOneis defined before the method itself. This breakscore-jswhich usesObject.definePropertyto define its polyfills.