<h2 dir="auto">Bug Report</h2>
<p dir="auto"><strong>Current Behavior</strong></p>
<p dir="auto">if a normal <code class="notranslate">import</code> statetement is used before a <code class="notranslate">export * from 'somwhere'</code> statement, the latter gets pushed to the top. This causes all code in <code class="notranslate">'somwhere'</code> to be executed before the code from the import.</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="import 'first';
export * from 'second';"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s">'first'</span><span class="pl-kos">;</span>
<span class="pl-k">export</span> <span class="pl-c1">*</span> <span class="pl-k">from</span> <span class="pl-s">'second'</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">becomes</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="'use strict';

Object.defineProperty(exports, &quot;__esModule&quot;, {
  value: true
});

var _second = require('second');

Object.keys(_second).forEach(function (key) {
  if (key === &quot;default&quot; || key === &quot;__esModule&quot;) return;
  Object.defineProperty(exports, key, {
    enumerable: true,
    get: function get() {
      return _second[key];
    }
  });
});

require('first');"><pre class="notranslate"><span class="pl-s">'use strict'</span><span class="pl-kos">;</span>

<span class="pl-v">Object</span><span class="pl-kos">.</span><span class="pl-en">defineProperty</span><span class="pl-kos">(</span><span class="pl-s1">exports</span><span class="pl-kos">,</span> <span class="pl-s">"__esModule"</span><span class="pl-kos">,</span> <span class="pl-kos">{</span>
  <span class="pl-c1">value</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-k">var</span> <span class="pl-s1">_second</span> <span class="pl-c1">=</span> <span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">'second'</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

<span class="pl-v">Object</span><span class="pl-kos">.</span><span class="pl-en">keys</span><span class="pl-kos">(</span><span class="pl-s1">_second</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">forEach</span><span class="pl-kos">(</span><span class="pl-k">function</span> <span class="pl-kos">(</span><span class="pl-s1">key</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
  <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-s1">key</span> <span class="pl-c1">===</span> <span class="pl-s">"default"</span> <span class="pl-c1">||</span> <span class="pl-s1">key</span> <span class="pl-c1">===</span> <span class="pl-s">"__esModule"</span><span class="pl-kos">)</span> <span class="pl-k">return</span><span class="pl-kos">;</span>
  <span class="pl-v">Object</span><span class="pl-kos">.</span><span class="pl-en">defineProperty</span><span class="pl-kos">(</span><span class="pl-s1">exports</span><span class="pl-kos">,</span> <span class="pl-s1">key</span><span class="pl-kos">,</span> <span class="pl-kos">{</span>
    <span class="pl-c1">enumerable</span>: <span class="pl-c1">true</span><span class="pl-kos">,</span>
    <span class="pl-en">get</span>: <span class="pl-k">function</span> <span class="pl-en">get</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">_second</span><span class="pl-kos">[</span><span class="pl-s1">key</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-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

<span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">'first'</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto"><strong>Expected behavior/code</strong></p>
<p dir="auto">I expect the second statement to happen second.</p>
<p dir="auto"><strong>Babel Configuration (.babelrc, package.json, cli command)</strong></p>
<p dir="auto">'try it out' section on babeljs.io</p>
<p dir="auto"><strong>Possible Solution</strong></p>
<p dir="auto">The generated <code class="notranslate">export *</code> code does look like it might be possible to just move it at the right position. I think it is not allowed to export the same name twice in es2015, so no name could be overridden in the <code class="notranslate">exports</code>  object.</p>
<p dir="auto"><strong>Additional context/Screenshots</strong></p>
<blockquote>
<p dir="auto">Issue originally made by <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/loganfsmyth/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/loganfsmyth">@loganfsmyth</a></p>
</blockquote>
<h3 dir="auto">Input code</h3>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import 'foo';
export {foo} from 'bar';"><pre class="notranslate"><code class="notranslate">import 'foo';
export {foo} from 'bar';
</code></pre></div>
<h3 dir="auto">Description</h3>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="'use strict';

Object.defineProperty(exports, &quot;__esModule&quot;, {
  value: true
});
exports.foo = undefined;

var _bar = require('bar');

Object.defineProperty(exports, 'foo', {
  enumerable: true,
  get: function get() {
    return _bar.foo;
  }
});

require('foo');"><pre class="notranslate"><code class="notranslate">'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.foo = undefined;

var _bar = require('bar');

Object.defineProperty(exports, 'foo', {
  enumerable: true,
  get: function get() {
    return _bar.foo;
  }
});

require('foo');
</code></pre></div>
<p dir="auto">Note that <code class="notranslate">foo</code> loads after <code class="notranslate">bar</code>.</p>