<p dir="auto">It's possible this behavior is to-spec, but I don't think so. As I understand it, in the example input code below, the object literal creates a block scope but the function itself creates an additional block scope. Thus, the inner <code class="notranslate">let foo</code> should shadow, not collide with, the outer <code class="notranslate">function foo</code></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="let obj = {
  foo: function foo() {
    let foo = true;
    console.log('foo ran');
  }
};

obj.foo();"><pre class="notranslate"><span class="pl-k">let</span> <span class="pl-s1">obj</span> <span class="pl-c1">=</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-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-k">let</span> <span class="pl-s1">foo</span> <span class="pl-c1">=</span> <span class="pl-c1">true</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-s">'foo ran'</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">obj</span><span class="pl-kos">.</span><span class="pl-en">foo</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<h3 dir="auto">Babel 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="// .babelrc
{}"><pre class="notranslate"><span class="pl-c">// .babelrc</span>
<span class="pl-kos">{</span><span class="pl-kos">}</span></pre></div>
<h3 dir="auto">Expected Behavior</h3>
<p dir="auto">The code should compile with no errors.</p>
<h3 dir="auto">Current Behavior</h3>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="TypeError: index.js: Duplicate declaration &quot;foo&quot;
  2 | let obj = {
  3 |   foo: function foo() {
&gt; 4 |     let foo = true;
    |         ^
  5 |     console.log('foo ran');
  6 |   }
  7 | };
    at File.buildCodeFrameError (/Users/daw/scratch/babel-duplicate-declaration-reproduction/node_modules/babel-core/lib/transformation/file/index.js:431:15)
    at Scope.checkBlockScopedCollisions (/Users/daw/scratch/babel-duplicate-declaration-reproduction/node_modules/babel-traverse/lib/scope/index.js:403:27)
    at Scope.registerBinding (/Users/daw/scratch/babel-duplicate-declaration-reproduction/node_modules/babel-traverse/lib/scope/index.js:597:16)
    at Scope.registerDeclaration (/Users/daw/scratch/babel-duplicate-declaration-reproduction/node_modules/babel-traverse/lib/scope/index.js:501:14)
    at Object.BlockScoped (/Users/daw/scratch/babel-duplicate-declaration-reproduction/node_modules/babel-traverse/lib/scope/index.js:189:28)
    at Object.newFn (/Users/daw/scratch/babel-duplicate-declaration-reproduction/node_modules/babel-traverse/lib/visitors.js:318:17)
    at NodePath._call (/Users/daw/scratch/babel-duplicate-declaration-reproduction/node_modules/babel-traverse/lib/path/context.js:76:18)
    at NodePath.call (/Users/daw/scratch/babel-duplicate-declaration-reproduction/node_modules/babel-traverse/lib/path/context.js:44:14)
    at NodePath.visit (/Users/daw/scratch/babel-duplicate-declaration-reproduction/node_modules/babel-traverse/lib/path/context.js:105:12)
    at TraversalContext.visitQueue (/Users/daw/scratch/babel-duplicate-declaration-reproduction/node_modules/babel-traverse/lib/context.js:150:16)"><pre class="notranslate"><code class="notranslate">TypeError: index.js: Duplicate declaration "foo"
  2 | let obj = {
  3 |   foo: function foo() {
&gt; 4 |     let foo = true;
    |         ^
  5 |     console.log('foo ran');
  6 |   }
  7 | };
    at File.buildCodeFrameError (/Users/daw/scratch/babel-duplicate-declaration-reproduction/node_modules/babel-core/lib/transformation/file/index.js:431:15)
    at Scope.checkBlockScopedCollisions (/Users/daw/scratch/babel-duplicate-declaration-reproduction/node_modules/babel-traverse/lib/scope/index.js:403:27)
    at Scope.registerBinding (/Users/daw/scratch/babel-duplicate-declaration-reproduction/node_modules/babel-traverse/lib/scope/index.js:597:16)
    at Scope.registerDeclaration (/Users/daw/scratch/babel-duplicate-declaration-reproduction/node_modules/babel-traverse/lib/scope/index.js:501:14)
    at Object.BlockScoped (/Users/daw/scratch/babel-duplicate-declaration-reproduction/node_modules/babel-traverse/lib/scope/index.js:189:28)
    at Object.newFn (/Users/daw/scratch/babel-duplicate-declaration-reproduction/node_modules/babel-traverse/lib/visitors.js:318:17)
    at NodePath._call (/Users/daw/scratch/babel-duplicate-declaration-reproduction/node_modules/babel-traverse/lib/path/context.js:76:18)
    at NodePath.call (/Users/daw/scratch/babel-duplicate-declaration-reproduction/node_modules/babel-traverse/lib/path/context.js:44:14)
    at NodePath.visit (/Users/daw/scratch/babel-duplicate-declaration-reproduction/node_modules/babel-traverse/lib/path/context.js:105:12)
    at TraversalContext.visitQueue (/Users/daw/scratch/babel-duplicate-declaration-reproduction/node_modules/babel-traverse/lib/context.js:150:16)
</code></pre></div>
<h3 dir="auto">Context</h3>
<p dir="auto">I originally encountered this trying to run already-compiled code through babel again (long story). The es2015 class transform outputs code that uses this kind of object literal syntax with methods defined via named <code class="notranslate">function</code> expressions. The result is that if you define a variable <code class="notranslate">foo</code> inside a method named <code class="notranslate">foo</code>, the resulting code will throw the above error if run through the babel compiler again.</p>
<h3 dir="auto">Your Environment</h3>
<table role="table">
<thead>
<tr>
<th>software</th>
<th>version</th>
</tr>
</thead>
<tbody>
<tr>
<td>Babel</td>
<td>6.18.0</td>
</tr>
<tr>
<td>node</td>
<td>6.6.0</td>
</tr>
<tr>
<td>yarn</td>
<td>0.17.9</td>
</tr>
<tr>
<td>Operating System</td>
<td>OS X 10.11.6</td>
</tr>
</tbody>
</table>
<blockquote>
<p dir="auto">Issue originally made by <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/FuzzOli87/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/FuzzOli87">@FuzzOli87</a></p>
</blockquote>
<h3 dir="auto">Bug information</h3>
<ul dir="auto">
<li><strong>Babel version:</strong> 6.3.13</li>
<li><strong>Node version:</strong> v5.3.0</li>
<li><strong>npm version:</strong> 3.5.3</li>
</ul>
<h3 dir="auto">Options</h3>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="{
  &quot;presets&quot;: [&quot;es2015&quot;],
  &quot;plugins&quot;: [
    &quot;transform-runtime&quot;
  ]
}"><pre class="notranslate"><code class="notranslate">{
  "presets": ["es2015"],
  "plugins": [
    "transform-runtime"
  ]
}
</code></pre></div>
<h3 dir="auto">Description</h3>
<p dir="auto">When using the runtime plugin, it adds an import statement after transpiling the code leading to errors.</p>
<p dir="auto">Test repo:<br>
<a href="https://github.com/FuzzOli87/test-ava-repo">https://github.com/FuzzOli87/test-ava-repo</a></p>
<p dir="auto">Doing node foo.js  creates the issue where gen.js gets transpiled with an import statement.</p>