ClassDeclaration: function visitClassDeclaration()

in packages/eui/scripts/babel/proptypes-from-ts-props/index.js [1434:1484]


      ClassDeclaration: function visitClassDeclaration(nodePath, state) {
        // only process typescript files
        if (
          path.extname(state.file.opts.filename) !== '.ts' &&
          path.extname(state.file.opts.filename) !== '.tsx'
        )
          return;

        const types = state.get('types');

        if (nodePath.node.superClass != null) {
          let isReactComponent = false;

          if (types.isMemberExpression(nodePath.node.superClass)) {
            const objectName = nodePath.node.superClass.object.name;
            const propertyName = nodePath.node.superClass.property.name;
            if (
              objectName === 'React' &&
              (propertyName === 'Component' || propertyName === 'PureComponent')
            ) {
              isReactComponent = true;
            }
          } else if (types.isIdentifier(nodePath.node.superClass)) {
            const identifierName = nodePath.node.superClass.name;
            if (
              identifierName === 'Component' ||
              identifierName === 'PureComponent'
            ) {
              if (state.get('importsFromReact').has(identifierName)) {
                isReactComponent = true;
              }
            }
          }

          if (isReactComponent && nodePath.node.superTypeParameters != null) {
            processComponentDeclaration(
              nodePath.node.superTypeParameters.params[0],
              nodePath,
              state
            );

            // babel-plugin-react-docgen passes `this.file.code` to react-docgen
            // instead of using the modified AST; to expose our changes to react-docgen
            // they need to be rendered to a string
            this.file.code = stripTypeScript(
              this.file.opts.filename,
              this.file.ast
            );
          }
        }
      },