Skip to content
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

polyfill-corejs3 won't polyfill some Promise static methods with method: "usage-pure" #105

Closed
giniyat202 opened this issue Oct 8, 2021 · 5 comments

Comments

@giniyat202
Copy link

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:

Promise: {
all: define(null, PromiseDependenciesWithIterators),
allSettled: define(null, [
"es.promise.all-settled",
...PromiseDependenciesWithIterators,
]),
any: define(null, ["es.promise.any", ...PromiseDependenciesWithIterators]),
race: define(null, PromiseDependenciesWithIterators),
try: define(null, [
"esnext.promise.try",
...PromiseDependenciesWithIterators,
]),
},

I've tried passing "promise/all-settled" and "promise/any" there and I started seeing correct output.

@zloirock
Copy link
Member

zloirock commented Oct 8, 2021

...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.)

@nyngwang
Copy link

Does this issue mean that usage-pure is still buggy and it should be avoided in production?

@zloirock
Copy link
Member

That means that usage-pure is still buggy with targets. #198 adds a kind of workaround for that.

@nyngwang
Copy link

nyngwang commented Jan 25, 2024

@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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants