<p dir="auto">Choose one: is this a bug report or feature request? A bug report.</p>
<p dir="auto">I couldn't tell if this was the same bug as other similar issues. Sorry for any duplication.</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="for(let [a] of c) {
  a=1;
  ()=&gt;a;
}"><pre class="notranslate"><span class="pl-k">for</span><span class="pl-kos">(</span><span class="pl-k">let</span> <span class="pl-kos">[</span><span class="pl-s1">a</span><span class="pl-kos">]</span> <span class="pl-k">of</span> <span class="pl-s1">c</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
  <span class="pl-s1">a</span><span class="pl-c1">=</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-c1">=&gt;</span><span class="pl-s1">a</span><span class="pl-kos">;</span>
<span class="pl-kos">}</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/env', { debug: true } ]
    ]
}"><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/env'</span><span class="pl-kos">,</span> <span class="pl-kos">{</span> <span class="pl-c1">debug</span>: <span class="pl-c1">true</span> <span class="pl-kos">}</span> <span class="pl-kos">]</span>
    <span class="pl-kos">]</span>
<span class="pl-kos">}</span></pre></div>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="BROWSERSLIST='IE 11' npx babel --config-file ./.babelrc test.js"><pre class="notranslate">BROWSERSLIST=<span class="pl-s"><span class="pl-pds">'</span>IE 11<span class="pl-pds">'</span></span> npx babel --config-file ./.babelrc test.js</pre></div>
<p dir="auto">Adding in the destructuring plugin doesn't change anything.</p>
<h3 dir="auto">Expected Behavior</h3>


<p dir="auto">Something like <code class="notranslate">@babel/preset-es2015</code> produces (boilerplate omitted):</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="  var _loop = function _loop() {
    var _step$value = _slicedToArray(_step.value, 1),
        a = _step$value[0];

    a = 1;

    (function () {
      return a;
    });
  };

  for (var _iterator = c[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
    _loop();
  }"><pre class="notranslate">  <span class="pl-k">var</span> <span class="pl-en">_loop</span> <span class="pl-c1">=</span> <span class="pl-k">function</span> <span class="pl-en">_loop</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">_step$value</span> <span class="pl-c1">=</span> <span class="pl-en">_slicedToArray</span><span class="pl-kos">(</span><span class="pl-s1">_step</span><span class="pl-kos">.</span><span class="pl-c1">value</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-s1">a</span> <span class="pl-c1">=</span> <span class="pl-s1">_step$value</span><span class="pl-kos">[</span><span class="pl-c1">0</span><span class="pl-kos">]</span><span class="pl-kos">;</span>

    <span class="pl-s1">a</span> <span class="pl-c1">=</span> <span class="pl-c1">1</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">return</span> <span class="pl-s1">a</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-k">for</span> <span class="pl-kos">(</span><span class="pl-k">var</span> <span class="pl-s1">_iterator</span> <span class="pl-c1">=</span> <span class="pl-s1">c</span><span class="pl-kos">[</span><span class="pl-v">Symbol</span><span class="pl-kos">.</span><span class="pl-c1">iterator</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">_step</span><span class="pl-kos">;</span> <span class="pl-c1">!</span><span class="pl-kos">(</span><span class="pl-s1">_iteratorNormalCompletion</span> <span class="pl-c1">=</span> <span class="pl-kos">(</span><span class="pl-s1">_step</span> <span class="pl-c1">=</span> <span class="pl-s1">_iterator</span><span class="pl-kos">.</span><span class="pl-en">next</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-c1">done</span><span class="pl-kos">)</span><span class="pl-kos">;</span> <span class="pl-s1">_iteratorNormalCompletion</span> <span class="pl-c1">=</span> <span class="pl-c1">true</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-en">_loop</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">Current Behavior</h3>


<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="var _loop = function _loop(_a) {
  _a = 1;

  (function () {
    return _a;
  });

  a = _a;
};

var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;

try {
  for (var _iterator = c[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
    var _ref3 = _step.value;

    var _ref2 = _slicedToArray(_ref3, 1);

    var _a2 = _ref2[0];

    _loop(_a2);
  }"><pre class="notranslate"><span class="pl-k">var</span> <span class="pl-en">_loop</span> <span class="pl-c1">=</span> <span class="pl-k">function</span> <span class="pl-en">_loop</span><span class="pl-kos">(</span><span class="pl-s1">_a</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
  <span class="pl-s1">_a</span> <span class="pl-c1">=</span> <span class="pl-c1">1</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">return</span> <span class="pl-s1">_a</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">a</span> <span class="pl-c1">=</span> <span class="pl-s1">_a</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">_iteratorNormalCompletion</span> <span class="pl-c1">=</span> <span class="pl-c1">true</span><span class="pl-kos">;</span>
<span class="pl-k">var</span> <span class="pl-s1">_didIteratorError</span> <span class="pl-c1">=</span> <span class="pl-c1">false</span><span class="pl-kos">;</span>
<span class="pl-k">var</span> <span class="pl-s1">_iteratorError</span> <span class="pl-c1">=</span> <span class="pl-c1">undefined</span><span class="pl-kos">;</span>

<span class="pl-k">try</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">_iterator</span> <span class="pl-c1">=</span> <span class="pl-s1">c</span><span class="pl-kos">[</span><span class="pl-v">Symbol</span><span class="pl-kos">.</span><span class="pl-c1">iterator</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">_step</span><span class="pl-kos">;</span> <span class="pl-c1">!</span><span class="pl-kos">(</span><span class="pl-s1">_iteratorNormalCompletion</span> <span class="pl-c1">=</span> <span class="pl-kos">(</span><span class="pl-s1">_step</span> <span class="pl-c1">=</span> <span class="pl-s1">_iterator</span><span class="pl-kos">.</span><span class="pl-en">next</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-c1">done</span><span class="pl-kos">)</span><span class="pl-kos">;</span> <span class="pl-s1">_iteratorNormalCompletion</span> <span class="pl-c1">=</span> <span class="pl-c1">true</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-k">var</span> <span class="pl-s1">_ref3</span> <span class="pl-c1">=</span> <span class="pl-s1">_step</span><span class="pl-kos">.</span><span class="pl-c1">value</span><span class="pl-kos">;</span>

    <span class="pl-k">var</span> <span class="pl-s1">_ref2</span> <span class="pl-c1">=</span> <span class="pl-en">_slicedToArray</span><span class="pl-kos">(</span><span class="pl-s1">_ref3</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-k">var</span> <span class="pl-s1">_a2</span> <span class="pl-c1">=</span> <span class="pl-s1">_ref2</span><span class="pl-kos">[</span><span class="pl-c1">0</span><span class="pl-kos">]</span><span class="pl-kos">;</span>

    <span class="pl-en">_loop</span><span class="pl-kos">(</span><span class="pl-s1">_a2</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">The line <code class="notranslate">a = _a</code> assigns to <code class="notranslate">a</code> when no variable <code class="notranslate">a</code> is in scope.</p>
<p dir="auto">It seems <code class="notranslate">@babel/preset-env</code> orders the relevant transforms like this:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="  transform-block-scoping { &quot;ie&quot;:&quot;11&quot; }
  transform-for-of { &quot;ie&quot;:&quot;11&quot; }"><pre class="notranslate"><code class="notranslate">  transform-block-scoping { "ie":"11" }
  transform-for-of { "ie":"11" }
</code></pre></div>
<p dir="auto">when they really should be ordered like this:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="  transform-for-of { &quot;ie&quot;:&quot;11&quot; }
  transform-block-scoping { &quot;ie&quot;:&quot;11&quot; }"><pre class="notranslate"><code class="notranslate">  transform-for-of { "ie":"11" }
  transform-block-scoping { "ie":"11" }
</code></pre></div>
<p dir="auto">or the relevant transformations should be insensitive to ordering.</p>
<p dir="auto">You can run them by themselves to confirm:</p>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="npx babel --no-babelrc --plugins @babel/transform-for-of,@babel/transform-block-scoping test.js # works correctly
npx babel --no-babelrc --plugins @babel/transform-block-scoping,@babel/transform-for-of test.js # breaks"><pre class="notranslate">npx babel --no-babelrc --plugins @babel/transform-for-of,@babel/transform-block-scoping test.js <span class="pl-c"><span class="pl-c">#</span> works correctly</span>
npx babel --no-babelrc --plugins @babel/transform-block-scoping,@babel/transform-for-of test.js <span class="pl-c"><span class="pl-c">#</span> breaks</span></pre></div>
<h3 dir="auto">Context</h3>


<p dir="auto">Our code had a more convoluted example, but basically captured a mutated loop variable within a lambda, and threw an exception at runtime because of the bogus assignment.</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.40</td>
</tr>
<tr>
<td>node</td>
<td>9.8.0</td>
</tr>
<tr>
<td>npm</td>
<td>5.6.0</td>
</tr>
<tr>
<td>Operating System</td>
<td>macOS 10.13.3</td>
</tr>
</tbody>
</table>
<p dir="auto">This generates invalid code:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="({
  foo: (/*string*/ x) =&gt; /*object*/
    10
});"><pre class="notranslate"><span class="pl-kos">(</span><span class="pl-kos">{</span>
  <span class="pl-en">foo</span>: <span class="pl-kos">(</span><span class="pl-c">/*string*/</span> <span class="pl-s1">x</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-c">/*object*/</span>
    <span class="pl-c1">10</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">Returns implicit <code class="notranslate">undefined</code>:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&quot;use strict&quot;;

({
  foo: function foo( /*string*/x) {
    return /*object*/
    10;
  }
});"><pre class="notranslate"><span class="pl-s">"use strict"</span><span class="pl-kos">;</span>

<span class="pl-kos">(</span><span class="pl-kos">{</span>
  <span class="pl-en">foo</span>: <span class="pl-k">function</span> <span class="pl-en">foo</span><span class="pl-kos">(</span> <span class="pl-c">/*string*/</span><span class="pl-s1">x</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-k">return</span> <span class="pl-c">/*object*/</span>
    <span class="pl-c1">10</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>