<p dir="auto"><strong>Current behavior</strong></p>
<p dir="auto">Using <a href="https://babeljs.io/repl#?browsers=firefox%2074&amp;build=&amp;builtIns=false&amp;spec=false&amp;loose=false&amp;code_lz=GYVwdgxgLglg9mABMAFATwJQG8BQjlwBOKANgKZSIAeicwimu--5lNAvAwNx7OEUhCSKj3wBfHGKA&amp;debug=false&amp;forceAllTransforms=false&amp;shippedProposals=false&amp;circleciRepo=&amp;evaluate=false&amp;fileSize=false&amp;timeTravel=false&amp;sourceType=module&amp;lineWrap=false&amp;presets=env%2Cenv&amp;prettier=false&amp;targets=&amp;version=7.11.1&amp;externalPlugins=" rel="nofollow">REPL</a> (current/default v7.11.1) with all of checkboxes disabled:</p>
<p dir="auto">(Explicitly disable <code class="notranslate">ENV</code> or enable <code class="notranslate">es2015</code> to see the error via the link above)</p>
<p dir="auto"><strong>Input Code</strong></p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="function f(y){
  for(let x of y){
    let x = y;
    return x;
  }
}"><pre class="notranslate"><span class="pl-k">function</span> <span class="pl-en">f</span><span class="pl-kos">(</span><span class="pl-s1">y</span><span class="pl-kos">)</span><span class="pl-kos">{</span>
  <span class="pl-k">for</span><span class="pl-kos">(</span><span class="pl-k">let</span> <span class="pl-s1">x</span> <span class="pl-k">of</span> <span class="pl-s1">y</span><span class="pl-kos">)</span><span class="pl-kos">{</span>
    <span class="pl-k">let</span> <span class="pl-s1">x</span> <span class="pl-c1">=</span> <span class="pl-s1">y</span><span class="pl-kos">;</span>
    <span class="pl-k">return</span> <span class="pl-s1">x</span><span class="pl-kos">;</span>
  <span class="pl-kos">}</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto"><strong>Expected behavior</strong></p>
<p dir="auto">That should successfully compile just as this code does:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="function f(z){
  for(let x=0; x&lt;y; x++){
    let x = y;
    return x;
  }
}"><pre class="notranslate"><span class="pl-k">function</span> <span class="pl-en">f</span><span class="pl-kos">(</span><span class="pl-s1">z</span><span class="pl-kos">)</span><span class="pl-kos">{</span>
  <span class="pl-k">for</span><span class="pl-kos">(</span><span class="pl-k">let</span> <span class="pl-s1">x</span><span class="pl-c1">=</span><span class="pl-c1">0</span><span class="pl-kos">;</span> <span class="pl-s1">x</span><span class="pl-c1">&lt;</span><span class="pl-s1">y</span><span class="pl-kos">;</span> <span class="pl-s1">x</span><span class="pl-c1">++</span><span class="pl-kos">)</span><span class="pl-kos">{</span>
    <span class="pl-k">let</span> <span class="pl-s1">x</span> <span class="pl-c1">=</span> <span class="pl-s1">y</span><span class="pl-kos">;</span>
    <span class="pl-k">return</span> <span class="pl-s1">x</span><span class="pl-kos">;</span>
  <span class="pl-kos">}</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">Which gives</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&quot;use strict&quot;;

function f(z) {
  for (var x = 0; x &lt; y; x++) {
    var _x = y;
    return _x;
  }
}"><pre class="notranslate"><span class="pl-s">"use strict"</span><span class="pl-kos">;</span>

