polyfill-corejs3 won't polyfill some Promise static methods with method: "usage-pure"
I've been experimenting with polyfill-corejs3 a bit and tried the following setup (also on this repo https://github.com/giniyat202/babel-polyfill-promise):
.browserslist:
chrome >= 75
.babelrc:
{
"presets": ["@babel/preset-env"],
"plugins": [
[
"polyfill-corejs3",
{
"method": "usage-pure"
}
]
]
}
input.js:
Promise.all();
Promise.allSettled();
Promise.any();
Promise.race();
I'm expecting both Promise.allSettled and Promise.any to be polyfilled. However, this is not the case here.
expected output:
"use strict";
var _allSettled = _interopRequireDefault(require("core-js-pure/features/promise/all-settled.js"));
var _any = _interopRequireDefault(require("core-js-pure/features/promise/any.js"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
Promise.all();
(0, _allSettled.default)();
(0, _any.default)();
Promise.race();
actual output:
"use strict";
Promise.all();
Promise.allSettled();
Promise.any();
Promise.race();
usage-global correctly provides the two missing polyfills.
I've noticed that these methods are defined without a pure reference:
https://github.com/babel/babel-polyfills/blob/fa4f9f3c42d50702b69f2aa8943840a5ba42c3fe/packages/babel-plugin-polyfill-corejs3/src/built-in-definitions.js#L338-L350
I've tried passing "promise/all-settled" and "promise/any" there and I started seeing correct output.
...or Promise should be polyfilled completely. With the current core-js architecture, promise/index that's loaded on Promise contains es.promise.{ all-settled, any }, so it should be polyfilled in chrome >= 75 and promise/{ all-settled, any } contains main es.promise module. (core-js@4 should optimize it, however the issue not about it.)
Does this issue mean that usage-pure is still buggy and it should be avoided in production?
That means that usage-pure is still buggy with targets. https://github.com/babel/babel-polyfills/pull/198 adds a kind of workaround for that.
@zloirock Oh, thank you so much :) Then I think I will pick usage-global for my project since this one is stable, right? Just a little question: if I want to contribute to this project as he/she did in the PR, what background knowledge should I have? Is there a guide or something?
@nyngwang look at https://github.com/babel/babel-polyfills/blob/main/CONTRIBUTING.md and https://github.com/babel/babel/blob/main/CONTRIBUTING.md.