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

Keep track of what is polyfilled #39

Open
shgysk8zer0 opened this issue Dec 11, 2023 · 1 comment
Open

Keep track of what is polyfilled #39

shgysk8zer0 opened this issue Dec 11, 2023 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@shgysk8zer0
Copy link
Owner

Some features cannot be fully implemented, and it would be helpful to have a consistent way of telling.

I'm thinking something along the lines of the following:

  export const key = Symbol.for('_polyfilled');

  export function markPolyfilled(thing, name) {
    if (thing.hasOwnProperty(key)) {
      thing[key].push(name);
    } else {
      Object.defineProperty(thing, key, {
        value: [name],
        enumerable: false,
        configurable: false,
        writable: false,
      });
    }    
  }

  export function isPolyfilled(thing, name) {
    return thing.hasOwnProperty(key) && thing[key].includes(name);
  }

Using Symbol.for() makes it easily accessible in other scripts/modules without importing.

Using Object.defineProperty() with enumerable set to false makes it so Object.keys() and Object.entries() won't list this.

Having an array allows for multiple records of polyfills on the same thing without conflict.

Example

  const obj = { num: 42 };
  markPolyfilled(obj, 'foo');
  markPolyfilled(obj, 'bar');
  console.log({
    foo: isPolyfilled(obj, 'foo'),
    bar: isPolyfilled(obj, 'bar'),
    bazz: isPolyfilled(obj, 'bazz'),
    keys: Object.keys(obj),
    symbols: Object.getOwnPropertySymbols(obj),
  });
@shgysk8zer0 shgysk8zer0 added the enhancement New feature or request label Dec 11, 2023
@shgysk8zer0 shgysk8zer0 self-assigned this Dec 11, 2023
@shgysk8zer0
Copy link
Owner Author

I've added the markPolyfilled() to utils.js and handle it automatically in polyfillMethod(), polyfillGetterSetter(), and overwriteMethod().

Making this widely supported is largely a matter of re-writing a ton of polyfills that are more direct. Will take some effort to do so.

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

No branches or pull requests

1 participant