### `@babel/runtime` - Added `@babel/runtime-corejs3` package and `corejs: 3` options to `@babel/plugin-transform-runtime`. - Added support of instance methods, fixes #8928. - Added flag `proposals` (in `corejs: { version: 3, proposals: true }` format) for support all proposals polyfills from `core-js`. - Used separate directories in runtime for `core-js` entry points with proposals and without. - Used `get-iterator-method` helper for getting iterators, fixes #2500. - As a cheap bonus, added support of IE8- (except some cases of `regenerator`). ### `@babel/polyfill` - Should be deprecated in favor of separate usage required features from `core-js` and `regenerator-runtime` with an informative message. ### `@babel/preset-env` - Uses for built-ins data from [`core-js-compat`](https://github.com/zloirock/core-js/tree/master/packages/core-js-compat) instead of `compat-table` since information from `compat-table` [is not enough](https://github.com/zloirock/core-js/tree/master/packages/core-js-compat). - `useBuilIns` now requires direct setting of `corejs` version option, without it will be used `2` by default and shown deprecation warning. - Added support of minor `core-js` versions for simplify updating in the future. - For preventing some order-related problems, polyfills in the both `core-js@3` plugins added on `post` stage in the order of `core-js-compat` data. - Divided plugins and polyfills parts of `preset-env`, instead of 2 internal plugins for adding polyfills, we have 6: usage and entry versions of plugins for `core-js@2`, ### Current state: `core-js@3`, `regenerator-runtime`. - Added support `samsung` target (for Samsung Internet) since `core-js-compat` and `compat-table` now contains mapping for this, fixes #6602. #### `useBuilIns: entry` with `corejs: 3` - No longer transforms `@babel/polyfill`. - Transforms **all possible** `core-js` entry points to import of related modules (based on data from [`core-js-compat`](https://unpkg.com/core-js-compat@3.0.0-beta.15/entries.json)). - Since of this, we no longer need `shippedProposals` / `proposals` flags with `useBuilIns: entry`. - Removes `regenerator-runtime/runtime` import where it's not required. #### `useBuilIns: usage` with `corejs: 3` - In addition to `shippedProposals`, added flag `proposals` (in `corejs: { version: 3, proposals: true }` format) for polyfill all proposals from `core-js`. - Fixed list of dependencies in built-in definitions. - Improved the way of determination method / built-in name and source of this method. - Adds import of required polyfills on `MemberExpression`, `ObjectPattern`, `in` operator. - Adds import of required polyfills on access to global object properties. - Adds import of all required common iterators on all syntax features which use iterators protocol (`for-of`, destructuring, spread, `yield` delegation, etc.). - Adds import of promises on syntax features which use promises (async functions/generators, dynamic import, etc.), fixes #9250, #7402, etc. ### `core-js@2` stuff I didn't want to tough `core-js@2`-related stuff, however - Fixed some serious errors in definitions which breaks `Object.getOwnPropertySymbols`, `Symbol.toStringTag` logic, `Promise#finally`, `Array#forEach`, etc. - `Array#flatMap` and trim methods moved to stable features as a part of ES2019 and loaded by deprecated `@babel/polyfill` and `@babel/preset-env` with `corejs: 2` option.
104 lines
3.6 KiB
Markdown
104 lines
3.6 KiB
Markdown
# Contributing
|
|
|
|
## Adding a new plugin or polyfill to support (when approved in the next ECMAScript version)
|
|
|
|
### Update [`plugin-features.js`](https://github.com/babel/babel/blob/master/packages/babel-preset-env/data/plugin-features.js)
|
|
|
|
*Example:*
|
|
|
|
If you were going to add `**` which is in ES2016:
|
|
|
|
Find the relevant entries on [compat-table](https://kangax.github.io/compat-table/es2016plus/#test-exponentiation_(**)_operator):
|
|
|
|
`exponentiation (**) operator`
|
|
|
|
Find the corresponding babel plugin:
|
|
|
|
`@babel/plugin-transform-exponentiation-operator`
|
|
|
|
And add them in this structure:
|
|
|
|
```js
|
|
// es2016
|
|
"@babel/plugin-transform-exponentiation-operator": {
|
|
features: [
|
|
"exponentiation (**) operator",
|
|
],
|
|
},
|
|
```
|
|
|
|
### Update data for `core-js@2` polyfilling
|
|
|
|
*Example:*
|
|
|
|
In case you want to add `Object.values` which is in ES2017:
|
|
|
|
Find the relevant feature and subfeature on [compat-table](https://kangax.github.io/compat-table/es2016plus/#test-Object_static_methods_Object.values)
|
|
and split it with `/`:
|
|
|
|
`Object static methods / Object.values`
|
|
|
|
Find the corresponding module on [`core-js@2`](https://github.com/zloirock/core-js/tree/v2/modules):
|
|
|
|
`es7.object.values.js`
|
|
|
|
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:
|
|
|
|
```js
|
|
const es = {
|
|
//...
|
|
"es7.object.values": "Object static methods / Object.values"
|
|
}
|
|
```
|
|
|
|
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).
|
|
|
|
### Update data for `core-js@3` polyfilling
|
|
|
|
Just update the version of [`core-js-compat`](https://github.com/zloirock/core-js/tree/master/packages/core-js-compat) in dependencies.
|
|
|
|
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).
|
|
|
|
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).
|
|
|
|
### Update [`plugins.json`](https://github.com/babel/babel/blob/master/packages/babel-preset-env/data/plugins.json)
|
|
|
|
Until `compat-table` is a standalone npm module for data we are using the git url
|
|
|
|
`"compat-table": "kangax/compat-table#[latest-commit-hash]"`,
|
|
|
|
So we update and then run `npm run build-data`. If there are no changes, then `plugins.json` will be the same.
|
|
|
|
## Tests
|
|
|
|
### Running tests locally
|
|
|
|
```bash
|
|
npm test
|
|
```
|
|
|
|
### Checking code coverage locally
|
|
|
|
```bash
|
|
npm run coverage
|
|
```
|
|
|
|
### Writing tests
|
|
|
|
#### General
|
|
|
|
All the tests for `@babel/preset-env` exist in the `test/fixtures` folder. The
|
|
test setup and conventions are exactly the same as testing a Babel plugin, so
|
|
please read our [documentation on writing tests](https://github.com/babel/babel/blob/master/CONTRIBUTING.md#babel-plugin-x).
|
|
|
|
#### Testing the `debug` option
|
|
|
|
Testing debug output to `stdout` is similar. Under the `test/debug-fixtures`,
|
|
create a folder with a descriptive name of your test, and add the following:
|
|
|
|
* Add a `options.json` file (just as the other tests, this is essentially a
|
|
`.babelrc`) with the desired test configuration (required)
|
|
* Add a `stdout.txt` file with the expected debug output. For added
|
|
convenience, if there is no `stdout.txt` present, the test runner will
|
|
generate one for you.
|