Esbuild: Missing String.prototype.replaceAll polyfill

Created on 14 Nov 2020  Â·  7Comments  Â·  Source: evanw/esbuild

Hi, String.prototype.replaceAll was introduced in es2021 so I'd expect the output for target es2015 to contain a polyfill for it. Maybe I'm missing something? Thanks in advance.

All 7 comments

The target level in esbuild only handles syntax-level concerns. You are free to include whatever polyfill you'd like to use.

Okay, thank you.

Side question: Is there a way you can recommend me so that the necessary
polyfills get added automatically?

On Sat, 14 Nov 2020, 18:19 Evan Wallace, notifications@github.com wrote:

The target level in esbuild only handles syntax-level concerns. You are
free to include whatever polyfill you'd like to use.

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/evanw/esbuild/issues/530#issuecomment-727246019, or
unsubscribe
https://github.com/notifications/unsubscribe-auth/AB2UDXSB5XVYQQJ2NAVLXJTSP3C3TANCNFSM4TVRLFPA
.

I guess that depends on the polyfill. You can insert the polyfill as an import into all files so it's guaranteed to come first with the inject feature. This is sufficient for almost everything including replaceAll.

But if you need to polyfill the functions used by esbuild's automatically-generated run-time code such as Object.assign, you'd currently have to use a separate <script> tag that comes before your own code. Arguably the run-time code not being polyfilled could be considered a bug in esbuild.

I see. And is there a way to automate the usage of the inject feature? I mean, is there a library that can help me identify which polyfills are required based on the code at hand and based on the target ECMAScript (or browser) version?

That's kind of a general JavaScript question instead of an esbuild-specific question, so it might be good to ask this question elsewhere. I'm not super knowledgable about this.

Many projects including Babel use core-js although I believe the primary author is in jail at the moment, so I'm not sure what the current state of that project is. We used es5-shim and es6-shim at work for a while but we no longer need it (we now require ES2017+).

Sorry I can't help more. Maybe someone else can comment with more context.

I believe the primary author is in jail at the moment

Nope -)

Oh hello! Never mind then. Welcome back :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lolychee picture lolychee  Â·  4Comments

egoist picture egoist  Â·  3Comments

mohsen1 picture mohsen1  Â·  3Comments

Gotterbild picture Gotterbild  Â·  3Comments

elektronik2k5 picture elektronik2k5  Â·  3Comments