propName.js 404 B

1234567891011121314
  1. /**
  2. * Returns the name of the prop given the JSXAttribute object.
  3. */
  4. export default function propName(prop = {}) {
  5. if (!prop.type || prop.type !== 'JSXAttribute') {
  6. throw new Error('The prop must be a JSXAttribute collected by the AST parser.');
  7. }
  8. if (prop.name.type === 'JSXNamespacedName') {
  9. return `${prop.name.namespace.name}:${prop.name.name.name}`;
  10. }
  11. return prop.name.name;
  12. }