You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
3.6 KiB

4 years ago
  1. # Contributing
  2. ## Adding a new plugin or polyfill to support (when approved in the next ECMAScript version)
  3. ### Update [`plugin-features.js`](https://github.com/babel/babel/blob/master/packages/babel-preset-env/data/plugin-features.js)
  4. *Example:*
  5. If you were going to add `**` which is in ES2016:
  6. Find the relevant entries on [compat-table](https://kangax.github.io/compat-table/es2016plus/#test-exponentiation_(**)_operator):
  7. `exponentiation (**) operator`
  8. Find the corresponding babel plugin:
  9. `@babel/plugin-transform-exponentiation-operator`
  10. And add them in this structure:
  11. ```js
  12. // es2016
  13. "@babel/plugin-transform-exponentiation-operator": {
  14. features: [
  15. "exponentiation (**) operator",
  16. ],
  17. },
  18. ```
  19. ### Update data for `core-js@2` polyfilling
  20. *Example:*
  21. In case you want to add `Object.values` which is in ES2017:
  22. Find the relevant feature and subfeature on [compat-table](https://kangax.github.io/compat-table/es2016plus/#test-Object_static_methods_Object.values)
  23. and split it with `/`:
  24. `Object static methods / Object.values`
  25. Find the corresponding module on [`core-js@2`](https://github.com/zloirock/core-js/tree/v2/modules):
  26. `es7.object.values.js`
  27. Find required ES version in [`corejs2-built-in-features.js`](https://github.com/babel/babel/blob/master/packages/babel-preset-env/data/corejs2-built-in-features.js) and add the new feature:
  28. ```js
  29. const es = {
  30. //...
  31. "es7.object.values": "Object static methods / Object.values"
  32. }
  33. ```
  34. If you wan to transform a new built-in by `useBuiltIns: 'usage'`, add mapping to related `core-js` modules to [this file](https://github.com/babel/babel/blob/master/packages/babel-preset-env/polyfills/corejs2/built-in-definitions.js).
  35. ### Update data for `core-js@3` polyfilling
  36. Just update the version of [`core-js-compat`](https://github.com/zloirock/core-js/tree/master/packages/core-js-compat) in dependencies.
  37. If you wan to transform a new built-in by `useBuiltIns: 'usage'`, add mapping to related [`core-js`](https://github.com/zloirock/core-js/tree/master/packages/core-js/modules) modules to [this file](https://github.com/babel/babel/blob/master/packages/babel-preset-env/polyfills/corejs3/built-in-definitions.js).
  38. If you want to mark a new proposal as shipped, add it to [this list](https://github.com/babel/babel/blob/master/packages/babel-preset-env/polyfills/corejs3/shipped-proposals.js).
  39. ### Update [`plugins.json`](https://github.com/babel/babel/blob/master/packages/babel-preset-env/data/plugins.json)
  40. Until `compat-table` is a standalone npm module for data we are using the git url
  41. `"compat-table": "kangax/compat-table#[latest-commit-hash]"`,
  42. So we update and then run `npm run build-data`. If there are no changes, then `plugins.json` will be the same.
  43. ## Tests
  44. ### Running tests locally
  45. ```bash
  46. npm test
  47. ```
  48. ### Checking code coverage locally
  49. ```bash
  50. npm run coverage
  51. ```
  52. ### Writing tests
  53. #### General
  54. All the tests for `@babel/preset-env` exist in the `test/fixtures` folder. The
  55. test setup and conventions are exactly the same as testing a Babel plugin, so
  56. please read our [documentation on writing tests](https://github.com/babel/babel/blob/master/CONTRIBUTING.md#babel-plugin-x).
  57. #### Testing the `debug` option
  58. Testing debug output to `stdout` is similar. Under the `test/debug-fixtures`,
  59. create a folder with a descriptive name of your test, and add the following:
  60. * Add a `options.json` file (just as the other tests, this is essentially a
  61. `.babelrc`) with the desired test configuration (required)
  62. * Add a `stdout.txt` file with the expected debug output. For added
  63. convenience, if there is no `stdout.txt` present, the test runner will
  64. generate one for you.