项目原始demo,不改动
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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. # Contributing
  2. ## Adding a new plugin to support (when approved in the next ECMAScript version)
  3. ### Update [`plugin-features.js`](https://github.com/babel/babel-preset-env/blob/master/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. `transform-exponentiation-operator`
  10. And add them in this structure:
  11. ```js
  12. // es2016
  13. "transform-exponentiation-operator": {
  14. features: [
  15. "exponentiation (**) operator",
  16. ],
  17. },
  18. ```
  19. ### Update [`built-in-features.js`](https://github.com/babel/babel-preset-env/blob/master/data/built-in-features.js)
  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](https://github.com/zloirock/core-js/tree/master/modules):
  26. `es7.object.values.js`
  27. Find 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:
  28. ```js
  29. const es2017 = {
  30. //...
  31. "es7.object.values": "Object static methods / Object.values"
  32. }
  33. ```
  34. ### Update [`plugins.json`](https://github.com/babel/babel-preset-env/blob/master/data/plugins.json)
  35. Until `compat-table` is a standalone npm module for data we are using the git url
  36. `"compat-table": "kangax/compat-table#[latest-commit-hash]"`,
  37. So we update and then run `npm run build-data`. If there are no changes, then `plugins.json` will be the same.
  38. ## Tests
  39. ### Running tests locally
  40. ```bash
  41. npm test
  42. ```
  43. ### Checking code coverage locally
  44. ```bash
  45. npm run coverage
  46. ```
  47. ### Writing tests
  48. #### General
  49. All the tests for `babel-preset-env` exist in the `test/fixtures` folder. The
  50. test setup and conventions are exactly the same as testing a Babel plugin, so
  51. please read our [documentation on writing tests](https://github.com/babel/babel/blob/master/CONTRIBUTING.md#babel-plugin-x).
  52. #### Testing the `debug` option
  53. Testing debug output to `stdout` is similar. Under the `test/debug-fixtures`,
  54. create a folder with a descriptive name of your test, and add the following:
  55. * Add a `options.json` file (just as the other tests, this is essentially a
  56. `.babelrc`) with the desired test configuration (required)
  57. * Add a `stdout.txt` file with the expected debug output. For added
  58. convenience, if there is no `stdout.txt` present, the test runner will
  59. generate one for you.