Is there a way to make babel transform Object.hasOwn?

604 Views Asked by At

preset-env only includes global altering polyfills core-js, which is not great as a library author.

https://github.com/zloirock/core-js#babelruntime talks about a babel transform for imports but none of them work on Object.hasOwn().

1

There are 1 best solutions below

0
Bruno Peres On

You can transform any code into another code using babel, that is exactly the role of babel transformations. Seems that there is one plugin available (disclaimer: I've never used it) but you can how the function would look like after the babel transformation, or you could also write your own babel-plugin for it.

You could also ship a polyfill together with your library, or require it as a dependency of your library.