UNPKG

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