<blockquote>
<p dir="auto">Issue originally made by David Aurelio (davidaurelio)</p>
</blockquote>
<h3 dir="auto">Bug information</h3>
<ul dir="auto">
<li><strong>Babel version:</strong> repl / 6.11.4</li>
<li><strong>Node version:</strong> 6.3.1</li>
</ul>
<h3 dir="auto">Options</h3>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="just paste in the repl"><pre class="notranslate"><code class="notranslate">just paste in the repl
</code></pre></div>
<h3 dir="auto">Input code</h3>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="for (let i = 0, {length} = a; i &lt; length; i++);"><pre class="notranslate"><code class="notranslate">for (let i = 0, {length} = a; i &lt; length; i++);
</code></pre></div>
<h3 dir="auto">Description</h3>
<p dir="auto">If using destructuring in a loop header, the corresponding variable declaration are wrapped in an IIFE, which effectively hides these variables from the surrounding code.</p>
<p dir="auto">Input code:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="for (let i = 0, {length} = a; i &lt; length; i++);"><pre class="notranslate"><code class="notranslate">for (let i = 0, {length} = a; i &lt; length; i++);
</code></pre></div>
<p dir="auto">output:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="for (function () {
  var i = 0;var _a = a;
  var length = _a.length;
}(); i &lt; length; i++) {}"><pre class="notranslate"><code class="notranslate">for (function () {
  var i = 0;var _a = a;
  var length = _a.length;
}(); i &lt; length; i++) {}
</code></pre></div>
<p dir="auto"><a href="http://babeljs.io/repl/#?evaluate=false&amp;lineWrap=false&amp;presets=es2015%2Creact%2Cstage-0%2Cstage-1%2Cstage-2%2Cstage-3&amp;experimental=false&amp;loose=false&amp;spec=false&amp;code=%0Afor%20(let%20i%20%3D%200%2C%20%7Blength%7D%20%3D%20a%3B%20i%20%3C%20length%3B%20i%2B%2B)%3B" rel="nofollow">http://babeljs.io/repl/#?evaluate=false&amp;lineWrap=false&amp;presets=es2015%2Creact%2Cstage-0%2Cstage-1%2Cstage-2%2Cstage-3&amp;experimental=false&amp;loose=false&amp;spec=false&amp;code=%0Afor%20(let%20i%20%3D%200%2C%20%7Blength%7D%20%3D%20a%3B%20i%20%3C%20length%3B%20i%2B%2B)%3B</a></p>
<p dir="auto">With the latest version of babel and its presets (<code class="notranslate">6.1.18 (babel-core 6.1.21)</code>), running <code class="notranslate">babel --preset es2015 script.js</code> with <code class="notranslate">script.js</code> containing:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="let list = [1, 2, 3, 4]
for ( let i = 0, { length } = list; i &lt; length; i++ ) {
    console.log( i + ': ' + list[i] )
}"><pre class="notranslate"><span class="pl-k">let</span> <span class="pl-s1">list</span> <span class="pl-c1">=</span> <span class="pl-kos">[</span><span class="pl-c1">1</span><span class="pl-kos">,</span> <span class="pl-c1">2</span><span class="pl-kos">,</span> <span class="pl-c1">3</span><span class="pl-kos">,</span> <span class="pl-c1">4</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">i</span> <span class="pl-c1">=</span> <span class="pl-c1">0</span><span class="pl-kos">,</span> <span class="pl-kos">{</span> length <span class="pl-kos">}</span> <span class="pl-c1">=</span> <span class="pl-s1">list</span><span class="pl-kos">;</span> <span class="pl-s1">i</span> <span class="pl-c1">&lt;</span> <span class="pl-s1">length</span><span class="pl-kos">;</span> <span class="pl-s1">i</span><span class="pl-c1">++</span> <span class="pl-kos">)</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-c1">+</span> <span class="pl-s">': '</span> <span class="pl-c1">+</span> <span class="pl-s1">list</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">…gives:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="'use strict';

var list = [1, 2, 3, 4];
for ((function () {
    var i = 0;var length = list.length;
})(); i &lt; length; i++) {
    console.log(i + ': ' + list[i]);
}"><pre class="notranslate"><span class="pl-s">'use strict'</span><span class="pl-kos">;</span>

<span class="pl-k">var</span> <span class="pl-s1">list</span> <span class="pl-c1">=</span> <span class="pl-kos">[</span><span class="pl-c1">1</span><span class="pl-kos">,</span> <span class="pl-c1">2</span><span class="pl-kos">,</span> <span class="pl-c1">3</span><span class="pl-kos">,</span> <span class="pl-c1">4</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-kos">(</span><span class="pl-k">function</span> <span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-k">var</span> <span class="pl-s1">i</span> <span class="pl-c1">=</span> <span class="pl-c1">0</span><span class="pl-kos">;</span><span class="pl-k">var</span> <span class="pl-s1">length</span> <span class="pl-c1">=</span> <span class="pl-s1">list</span><span class="pl-kos">.</span><span class="pl-c1">length</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><span class="pl-kos">;</span> <span class="pl-s1">i</span> <span class="pl-c1">&lt;</span> <span class="pl-s1">length</span><span class="pl-kos">;</span> <span class="pl-s1">i</span><span class="pl-c1">++</span><span class="pl-kos">)</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-c1">+</span> <span class="pl-s">': '</span> <span class="pl-c1">+</span> <span class="pl-s1">list</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>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">…which is totally wrong. The IIFE hides the declared variables from the for-loop body.</p>
<p dir="auto">This issue wasn't there in version <code class="notranslate">6.0.14</code> at least.</p>