Repository: babel/babel (TypeScript)

Issue:
Babel transpiler dislocates comments when fat arrow functions are used! 
## Bug Report
Babel transpiler dislocates the jsdocs comments to a separate location in the output file when fat arrow functions are used in a class.

**Current Behavior**
for example, the following function has associated jsdoc comments:
```
/**
     * Promise factory to generate a Bearer Token for write_access to private data.
     * The Unsplash API uses OAuth2 to authenticate and authorize Unsplash users. 
     * Unsplash’s OAuth2 paths live at https://unsplash.com/oauth/.
     * @function generateBearerToken
     * @memberof UnsplashApi
     * @returns {Object} - The user's Access Token JSON data object.
     */
    generateBearerToken = () => {
        let url = this.BEARER_TOKEN_URL +
            '?client_id=' + (this.access_key) +
            '&client_secret=' + (this.secret_key) +
            '&redirect_uri=' + (this.redirect_uri) +
            '&code=' + (this.code) +
            '&grant_type=' + (this.grant_type);
        return this.fetchUrl(url, 'POST');
    };
```
which should produce compiled code like this:
```
/**
     * Promise factory to generate a Bearer Token for write_access to private data.
     * The Unsplash API uses OAuth2 to authenticate and authorize Unsplash users. 
     * Unsplash’s OAuth2 paths live at https://unsplash.com/oauth/.
     * @function generateBearerToken
     * @memberof UnsplashApi
     * @returns {Object} - The user's Access Token JSON data object.
     */
  this.generateBearerToken = function () {
        var url = _this.BEARER_TOKEN_URL + '?client_id=' + _this.access_key + '&client_secret=' + _this.secret_key + '&redirect_uri=' + _this.redirect_uri + '&code=' + _this.code + '&grant_type=' + _this.grant_type;
        return _this.fetchUrl(url, 'POST');
    };
```
Instead it produces the following separately at different locations:
```
this.generateBearerToken = function () {
        var url = _this.BEARER_TOKEN_URL + '?client_id=' + _this.access_key + '&client_secret=' + _this.secret_key + '&redirect_uri=' + _this.redirect_uri + '&code=' + _this.code + '&grant_type=' + _this.grant_type;
        return _this.fetchUrl(url, 'POST');
    };

......................................................
.....................................................
//at the bottom of the page
/**
     * Promise factory to generate a Bearer Token for write_access to private data.
     * The Unsplash API uses OAuth2 to authenticate and authorize Unsplash users. 
     * Unsplash’s OAuth2 paths live at https://unsplash.com/oauth/.
     * @function generateBearerToken
     * @memberof UnsplashApi
     * @returns {Object} - The user's Access Token JSON data object.
     */
```
I observed this behaviour only when regular class methods are changed to fat arrow functions.

