Giter Club home page Giter Club logo

es-compat's Introduction

npm version npm downloads

es-compat

Check JavaScript code compatibility with target browsers and Node.js versions

Checks that the language features used in your code/bundles are supported by your browserslist targets.

Tools

Rationale

You might not need a transpiler or polyfills.

Or, you may be transpiling your own code but not prebuilt 3rd-party libraries - leaving you open to breakages when they use new language features.

ESLint supports targeting a specific ECMAScript version, and eslint-plugin-es-x allows forbidding individual language features. However when building applications, what we target are particular browser/runtime versions. This project lets you check compatibility by specifying those targets directly via a browserslist. It will figure out which individual features you can use, by looking up those targets in the MDN compatibility dataset.

Usage scenario examples

If you're not using a transpiler, run the tool/linter on your source code to ensure you're not using language features that aren't supported in your application's supported browsers.

If you transpile your own code but not 3rd party libraries, run the tool/linter on your output bundles to ensure they're not using language features that aren't supported in your application's supported browsers.

Scope

ECMAScript language features only; this includes syntax, built-ins, and methods.

It doesn't check browser/runtime-specific APIs (see eslint-plugin-compat), or CSS (see doiuse).

ECMAScript version coverage

n Expand for footnotes...

1 Excluding features not statically detectable: revised Function.prototype.toString, stable Array.prototype.sort, well-formed JSON.stringify.

2 Excluding Symbol.prototype.description; as a debug feature, it's not worth the false positives that arise due to its name and not being a method.

3 ES2015 (ES6) is out of scope; it's been supported by evergreen browsers for many years. Assisting you to continue supporting IE11 is not a goal of this tool.

4 ES5 is out of scope; it's over 10 years old and supported even in IE10.

Browser compatibility data

We use a pinned version of @mdn/browser-compat-data, because their SemVer policy allows for breaking changes to the data structure even in minor and patch releases. If you need to use more up to date data, use the overrides facility of package.json to specify a later version - but be aware that it might break.

Limitations

Because JavaScript is untyped, detection of some features' usage (namely prototype methods) through static analysis requires some assumptions to be made. This shouldn't be a problem as long as you avoid creating your own methods having the same names, or write code in an unusual way to deliberately evade detection.

Support can only be checked for the browsers and runtimes covered by the MDN compatibility dataset.

The MDN compatibility dataset has very good feature coverage of the top ~6 desktop and mobile browsers, and Node.js (much more than kangax/compat-table). In case of missing data for a feature (support unknown, or unknown in which version support was added), we currently assume support.

Contributing

Contributions and feedback welcome. Please see the GitHub issues or create one, as appropriate.

Related

* Thanks to these projects in particular (and many others) for making this project possible.

es-compat's People

Contributors

robatwilliams avatar brettz9 avatar lukeapage avatar sobstel avatar amanvarshney11 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.