es-check icon indicating copy to clipboard operation
es-check copied to clipboard

Possibility of detecting polyfills with the --checkFeatures flag

Open cascornelissen opened this issue 1 year ago • 2 comments

First of all, I want to share that I'm really stoked about this new --checkFeatures flag, I've tried setting up something similar in the past and stopped when I realised how much work this would be.

Requested Update

If even remotely possible it'd be nice if the --checkFeatures flag would take polyfills like core-js into account.

Why Is This Update Needed?

We're using core-js to polyfill certain ES features such as Array.prototype.toSorted() but when trying out the new --checkFeatures we noticed that this triggers an error when running es-check with es2022.

This might be vastly more complicated than one would initially think as in our setup we load the polyfill in a different file (chunk) than where .toSorted() is being called. Additionally there's of course a plethora of different polyfills and trying to even detect some of them might result in a lot of work. Maybe alternative ways of doing this can be thought of.

Are There Examples Of This Requested Update Elsewhere?

Not that we could find 🤷🏼‍♂️

cascornelissen avatar Jan 07 '25 15:01 cascornelissen

The option is called --checkFeatures (now), correct?

I was bitten by this, as es-check claims the following code (just a simplified reproduction) is not es2017-compatible:

Array.prototype.at = function(index) { return this[index]; };
[1, 2, 3].at(2); // 3

(I could imagine it might work even in 1996 LiveScript…? Maybe the array needs to be created differently, though.)

I understand this might be difficult to implement (I know very little about AST parsing) – so is it out of scope of this utility?

p3k avatar Jan 13 '25 17:01 p3k

My bad, changed --detectFeatures to --checkFeatures, no idea why I came up with a new name for the option while writing this ticket 😂

cascornelissen avatar Jan 14 '25 14:01 cascornelissen

This is interesting! I am going to think on it and would accept PRs—especially something that could be added as a plugin.

yowainwright avatar Mar 26 '25 07:03 yowainwright