Skip to content

Why createMetaResolver ignores object for instance polyfills #193

Open
@steverep

Description

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.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions