<h2 dir="auto">Bug Report</h2>
<p dir="auto">The following code cannot be compiled when using <code class="notranslate">@babel/plugin-proposal-private-methods</code>.<br>
Output: <code class="notranslate">Duplicate declaration "i"</code>.</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="class A {
  #a() {
    const i = 9
  }

  #b() {
    const i = 8
  }
}"><pre class="notranslate"><span class="pl-k">class</span> <span class="pl-v">A</span> <span class="pl-kos">{</span>
  #<span class="pl-en">a</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-k">const</span> <span class="pl-s1">i</span> <span class="pl-c1">=</span> <span class="pl-c1">9</span>
  <span class="pl-kos">}</span>

  #<span class="pl-en">b</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-k">const</span> <span class="pl-s1">i</span> <span class="pl-c1">=</span> <span class="pl-c1">8</span>
  <span class="pl-kos">}</span>
<span class="pl-kos">}</span></pre></div>
<h2 dir="auto">Bug Report</h2>
<p dir="auto"><strong>Current behavior</strong><br>
Switch statements containing closures are generating broken code causing adjacent cases to run. See this minimal reproduction with the default settings:</p>
<p dir="auto"><a href="https://babeljs.io/en/repl#?browsers=defaults&amp;build=&amp;builtIns=false&amp;spec=false&amp;loose=false&amp;code_lz=GYewTgBAFAxiB2BnALhAhhEwIG0CMAugJQQDeAUBBIgO4CWyMAFtMmAK4CmJFVVMaRJwhsuALjKU-_BCggAjCAF4IeANxTpUEkoB8CjdKp1sUUdwVhOaANaGjceMjrwu9qgF9NEAUIjA0ABshCV4jZCYwEBoIeE4YgFEwKLAoACJ2eCs0ZjR5QM40oncIL09yLyA&amp;debug=false&amp;forceAllTransforms=false&amp;shippedProposals=false&amp;circleciRepo=&amp;evaluate=false&amp;fileSize=false&amp;timeTravel=false&amp;sourceType=module&amp;lineWrap=true&amp;presets=env%2Creact%2Cstage-2%2Cenv&amp;prettier=false&amp;targets=&amp;version=7.10.4&amp;externalPlugins=" rel="nofollow">https://babeljs.io/en/repl#?browsers=defaults&amp;build=&amp;builtIns=false&amp;spec=false&amp;loose=false&amp;code_lz=GYewTgBAFAxiB2BnALhAhhEwIG0CMAugJQQDeAUBBIgO4CWyMAFtMmAK4CmJFVVMaRJwhsuALjKU-_BCggAjCAF4IeANxTpUEkoB8CjdKp1sUUdwVhOaANaGjceMjrwu9qgF9NEAUIjA0ABshCV4jZCYwEBoIeE4YgFEwKLAoACJ2eCs0ZjR5QM40oncIL09yLyA&amp;debug=false&amp;forceAllTransforms=false&amp;shippedProposals=false&amp;circleciRepo=&amp;evaluate=false&amp;fileSize=false&amp;timeTravel=false&amp;sourceType=module&amp;lineWrap=true&amp;presets=env%2Creact%2Cstage-2%2Cenv&amp;prettier=false&amp;targets=&amp;version=7.10.4&amp;externalPlugins=</a></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="for (const a of [1]) {
  switch (true) {
    case true: {
      const b = 1;
      () =&gt; b;
      if (true) break;
      continue;
    }
    case false: {
      throw new Error(&quot;unreachable&quot;);
    }
  }
}"><pre class="notranslate"><span class="pl-k">for</span> <span class="pl-kos">(</span><span class="pl-k">const</span> <span class="pl-s1">a</span> <span class="pl-k">of</span> <span class="pl-kos">[</span><span class="pl-c1">1</span><span class="pl-kos">]</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
  <span class="pl-k">switch</span> <span class="pl-kos">(</span><span class="pl-c1">true</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-k">case</span> <span class="pl-c1">true</span>: <span class="pl-kos">{</span>
      <span class="pl-k">const</span> <span class="pl-s1">b</span> <span class="pl-c1">=</span> <span class="pl-c1">1</span><span class="pl-kos">;</span>
      <span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-s1">b</span><span class="pl-kos">;</span>
      <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-c1">true</span><span class="pl-kos">)</span> <span class="pl-k">break</span><span class="pl-kos">;</span>
      <span class="pl-k">continue</span><span class="pl-kos">;</span>
    <span class="pl-kos">}</span>
    <span class="pl-k">case</span> <span class="pl-c1">false</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">"unreachable"</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>Output Code</strong></p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="for (var _i = 0, _arr = [1]; _i &lt; _arr.length; _i++) {
  var a = _arr[_i];

  switch (true) {
    case true:
      {
        var _ret = function () {
          var b = 1;

          (function () {
            return b;
          });

          if (true) return &quot;break&quot;;
          return &quot;continue&quot;;
        }();

        switch (_ret) {
          case &quot;break&quot;:
            break;

          case &quot;continue&quot;:
            continue;
        }
      }

    case false:
      {
        throw new Error(&quot;unreachable&quot;);
      }
  }
}"><pre class="notranslate"><span class="pl-k">for</span> <span class="pl-kos">(</span><span class="pl-k">var</span> <span class="pl-s1">_i</span> <span class="pl-c1">=</span> <span class="pl-c1">0</span><span class="pl-kos">,</span> <span class="pl-s1">_arr</span> <span class="pl-c1">=</span> <span class="pl-kos">[</span><span class="pl-c1">1</span><span class="pl-kos">]</span><span class="pl-kos">;</span> <span class="pl-s1">_i</span> <span class="pl-c1">&lt;</span> <span class="pl-s1">_arr</span><span class="pl-kos">.</span><span class="pl-c1">length</span><span class="pl-kos">;</span> <span class="pl-s1">_i</span><span class="pl-c1">++</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">_arr</span><span class="pl-kos">[</span><span class="pl-s1">_i</span><span class="pl-kos">]</span><span class="pl-kos">;</span>

  <span class="pl-k">switch</span> <span class="pl-kos">(</span><span class="pl-c1">true</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-k">case</span> <span class="pl-c1">true</span>:
      <span class="pl-kos">{</span>
        <span class="pl-k">var</span> <span class="pl-s1">_ret</span> <span class="pl-c1">=</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">var</span> <span class="pl-s1">b</span> <span class="pl-c1">=</span> <span class="pl-c1">1</span><span class="pl-kos">;</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">return</span> <span class="pl-s1">b</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">if</span> <span class="pl-kos">(</span><span class="pl-c1">true</span><span class="pl-kos">)</span> <span class="pl-k">return</span> <span class="pl-s">"break"</span><span class="pl-kos">;</span>
          <span class="pl-k">return</span> <span class="pl-s">"continue"</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-k">switch</span> <span class="pl-kos">(</span><span class="pl-s1">_ret</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
          <span class="pl-k">case</span> <span class="pl-s">"break"</span>:
            <span class="pl-k">break</span><span class="pl-kos">;</span>

          <span class="pl-k">case</span> <span class="pl-s">"continue"</span>:
            <span class="pl-k">continue</span><span class="pl-kos">;</span>
        <span class="pl-kos">}</span>
      <span class="pl-kos">}</span>

    <span class="pl-k">case</span> <span class="pl-c1">false</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">"unreachable"</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>Expected behavior</strong><br>
