babel / babel/babel-polyfills

Why createMetaResolver ignores object for instance polyfills

Open
#193 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
357
Forks
62
PR merge metrics
No merged PRs in 30d

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`](https://github.com/babel/babel-polyfills/blob/984c56c59568283889c3f0f89e58d370e4fd10f8/docs/polyfill-provider.md), 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:

```js
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.

Contributor guide

Open the contributing guide

Research direction

Start with docs/polyfill-provider.md and the documented createMetaResolver behavior for instance properties. Compare that behavior with the core JS providers' handling, then determine whether an object-aware API change is appropriate and define the expected resolver behavior before implementation.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.