<h3 dir="auto">How are you using Babel?</h3>
<p dir="auto">@babel/eslint-parser</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="import * as t from '@babel/types';
import { parse } from '@babel/parser';
import generator from '@babel/generator';

const code = `
import React from &quot;react&quot;;
// 1111
class App extends React.Component {}
`;

describe('babel', () =&gt; {
  it('clone and generate', () =&gt; {
    expect(
      generator(
        t.cloneNode(
          parse(code, {
            sourceType: 'module',
          }),
          true,
          false,
        ),
        {
          retainLines: true,
        },
      ).code,
    ).toEqual(code);
  });
});"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-c1">*</span> <span class="pl-k">as</span> <span class="pl-s1">t</span> <span class="pl-k">from</span> <span class="pl-s">'@babel/types'</span><span class="pl-kos">;</span>
<span class="pl-k">import</span> <span class="pl-kos">{</span> <span class="pl-s1">parse</span> <span class="pl-kos">}</span> <span class="pl-k">from</span> <span class="pl-s">'@babel/parser'</span><span class="pl-kos">;</span>
<span class="pl-k">import</span> <span class="pl-s1">generator</span> <span class="pl-k">from</span> <span class="pl-s">'@babel/generator'</span><span class="pl-kos">;</span>

<span class="pl-k">const</span> <span class="pl-s1">code</span> <span class="pl-c1">=</span> <span class="pl-s">`</span>
<span class="pl-s">import React from "react";</span>
<span class="pl-s">// 1111</span>
<span class="pl-s">class App extends React.Component {}</span>
<span class="pl-s">`</span><span class="pl-kos">;</span>