**Input Code**
Please clone this repo and see ` fat_arrow_build` and `normal_build` folders:
https://github.com/SandeepVattapparambil/webpack_bug
or see this link:
[babel playground](https://babeljs.io/repl#?babili=false&browsers=&build=&builtIns=false&spec=false&loose=false&code_lz=PQKhCgAIUhRBlAbJAxgGwIYGcuQO4CWALgBaQBmGRkGATrQPZ6QEB2rAprRQK6spECDVlighg4cAHIeWDpCxFaBAVIDck0BGiQAAumy4ACgzQBPAObCxkACol5AWwxtIAB1OXhqTDjESDHEgTcytWSABvSUgYyC0oWJ0AYV9cFGFFWh4BBloE2JhdNzoMR0iQAF9IBwILEmp8mMLi2lLyqsIAE1JIRugJRPSRJWyiXIAKGrqiABp8Am6SAEpIvtjSAiwAOlZS-QBeSCkQr1Z1NZiN7an6yEObog1ExKutrp7D95In2Iro2Piz0Ku0c8iwGDMADk9n1CuQ-AIhKxYXo2Jw8kDIABBaocNBuLi8fiCbxjBQQyAgjiwgaxcFQvZ3SDjFb7AB8q2esSGWFMHC2aAYFnGUgAEgQ5gBJGhlDBHOavKmQADURy2UiWPxif0agMSwMZ9PFilyZhRunhxKR5rRXBROIc-MJlsRpIY5LMlJhQNpMSNmzGtE9hxZdw5US5MR5fIFQpFACITmF4yxcJ0uAQAG4cToURhlUjyADitA4HAA1u5TLJmc5WGYVlIVUcMKxc2ECHLxq2LGgOEt1ZrGn8dY4GJ0eH2thwAB4eWhEXCHJPCNRAA&debug=false&forceAllTransforms=false&shippedProposals=false&circleciRepo=&evaluate=false&fileSize=false&sourceType=module&lineWrap=true&presets=es2015%2Creact%2Cstage-2&prettier=false&targets=&version=6.26.0&envVersion=)

**Expected behavior/code**
I expected the following output:
```
/**
     * Promise factory to generate a Bearer Token for write_access to private data.
     * The Unsplash API uses OAuth2 to authenticate and authorize Unsplash users. 
     * Unsplash’s OAuth2 paths live at https://unsplash.com/oauth/.
     * @function generateBearerToken
     * @memberof UnsplashApi
     * @returns {Object} - The user's Access Token JSON data object.
     */
  this.generateBearerToken = function () {
        var url = _this.BEARER_TOKEN_URL + '?client_id=' + _this.access_key + '&client_secret=' + _this.secret_key + '&redirect_uri=' + _this.redirect_uri + '&code=' + _this.code + '&grant_type=' + _this.grant_type;
        return _this.fetchUrl(url, 'POST');
    };
```

**Babel Configuration (.babelrc, package.json, cli command)**
available in repo link

**Environment**
- Babel version(s): 6.26.3
- Node/npm version: v9.4.0
- OS:  Windows 10
- Monorepo: yes
- How you are using Babel: loader



Hints:
Hey @SandeepVattapparambil! We really appreciate you taking the time to report an issue. The collaborators
on this project attempt to help as many people as possible, but we're a limited number of volunteers,
so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
community that typically always has someone willing to help. You can sign-up [here](https://slack.babeljs.io/)
for an invite.
The problem is that the comment isn't moved to the compiled property. In Babel 7 it is just discarded.
Hello - I'm actually trying to find a solution to this issue as well. Any updates since 2018?
Thanks.

Patch:
diff --git a/packages/babel-helper-create-class-features-plugin/src/fields.ts b/packages/babel-helper-create-class-features-plugin/src/fields.ts
--- a/packages/babel-helper-create-class-features-plugin/src/fields.ts
+++ b/packages/babel-helper-create-class-features-plugin/src/fields.ts
@@ -557,14 +557,17 @@ function buildPrivateFieldInitLoose(
   const { id } = privateNamesMap.get(prop.node.key.id.name);
   const value = prop.node.value || prop.scope.buildUndefinedNode();
 
-  return template.statement.ast`
-    Object.defineProperty(${ref}, ${t.cloneNode(id)}, {
-      // configurable is false by default
-      // enumerable is false by default
-      writable: true,
-      value: ${value}
-    });
-  `;
+  return inheritPropComments(
+    template.statement.ast`
+      Object.defineProperty(${ref}, ${t.cloneNode(id)}, {
+        // configurable is false by default
+        // enumerable is false by default
+        writable: true,
+        value: ${value}
+      });
+    `,
+    prop,
+  );
 }
 
 function buildPrivateInstanceFieldInitSpec(
@@ -578,24 +581,30 @@ function buildPrivateInstanceFieldInitSpec(
 
   if (!process.env.BABEL_8_BREAKING) {
     if (!state.availableHelper("classPrivateFieldInitSpec")) {
-      return template.statement.ast`${t.cloneNode(id)}.set(${ref}, {
-        // configurable is always false for private elements
-        // enumerable is always false for private elements
-        writable: true,
-        value: ${value},
-      })`;
+      return inheritPropComments(
+        template.statement.ast`${t.cloneNode(id)}.set(${ref}, {
+          // configurable is always false for private elements
+          // enumerable is always false for private elements
+          writable: true,
+          value: ${value},
+        })`,
+        prop,
+      );
     }
   }
 
   const helper = state.addHelper("classPrivateFieldInitSpec");
-  return template.statement.ast`${helper}(
-    ${t.thisExpression()},
-    ${t.cloneNode(id)},
-    {
-      writable: true,
-      value: ${value}
-    },
-  )`;
+  return inheritPropComments(
+    template.statement.ast`${helper}(
+      ${t.thisExpression()},
+      ${t.cloneNode(id)},
+      {
+        writable: true,
+        value: ${value}
+      },
+    )`,
+    prop,
+  );
 }
 
 function buildPrivateStaticFieldInitSpec(
@@ -614,26 +623,32 @@ function buildPrivateStaticFieldInitSpec(
       initAdded: true,
     });
 
-    return template.statement.ast`
-      var ${t.cloneNode(id)} = {
-        // configurable is false by default
-        // enumerable is false by default
-        // writable is false by default
-        get: ${getId ? getId.name : prop.scope.buildUndefinedNode()},
-        set: ${setId ? setId.name : prop.scope.buildUndefinedNode()}
-      }
-    `;
+    return inheritPropComments(
+      template.statement.ast`
+        var ${t.cloneNode(id)} = {
+          // configurable is false by default
+          // enumerable is false by default
+          // writable is false by default
+          get: ${getId ? getId.name : prop.scope.buildUndefinedNode()},
+          set: ${setId ? setId.name : prop.scope.buildUndefinedNode()}
+        }
+      `,
+      prop,
+    );
   }
 
   const value = prop.node.value || prop.scope.buildUndefinedNode();
-  return template.statement.ast`
-    var ${t.cloneNode(id)} = {
-      // configurable is false by default
-      // enumerable is false by default
-      writable: true,
-      value: ${value}
-    };
-  `;
+  return inheritPropComments(
+    template.statement.ast`
+      var ${t.cloneNode(id)} = {
+        // configurable is false by default
+        // enumerable is false by default
+        writable: true,
+        value: ${value}
+      };
+    `,
+    prop,
+  );
 }
 
 function buildPrivateMethodInitLoose(
@@ -646,14 +661,17 @@ function buildPrivateMethodInitLoose(
   if (initAdded) return;
 
   if (methodId) {
-    return template.statement.ast`
+    return inheritPropComments(
+      template.statement.ast`
         Object.defineProperty(${ref}, ${id}, {
           // configurable is false by default
           // enumerable is false by default
           // writable is false by default
           value: ${methodId.name}
         });
-      `;
+      `,
+      prop,
+    );
   }
   const isAccessor = getId || setId;
   if (isAccessor) {
@@ -662,15 +680,18 @@ function buildPrivateMethodInitLoose(
       initAdded: true,
     });
 
-    return template.statement.ast`
-      Object.defineProperty(${ref}, ${id}, {
-        // configurable is false by default
-        // enumerable is false by default
-        // writable is false by default
-        get: ${getId ? getId.name : prop.scope.buildUndefinedNode()},
-        set: ${setId ? setId.name : prop.scope.buildUndefinedNode()}
-      });
-    `;
+    return inheritPropComments(
+      template.statement.ast`
+        Object.defineProperty(${ref}, ${id}, {
+          // configurable is false by default
+          // enumerable is false by default
+          // writable is false by default
+          get: ${getId ? getId.name : prop.scope.buildUndefinedNode()},
+          set: ${setId ? setId.name : prop.scope.buildUndefinedNode()}
+        });
+      `,
+      prop,
+    );
   }
 }
 
