<blockquote>
<p dir="auto">Issue originally reported by <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/danez/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/danez">@danez</a> in <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="165361588" data-permission-text="Title is private" data-url="https://github.com/babel/babylon/issues/78" data-hovercard-type="issue" data-hovercard-url="/babel/babylon/issues/78/hovercard" href="https://github.com/babel/babylon/issues/78">babel/babylon#78</a></p>
</blockquote>
<p dir="auto">According to the spec when defining multiple variables with the same name, the parser should throw and SyntaxError when using <code class="notranslate">let</code> or <code class="notranslate">const</code>:</p>
<p dir="auto"><code class="notranslate">let foo, foo;</code><br>
or<br>
<code class="notranslate">let foo; let foo;</code></p>
<p dir="auto">From <a href="https://tc39.github.io/ecma262/#sec-let-and-const-declarations-static-semantics-early-errors" rel="nofollow">13.2.1.1</a>:</p>
<blockquote>
<p dir="auto">It is a Syntax Error if the BoundNames of BindingList contains any duplicate entries.</p>
</blockquote>
<p dir="auto">V8 trows an error for <code class="notranslate">let</code> and <code class="notranslate">const</code>, but not vor <code class="notranslate">var</code>.</p>
<p dir="auto">Choose one: is this a bug report or feature request?</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="const t = true

{
  t = false
}

{
  t = false
}"><pre class="notranslate"><span class="pl-k">const</span> <span class="pl-s1">t</span> <span class="pl-c1">=</span> <span class="pl-c1">true</span>

<span class="pl-kos">{</span>
  <span class="pl-s1">t</span> <span class="pl-c1">=</span> <span class="pl-c1">false</span>
<span class="pl-kos">}</span>

<span class="pl-kos">{</span>
  <span class="pl-s1">t</span> <span class="pl-c1">=</span> <span class="pl-c1">false</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: ['es2015']
}"><pre class="notranslate"><span class="pl-kos">{</span>
  <span class="pl-c1">presets</span>: <span class="pl-kos">[</span><span class="pl-s">'es2015'</span><span class="pl-kos">]</span>
<span class="pl-kos">}</span></pre></div>
<h3 dir="auto">Expected Behavior</h3>


<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 t = true;
{
  t = (function () {
    throw new Error(&quot;\&quot;t\&quot; is read-only&quot;);
  }(), false);
}
{
  t = (function () {
    throw new Error(&quot;\&quot;t\&quot; is read-only&quot;);
  }(), false);
}"><pre class="notranslate"><span class="pl-k">var</span> <span class="pl-s1">t</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-s1">t</span> <span class="pl-c1">=</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">throw</span> <span class="pl-k">new</span> <span class="pl-v">Error</span><span class="pl-kos">(</span><span class="pl-s">"\"t\" is read-only"</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-c1">false</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">t</span> <span class="pl-c1">=</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">throw</span> <span class="pl-k">new</span> <span class="pl-v">Error</span><span class="pl-kos">(</span><span class="pl-s">"\"t\" is read-only"</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-c1">false</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span></pre></div>
<h3 dir="auto">Possible Solution</h3>


<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="var _tReadonlyError = new Error(&quot;\&quot;t\&quot; is read-only&quot;);

var t = true;
{
  t = (function () {
    throw _tReadonlyError;
  }(), false);
}
{
  t = (function () {
    throw _tReadonlyError;
  }(), false);
}"><pre class="notranslate"><span class="pl-k">var</span> <span class="pl-s1">_tReadonlyError</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-v">Error</span><span class="pl-kos">(</span><span class="pl-s">"\"t\" is read-only"</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

<span class="pl-k">var</span> <span class="pl-s1">t</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-s1">t</span> <span class="pl-c1">=</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">throw</span> <span class="pl-s1">_tReadonlyError</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-c1">false</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">t</span> <span class="pl-c1">=</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">throw</span> <span class="pl-s1">_tReadonlyError</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-c1">false</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span></pre></div>
<h3 dir="auto">Context</h3>


<p dir="auto">It's just an idea. We can hoist the error (or even the function) to avoid duplicating code so much. Minifiers probably won't catch it in more complex condition.</p>
<h3 dir="auto">Your Environment</h3>

<p dir="auto"><a href="http://babeljs.io/repl#?babili=false&amp;browsers=IE%2011&amp;build=&amp;builtIns=false&amp;code_lz=MYewdgzgLgBLC8cBOBXApgKAwbwzOMiAZgIYA2EmAvlrvgjKRdUA&amp;debug=true&amp;circleciRepo=&amp;evaluate=false&amp;lineWrap=true&amp;presets=es2015&amp;targets=&amp;version=7.0.0-beta.31" rel="nofollow">REPL</a></p>
<p dir="auto">What do you think about that <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/maurobringolf/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/maurobringolf">@maurobringolf</a>?</p>