<blockquote>
<p dir="auto">Issue originally made by <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/spicyj/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/spicyj">@spicyj</a></p>
</blockquote>
<h3 dir="auto">Bug information</h3>
<ul dir="auto">
<li><strong>Babel version:</strong> 6.11.6</li>
<li><strong>Node version:</strong> 6</li>
<li><strong>npm version:</strong> 3</li>
</ul>
<h3 dir="auto">Description</h3>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="var traverse = require('babel-traverse').default, babylon = require('babylon');
traverse(babylon.parse('let x; let x;'))"><pre class="notranslate"><code class="notranslate">var traverse = require('babel-traverse').default, babylon = require('babylon');
traverse(babylon.parse('let x; let x;'))
</code></pre></div>
<p dir="auto">should throw an error about duplicate bindings, but it throws</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="TypeError: Cannot read property file of undefined
    at Scope.checkBlockScopedCollisions (node_modules/babel-traverse/lib/scope/index.js:492:21)
    at Scope.registerBinding (node_modules/babel-traverse/lib/scope/index.js:681:16)
    at Scope.registerDeclaration (node_modules/babel-traverse/lib/scope/index.js:580:14)
    ...
    at TraversalContext.visit (node_modules/babel-traverse/lib/context.js:219:19)
    at Function.traverse.node (node_modules/babel-traverse/lib/index.js:171:17)
    at traverse (node_modules/babel-traverse/lib/index.js:90:12)
    at repl:1:81"><pre class="notranslate"><code class="notranslate">TypeError: Cannot read property file of undefined
    at Scope.checkBlockScopedCollisions (node_modules/babel-traverse/lib/scope/index.js:492:21)
    at Scope.registerBinding (node_modules/babel-traverse/lib/scope/index.js:681:16)
    at Scope.registerDeclaration (node_modules/babel-traverse/lib/scope/index.js:580:14)
    ...
    at TraversalContext.visit (node_modules/babel-traverse/lib/context.js:219:19)
    at Function.traverse.node (node_modules/babel-traverse/lib/index.js:171:17)
    at traverse (node_modules/babel-traverse/lib/index.js:90:12)
    at repl:1:81
</code></pre></div>
<p dir="auto">instead because this.hub is undefined on this line: </p><div class="Box Box--condensed my-2">
  <div class="Box-header f6">
    <p class="mb-0 text-bold">
      <a href="https://github.com/babel/babel/blob/dce9ee9d80547a421cf521a645b84049560647bd/packages/babel-traverse/src/scope/index.js#L350">babel/packages/babel-traverse/src/scope/index.js</a>
    </p>
    <p class="mb-0 color-fg-muted">
         Line 350
      in
      <a data-pjax="true" class="commit-tease-sha" href="/babel/babel/commit/dce9ee9d80547a421cf521a645b84049560647bd">dce9ee9</a>
    </p>
  </div>
  <div itemprop="text" class="Box-body p-0 blob-wrapper blob-wrapper-embedded data">
    <table class="highlight tab-size mb-0 js-file-line-container" data-tab-size="8" data-paste-markdown-skip="">

        <tbody><tr class="border-0">
          <td id="L350" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="350"></td>
          <td id="LC350" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line"> <span class="pl-k">throw</span> <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">hub</span><span class="pl-kos">.</span><span class="pl-c1">file</span><span class="pl-kos">.</span><span class="pl-en">buildCodeFrameError</span><span class="pl-kos">(</span><span class="pl-s1">id</span><span class="pl-kos">,</span> <span class="pl-s1">messages</span><span class="pl-kos">.</span><span class="pl-en">get</span><span class="pl-kos">(</span><span class="pl-s">"scopeDuplicateDeclaration"</span><span class="pl-kos">,</span> <span class="pl-s1">name</span><span class="pl-kos">)</span><span class="pl-kos">,</span> <span class="pl-v">TypeError</span><span class="pl-kos">)</span><span class="pl-kos">;</span> </td>
        </tr>
    </tbody></table>
  </div>
