<h2 dir="auto">Bug Report</h2>
<p dir="auto"><strong>Current Behavior</strong></p>
<p dir="auto">babel is confused about a duplicate declaration when a type is imported and a value with the same name is declared locally. See code below.</p>
<p dir="auto"><strong>Input Code</strong></p>
<p dir="auto">The following code results in a "Duplicate declaration" error, but is accepted by TypeScript (the compiler). It's because the <code class="notranslate">SomeThing</code> import is a type (for example <code class="notranslate">export interface SomeThing{}</code>), whereas the local const declaration is a value, so the two are not actually in any conflict.</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import { SomeThing } from './module';
const SomeThing = 1;"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-kos">{</span> <span class="pl-v">SomeThing</span> <span class="pl-kos">}</span> <span class="pl-k">from</span> <span class="pl-s">'./module'</span><span class="pl-kos">;</span>
<span class="pl-k">const</span> <span class="pl-v">SomeThing</span> <span class="pl-c1">=</span> <span class="pl-c1">1</span><span class="pl-kos">;</span></pre></div>
<p dir="auto"><strong>Expected behavior/code</strong></p>
<p dir="auto">The babel typescript transform should accept the same code as the typescript compiler.</p>
<p dir="auto"><strong>Babel Configuration (.babelrc, package.json, cli command)</strong></p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="module.exports = {
  presets: [
    &quot;next/babel&quot;,
    &quot;@zeit/next-typescript/babel&quot;
  ],
  plugins: [
    [&quot;react-intl&quot;, { messagesDir: &quot;./locale/en/messages/&quot; }],
    [&quot;emotion&quot;, { inline: true, autoLabel: true }],
    [&quot;transform-define&quot;, require(&quot;./env.js&quot;)]
  ]
};"><pre class="notranslate"><span class="pl-smi">module</span><span class="pl-kos">.</span><span class="pl-c1">exports</span> <span class="pl-c1">=</span> <span class="pl-kos">{</span>
  <span class="pl-c1">presets</span>: <span class="pl-kos">[</span>
    <span class="pl-s">"next/babel"</span><span class="pl-kos">,</span>
    <span class="pl-s">"@zeit/next-typescript/babel"</span>
  <span class="pl-kos">]</span><span class="pl-kos">,</span>
  <span class="pl-c1">plugins</span>: <span class="pl-kos">[</span>
    <span class="pl-kos">[</span><span class="pl-s">"react-intl"</span><span class="pl-kos">,</span> <span class="pl-kos">{</span> <span class="pl-c1">messagesDir</span>: <span class="pl-s">"./locale/en/messages/"</span> <span class="pl-kos">}</span><span class="pl-kos">]</span><span class="pl-kos">,</span>
    <span class="pl-kos">[</span><span class="pl-s">"emotion"</span><span class="pl-kos">,</span> <span class="pl-kos">{</span> <span class="pl-c1">inline</span>: <span class="pl-c1">true</span><span class="pl-kos">,</span> <span class="pl-c1">autoLabel</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><span class="pl-s">"transform-define"</span><span class="pl-kos">,</span> <span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">"./env.js"</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>
<p dir="auto"><strong>Environment</strong></p>
<ul dir="auto">
<li>Babel version(s): @babel/plugin-syntax-typescript@7.0.0-beta.47</li>
</ul>
<p dir="auto">There's a bug where a variable _ref isn't defined when you declare a generator using a spread.</p>
<p dir="auto">ES6:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="let a = function*(args) {
  this.runRoute(...args);
};"><pre class="notranslate"><span class="pl-k">let</span> <span class="pl-s1">a</span> <span class="pl-c1">=</span> <span class="pl-k">function</span><span class="pl-c1">*</span><span class="pl-kos">(</span><span class="pl-s1">args</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
  <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-en">runRoute</span><span class="pl-kos">(</span>...<span class="pl-s1">args</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">Compiled:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&quot;use strict&quot;;

var _toArray = function (arr) {
  return Array.isArray(arr) ? arr : Array.from(arr);
};

var a = regeneratorRuntime.mark(function callee$0$0(args) {
  return regeneratorRuntime.wrap(function callee$0$0$(context$1$0) {
    while (1) switch (context$1$0.prev = context$1$0.next) {
      case 0:
        (_ref = this).runRoute.apply(_ref, _toArray(args)); // _ref is not defined
      case 1:
      case &quot;end&quot;:
        return context$1$0.stop();
    }
  }, callee$0$0, this);
});"><pre class="notranslate"><span class="pl-s">"use strict"</span><span class="pl-kos">;</span>

<span class="pl-k">var</span> <span class="pl-en">_toArray</span> <span class="pl-c1">=</span> <span class="pl-k">function</span> <span class="pl-kos">(</span><span class="pl-s1">arr</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
  <span class="pl-k">return</span> <span class="pl-v">Array</span><span class="pl-kos">.</span><span class="pl-en">isArray</span><span class="pl-kos">(</span><span class="pl-s1">arr</span><span class="pl-kos">)</span> ? <span class="pl-s1">arr</span> : <span class="pl-v">Array</span><span class="pl-kos">.</span><span class="pl-en">from</span><span class="pl-kos">(</span><span class="pl-s1">arr</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">var</span> <span class="pl-s1">a</span> <span class="pl-c1">=</span> <span class="pl-s1">regeneratorRuntime</span><span class="pl-kos">.</span><span class="pl-en">mark</span><span class="pl-kos">(</span><span class="pl-k">function</span> <span class="pl-en">callee$0$0</span><span class="pl-kos">(</span><span class="pl-s1">args</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
  <span class="pl-k">return</span> <span class="pl-s1">regeneratorRuntime</span><span class="pl-kos">.</span><span class="pl-en">wrap</span><span class="pl-kos">(</span><span class="pl-k">function</span> <span class="pl-en">callee$0$0$</span><span class="pl-kos">(</span><span class="pl-s1">context$1$0</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-k">while</span> <span class="pl-kos">(</span><span class="pl-c1">1</span><span class="pl-kos">)</span> <span class="pl-k">switch</span> <span class="pl-kos">(</span><span class="pl-s1">context$1$0</span><span class="pl-kos">.</span><span class="pl-c1">prev</span> <span class="pl-c1">=</span> <span class="pl-s1">context$1$0</span><span class="pl-kos">.</span><span class="pl-c1">next</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
      <span class="pl-k">case</span> <span class="pl-c1">0</span>:
        <span class="pl-kos">(</span><span class="pl-s1">_ref</span> <span class="pl-c1">=</span> <span class="pl-smi">this</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-c1">runRoute</span><span class="pl-kos">.</span><span class="pl-en">apply</span><span class="pl-kos">(</span><span class="pl-s1">_ref</span><span class="pl-kos">,</span> <span class="pl-en">_toArray</span><span class="pl-kos">(</span><span class="pl-s1">args</span><span class="pl-kos">)</span><span class="pl-kos">)</span><span class="pl-kos">;</span> <span class="pl-c">// _ref is not defined</span>
      <span class="pl-k">case</span> <span class="pl-c1">1</span>:
      <span class="pl-k">case</span> <span class="pl-s">"end"</span>:
        <span class="pl-k">return</span> <span class="pl-s1">context$1$0</span><span class="pl-kos">.</span><span class="pl-en">stop</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">callee$0$0</span><span class="pl-kos">,</span> <span class="pl-smi">this</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>
<p dir="auto">You can <a href="http://6to5.org/repl/#?experimental=true&amp;playground=true&amp;evaluate=true&amp;code=%0Alet%20a%20%3D%20function*%28args%29%20%7B%0A%20%20this.runRoute%28...args%29%3B%0A%7D%3B%0A" rel="nofollow">check it out</a></p>
<p dir="auto">I think the requirements to duplicate this bug are the following:</p>
<ul dir="auto">
<li>The function must be a generator.</li>
<li>The function must use a spread.</li>
<li>The function must be calling another function on <code class="notranslate">this</code>.</li>
</ul>
<p dir="auto">You really just need to add a <code class="notranslate">let _ref = this;</code> sometime before.</p>
<p dir="auto">For now, I'll just have to write the spread manually:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="let a = function*(args) {
  this.runRoute.apply(this, args);
};"><pre class="notranslate"><span class="pl-k">let</span> <span class="pl-s1">a</span> <span class="pl-c1">=</span> <span class="pl-k">function</span><span class="pl-c1">*</span><span class="pl-kos">(</span><span class="pl-s1">args</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
  <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">runRoute</span><span class="pl-kos">.</span><span class="pl-en">apply</span><span class="pl-kos">(</span><span class="pl-smi">this</span><span class="pl-kos">,</span> <span class="pl-s1">args</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span><span class="pl-kos">;</span></pre></div>