No error is thrown (the break statement functions as intended, and the false case does not run).</p>
<p dir="auto"><strong>Babel Configuration (babel.config.js, .babelrc, package.json#babel, cli command, .eslintrc)</strong><br>
Defaults. See the REPL.</p>
<p dir="auto"><strong>Environment</strong><br>
Defaults. See the REPL.</p>
<p dir="auto"><strong>Possible Solution</strong><br>
If you want to use a <code class="notranslate">break</code> statement here, it needs to be a labeled break to break the outer loop.</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="switch (_ret) {
  case &quot;break&quot;:
    break outer;

  case &quot;continue&quot;:
    continue;
}"><pre class="notranslate"><span class="pl-k">switch</span> <span class="pl-kos">(</span><span class="pl-s1">_ret</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
  <span class="pl-k">case</span> <span class="pl-s">"break"</span>:
    <span class="pl-k">break</span> outer<span class="pl-kos">;</span>

  <span class="pl-k">case</span> <span class="pl-s">"continue"</span>:
    <span class="pl-k">continue</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">Alternatively, use an if instead of a nested switch.</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="if (_ret === &quot;break&quot;) break;
if (_ret === &quot;continue&quot;) continue;"><pre class="notranslate"><span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-s1">_ret</span> <span class="pl-c1">===</span> <span class="pl-s">"break"</span><span class="pl-kos">)</span> <span class="pl-k">break</span><span class="pl-kos">;</span>
<span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-s1">_ret</span> <span class="pl-c1">===</span> <span class="pl-s">"continue"</span><span class="pl-kos">)</span> <span class="pl-k">continue</span><span class="pl-kos">;</span></pre></div>