Suppose that I try to add a new method to the global Math object as follows:
(function () {
Math["addOne"] = function(x) {return x + 1};
console.log(Math.addOne(1), Math.addOne(2));
}());
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.
Suppose that I try to add a new method to the global
Mathobject as follows:Then minifying that with the
babel-minifycli application, I get the following output (pretty printed):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"] = ...toMath.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 forMath.signwhich is provided bycore-js, which usesObject.definePropertyto define it.