isDestructuringAssignment.js 376 B

1234567891011
  1. /**
  2. * Checks if the input Identifier is part of a destructuring Assignment
  3. * and the name of the property key matches the input name
  4. */
  5. export default function isDestructuringAssignment(path, name) {
  6. if (!path.isObjectProperty()) {
  7. return false;
  8. }
  9. const id = path.get('key');
  10. return id.isIdentifier({ name }) && path.parentPath.isObjectPattern();
  11. }