</div>
.<p></p>
<p dir="auto">Can we fix this as-is? Do I need to pass in a File object of some sort (how would I construct one)?</p>
<p dir="auto">(I'm actually passing <code class="notranslate">sourceFilename</code> and <code class="notranslate">code</code> to traverse already.)</p>
<p dir="auto">Since v1.11, 6to5 is modifying the source code in places where there are no es6 features.</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="var foo = function(bar) { this.foo = bar; };

var arr = [
  'item1',
  'item2',
  ...
];

var bar = 'bar',
    baz = 'baz';"><pre class="notranslate"><span class="pl-k">var</span> <span class="pl-en">foo</span> <span class="pl-c1">=</span> <span class="pl-k">function</span><span class="pl-kos">(</span><span class="pl-s1">bar</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">foo</span> <span class="pl-c1">=</span> <span class="pl-s1">bar</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">arr</span> <span class="pl-c1">=</span> <span class="pl-kos">[</span>
  <span class="pl-s">'item1'</span><span class="pl-kos">,</span>
  <span class="pl-s">'item2'</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">bar</span> <span class="pl-c1">=</span> <span class="pl-s">'bar'</span><span class="pl-kos">,</span>
    <span class="pl-s1">baz</span> <span class="pl-c1">=</span> <span class="pl-s">'baz'</span><span class="pl-kos">;</span></pre></div>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="var foo = function (bar) {
  this.foo = bar;
};

var arr = [&quot;item1&quot;, &quot;item2&quot;, ...];

var bar = &quot;bar&quot;, baz = &quot;baz&quot;;"><pre class="notranslate"><span class="pl-k">var</span> <span class="pl-en">foo</span> <span class="pl-c1">=</span> <span class="pl-k">function</span> <span class="pl-kos">(</span><span class="pl-s1">bar</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">foo</span> <span class="pl-c1">=</span> <span class="pl-s1">bar</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">arr</span> <span class="pl-c1">=</span> <span class="pl-kos">[</span><span class="pl-s">"item1"</span><span class="pl-kos">,</span> <span class="pl-s">"item2"</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">bar</span> <span class="pl-c1">=</span> <span class="pl-s">"bar"</span><span class="pl-kos">,</span> <span class="pl-s1">baz</span> <span class="pl-c1">=</span> <span class="pl-s">"baz"</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">Some es6 features are also getting more modifications than before.</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="toString() {
  return `${this.name}: ${this.message}` + (
    this.url ? ` See: ${this.url}` : ''
  );
}
// used to (&lt;1.11) become:
toString: function() {
  return &quot;&quot; + this.name + &quot;: &quot; + this.message + (
    this.url ? &quot; See: &quot; + this.url : ''
  );
}
// and is now (1.11)
toString: function() {
  return &quot;&quot; + this.name + &quot;: &quot; + this.message + (this.url ? &quot; See: &quot; + this.url : &quot;&quot;);
}"><pre class="notranslate"><span class="pl-en">toString</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-s">`<span class="pl-s1"><span class="pl-kos">${</span><span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">name</span><span class="pl-kos">}</span></span>: <span class="pl-s1"><span class="pl-kos">${</span><span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">message</span><span class="pl-kos">}</span></span>`</span> <span class="pl-c1">+</span> <span class="pl-kos">(</span>
    <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">url</span> ? <span class="pl-s">` See: <span class="pl-s1"><span class="pl-kos">${</span><span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">url</span><span class="pl-kos">}</span></span>`</span> : <span class="pl-s">''</span>
  <span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>
<span class="pl-c">// used to (&lt;1.11) become:</span>
toString: <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-s">""</span> <span class="pl-c1">+</span> <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">name</span> <span class="pl-c1">+</span> <span class="pl-s">": "</span> <span class="pl-c1">+</span> <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">message</span> <span class="pl-c1">+</span> <span class="pl-kos">(</span>
    <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">url</span> ? <span class="pl-s">" See: "</span> <span class="pl-c1">+</span> <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">url</span> : <span class="pl-s">''</span>
  <span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>
<span class="pl-c">// and is now (1.11)</span>
toString: <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-s">""</span> <span class="pl-c1">+</span> <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">name</span> <span class="pl-c1">+</span> <span class="pl-s">": "</span> <span class="pl-c1">+</span> <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">message</span> <span class="pl-c1">+</span> <span class="pl-kos">(</span><span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">url</span> ? <span class="pl-s">" See: "</span> <span class="pl-c1">+</span> <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">url</span> : <span class="pl-s">""</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span></pre></div>