function replacePropTypesReferences()

in transforms/React-PropTypes-to-prop-types.js [242:268]


  function replacePropTypesReferences(j, root) {
    let hasModifications = false;

    root
      .find(j.Identifier)
      .filter(isReactPropTypes)
      .forEach(path => {
        hasModifications = true;

        // VariableDeclarator should be removed entirely
        // eg 'const PropTypes = React.PropTypes'
        // Don't remove pointers though
        // eg 'const ReactPropTypes = PropTypes'
        if (
          path.parent.parent.node.type === 'VariableDeclarator' &&
          path.parent.parent.node.id.name === 'PropTypes'
        ) {
          j(path.parent.parent).remove();
        } else {
          // MemberExpression should be updated
          // eg 'foo = React.PropTypes.string'
          j(path.parent).replaceWith(j.identifier(localPropTypesName));
        }
      });

    return hasModifications;
  }