<h2 dir="auto">Bug Report</h2>
<p dir="auto"><strong>Current Behavior</strong><br>
<code class="notranslate">Duplicate declaration "x"</code> is thrown for the below code, this does not happen when natively run by e.g. Chrome. See <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/kzc/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/kzc">@kzc</a>'s comments below for clarification of the ECMA specification where it's also shown that the Bable behavior is incorrect.</p>
<p dir="auto">This does not matter in itself, it doesn't make sense to write this code. However, e.g. Terser correctly treats them as different scopes and reuses variable names as below if it sees that the for-variable is not used (this mostly happens when using <code class="notranslate">.entries()</code> and you at some point stop referencing key or value). This makes it fragile to import some pre-minified code in projects, especially as the error does not show up until it is transpiled by Babel, the code works on its own.</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="for (let x of [1]) {
  let x=1;
}"><pre class="notranslate"><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-kos">[</span><span class="pl-c1">1</span><span class="pl-kos">]</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-c1">1</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto"><strong>Expected behavior/code</strong><br>
<code class="notranslate">x</code> should be shadowed and the code should compile. Again, see <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/kzc/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/kzc">@kzc</a>'s comments below for exact expected behavior.</p>
<p dir="auto"><strong>Environment</strong><br>
Easily replicated in the Babel repl (online), 7.4.0, use es2015 or preset-env.</p>
<p dir="auto"><a href="https://babeljs.io/repl/#?babili=false&amp;browsers=ie%20%3E%3D%2011&amp;build=&amp;builtIns=false&amp;spec=false&amp;loose=true&amp;code_lz=GYewTgBAFANgpgFwgDwiYEDaBGAugSggG8AoCCeJZAXmwG4SBfIA&amp;debug=false&amp;forceAllTransforms=false&amp;shippedProposals=false&amp;circleciRepo=&amp;evaluate=true&amp;fileSize=false&amp;timeTravel=false&amp;sourceType=module&amp;lineWrap=false&amp;presets=env&amp;prettier=false&amp;targets=&amp;version=7.4.5&amp;externalPlugins=" rel="nofollow">https://babeljs.io/repl/#?babili=false&amp;browsers=ie%20%3E%3D%2011&amp;build=&amp;builtIns=false&amp;spec=false&amp;loose=true&amp;code_lz=GYewTgBAFANgpgFwgDwiYEDaBGAugSggG8AoCCeJZAXmwG4SBfIA&amp;debug=false&amp;forceAllTransforms=false&amp;shippedProposals=false&amp;circleciRepo=&amp;evaluate=true&amp;fileSize=false&amp;timeTravel=false&amp;sourceType=module&amp;lineWrap=false&amp;presets=env&amp;prettier=false&amp;targets=&amp;version=7.4.5&amp;externalPlugins=</a></p>
<p dir="auto"><strong>Possible Solution</strong><br>
Do not throw the error, the code should compile.</p>
<h2 dir="auto">Bug Report</h2>
<p dir="auto"><strong>Current Behavior</strong><br>
Throws this exception:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="TypeError: undefined: Duplicate declaration &quot;i&quot;
  1 | 
  2 | for (let i of 'foo') {
&gt; 3 |   let i = 'a';
    |       ^
  4 |   console.log(i);
  5 | }
  6 | "><pre class="notranslate"><code class="notranslate">TypeError: undefined: Duplicate declaration "i"
  1 | 
  2 | for (let i of 'foo') {
&gt; 3 |   let i = 'a';
    |       ^
  4 |   console.log(i);
  5 | }
  6 | 
</code></pre></div>
<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="for (let i of 'foo') {
  let i = 'a';
  console.log(i);
}"><pre class="notranslate"><span class="pl-k">for</span> <span class="pl-kos">(</span><span class="pl-k">let</span> <span class="pl-s1">i</span> <span class="pl-k">of</span> <span class="pl-s">'foo'</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
  <span class="pl-k">let</span> <span class="pl-s1">i</span> <span class="pl-c1">=</span> <span class="pl-s">'a'</span><span class="pl-kos">;</span>
  <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s1">i</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto"><strong>Expected behavior/code</strong><br>
Should prints <code class="notranslate">'a'</code> three times instead of throws this exception.<br>
This is the behaviour in Node and Safari, for example.</p>
<p dir="auto"><strong>Babel Configuration (CLI command)</strong></p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="const output = require('@babel/core').transform(`
for (let i of 'foo') {
  let i = 'a';
  console.log(i);
}
`, {
  presets: ['@babel/preset-env']
});"><pre class="notranslate"><span class="pl-k">const</span> <span class="pl-s1">output</span> <span class="pl-c1">=</span> <span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">'@babel/core'</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">transform</span><span class="pl-kos">(</span><span class="pl-s">`</span>
<span class="pl-s">for (let i of 'foo') {</span>
<span class="pl-s">  let i = 'a';</span>
<span class="pl-s">  console.log(i);</span>
<span class="pl-s">}</span>
<span class="pl-s">`</span><span class="pl-kos">,</span> <span class="pl-kos">{</span>
  <span class="pl-c1">presets</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-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto"><strong>Environment</strong></p>
<ul dir="auto">
<li>Babel version(s): lastest</li>
<li>Node/npm version: Node 9</li>
<li>OS: macOS High Sierra</li>
<li>Monorepo: yes</li>
<li>How you are using Babel: <code class="notranslate">cli</code></li>
</ul>