Repository: babel/babel
File: packages/babel-plugin-transform-typescript/src/index.js (JavaScript)

Code before:
      `"${name}" without registering it in the scope tracker. If you are the author\n` +
      ` of that plugin, please use "scope.registerDeclaration(declarationPath)".`,
  );

  return false;
}

function registerGlobalType(programScope, name) {
  GLOBAL_TYPES.get(programScope.path.node).add(name);
}

export default declare(
  (
    api,
    { jsxPragma = "React", allowNamespaces = false, declareFields = false },
  ) => {
    api.assertVersion(7);

    const JSX_ANNOTATION_REGEX = /\*?\s*@jsx\s+([^\s]+)/;

    const classMemberVisitors = {
      field(path) {
        const { node } = path;

        if (!declareFields && node.declare) {
          throw path.buildCodeFrameError(
            `The 'declare' modifier is only allowed when the 'declareFields' option of ` +
              `@babel/plugin-transform-typescript or @babel/preset-typescript is enabled.`,
          );
        }
        if (node.definite || node.declare) {
          if (node.value) {
            throw path.buildCodeFrameError(
              `Definietly assigned fields and fields with the 'declare' modifier cannot` +
                ` be initialized here, but only in the constructor`,
            );
          }

          path.remove();
        } else if (!declareFields && !node.value && !node.decorators) {
          path.remove();
        }

        if (node.accessibility) node.accessibility = null;
        if (node.abstract) node.abstract = null;
        if (node.readonly) node.readonly = null;
        if (node.optional) node.optional = null;
        if (node.typeAnnotation) node.typeAnnotation = null;
      },
      method({ node }) {
        if (node.accessibility) node.accessibility = null;

Review comment (suggestion):
I didn't use the `ClassProperty` visitor because the class fields transform transforms them using the `Class` visitor, so they would never be visited in practice.

Code after:
      `"${name}" without registering it in the scope tracker. If you are the author\n` +
      ` of that plugin, please use "scope.registerDeclaration(declarationPath)".`,
  );

  return false;
}

function registerGlobalType(programScope, name) {
  GLOBAL_TYPES.get(programScope.path.node).add(name);
}

export default declare(
  (
    api,
    {
      jsxPragma = "React",
      allowNamespaces = false,
      allowDeclareFields = false,
    },
  ) => {
    api.assertVersion(7);

    const JSX_ANNOTATION_REGEX = /\*?\s*@jsx\s+([^\s]+)/;

    const classMemberVisitors = {
      field(path) {
        const { node } = path;

        if (!allowDeclareFields && node.declare) {
          throw path.buildCodeFrameError(
            `The 'declare' modifier is only allowed when the 'allowDeclareFields' option of ` +
              `@babel/plugin-transform-typescript or @babel/preset-typescript is enabled.`,
          );
        }
        if (node.definite || node.declare) {
          if (node.value) {
            throw path.buildCodeFrameError(
              `Definietly assigned fields and fields with the 'declare' modifier cannot` +
                ` be initialized here, but only in the constructor`,
            );
          }

          path.remove();
        } else if (!allowDeclareFields && !node.value && !node.decorators) {
          path.remove();
        }

        if (node.accessibility) node.accessibility = null;
        if (node.abstract) node.abstract = null;
        if (node.readonly) node.readonly = null;
        if (node.optional) node.optional = null;