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

JavaScript browser compatibility checker which checks against »can I use« data #103

Open
mischah opened this issue Oct 5, 2017 · 9 comments

Comments

@mischah
Copy link

mischah commented Oct 5, 2017

There are already tools for checking CSS compatibility like the following:

But I could b’t find any for JavaScript.
It would be awesome to have a node module (with a CLI) for that.

Related:
caniuse API

@sindresorhus
Copy link
Owner

The only thing I could find is https://github.com/amilajack/eslint-plugin-compat

@mischah
Copy link
Author

mischah commented Oct 5, 2017

Thanks. Missed that. Looks pretty neat. But I would prefer to have something as a standalone tool.

Is this still a valid module request?

@sindresorhus
Copy link
Owner

Is this still a valid module request?

Yes, I was just sharing prior art.

@mischah
Copy link
Author

mischah commented Mar 6, 2018

Tried eslint-plugin-compat extensively.
It simply doesn’t work as expected. ES6 methods like Object.assign() and String.prototype.padEnd() didn’t cause errors. Same for arrow functions. Plus, when something causes an error, the error remains when using a proper polyfill.

@CodeByAlex
Copy link

@mischah Did you find anything since your last post?

@mischah
Copy link
Author

mischah commented Mar 27, 2019

@CodeByAlex Nope.

@robatwilliams
Copy link

robatwilliams commented Nov 22, 2019

A few colleagues and I came up with some things that such a tool could do (before we found this issue). It needs to be borne in mind that APIs can be polyfilled whereas language features cannot.

Will it work

In which browsers/versions will this work?

Will this work in these browsers/versions?
=> https://github.com/amilajack/eslint-plugin-compat (bearing in mind #103 (comment))

Making it work

How could I change this to make it work in these browsers/versions?

Change this to make it work in these browsers/versions.

How might I change this to make it work in more browsers/versions?

Polyfilling

Give me a JavaScript expression that determines if I need to load any polyfills to make this work in the current browser (for use in browserSupportsAllFeatures() as described in Loading Polyfills Only When Needed.

Which polyfills do I need (worst case scenario) to make this work in these browsers/versions?

Create a polyfills file (worst case scenario) to make this work in these browsers/versions.

Give me only the polyfills needed to make this work in the current browser.
=> https://polyfill.io/ (use the generated expression from above to avoid unnecessary round-trip in latest browsers)

Tools and resources for implementation

Which APIs does this use?
=> https://github.com/Financial-Times/js-features-analyser

Which language features does this use?
=> https://github.com/babel/babel-eslint

Is this API or language feature supported in this browser?
=> https://github.com/kangax/compat-table/ (https://github.com/kangax/compat-table/blob/gh-pages/data-esnext.js)
=> https://github.com/Fyrd/caniuse

@robatwilliams
Copy link

I did some experimentation to investigate the feasibility of this: https://github.com/robatwilliams/workie

I posted some notes there - in conclusion, it would be possible, but there are some limitations and I think it's quite a niche use case.

@robatwilliams
Copy link

Focusing on the language feature aspect, I created an ESLint plugin and companion CLI tool which use browserslist and the MDN browser compatibility data.

https://github.com/robatwilliams/es-compat

I've just released a beta version which covers ES2018 and 2019. It shouldn't be much more work to add the other ES20xx versions for a MVP. Let me know if you have any feedback.

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

No branches or pull requests

4 participants