Contributing——模具行业从业者必备知识手册
-
<h2>Contributing</h2>
<h3>Adding a new plugin or polyfill to support (when approved in the next ECMAScript version)</h3>
<h4>Update
plugin-features.js</h4><p><em>Example:</em></p>
<p>If you were going to add <code>**</code> which is in ES2016:</p>
<p>Find the relevant entries on <a href="https://kangax.github.io/compat-table/es2016plus/#test-exponentiation_(**">compat-table</a>_operator):</p>
<p><code>exponentiation (**) operator</code></p>
<p>Find the corresponding babel plugin:</p>
<p><code>@babel/plugin-transform-exponentiation-operator</code></p>
<p>And add them in this structure:</p>
<pre><code>
// es2016
"@babel/plugin-transform-exponentiation-operator": {
features: [
"exponentiation (**) operator",
],
},
</code></pre><h4>Update data for
core-js@2polyfilling</h4><p><em>Example:</em></p>
<p>In case you want to add <code>Object.values</code> which is in ES2017:</p>
<p>Find the relevant feature and subfeature on <a href="https://kangax.github.io/compat-table/es2016plus/#test-Object_static_methods_Object.values">compat-table</a></p>
<p>and split it with <code>/</code>:</p><p><code>Object static methods / Object.values</code></p>
<p>Find the corresponding module on <a href="https://github.com/zloirock/core-js/tree/v2/modules"><code>core-js@2</code></a>:</p>
<p><code>es7.object.values.js</code></p>
<p>Find required ES version in <a href="https://github.com/babel/babel/blob/main/packages/babel-preset-env/data/corejs2-built-in-features.js"><code>corejs2-built-in-features.js</code></a> and add the new feature:</p>
<pre><code>
const es = {
//...
"es7.object.values": "Object static methods / Object.values"
}
</code></pre><p>If you want to transform a new built-in by <code>useBuiltIns: 'usage'</code>, add mapping to related <code>core-js</code> modules to <a href="https://github.com/babel/babel/blob/main/packages/babel-preset-env/polyfills/corejs2/built-in-definitions.js">this file</a>.</p>
<h4>Update data for
core-js@3polyfilling</h4><p>Just update the version of <a href="https://github.com/zloirock/core-js/tree/main/packages/core-js-compat"><code>core-js-compat</code></a> in dependencies.</p>
<p>If you want to transform a new built-in by <code>useBuiltIns: 'usage'</code>, add mapping to related <a href="https://github.com/zloirock/core-js/tree/main/packages/core-js/modules"><code>core-js</code></a> modules to <a href="https://github.com/babel/babel/blob/main/packages/babel-preset-env/polyfills/corejs3/built-in-definitions.js">this file</a>.</p>
<p>If you want to mark a new proposal as shipped, add it to <a href="https://github.com/babel/babel/blob/main/packages/babel-preset-env/polyfills/corejs3/shipped-proposals.js">this list</a>.</p>
<h4>Update
plugins.json</h4><p>Until <code>compat-table</code> is a standalone npm module for data we are using the git commit in <code>packages/babel-compat-data/scripts/download-compat-table.sh</code></p>
<p><code>COMPAT_TABLE_COMMIT=[latest-commit-hash]</code>,</p>
<p>So we update and then run <code>npm run build-data</code>. If there are no changes, then <code>plugins.json</code> will be the same.</p>
<h3>Tests</h3>
<h4>Running tests</h4>
<p>See general <a href="https://github.com/babel/babel/blob/main/CONTRIBUTING.md#running-lintingtests">CONTRIBUTING.md</a>.</p><h4>Writing tests</h4>
<p>#### General</p>
<p>All the tests for <code>@babel/preset-env</code> exist in the <code>test/fixtures</code> folder. The</p>
<p>test setup and conventions are exactly the same as testing a Babel plugin, so</p>
<p>please read our <a href="https://github.com/babel/babel/blob/main/CONTRIBUTING.md#babel-plugin-x">documentation on writing tests</a>.</p><p>#### Testing the <code>debug</code> option</p>
<p>Testing debug output to <code>stdout</code> is similar. Under the <code>test/debug-fixtures</code>,</p>
<p>create a folder with a descriptive name of your test, and add the following:</p><ul>
<li>Add a <code>options.json</code> file (just as the other tests, this is</li>
</ul><hr>
<p>哪个方案更实用?欢迎投票讨论。</p>