getMemberExpressionRoot.js 371 B

123456789101112131415
  1. /**
  2. * Returns the path to the first part of the MemberExpression. I.e. given a
  3. * path representing
  4. *
  5. * foo.bar.baz
  6. *
  7. * it returns the path of/to `foo`.
  8. */
  9. export default function getMemberExpressionRoot(memberExpressionPath) {
  10. let path = memberExpressionPath;
  11. while (path.isMemberExpression()) {
  12. path = path.get('object');
  13. }
  14. return path;
  15. }