<span class="pl-en">describe</span><span class="pl-kos">(</span><span class="pl-s">'babel'</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-kos">{</span>
  <span class="pl-en">it</span><span class="pl-kos">(</span><span class="pl-s">'clone and generate'</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-kos">{</span>
    <span class="pl-en">expect</span><span class="pl-kos">(</span>
      <span class="pl-en">generator</span><span class="pl-kos">(</span>
        <span class="pl-s1">t</span><span class="pl-kos">.</span><span class="pl-en">cloneNode</span><span class="pl-kos">(</span>
          <span class="pl-en">parse</span><span class="pl-kos">(</span><span class="pl-s1">code</span><span class="pl-kos">,</span> <span class="pl-kos">{</span>
            <span class="pl-c1">sourceType</span>: <span class="pl-s">'module'</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">true</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-c1">retainLines</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">code</span><span class="pl-kos">,</span>
    <span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">toEqual</span><span class="pl-kos">(</span><span class="pl-s1">code</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 and expected behavior</h3>
<p dir="auto">current code: with duplicate comments</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import React from &quot;react&quot;;
// 1111
// 1111
class App extends React.Component {}"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-v">React</span> <span class="pl-k">from</span> <span class="pl-s">"react"</span><span class="pl-kos">;</span>
<span class="pl-c">// 1111</span>
<span class="pl-c">// 1111</span>
<span class="pl-k">class</span> <span class="pl-v">App</span> <span class="pl-k">extends</span> <span class="pl-v">React</span><span class="pl-kos">.</span><span class="pl-c1">Component</span> <span class="pl-kos">{</span><span class="pl-kos">}</span></pre></div>
<p dir="auto">expected code</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import React from &quot;react&quot;;
// 1111
class App extends React.Component {}"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-v">React</span> <span class="pl-k">from</span> <span class="pl-s">"react"</span><span class="pl-kos">;</span>
<span class="pl-c">// 1111</span>
<span class="pl-k">class</span> <span class="pl-v">App</span> <span class="pl-k">extends</span> <span class="pl-v">React</span><span class="pl-kos">.</span><span class="pl-c1">Component</span> <span class="pl-kos">{</span><span class="pl-kos">}</span></pre></div>
<h3 dir="auto">Environment</h3>
<div class="highlight highlight-source-json notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="  &quot;dependencies&quot;: {
    &quot;@babel/generator&quot;: &quot;^7.17.10&quot;,
    &quot;@babel/parser&quot;: &quot;^7.17.10&quot;,
    &quot;@babel/traverse&quot;: &quot;^7.17.10&quot;,
    &quot;@babel/types&quot;: &quot;^7.17.10&quot;,
    &quot;@types/babel__generator&quot;: &quot;^7.6.4&quot;,
    &quot;@types/babel__traverse&quot;: &quot;^7.17.1&quot;,
  },"><pre class="notranslate">  <span class="pl-ent">"dependencies"</span>: {
    <span class="pl-ent">"@babel/generator"</span>: <span class="pl-s"><span class="pl-pds">"</span>^7.17.10<span class="pl-pds">"</span></span>,
    <span class="pl-ent">"@babel/parser"</span>: <span class="pl-s"><span class="pl-pds">"</span>^7.17.10<span class="pl-pds">"</span></span>,
    <span class="pl-ent">"@babel/traverse"</span>: <span class="pl-s"><span class="pl-pds">"</span>^7.17.10<span class="pl-pds">"</span></span>,
    <span class="pl-ent">"@babel/types"</span>: <span class="pl-s"><span class="pl-pds">"</span>^7.17.10<span class="pl-pds">"</span></span>,
    <span class="pl-ent">"@types/babel__generator"</span>: <span class="pl-s"><span class="pl-pds">"</span>^7.6.4<span class="pl-pds">"</span></span>,
    <span class="pl-ent">"@types/babel__traverse"</span>: <span class="pl-s"><span class="pl-pds">"</span>^7.17.1<span class="pl-pds">"</span></span>,
  },</pre></div>
<ul dir="auto">
<li>node: v16.14.2</li>
<li>os: macos</li>
</ul>
<h3 dir="auto">Possible solution</h3>
<p dir="auto"><em>No response</em></p>
<h3 dir="auto">Additional context</h3>
<p dir="auto"><em>No response</em></p>
<blockquote>
<p dir="auto">Issue originally made by <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/welefen/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/welefen">@welefen</a></p>
</blockquote>
<h3 dir="auto">Options</h3>
<p dir="auto">Babel 5:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="var data = babel.transform(content, {
  filename: 'file',
  //retainLines: retainLines === undefined ? true : retainLines,
  stage: 0,
  modules: 'common',
  loose: true,
  optional: 'runtime'
});"><pre class="notranslate"><span class="pl-k">var</span> <span class="pl-s1">data</span> <span class="pl-c1">=</span> <span class="pl-s1">babel</span><span class="pl-kos">.</span><span class="pl-en">transform</span><span class="pl-kos">(</span><span class="pl-s1">content</span><span class="pl-kos">,</span> <span class="pl-kos">{</span>
  <span class="pl-c1">filename</span>: <span class="pl-s">'file'</span><span class="pl-kos">,</span>
  <span class="pl-c">//retainLines: retainLines === undefined ? true : retainLines,</span>
  <span class="pl-c1">stage</span>: <span class="pl-c1">0</span><span class="pl-kos">,</span>
  <span class="pl-c1">modules</span>: <span class="pl-s">'common'</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-c1">optional</span>: <span class="pl-s">'runtime'</span>
<span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">Babel 6:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="var data = require(&quot;babel-core&quot;).transform(content, {
  presets: [&quot;es2015-loose&quot;, &quot;stage-1&quot;],
  plugins: ['transform-runtime'],
});"><pre class="notranslate"><span class="pl-k">var</span> <span class="pl-s1">data</span> <span class="pl-c1">=</span> <span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">"babel-core"</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">transform</span><span class="pl-kos">(</span><span class="pl-s1">content</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-s">"es2015-loose"</span><span class="pl-kos">,</span> <span class="pl-s">"stage-1"</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">'transform-runtime'</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">Input code</h3>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="var a = class {
  async test(){
    await Promise.resolve(1);
  }
}
"><pre class="notranslate"><span class="pl-k">var</span> <span class="pl-s1">a</span> <span class="pl-c1">=</span> <span class="pl-k">class</span> <span class="pl-kos">{</span>
  <span class="pl-k">async</span> <span class="pl-en">test</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">{</span>
    <span class="pl-k">await</span> <span class="pl-v">Promise</span><span class="pl-kos">.</span><span class="pl-en">resolve</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-kos">}</span></pre></div>
<h3 dir="auto">Description</h3>
<p dir="auto">use Babel 5 Compiled: 171ms<br>
use Babel 6 Compiled: 6245ms</p>