<h2 dir="auto">Bug Report</h2>
<p dir="auto"><strong>Current Behavior</strong></p>
<p dir="auto">Sharing an identifier instance between visitors breaks import aliasing.</p>
<p dir="auto"><strong>Input Code</strong></p>
<p dir="auto"><em>babel-plugin.js</em></p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="module.exports = function babelPlugin({ types: t }) {
  return {
    name: 'test',
    visitor: {
      Program: {
        enter(path) {
          const program = path.scope.getProgramParent();
         
          // Alias the import so that it doesn't clash with anything else
          // then reuse it when inseting the calls
          this.localName = program.generateUidIdentifier('_foo');

          // Add `import { foo as _foo } from &quot;bar&quot;`
          [this.last] = program.path.unshiftContainer(
            &quot;body&quot;,
            t.importDeclaration(
              [t.importSpecifier(this.localName, t.identifier(&quot;foo&quot;))],
              t.stringLiteral(&quot;bar&quot;)
            )
          );
        }
      },
      JSXElement(path) {
        // Add `_foo.doSomething()`
        [this.last] = this.last.insertAfter(
          t.expressionStatement(
            t.callExpression(
              t.memberExpression(this.localName, t.identifier(&quot;doSomething&quot;)),
              []
            )
          )
        );
      },
    },
  };
};"><pre class="notranslate"><span class="pl-smi">module</span><span class="pl-kos">.</span><span class="pl-en">exports</span> <span class="pl-c1">=</span> <span class="pl-k">function</span> <span class="pl-en">babelPlugin</span><span class="pl-kos">(</span><span class="pl-kos">{</span> <span class="pl-c1">types</span>: <span class="pl-s1">t</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-kos">{</span>
    <span class="pl-c1">name</span>: <span class="pl-s">'test'</span><span class="pl-kos">,</span>
    <span class="pl-c1">visitor</span>: <span class="pl-kos">{</span>
      <span class="pl-c1">Program</span>: <span class="pl-kos">{</span>
        <span class="pl-en">enter</span><span class="pl-kos">(</span><span class="pl-s1">path</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
          <span class="pl-k">const</span> <span class="pl-s1">program</span> <span class="pl-c1">=</span> <span class="pl-s1">path</span><span class="pl-kos">.</span><span class="pl-c1">scope</span><span class="pl-kos">.</span><span class="pl-en">getProgramParent</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
         
          <span class="pl-c">// Alias the import so that it doesn't clash with anything else</span>
          <span class="pl-c">// then reuse it when inseting the calls</span>
          <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">localName</span> <span class="pl-c1">=</span> <span class="pl-s1">program</span><span class="pl-kos">.</span><span class="pl-en">generateUidIdentifier</span><span class="pl-kos">(</span><span class="pl-s">'_foo'</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

          <span class="pl-c">// Add `import { foo as _foo } from "bar"`</span>
          <span class="pl-kos">[</span><span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">last</span><span class="pl-kos">]</span> <span class="pl-c1">=</span> <span class="pl-s1">program</span><span class="pl-kos">.</span><span class="pl-c1">path</span><span class="pl-kos">.</span><span class="pl-en">unshiftContainer</span><span class="pl-kos">(</span>
            <span class="pl-s">"body"</span><span class="pl-kos">,</span>
            <span class="pl-s1">t</span><span class="pl-kos">.</span><span class="pl-en">importDeclaration</span><span class="pl-kos">(</span>
              <span class="pl-kos">[</span><span class="pl-s1">t</span><span class="pl-kos">.</span><span class="pl-en">importSpecifier</span><span class="pl-kos">(</span><span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">localName</span><span class="pl-kos">,</span> <span class="pl-s1">t</span><span class="pl-kos">.</span><span class="pl-en">identifier</span><span class="pl-kos">(</span><span class="pl-s">"foo"</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-kos">.</span><span class="pl-en">stringLiteral</span><span class="pl-kos">(</span><span class="pl-s">"bar"</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-kos">,</span>
      <span class="pl-en">JSXElement</span><span class="pl-kos">(</span><span class="pl-s1">path</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-c">// Add `_foo.doSomething()`</span>
        <span class="pl-kos">[</span><span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">last</span><span class="pl-kos">]</span> <span class="pl-c1">=</span> <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">last</span><span class="pl-kos">.</span><span class="pl-en">insertAfter</span><span class="pl-kos">(</span>
          <span class="pl-s1">t</span><span class="pl-kos">.</span><span class="pl-en">expressionStatement</span><span class="pl-kos">(</span>
            <span class="pl-s1">t</span><span class="pl-kos">.</span><span class="pl-en">callExpression</span><span class="pl-kos">(</span>
              <span class="pl-s1">t</span><span class="pl-kos">.</span><span class="pl-en">memberExpression</span><span class="pl-kos">(</span><span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">localName</span><span class="pl-kos">,</span> <span class="pl-s1">t</span><span class="pl-kos">.</span><span class="pl-en">identifier</span><span class="pl-kos">(</span><span class="pl-s">"doSomething"</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-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-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"><em>example.js</em></p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import React, { Component } from 'react'
import { Node } from 'some-library'

class App extends Component {
  render() {
    return (
      &lt;&gt;
        &lt;Node uri=&quot;test1.txt&quot;&gt;hello&lt;/Node&gt;
        &lt;Node uri=&quot;test2.txt&quot;&gt;hello&lt;/Node&gt;
        &lt;Node uri=&quot;test3.txt&quot;&gt;hello&lt;/Node&gt;
      &lt;/&gt;
    )
  }
}"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-v">React</span><span class="pl-kos">,</span> <span class="pl-kos">{</span> <span class="pl-v">Component</span> <span class="pl-kos">}</span> <span class="pl-k">from</span> <span class="pl-s">'react'</span>
<span class="pl-k">import</span> <span class="pl-kos">{</span> <span class="pl-v">Node</span> <span class="pl-kos">}</span> <span class="pl-k">from</span> <span class="pl-s">'some-library'</span>

<span class="pl-k">class</span> <span class="pl-v">App</span> <span class="pl-k">extends</span> <span class="pl-v">Component</span> <span class="pl-kos">{</span>
  <span class="pl-en">render</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-kos">(</span>
      <span class="pl-c1">&lt;</span><span class="pl-c1">&gt;</span>
        <span class="pl-c1">&lt;</span><span class="pl-ent">Node</span> <span class="pl-c1">uri</span><span class="pl-c1">=</span><span class="pl-s">"test1.txt"</span><span class="pl-c1">&gt;</span>hello<span class="pl-c1">&lt;</span><span class="pl-c1">/</span><span class="pl-ent">Node</span><span class="pl-c1">&gt;</span>
        <span class="pl-c1">&lt;</span><span class="pl-ent">Node</span> <span class="pl-c1">uri</span><span class="pl-c1">=</span><span class="pl-s">"test2.txt"</span><span class="pl-c1">&gt;</span>hello<span class="pl-c1">&lt;</span><span class="pl-c1">/</span><span class="pl-ent">Node</span><span class="pl-c1">&gt;</span>
        <span class="pl-c1">&lt;</span><span class="pl-ent">Node</span> <span class="pl-c1">uri</span><span class="pl-c1">=</span><span class="pl-s">"test3.txt"</span><span class="pl-c1">&gt;</span>hello<span class="pl-c1">&lt;</span><span class="pl-c1">/</span><span class="pl-ent">Node</span><span class="pl-c1">&gt;</span>
      <span class="pl-c1">&lt;</span><span class="pl-c1">/</span><span class="pl-c1">&gt;</span>
    <span class="pl-kos">)</span>
  <span class="pl-kos">}</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto"><strong>Expected behavior/code</strong></p>
<p dir="auto">Transpiled in following way:</p>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="BABEL_DISABLE_CACHE=1 babel --verbose example.js  --out-dir dist/"><pre class="notranslate">BABEL_DISABLE_CACHE=1 babel --verbose example.js  --out-dir dist/</pre></div>
<p dir="auto">Produces:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="// (...)
var _bar = require(&quot;bar&quot;);
// (...)
_bar.foo.doSomething();
_foo.doSomething();
_foo.doSomething();
// (...)"><pre class="notranslate"><span class="pl-c">// (...)</span>
<span class="pl-k">var</span> <span class="pl-s1">_bar</span> <span class="pl-c1">=</span> <span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">"bar"</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-c">// (...)</span>
<span class="pl-s1">_bar</span><span class="pl-kos">.</span><span class="pl-c1">foo</span><span class="pl-kos">.</span><span class="pl-en">doSomething</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-s1">_foo</span><span class="pl-kos">.</span><span class="pl-en">doSomething</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-s1">_foo</span><span class="pl-kos">.</span><span class="pl-en">doSomething</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-c">// (...)</span></pre></div>
<p dir="auto">Expected result:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="// (...)
var _bar = require(&quot;bar&quot;);
// (...)
_bar.foo.doSomething();
_bar.foo.doSomething();
_bar.foo.doSomething();
// (...)"><pre class="notranslate"><span class="pl-c">// (...)</span>
<span class="pl-k">var</span> <span class="pl-s1">_bar</span> <span class="pl-c1">=</span> <span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">"bar"</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-c">// (...)</span>
<span class="pl-s1">_bar</span><span class="pl-kos">.</span><span class="pl-c1">foo</span><span class="pl-kos">.</span><span class="pl-en">doSomething</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-s1">_bar</span><span class="pl-kos">.</span><span class="pl-c1">foo</span><span class="pl-kos">.</span><span class="pl-en">doSomething</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-s1">_bar</span><span class="pl-kos">.</span><span class="pl-c1">foo</span><span class="pl-kos">.</span><span class="pl-en">doSomething</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-c">// (...)</span></pre></div>
<p dir="auto"><strong>Babel Configuration (.babelrc, package.json, cli command)</strong></p>
<p dir="auto"><em>babel.config.js</em></p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="module.exports = {
  env: {
    development: {
      presets: [[&quot;next/babel&quot;]],
      plugins: [&quot;./babel-plugin&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">env</span>: <span class="pl-kos">{</span>
    <span class="pl-c1">development</span>: <span class="pl-kos">{</span>
      <span class="pl-c1">presets</span>: <span class="pl-kos">[</span><span class="pl-kos">[</span><span class="pl-s">"next/babel"</span><span class="pl-kos">]</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-s">"./babel-plugin"</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-kos">}</span><span class="pl-kos">;</span></pre></div>
<p dir="auto"><strong>Environment</strong></p>
<ul dir="auto">
<li>Babel version(s): v7.5.5</li>
<li>Node/npm version: v12.4.0</li>
<li>OS: macOS v10.14.6</li>
<li>How you are using Babel: cli</li>
</ul>
<p dir="auto"><strong>Possible Solution</strong><br>
I'm a complete rookie when it comes to the babel internals, so I'm probably not fit for producing an actual bugfix, but I can share a workaround that I've made for this issue.</p>
<p dir="auto">I can namely achieve the expected result by recreating the identifier in each visitor instead:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="module.exports = function djediBabelPlugin({ types: t }) {
  return {
    name: 'test',
    visitor: {
      Program: {
        enter(path) {
          const program = path.scope.getProgramParent();
         
          // Rename the import so that it doesn't clash with anything else
          // then reuse it when inseting the calls
          this.localName = program.generateUidIdentifier('_foo').name;

          // Add `import { foo as _foo } from &quot;bar&quot;`
          [this.last] = program.path.unshiftContainer(
            &quot;body&quot;,
            t.importDeclaration(
              [t.importSpecifier(t.identifier(this.localName), t.identifier(&quot;foo&quot;))],
              t.stringLiteral(&quot;bar&quot;)
            )
          );
        }
      },
      JSXElement(path) {
        // Add `_foo.doSomething()`
        [this.last] = this.last.insertAfter(
          t.expressionStatement(
            t.callExpression(
              t.memberExpression(t.identifier(this.localName), t.identifier(&quot;doSomething&quot;)),
              []
            )
          )
        );
      },
    },
  };
};"><pre class="notranslate"><span class="pl-smi">module</span><span class="pl-kos">.</span><span class="pl-en">exports</span> <span class="pl-c1">=</span> <span class="pl-k">function</span> <span class="pl-en">djediBabelPlugin</span><span class="pl-kos">(</span><span class="pl-kos">{</span> <span class="pl-c1">types</span>: <span class="pl-s1">t</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-kos">{</span>
    <span class="pl-c1">name</span>: <span class="pl-s">'test'</span><span class="pl-kos">,</span>
    <span class="pl-c1">visitor</span>: <span class="pl-kos">{</span>
      <span class="pl-c1">Program</span>: <span class="pl-kos">{</span>
        <span class="pl-en">enter</span><span class="pl-kos">(</span><span class="pl-s1">path</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
          <span class="pl-k">const</span> <span class="pl-s1">program</span> <span class="pl-c1">=</span> <span class="pl-s1">path</span><span class="pl-kos">.</span><span class="pl-c1">scope</span><span class="pl-kos">.</span><span class="pl-en">getProgramParent</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
         
          <span class="pl-c">// Rename the import so that it doesn't clash with anything else</span>
          <span class="pl-c">// then reuse it when inseting the calls</span>
          <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">localName</span> <span class="pl-c1">=</span> <span class="pl-s1">program</span><span class="pl-kos">.</span><span class="pl-en">generateUidIdentifier</span><span class="pl-kos">(</span><span class="pl-s">'_foo'</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-c1">name</span><span class="pl-kos">;</span>

          <span class="pl-c">// Add `import { foo as _foo } from "bar"`</span>
          <span class="pl-kos">[</span><span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">last</span><span class="pl-kos">]</span> <span class="pl-c1">=</span> <span class="pl-s1">program</span><span class="pl-kos">.</span><span class="pl-c1">path</span><span class="pl-kos">.</span><span class="pl-en">unshiftContainer</span><span class="pl-kos">(</span>
            <span class="pl-s">"body"</span><span class="pl-kos">,</span>
            <span class="pl-s1">t</span><span class="pl-kos">.</span><span class="pl-en">importDeclaration</span><span class="pl-kos">(</span>
              <span class="pl-kos">[</span><span class="pl-s1">t</span><span class="pl-kos">.</span><span class="pl-en">importSpecifier</span><span class="pl-kos">(</span><span class="pl-s1">t</span><span class="pl-kos">.</span><span class="pl-en">identifier</span><span class="pl-kos">(</span><span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">localName</span><span class="pl-kos">)</span><span class="pl-kos">,</span> <span class="pl-s1">t</span><span class="pl-kos">.</span><span class="pl-en">identifier</span><span class="pl-kos">(</span><span class="pl-s">"foo"</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-kos">.</span><span class="pl-en">stringLiteral</span><span class="pl-kos">(</span><span class="pl-s">"bar"</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-kos">,</span>
      <span class="pl-en">JSXElement</span><span class="pl-kos">(</span><span class="pl-s1">path</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-c">// Add `_foo.doSomething()`</span>
        <span class="pl-kos">[</span><span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">last</span><span class="pl-kos">]</span> <span class="pl-c1">=</span> <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">last</span><span class="pl-kos">.</span><span class="pl-en">insertAfter</span><span class="pl-kos">(</span>
          <span class="pl-s1">t</span><span class="pl-kos">.</span><span class="pl-en">expressionStatement</span><span class="pl-kos">(</span>
            <span class="pl-s1">t</span><span class="pl-kos">.</span><span class="pl-en">callExpression</span><span class="pl-kos">(</span>
              <span class="pl-s1">t</span><span class="pl-kos">.</span><span class="pl-en">memberExpression</span><span class="pl-kos">(</span><span class="pl-s1">t</span><span class="pl-kos">.</span><span class="pl-en">identifier</span><span class="pl-kos">(</span><span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">localName</span><span class="pl-kos">)</span><span class="pl-kos">,</span> <span class="pl-s1">t</span><span class="pl-kos">.</span><span class="pl-en">identifier</span><span class="pl-kos">(</span><span class="pl-s">"doSomething"</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-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-kos">,</span>
  <span class="pl-kos">}</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span><span class="pl-kos">;</span></pre></div>
<h2 dir="auto">This is a bug report</h2>
<p dir="auto">With the <code class="notranslate">@babel/plugin-proposal-class-properties</code> plugin, it appears that property initializers get duplicated in the nested class' constructor when both classes are extended classes that call super.</p>
<h3 dir="auto">Input Code</h3>
<p dir="auto">Minimum repro:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="class A extends C {
  B;
  constructor() {
    super();
    this.B = class B extends C {
      constructor() {
        super();
      }
    };
  }
}
"><pre class="notranslate"><span class="pl-k">class</span> <span class="pl-v">A</span> <span class="pl-k">extends</span> <span class="pl-v">C</span> <span class="pl-kos">{</span>
  <span class="pl-c1">B</span><span class="pl-kos">;</span>
  <span class="pl-en">constructor</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-smi">super</span><span class="pl-kos">(</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">B</span> <span class="pl-c1">=</span> <span class="pl-k">class</span> <span class="pl-v">B</span> <span class="pl-k">extends</span> <span class="pl-v">C</span> <span class="pl-kos">{</span>
      <span class="pl-en">constructor</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-smi">super</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-kos">}</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="module.exports = {
  plugins: [
    ['@babel/plugin-proposal-class-properties', { loose: true }],
  ],
  presets: [
    ['@babel/preset-env', { targets: { node: 'current' } }],
  ],
};"><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">plugins</span>: <span class="pl-kos">[</span>
    <span class="pl-kos">[</span><span class="pl-s">'@babel/plugin-proposal-class-properties'</span><span class="pl-kos">,</span> <span class="pl-kos">{</span> <span class="pl-c1">loose</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-kos">,</span>
  <span class="pl-c1">presets</span>: <span class="pl-kos">[</span>
    <span class="pl-kos">[</span><span class="pl-s">'@babel/preset-env'</span><span class="pl-kos">,</span> <span class="pl-kos">{</span> <span class="pl-c1">targets</span>: <span class="pl-kos">{</span> <span class="pl-c1">node</span>: <span class="pl-s">'current'</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-kos">}</span><span class="pl-kos">;</span></pre></div>
<h3 dir="auto">Expected Behavior</h3>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="class A extends C {
  constructor() {
    super();
    this.B = void 0;
    this.B = class B extends C {
      constructor() {
        super();
      }
    };
  }
}"><pre class="notranslate"><span class="pl-k">class</span> <span class="pl-v">A</span> <span class="pl-k">extends</span> <span class="pl-v">C</span> <span class="pl-kos">{</span>
  <span class="pl-en">constructor</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-smi">super</span><span class="pl-kos">(</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">B</span> <span class="pl-c1">=</span> <span class="pl-k">void</span> <span class="pl-c1">0</span><span class="pl-kos">;</span>
    <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">B</span> <span class="pl-c1">=</span> <span class="pl-k">class</span> <span class="pl-v">B</span> <span class="pl-k">extends</span> <span class="pl-v">C</span> <span class="pl-kos">{</span>
      <span class="pl-en">constructor</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-smi">super</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-kos">}</span>
<span class="pl-kos">}</span></pre></div>
<h3 dir="auto">Current Behavior</h3>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="class A extends C {
  constructor() {
    super();
    this.B = void 0;
    this.B = class B extends C {
      constructor() {
        super();
        this.B = void 0; // THIS LINE SHOULDN'T BE HERE!
      }
    };
  }
}"><pre class="notranslate"><span class="pl-k">class</span> <span class="pl-v">A</span> <span class="pl-k">extends</span> <span class="pl-v">C</span> <span class="pl-kos">{</span>
  <span class="pl-en">constructor</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-smi">super</span><span class="pl-kos">(</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">B</span> <span class="pl-c1">=</span> <span class="pl-k">void</span> <span class="pl-c1">0</span><span class="pl-kos">;</span>
    <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">B</span> <span class="pl-c1">=</span> <span class="pl-k">class</span> <span class="pl-v">B</span> <span class="pl-k">extends</span> <span class="pl-v">C</span> <span class="pl-kos">{</span>
      <span class="pl-en">constructor</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-smi">super</span><span class="pl-kos">(</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">B</span> <span class="pl-c1">=</span> <span class="pl-k">void</span> <span class="pl-c1">0</span><span class="pl-kos">;</span> <span class="pl-c">// THIS LINE SHOULDN'T BE HERE!</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">example (same deal, but with <code class="notranslate">B = 1;</code>): <a href="https://babeljs.io/repl/#?babili=false&amp;browsers=&amp;build=&amp;builtIns=false&amp;code_lz=MYGwhgzhAECC0FMAeAXBA7AJjAwtA3gFDTQBC0AvNAIwDcx0wA9uhCgE4CuwKT7AFAEoCDEhE4AHBAMH0SJFAAsAlhAB05KqEgxyyNFlwj585qw7deM4yfnipMubYC-o6M6evnQA&amp;debug=false&amp;forceAllTransforms=false&amp;shippedProposals=false&amp;circleciRepo=&amp;evaluate=false&amp;fileSize=false&amp;lineWrap=false&amp;presets=stage-2&amp;prettier=false&amp;targets=&amp;version=6.26.0&amp;envVersion=" rel="nofollow">https://babeljs.io/repl/#?babili=false&amp;browsers=&amp;build=&amp;builtIns=false&amp;code_lz=MYGwhgzhAECC0FMAeAXBA7AJjAwtA3gFDTQBC0AvNAIwDcx0wA9uhCgE4CuwKT7AFAEoCDEhE4AHBAMH0SJFAAsAlhAB05KqEgxyyNFlwj585qw7deM4yfnipMubYC-o6M6evnQA&amp;debug=false&amp;forceAllTransforms=false&amp;shippedProposals=false&amp;circleciRepo=&amp;evaluate=false&amp;fileSize=false&amp;lineWrap=false&amp;presets=stage-2&amp;prettier=false&amp;targets=&amp;version=6.26.0&amp;envVersion=</a></p>
<p dir="auto">There is an extra <code class="notranslate">this.B = void 0;</code> which is problematic because it will make <code class="notranslate">this.B = undefined</code> if the inner class is instantiated at any point, overwriting <code class="notranslate">this.B = class ...</code>.</p>
<h3 dir="auto">Possible Solution</h3>
<p dir="auto">There's probably some logic that just naively inserts the initializer based on the constructor pattern without accounting for context?</p>
<h3 dir="auto">Context</h3>
<p dir="auto">I am implementing some React components, where a nested component is defined during the parent's constructor call because it will need to read props from the parent. The reason why there's a property initializer that's set to <code class="notranslate">undefined</code> in the first place is for flow types.</p>
<h3 dir="auto">Your Environment</h3>

<table role="table">
<thead>
<tr>
<th>software</th>
<th>version(s)</th>
</tr>
</thead>
<tbody>
<tr>
<td>Babel</td>
<td>7.0.0-beta.39</td>
</tr>
<tr>
<td>Babylon</td>
<td></td>
</tr>
<tr>
<td>node</td>
<td>8.9.0</td>
</tr>
<tr>
<td>npm</td>
<td>5.5.1</td>
</tr>
<tr>
<td>Operating System</td>
<td>macos</td>
</tr>
</tbody>
</table>