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

Why createMetaResolver ignores object for instance polyfills #193

Open
steverep opened this issue Dec 28, 2023 · 1 comment
Open

Why createMetaResolver ignores object for instance polyfills #193

steverep opened this issue Dec 28, 2023 · 1 comment

Comments

@steverep
Copy link

I'm using @babel/helper-define-polyfill-provider with a simple custom plugin to inject various polyfills for an application. In the documentation for createMetaResolver, it's noted:

Instance properties aren't categorized by their object, because often it's not possible to statically determine it.

I understand that, but I'm wondering if completely ignoring it is the best approach considering it's not always impossible to determine the object. And in those cases, it seems the resolver should not return a polyfill if the object does not match the desired prototype, which would save some unnecessary injections.

By ignoring it, a provider has to manually do this for example, by adding the desired object to the resolve data and then something like:

if (
  meta.kind === "property" &&
  meta.placement === "prototype &&
  meta?.object &&
  meta.object !== dest.object
  ) {
  // skip polyfill injection because object is not null and doesn't match
}

Or is that a bad idea? Although it seems like the Core JS providers already do something like this in a more roundabout way?

If I'm way off base here, please explain and feel free to close this. Otherwise I guess consider it a feature request for an API improvement.

@steverep
Copy link
Author

@nicolo-ribaudo could I ping you for an opinion here? Just wondering if my logic is wrong before I go implementing it with the assumption in my OP.

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

1 participant