propName.js 573 B

12345678910111213141516171819202122
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = propName;
  6. /**
  7. * Returns the name of the prop given the JSXAttribute object.
  8. */
  9. function propName() {
  10. var prop = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  11. if (!prop.type || prop.type !== 'JSXAttribute') {
  12. throw new Error('The prop must be a JSXAttribute collected by the AST parser.');
  13. }
  14. if (prop.name.type === 'JSXNamespacedName') {
  15. return prop.name.namespace.name + ':' + prop.name.name.name;
  16. }
  17. return prop.name.name;
  18. }