@@ -719,24 +740,30 @@ function buildPrivateAccessorInitialization(
 
   if (!process.env.BABEL_8_BREAKING) {
     if (!state.availableHelper("classPrivateFieldInitSpec")) {
-      return template.statement.ast`
-      ${id}.set(${ref}, {
-        get: ${getId ? getId.name : prop.scope.buildUndefinedNode()},
-        set: ${setId ? setId.name : prop.scope.buildUndefinedNode()}
-      });
-    `;
+      return inheritPropComments(
+        template.statement.ast`
+          ${id}.set(${ref}, {
+            get: ${getId ? getId.name : prop.scope.buildUndefinedNode()},
+            set: ${setId ? setId.name : prop.scope.buildUndefinedNode()}
+          });
+        `,
+        prop,
+      );
     }
   }
 
   const helper = state.addHelper("classPrivateFieldInitSpec");
-  return template.statement.ast`${helper}(
-    ${t.thisExpression()},
-    ${t.cloneNode(id)},
-    {
-      get: ${getId ? getId.name : prop.scope.buildUndefinedNode()},
-      set: ${setId ? setId.name : prop.scope.buildUndefinedNode()}
-    },
-  )`;
+  return inheritPropComments(
+    template.statement.ast`${helper}(
+      ${t.thisExpression()},
+      ${t.cloneNode(id)},
+      {
+        get: ${getId ? getId.name : prop.scope.buildUndefinedNode()},
+        set: ${setId ? setId.name : prop.scope.buildUndefinedNode()}
+      },
+    )`,
+    prop,
+  );
 }
 
 function buildPrivateInstanceMethodInitalization(
@@ -750,15 +777,21 @@ function buildPrivateInstanceMethodInitalization(
 
   if (!process.env.BABEL_8_BREAKING) {
     if (!state.availableHelper("classPrivateMethodInitSpec")) {
-      return template.statement.ast`${id}.add(${ref})`;
+      return inheritPropComments(
+        template.statement.ast`${id}.add(${ref})`,
+        prop,
+      );
     }
   }
 
   const helper = state.addHelper("classPrivateMethodInitSpec");
-  return template.statement.ast`${helper}(
-    ${t.thisExpression()},
-    ${t.cloneNode(id)}
-  )`;
+  return inheritPropComments(
+    template.statement.ast`${helper}(
+      ${t.thisExpression()},
+      ${t.cloneNode(id)}
+    )`,
+    prop,
+  );
 }
 
 function buildPublicFieldInitLoose(
@@ -768,12 +801,15 @@ function buildPublicFieldInitLoose(
   const { key, computed } = prop.node;
   const value = prop.node.value || prop.scope.buildUndefinedNode();
 
-  return t.expressionStatement(
-    t.assignmentExpression(
-      "=",
-      t.memberExpression(ref, key, computed || t.isLiteral(key)),
-      value,
+  return inheritPropComments(
+    t.expressionStatement(
+      t.assignmentExpression(
+        "=",
+        t.memberExpression(ref, key, computed || t.isLiteral(key)),
+        value,
+      ),
     ),
+    prop,
   );
 }
 
@@ -785,14 +821,17 @@ function buildPublicFieldInitSpec(
   const { key, computed } = prop.node;
   const value = prop.node.value || prop.scope.buildUndefinedNode();
 
-  return t.expressionStatement(
-    t.callExpression(state.addHelper("defineProperty"), [
-      ref,
-      computed || t.isLiteral(key)
-        ? key
-        : t.stringLiteral((key as t.Identifier).name),
-      value,
-    ]),
+  return inheritPropComments(
+    t.expressionStatement(
+      t.callExpression(state.addHelper("defineProperty"), [
+        ref,
+        computed || t.isLiteral(key)
+          ? key
+          : t.stringLiteral((key as t.Identifier).name),
+        value,
+      ]),
+    ),
+    prop,
   );
 }
 
@@ -814,25 +853,31 @@ function buildPrivateStaticMethodInitLoose(
       initAdded: true,
     });
 
-    return template.statement.ast`
+    return inheritPropComments(
+      template.statement.ast`
+        Object.defineProperty(${ref}, ${id}, {
+          // configurable is false by default
+          // enumerable is false by default
+          // writable is false by default
+          get: ${getId ? getId.name : prop.scope.buildUndefinedNode()},
+          set: ${setId ? setId.name : prop.scope.buildUndefinedNode()}
+        })
+      `,
+      prop,
+    );
+  }
+
+  return inheritPropComments(
+    template.statement.ast`
       Object.defineProperty(${ref}, ${id}, {
         // configurable is false by default
         // enumerable is false by default
         // writable is false by default
-        get: ${getId ? getId.name : prop.scope.buildUndefinedNode()},
-        set: ${setId ? setId.name : prop.scope.buildUndefinedNode()}
-      })
-    `;
-  }
-
-  return template.statement.ast`
-    Object.defineProperty(${ref}, ${id}, {
-      // configurable is false by default
-      // enumerable is false by default
-      // writable is false by default
-      value: ${methodId.name}
-    });
-  `;
+        value: ${methodId.name}
+      });
+    `,
+    prop,
+  );
 }
 
 function buildPrivateMethodDeclaration(
@@ -872,13 +917,16 @@ function buildPrivateMethodDeclaration(
     declId = id;
   }
 
-  return t.functionDeclaration(
-    t.cloneNode(declId),
-    // @ts-expect-error params for ClassMethod has TSParameterProperty
-    params,
-    body,
-    generator,
-    async,
+  return inheritPropComments(
+    t.functionDeclaration(
+      t.cloneNode(declId),
+      // @ts-expect-error params for ClassMethod has TSParameterProperty
+      params,
+      body,
+      generator,
+      async,
+    ),
+    prop,
   );
 }
 
@@ -994,6 +1042,23 @@ function isNameOrLength({ key, computed }: t.ClassProperty) {
   return false;
 }
 
+/**
+ * Inherit comments from class members. This is a reduced version of
+ * t.inheritsComments: the trailing comments are not inherited because
+ * for most class members except the last one, their trailing comments are
+ * the next sibiling's leading comments.
+ *
+ * @template T transformed class member type
+ * @param {T} node transformed class member
+ * @param {PropPath} prop class member
+ * @returns transformed class member type with comments inherited
+ */
+function inheritPropComments<T extends t.Node>(node: T, prop: PropPath) {
+  t.inheritLeadingComments(node, prop.node);
+  t.inheritInnerComments(node, prop.node);
+  return node;
+}
+
 export function buildFieldsInitNodes(
   ref: t.Identifier,
   superRef: t.Expression | undefined,
@@ -1056,9 +1121,14 @@ export function buildFieldsInitNodes(
         // We special-case the single expression case to avoid the iife, since
         // it's common.
         if (blockBody.length === 1 && t.isExpressionStatement(blockBody[0])) {
-          staticNodes.push(blockBody[0]);
+          staticNodes.push(inheritPropComments(blockBody[0], prop));
         } else {
-          staticNodes.push(template.statement.ast`(() => { ${blockBody} })()`);
+          staticNodes.push(
+            t.inheritsComments(
+              template.statement.ast`(() => { ${blockBody} })()`,
+              prop.node,
+            ),
+          );
         }
         break;
       }
diff --git a/packages/babel-plugin-proposal-class-static-block/src/index.ts b/packages/babel-plugin-proposal-class-static-block/src/index.ts
--- a/packages/babel-plugin-proposal-class-static-block/src/index.ts
+++ b/packages/babel-plugin-proposal-class-static-block/src/index.ts
@@ -64,7 +64,10 @@ export default declare(({ types: t, template, assertVersion }) => {
           // We special-case the single expression case to avoid the iife, since
           // it's common.
           if (blockBody.length === 1 && t.isExpressionStatement(blockBody[0])) {
-            replacement = blockBody[0].expression;
+            replacement = t.inheritsComments(
+              blockBody[0].expression,
+              blockBody[0],
+            );
           } else {
             replacement = template.expression.ast`(() => { ${blockBody} })()`;
           }


Test patch:
diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/compile-to-class/preserve-comments/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/compile-to-class/preserve-comments/input.js
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/compile-to-class/preserve-comments/input.js
@@ -0,0 +1,9 @@
+class C {
+  /* before a */
+  a;
+  /* after a */
+
+  /* before b */
+  static b;
+  /* after b */
+}
diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/compile-to-class/preserve-comments/options.json b/packages/babel-plugin-proposal-class-properties/test/fixtures/compile-to-class/preserve-comments/options.json
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/compile-to-class/preserve-comments/options.json
@@ -0,0 +1,3 @@
+{
+  "plugins": ["proposal-class-properties"]
+}
diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/compile-to-class/preserve-comments/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/compile-to-class/preserve-comments/output.js
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/compile-to-class/preserve-comments/output.js
@@ -0,0 +1,10 @@
+class C {
+  constructor() {
+    /* before a */
+    babelHelpers.defineProperty(this, "a", void 0);
+  }
+  /* after b */
+}
+/* after a */
+/* before b */
+babelHelpers.defineProperty(C, "b", void 0);
diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/preserve-comments/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/preserve-comments/input.js
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/preserve-comments/input.js
@@ -0,0 +1,9 @@
+class C {
+  /* before a */
+  #a;
+  /* after a */
+
+  /* before b */
+  static #b;
+  /* after b */
+}
diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/preserve-comments/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/preserve-comments/output.js
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/preserve-comments/output.js
@@ -0,0 +1,18 @@
+var _a = /*#__PURE__*/babelHelpers.classPrivateFieldLooseKey("a");
+var _b = /*#__PURE__*/babelHelpers.classPrivateFieldLooseKey("b");
+var C = /*#__PURE__*/babelHelpers.createClass(function C() {
+  "use strict";
+
+  babelHelpers.classCallCheck(this, C);
+  /* before a */
+  Object.defineProperty(this, _a, {
+    writable: true,
+    value: void 0
+  });
+} /* after b */);
+/* after a */
+/* before b */
+Object.defineProperty(C, _b, {
+  writable: true,
+  value: void 0
+});
diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/preserve-comments/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/preserve-comments/input.js
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/preserve-comments/input.js
@@ -0,0 +1,9 @@
+class C {
+  /* before a */
+  #a;
+  /* after a */
+
+  /* before b */
+  static #b;
+  /* after b */
+}
diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/preserve-comments/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/preserve-comments/output.js
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/preserve-comments/output.js
@@ -0,0 +1,17 @@
+var _a = /*#__PURE__*/new WeakMap();
+var C = /*#__PURE__*/babelHelpers.createClass(function C() {
+  "use strict";
+
+  babelHelpers.classCallCheck(this, C);
+  /* before a */
+  babelHelpers.classPrivateFieldInitSpec(this, _a, {
+    writable: true,
+    value: void 0
+  });
+} /* after b */);
+/* after a */
+/* before b */
+var _b = {
+  writable: true,
+  value: void 0
+};
diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/public-loose/preserve-comments/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/public-loose/preserve-comments/input.js
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/public-loose/preserve-comments/input.js
@@ -0,0 +1,9 @@
+class C {
+  /* before a */
+  a;
+  /* after a */
+
+  /* before b */
+  static b;
+  /* after b */
+}
diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/public-loose/preserve-comments/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/public-loose/preserve-comments/output.js
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/public-loose/preserve-comments/output.js
@@ -0,0 +1,10 @@
+var C = /*#__PURE__*/babelHelpers.createClass(function C() {
+  "use strict";
+
+  babelHelpers.classCallCheck(this, C);
+  /* before a */
+  this.a = void 0;
+} /* after b */);
+/* after a */
+/* before b */
+C.b = void 0;
diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/public/preserve-comments/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/public/preserve-comments/input.js
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/public/preserve-comments/input.js
@@ -0,0 +1,9 @@
+class C {
+  /* before a */
+  a;
+  /* after a */
+
+  /* before b */
+  static b;
+  /* after b */
+}
diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/public/preserve-comments/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/public/preserve-comments/output.js
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/public/preserve-comments/output.js
@@ -0,0 +1,10 @@
+var C = /*#__PURE__*/babelHelpers.createClass(function C() {
+  "use strict";
+
+  babelHelpers.classCallCheck(this, C);
+  /* before a */
+  babelHelpers.defineProperty(this, "a", void 0);
+} /* after b */);
+/* after a */
+/* before b */
+babelHelpers.defineProperty(C, "b", void 0);
diff --git a/packages/babel-plugin-proposal-class-static-block/test/fixtures/class-static-block/preserve-comments/input.js b/packages/babel-plugin-proposal-class-static-block/test/fixtures/class-static-block/preserve-comments/input.js
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-proposal-class-static-block/test/fixtures/class-static-block/preserve-comments/input.js
@@ -0,0 +1,22 @@
+class C {
+  /* before 1 */
+  static {}
+  /* after 1 */
+
+  /* before 2 */
+  static {
+    /* before this.foo */
+    this.foo = 42;
+    /* after this.foo */
+  }
+  /* after 2 */
+
+  /* before 3 */
+  static {
+    /* before this.bar */
+    this.bar = 42;
+    this.bar = 42;
+    /* after this.bar */
+  }
+  /* after 3 */
+}
diff --git a/packages/babel-plugin-proposal-class-static-block/test/fixtures/class-static-block/preserve-comments/output.js b/packages/babel-plugin-proposal-class-static-block/test/fixtures/class-static-block/preserve-comments/output.js
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-proposal-class-static-block/test/fixtures/class-static-block/preserve-comments/output.js
@@ -0,0 +1,18 @@
+class C {
+  /* before 1 */
+  static #_ = (() => {})();
+  /* after 1 */
+  /* before 2 */
+  static #_2 = /* before this.foo */
+  this.foo = 42
+  /* after this.foo */;
+  /* after 2 */
+  /* before 3 */
+  static #_3 = (() => {
+    /* before this.bar */
+    this.bar = 42;
+    this.bar = 42;
+    /* after this.bar */
+  })();
+  /* after 3 */
+}
diff --git a/packages/babel-plugin-proposal-class-static-block/test/fixtures/integration-loose/name-conflict/output.js b/packages/babel-plugin-proposal-class-static-block/test/fixtures/integration-loose/name-conflict/output.js
--- a/packages/babel-plugin-proposal-class-static-block/test/fixtures/integration-loose/name-conflict/output.js
+++ b/packages/babel-plugin-proposal-class-static-block/test/fixtures/integration-loose/name-conflict/output.js
@@ -4,5 +4,7 @@ Object.defineProperty(Foo, _, {
   writable: true,
   value: 42
 });
+// static block can not be tranformed as `#_` here
+
 Foo.foo = babelHelpers.classPrivateFieldLooseBase(Foo, _)[_];
 expect(Foo.foo).toBe(42);
diff --git a/packages/babel-plugin-proposal-class-static-block/test/fixtures/integration-loose/preserve-comments/input.js b/packages/babel-plugin-proposal-class-static-block/test/fixtures/integration-loose/preserve-comments/input.js
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-proposal-class-static-block/test/fixtures/integration-loose/preserve-comments/input.js
@@ -0,0 +1,22 @@
+class C {
+  /* before 1 */
+  static {}
+  /* after 1 */
+
+  /* before 2 */
+  static {
+    /* before this.foo */
+    this.foo = 42;
+    /* after this.foo */
+  }
+  /* after 2 */
+
+  /* before 3 */
+  static {
+    /* before this.bar */
+    this.bar = 42;
+    this.bar = 42;
+    /* after this.bar */
+  }
+  /* after 3 */
+}
diff --git a/packages/babel-plugin-proposal-class-static-block/test/fixtures/integration-loose/preserve-comments/output.js b/packages/babel-plugin-proposal-class-static-block/test/fixtures/integration-loose/preserve-comments/output.js
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-proposal-class-static-block/test/fixtures/integration-loose/preserve-comments/output.js
@@ -0,0 +1,16 @@
+class C {}
+/* before 1 */
+(() => {})();
+/* after 1 */
+/* before 2 */
+/* before this.foo */C.foo = 42;
+/* after this.foo */
+/* after 2 */
+/* before 3 */
+(() => {
+  /* before this.bar */
+  C.bar = 42;
+  C.bar = 42;
+  /* after this.bar */
+})();
+/* after 3 */
diff --git a/packages/babel-plugin-proposal-class-static-block/test/fixtures/integration/name-conflict/output.js b/packages/babel-plugin-proposal-class-static-block/test/fixtures/integration/name-conflict/output.js
--- a/packages/babel-plugin-proposal-class-static-block/test/fixtures/integration/name-conflict/output.js
+++ b/packages/babel-plugin-proposal-class-static-block/test/fixtures/integration/name-conflict/output.js
@@ -3,5 +3,7 @@ var _ = {
   writable: true,
   value: 42
 };
+// static block can not be tranformed as `#_` here
+
 Foo.foo = babelHelpers.classStaticPrivateFieldSpecGet(Foo, Foo, _);
 expect(Foo.foo).toBe(42);
diff --git a/packages/babel-plugin-proposal-class-static-block/test/fixtures/integration/preserve-comments/input.js b/packages/babel-plugin-proposal-class-static-block/test/fixtures/integration/preserve-comments/input.js
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-proposal-class-static-block/test/fixtures/integration/preserve-comments/input.js
@@ -0,0 +1,22 @@
+class C {
+  /* before 1 */
+  static {}
+  /* after 1 */
+
+  /* before 2 */
+  static {
+    /* before this.foo */
+    this.foo = 42;
+    /* after this.foo */
+  }
+  /* after 2 */
+
+  /* before 3 */
+  static {
+    /* before this.bar */
+    this.bar = 42;
+    this.bar = 42;
+    /* after this.bar */
+  }
+  /* after 3 */
+}
diff --git a/packages/babel-plugin-proposal-class-static-block/test/fixtures/integration/preserve-comments/output.js b/packages/babel-plugin-proposal-class-static-block/test/fixtures/integration/preserve-comments/output.js
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-proposal-class-static-block/test/fixtures/integration/preserve-comments/output.js
@@ -0,0 +1,16 @@
+class C {}
+/* before 1 */
+(() => {})();
+/* after 1 */
+/* before 2 */
+/* before this.foo */C.foo = 42;
+/* after this.foo */
+/* after 2 */
+/* before 3 */
+(() => {
+  /* before this.bar */
+  C.bar = 42;
+  C.bar = 42;
+  /* after this.bar */
+})();
+/* after 3 */
diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors-loose/preserve-comments/input.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors-loose/preserve-comments/input.js
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors-loose/preserve-comments/input.js
@@ -0,0 +1,9 @@
+class C {
+  /* before get a */
+  get #a() { return 42 };
+  /* after get a */
+
+  /* before set a */
+  set #a(v) {}
+  /* after set a */
+}
diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors-loose/preserve-comments/output.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors-loose/preserve-comments/output.js
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors-loose/preserve-comments/output.js
@@ -0,0 +1,17 @@
+var _a = /*#__PURE__*/babelHelpers.classPrivateFieldLooseKey("a");
+class C {
+  constructor() {
+    /* before get a */
+    Object.defineProperty(this, _a, {
+      get: _get_a,
+      set: _set_a
+    });
+  }
+  /* after set a */
+}
+function _get_a() {
+  return 42;
+}
+/* after get a */
+/* before set a */
+function _set_a(v) {}
diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors-privateFieldsAsProperties/preserve-comments/input.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors-privateFieldsAsProperties/preserve-comments/input.js
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors-privateFieldsAsProperties/preserve-comments/input.js
@@ -0,0 +1,9 @@
+class C {
+  /* before get a */
+  get #a() { return 42 };
+  /* after get a */
+
+  /* before set a */
+  set #a(v) {}
+  /* after set a */
+}
diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors-privateFieldsAsProperties/preserve-comments/output.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors-privateFieldsAsProperties/preserve-comments/output.js
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors-privateFieldsAsProperties/preserve-comments/output.js
@@ -0,0 +1,17 @@
+var _a = /*#__PURE__*/babelHelpers.classPrivateFieldLooseKey("a");
+class C {
+  constructor() {
+    /* before get a */
+    Object.defineProperty(this, _a, {
+      get: _get_a,
+      set: _set_a
+    });
+  }
+  /* after set a */
+}
+function _get_a() {
+  return 42;
+}
+/* after get a */
+/* before set a */
+function _set_a(v) {}
diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/preserve-comments/input.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/preserve-comments/input.js
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/preserve-comments/input.js
@@ -0,0 +1,9 @@
+class C {
+  /* before get a */
+  get #a() { return 42 };
+  /* after get a */
+
+  /* before set a */
+  set #a(v) {}
+  /* after set a */
+}
diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/preserve-comments/output.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/preserve-comments/output.js
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/preserve-comments/output.js
@@ -0,0 +1,17 @@
+var _a = /*#__PURE__*/new WeakMap();
+class C {
+  constructor() {
+    /* before get a */
+    babelHelpers.classPrivateFieldInitSpec(this, _a, {
+      get: _get_a,
+      set: _set_a
+    });
+  }
+  /* after set a */
+}
+function _get_a() {
+  return 42;
+}
+/* after get a */
+/* before set a */
+function _set_a(v) {}
diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method-loose/preserve-comments/input.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method-loose/preserve-comments/input.js
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method-loose/preserve-comments/input.js
@@ -0,0 +1,5 @@
+class C {
+  /* before a */
+  #a() {};
+  /* after a */
+}
diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method-loose/preserve-comments/output.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method-loose/preserve-comments/output.js
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method-loose/preserve-comments/output.js
@@ -0,0 +1,10 @@
+var _a = /*#__PURE__*/babelHelpers.classPrivateFieldLooseKey("a");
+class C {
+  constructor() {
+    /* before a */
+    Object.defineProperty(this, _a, {
+      value: _a2
+    });
+  }
+} /* after a */
+function _a2() {}
diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/preserve-comments/input.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/preserve-comments/input.js
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/preserve-comments/input.js
@@ -0,0 +1,5 @@
+class C {
+  /* before a */
+  #a() {};
+  /* after a */
+}
diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/preserve-comments/output.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/preserve-comments/output.js
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/preserve-comments/output.js
@@ -0,0 +1,8 @@
+var _a = /*#__PURE__*/new WeakSet();
+class C {
+  constructor() {
+    /* before a */
+    babelHelpers.classPrivateMethodInitSpec(this, _a);
+  }
+} /* after a */
+function _a2() {}
diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-static-method-loose/preserve-comments/input.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-static-method-loose/preserve-comments/input.js
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-static-method-loose/preserve-comments/input.js
@@ -0,0 +1,5 @@
+class C {
+  /* before a */
+  static #a() {};
+  /* after a */
+}
diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-static-method-loose/preserve-comments/output.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-static-method-loose/preserve-comments/output.js
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-static-method-loose/preserve-comments/output.js
@@ -0,0 +1,10 @@
+var _a = /*#__PURE__*/babelHelpers.classPrivateFieldLooseKey("a");
+class C {
+
+  /* after a */
+}
+/* before a */
+function _a2() {}
+Object.defineProperty(C, _a, {
+  value: _a2
+});
diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-static-method/preserve-comments/input.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-static-method/preserve-comments/input.js
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-static-method/preserve-comments/input.js
@@ -0,0 +1,5 @@
+class C {
+  /* before a */
+  static #a() {};
+  /* after a */
+}
diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-static-method/preserve-comments/output.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-static-method/preserve-comments/output.js
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-static-method/preserve-comments/output.js
@@ -0,0 +1,6 @@
+class C {
+
+  /* after a */
+}
+/* before a */
+function _a() {}
diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors-loose/preserve-comments/input.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors-loose/preserve-comments/input.js
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors-loose/preserve-comments/input.js
@@ -0,0 +1,9 @@
+class C {
+  /* before get a */
+  static get #a() { return 42 };
+  /* after get a */
+
+  /* before set a */
+  static set #a(v) {}
+  /* after set a */
+}
diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors-loose/preserve-comments/output.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors-loose/preserve-comments/output.js
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors-loose/preserve-comments/output.js
@@ -0,0 +1,13 @@
+var _a = /*#__PURE__*/babelHelpers.classPrivateFieldLooseKey("a");
+class C {}
+/* before get a */
+function _get_a() {
+  return 42;
+}
+/* after get a */
+/* before set a */
+function _set_a(v) {}
+Object.defineProperty(C, _a, {
+  get: _get_a,
+  set: _set_a
+});
diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors-privateFieldsAsProperties/preserve-comments/input.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors-privateFieldsAsProperties/preserve-comments/input.js
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors-privateFieldsAsProperties/preserve-comments/input.js
@@ -0,0 +1,9 @@
+class C {
+  /* before get a */
+  static get #a() { return 42 };
+  /* after get a */
+
+  /* before set a */
+  static set #a(v) {}
+  /* after set a */
+}
diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors-privateFieldsAsProperties/preserve-comments/output.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors-privateFieldsAsProperties/preserve-comments/output.js
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors-privateFieldsAsProperties/preserve-comments/output.js
@@ -0,0 +1,13 @@
+var _a = /*#__PURE__*/babelHelpers.classPrivateFieldLooseKey("a");
+class C {}
+/* before get a */
+function _get_a() {
+  return 42;
+}
+/* after get a */
+/* before set a */
+function _set_a(v) {}
+Object.defineProperty(C, _a, {
+  get: _get_a,
+  set: _set_a
+});
diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors/preserve-comments/input.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors/preserve-comments/input.js
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors/preserve-comments/input.js
@@ -0,0 +1,9 @@
+class C {
+  /* before get a */
+  static get #a() { return 42 };
+  /* after get a */
+
+  /* before set a */
+  static set #a(v) {}
+  /* after set a */
+}
diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors/preserve-comments/output.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors/preserve-comments/output.js
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/static-accessors/preserve-comments/output.js
@@ -0,0 +1,12 @@
+class C {}
+/* before get a */
+function _get_a() {
+  return 42;
+}
+/* after get a */
+/* before set a */
+function _set_a(v) {}
+var _a = {
+  get: _get_a,
+  set: _set_a
+};
diff --git a/packages/babel-plugin-transform-classes/test/fixtures/get-set-loose/preserve-comments/input.js b/packages/babel-plugin-transform-classes/test/fixtures/get-set-loose/preserve-comments/input.js
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-transform-classes/test/fixtures/get-set-loose/preserve-comments/input.js
@@ -0,0 +1,9 @@
+class C {
+  /* before get a */
+  get a() { return 42 }
+  /* after get a */
+
+  /* before set a */
+  set a(v) {}
+  /* after set a */
+}
diff --git a/packages/babel-plugin-transform-classes/test/fixtures/get-set-loose/preserve-comments/output.js b/packages/babel-plugin-transform-classes/test/fixtures/get-set-loose/preserve-comments/output.js
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-transform-classes/test/fixtures/get-set-loose/preserve-comments/output.js
@@ -0,0 +1,18 @@
+let C = /*#__PURE__*/function () {
+  "use strict";
+
+  function C() {}
+  babelHelpers.createClass(C, [{
+    key: "a",
+    get: /* before get a */
+    function () {
+      return 42;
+    }
+    /* after get a */
+
+    /* before set a */,
+    set: function (v) {}
+    /* after set a */
+  }]);
+  return C;
+}();
diff --git a/packages/babel-plugin-transform-classes/test/fixtures/get-set/preserve-comments/input.js b/packages/babel-plugin-transform-classes/test/fixtures/get-set/preserve-comments/input.js
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-transform-classes/test/fixtures/get-set/preserve-comments/input.js
@@ -0,0 +1,9 @@
+class C {
+  /* before get a */
+  get a() { return 42 }
+  /* after get a */
+
+  /* before set a */
+  set a(v) {}
+  /* after set a */
+}
diff --git a/packages/babel-plugin-transform-classes/test/fixtures/get-set/preserve-comments/output.js b/packages/babel-plugin-transform-classes/test/fixtures/get-set/preserve-comments/output.js
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-transform-classes/test/fixtures/get-set/preserve-comments/output.js
@@ -0,0 +1,20 @@
+let C = /*#__PURE__*/function () {
+  "use strict";
+
+  function C() {
+    babelHelpers.classCallCheck(this, C);
+  }
+  babelHelpers.createClass(C, [{
+    key: "a",
+    get: /* before get a */
+    function () {
+      return 42;
+    }
+    /* after get a */
+
+    /* before set a */,
+    set: function (v) {}
+    /* after set a */
+  }]);
+  return C;
+}();
diff --git a/packages/babel-plugin-transform-classes/test/fixtures/loose/preserve-comments/input.js b/packages/babel-plugin-transform-classes/test/fixtures/loose/preserve-comments/input.js
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-transform-classes/test/fixtures/loose/preserve-comments/input.js
@@ -0,0 +1,5 @@
+class C {
+  /* before a */
+  a() {}
+  /* after a */
+}
diff --git a/packages/babel-plugin-transform-classes/test/fixtures/loose/preserve-comments/output.js b/packages/babel-plugin-transform-classes/test/fixtures/loose/preserve-comments/output.js
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-transform-classes/test/fixtures/loose/preserve-comments/output.js
@@ -0,0 +1,10 @@
+var C = /*#__PURE__*/function () {
+  "use strict";
+
+  function C() {}
+  var _proto = C.prototype;
+  /* before a */
+  _proto.a = function a() {}
+  /* after a */;
+  return C;
+}();
diff --git a/packages/babel-plugin-transform-classes/test/fixtures/spec/preserve-comments/input.js b/packages/babel-plugin-transform-classes/test/fixtures/spec/preserve-comments/input.js
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-transform-classes/test/fixtures/spec/preserve-comments/input.js
@@ -0,0 +1,5 @@
+class C {
+  /* before a */
+  a() {}
+  /* after a */
+}
diff --git a/packages/babel-plugin-transform-classes/test/fixtures/spec/preserve-comments/output.js b/packages/babel-plugin-transform-classes/test/fixtures/spec/preserve-comments/output.js
new file mode 100644
--- /dev/null
+++ b/packages/babel-plugin-transform-classes/test/fixtures/spec/preserve-comments/output.js
@@ -0,0 +1,14 @@
+var C = /*#__PURE__*/function () {
+  "use strict";
+
+  function C() {
+    babelHelpers.classCallCheck(this, C);
+  }
+  babelHelpers.createClass(C, [{
+    key: "a",
+    value: /* before a */
+    function a() {}
+    /* after a */
+  }]);
+  return C;
+}();
diff --git a/packages/babel-plugin-transform-new-target/test/fixtures/general/class-properties-loose/output.js b/packages/babel-plugin-transform-new-target/test/fixtures/general/class-properties-loose/output.js
--- a/packages/babel-plugin-transform-new-target/test/fixtures/general/class-properties-loose/output.js
+++ b/packages/babel-plugin-transform-new-target/test/fixtures/general/class-properties-loose/output.js
@@ -10,6 +10,7 @@ class Foo {
     };
     this.Bar = (_class = class {
       constructor() {
+        // should not replace
         this.q = this.constructor;
       } // should not replace
     }, _class.p = void 0, _class.p1 = class {
diff --git a/packages/babel-plugin-transform-new-target/test/fixtures/general/class-properties/output.js b/packages/babel-plugin-transform-new-target/test/fixtures/general/class-properties/output.js
--- a/packages/babel-plugin-transform-new-target/test/fixtures/general/class-properties/output.js
+++ b/packages/babel-plugin-transform-new-target/test/fixtures/general/class-properties/output.js
@@ -10,6 +10,7 @@ class Foo {
     });
     this.Bar = (_class = class {
       constructor() {
+        // should not replace
         babelHelpers.defineProperty(this, "q", this.constructor);
       } // should not replace
     }, babelHelpers.defineProperty(_class, "p", void 0), babelHelpers.defineProperty(_class, "p1", class {