<span class="pl-k">function</span> <span class="pl-en">f</span><span class="pl-kos">(</span><span class="pl-s1">z</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
  <span class="pl-k">for</span> <span class="pl-kos">(</span><span class="pl-k">var</span> <span class="pl-s1">x</span> <span class="pl-c1">=</span> <span class="pl-c1">0</span><span class="pl-kos">;</span> <span class="pl-s1">x</span> <span class="pl-c1">&lt;</span> <span class="pl-s1">y</span><span class="pl-kos">;</span> <span class="pl-s1">x</span><span class="pl-c1">++</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-k">var</span> <span class="pl-s1">_x</span> <span class="pl-c1">=</span> <span class="pl-s1">y</span><span class="pl-kos">;</span>
    <span class="pl-k">return</span> <span class="pl-s1">_x</span><span class="pl-kos">;</span>
  <span class="pl-kos">}</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto"><strong>Actual behavior</strong></p>
<p dir="auto">However, the error is:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="/repl.js: Duplicate declaration &quot;x&quot;
  1 | function f(y){
  2 |   for(let x of y){
&gt; 3 |     let x = y;
    |         ^
  4 |     return x;
  5 |   }
  6 | }"><pre class="notranslate"><code class="notranslate">/repl.js: Duplicate declaration "x"
  1 | function f(y){
  2 |   for(let x of y){
&gt; 3 |     let x = y;
    |         ^
  4 |     return x;
  5 |   }
  6 | }
</code></pre></div>
<p dir="auto"><strong>Additional context</strong></p>
<p dir="auto">If the ES6 transpiling (<code class="notranslate">let</code> to <code class="notranslate">var</code>) is disabled (ENV: <code class="notranslate">firefox 74</code>), that code correctly gives:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&quot;use strict&quot;;

function f(y) {
  for (let x of y) {
    let x = y;
    return x;
  }
}"><pre class="notranslate"><span class="pl-s">"use strict"</span><span class="pl-kos">;</span>

<span class="pl-k">function</span> <span class="pl-en">f</span><span class="pl-kos">(</span><span class="pl-s1">y</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
  <span class="pl-k">for</span> <span class="pl-kos">(</span><span class="pl-k">let</span> <span class="pl-s1">x</span> <span class="pl-k">of</span> <span class="pl-s1">y</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-k">let</span> <span class="pl-s1">x</span> <span class="pl-c1">=</span> <span class="pl-s1">y</span><span class="pl-kos">;</span>
    <span class="pl-k">return</span> <span class="pl-s1">x</span><span class="pl-kos">;</span>
  <span class="pl-kos">}</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto"><strong>Environment</strong></p>
<ul dir="auto">
<li>Babel version: REPL  v7.11.1</li>
<li>Browser: Firefox 76 on Windows 7</li>
</ul>
<p dir="auto">Choose one: is this a bug report or feature request?<br>
Bug</p>

<h3 dir="auto">Input Code</h3>


<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="// 'a.js'
let a = (obj) =&gt; ({...obj})
// 'b.js'
let a = (obj) =&gt; ({...obj})
// ....and other files that uses object spread"><pre class="notranslate"><span class="pl-c">// 'a.js'</span>
<span class="pl-k">let</span> <span class="pl-en">a</span> <span class="pl-c1">=</span> <span class="pl-kos">(</span><span class="pl-s1">obj</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">(</span><span class="pl-kos">{</span>...<span class="pl-s1">obj</span><span class="pl-kos">}</span><span class="pl-kos">)</span>
<span class="pl-c">// 'b.js'</span>
<span class="pl-k">let</span> <span class="pl-en">a</span> <span class="pl-c1">=</span> <span class="pl-kos">(</span><span class="pl-s1">obj</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">(</span><span class="pl-kos">{</span>...<span class="pl-s1">obj</span><span class="pl-kos">}</span><span class="pl-kos">)</span>
<span class="pl-c">// ....and other files that uses object spread</span></pre></div>
<h3 dir="auto">Babel/Babylon Configuration (.babelrc, package.json, cli command)</h3>

<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="{
  presets: [
    ['@babel/preset-env', {
      modules: false,
      useBuiltIns: 'usage',
      targets: { android: '4.4', ios: '9' }
    }]
  ]
}"><pre class="notranslate"><span class="pl-kos">{</span>
  <span class="pl-c1">presets</span>: <span class="pl-kos">[</span>
    <span class="pl-kos">[</span><span class="pl-s">'@babel/preset-env'</span><span class="pl-kos">,</span> <span class="pl-kos">{</span>
      <span class="pl-c1">modules</span>: <span class="pl-c1">false</span><span class="pl-kos">,</span>
      <span class="pl-c1">useBuiltIns</span>: <span class="pl-s">'usage'</span><span class="pl-kos">,</span>
      <span class="pl-c1">targets</span>: <span class="pl-kos">{</span> <span class="pl-c1">android</span>: <span class="pl-s">'4.4'</span><span class="pl-kos">,</span> <span class="pl-c1">ios</span>: <span class="pl-s">'9'</span> <span class="pl-kos">}</span>
    <span class="pl-kos">}</span><span class="pl-kos">]</span>
  <span class="pl-kos">]</span>
<span class="pl-kos">}</span></pre></div>
<h3 dir="auto">Expected Behavior</h3>
<p dir="auto">Only one occurrence of object spread helpers.</p>
<h3 dir="auto">Current Behavior</h3>
<p dir="auto">Duplicated <code class="notranslate">function _objectSpread() {...}</code> and <code class="notranslate">function _defineProperty(obj, key, value) {...}</code> per file</p>
<h3 dir="auto">Possible Solution</h3>
<p dir="auto">Maybe:</p>
<ol dir="auto">
<li>Make <a href="https://github.com/babel/babel/tree/master/packages/babel-plugin-proposal-object-rest-spread">babel-plugin-proposal-object-rest-spread</a> support <code class="notranslate">useBuiltins: 'usage'</code> as it currently supports only true/false, or treat <code class="notranslate">'usage'</code> as <code class="notranslate">true</code>.</li>
<li>Or allow passing options to individual plugins inside option of <code class="notranslate">preset-env</code>, something like</li>
</ol>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="    ['@babel/preset-env', {
      pluginOptions: {
         '@babel/plugin-proposal-object-rest-spread': {
           useBuiltIns: 'true'
         }
      }
    ]"><pre class="notranslate"><code class="notranslate">    ['@babel/preset-env', {
      pluginOptions: {
         '@babel/plugin-proposal-object-rest-spread': {
           useBuiltIns: 'true'
         }
      }
    ]
</code></pre></div>
<h3 dir="auto">Context</h3>


<p dir="auto">I want to use the new <code class="notranslate">useBuiltIns: 'usage'</code> feature to polyfill on demand, making smaller outputs without manually defining <code class="notranslate">exclude</code> option for ES6/7 features that I don't actually use. However this is instead duplicated object spread helpers that bloats the output.</p>
<h3 dir="auto">Your Environment</h3>
<table role="table">
<thead>
<tr>
<th>software</th>
<th>version(s)</th>
</tr>
</thead>
<tbody>
<tr>
<td>Babel</td>
<td>7.0.0.beta-44</td>
</tr>
<tr>
<td>node</td>
<td>9.10.1</td>
</tr>
<tr>
<td>npm</td>
<td>5.6.0</td>
</tr>
<tr>
<td>Operating System</td>
<td>Windows 10 x64</td>
</tr>
</tbody>
</table>